]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.4.36/iommu-vt-d-fix-iommu-lookup-for-sr-iov-virtual-functions.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.4.36 / iommu-vt-d-fix-iommu-lookup-for-sr-iov-virtual-functions.patch
CommitLineData
9c6fd700
GKH
1From 1c387188c60f53b338c20eee32db055dfe022a9b Mon Sep 17 00:00:00 2001
2From: Ashok Raj <ashok.raj@intel.com>
3Date: Fri, 21 Oct 2016 15:32:05 -0700
4Subject: iommu/vt-d: Fix IOMMU lookup for SR-IOV Virtual Functions
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9From: Ashok Raj <ashok.raj@intel.com>
10
11commit 1c387188c60f53b338c20eee32db055dfe022a9b upstream.
12
13The VT-d specification (§8.3.3) says:
14 ‘Virtual Functions’ of a ‘Physical Function’ are under the scope
15 of the same remapping unit as the ‘Physical Function’.
16
17The BIOS is not required to list all the possible VFs in the scope
18tables, and arguably *shouldn't* make any attempt to do so, since there
19could be a huge number of them.
20
21This has been broken basically for ever — the VF is never going to match
22against a specific unit's scope, so it ends up being assigned to the
23INCLUDE_ALL IOMMU. Which was always actually correct by coincidence, but
24now we're looking at Root-Complex integrated devices with SR-IOV support
25it's going to start being wrong.
26
27Fix it to simply use pci_physfn() before doing the lookup for PCI devices.
28
29Signed-off-by: Sainath Grandhi <sainath.grandhi@intel.com>
30Signed-off-by: Ashok Raj <ashok.raj@intel.com>
31Signed-off-by: David Woodhouse <dwmw2@infradead.org>
32Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
33
34---
35 drivers/iommu/dmar.c | 4 +++-
36 drivers/iommu/intel-iommu.c | 13 +++++++++++++
37 2 files changed, 16 insertions(+), 1 deletion(-)
38
39--- a/drivers/iommu/dmar.c
40+++ b/drivers/iommu/dmar.c
41@@ -326,7 +326,9 @@ static int dmar_pci_bus_notifier(struct
42 struct pci_dev *pdev = to_pci_dev(data);
43 struct dmar_pci_notify_info *info;
44
45- /* Only care about add/remove events for physical functions */
46+ /* Only care about add/remove events for physical functions.
47+ * For VFs we actually do the lookup based on the corresponding
48+ * PF in device_to_iommu() anyway. */
49 if (pdev->is_virtfn)
50 return NOTIFY_DONE;
51 if (action != BUS_NOTIFY_ADD_DEVICE &&
52--- a/drivers/iommu/intel-iommu.c
53+++ b/drivers/iommu/intel-iommu.c
54@@ -885,7 +885,13 @@ static struct intel_iommu *device_to_iom
55 return NULL;
56
57 if (dev_is_pci(dev)) {
58+ struct pci_dev *pf_pdev;
59+
60 pdev = to_pci_dev(dev);
61+ /* VFs aren't listed in scope tables; we need to look up
62+ * the PF instead to find the IOMMU. */
63+ pf_pdev = pci_physfn(pdev);
64+ dev = &pf_pdev->dev;
65 segment = pci_domain_nr(pdev->bus);
66 } else if (has_acpi_companion(dev))
67 dev = &ACPI_COMPANION(dev)->dev;
68@@ -898,6 +904,13 @@ static struct intel_iommu *device_to_iom
69 for_each_active_dev_scope(drhd->devices,
70 drhd->devices_cnt, i, tmp) {
71 if (tmp == dev) {
72+ /* For a VF use its original BDF# not that of the PF
73+ * which we used for the IOMMU lookup. Strictly speaking
74+ * we could do this for all PCI devices; we only need to
75+ * get the BDF# from the scope table for ACPI matches. */
76+ if (pdev->is_virtfn)
77+ goto got_pdev;
78+
79 *bus = drhd->devices[i].bus;
80 *devfn = drhd->devices[i].devfn;
81 goto out;