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

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