Skip to content

drm/asahi: g17: kill a hung client's work instead of letting it take the GPU down - #2504

Draft
jgoyvaerts wants to merge 5 commits into
aurora-silicon:mainfrom
jgoyvaerts:m4pro/g17-guilty-exit-kill
Draft

jgoyvaerts wants to merge 5 commits into
aurora-silicon:mainfrom
jgoyvaerts:m4pro/g17-guilty-exit-kill

Conversation

@jgoyvaerts

@jgoyvaerts jgoyvaerts commented Nov 20, 2026 •

Copy link
Copy Markdown

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_LOST keeps 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, as release_queue would, and logs scheduler N closed for its open client.

  • Only the first close of a context counts. The client's own close later leaves the firmware side alone, because a second teardown entry after the reclaim would release the scheduler twice.
  • 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 the failure, goes on with the other failed owners and retries at the next service pass. An error after that, once the context counts as closed, fails the event service and stops the device, as the client's own close does, since no later close would release the owner.
  • Admission gives no lease to an owner whose pairs are released (State::owner_released, checked in acquire_render and try_acquire_render under 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.
  • The scheduler release, and with it the context reclaim and the detach, waits for the client's own close.
  • Only render slots are scanned, so a compute-only queue of such a VM stays open.

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.

  • The mark lives on the pair, not the QID. It is dropped when the pair is rebound in place to another owner, and kept through the owner's close.
  • A retirement on another queue of the same VM doesn't clear it.
  • Compute queues and M5 keep the old rule.
  • Cost: a bystander that is blamed collaterally twice, with nothing retired on its blamed pair in between, now has its VM poisoned, where today its failure stays non-sticky.

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_model case whose fragment shader spins, guarded, beside a drawing desktop:

Kernel Shape Result
1+2 (m4.173), run 1 firmware blamed deqp first; table listed all its work 1 recovery, kill path not needed
1+2 (m4.173), run 2 first table had none of deqp's work (the 11-19 storm's shape) deqp killed at gen 4; 32 groups released after the next restart; pair parked. 4 recoveries in 270 ms, only deqp failed
+3 (m4.174) first blame on a bystander (t3code) kernel closed t3code's open queue cleanly; deqp's VM never turned guilty (what 4 fixes)
+3+4 (m4.175) first blames on Chromium's GPU processes deqp turned guilty but was never failed (what 5 fixes): 8 recoveries, 7 counted, ended by a restart table that dropped its work
+3+4+5 (m4.176) firmware blamed deqp first 1 recovery; kernel closed deqp's still-open queue; the table dropped its work
r4 (m4.179), 7 runs runs 2-4 and 6: firmware blamed deqp first; run 5 passed; runs 1 and 7: first blame on a bystander, reason 0, fault banks clear runs 2-4, 6: 1 recovery, only deqp failed. Run 1: t3code's started render failed as guilty; then 16 restarts on deqp, its queue closed at gen 3, 14 restarts forgiven, its work never killed. Run 7: t3code, then Hyprland failed as guilty; Hyprland lost its device and the session ended. Row failed
G17: GPU recovery (reason Some(0)): firmware blamed queue 101, failing its oldest render
asahi: GPU work of a client failed (EIO, reported at g17/runtime.rs:1499, client deqp-vk[144042]); the client sees a lost device
G17: scheduler 19 closed for its open client at recovery gen 1: a GPU recovery failed its VM as guilty

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.

  • Base: integration/aurora 110861f. 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' generation parameter 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.
  • KUnit on this branch: 756 tests, 755 passed, 1 skipped (needs CONFIG_UCLAMP_TASK), no failures.
    • New cases cover the kill rule, the sighting latch, counts_idle, the kept-slot hold, the table line and the first close.
    • A stateful stand-in replays whole cascades through 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

  • A first blame on a bystander poisons the bystander (reason 0, fault banks clear, another VM running). render_culprit moves 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, so classify() 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.
  • No kill after the kernel's close in a long cascade (m4.179 run 1): 16 restarts on deqp after the bystander blame, its queue closed at gen 3, 14 restarts forgiven, killed: 0. Not yet explained.
  • The bystander cost of 4: a client blamed twice as collateral without retiring anything on that pair is poisoned. That includes the compositor, which is a GL client without robustness.
  • The restart budget: if a culprit's later restart tables don't list its commands, the restarts after its guilt count once drm/asahi: g17: keep the GPU running for other clients when one client's commands hang or restart the firmware #2500's charge for that culprit runs out (one per command it held), and the close and kill need about two more. That's tight against the limit of 8 when the first blames land on bystanders. The cascade cases' counts model only the forgiveness of leftover restarts (4, 5), not drm/asahi: g17: keep the GPU running for other clients when one client's commands hang or restart the firmware #2500's charge, which covers the restarts before it.
  • Other SoCs and firmware: not tested on the M4, the M4 Max (including 26B123), the A18 Pro or M5.

