Repository navigation
iommu/apple-dart: preserve translations across a firmware 27 DCP cycle - #3807
Conversation
Gate commands and save the internal display DART streams before the DCP powers down. Check retained translation registers before re-enabling streams on wake. Leave unused, invalid streams off and refuse to resume a DART with lost live mappings. Signed-off-by: Diljit Singh <hey@djdev.me>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
J516s (T6030, M3 Pro) hardware qualification PASS for exact head
|
DjDeveloperr
left a comment
There was a problem hiding this comment.
FINISH, then merge at 91388df2aa97
-
drivers/iommu/apple-dart-v27-late.inc:626discards the result ofapple_dart_power_dark(dev, true). It returns-EBUSYwhen display writers fail to drain and can undo the dark state. The caller can still return a successful cycle handle and allow power-off. Free the new handle and return the error before gating commands or taking the snapshot. -
At line 634 the idle-error rollback opens the DART before flushing it. If that flush times out, the function frees the handle with commands available and the stale flag cleared. Preserve a dark, gated state on flush failure as the wake error path does. Exercise both failures along with the shared DART peer check.
Checks and evidence
I traced the existing dark-entry helper and both release paths. J516s exercised the display consumer across two successful power cycles. Apple build, host and DART-related KUnit checks passed.
Check apple_dart_power_dark() in apple_dart_v27_cycle_off() before gating commands and abort cleanly on failure. In apple_dart_v27_cycle_release(), when the post-lit TLB flush fails (on either cycle_off() idle-error rollback or cycle_on()), restore display_tlb_stale, re-enter dark mode, and re-gate commands instead of leaving the DART live with an un-flushed TLB. Add KUnit coverage (apple_dart_test_v27_cycle_errors) for failed dark-mode entry and failed TLB flush on both rollback and cycle_on(). Signed-off-by: Diljit Singh <hey@djdev.me>
|
Addressed review findings in
|
|
J516s hardware verification for exact head
|
|
J516s (M3 Pro, T6030) hardware row at
|
Limit the temporary driver override to the cycle-off call. An assertion can abort the test before the final cleanup, leaving the driver core to unbind a KUnit device with the platform driver still installed in its driver pointer. Save and restore the prior driver under the device lock. Signed-off-by: DjDeveloperr <hey@djdev.me>
|
Head |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Hold at ed67b5f6dbec. Two release paths can leave a stale DART translation.
- In
apple_dart_v27_cycle_release(), the final flush can complete while a dark writer is still publishing the locked root. The writer recordsdisplay_tlb_stalebefore publishing, then returns without invalidating. Release clears that flag and opens the DART without drainingdisplay_dark_writers. Use the existing dark-exit protocol to drain writers and flush before reopening. Release · Writer - If cycle-off times out because
TLB_CMD_BUSYstays set, rollback calls that same flush and writesFLUSH_ALLbefore checking whether the command port can accept it. Wait for idle before issuing the command and keep the DART gated if it times out. Cover the in-flight writer and busy rollback in the DART tests. Flush · Rollback
J516s passed two target cycles on the unchanged runtime. J714s/T6050 passed the shared-driver control on combined candidate 730f0cadeb6d, which contains this exact head. The internal panel stayed at 3024×1964 at 120 Hz through RTC wake and the later PCIe re-entry abort tracked in #3846. Display/DCP mappings stayed unchanged, with zero new DART faults and verified stock handback. J714s uses DART revision 0x0204, outside the new cycle path. J516s receipt
Match apple_dart_display_dark_exit() in apple_dart_v27_cycle_release(): mark display_tlb_stale, drain in-flight display_dark_writers under managed_lock, and complete the post-lit TLB flush before clearing commands_gated and display_dark. If writers fail to drain or the flush fails, keep the DART dark, gated, and marked stale. In apple_dart_v27_cycle_flush() and the pre-stream flush in apple_dart_v27_cycle_on(), wait for DART_T8110_TLB_CMD_BUSY to clear before writing FLUSH_ALL so a busy rollback does not clobber an active TLB command. Extend apple_dart_test_v27_cycle_errors() to cover busy-command rollback preservation, in-flight dark-writer draining before the final flush, and stuck dark-writer -EBUSY rollback. Signed-off-by: Diljit Singh <hey@djdev.me>
|
Addressed both review blockers from #3807 (review) in
Local checks at |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Hold at d9aa641cab45. Both command writes now wait for idle. The writer drain also handles ordinary completion, a writer arriving during the flush, and a stuck writer. One boundary case still leaves the display DART gated after a successful wake flush.
I ran the exact apple_dart_v27_cycle_release() in a native host harness with controlled writer completion and a stubbed flush. When the writer finished during the 9,999th sleep, the final pass saw zero writers and flushed successfully. Its continue exhausted the loop before it could reopen the DART. The result was -EBUSY, one successful flush, zero writers, stale clear, and both gates still set. cycle_on() then frees the handle. After a successful flush, recheck writers and stale state under managed_lock before applying the retry limit. Cover the final-pass success and preserve the stuck-writer timeout. Release loop
The new KUnit fixture also initializes stack-resident delayed work as ordinary work. That triggers the debug-objects stack warning when work or timer debugging is enabled. Allocate the writer context with kunit_kzalloc() before acquiring the cycle. Fixture
Recheck display_dark_writers and display_tlb_stale under managed_lock immediately after a successful apple_dart_v27_cycle_flush() so a dark writer finishing on the final sleep still completes release cleanly instead of returning -EBUSY with display_tlb_stale cleared. On an actual retry-budget timeout, re-mark display_tlb_stale = true before returning -EBUSY. Allocate apple_dart_test_dark_writer_ctx with kunit_kzalloc() before entering the cycle instead of placing a delayed_work on the stack. Signed-off-by: Diljit Singh <hey@djdev.me>
|
Folded both items from #3807 (review) in
Strict |
DjDeveloperr
left a comment
There was a problem hiding this comment.
No blocking code findings at 01bbc1d13c30. I reran the native host harness against the old and new release functions. The previous head returned -EBUSY when the writer finished on sleep 9,999. This head reopens the DART after one successful flush on sleeps 9,999 and 10,000. A mapping change during the flush triggered a second flush. A stuck writer, continuous changes through the retry limit, and a flush timeout all left the DART dark, gated and marked stale.
With simulated command registers, an already-busy port received zero writes. I also verified that the delayed-work fixture is allocated before the cycle starts and its work is flushed before teardown.
CI and fresh J516s target and J714s shared-driver receipts are still pending for this runtime.
|
J714s / T6050 shared display-DART control passed at
|
There was a problem hiding this comment.
Verdict: MERGE at 01bbc1d
Checked:
- Risk: the interface has no caller in this PR (only
apple_dart_v27_cycle_off/onexports, a forward decl and a KUnit case), so nothing changes at runtime until the T6030 display series calls it.cycle_off()refuses every DART already held another way (dispext, managed SIDs, preserve_display, sleep_saved, borrowed, gated/dark, rev >= 2.2), so it can't stack on the existing holds. - Error paths: an idle-check failure in
cycle_off()rolls back throughcycle_release()and frees the cycle. A lost state, a busy TLB or a stream mismatch incycle_on()leaves the DART dark and gated, then drops the device reference and frees the cycle.cycle_release()drains the dark writers, flushes underd->lockand re-checks before it clearsdisplay_darkandcommands_gated. A failed drain or flush leaves the DART stale and gated. - Ran apple-dart KUnit at this head on the buildbox (arm64, 16K pages):
apple_dart_test_v27_cycle_errors,display_keep,gated_commands,gated_irqand the dapf/consumer cases pass, 8/8. Negative control: with the dark-writer check incycle_release()bypassed (if (!d->display_dark_writers)->if (1)),v27_cycle_errorsfails 5 expectations (flush ran before the writer published, stale left set, the undrained writer not refused), so the new case catches the drain regression. - Note, not this PR: the full
apple-dart*suite stack-overflows atapple_dart_test_t8132_fw_mirror_selection(a 37 KB on-stack memset with 32 KB task stacks), and it does so on main 13c7f69 too. The 24 cases after it never run, and linux CI doesn't run the apple-dart suite at all. B1 is tracking that as a CI follow-up.
Follow-ups (non-blocking): cycle_on() flushes the TLB inline without d->lock. That's safe while commands are gated, but calling apple_dart_v27_cycle_flush() there would keep a single flush path. Re-run the J516s/J714s rows after the release-sequence change, as the PR body already plans, before the T6030 caller lands.
satchlj
left a comment
There was a problem hiding this comment.
Reviewed 01bbc1d13c30.
apple_dart_v27_cycle_off()/apple_dart_v27_cycle_on()gate strictly on DART hardware properties (T8110 layout, rev < 0x0202, and mutual exclusion with existing DART holds) and add no runtime caller yet.- Lock ordering in
apple_dart_v27_cycle_release()(managed_lock->d->lock, withusleep_range()andapple_dart_v27_cycle_flush()outsidemanaged_lock) matches the existingapple-dart.cdark-exit protocol. - Dark-writer drain rechecks
!display_dark_writers && !display_tlb_staleundermanaged_lockafter each flush before enforcing the retry bound, and all drain/flush/retention error paths fail closed (leavingdisplay_dark,commands_gated, anddisplay_tlb_staleset). apple_dart_test_v27_cycle_errorsheap-allocates its delayed-work context and exercises dark-entry-EBUSY, busy-command-port rollback without touchingTLB_CMD, in-flight writer drain ordering, stuck-writer refusal, and flush timeouts on both rollback and wake.
|
Merging at |
|
Post-merge check of the landed merge
The 34-case run left out |
What: Add a firmware-27 display DART power-cycle interface. Gate commands before power-off, verify retained translation registers on power-up, restore the saved stream enables, and keep the DART quiesced if its state was lost. Disabled streams with invalid translation tables may change without becoming active.
Tested: Strict checkpatch and whitespace checks passed. All 24 DART host runs passed, and Clang AArch64 built
apple-dart.o.J516s, integrated kernel
af2647f710fd,direct-t357h-02: the internal firmware-27.2 DCP restarted and modeset to 3456×2160 at 120 Hz after both same-boot wakes. Neither wake window added a priority 0–3 kernel record. The second wake failed the RTC latch check.J516s completed two consecutive deep-sleep cycles on the hardware-tested runtime, with display and PCIe DART restored after both wakes, zero DART faults and clean stock handback. That receipt also covers
ed67b5f6dbec, which changed only the KUnit fixture. The subsequent runtime change updates the release sequence.J714s/T6050 passed the shared-driver check on combined candidate
730f0cadeb6d, which containsed67b5f6dbecunchanged. Internal eDP stayed active at 3024×1964 and 120 Hz across RTC wake and the separate #3846 PCIe re-entry abort. Display/DCP mappings stayed unchanged, with zero new DART faults and verified stock handback. DART revision 0x0204 excludes the new cycle entry points on this Mac.Risk: Two-way door. The interface adds no caller. The companion T6030 display series enables it for the internal display DARTs.
Current-head CI: Apple build, host tests, PR text and Asahi KUnit passed.
Not yet: J516s target and J714s shared-driver hardware retests after the release-sequence change, and GitHub maintainer approval. The independent code review found both earlier blockers resolved. Earlier J714s receipt