Advertisement
Guest User

ACS fc27 4.15.0

a guest
Feb 1st, 2018
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. From wendell Fri Mar 10 15:23:02 2017
  2. Content-Type: text/plain; charset="utf-8"
  3. MIME-Version: 1.0
  4. Content-Transfer-Encoding: 7bit
  5. Subject: [PATCH] ACS-patch
  6. From: level1techs <queries@level1techs.com>
  7. Date: Fri, 10 Mar 2017 18:22:12 +0300
  8.  
  9. This is imperfect and no one should use this. I was able to apply this on
  10. fedora 25/26 kernels "the fedora way" by copying it into the kernel
  11. dir and doing
  12. ## scripts/newpatch.sh acs.patch
  13. then
  14. # fedpkg local
  15.  
  16. It masks (but not fixes) the iommu groups. you will need to add
  17. a line to your /etc/default/grub kernel line something like
  18. pcie_acs_override=downstream pci-stub.ids="1003:1f1f,1003:1f1c"
  19.  
  20. where the pci-stub.ids are the PCIe IDs you intend to pass through to
  21. your virtual machine.
  22.  
  23. Fixed for fc27 4.15.0 by Dryparn
  24. ---
  25.  
  26. --- a/drivers/pci/quirks.c 2018-02-01 22:56:44.044737101 +0100
  27. +++ b/drivers/pci/quirks.c 2018-02-01 23:00:37.598646953 +0100
  28. @@ -3394,6 +3394,108 @@
  29. DECLARE_PCI_FIXUP_CLASS_HEADER(PCI_VENDOR_ID_ATI, PCI_ANY_ID,
  30. PCI_CLASS_DISPLAY_VGA, 8, quirk_no_pm_reset);
  31.  
  32. +static bool acs_on_downstream;
  33. +static bool acs_on_multifunction;
  34. +
  35. +#define NUM_ACS_IDS 16
  36. +struct acs_on_id {
  37. + unsigned short vendor;
  38. + unsigned short device;
  39. +};
  40. +static struct acs_on_id acs_on_ids[NUM_ACS_IDS];
  41. +static u8 max_acs_id;
  42. +
  43. +static __init int pcie_acs_override_setup(char *p)
  44. +{
  45. + if (!p)
  46. + return -EINVAL;
  47. +
  48. + while (*p) {
  49. + if (!strncmp(p, "downstream", 10))
  50. + acs_on_downstream = true;
  51. + if (!strncmp(p, "multifunction", 13))
  52. + acs_on_multifunction = true;
  53. + if (!strncmp(p, "id:", 3)) {
  54. + char opt[5];
  55. + int ret;
  56. + long val;
  57. +
  58. + if (max_acs_id >= NUM_ACS_IDS - 1) {
  59. + pr_warn("Out of PCIe ACS override slots (%d)\n",
  60. + NUM_ACS_IDS);
  61. + goto next;
  62. + }
  63. +
  64. + p += 3;
  65. + snprintf(opt, 5, "%s", p);
  66. + ret = kstrtol(opt, 16, &val);
  67. + if (ret) {
  68. + pr_warn("PCIe ACS ID parse error %d\n", ret);
  69. + goto next;
  70. + }
  71. + acs_on_ids[max_acs_id].vendor = val;
  72. +
  73. + p += strcspn(p, ":");
  74. + if (*p != ':') {
  75. + pr_warn("PCIe ACS invalid ID\n");
  76. + goto next;
  77. + }
  78. +
  79. + p++;
  80. + snprintf(opt, 5, "%s", p);
  81. + ret = kstrtol(opt, 16, &val);
  82. + if (ret) {
  83. + pr_warn("PCIe ACS ID parse error %d\n", ret);
  84. + goto next;
  85. + }
  86. + acs_on_ids[max_acs_id].device = val;
  87. + max_acs_id++;
  88. + }
  89. +next:
  90. + p += strcspn(p, ",");
  91. + if (*p == ',')
  92. + p++;
  93. + }
  94. +
  95. + if (acs_on_downstream || acs_on_multifunction || max_acs_id)
  96. + pr_warn("Warning: PCIe ACS overrides enabled; This may allow non-IOMMU protected peer-to-peer DMA\n");
  97. +
  98. + return 0;
  99. +}
  100. +early_param("pcie_acs_override", pcie_acs_override_setup);
  101. +
  102. +static int pcie_acs_overrides(struct pci_dev *dev, u16 acs_flags)
  103. +{
  104. + int i;
  105. +
  106. + /* Never override ACS for legacy devices or devices with ACS caps */
  107. + if (!pci_is_pcie(dev) ||
  108. + pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ACS))
  109. + return -ENOTTY;
  110. +
  111. + for (i = 0; i < max_acs_id; i++)
  112. + if (acs_on_ids[i].vendor == dev->vendor &&
  113. + acs_on_ids[i].device == dev->device)
  114. + return 1;
  115. +
  116. + switch (pci_pcie_type(dev)) {
  117. + case PCI_EXP_TYPE_DOWNSTREAM:
  118. + case PCI_EXP_TYPE_ROOT_PORT:
  119. + if (acs_on_downstream)
  120. + return 1;
  121. + break;
  122. + case PCI_EXP_TYPE_ENDPOINT:
  123. + case PCI_EXP_TYPE_UPSTREAM:
  124. + case PCI_EXP_TYPE_LEG_END:
  125. + case PCI_EXP_TYPE_RC_END:
  126. + if (acs_on_multifunction && dev->multifunction)
  127. + return 1;
  128. + }
  129. +
  130. + return -ENOTTY;
  131. +}
  132. +
  133. +
  134. /*
  135. * Thunderbolt controllers with broken MSI hotplug signaling:
  136. * Entire 1st generation (Light Ridge, Eagle Ridge, Light Peak) and part
  137. @@ -4512,6 +4614,7 @@
  138. { PCI_VENDOR_ID_CAVIUM, PCI_ANY_ID, pci_quirk_cavium_acs },
  139. /* APM X-Gene */
  140. { PCI_VENDOR_ID_AMCC, 0xE004, pci_quirk_xgene_acs },
  141. + { PCI_ANY_ID, PCI_ANY_ID, pcie_acs_overrides },
  142. { 0 }
  143. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement