Skip to content

iommu/apple-dart: keep a retained DART across s2idle and restore translations if its reset fails (Neo Wi-Fi/BT lost after sleep) - #336

Merged
RyanTheTide merged 3 commits into
aurora-wipfrom
fix/apple-dart-resume-retained
Oct 17, 2026
Merged

RyanTheTide merged 3 commits into
aurora-wipfrom
fix/apple-dart-resume-retained

Conversation

@RyanTheTide

Copy link
Copy Markdown
Contributor

After an s2idle cycle, the MacBook Neo can lose Wi-Fi and Bluetooth until reboot, on the default kernel. It happened on the night of 2026-10-16: about 1 in 17 five-minute sleeps.

Cause

  • The PCIe radio's DART (pcie0_dart, iommu@390000000) shares the power domain ps_apcie_gp with the PCIe host. The Wi-Fi awake path deliberately keeps that domain powered through s2idle.
  • apple_dart_resume() nevertheless always reset this DART (TCR=0, TTBRs cleared, TLB flush) while the MT7932 was still running.
  • When that flush timed out (TLB command 0x1 for stream 0 timed out → Failed to reset DART on resume), resume returned before restoring TTBR/TCR, so SIDs 1-2 were left untranslated.
  • Bluetooth's restore then timed out ("terminal transport fault … -110"), and Wi-Fi lost DMA (scan -EIO).

Commits

  1. 82494bf5c6b0 iommu/apple-dart: Do not reset a DART that kept its state across sleep.
  2. 39bc76211b30 iommu/apple-dart: Keep a retained DART in bypass from being reset.
  3. d9fc21447419 iommu/apple-dart: Restore the translations when the reset on resume fails.
    • Resume now always restores every saved TTBR/TCR.
    • If the reset failed, it repeats the non-destructive reset tail (apple_dart_hw_finish_reset(): acknowledge errors, the T8110 v2.2+ unlock, ERROR_MASK = 0, flush) once, names the stage that failed, and returns that error.
    • A reset_incomplete flag makes the next runtime resume finish the tail too.

Testing

  • KUnit (apple-dart):
    • 22/22 at 1 and 2 CPUs under lockdep.
    • New tests: lost state, the radio case, an unlock pre-submit timeout and a stuck unlock.
    • Fail-before: 15/20 on the base, 18/20 with the first two commits, 20/22 on v1.
  • Review: an independent review of v1 found a MAJOR (the recovery could hide a failed unlock) and a MINOR (the test aperture); both are fixed in v2. Re-review: APPROVE, no findings.
  • MacBook Neo (J700):
    • v1: 12/12 × 300 s s2idle with the dock on the front and the tether on the rear. Wi-Fi and BT back after every resume. 0 DART/TLB/reset lines. The pcie0_dart state was identical on all 24 before/after snapshots.
    • The full regression battery passes: display, GPU, Wi-Fi, BT, Touch ID, camera, mic, thermal, logs.
    • v2 smoke: 3/3 × 300 s, with the pm_test devices rollback OK and the same battery.
  • M1 Pro (t6000), this merge onto aurora-wip 5ca66ce, aurora and stock DTB:
    • pm_test=platform 3/3 per boot. 0 DART fault lines, and DART runtime states identical to the previous baseline.
    • tcycle 10/10, eDP and GL OK, 0 WARNING/BUG.
  • M2 (t8112): not tested; it was offline. The Neo exercises the same T8110-type DART path.

The failure is intermittent, so the efficacy evidence is the KUnit model of the timeout case. The hardware runs are the no-regression gate; the reset-failure path never fired on hardware during them.

🤖 Generated with Claude Code

apple_dart_resume() resets every DART on resume, clearing its page
table pointers and disabling translation before restoring the saved
values. That is only correct when the DART lost power. A DART whose
power domain stayed on still has its state, and may still be translating
for a consumer that kept running through the sleep: dwc3-apple keeps its
core up across system sleep as a syscore device, which holds the shared
power domain on, and with xHCI now left running in suspend-to-idle the
controller can write events or touch its scratchpad while the DART is
resumed. A DMA that hits the reset window faults, and xHCI halts on a
Host System Error.