Assisted-by: LLM (Claude:Opus 5.5)

@jgoyvaerts
jgoyvaerts force-pushed the m4pro/g17-guilty-exit-kill branch from 0868df5 to f2f239a Compare November 20, 2026 20:43
@jgoyvaerts jgoyvaerts changed the title drm/asahi: g17: kill a closed guilty context instead of waiting for its work, and log each restart table drm/asahi: g17: kill a hung client's work instead of letting it take the GPU down Nov 20, 2026
@jgoyvaerts
jgoyvaerts force-pushed the m4pro/g17-guilty-exit-kill branch from f2f239a to 54e48a2 Compare November 21, 2026 06:14
@jgoyvaerts

Copy link
Copy Markdown
Author

Commit messages only, for the pre-PR checklist: the commits no longer carry Assisted-by (item 4), and the disclosure is now the PR body's last line. The tree is identical to f2f239a3b5 (git diff f2f239a3b5 54e48a2bfe is empty). New head 54e48a2bfe.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown

Blockers: 1.

Checked the new close latch (Context::note_closed/note_open_client), close_failed_owners, the guilty kill route and its release proof (restarted_since_kill, guilty_kill_done), the collateral mark in classify() and the keep path in detach_context. Keying on is_m5() is the firmware protocol profile, not a chip check, so that is fine.

  1. drivers/gpu/drm/asahi/g17/runtime/compute_exit.rs:443-452 and runtime/backend.rs:110-124: the first-close latch is taken before the fallible part of the close. teardown.close() can fail (teardown.rs:187, insert allocates); then release_compute, release_render and admission.release_owner never run, yet closed_generation is already set. The client's own close later sees note_closed() return false and skips the whole block, so the owner's slots, admission and teardown entry are never released. In close_failed_owners the ? also aborts the rest of that service pass (it runs at compute_exit.rs:213, before the kill retries). Before this change a failed close could be retried by the next close; now it cannot. Do the fallible insert first (reserve the teardown entry, then latch), or clear closed_generation again on any error so the client's close redoes it, and in close_failed_owners log and continue instead of returning.
  2. Nit: context.rs:220 says closed_generation is the generation "at this context's latest close", but close_once keeps the first (and the commit relies on that). Fix the comment.

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, kept_guilty_pairs= stays bounded and is reported, 0 new kernel errors, 0 failed units. Also one 25G83 M4 Max (J616C) boot running the same case, since the change applies there too.

Assisted-by: LLM (Claude:Opus 5.5)

@jgoyvaerts
jgoyvaerts force-pushed the m4pro/g17-guilty-exit-kill branch from 54e48a2 to 3efdb5d Compare November 21, 2026 16:52
@jgoyvaerts

Copy link
Copy Markdown
Author

