From: "Jan Beulich" Subject: [PATCH] VT-d: fix device assignment failure (regression from Xen c/s 19805:2f1fa2215e60) Date: Tue, 02 Nov 2010 08:04:30 +0000 Message-ID: <4CCFD41E0200007800020359@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part331EBD1E.1__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: "xen-devel@lists.xensource.com" Cc: Weidong Han List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part331EBD1E.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline If the device at :00.0 is the device the mapping operation was initiated for, trying to map it a second time will fail, and hence this second mapping attempt must be prevented (as was done prior to said c/s). Once at it, simplify the code a little, too. Signed-off-by: Jan Beulich --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -1371,23 +1371,16 @@ static int domain_context_mapping(struct if ( find_upstream_bridge(&bus, &devfn, &secbus) < 1 ) break; =20 - /* PCIe to PCI/PCIx bridge */ - if ( pdev_type(bus, devfn) =3D=3D DEV_TYPE_PCIe2PCI_BRIDGE ) - { - ret =3D domain_context_mapping_one(domain, drhd->iommu, bus, = devfn); - if ( ret ) - return ret; + ret =3D domain_context_mapping_one(domain, drhd->iommu, bus, = devfn); =20 - /* - * Devices behind PCIe-to-PCI/PCIx bridge may generate - * different requester-id. It may originate from devfn=3D0 - * on the secondary bus behind the bridge. Map that id - * as well. - */ + /* + * Devices behind PCIe-to-PCI/PCIx bridge may generate different + * requester-id. It may originate from devfn=3D0 on the secondary = bus + * behind the bridge. Map that id as well if we didn't already. + */ + if ( !ret && pdev_type(bus, devfn) =3D=3D DEV_TYPE_PCIe2PCI_BRIDGE= && + (secbus !=3D pdev->bus || pdev->devfn !=3D 0) ) ret =3D domain_context_mapping_one(domain, drhd->iommu, = secbus, 0); - } - else /* Legacy PCI bridge */ - ret =3D domain_context_mapping_one(domain, drhd->iommu, bus, = devfn); =20 break; =20 --=__Part331EBD1E.1__= Content-Type: text/plain; name="vtd-check-secbus-devfn.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="vtd-check-secbus-devfn.patch" If the device at :00.0 is the device the mapping operation = was=0Ainitiated for, trying to map it a second time will fail, and = hence=0Athis second mapping attempt must be prevented (as was done prior = to=0Asaid c/s).=0A=0AOnce at it, simplify the code a little, too.=0A=0ASign= ed-off-by: Jan Beulich =0A=0A--- a/xen/drivers/passthr= ough/vtd/iommu.c=0A+++ b/xen/drivers/passthrough/vtd/iommu.c=0A@@ -1371,23 = +1371,16 @@ static int domain_context_mapping(struct=0A if ( = find_upstream_bridge(&bus, &devfn, &secbus) < 1 )=0A break;=0A = =0A- /* PCIe to PCI/PCIx bridge */=0A- if ( pdev_type(bus, = devfn) =3D=3D DEV_TYPE_PCIe2PCI_BRIDGE )=0A- {=0A- ret = =3D domain_context_mapping_one(domain, drhd->iommu, bus, devfn);=0A- = if ( ret )=0A- return ret;=0A+ ret =3D = domain_context_mapping_one(domain, drhd->iommu, bus, devfn);=0A =0A- = /*=0A- * Devices behind PCIe-to-PCI/PCIx bridge may = generate=0A- * different requester-id. It may originate from = devfn=3D0=0A- * on the secondary bus behind the bridge. Map = that id=0A- * as well.=0A- */=0A+ /*=0A+ = * Devices behind PCIe-to-PCI/PCIx bridge may generate different=0A+ = * requester-id. It may originate from devfn=3D0 on the secondary = bus=0A+ * behind the bridge. Map that id as well if we didn't = already.=0A+ */=0A+ if ( !ret && pdev_type(bus, devfn) = =3D=3D DEV_TYPE_PCIe2PCI_BRIDGE &&=0A+ (secbus !=3D pdev->bus = || pdev->devfn !=3D 0) )=0A ret =3D domain_context_mapping_one(= domain, drhd->iommu, secbus, 0);=0A- }=0A- else /* Legacy = PCI bridge */=0A- ret =3D domain_context_mapping_one(domain, = drhd->iommu, bus, devfn);=0A =0A break;=0A =0A --=__Part331EBD1E.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__Part331EBD1E.1__=--