Skip to content

dart: release aura's L2 tables from a locked DART at shutdown - #311

Open
DjDeveloperr wants to merge 1 commit into
mainfrom
fix/dart-locked-l2-release-20261119
Open

DjDeveloperr wants to merge 1 commit into
mainfrom
fix/dart-locked-l2-release-20261119

Conversation

@DjDeveloperr

Copy link
Copy Markdown
Contributor

Summary

dart_get_l2() adds heap L2 tables under a locked DART's roots whenever aura maps a range there. On the J773g, the boot modeset maps its RTKit buffers and a temporary framebuffer through the locked DCP DART at DVA 0x10000000+. But dart_shutdown_checked() only freed aura's handle of a locked DART (display DARTs are opened with keep as well). The roots kept pointing at those heap tables while the heap went to the OS:

  • the IOMMU could still walk freed memory;
  • Linux's retained-DCP admission refused the DART: DCP admission: root[8]=0000001000eadc01 child=1000eadc000 outside ADT [105ffeec000,105fff1c000).

At shutdown of a locked DART, this unlinks each heap L2 table that no longer maps anything, invalidates, then frees it. A table that still maps pages is logged with its first DVAs and kept. The bootloader's own tables (not heap) are never touched.

Testing

Owner's Mac mini J773g (26.6.2 stub), 2026-11-19, aura-try trial. The Stage 2 was the boot-HDMI test series plus #113/#199/#258 and this commit:

  • aura log: display: Quiescing DCP (external, no reset), then dart[30a340000 23]: released aura's empty L2 tables from the locked DART.
  • Linux (linux#1192 kernel): apple-dart 30a340000.iommu: Preserving DCP SID23 root 0x00000105ffeec000 and 2 foreign 32-MiB slots. Without this commit the same boot refused root[8] as above.
  • Host tests: test_locked_dart_tables.py, test_dart_failure_lifetime.py, test_display_dart_view.py, test_native_dart_tables.py and test_dart_gen3_tlbi_l2_roots.py pass (35). The two harnesses that compile dart_shutdown_checked() now also extract the new helper.
  • Builds (USE_CLANG=1 BUILDSTD=1 RELEASE=1 CHAINLOADING=1 ESP_STAGE2=1).
  • Not tested on other Macs. Only locked DARTs with heap L2 tables that map nothing are affected.

🤖 Generated with Claude Code

dart_get_l2() adds heap L2 tables under a locked DART's roots when aura
maps a range there (the J773g boot modeset maps its RTKit buffers and
temporary framebuffer through the locked DCP DART), but shutdown only
freed aura's handle of a locked DART. The roots kept pointing at those
tables while the heap went to the OS as RAM: the IOMMU could walk freed
memory, and Linux refuses such a DART ("root[8] ... child outside ADT").

At shutdown, unlink each heap L2 table that maps nothing any more,
invalidate, and free it. One that still maps pages is reported with its
first DVAs and kept.

Signed-off-by: Diljit Singh <hey@djdev.me>
@DjDeveloperr
DjDeveloperr force-pushed the fix/dart-locked-l2-release-20261119 branch from 44a66d1 to 0033959 Compare November 19, 2026 08:03
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

The format-check failure comes from main, not from this change: all 34 violations are in src/sptm_virt_s2r.c, which this PR doesn't touch. src/dart.c is clang-format clean (20.1.8). The other 15 checks pass.

🤖 Generated with Claude Code

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks, this explains the root[8] refusal well. Two points in dart_release_locked_l2(). First, tlb_invalidate() can time out and mark the DART failed, and later calls then return early, but the loop still frees each L2. Those pages could still be walked. Could it check dart->failed after invalidating and keep the tables (returning false) in that case? Unlinking all empty tables, invalidating once, then freeing would also avoid one TLBI per table. Second, a heap L2 that still maps pages is logged as kept, but it is still aura heap that the OS receives, and dart_collect_tables() skips locked DARTs, so nothing reserves it. Returning false from dart_shutdown_checked() there, or listing those L2s in dart_collect_tables(), would keep it fail-closed. Also, the new helper sits between dart_shutdown_checked()'s comment and its body. Happy to run a J616s no-regression boot.

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