Compare the translation registers with the values saved at suspend.
When they still match and at least one page table is valid, the DART did
not lose power: leave it alone and only invalidate its TLBs. Otherwise
reset and restore it as before. A powered-off DART reads back with no
valid page table, so it always takes the reset path.

The TLBs are flushed with one command per stream rather than one command
for a map of all streams. Where the streams of a map are remapped onto its
first stream, a map flush only reaches that first stream, which would
leave stale entries of every other stream behind.

Two consequences beyond the USB case:

- The suspend and resume callbacks are shared by runtime PM and system
  sleep. Every runtime resume of an unlocked DART whose power domain
  stayed on now also skips the reset and only invalidates the TLBs. This
  applies to all DARTs the driver handles, on other Apple SoCs as well,
  including the t8110 ones.

- "Retained" is judged only by TCR and TTBR matching the values saved at
  suspend. On that path the error status and the stream enables are no
  longer reset; they are left as the DART kept them.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
The resume path only treats a DART as having kept its state when a stream
has a valid page table. A stream of an identity domain bypasses the DART
without one, for example with iommu.passthrough=1 or where the default
domain type is identity. Such a DART reads back exactly as it was saved,
its consumer may still be doing DMA, and it was reset all the same, which
disables DMA on every stream before the saved state is restored.

Count a stream whose TCR still holds the bypass setting of its generation
as live as well, on DARTs that support bypass. A DART that lost power
reads back with neither, so it still takes the reset path.

This completes "iommu/apple-dart: Do not reset a DART that kept its state
across sleep". Test it for a T8103 and a T8110 DART; both tests fail
without this change.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
…ails

apple_dart_resume() returns as soon as apple_dart_hw_reset() fails. By
then the reset has disabled translation on every stream and cleared the
page table pointers, so the DART is left without any translation and
every DMA of its consumers faults until something resets it again. On
the J700 this happened to the DART of the PCIe radio: "TLB command 0x1
for stream 0 timed out" on resume, after which the Bluetooth function
could not restore its transport and Wi-Fi lost its DMA until a reboot.

The reset can only fail in its last steps, after the translation
registers are cleared: the unlock of a T8110 v2.2 or later DART that
locks on errors, and the TLB flush. Move those steps, with the error
acknowledgment and unmasking around the unlock, into
apple_dart_hw_finish_reset(). It leaves the translation registers alone
and reports the step that failed.

On resume, write the saved page table pointers and translation controls
back whatever the reset returned. They still describe the page tables in
use, and this path is only taken when the DART did not keep its state,
so its TLBs hold nothing from before the sleep. Then, if the reset
failed, repeat all of its last steps once, not only the flush. When the
unlock fails, the reset returns before it unmasks the error interrupt
and flushes the TLBs, and a flush that completes later says nothing
about either.

If they fail again, resume returns the error. After a failed system
resume the PM core leaves the DART runtime suspended, with the restored
registers matching the saved ones, so its next runtime resume would take
the path for a DART that kept its state and only flush the TLBs. Have
that resume repeat the last steps of the reset instead.

The tests cover an unlock that times out while the command engine is
busy, followed by stream flushes that complete, through a KUnit stub of
the unlock, and an unlock that never gets through. They size the fake
register space for the T8110 layout, whose exception records start at
16 KiB, and put a guard page after it.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
@joshuaswarren

joshuaswarren commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

GREEN on d9fc214

Review at exact head 4718d69, branch w73/move-pmgr-misc-debugfs, one commit on asl/aurora-edge 139dfe6.

Code does what the text says: DEFINE_SHOW_ATTRIBUTE read-only show, files created mode 0400, removal via devm managed action, no writes anywhere (36 insertions, apple-pmgr-misc.c only, plus two includes). Init runs only on successful probe. State line honest: built with clang, never booted, draft. No internal names, paths, or tooling in the body. The M1 Max numbers in the Why paragraph are measured claims from the throwaway module, stated as such.

No findings.

@joshuaswarren

joshuaswarren commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

CHANGES on d9fc214

RETRACTED — misfiled verdict. The GREEN above names head 4718d69 (a pmgr-misc debugfs move from another tree) and describes that change; this PR 336 is the DART s2idle work at head d9fc214, closed. My review was for w73's unopened move PR, not this PR, and I supplied the wrong number. This verdict is void here; my apologies to the participants — nothing in that review describes your change.

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.

2 participants