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