History

PCI/ATS: Only enable ATS for trusted devices

Add pci_ats_supported(), which checks whether a device has an ATS capability, and whether it is trusted. A device is untrusted if it is plugged into an external-facing port such as Thunderbolt and could be spoofing an existing device to exploit weaknesses in the IOMMU configuration. PCIe ATS is one such weaknesses since it allows endpoints to cache IOMMU translations and emit transactions with 'Translated' Address Type (10b) that partially bypass the IOMMU translation. The SMMUv3 and VT-d IOMMU drivers already disallow ATS and transactions with 'Translated' Address Type for untrusted devices. Add the check to pci_enable_ats() to let other drivers (AMD IOMMU for now) benefit from it. By checking ats_cap, the pci_ats_supported() helper also returns whether ATS was globally disabled with pci=noats, and could later include more things, for example whether the whole PCIe hierarchy down to the endpoint supports ATS.

Jean-Philippe Brucker committed 6 years ago

Commit 52137671 parent 79659192 files · +20 −1Browse files

Unified · Split

2 files
  1. drivers/pci/ats.c +17 −1
  2. include/linux/pci-ats.h +3 −0
drivers/pci/ats.c+17−1
@@ -30,6 +30,22 @@ void pci_ats_init(struct pci_dev *dev) · 29 unmodified lines
3030 dev->ats_cap = pos;
3131 }
3232
33+/**
34+ * pci_ats_supported - check if the device can use ATS
35+ * @dev: the PCI device
36+ *
37+ * Returns true if the device supports ATS and is allowed to use it, false
38+ * otherwise.
39+ */
40+bool pci_ats_supported(struct pci_dev *dev)
41+{
42+ if (!dev->ats_cap)
43+ return false;
44+
45+ return (dev->untrusted == 0);
46+}
47+EXPORT_SYMBOL_GPL(pci_ats_supported);
48+
3349 /**
3450 * pci_enable_ats - enable the ATS capability
3551 * @dev: the PCI device
@@ -42,7 +58,7 @@ int pci_enable_ats(struct pci_dev *dev, int ps) · 6 unmodified lines
4258 u16 ctrl;
4359 struct pci_dev *pdev;
4460
45− if (!dev->ats_cap)
61+ if (!pci_ats_supported(dev))
4662 return -EINVAL;
4763
4864 if (WARN_ON(dev->ats_enabled))
include/linux/pci-ats.h+3−0
@@ -6,11 +6,14 @@ · 5 unmodified lines
66
77 #ifdef CONFIG_PCI_ATS
88 /* Address Translation Service */
9+bool pci_ats_supported(struct pci_dev *dev);
910 int pci_enable_ats(struct pci_dev *dev, int ps);
1011 void pci_disable_ats(struct pci_dev *dev);
1112 int pci_ats_queue_depth(struct pci_dev *dev);
1213 int pci_ats_page_aligned(struct pci_dev *dev);
1314 #else /* CONFIG_PCI_ATS */
15+static inline bool pci_ats_supported(struct pci_dev *d)
16+{ return false; }
1417 static inline int pci_enable_ats(struct pci_dev *d, int ps)
1518 { return -ENODEV; }
1619 static inline void pci_disable_ats(struct pci_dev *d) { }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t