]> git.proxmox.com Git - pve-kernel.git/blame - patches/kernel/0003-pci-Enable-overrides-for-missing-ACS-capabilities-4..patch
rebase patches on top of Ubuntu-4.13.0-43.48
[pve-kernel.git] / patches / kernel / 0003-pci-Enable-overrides-for-missing-ACS-capabilities-4..patch
CommitLineData
59d5af67 1From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
ba2f1a67 2From: Mark Weiman <mark.weiman@markzz.com>
754ba827 3Date: Sat, 29 Jul 2017 09:15:32 -0400
59d5af67 4Subject: [PATCH] pci: Enable overrides for missing ACS capabilities (4.12+)
b9e76370
FG
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
ba2f1a67
FG
8
9This an updated version of Alex Williamson's patch from:
10https://lkml.org/lkml/2013/5/30/513
11
12Original commit message follows:
ba2f1a67
FG
13PCIe ACS (Access Control Services) is the PCIe 2.0+ feature that
14allows us to control whether transactions are allowed to be redirected
15in various subnodes of a PCIe topology. For instance, if two
16endpoints are below a root port or downsteam switch port, the
17downstream port may optionally redirect transactions between the
18devices, bypassing upstream devices. The same can happen internally
19on multifunction devices. The transaction may never be visible to the
20upstream devices.
21
22One upstream device that we particularly care about is the IOMMU. If
23a redirection occurs in the topology below the IOMMU, then the IOMMU
24cannot provide isolation between devices. This is why the PCIe spec
25encourages topologies to include ACS support. Without it, we have to
26assume peer-to-peer DMA within a hierarchy can bypass IOMMU isolation.
27
28Unfortunately, far too many topologies do not support ACS to make this
29a steadfast requirement. Even the latest chipsets from Intel are only
30sporadically supporting ACS. We have trouble getting interconnect
31vendors to include the PCIe spec required PCIe capability, let alone
32suggested features.
33
34Therefore, we need to add some flexibility. The pcie_acs_override=
35boot option lets users opt-in specific devices or sets of devices to
36assume ACS support. The "downstream" option assumes full ACS support
37on root ports and downstream switch ports. The "multifunction"
38option assumes the subset of ACS features available on multifunction
39endpoints and upstream switch ports are supported. The "id:nnnn:nnnn"
40option enables ACS support on devices matching the provided vendor
41and device IDs, allowing more strategic ACS overrides. These options
42may be combined in any order. A maximum of 16 id specific overrides
43are available. It's suggested to use the most limited set of options
44necessary to avoid completely disabling ACS across the topology.
45Note to hardware vendors, we have facilities to permanently quirk
46specific devices which enforce isolation but not provide an ACS
47capability. Please contact me to have your devices added and save
48your customers the hassle of this boot option.
b9e76370
FG
49
50Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
ba2f1a67 51---
754ba827
FG
52 Documentation/admin-guide/kernel-parameters.txt | 9 +++
53 drivers/pci/quirks.c | 102 ++++++++++++++++++++++++
54 2 files changed, 111 insertions(+)
ba2f1a67
FG
55
56diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
1f1e1833 57index ce24cb1e8f46..0cc1d4200c24 100644
ba2f1a67
FG
58--- a/Documentation/admin-guide/kernel-parameters.txt
59+++ b/Documentation/admin-guide/kernel-parameters.txt
1f1e1833 60@@ -2938,6 +2938,15 @@
ba2f1a67
FG
61 nomsi [MSI] If the PCI_MSI kernel config parameter is
62 enabled, this kernel boot option can be used to
63 disable the use of MSI interrupts system-wide.
64+ pci_acs_override =
65+ [PCIE] Override missing PCIe ACS support for:
66+ downstream
67+ All downstream ports - full ACS capabilities
68+ multfunction
69+ All multifunction devices - multifunction ACS subset
70+ id:nnnn:nnnn
71+ Specfic device - full ACS capabilities
72+ Specified as vid:did (vendor/device ID) in hex
73 noioapicquirk [APIC] Disable all boot interrupt quirks.
74 Safety option to keep boot IRQs enabled. This
75 should never be necessary.
76diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
3adc5321 77index 99eec22d99b7..7576c2b0c913 100644
ba2f1a67
FG
78--- a/drivers/pci/quirks.c
79+++ b/drivers/pci/quirks.c
b9e76370 80@@ -3687,6 +3687,107 @@ static int __init pci_apply_final_quirks(void)
ba2f1a67
FG
81
82 fs_initcall_sync(pci_apply_final_quirks);
83
84+static bool acs_on_downstream;
85+static bool acs_on_multifunction;
86+
87+#define NUM_ACS_IDS 16
88+struct acs_on_id {
89+ unsigned short vendor;
90+ unsigned short device;
91+};
92+static struct acs_on_id acs_on_ids[NUM_ACS_IDS];
93+static u8 max_acs_id;
94+
95+static __init int pcie_acs_override_setup(char *p)
96+{
97+ if (!p)
98+ return -EINVAL;
99+
100+ while (*p) {
101+ if (!strncmp(p, "downstream", 10))
102+ acs_on_downstream = true;
103+ if (!strncmp(p, "multifunction", 13))
104+ acs_on_multifunction = true;
105+ if (!strncmp(p, "id:", 3)) {
106+ char opt[5];
107+ int ret;
108+ long val;
109+
110+ if (max_acs_id >= NUM_ACS_IDS - 1) {
111+ pr_warn("Out of PCIe ACS override slots (%d)\n",
112+ NUM_ACS_IDS);
113+ goto next;
114+ }
115+
116+ p += 3;
117+ snprintf(opt, 5, "%s", p);
118+ ret = kstrtol(opt, 16, &val);
119+ if (ret) {
120+ pr_warn("PCIe ACS ID parse error %d\n", ret);
121+ goto next;
122+ }
123+ acs_on_ids[max_acs_id].vendor = val;
124+
125+ p += strcspn(p, ":");
cfe8ba0b 126+ if (*p != ':') {
ba2f1a67
FG
127+ pr_warn("PCIe ACS invalid ID\n");
128+ goto next;
129+ }
130+
131+ p++;
132+ snprintf(opt, 5, "%s", p);
133+ ret = kstrtol(opt, 16, &val);
134+ if (ret) {
135+ pr_warn("PCIe ACS ID parse error %d\n", ret);
136+ goto next;
137+ }
138+ acs_on_ids[max_acs_id].device = val;
139+ max_acs_id++;
140+ }
141+next:
142+ p += strcspn(p, ",");
143+ if (*p == ',')
144+ p++;
145+ }
146+
147+ if (acs_on_downstream || acs_on_multifunction || max_acs_id)
148+ pr_warn("Warning: PCIe ACS overrides enabled; This may allow non-IOMMU protected peer-to-peer DMA\n");
149+
150+ return 0;
151+}
152+early_param("pcie_acs_override", pcie_acs_override_setup);
153+
154+static int pcie_acs_overrides(struct pci_dev *dev, u16 acs_flags)
155+{
156+ int i;
157+
158+ /* Never override ACS for legacy devices or devices with ACS caps */
159+ if (!pci_is_pcie(dev) ||
160+ pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ACS))
161+ return -ENOTTY;
162+
163+ for (i = 0; i < max_acs_id; i++)
164+ if (acs_on_ids[i].vendor == dev->vendor &&
165+ acs_on_ids[i].device == dev->device)
166+ return 1;
167+
168+ switch (pci_pcie_type(dev)) {
169+ case PCI_EXP_TYPE_DOWNSTREAM:
170+ case PCI_EXP_TYPE_ROOT_PORT:
171+ if (acs_on_downstream)
172+ return 1;
173+ break;
174+ case PCI_EXP_TYPE_ENDPOINT:
175+ case PCI_EXP_TYPE_UPSTREAM:
176+ case PCI_EXP_TYPE_LEG_END:
177+ case PCI_EXP_TYPE_RC_END:
178+ if (acs_on_multifunction && dev->multifunction)
179+ return 1;
180+ }
181+
182+ return -ENOTTY;
183+}
754ba827 184+
ba2f1a67 185 /*
754ba827 186 * Following are device-specific reset methods which can be used to
ba2f1a67 187 * reset a single function if other methods (e.g. FLR, PM D0->D3) are
3adc5321 188@@ -4529,6 +4630,7 @@ static const struct pci_dev_acs_enabled {
ba2f1a67
FG
189 { 0x10df, 0x720, pci_quirk_mf_endpoint_acs }, /* Emulex Skyhawk-R */
190 /* Cavium ThunderX */
191 { PCI_VENDOR_ID_CAVIUM, PCI_ANY_ID, pci_quirk_cavium_acs },
192+ { PCI_ANY_ID, PCI_ANY_ID, pcie_acs_overrides },
193 { 0 }
194 };
195
196--
777ee9fe 1972.14.2
ba2f1a67 198