From 027c9476464dc3f1a70b91501e94925df427d3a8 Mon Sep 17 00:00:00 2001 From: Dj <43033058+DjDeveloperr@users.noreply.github.com> Date: Thu, 26 Nov 2026 02:39:20 -0500 Subject: [PATCH] PCI: Mark devices below a device tree external-facing port untrusted The device tree binding defines "external-facing" on a port as: every bridge and endpoint downstream of it is external to the machine. pci_set_bus_of_node() still sets external_facing on such a port, but since commit 3b96b895127b ("PCI: Detect and trust built-in Thunderbolt chips") only arch_pci_dev_is_removable() marks the devices below it untrusted or removable, and that is implemented for x86 with ACPI only. On device tree systems, devices tunneled through a USB4 or Thunderbolt port are therefore treated as built in: iommu-dma maps their buffers in place instead of bouncing the unaligned ones, so with 16K IOMMU pages a device can reach the rest of each page around its buffers, and ATS stays allowed. Mark the devices directly below a port that the device tree marks external-facing untrusted and removable again, as before that commit. The ACPI exception for a built-in discrete controller below an ExternalFacingPort does not apply: the binding leaves no room for one. Fixes: 3b96b895127b ("PCI: Detect and trust built-in Thunderbolt chips") Signed-off-by: Dj <43033058+DjDeveloperr@users.noreply.github.com> --- drivers/pci/probe.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index c38a60df06d81..d1bd1670841c9 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -1735,6 +1736,20 @@ static void set_pcie_cxl(struct pci_dev *dev) } +/* + * Every bridge and endpoint below a port that the device tree marks + * "external-facing" is external to the machine, as the binding defines it. + * Unlike an ACPI ExternalFacingPort (see arch_pci_dev_is_removable()), no + * built-in controller sits below such a port. + */ +static bool pci_dev_below_of_external_port(struct pci_dev *dev) +{ + struct pci_dev *parent = pci_upstream_bridge(dev); + + return parent && parent->external_facing && + of_property_read_bool(parent->dev.of_node, "external-facing"); +} + static void set_pcie_untrusted(struct pci_dev *dev) { struct pci_dev *parent = pci_upstream_bridge(dev); @@ -1750,7 +1765,7 @@ static void set_pcie_untrusted(struct pci_dev *dev) return; } - if (arch_pci_dev_is_removable(dev)) { + if (arch_pci_dev_is_removable(dev) || pci_dev_below_of_external_port(dev)) { pci_dbg(dev, "marking as untrusted\n"); dev->untrusted = true; } @@ -1778,7 +1793,7 @@ static void pci_set_removable(struct pci_dev *dev) return; } - if (arch_pci_dev_is_removable(dev)) { + if (arch_pci_dev_is_removable(dev) || pci_dev_below_of_external_port(dev)) { pci_dbg(dev, "marking as removable\n"); dev_set_removable(&dev->dev, DEVICE_REMOVABLE); }