Skip to content

Commit 5213767

Browse files
jpbruckerjoergroedel
authored andcommitted
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. Signed-off-by: Jean-Philippe Brucker <[email protected]> Reviewed-by: Joerg Roedel <[email protected]> Acked-by: Bjorn Helgaas <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 7965919 commit 5213767

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

drivers/pci/ats.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ void pci_ats_init(struct pci_dev *dev)
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)
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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
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) { }

0 commit comments

Comments
 (0)