Advertisement
Guest User

Untitled

a guest
May 19th, 2018
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.96 KB | None | 0 0
  1. Subject: [PATCH] pci: Enable overrides for missing ACS capabilities (4.14+)
  2.  
  3. This an updated version of Alex Williamson's patch from:
  4. https://lkml.org/lkml/2013/5/30/513
  5.  
  6. Original commit message follows:
  7. ---
  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.  
  17. One upstream device that we particularly care about is the IOMMU. If
  18. a redirection occurs in the topology below the IOMMU, then the IOMMU
  19. cannot provide isolation between devices. This is why the PCIe spec
  20. encourages topologies to include ACS support. Without it, we have to
  21. assume peer-to-peer DMA within a hierarchy can bypass IOMMU isolation.
  22.  
  23. Unfortunately, far too many topologies do not support ACS to make this
  24. a steadfast requirement. Even the latest chipsets from Intel are only
  25. sporadically supporting ACS. We have trouble getting interconnect
  26. vendors to include the PCIe spec required PCIe capability, let alone
  27. suggested features.
  28.  
  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. ---
  45.  
  46. --- a/Documentation/admin-guide/kernel-parameters.txt
  47. +++ b/Documentation/admin-guide/kernel-parameters.txt
  48. @@ -3027,6 +3027,15 @@
  49. pcie_pme= [PCIE,PM] Native PCIe PME signaling options:
  50. nomsi Do not use MSI for native PCIe PME signaling (this makes
  51. all PCIe root ports use INTx for all services).
  52. + pcie_acs_override =
  53. + [PCIE] Override missing PCIe ACS support for:
  54. + downstream
  55. + All downstream ports - full ACS capabilties
  56. + multifunction
  57. + All multifunction devices - multifunction ACS subset
  58. + id:nnnn:nnnn
  59. + Specfic device - full ACS capabilities
  60. + Specified as vid:did (vendor/device ID) in hex
  61.  
  62. pcmv= [HW,PCMCIA] BadgePAD 4
  63.  
  64. --- a/drivers/pci/quirks.c
  65. +++ b/drivers/pci/quirks.c
  66. @@ -3674,6 +3674,112 @@
  67. fs_initcall_sync(pci_apply_final_quirks);
  68.  
  69. /*
  70. + * Enable overrides for missing ACS capabilities
  71. + * https://lkml.org/lkml/2013/5/30/513
  72. + *
  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. +/*
  176. * Following are device-specific reset methods which can be used to
  177. * reset a single function if other methods (e.g. FLR, PM D0->D3) are
  178. * not available.
  179. @@ -4490,6 +4596,7 @@
  180. { PCI_VENDOR_ID_CAVIUM, PCI_ANY_ID, pci_quirk_cavium_acs },
  181. /* APM X-Gene */
  182. { PCI_VENDOR_ID_AMCC, 0xE004, pci_quirk_xgene_acs },
  183. + { PCI_ANY_ID, PCI_ANY_ID, pcie_acs_overrides },
  184. { 0 }
  185. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement