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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. From 469fd3d2d05583a20c8210354cf0ad6cbd2360f7 Mon Sep 17 00:00:00 2001
  2. From: Mark Weiman <[email protected]>
  3. Date: Sat, 29 Jul 2017 09:15:32 -0400
  4. Subject: [PATCH 003/242] pci: Enable overrides for missing ACS capabilities
  5. (4.12+)
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. This an updated version of Alex Williamson's patch from:
  10. https://lkml.org/lkml/2013/5/30/513
  11. Original commit message follows:
  12. PCIe ACS (Access Control Services) is the PCIe 2.0+ feature that
  13. allows us to control whether transactions are allowed to be redirected
  14. in various subnodes of a PCIe topology. For instance, if two
  15. endpoints are below a root port or downsteam switch port, the
  16. downstream port may optionally redirect transactions between the
  17. devices, bypassing upstream devices. The same can happen internally
  18. on multifunction devices. The transaction may never be visible to the
  19. upstream devices.
  20. One upstream device that we particularly care about is the IOMMU. If
  21. a redirection occurs in the topology below the IOMMU, then the IOMMU
  22. cannot provide isolation between devices. This is why the PCIe spec
  23. encourages topologies to include ACS support. Without it, we have to
  24. assume peer-to-peer DMA within a hierarchy can bypass IOMMU isolation.
  25. Unfortunately, far too many topologies do not support ACS to make this
  26. a steadfast requirement. Even the latest chipsets from Intel are only
  27. sporadically supporting ACS. We have trouble getting interconnect
  28. vendors to include the PCIe spec required PCIe capability, let alone
  29. suggested features.
  30. Therefore, we need to add some flexibility. The pcie_acs_override=
  31. boot option lets users opt-in specific devices or sets of devices to
  32. assume ACS support. The "downstream" option assumes full ACS support
  33. on root ports and downstream switch ports. The "multifunction"
  34. option assumes the subset of ACS features available on multifunction
  35. endpoints and upstream switch ports are supported. The "id:nnnn:nnnn"
  36. option enables ACS support on devices matching the provided vendor
  37. and device IDs, allowing more strategic ACS overrides. These options
  38. may be combined in any order. A maximum of 16 id specific overrides
  39. are available. It's suggested to use the most limited set of options
  40. necessary to avoid completely disabling ACS across the topology.
  41. Note to hardware vendors, we have facilities to permanently quirk
  42. specific devices which enforce isolation but not provide an ACS
  43. capability. Please contact me to have your devices added and save
  44. your customers the hassle of this boot option.
  45. Signed-off-by: Fabian Grünbichler <[email protected]>
  46. ---
  47. Documentation/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 7441c67d1d8e..73fd6abac39b 100644
  52. --- a/Documentation/admin-guide/kernel-parameters.txt
  53. +++ b/Documentation/admin-guide/kernel-parameters.txt
  54. @@ -2918,6 +2918,15 @@
  55. nomsi [MSI] If the PCI_MSI kernel config parameter is
  56. enabled, this kernel boot option can be used to
  57. disable the use of MSI interrupts system-wide.
  58. + pci_acs_override =
  59. + [PCIE] Override missing PCIe ACS support for:
  60. + downstream
  61. + All downstream ports - full ACS capabilities
  62. + multfunction
  63. + All multifunction devices - multifunction ACS subset
  64. + id:nnnn:nnnn
  65. + Specfic 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 02b009426670..c29d89ffc9b2 100644
  72. --- a/drivers/pci/quirks.c
  73. +++ b/drivers/pci/quirks.c
  74. @@ -3687,6 +3687,107 @@ static int __init pci_apply_final_quirks(void)
  75. fs_initcall_sync(pci_apply_final_quirks);
  76. +static bool acs_on_downstream;
  77. +static bool acs_on_multifunction;
  78. +
  79. +#define NUM_ACS_IDS 16
  80. +struct acs_on_id {
  81. + unsigned short vendor;
  82. + unsigned short device;
  83. +};
  84. +static struct acs_on_id acs_on_ids[NUM_ACS_IDS];
  85. +static u8 max_acs_id;
  86. +
  87. +static __init int pcie_acs_override_setup(char *p)
  88. +{
  89. + if (!p)
  90. + return -EINVAL;
  91. +
  92. + while (*p) {
  93. + if (!strncmp(p, "downstream", 10))
  94. + acs_on_downstream = true;
  95. + if (!strncmp(p, "multifunction", 13))
  96. + acs_on_multifunction = true;
  97. + if (!strncmp(p, "id:", 3)) {
  98. + char opt[5];
  99. + int ret;
  100. + long val;
  101. +
  102. + if (max_acs_id >= NUM_ACS_IDS - 1) {
  103. + pr_warn("Out of PCIe ACS override slots (%d)\n",
  104. + NUM_ACS_IDS);
  105. + goto next;
  106. + }
  107. +
  108. + p += 3;
  109. + snprintf(opt, 5, "%s", p);
  110. + ret = kstrtol(opt, 16, &val);
  111. + if (ret) {
  112. + pr_warn("PCIe ACS ID parse error %d\n", ret);
  113. + goto next;
  114. + }
  115. + acs_on_ids[max_acs_id].vendor = val;
  116. +
  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. * Following are device-specific reset methods which can be used to
  179. * reset a single function if other methods (e.g. FLR, PM D0->D3) are
  180. @@ -4514,6 +4615,7 @@ static const struct pci_dev_acs_enabled {
  181. { 0x10df, 0x720, pci_quirk_mf_endpoint_acs }, /* Emulex Skyhawk-R */
  182. /* Cavium ThunderX */
  183. { PCI_VENDOR_ID_CAVIUM, PCI_ANY_ID, pci_quirk_cavium_acs },
  184. + { PCI_ANY_ID, PCI_ANY_ID, pcie_acs_overrides },
  185. { 0 }
  186. };
  187. --
  188. 2.14.2