Repository navigation
drm/asahi: g17: allow sibling render completion while direct prepare is lent - #3174
Conversation
…is lent Two physical render pairs bound to one logical context share a single free-list Lease. With direct render submission enabled on M5 (PR #2955) alongside two render pairs per owner, lend_render() prepares the shared pool lease and releases the device mutex while the lent pair builds and publishes off-lock. Previously Lease encoded preparation as a single scalar phase (LeasePhase::Preparing), so when the event worker retired a completed render on the sibling pair while the other pair was lent, Lease::complete_render() saw LeasePhase::Preparing, returned EINVAL, and stopped the GPU runtime (reproduced immediately by gpubench-vk render.light depth=8 on J716c). Track active preparations with a counter (preparing) and whether at least one render of the generation has published (published): - Lease::complete_render() admits completions while sibling preparations are lent, while still rejecting completions with EINVAL if no published render holds references above the reserved preparations. - Add Lease::cancel_prepare() and update Pools::rollback() to undo only the rolled-back preparation instead of restoring a pre-prepare snapshot, preserving any sibling completions or observed control-ring release witnesses that occurred while lent. - Add Firmware::rollback_render_pool() so a rollback that drops the last reference on an already-published generation immediately flushes its pending FreeListRelease (or queues events on EAGAIN). - Add KUnit coverage in freelist.rs and a host mutation test in tools/asahi/g17-freelist-lease-direct-tests.py. Signed-off-by: Erik Bourget <erik@ebourget.net>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Audited full diff across freelist.rs, pools.rs, render.rs, direct.rs, submit.rs, and the new host/KUnit tests: replacing LeasePhase::Preparing with preparing/published counters cleanly allows published sibling renders to retire while another pair is lent off-lock, still rejects retiring an unpublished preparation with EINVAL, preserves previous_release witnesses on unpublished rollback, exposes pending final releases on published/lingering rollback, and flushes/handles EAGAIN vs transport failure safely in rollback_render_pool(). Holding merge for CI completion and a second G17 generation row (e.g., G17P or G16/M4 Pro).
|
Merging under the P0 regression-fix exception ( |
|
Post-merge check on the MacBook Neo (J700, A18 Pro): the depth >= 8 render runs are clean on Kernel: plain
Userspace: system Mesa
Full row set, 3 reps: render.light d1/4/8/32, queues d2/4/8, compute.light, compute.heavy, copy.bw, idle.wake and rt.scene.
Smoke:
Kernel log for the whole boot: no GPU fault, timeout, quarantine or runtime-stop lines, no WARN/BUG, no AVC denials, 0 failed units. Two later test kernels on the same base, which add two pending G17 performance fixes, also ran d8/d16/d32 cleanly (about 29–31 µs) with the same clean log. |
What: Track active render free-list preparations with a counter and a per-generation published flag on
Lease, and replace snapshot-basedPools::rollback()with per-preparation cancellation (Lease::cancel_prepare()/Firmware::rollback_render_pool()). Fixes a regression introduced when direct render submission was enabled on M5 (#2955) alongside two render pairs per owner, where a sibling render completing while the other pair was lent off-lock hitLease::complete_render() -> EINVALand stopped the GPU runtime.Tested: J716c M5 Max (
ewb-m5,7.3.0-ewb316+) ata4f42a41076e: boots cleanly into Hyprland (0 new kernel errors);gpubench-vkpasses 3/3render.light(depths=1,4,8, >316k depth-8 submits, 23.4–24.0 us/submit; previously crashed GPU runtime immediately atdepth=8), 2/2queue.rebind(depths=14,84, valid CRCs),queue.churn,compute.light/heavy,render.heavy,concurrent.cr, andsync.signal;gpubench-stress-vk --all --duration 45 --kernel-logpasses 16/16 (1 skipped: ray query unsupported) with 0 kernel GPU errors;tools/asahi/run-host-tests.py --only g17-passes 120/120 (including newg17-freelist-lease-direct-testsand 4 negative-control mutations);drivers/gpu/drm/asahi/compiles cleanly withCONFIG_KUNIT=yand zero warnings in modified files underCONFIG_WERROR=y.Risk: two-way door · M4 Pro and M5 Macs using the G17 GPU driver (G17P/G17G/G17S/G17C).
Not yet: G17P/G17G/G17S hardware not present on this test bench (covered by J716c G17C hardware tests, KUnit compile check, and host mutation tests).
Details
Root cause
Two physical render pairs bound to one logical context share a single
RenderPoolandLeaseentry (drivers/gpu/drm/asahi/g17/runtime/render/pools.rs). At pipelined render depths aboveSIBLING_BACKLOG(1), work spreads across both pairs:render_direct()on pair B callslend_render()->pools.prepare(), which transitioned the sharedLeasefromLeasePhase::ReadytoLeasePhase::Preparing, then dropped the device mutex while pair B built and published off-lock.observe_renders()retired a completed render on sibling pair A (notpreparing), callingHost::complete_render()->Pools::completed()->Lease::complete_render().Lease::complete_render()rejectedLeasePhase::PreparingwithEINVAL, propagating out ofruntime_event_turn()intoGPU event service failed: EINVALand stopping the GPU runtime (device lost).Additionally,
Pools::rollback()previously overwroteself.leases[slot]with a pre-prepareOption<Lease>snapshot. Once sibling completions are permitted while a preparation is lent, restoring a stale snapshot on rollback would drop sibling completion decrements or observed control-ring release witnesses.Fix
drivers/gpu/drm/asahi/g17/freelist.rs: ReplaceLeasePhase::Preparingwith apreparing: u32counter andpublished: boolflag onLease.Lease::complete_render()permits completion wheneverphase == Ready,published == true, and references/commands exceed the3 * preparing/2 * preparingreserved by live preparations (preserving theEINVALguard against retiring an unactivated preparation).Lease::cancel_prepare()undoes one unpublished preparation (preparing -= 1,references -= 3,commands -= 2). Ifreferences == 0and!published, it transitions cleanly toReleaseSent(cursor)(preserving any unconsumedprevious_releasewitness) orReleased(if already observed consumed or never released) without emitting a bogusFreeListRelease. Ifreferences == 0andpublished,pending_release()exposes the finalFreeListReleasefor the generation.drivers/gpu/drm/asahi/g17/runtime/render/pools.rs&render.rs/direct.rs/submit.rs:Pools::rollback()delegates toLease::cancel_prepare()and returns whether a final release is now pending.Firmware::rollback_render_pool()flushes any exposed pending release viarelease_render_lists(), queues the event worker onEAGAIN, and marks the device lost (lose_device_quietly()) on non-EAGAINtransport/invariant failure so a committed control-ring release record cannot strand on mailbox timeout.drivers/gpu/drm/asahi/g17/freelist.rsand a registered host mutation test intools/asahi/g17-freelist-lease-direct-tests.py(tools/asahi/run-host-tests.py).Evidence
Failure before fix (
origin/main4f1168e1a7ff+ open daily PRs, J716c7.3.0-ewb315+)Verification at PR head (
a4f42a41076e, J716c7.3.0-ewb316+, Borealis Mesa2e9a5c1f967)Host tests & build checks at
a4f42a41076e