Repository navigation
drm/asahi: g17: hold a compute pool release until its context's kill is acknowledged - #3652
Conversation
…d kill The GPU firmware on the M4 Pro (25G83) crashed in agx_scheduler shortly after a ContextKill, four times with four signatures: a NULL store through a zeroed descriptor slot, a cache clean of an unmapped object, and loads through NULL+0x44 and NULL+8. Where the host logged it, an idle compute queue of the killed context had its pool release consumed, and was vacated, within about 2 ms of that kill. An idle queue is never an exit candidate, so no kill transaction marks it, and vacate_idle_pools, the only publisher of a compute pool's FreeListRelease, may release it while the firmware still handles the kill of the context it belongs to. Compile the production vacate_idle_pools and the Queue predicates it reads against host stubs. An idle pool of an unkilled context, or of a context whose kill the firmware finished, is released as before. None is released while the context's kill is published and unfinished, whether its queue is still bound or was detached when its owner exited. A source rule checks that every ContextKill publication marks its context's kill published, so that each kill route reaches the gate. The release checks fail on the current code: the harness is registered as expected to fail until the fix. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
A ContextKill is handled by the firmware after its publication, and the firmware walks the killed context's queues while it does. An idle compute queue of that context is no exit candidate, so no kill marks it, and vacate_idle_pools could publish its FreeListRelease right behind the kill. On the M4 Pro (25G83) that pairing, a queue of the killed context vacated within about 2 ms of its kill, came just before each logged GPU firmware crash in agx_scheduler on this path (NULL+8, NULL+0x44, and a cache clean of an unmapped object). A queue is no longer a vacate candidate while the context its record names has a kill published that the firmware has not finished (the scheduler page shows it killed): a firmware witness, not a timer. That context is the bound owner's, or, once the owner exited and the queue was detached, the one whose pages it retained. Those pages now share the context's kill-published flag, so a detached queue still sees the kill. Every kill route publishes through the compute exit or the render-only kill, and both mark the context's kill published. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
The pool-release gate treats a context's kill as finished once the context's scheduler page shows it killed. On the M4 Pro (25G83) that word read set 4 us after a kill was published, before the firmware acknowledged that kill: the pool release of the killed context's idle compute queue went out, and the firmware crashed 150 ms later in agx_scheduler (NULL+8, PC 0x18d5c), as before the gate. The page's word does not witness a particular kill. Compile the production kill state of a context and of the pages a detached queue retains (context.rs) into the kill-vacate harness, against a stub scheduler page. A kill published while the page already shows the context killed, and not acknowledged, must hold the pool release, bound or detached. It does not on the current code: the harness is registered as expected to fail until the fix. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
…edged The pool-release gate held an idle compute queue's FreeListRelease only until the scheduler page of the queue's context showed it killed. On the M4 Pro (25G83) that word read set 4 us after a kill was published: the firmware had not acknowledged that kill, the release went out, and the firmware crashed 150 ms later in agx_scheduler, with the same NULL+8 as without the gate. The word is no witness of a particular kill. Why it was already set is not known. Witness the kill by its own acknowledgement instead. A context's kill becomes a shared state holding the published ContextKill's cookie and whether the firmware acknowledged that cookie. Both publication sites record the cookie. The kill acknowledgement (event ContextKilled) passes every compute queue and acknowledges the kill of the context its record names, bound or retained after its owner exited. A kill stays unfinished until then, and its context's idle queues keep their pools. The scheduler page is no longer read for this. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
|
Hardware result for f987fd4: FAIL. (Edited: an earlier version said the firmware never acknowledged the kill; the crash trace does not log acknowledgements, so that is not shown.) The firmware crashed with the gate in place, so I pushed a fix on top: a1db565, with its red test 60de717. M4 Pro (J616s, 25G83), kernel 7.3.0-m4.207, which carries f987fd4 and its red test plus a diagnostic line at each compute pool release. Storm chain (multi-process dEQP hang cases), 2026-11-29, pass 3 of 3:
So the page's killed word read set before the kill could have been acknowledged to the host. Whether it was set before the kill was published, or the firmware wrote it within those 4 us, is not known: the crash trace logs restarts and kills, not acknowledgements. One hypothesis for an early word, not checked: a GPU recovery sets it when it fails the context as guilty, as one did for this context at recovery gen 13, 2.2 s before the kill. a1db565 waits for the kill's own acknowledgement instead and no longer reads the page for this. The PR body now describes that witness. Result notes (local): |
The comment on Kill::unfinished said the scheduler page's killed word read set long before the firmware acknowledged the kill. The log does not show that: the crash trace records restarts and kills, not acknowledgements. What it shows is that the word read set 4 us after the kill was published, in the same host pass, before the host could have seen the acknowledgement. Say that. No code change. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
A context's kill state holds the published ContextKill's cookie and whether the firmware acknowledged that cookie. Context::kill_unfinished answers whether a published kill still waits for its acknowledgement. Add the other half, Context::kill_acknowledged: a kill was published and its own ContextKilled event acknowledged it. The scheduler page's killed word does not prove this kill finished, so the query does not read it. No caller yet; it is for ending a closed context's pending kill on that acknowledgement. No behavior change. The kill-vacate harness checks it: no kill, an unacknowledged kill with the page word set, and another kill's acknowledgement are not acknowledged; the kill's own is. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
Conflict in g17/context.rs (Context::new): keep both main's admission order wait and this branch's kill state. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
…nfinished The pool release of an idle compute queue waits for its context's kill to be acknowledged. A successor of the same VM does not need that release: Queue::reusable() hands it the released queue and its pool as they are. During an unfinished kill the firmware still walks the killed context's queues, and the successor would install its own record and commands on one of them. Check the same thing in reusable(): no queue whose bound or retained context has a kill published and not acknowledged is reusable. vacate_candidate() and reusable() now share the check (Queue::kill_unfinished). The kill-vacate harness checks that a released, warm queue is not reusable while its context's kill is unacknowledged, also when the scheduler page already shows the context killed, bound or detached, and is reusable once the kill is acknowledged or with no kill. A new mutation, reuse-ungated, removes the check from reusable() and is caught. Four harnesses that compile reusable() get a Queue::kill_unfinished stub that reports no kill. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
|
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.
Approving at 504a550.
How I read it: a context's kill is now a shared Kill, which holds the published ContextKill's cookie and whether that cookie was acknowledged. FirmwarePages keeps it, so a queue detached from an exited owner still sees that owner's kill. Both kill routes record the cookie. The ContextKilled acknowledgement passes every compute queue before the exit and render-kill matching, so a render-only kill is also acknowledged, as long as some queue names that context. While a kill is unacknowledged, both vacate_candidate() and reusable() say no, so no FreeListRelease goes out and no successor takes the pool. Not trusting the scheduler page's killed word is right, given the 4 us reading in the details.
I also checked the paths that don't go through reusable(), and I see no hole. can_rearm()'s recycled path only runs after the queue's own exit was acknowledged (exit stays set until then), and only on a pool that is already vacant. shareable() needs a live owner. The known limit is that an unacknowledged kill holds that context's idle queues until processor stop. That only affects that one context, so it's fine for now.
What I ran on pc:
- g17 host tests: main 404/404, main + #3600 + #3601 + #3652 414/414. That includes g17-kill-vacate with all five of its mutations caught.
- W=1 of
drivers/gpu/drm/asahi: no new warnings against main.
Small thing, no change needed: Context::kill_acknowledged() has no caller yet and is kept with allow(dead_code). That's fine if the follow-up that uses it comes soon.
Before merge: J714s and J700 rows at the exact head are queued with the M5 and Neo leads. This merges cleanly on main and lands after #3601. #3704 and #3976 conflict with it in one test harness, tools/asahi/g17-m5-sibling-rearm-tests.py: the fix is to keep both the backing_owner and retained_owner fields. Whichever of them lands second needs that test-only merge.
|
Status: #3600 and #3601 are merged. This one is held for one more J714s (M5 Pro) run. It's a measurement question, not a change request. What the M5 row showed (main f778d6c against main + #3600 + #3601 + #3652, module-only Why it points here: this PR is the only change in that arm that decides when a compute pool is released. What the single reading can't tell: whether the pool was in the 10 s warm window (bounded, intended) or held behind a kill that wasn't acknowledged. The next M5 run reads GPU memory and every compute queue's pool state at +0.5, +3 and +12 s after each of 3 open/use/close cycles. Each cycle includes a client killed with work in flight. Then it reads again with the session stopped, and unloads the driver. Base is main with #3600 + #3601; head adds only this PR. If the memory comes back by +12 s, this is bounded and the row's gate gets adjusted. If it stays, or grows per cycle, I'll follow up here with the numbers and a fix. |
|
J714s memory re-run at
One thing is still owed before merge: a J700 (G17P) row at this head. That kit is being built now. |
|
Follow-up to the comment above: the memory on the M5 is bounded and intended. The 64 MiB was a pool still inside its normal 10 s warm window, not something this PR holds back. J714s (M5 Pro) memory run. Base = main
Not shown: whether a ContextKill was published in the killed-client cycles. Compute-exit kills have no counter in the capacity file, and no queue had an exit pending 0.5 s after the kill. So the gate's own hold path still isn't proven on hardware, as your "Not yet" says. On the row side, the J714s judge's single +3 s memory reading was the faulty check. It now reads past the warm window. A J700 (G17P) row is still owed before merge. |
|
Merged at the approved head J714s (M5 Pro, G17S) memory row, done earlier today. Base was main's aurora.ko, head was main + this PR, both on the same kernel. Over 3 cycles of rt.scene, one churn client and one SIGKILLed churn client, head always returned to the same level as base 12 s after each close (-2.6 MiB on head, 0 to -8 MiB on base). No queue was ever held. With the session stopped, both arms read 0.00 MiB. Details are in the comment above. J700 (Neo, G17P) row, 09:18-09:51Z. Base was main
Local checks on pc: the g17 host suite, run with the merge tree on main |
What: An idle compute queue could have its pool released (FreeListRelease, then vacancy) right behind a ContextKill of the context it belongs to, while the GPU firmware was still handling that kill. On the M4 Pro (25G83) that pairing came just before each logged firmware crash in agx_scheduler. Now a queue's pool is released only after the firmware has acknowledged the kill of the context its record names (that kill's own ContextKilled event), with no timer.
Tested: M4 Pro (J616s, 25G83) at f987fd4 (backported): FAIL, the firmware crashed (see the comment): that version took the scheduler page's killed word as the witness, and the word read set before the host could have seen the kill's acknowledgement. Head 504a550: no exact-head Mac run yet. Backport, not an exact-head row: test kernel m4.235 carried this PR's commits including 504a550, picked from the PR head, with #3644 1-5; on the J616s, 2026-12-04 23:59 to 12-05 00:01:44 UTC, a 120 s gpubench load (life.spinkill) whose clients spin until the host watchdog fails their command, then exit: PASS. 4 kills published and all 4 acknowledged, 32-49 µs after publication; 0 pool releases while a kill was unacknowledged; 0 recoveries, 0 firmware crashes. Earlier test kernels ran the gate through a 3-pass storm load and client-kill stress loads without a firmware crash, but no kill happened in them. KUnit at 504a550: 1058 run, 1057 pass, 1 skip; all tools/asahi g17-* and neo-* host harnesses pass (54/54). Host harnesses pass, including g17-kill-vacate, which is red on main and on f987fd4 and green here.
Risk: two-way door · G17 Macs (the gate is in shared compute-queue code; it holds a queue only while a kill of its context is unacknowledged)
Not yet: a hardware run at the exact head 504a550. The gate blocking a release inside the ~40 µs window before a kill's acknowledgement is not yet observed: in the backport run no release or rebind tried to happen there. Checking whether the firmware ever leaves a kill unacknowledged (see Known limits). These are tests; no code is open.
Details
The crashes. On the M4 Pro (J616s, 25G83) the GPU firmware crashed in agx_scheduler, each time shortly after a ContextKill, with four signatures:
The pairing. Where the host logged it, a compute queue of the killed context had its pool release consumed, so the host vacated it, shortly after the kill. Where the killed scheduler page was logged, the vacated queue's last kick named that page.
Why. An idle queue (no commands) is never an exit candidate, so no kill transaction marks it.
vacate_idle_pools, the only publisher of an idle compute queue's FreeListRelease (Queue::begin_growthalso releases a pool, but only an open owner's, with no exit and no work), could therefore release it while the firmware still handled its context's kill. The firmware walks the killed context's queues while it does.The change.
Queue::vacate_candidateis false while the context its record names has a kill published that the firmware has not acknowledged (Context::kill_unfinished). That context is the bound owner's, or, once the owner exited and the queue was detached, the one whose pages it retained.Kill: the published ContextKill's cookie, and whether the firmware acknowledged that cookie.FirmwarePagesshares it.note_kill_published(cookie)).Registry::acknowledge_compute_exit, event ContextKilled) passes every compute queue, which acknowledges the kill of its bound or retained context (Queue::acknowledge_context_kill). Another cookie does nothing.Queue::reusable). The same check holds that back too: no queue is reusable while its context's kill is unfinished.vacate_candidateandreusableshare it (Queue::kill_unfinished). A client waiting for a compute channel meanwhile is woken by the housekeeping pass that sees the queue reusable again.Known limits.
Evidence
Hardware, backport (not the exact head). Test kernel m4.235 on the M4 Pro (J616s, 25G83): this PR's commits including 504a550 and #3644 1-5, picked from the PR heads (driver code identical by patch-id; only host-harness registry context differs), plus local diagnostics that log each kill's publication and acknowledgement and each compute pool release with its context's kill state. life.spinkill, 120 s, 2026-12-04 23:59:18 to 12-05 00:01:44 UTC: PASS.
Head
504a550943a0, which gatesreusable()on top ofd764bdfdff70: main9b8e29feafe7merged in (one conflict, inContext::new: main's admission order wait and this PR's kill state, both kept). Before that, its last two commits change a comment and add a query with no caller yet,Context::kill_acknowledged.tools/asahi/g17-kill-vacate-tests.pycompiles the productionvacate_idle_pools,Queue::vacate,vacate_candidate,recycled_pending,reusableandacknowledge_context_kill, and the productionKill,FirmwarePagesandContextkill methods, against host stubs and a stub scheduler page.bound-only,no-gate,any-cookie,bound-ack-onlyandreuse-ungatedare caught.reuse-ungatedremoves the check fromreusableand is caught).Context::kill_acknowledged(19d7be2): false with no kill, with an unacknowledged kill whose page word is set, and after another kill's acknowledgement; true after the kill's own.note_kill_published(cookie);acknowledge_compute_exitacknowledges the context kill on every queue before it returns.19d7be25ea62; atd764bdfdff70and504a550943a0, 1058 run, 1057 pass, 1 skip.run-host-tests.py --onlyeach: g17-kill-vacate 6/6, g17-kill-route 12/12, g17-object-fence 15/15, g17-m5-sibling-rearm 15/15, g17-m5-sibling-compute 9/9, g17-growth 2/2. object-fence and sibling-compute compileFirmwarePagesandacknowledge_compute_exitand got stubs.tools/asahi/g17-*andneo-*harnesses: one failure, g17-output-fence, which fails the same way on main (fn member_done(matches twice in fence.rs).