Fixed in 3efdb5d8e2. Only commit 3 changed, and its message now explains the new order.

  1. The close now latches only after its teardown entry is reserved. release_queue checks Context::is_closed() first (backend.rs:110), runs teardown.close(), and only then calls note_closed() (backend.rs:118). close_failed_owners runs one close per owner through close_for_open_client (compute_exit.rs:458) in the same order. If a close fails, it logs the error and continues (compute_exit.rs:448), so the service pass is no longer aborted (compute_exit.rs:213). A close that failed on the insert leaves the context open, and the next close redoes all of it.
  2. The comment at context.rs:220 now says "first close".

Testing: arm64 defconfig + asahi.config build of drivers/gpu/drm/asahi, with no new warnings. KUnit on arm64 qemu: 737/739; the only failure is apple-isp-hw.isp_test_sensor_sysfs, which also fails on integration. run-host-tests.py --only g17: 94/94. g17-admission-order-tests.py has a new case, failed_close_is_redone (line 725): the teardown push fails, the context stays open and nothing is released, then the retry reserves the entry and releases the owner. A new latch-before-close mutation restores the old order, and the test catches it.

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)

@RyanTheTide

Copy link
Copy Markdown

Re-review of 3efdb5d: Blockers: 1.

Earlier points:

  • Latch before the fallible teardown insert: resolved. release_queue now checks is_closed() (runtime/backend.rs:110), reserves the teardown entry, and only then calls note_closed() (backend.rs:118); close_for_open_client uses the same order (runtime/compute_exit.rs:458-460). failed_close_is_redone and the latch-before-close mutation cover it.
  • Nit on the closed_generation comment: resolved (context.rs:220).

Since then (only the third commit changed; I diffed the old and new heads):

  1. drivers/gpu/drm/asahi/g17/runtime/compute_exit.rs:446-450, 462: close_failed_owners now logs and continues on every error from close_for_open_client, but only the teardown reservation fails before the latch. release_compute(owner)? at :462 runs after note_closed(), and it can fail: runtime.rs:666-669 (EIO on a missing entry or queue, EINVAL from cancel_unpublished) and queue/compute.rs:1972 (set_owner error). If it does, release_render, sync_render_holds and admission.release_owner never run. The next pass skips the context because it is closed (:443), and the client's later close skips it too (backend.rs:110), so the owner's compute slot and admission are leaked for good, with only a log line. Before this push the ? let the error out of service_compute_exit (:213). The client's own close stops the device on the same error (backend.rs:277). Fix: keep the log-and-continue only for a failed teardown.close(). Have close_failed_owners return Result again and pass any error after the latch up through service_compute_exit, so it fails closed like release_queue. Also, the comment at :447 is accurate only for the teardown case.

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, kept_guilty_pairs= reported and bounded, 0 new kernel errors, 0 failed units. Plus one J616C (25G83) boot running the same case.

Assisted-by: LLM (Claude:Opus 5.5)

@jgoyvaerts
jgoyvaerts force-pushed the m4pro/g17-guilty-exit-kill branch from 3efdb5d to ca0bda2 Compare November 22, 2026 01:59
@jgoyvaerts

jgoyvaerts commented Nov 22, 2026 •

Copy link
Copy Markdown
Author

Fixed in ca0bda2152. Only commit 3 changed, and its message now covers the error path.

close_failed_owners returns Result again, and service_compute_exit passes its error up with ? (runtime/compute_exit.rs:213, :434). Log-and-continue is now only around teardown.close() (:449), the one step before the latch; the next service pass retries that close. After note_closed(), release_compute(owner)? and release_render(owner)? (:457) send any error out of the event service, which loses the device and stops the runtime, the same fail-closed result as the client's own close. The close_for_open_client helper is folded back in, and the comments at :446-448 and :455-456 say which case is which.

Test: g17-kill-route-tests.py now compiles the real close_failed_owners against mock firmware. The new case a_failed_owner_close_is_retried_before_its_latch_and_fails_the_pass_after (line 437) checks three things. A failed reservation leaves that owner open while the pass still closes the other failed owner, and the retry closes it. A failed release_compute after the latch returns Err(EIO) and releases no admission. M5 is never touched. Two new mutations, post-latch-swallowed and reserve-fails-pass, each fail it.

