Skip to content

PCI: mark devices below a DT external-facing port untrusted and removable - #2992

Draft
Alyx-ML wants to merge 1 commit into
aurora-silicon:mainfrom
Alyx-ML:aurora/pci-external-facing
Draft

Alyx-ML wants to merge 1 commit into
aurora-silicon:mainfrom
Alyx-ML:aurora/pci-external-facing

Conversation

@Alyx-ML

@Alyx-ML Alyx-ML commented Nov 23, 2026

Copy link
Copy Markdown

Part of the #2755 split, as its own PCI-core patch. Draft: it needs dock numbers.

Summary

 set_pcie_untrusted() / pci_set_removable()
   parent->external_facing via arch_pci_dev_is_removable()   # ACPI only; a stub on arm64
+  || (parent is external_facing && parent has an of_node)   # DT "external-facing"

The PCI core then gives tunnelled devices strict DMA domains, swiotlb bouncing for sub-granule
buffers, and no ATS. On ACPI systems nothing changes. t6040-usb4.dtsi already has its tunnel
nodes with external-facing (the #2755 text said they arrived with #2069; that was wrong).

Evidence

  • Before: no device behind an Apple PCIe-C root port was marked untrusted. A host harness on a
    modelled DT topology marks nothing.
  • After: the harness marks both functions below the port, and not the port itself, an internal
    Wi-Fi function, or an ACPI-style flag without a DT node. A script finds external-facing on
    every enabled PCIe-C root port in all 138 Apple trees. Build: passed, Apple build and KUnit.
  • Needed before merging: dock NVMe and NIC throughput, before and after, on one M1 or M2 and
    one M4 Pro.

Merge Danger

Door: two-way

Blast Radius: USB4/Thunderbolt devices

Every tunnelled PCIe device on every USB4 Mac gets strict IOMMU handling. The cost is the open
question.

Assisted-by: LLM (Claude:Opus 5.5)

…able

The device tree binding says a port marked "external-facing" leads out
of the machine, and drivers/pci/of.c sets external_facing on such a
port. Since commit 3b96b89 ("PCI: Detect and trust built-in
Thunderbolt chips") the PCI core reads that flag only through
arch_pci_dev_is_removable(), which exists for x86 with ACPI. On arm64 it
is a stub that returns false, so no device behind an Apple PCIe-C (USB4
tunnel) root port was ever marked untrusted or removable. Every such
root port in the Apple device trees has external-facing.

Because of that, a device plugged into a Thunderbolt or USB4 port got
the same IOMMU treatment as internal hardware: whatever default domain
the command line or Kconfig chose (identity with iommu.passthrough=1),
lazy TLB flushing, and no bounce buffering of sub-page buffers. On
T6050, whose PCIe-C DART is not read as a tunnel DART, the DART driver
did not force translation either.

Mark a device untrusted and removable when its upstream bridge is
external-facing and the flag came from the device tree (the bridge has
an of_node). Deeper devices inherit it, as before. The port itself stays
internal, as it has been since commit 99b50be ("PCI: Treat
"external-facing" devices themselves as internal"). ACPI systems are
unchanged: their external_facing still goes through
arch_pci_dev_is_removable().

With the mark in place the IOMMU core forces a strict DMA domain for
these devices, refuses a driver that asks for identity, disables ATS,
and dma-iommu bounces buffers that do not fill whole IOVA pages through
swiotlb.

Verified with a host harness that runs the patched set_pcie_untrusted() and
pci_set_removable() on a modelled DT topology (external-facing root port,
dock bridge, endpoint): both functions below the port are marked, the port
and an internal Wi-Fi function are not, and an ACPI-style external_facing
without a DT node is left alone. The unpatched code marks nothing. A script
that mirrors the device tree checks found external-facing on every enabled
PCIe-C root port in all 138 Apple board trees (80 tunnel references). The
kernel was not built here and no hardware was used.

Expected cost: strict TLB invalidation, and bounce copies for small,
unaligned buffers of tunnelled devices (16 KiB IOVA granule). Dock
throughput (network and NVMe) on M1, M2 and M4 Pro, before and after,
is needed before this is merged.

Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant