linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iommu/vt-d: Fix IOMMU lookup for VF's
@ 2016-10-21 22:32 Ashok Raj
  2016-10-30 12:10 ` David Woodhouse
  0 siblings, 1 reply; 2+ messages in thread
From: Ashok Raj @ 2016-10-21 22:32 UTC (permalink / raw)
  To: linux-kernel
  Cc: Ashok Raj, David Woodhouse, Joerg Roedel, Sainath Grandhi, iommu, stable

IOMMU driver must pick the same IOMMU as that of a Physical Function (PF) for
any of its Virtual Functions (VF). It is not practical to list all the VF's
in the DMAR scope, as this list could be quite large. Linux also ignores any
VF's listed in DMAR. See dmar_pci_bus_notifier() for virtfn handling.

Since the driver is looking for the bdf of the VF, it will not find one from
searching the DRHD listed in BIOS.  As a result, the IOMMU driver associates
the VF's under the INCLUDE_ALL iommu incorrectly.

This patch looks up the IOMMU of the PF when handling VF's.

Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: Ashok Raj <ashok.raj@intel.com>
Cc: Sainath Grandhi <sainath.grandhi@intel.com>
Cc: iommu@lists.linux-foundation.org
Cc: stable@vger.kernel.org

Signed-off-by: Sainath Grandhi <sainath.grandhi@intel.com>
Signed-off-by: Ashok Raj <ashok.raj@intel.com>
---
 drivers/iommu/intel-iommu.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index a4407ea..c2e4b5c 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -885,6 +885,7 @@ static struct intel_iommu *device_to_iommu(struct device *dev, u8 *bus, u8 *devf
 	struct intel_iommu *iommu;
 	struct device *tmp;
 	struct pci_dev *ptmp, *pdev = NULL;
+	struct pci_dev *pf_pdev = NULL;
 	u16 segment = 0;
 	int i;
 
@@ -893,6 +894,11 @@ static struct intel_iommu *device_to_iommu(struct device *dev, u8 *bus, u8 *devf
 
 	if (dev_is_pci(dev)) {
 		pdev = to_pci_dev(dev);
+		/*
+		 * Always lookup the PF's IOMMU when handling VF's
+		 */
+		pf_pdev = pci_physfn(pdev);
+		dev = &pf_pdev->dev;
 		segment = pci_domain_nr(pdev->bus);
 	} else if (has_acpi_companion(dev))
 		dev = &ACPI_COMPANION(dev)->dev;
@@ -905,6 +911,9 @@ static struct intel_iommu *device_to_iommu(struct device *dev, u8 *bus, u8 *devf
 		for_each_active_dev_scope(drhd->devices,
 					  drhd->devices_cnt, i, tmp) {
 			if (tmp == dev) {
+				if (pdev->is_virtfn)
+					goto got_pdev;
+
 				*bus = drhd->devices[i].bus;
 				*devfn = drhd->devices[i].devfn;
 				goto out;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] iommu/vt-d: Fix IOMMU lookup for VF's
  2016-10-21 22:32 [PATCH] iommu/vt-d: Fix IOMMU lookup for VF's Ashok Raj
@ 2016-10-30 12:10 ` David Woodhouse
  0 siblings, 0 replies; 2+ messages in thread
From: David Woodhouse @ 2016-10-30 12:10 UTC (permalink / raw)
  To: Ashok Raj, linux-kernel; +Cc: Joerg Roedel, Sainath Grandhi, iommu, stable

[-- Attachment #1: Type: text/plain, Size: 799 bytes --]

On Fri, 2016-10-21 at 15:32 -0700, Ashok Raj wrote:
> IOMMU driver must pick the same IOMMU as that of a Physical Function (PF) for
> any of its Virtual Functions (VF). It is not practical to list all the VF's
> in the DMAR scope, as this list could be quite large. Linux also ignores any
> VF's listed in DMAR. See dmar_pci_bus_notifier() for virtfn handling.
> 
> Since the driver is looking for the bdf of the VF, it will not find one from
> searching the DRHD listed in BIOS.  As a result, the IOMMU driver associates
> the VF's under the INCLUDE_ALL iommu incorrectly.
> 
> This patch looks up the IOMMU of the PF when handling VF's.

I've made some cosmetic fixes — adding comments, and tweaking the
commit comment — and applied this to my tree. Thanks.

-- 
dwmw2



[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 5760 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-10-30 18:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-21 22:32 [PATCH] iommu/vt-d: Fix IOMMU lookup for VF's Ashok Raj
2016-10-30 12:10 ` David Woodhouse

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).