Repository navigation
drm/asahi: g17: kill a hung client's work instead of letting it take the GPU down - #2504
jgoyvaerts wants to merge 5 commits into
Conversation
0868df5 to
f2f239a
Compare
f2f239a to
54e48a2
Compare
|
Commit messages only, for the pre-PR checklist: the commits no longer carry Assisted-by: LLM (Claude:Opus 5.5) |
|
Blockers: 1. Checked the new close latch (
HW row: J616s on this head, default command line: the deqp-vk memory_model hang case run 10 times in a row beside a drawing desktop, with at least one run where the first blame lands on a bystander. Pass: no restart-storm stop, the desktop keeps its device, Assisted-by: LLM (Claude:Opus 5.5) |
54e48a2 to
3efdb5d
Compare
|
Fixed in
Testing: arm64 The J616s row will follow the next kernel build of our tree. The memory_model hang case stays with the owner. We'd take your offer to run the M4 Max (J616C) row in your lab. Assisted-by: LLM (Claude:Opus 5.5) |
|
Re-review of 3efdb5d: Blockers: 1. Earlier points:
Since then (only the third commit changed; I diffed the old and new heads):
HW row: unchanged from last time: J616s on this head, default command line, the deqp-vk memory_model hang case 10 times in a row beside a drawing desktop, at least one run with the first blame on a bystander. Pass: no restart-storm stop, the desktop keeps its device, Assisted-by: LLM (Claude:Opus 5.5) |
3efdb5d to
ca0bda2
Compare
|
Fixed in
Test: g17-kill-route-tests.py now compiles the real Results:
The J616s hang row follows our next kernel build (m4.179). We have no J616C (25G83) here. Could you, or someone with one, run that boot? Assisted-by: LLM (Claude:Opus 5.5) |
|
Re-reviewed at ca0bda2: the blocker is fixed. On rows: to be precise about what we have, it's an M4 Pro (J616s, T6040), not a J616C, so we can't give a 25G83 M4 Max boot. The J616s hang row you plan on m4.179 is the one that matters for this head; once it's posted (hung client killed, other clients keep rendering, no device loss, default command line), this is approved from our side. Assisted-by: LLM (Claude:Opus 5.5) |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Adversarial review at ca0bda2152a2 against the pre-PR checklist.
CI (host-tests), commit attribution/sign-off (§4), naming (§6), and firmware-profile scoping (is_m5(), §1) are clean, and the earlier close_failed_owners pre-/post-latch error handling fix in ca0bda2152a2 looks solid.
Blocker (code)
- Permanent render-slot leak when
try_render_earlyraces with a kernel-closed open client (drivers/gpu/drm/asahi/g17/runtime/compute_exit.rs:434-466,drivers/gpu/drm/asahi/g17/runtime/backend.rs:110-126,drivers/gpu/drm/asahi/g17/runtime/render/submit.rs:569-580,drivers/gpu/drm/asahi/g17/queue/admission.rs:173, 202-215):- Commit 3 (
close_failed_owners) is the first path that callsadmission.release_owner(owner)while the userspaceQueueis still open (context.is_closed() == true,context.held_by_open_client() == true,Backend::closed == false), and makesBackend::release_queueskipadmission.release_owner(self.owner)when the client later closes (backend.rs:110). - Once the killed guilty pair drains on the guilty proof while the client still holds its queue open,
release_drained_render(runtime/render/settle.rs:348-350) callsadmission.pair_drained(slot), clearingstate.quarantinedon that slot whilestate.owners[slot] == ownerandstate.released & (1 << slot) != 0. - Unlike
admit_render(submit.rs:165-169),Backend::try_render_early(submit.rs:569-580) does not checkpacket.completion.status().get() != 0orself.context.is_closed()before callingself.admission.try_acquire_render(self.owner, self.pairs.into(), Request::of(packet)). - A
Queue::submitthat already passed the initialstatus().get() != 0check before recovery (or between commands of a multi-command submit) can entertry_render_early->try_acquire_render:state.refusal(owner)succeeds (owner_quarantine(owner)is nowNoneandowners.contains(&owner)istrue).state.acquire(owner, pairs)(admission.rs:202-215) selects the owner's idle slot without checkingreleased,held, orkill_hold, callstake_idle(slot, owner)which clearsself.released &= !(1u64 << slot)(admission.rs:173), and whenpairs > 1can also callclaim_sibling(owner, pairs)(admission.rs:213) to claim a fresh sibling slot for the already-closed owner withreleased = 0.render_with_leasethen fails immediately withEIO(submit.rs:398) and drops theRenderLease, leavingowners[slot] == ownerwithreleased == 0(and any newly claimed sibling slot withreleased == 0).
- When the client later closes its queue,
Backend::release_queueseesself.context.is_closed() == trueand skipsadmission.release_owner(self.owner). Afterdetach_contextclearsheld/kill_hold, those slot(s) stay permanently leaked in admission (even acrossrelease_retained_owners_after_processor_stop(),admission.rs:803-813, which only clearsstate.released & !state.active). - Fix: Check
packet.completion.status().get() != 0 || self.context.is_closed()(orself.admission_open().is_err()) intry_render_earlybeforetry_acquire_render, preventState::acquire/take_idlefrom reusing or sibling-claiming slots for an owner whose slots are alreadyreleased, and/or callfirmware.queues.admission.release_owner(self.owner)unconditionally inBackend::release_queue(release_owneris idempotent onowners[slot] == self.owner).
- Commit 3 (
Nit
drivers/gpu/drm/asahi/g17/queue/render.rs(Pair::guilty_unretireddoc comment): still reads "since the context's latest close" instead of "first close" (matching thecontext.rs:220fix).
Hardware evidence still owed (§5)
- J616s run on current head (
ca0bda21/ post-fix head), default command line: repeateddeqp-vkmemory_modelhang beside a drawing desktop (no restart-storm stop, desktop keeps its device,kept_guilty_pairs=reported and bounded) plus a regression check (0 SELinux denials, 0 failed units, 0 new kernel errors).
Assisted-by: LLM (Gemini 4 Neon)
ca0bda2 to
4f5c986
Compare
|
Thanks, the race is real. Fixed in I confirmed it in the code: the sleeping path ( Fix chosen: admission itself gives no lease to a released owner. The new
Owner IDs come from a 64-bit sequence and are never reused, so released means closed for good. Nit: Tests:
Results:
The J616s rows (the hang case and the regression check) follow our next kernel build. Assisted-by: LLM (Claude:Opus 5.5) |
|
Checked 4f5c986: Assisted-by: LLM (Claude:Opus 5.5) |
…ts work A client whose render work a GPU recovery found guilty keeps that work published after it exits: on 25G83 the host cannot take published groups back, and only a kill of the context unlinks them. The kill never came. kill_route() gives a pair that is not executed_for_kill() (a started group plus never-started ones behind it) no route, and kill_unsafe() holds the kill while any other client renders, up to LIVENESS_NS (5 s). Meanwhile each restart reran the guilty group, it hung again about every 83 ms, and eight such restarts stop the GPU for every client. On 2026-11-19 19:12 UTC a deqp-vk memory_model case (a hang in Mesa's G17P 64-bit atomic emulation) did exactly that beside a drawing desktop: deqp-vk exited 0.1 s after its EIO, its pair stayed at active=32 with frozen stamps for 12 restarts, the storm limit stopped the GPU, Hyprland lost its device and the machine rebooted. Which pairs: a quarantined pair of a closed owner, every group published, its VM recovery_guilty, not M5 (Pair::guilty_for_kill), and only once the host accepted a restart since the context's latest close. The VM stays guilty and a failed VM's pairs are all quarantined, but its groups behind the one that hung may run fine; killing those would unlink work with nothing left to hang and no restart to release it. A group that still runs hangs again within ~83 ms, so this costs one restart at most. The kill: teardown_idle() counts such a pair, the render kill is eligible at once rather than after RENDER_KILL_DELAY_NS, it waits only for other clients' compute (kill_waits_as_failed), admission holds the pair with its work, kill_retry_delay() keeps polling, and it is still published once per context. A line logs each kill that releases guilty pairs, with the recovery generation. The release of its groups: the executed pair's proof (kill done on the scheduler page, no restart in progress) plus a restart the host accepted after it first saw the kill done (Context::restarted_since_kill). A group running at the kill keeps running until a restart drops it, and a restart between the kill's publication and its completion does not count, so the generation is latched at the first sighting, not at publication. The sighting is also taken while the firmware is halted in a restart, so a kill finished just before a restart the host had not seen yet still counts for that restart. Without the acknowledgement or a later restart the pair stays held, its memory pinned, until the processors stop. The pair afterwards: it never counts as idle for the scheduler release while it may run (counts_idle). Once its groups went on the guilty proof it counts (Pair::guilty_released), whether or not the firmware consumed the ring entries of the groups the kill unlinked. At detach, after the consumed scheduler release, it parks if its rings were consumed. If not, its graph and rings are kept and its slot is held (hold_kept_slots, as the kill held only the slots whose queues the scheduler page listed), out of service until the processors stop, because a parked pair's rings go to the next owner with entries naming freed descriptors and its queues stay installed. A released pair is not quarantined again when another queue of its VM fails, so it can still park. Both end states are logged with the ring cursors; debugfs counts kept pairs. A closed context that is neither failed nor holds such a pair keeps today's route and kill_unsafe() gate. This relies on four 25G83 behaviours, all seen on the M4 Pro in the same deqp-vk case beside a drawing desktop (2026-11-20 02:18 UTC). The restart table of the first recovery lacked the client's commands, the same shape as the storm above: - a context kill leaves a started group running until a restart: the restart 8 ms after the kill still found the GPU hung; - a restart drops started groups and never runs a killed context's unlinked work again: no recovery followed that restart; - releasing the pool after killing a hung render does not crash the firmware (a compute traversal did, see queue/compute/exit.rs); - the wait for foreign compute ends within the restart storm budget: the kill went out 260 ms after the EIO, 4 recoveries in all, only the first counted toward the limit. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
Whether a recovery fails a VM and whether the restart counts toward the storm limit depend on the firmware's restart table: which queues it lists, with which stamps, which records it flags guilty or cancelled, and which of them the host finds by exact stamp. None of that was logged, so the 2026-11-19 19:12 UTC storm could not tell why the restarts that blamed the already failed deqp-vk queue still counted: its commands were missing from the tables, or the firmware flagged another live VM guilty. Print one line per recovery, in the recovery service right after the firmware resumes from the records already copied while it was halted: the record count and the first 24 records as qid:stamp:flags/match (E exact stamp, O oldest published work, - not found, ? M5), then a count of the rest. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
…eps it open A guilty context is killed only once its queue closed: Pair::guilty_unretired needs a closed owner, and the kill machinery serves the teardown entry a close creates. A client that keeps the queue open after its lost device (a process that ignores VK_ERROR_DEVICE_LOST, or waits in an error dialog) leaves its guilty work published. Each restart reaches the group that hung and it hangs again about every 83 ms. Then the restart storm limit, or the recovery table's contents, decide whether the GPU stops for every client, and each forgiven restart still drops other clients' running work. Nothing of such a VM can run again. A recovery that finds it guilty records the failure in its status, and every later submission, install and publication checks that status. So close the queue on its client's behalf, as the client's own close (release_queue) would: the teardown entry, the compute and render owner releases, the render holds and the admission release. The kill, the release of its groups after a later restart, and the park or keep at detach then follow the path an exited client takes. A line logs each such close with the recovery generation. Only the first close of a context counts (Context::note_closed): the client's own close later finds the queue closed and leaves the firmware side alone, since its teardown entry may be released and reclaimed by then and a second one would release the scheduler twice. The kill gate keeps its restart since the close, now the kernel's close. A close counts only once its teardown entry is reserved, the one step of it that allocates: a close that fails there leaves the context open, and the next close redoes all of it. The kernel's close logs such a failure and retries at the next service pass; the other failed owners of that pass are still closed. An error after that, once the context counts as closed, fails the event service and with it the device, as the client's own close does: no later close would release the owner's compute slot and admission. For the same reason admission gives no lease to an owner whose pairs are released (State::owner_released, in acquire_render and try_acquire_render), under the lock release_owner takes. The client of a kernel-closed queue may still publish early (try_render_early, which checks no VM status) once its drained pair left quarantine: taking that pair back, or claiming a sibling, would clear its released bit for good. Owner IDs are never reused, so a released owner is closed for good. admits_render does not check it, so the scheduler's prepare step does not wait for such a job; its publication fails it at once. The client's queue still holds the context, so its scheduler release, and with it the context's reclaim and the pair's detach, waits for the client's own close (Context::held_by_open_client). The guilty groups go on the kill before that; until the close the killed pair stays held. Only VMs that a recovery found guilty and whose status recorded a failure, with an open owner, no builder and no owner switch on the slot. Only render slots are scanned, so a compute-only queue of such a VM stays open until its client closes it. Not on M5. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
A recovery classifies every VM it does not find guilty as spared, and a later blame on a queue whose oldest work is spared counts as collateral to that earlier recovery, not as guilt of its VM (classify()). The blamed command then fails with EIO without poisoning its VM. That holds once. When the first restart of a cascade blames a client the real culprit starved, the culprit's work is spared, and every later restart that blames it finds that spared work and calls it collateral. The culprit's VM is never guilty and never failed: no restart that only drops its work is forgiven, a closed or open culprit is never killed, and the cascade ends only when a restart table happens to drop all of its work, or at the restart storm limit. 2026-11-19 19:12 UTC: gen 0 blamed chromium, then deqp-vk's spinning queue was collateral at gens 1, 3-7 and 10-12, and the storm limit stopped the GPU for every client. 2026-11-20 15:03 UTC: gen 0 blamed t3code, deqp-vk's queue was collateral at gens 2 and 4. Now a restart that blames a render pair's spared work as collateral marks that pair with its recovery generation (Pair::note_collateral). A later restart that blames the marked pair again, with none of its work retired in between, finds the hang its own, and the pair's VM is guilty. A retirement of the pair's work clears the mark, so a bystander that makes progress between blames stays collateral. The mark lives on the pair, not the QID, and Pair::bind_owner drops it when it binds the pair in place to another owner (rebound_collateral): a previous owner that closed without retiring anything must not make the next owner's first blame its second. A rebind for the same owner keeps it, and so does the owner's close, since an exited culprit's spared work stays published. A retirement on another queue of the same VM does not clear it, or a culprit with a second, healthy queue would stay immune. Compute queues keep the old rule. The cost for a bystander blamed collaterally twice with nothing of its blamed pair retired in between: its VM is poisoned, where today its failure stays non-sticky. Its client saw a lost device at both blames. The new cases replay a stateful cascade through classify(): the 2026-11-19 and 2026-11-20 15:03 cascades, a culprit blamed first, a bystander retiring between blames, a retirement on the culprit's other pair, and a pair rebound in place to a new owner. All but the culprit blamed first (unchanged behaviour) fail without the part they cover. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
…ilty A spared render pair blamed a second time with none of its work retired in between turns its VM guilty, but nothing failed that VM. The culprit's commands had all failed already, without poisoning it: restarts before listed them as interrupted while its VM was innocent, and the first, collateral blame failed its oldest. Failing them again changes nothing (Pair::quarantine skips failed work), so no FailedOwned, no terminal and no VmStatus::record followed. With its status clear, a restart that only drops its work is not forgiven, and the closed or open culprit is never killed. On 2026-11-20 17:52 UTC (m4.175) the first three restarts blamed chromium's GPU processes, deqp-vk's spinning pair turned guilty at its second blame, and still 7 of 8 restarts counted before a restart table happened to drop all of deqp's work. So classify() records the failure itself for the VMs that a repeated collateral blame finds guilty, after leftover judged this restart on their state before it. Nothing later in the same restart forgives: classify_work and the settle steps go by class and recovery_guilty, and the status only keeps the failed VM's work from replays and new submissions. Not on M5: the runtime's collateral hooks (and with them the previous change) are off there, so an M5 classify is as before. M5 takes published work back through its recovery target and has not been tested with this. The test stand-in now keeps a pair's work failed once a restart listed it or a blame failed it, and does not fail it again, as the queues do. The new case replays the m4.175 cascade, render attribution included: 5 counted restarts, then forgiven ones. Without the record, it and the four culprit and bystander cases before it fail. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
4f5c986 to
9a1843f
Compare
|
Rebased onto integration/aurora 110861f; head is now
The J616s hang row comes on our next test kernel. Assisted-by: LLM (Claude:Opus 5.5) |
|
Checked the rebase to 9a1843f with a range-diff against 4f5c986. Commits 2 and 3 are unchanged; commit 1 only picks up the new task-stage-order context in No new points. Approval still stands once the J616s hang row is posted at this head (unchanged ask). Assisted-by: LLM (Claude:Opus 5.5) |
|
J616s hang row: FAIL. Kernel: our combined test kernel m4.179, which carries this series at r4 (the same code as 9a1843f minus the merge with #2500, which m4.179 doesn't have). Same 7 runs. In runs 2-4 and 6 the firmware blamed deqp first: 1 recovery, only deqp failed. Run 5 passed. In runs 1 and 7 the first blame landed on a bystander: t3code in run 1, and t3code then Hyprland in run 7. Each time it was reason 0 with both fault banks clear. The bystander's started render was failed as guilty, and Hyprland lost its device, which ended the session. Root cause is in the reason-0 path. Attribution returns Second issue, from run 1: after the t3code blame, 16 restarts blamed deqp. The kernel closed deqp's scheduler at gen 3, then 14 restarts were forgiven as dropped work of a failed VM, and deqp's work was never killed (0 kills). Next: a diagnostic in our test kernel that logs, per recovery, every running pair's front render (VM, tiler start, fragment end, and whether the firmware blamed it). Then we pick a fix on that evidence. I've updated the description to match and moved the PR to draft until then. Assisted-by: LLM (Claude:Opus 5.5) |
|
Still working on this, so the PR stays in draft. A fix for the bystander-first blame is written and passes KUnit and the g17 host tests. It is not on this branch yet. A blame that only the firmware gives, with no slot, pass-record or earlier-guilt evidence behind it, is now collateral the first time: the blamed command fails and the VM stays usable. The VM becomes guilty when its render pair is blamed again before any of its work retires. Queues that keep no collateral mark (compute queues, M5) stay guilty at once, as before. A real culprit costs one more restart. In the run 7 shape, t3code and Hyprland each lose one command, and only deqp is failed. It goes on this branch once the hang row passes with it on hardware. The second issue from run 1 (deqp's work not killed after its close) is separate and still open. Assisted-by: LLM (Claude:Opus 5.5) |
G17 recovery: stop a hung client's work from taking the GPU down for every client. This does not hold yet when the firmware's first blame lands on a bystander's started render: that bystander is still failed as guilty (see Not done). Five changes, all for the 25G83 firmware on the M4 Pro (T6040). M5 is excluded from the kill and the attribution changes.
1. Kill a closed guilty context instead of waiting for its work. A recovery found a client's render work guilty and failed its VM. The client exited, but its work stayed published. On 25G83 the host cannot take published groups back; only a kill of the context unlinks them, and that kill never came:
kill_route()gave no route to a pair that holds a started group with never-started groups behind it.kill_unsafe()held any kill while another client rendered, for up to 5 s.Each restart reached the hung group again, about every 83 ms, until the storm limit stopped the GPU. Now a quarantined pair of a closed owner, with all its work published and its VM
recovery_guilty, is killed at once. This applies only after a restart since the close, so a guilty client's healthy queued groups can still retire on their stamps. Its groups go only after the kill is done and a later restart has run. At detach the pair parks if its rings were consumed; otherwise it is kept out of service until the processors stop. debugfs counts kept pairs (kept_guilty_pairs=).2. Log the restart table of each recovery in one line: the record count, then the first 24 records as
q<qid>:<stamp>:<flags>/<match>.3. Close a guilty failed VM's queue for a client that keeps it open. The kill in 1 needs a closed queue. A client that ignores
VK_ERROR_DEVICE_LOSTkeeps its guilty work published. A VM that a recovery found guilty and whose status recorded the failure can't run anything again, because every submission, install and publication checks that status. So the kernel now closes its queue on the client's behalf, asrelease_queuewould, and logsscheduler N closed for its open client.State::owner_released, checked inacquire_renderandtry_acquire_renderunder the pool lock). The client of a kernel-closed queue may still publish early once its drained pair left quarantine; taking that pair back, or claiming a sibling, would clear its released bit with nothing left to release it. Owner IDs are never reused.4. Blame a spared culprit's hang on it the second time.
classify()treats a blame on a queue whose oldest work an earlier recovery spared as collateral, not as guilt. When a cascade's first restart blames a client that the spinning culprit starved, the culprit's work is spared, and every later blame on it is collateral. The culprit's VM then never turns guilty: no forgiveness, no kill. Now a restart that blames a render pair's spared work as collateral marks that pair. A later restart that blames the marked pair again, with none of its work retired in between, makes its VM guilty.5. Fail the culprit's VM when that repeated blame finds it guilty. The culprit's commands had all failed already without poisoning it: earlier restarts listed them as interrupted while its VM was innocent. Failing them again changes nothing, so
classify()records the failure itself. It does so after the restart's forgiveness decision, so the restart that finds the VM guilty still counts.Tested on the J616s (M4 Pro, 48 GiB, 25G83)
All five run in our daily kernel (m4.176). The hardware runs used one deqp-vk
memory_modelcase whose fragment shader spins, guarded, beside a drawing desktop:A first blame on a bystander's started render is not handled (m4.179 runs 1 and 7): the bystander is failed as guilty, so the desktop does not survive that case. After such a blame, 4 and 5 did run on hardware in m4.179 run 1 (deqp turned guilty and the kernel closed its queue at gen 3), but the kill in 1 never followed. In the m4.176 run the restart dropped deqp's work first. We can't force the firmware to blame a particular client.
integration/aurora110861f. Since drm/asahi: g17: keep the GPU running for other clients when one client's commands hang or restart the firmware #2500,classify()also returns whether the restart is charged to its guilty clients. In the rebase, that return and this series'generationparameter are merged, and the poison of a repeat culprit (5) runs before drm/asahi: g17: keep the GPU running for other clients when one client's commands hang or restart the firmware #2500's per-VM command count. Neither depends on the other: the count covers every active command whatever the VM's error. The rest of the rebase is context only.CONFIG_UCLAMP_TASK), no failures.counts_idle, the kept-slot hold, the table line and the first close.classify(): the 2026-11-19 storm (4 counted restarts instead of 8), the m4.174 and m4.175 runs, a culprit blamed first, a bystander that retires between blames, a retirement on the culprit's other pair, and a pair rebound to a new owner. All but the culprit blamed first (unchanged behaviour) fail without the part of the change they cover.tools/asahi/run-host-tests.py --only g17: 97/97 passed. The harnesses that compile the changed code are updated, with new mutations for the guilty kill route, a second close, a close that counts before its teardown entry is reserved (a failed allocation, then the retry), the kernel's close of a failed owner (a failed reservation retried without aborting the pass; a failed release after the latch fails it), and a released owner asking admission for its pair again.Not done
render_culpritmoves the blame only off an unstarted render (pass == [0, 0]) with a single running VM. The bystander's render had its tiler start written and deqp was running, soclassify()fails the bystander's VM as guilty. This predates the series (same shape on m4.174 and m4.175), but here it ends the session when the bystander is the compositor. G17P writes only tiler start and fragment end per render, so a started culprit and a started, starved bystander look the same from the blamed pair alone. Next: a diagnostic in our test kernel that logs every running pair's front render (tiler start, fragment end, firmware blame) per recovery, then a fix chosen on that evidence.killed: 0. Not yet explained.Assisted-by: LLM (Claude:Opus 5.5)