Skip to content

iommu/apple-dart, PCI: apple: undo a failed attach, keep RID-to-SID slots, drop TEST labels - #2991

Draft
Alyx-ML wants to merge 3 commits into
aurora-silicon:integration/aurorafrom
Alyx-ML:aurora/dart-attach-rollback
Draft

Alyx-ML wants to merge 3 commits into
aurora-silicon:integration/aurorafrom
Alyx-ML:aurora/dart-attach-rollback

Conversation

@Alyx-ML

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

Copy link
Copy Markdown

Part of the #2755 split. Draft until it has a run on a Mac (the last Evidence line says which). The apple_dart_def_domain_type() hunk is dropped: the IOMMU core already
forces a DMA domain for untrusted devices.

Summary

 apple_dart_attach_dev_paging_unguarded()  err:
+  apple_dart_attach_paging_undo()        # streams back on the old domain, or blocked
-  if (stream_maps[0].dart->managed_sids) mod_streams(..., false)
+  apple_dart_attach_drop_streams()       # every DART; keep a locked stream the attach reached
 pcie-apple: function enabled again
+  keep its RID-to-SID slot
 pcie-apple-cio.c
-  sv6t9 diagnostics, J714s only          # removed, not renamed
 TEST labels -> what the code does;  PS_PROT readout -> dev_dbg()

Evidence

Host harnesses compile the patched functions unchanged against mocks of the hardware helpers
(ASan, UBSan):

  • Before: the unpatched attach fails 7 of 11 undo cases, leaving a stream on the failed
    domain.
  • After: the attach passes 11 of 11 undo cases. The stream maps pass 7 of 7 cases (plain,
    locked reached, locked not reached, locked failing, managed, managed and locked). Only the
    failed device's streams are dropped; another device's stay.
  • Build: passed, Apple build and KUnit.
  • Needed before merging: a boot with display and USB on M1 or M2, a USB4 dock attach, and a
    sleep on a J714s (where the diagnostics were removed).

The J714s/J716c retimer scan skip is left as it is. It changes what the driver does, not only
what it logs, so removing it needs a hardware run.

Merge Danger

Door: two-way

Blast Radius: IOMMU error paths

Only failed attaches change. Fewer log lines on J714s sleep.

Assisted-by: LLM (Claude:Opus 5.5)

apple_dart_attach_dev_paging_unguarded() programs each of a device's
stream maps in turn. If the second one failed (a TLB invalidate that
times out, a refused cold ANE stream), the first kept pointing at the
new domain's page tables. Only a managed DART was undone. The IOMMU core
does not revert the device whose attach failed, because it expects that
device unchanged, and it may free the new domain right after. On a first
attach there is no old domain at all. The DART could then walk freed
page tables.

On failure, put the old domain back on every stream map the attach
touched: bypass for the identity domain, the old tables for a paging
domain of this driver, and blocked translation otherwise (no old domain,
the blocked domain, a DCP domain) or when restoring fails.

The error path also took the device's streams back out of the domain's
stream maps only when the first DART was managed. For any other DART the
streams stayed, so the domain went on flushing them, and freeing it
unmapped the firmware root of a locked stream the attach never reached.
Take the streams out for every DART, except a locked stream the attach
reached: the domain's tables may have been in its firmware root, so
apple_dart_domain_free() must still invalidate it before freeing them.
A managed DART is still quarantined and its streams removed, as before.

Verified with host harnesses that compile the patched functions
unchanged against mocks of the hardware helpers, under ASan and UBSan.
The undo: 11 cases (first attach, identity, blocked, paging and DCP old
domains, a failing restore, locked and managed DARTs, an early failure
and a success) leave each stream on the old domain or blocked, never on
the failed one, with runtime PM balanced; the unpatched function fails
7 of them. The stream maps: 7 cases (plain, locked reached, locked not
reached, locked failing, managed, managed and locked) drop exactly the
failed device's streams and keep another device's. The kernel object
was not built here and no hardware was used.

Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
pci_reenable_device() calls the host bridge's enable_device() hook again
without a disable in between. The PCI core does that at a resume, for
drivers that use it, and after a bridge's resources are resized.
apple_pcie_enable_device() then allocated a second RID-to-SID slot for the
same requester ID, and apple_pcie_disable_device() releases only the first
match. Each cycle leaked a slot until the table was full and the next
enable failed with -ENOSPC. On a port whose table is indexed by SID, the
second enable failed at once with -EBUSY, which fails the resume.

Look up the function's own valid entry first and reuse its slot. Managed
(J713 radio) admission is unchanged and still refuses a second enable. The
slot of another function that shares the SID is not reused.

Verified with a host harness that compiles the patched enable and disable
hooks unchanged against mocks of the port registers, under ASan and UBSan:
21 enables of one function take one slot and one disable frees it, an
indexed port re-enables without -EBUSY, two functions sharing a SID keep one
slot each on an allocated table and the second is still refused on an
indexed one, and managed admission still returns -EBUSY. The unpatched hooks
leak a slot per re-enable and fail at the 17th. The kernel object was not
built here and no hardware was used.

Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
Several working code paths and log lines were labelled "TEST" from
T6050 bring-up: the T6050 path sleep quirk, the 10 ms notification
timeout under QUIRK_CIO_MACOS_FRAMES (called a "placeholder"), the
PS_PROT readout after a CIO DART wake, and the T6050 PCIe-C sleep
order. The labels suggest temporary code.

Describe what each one does instead, and print the PS_PROT readout with
dev_dbg() so it stays available through dynamic debug.

Remove the sv6t9 PCIe-C sleep diagnostics. They ran only on J714s
(of_machine_is_compatible("apple,j714s")) and printed, at info level on
every sleep, the power state of each function behind the tunnel and the
PME_Turn_Off register as macOS reads it. Keep the register read that
follows PME_Turn_Off, since it is part of the access order traced from
macOS; only the print goes.

The J714s/J716c retimer scan skip in retimer.c is left as it is. It is
not a diagnostic: it stops a scan that makes the host router firmware
time out three times per dock enumeration, so removing it changes
behaviour on those machines and needs a hardware run.

Not built or run here; the change touches comments, log output, and
code that only logs.

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