Results:

  • arm64 defconfig + asahi.config, LLVM=1, drivers/gpu/drm/asahi builds clean, with the same 31 baseline warnings and none in the touched files.
  • KUnit on arm64 qemu: 737/739. The one failure is apple-isp-hw.isp_test_sensor_sysfs, which also fails on integration.
  • run-host-tests.py --only g17: 96/96.

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)

@RyanTheTide

Copy link
Copy Markdown

Re-reviewed at ca0bda2: the blocker is fixed. close_failed_owners() returns Result again and service_compute_exit() propagates it (:213). Only a failed teardown.close() before note_closed() logs and continues, and the next pass retries it. Everything after the latch (release_compute, release_render) now fails the service, so the owner's slot and admission can no longer leak behind a closed context. The new host case with its two mutations covers both halves. No new points.

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 DjDeveloperr left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

  1. Permanent render-slot leak when try_render_early races 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 calls admission.release_owner(owner) while the userspace Queue is still open (context.is_closed() == true, context.held_by_open_client() == true, Backend::closed == false), and makes Backend::release_queue skip admission.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) calls admission.pair_drained(slot), clearing state.quarantined on that slot while state.owners[slot] == owner and state.released & (1 << slot) != 0.
    • Unlike admit_render (submit.rs:165-169), Backend::try_render_early (submit.rs:569-580) does not check packet.completion.status().get() != 0 or self.context.is_closed() before calling self.admission.try_acquire_render(self.owner, self.pairs.into(), Request::of(packet)).
    • A Queue::submit that already passed the initial status().get() != 0 check before recovery (or between commands of a multi-command submit) can enter try_render_early -> try_acquire_render:
      • state.refusal(owner) succeeds (owner_quarantine(owner) is now None and owners.contains(&owner) is true).
      • state.acquire(owner, pairs) (admission.rs:202-215) selects the owner's idle slot without checking released, held, or kill_hold, calls take_idle(slot, owner) which clears self.released &= !(1u64 << slot) (admission.rs:173), and when pairs > 1 can also call claim_sibling(owner, pairs) (admission.rs:213) to claim a fresh sibling slot for the already-closed owner with released = 0.
      • render_with_lease then fails immediately with EIO (submit.rs:398) and drops the RenderLease, leaving owners[slot] == owner with released == 0 (and any newly claimed sibling slot with released == 0).
    • When the client later closes its queue, Backend::release_queue sees self.context.is_closed() == true and skips admission.release_owner(self.owner). After detach_context clears held/kill_hold, those slot(s) stay permanently leaked in admission (even across release_retained_owners_after_processor_stop(), admission.rs:803-813, which only clears state.released & !state.active).
    • Fix: Check packet.completion.status().get() != 0 || self.context.is_closed() (or self.admission_open().is_err()) in try_render_early before try_acquire_render, prevent State::acquire / take_idle from reusing or sibling-claiming slots for an owner whose slots are already released, and/or call firmware.queues.admission.release_owner(self.owner) unconditionally in Backend::release_queue (release_owner is idempotent on owners[slot] == self.owner).

Nit

  • drivers/gpu/drm/asahi/g17/queue/render.rs (Pair::guilty_unretired doc comment): still reads "since the context's latest close" instead of "first close" (matching the context.rs:220 fix).

Hardware evidence still owed (§5)

  • J616s run on current head (ca0bda21 / post-fix head), default command line: repeated deqp-vk memory_model hang 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)

@jgoyvaerts
jgoyvaerts force-pushed the m4pro/g17-guilty-exit-kill branch from ca0bda2 to 4f5c986 Compare November 22, 2026 06:09
@jgoyvaerts

Copy link
Copy Markdown
Author

Thanks, the race is real. Fixed in 4f5c986319; only commit 3 changed, and its message now covers it.

