Repository navigation
PCI: mark devices below a device tree external-facing port untrusted - #3213
Conversation
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 3b96b89 ("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: 3b96b89 ("PCI: Detect and trust built-in Thunderbolt chips") Signed-off-by: Dj <[email protected]>
|
Merge readiness at
Areas: none matched in CODEOWNERS Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
Verdict at Blockers: none Checked
Runtime impact on docks (for the rows)
Evidence
|
|
J773g (M4 Mac mini) at How it was run: two guarded one-shots on the default cmdline, the same day on the same Mac. Both returned to the stock kernel afterwards, and the kits were removed from the Mac.
No USB4/Thunderbolt device is attached to this Mac, so this is a smoke check: no new kernel lines, PCIe and Wi-Fi unaffected, and one s2idle cycle survived. It doesn't exercise a dock.
The only extra err-level kernel lines on the candidate are the scaler module A/B's two job timeouts (#3217). They aren't TB/PCI lines. |
|
J714s (MacBook Pro 14" M5 Pro, T6050) row at
|
RyanTheTide
left a comment
There was a problem hiding this comment.
Verdict at 027c9476: approve (code). Merge after the hardware rows the body lists.
Blockers: none in the code.
Checked
- Devices below a bridge that is
external_facingand whose DT node hasexternal-facingare marked untrusted and removable. That matches the binding: nothing built in sits below such a port. - The ACPI path is unchanged, and the change is keyed on the DT property, with no chip gates.
Note: this turns on strict IOMMU and bounce buffering for USB4 tunnel devices. The rows should cover a USB4 dock's PCIe devices (Ethernet throughput, NVMe enclosure) working, plus one built-in PCIe device that must stay trusted (the Wi-Fi), on one Mac per USB4 generation.
|
This merged through auto-merge on my code approval, which I had written as "merge after the hardware rows the body lists". I've reverted it in #3351 so no fleet cut picks up an untested change to how USB4-tunnelled devices are trusted. Please reland it as is, with the dock row (tunnelled Ethernet and NVMe working, throughput noted, the built-in Wi-Fi still trusted) on one Mac per USB4 generation. The code review stands. Sorry for the churn. |
…trusted" This reverts merge c9f9324 (aurora-silicon#3213). It merged on an approval before the hardware rows its description lists as owed. It marks every device behind a USB4/Thunderbolt PCIe tunnel untrusted and removable on every Apple Silicon Mac, which turns on strict IOMMU handling and bounce buffering for them, and that has not run on a Mac yet. Reland it once a USB4 dock's PCIe devices (Ethernet, NVMe) and the built-in Wi-Fi have been checked on one Mac per USB4 generation. Signed-off-by: Ryan Murray <[email protected]>
What: On device tree systems, PCIe devices tunneled behind a USB4/Thunderbolt root port marked
external-facingare now marked untrusted and removable again, as the binding requires ("all bridges and endpoints downstream of this port are external to the machine"). Since 3b96b89 only an x86+ACPI hook did this, so on Apple Silicon tunneled devices were treated as built in. iommu-dma mapped their sub-16K buffers in place instead of bouncing them, the device could reach the rest of each 16K IOMMU page, and ATS stayed allowed.Tested: builds at 027c947 (
W=1, arm64); the KUnitthunderboltsuite with this branch merged with the other two USB4 branches: 78/78. Hardware rows still owed (below).Risk: two-way door · every Mac with USB4/Thunderbolt PCIe tunnels (all
apcie-c/ USB4 PCIe ports in the Apple DTs); generic PCI code for any DTexternal-facingportNot yet: hardware rows at this head on J714s (M5 Pro, USB4 dock) and J773g (M4 mini): dock attach and detach, displays, dock storage or Ethernet I/O with throughput against base, one deep sleep with the dock attached, 0 IOMMU/DART faults.
Details
pci_dev_below_of_external_port()is true when the upstream bridge hasexternal_facingset and its DT node has theexternal-facingproperty. It checks the property becauseexternal_facingcan also come from ACPI. The result feedsset_pcie_untrusted()andpci_set_removable(). Descendants inherit the flags from their parent, as before.arch_pci_dev_is_removable()and is unchanged. The DT binding leaves no room for such a controller.max_hw_sectors_kb.removablereadsremovablein sysfs.removableon the tunneled devices (fixed/unknownon internal ones), dock storage and Ethernet throughput against base, no "swiotlb buffer is full" or "bounce buffers are inactive" messages, 0 DART faults.Evidence
Head
027c9476464dc3f1a70b91501e94925df427d3a8, basemain40e5e29cc915.The binding text, from dt-schema
pci-pci-bridge.yaml: "When present, the port is externally facing. All bridges and endpoints downstream of this port are external to the machine."Every
external-facingnode inarch/arm64/boot/dts/apple/is the root port of a USB4/Thunderbolt PCIe tunnel (apciec*_port,usb4_*_pcie_port). No other arm64 DT in the tree uses the property.Row checklist, per Mac, against base:
cat /sys/bus/pci/devices/*/removable: tunneled devices readremovable, internal ones don'tqueue/max_hw_sectors_kb(expected 256) and read throughput; dock Ethernet throughputdmesg: no "swiotlb buffer is full", "bounce buffers are inactive" or "Device is not trusted"; 0 DART faults