0003-pci-Enable-overrides-for-missing-ACS-capabilities-4..patch 6.8 KB

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