I confirmed it in the code: the sleeping path (acquire_render) runs its status and closed check under the pool mutex, after release_owner, so it already refuses. try_acquire_render checks neither, and it has two callers, not one: try_render_early (submit.rs:577) and the direct-slot lookup in render_with_lease (submit.rs:414). Once the drained pair leaves quarantine, refusal passes and acquire takes the owner's released slot back (or claims a sibling), which clears released for good.

Fix chosen: admission itself gives no lease to a released owner. The new State::owner_released (queue/admission.rs:139) is checked in acquire_render (:686, ECANCELED) and try_acquire_render (:746, None), under the same lock release_owner takes. That makes the invariant hold for every lease, whoever asks and whatever it checked before, and it is atomic with the release. The other two options don't get there:

  • Gating try_render_early covers one of the two unchecked callers, and a check outside the pool lock still races the release.
  • An unconditional release_owner in release_queue repairs the slot only at the client's close. A client that keeps its fd open, the case this commit exists for, would hold the pair (and a sibling) until then.

Owner IDs come from a 64-bit sequence and are never reused, so released means closed for good. admits_render doesn't apply the check, so the scheduler's prepare step never waits on such a job, and publication fails it at once.

Nit: Pair::guilty_unretired now says "first close" (queue/render.rs:2622).

Tests:

  • KUnit a_released_owner_takes_no_pair_again (admission.rs:1324): after release_owner, try_acquire_render returns None and acquire_render ECANCELED (both with pairs=2), admits_render is true, the slot stays released, no sibling is claimed, and another owner still takes the pair.
  • Host test in g17-admission-order-tests.py (:279), plus mutation released-owner-retakes, which the test catches.

Results:

  • arm64 defconfig + asahi.config, LLVM=1, drivers/gpu/drm/asahi builds clean: 31 warnings, unchanged, none in the touched code.
  • KUnit on arm64 qemu: 738/740 (1 skip). The one failure is apple-isp-hw.isp_test_sensor_sysfs, which also fails on integration.
  • run-host-tests.py --only g17: 97/97.

The J616s rows (the hang case and the regression check) follow our next kernel build.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown

Checked 4f5c986: State::owner_released() is tested under the pool lock in both acquire_render() (ECANCELED, after the wait loop, so a waiter woken by the release also refuses) and try_acquire_render() (None), which covers both unchecked callers you found and is atomic with release_owner(). Owner IDs never being reused makes "released" final, so there's no false refusal. The new KUnit case pins it. Approved from our side once the J616s hang row is posted (unchanged ask).

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>
@jgoyvaerts
jgoyvaerts force-pushed the m4pro/g17-guilty-exit-kill branch from 4f5c986 to 9a1843f Compare November 22, 2026 21:34
@jgoyvaerts

Copy link
Copy Markdown
Author

Rebased onto integration/aurora 110861f; head is now 9a1843fe1f.

The J616s hang row comes on our next test kernel.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown

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 Pair::quarantine (the guilty_released early return before release_task_order_if_held() is fine, since release_witnessed() has already popped every group of such a pair). In classify() both #2500's charged result and the generation parameter are kept, and poisoning a repeated culprit before the held count doesn't change the charge: Queue::classify and Pair::classify visit every active command whatever its VM's error, so charge_restart() still sees the real in-flight count.

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)

@jgoyvaerts

Copy link
Copy Markdown
Author

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 memory_model spin case beside the drawing desktop, default command line.

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 Firmware, and render_culprit moves the blame only off an unstarted render (pass == [0, 0]) when exactly one VM is running. Both bystanders' front renders had their tiler start written (pass = [x, 0]), and deqp was running too. So the blame stays, and classify() finds the blamed VM guilty and poisons it. This predates the PR (same bystander-first shape on m4.174 and m4.175). But the PR's claim that the desktop stays alive doesn't hold in that case.

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)

@jgoyvaerts
jgoyvaerts marked this pull request as draft November 23, 2026 02:12
@jgoyvaerts

Copy link
Copy Markdown
Author

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)

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.

3 participants