]>
Commit | Line | Data |
---|---|---|
59d5af67 | 1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
ba2f1a67 | 2 | From: Mark Weiman <mark.weiman@markzz.com> |
55f9bfa9 FG |
3 | Date: Wed, 7 Feb 2018 16:04:03 -0500 |
4 | Subject: [PATCH] pci: Enable overrides for missing ACS capabilities (4.15) | |
b9e76370 FG |
5 | MIME-Version: 1.0 |
6 | Content-Type: text/plain; charset=UTF-8 | |
7 | Content-Transfer-Encoding: 8bit | |
ba2f1a67 FG |
8 | |
9 | This an updated version of Alex Williamson's patch from: | |
10 | https://lkml.org/lkml/2013/5/30/513 | |
11 | ||
12 | Original commit message follows: | |
ba2f1a67 FG |
13 | PCIe ACS (Access Control Services) is the PCIe 2.0+ feature that |
14 | allows us to control whether transactions are allowed to be redirected | |
15 | in various subnodes of a PCIe topology. For instance, if two | |
16 | endpoints are below a root port or downsteam switch port, the | |
17 | downstream port may optionally redirect transactions between the | |
18 | devices, bypassing upstream devices. The same can happen internally | |
19 | on multifunction devices. The transaction may never be visible to the | |
20 | upstream devices. | |
21 | ||
22 | One upstream device that we particularly care about is the IOMMU. If | |
23 | a redirection occurs in the topology below the IOMMU, then the IOMMU | |
24 | cannot provide isolation between devices. This is why the PCIe spec | |
25 | encourages topologies to include ACS support. Without it, we have to | |
26 | assume peer-to-peer DMA within a hierarchy can bypass IOMMU isolation. | |
27 | ||
28 | Unfortunately, far too many topologies do not support ACS to make this | |
29 | a steadfast requirement. Even the latest chipsets from Intel are only | |
30 | sporadically supporting ACS. We have trouble getting interconnect | |
31 | vendors to include the PCIe spec required PCIe capability, let alone | |
32 | suggested features. | |
33 | ||
34 | Therefore, we need to add some flexibility. The pcie_acs_override= | |
35 | boot option lets users opt-in specific devices or sets of devices to | |
36 | assume ACS support. The "downstream" option assumes full ACS support | |
37 | on root ports and downstream switch ports. The "multifunction" | |
38 | option assumes the subset of ACS features available on multifunction | |
39 | endpoints and upstream switch ports are supported. The "id:nnnn:nnnn" | |
40 | option enables ACS support on devices matching the provided vendor | |
41 | and device IDs, allowing more strategic ACS overrides. These options | |
42 | may be combined in any order. A maximum of 16 id specific overrides | |
43 | are available. It's suggested to use the most limited set of options | |
44 | necessary to avoid completely disabling ACS across the topology. | |
45 | Note to hardware vendors, we have facilities to permanently quirk | |
46 | specific devices which enforce isolation but not provide an ACS | |
47 | capability. Please contact me to have your devices added and save | |
48 | your customers the hassle of this boot option. | |
b9e76370 FG |
49 | |
50 | Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com> | |
ba2f1a67 | 51 | --- |
754ba827 | 52 | Documentation/admin-guide/kernel-parameters.txt | 9 +++ |
55f9bfa9 FG |
53 | drivers/pci/quirks.c | 101 ++++++++++++++++++++++++ |
54 | 2 files changed, 110 insertions(+) | |
ba2f1a67 FG |
55 | |
56 | diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt | |
e4087db3 | 57 | index c14cccce6272..b3aa6fcfe035 100644 |
ba2f1a67 FG |
58 | --- a/Documentation/admin-guide/kernel-parameters.txt |
59 | +++ b/Documentation/admin-guide/kernel-parameters.txt | |
e4087db3 | 60 | @@ -2971,6 +2971,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 | |
55f9bfa9 FG |
68 | + multifunction |
69 | + Add multifunction devices - multifunction ACS subset | |
ba2f1a67 | 70 | + id:nnnn:nnnn |
55f9bfa9 | 71 | + Specific device - full ACS capabilities |
ba2f1a67 FG |
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. | |
76 | diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c | |
c0514fa3 | 77 | index 26b3ed731208..d66c874a7a6e 100644 |
ba2f1a67 FG |
78 | --- a/drivers/pci/quirks.c |
79 | +++ b/drivers/pci/quirks.c | |
ecef40a2 | 80 | @@ -3702,6 +3702,106 @@ 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; | |
ba2f1a67 | 124 | + p += strcspn(p, ":"); |
cfe8ba0b | 125 | + if (*p != ':') { |
ba2f1a67 FG |
126 | + pr_warn("PCIe ACS invalid ID\n"); |
127 | + goto next; | |
128 | + } | |
129 | + | |
130 | + p++; | |
131 | + snprintf(opt, 5, "%s", p); | |
132 | + ret = kstrtol(opt, 16, &val); | |
133 | + if (ret) { | |
134 | + pr_warn("PCIe ACS ID parse error %d\n", ret); | |
135 | + goto next; | |
136 | + } | |
137 | + acs_on_ids[max_acs_id].device = val; | |
138 | + max_acs_id++; | |
139 | + } | |
140 | +next: | |
141 | + p += strcspn(p, ","); | |
142 | + if (*p == ',') | |
143 | + p++; | |
144 | + } | |
145 | + | |
146 | + if (acs_on_downstream || acs_on_multifunction || max_acs_id) | |
147 | + pr_warn("Warning: PCIe ACS overrides enabled; This may allow non-IOMMU protected peer-to-peer DMA\n"); | |
148 | + | |
149 | + return 0; | |
150 | +} | |
151 | +early_param("pcie_acs_override", pcie_acs_override_setup); | |
152 | + | |
153 | +static int pcie_acs_overrides(struct pci_dev *dev, u16 acs_flags) | |
154 | +{ | |
155 | + int i; | |
156 | + | |
157 | + /* Never override ACS for legacy devices or devices with ACS caps */ | |
158 | + if (!pci_is_pcie(dev) || | |
159 | + pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ACS)) | |
160 | + return -ENOTTY; | |
161 | + | |
162 | + for (i = 0; i < max_acs_id; i++) | |
163 | + if (acs_on_ids[i].vendor == dev->vendor && | |
164 | + acs_on_ids[i].device == dev->device) | |
165 | + return 1; | |
166 | + | |
167 | + switch (pci_pcie_type(dev)) { | |
55f9bfa9 FG |
168 | + case PCI_EXP_TYPE_DOWNSTREAM: |
169 | + case PCI_EXP_TYPE_ROOT_PORT: | |
170 | + if (acs_on_downstream) | |
171 | + return 1; | |
172 | + break; | |
173 | + case PCI_EXP_TYPE_ENDPOINT: | |
174 | + case PCI_EXP_TYPE_UPSTREAM: | |
175 | + case PCI_EXP_TYPE_LEG_END: | |
176 | + case PCI_EXP_TYPE_RC_END: | |
177 | + if (acs_on_multifunction && dev->multifunction) | |
178 | + return 1; | |
ba2f1a67 FG |
179 | + } |
180 | + | |
181 | + return -ENOTTY; | |
182 | +} | |
754ba827 | 183 | + |
ba2f1a67 | 184 | /* |
754ba827 | 185 | * Following are device-specific reset methods which can be used to |
ba2f1a67 | 186 | * reset a single function if other methods (e.g. FLR, PM D0->D3) are |
c0514fa3 | 187 | @@ -4538,6 +4638,7 @@ static const struct pci_dev_acs_enabled { |
ba2f1a67 | 188 | { PCI_VENDOR_ID_CAVIUM, PCI_ANY_ID, pci_quirk_cavium_acs }, |
55f9bfa9 FG |
189 | /* APM X-Gene */ |
190 | { PCI_VENDOR_ID_AMCC, 0xE004, pci_quirk_xgene_acs }, | |
ba2f1a67 FG |
191 | + { PCI_ANY_ID, PCI_ANY_ID, pcie_acs_overrides }, |
192 | { 0 } | |
193 | }; | |
194 |