Skip to content

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

Merged
RyanTheTide merged 10 commits into
aurora-silicon:mainfrom
jgoyvaerts:m4pro/g17-guilty-exit-kill
Nov 27, 2026
Merged

RyanTheTide merged 10 commits into
aurora-silicon:mainfrom
jgoyvaerts:m4pro/g17-guilty-exit-kill

Conversation

@jgoyvaerts

@jgoyvaerts jgoyvaerts commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

What: G17 recovery: kill a hung client's work instead of letting it take the GPU down for every client, and stop a firmware blame that lands on a bystander from failing the bystander's VM.
Tested: J616s M4 Pro (25G83) at 1b0abfeb7e03 (on aurora main a851ca0, no other G17 recovery changes): the hang row passes 10/10. 26 recoveries; deqp-vk failed in all 10 runs; of 9 bystander blames none failed or closed a desktop client, and the off-screen renderer took one collateral EIO with its VM kept; 0 storm-limit lines, 0 err-level kernel lines, 0 failed units, no AVC denials. The same row passed 10/10 at b731bf1a34b0 on main 8c6bd8d. KUnit 875/876 (1 skip), every g17 host test passes.
Risk: two-way door · G17P Macs (M4 family on 25G83); M5 is excluded from the kill and attribution paths.
Not yet: one M5 or Neo run at this head; the M4, M4 Max and A18 Pro are untested.

Known limits:

  • With another VM's compute in flight, the pass records can't rule it out, so a started blamed render keeps the firmware's blame, collateral once: the bystander loses one command (EIO), its VM stays usable.
  • A slow innocent render that started just before the hung one is suspected the same way: one EIO, VM kept, guilty only if suspected again before its work retires.
  • A hung culprit now takes one more restart before its VM fails when only the firmware or the pass records name it.
Details

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.

6. Fail a VM only when evidence or a repeat confirms its blame. A timeout restart names the queue the firmware chose. Without slot keys, a bystander whose render had started while waiting behind the culprit's was failed as guilty on the spot; with the compositor that ends the session. Now a blame only the firmware gives (Attribution::Firmware) is collateral the first time: the blamed command fails, the VM stays usable, and its render pair is marked. Blamed again before any of its work retires, the VM is guilty. Evidence (slot identity, the host's pass records, earlier guilt) still makes a VM guilty at once. Compute queues and M5 keep no collateral mark (Queues::marks_collateral), so their unconfirmed blame stays guilty at once, as before.

7. Suspect the oldest running render, never an unstarted one. The host's pass records now pick the suspect: the running render whose tiler started first is taken as the hang, since the others started after it and wait behind it. Its VM's running pairs are suspected (Attribution::Suspects), whether or not the firmware blamed them. A suspicion is not proof (a slow innocent render that started just before the hung one looks the same), so classify() treats it like the firmware's blame: collateral the first time, guilty on a repeat before the pair's work retires. A blamed render that never started is never the hang: with nothing running, or with another VM's compute in flight (which these records cannot see), nobody is blamed (NoCulprit). A VM an earlier recovery found guilty still comes first, as evidence.

Known limits

  • (a) Foreign compute in flight: the pass records can't rule out another VM's compute as the hang, so a started blamed render keeps the firmware's blame, which 6 makes collateral once: the bystander loses one command (EIO, seen as a lost device), its VM stays usable, and it turns guilty only if blamed again before any of its work retires.
  • (b) A slow innocent render that started just before the hung one is the oldest running render, so it is suspected: it can take one EIO (seen as a lost device), with its VM kept, and turns guilty only if suspected again before its pair's work retires. Seen once in the m4.184 row (run 6, the off-screen renderer, which kept rendering).
  • Page faults: drm/asahi: g17: blame GPU page faults on the faulting VM, and see through a stale fault reason #2227's fault_override names the faulting slots' work when it excludes the blamed queue (evidence, guilty at once). A page fault inside the blamed VM stays the firmware's blame, so it is collateral once and turns guilty at its next fault, one restart later than before 6.
  • Restart accounting: a collateral restart has no guilty client, so it counts toward the device's storm limit instead of being charged to a client (drm/asahi: g17: keep the GPU running for other clients when one client's commands hang or restart the firmware #2500). With 7 the culprit is named as evidence in nearly every restart (40 of 41 in the m4.184 row), and a restart with work retired since starts a new window.

Not done

  • 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 seen in the m4.184 row; not yet explained.
  • The bystander cost of 4: a client blamed twice as collateral without retiring anything on that pair is poisoned. 7 makes this rare: a second blame on a bystander behind a running culprit names the culprit instead.
  • Interrupted spared renders are presented once: a spared render that a restart interrupts completes with ECANCELED, and a compositor may show the partly drawn buffer for a frame. Reporting a bystander's first failed command as discarded rather than EIO is a follow-up.
  • Other SoCs and firmware: not tested on the M4, the M4 Max (including 26B123), the A18 Pro or M5.
Evidence

Tested on the J616s (M4 Pro, 48 GiB, 25G83)

Changes 1-5 run in our daily kernel (m4.176); 6 and 7 ran in our test kernels (m4.183, m4.184). 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 1 and 7: first blame on a bystander, reason 0, fault banks clear Run 7: t3code, then Hyprland failed as guilty; Hyprland lost its device and the session ended. Row failed (what 6 and 7 fix)
+6 (m4.183), 2 runs run 2: the firmware blamed quickshell twice behind deqp, the second time on a render that had not started quickshell failed as guilty on the repeat (what 7 fixes)
+6+7, oldest render taken as proof (m4.184), 10 runs 41 recoveries in runs 1-9 (run 10 passed); an off-screen bystander renderer from run 6 on Pass. deqp failed and its queue closed as guilty in every hanging run. The firmware blamed a bystander 18 times (t3code 14, Hyprland 3, the off-screen renderer 1); all 18 were spared and no desktop client was failed. The oldest running render was the culprit in 40 of 41 recoveries. 0 storm-limit lines, 0 err-level kernel lines
+6+7, oldest render only suspected (m4.186), 10 runs 32 recoveries; the off-screen renderer from run 6 on Pass. deqp failed in all 10 runs and its queue was closed in 7. All 9 bystander blames were spared (Hyprland 3, Chromium 3, t3code 2, quickshell 1); the off-screen renderer took one collateral EIO with its VM kept. The oldest running render was the culprit in 31 of 32 recoveries. 0 storm-limit lines, 0 err-level kernel lines, 0 failed units, no AVC denials (no SELinux or AppArmor policy loaded)
this head on aurora main (m4.190), 10 runs 29 recoveries; the off-screen renderer throughout Pass. deqp failed in the 9 runs that hung, its queue closed as guilty and killed at its compute exit in 5. 8 bystander blames spared (Chromium 2, quickshell 2, Electron 1, the off-screen renderer 3); 15 suspects lines, 12 blames lines. The off-screen renderer took one collateral EIO with its VM kept (known limit (a): another VM's compute was in flight). 0 storm-limit lines, 0 err-level kernel lines, 0 failed units, no AVC denials, kept_guilty_pairs=0 throughout
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
  • 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 at a43b5e2d83da: 761 tests, 760 passed, 1 skipped (needs CONFIG_UCLAMP_TASK), no failures. run-host-tests.py --only g17 97/97.
    • 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 (now guilty at its second blame), a confirmed first blame (guilty at once), the m4.179 run 7 bystanders, a bystander that retires between blames, a retirement on the culprit's other pair, and a pair rebound to a new owner.
    • culprit() cases replay the m4.183 run 2 restarts with their tiler starts (deqp named each time, quickshell never), and cover an unstarted blamed render, foreign compute and a VM with several running pairs. They fail on the previous rule. A new case shows an innocent slow render that is suspected once is not failed, while a render suspected twice is.
  • 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.

Regression check at the previous rule (m4.184 row): 0 failed units, 0 err-level kernel lines, 0 storm-limit lines; our kernels load no SELinux or AppArmor policy, so there are no denials to count.

@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
Contributor 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
Contributor

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
Contributor 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
Contributor

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
Contributor 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
Contributor

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
Contributor

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).

@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
Contributor 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
Contributor

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)

@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
Contributor 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
Contributor

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
Contributor 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

jgoyvaerts commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor 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.

@jgoyvaerts

jgoyvaerts commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Updated to 75f27b9645: two commits on top of 9a1843fe1f, same base. This supersedes the fix described in my earlier comment: its repeat rule alone failed on hardware (a bystander blamed twice behind the culprit was failed on the repeat), and the second commit replaces the blame choice with the host's pass records.

  • drm/asahi: g17: fail a VM only when evidence or a repeat confirms its blame: classify() (g17/recovery.rs) treats a firmware-only blame as collateral once; compute and M5 keep first-blame guilt (Queues::marks_collateral).
  • drm/asahi: g17: blame the oldest running render, never an unstarted one: culprit() (g17/runtime/render/recovery.rs) names the VM of the running render with the oldest tiler start; an unstarted blamed render is never guilty (host_fallback maps Some(0) to NoCulprit).

J616s hang row (the same memory_model spin beside the drawing desktop, our combined test kernel): 10/10 runs, 41 recoveries. deqp was failed and its queue closed as guilty in every hanging run. All 18 bystander blames were spared (t3code 14, Hyprland 3, an off-screen renderer 1), no desktop client failed, and the oldest running render was the culprit in 40 of 41 recoveries. 0 storm-limit lines, 0 err-level kernel lines. One known limit, in the description: a slow innocent render that started just before the hung one can take one EIO with its VM kept.

KUnit on this branch 759/760 (1 skip), run-host-tests.py --only g17 97/97. Out of draft.

@jgoyvaerts
jgoyvaerts marked this pull request as ready for review November 24, 2026 16:15
@jgoyvaerts
jgoyvaerts requested review from a team as code owners November 24, 2026 16:15
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) changes-requested A reviewer requested changes (bot) ci-failing A check failed at the PR head (bot) labels Nov 24, 2026
@jgoyvaerts

Copy link
Copy Markdown
Contributor Author

Merged main f7b890d4380e into the branch, pushed normally: new head cf9355f7ee58, on top of b731bf1a34b0.

Conflict: only tools/asahi/run-host-tests.py. g17-kill-route-tests.py keeps this branch's mutation list (a superset of main's), and main's new g17-m5-direct-compute, g17-m5-multiqueue-contention and g17-m5-render-fast-done entries follow it. No driver file conflicted, and the recovery path is unchanged: the branch's diff against main is line-for-line the same as at b731bf1a34b0 (2,833 lines, no +/- line differs).

Checks at cf9355f7ee58:

  • KUnit (arm64): 837 tests, 836 passed, 1 skipped.
  • Host tests: every g17 test passes, including g17-kill-route-tests.py with all 11 mutations. The 29 failures are local only: g15-*, sep-suspend-errors, apple-dcp and test-m3-uapi need the rustup 1.93.1 toolchain, which this machine doesn't have. Plain main fails the same set here.

The J616s hang row at b731bf1a34b0 (10/10 PASS) covers the same driver code. The M5 or Neo row is still open.

@github-actions github-actions Bot added needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) and removed merge-conflict Conflicts with the base branch (bot) labels Nov 25, 2026
DjDeveloperr
DjDeveloperr previously approved these changes Nov 25, 2026

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verified the main merge-forward resolution in tools/asahi/run-host-tests.py: cleanly preserves both main's new M5 host tests and this branch's superset mutation entries with no unintended diff. Holding merge until CI completes green and updated hardware verification clears.

@github-actions github-actions Bot added merge-conflict Conflicts with the base branch (bot) and removed needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 25, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor

This branch conflicts with main again. Could you merge main into it with a normal push (no force push) within 24 hours? After that a maintainer will do the forward merge and merge it once CI is green. Rows carry over if the changed files stay byte-identical.

Conflicts, and how they were resolved:

- g17/context.rs: main replaced the compute_binding_hint flag with the
  compute_bindings count and added compute_ordinal. Both are kept, next
  to this branch's kill_seen, closed_generation and
  closed_for_open_client fields. The branch never used the old flag.
- g17/queue/admission.rs: main's admits_render() takes the pairs the
  owner asks for. This branch's a_released_owner_takes_no_pair_again
  test now passes the 2 pairs its owner asks for elsewhere.
- tools/asahi/g17-admission-order-tests.py: the held fixture extracts
  both this branch's owner_released() and main's set_owner().

No behaviour changes: set_owner() is the single writer of owners[], and
try_acquire_render() still checks owner_released() before take_idle().

Signed-off-by: Jonathan Goyvaerts <[email protected]>
@jgoyvaerts

Copy link
Copy Markdown
Contributor Author

Merged main b14959b819cf into the branch, pushed normally: new head 1b0abfeb7e03, on top of cf9355f7ee58.

Conflicts, and how they were resolved:

  • g17/context.rs: main replaced the compute_binding_hint flag with the compute_bindings count and added compute_ordinal. Both are kept, next to this branch's kill_seen, closed_generation and closed_for_open_client fields. The branch never used the old flag.
  • tools/asahi/g17-admission-order-tests.py: the held fixture extracts both this branch's owner_released() and main's set_owner().
  • g17/queue/admission.rs: this one was not a textual conflict. Main's admits_render() now takes the pairs the owner asks for, so this branch's KUnit test a_released_owner_takes_no_pair_again passes the 2 pairs its owner asks for in the calls just above it.

No change to the recovery path. Apart from that test argument, the branch's diff against main is line for line the same as at cf9355f7ee58. Main's set_owner() is now the single writer of a slot's owner, and try_acquire_render() still checks owner_released() before take_idle().

Checks at 1b0abfeb7e03:

  • KUnit (arm64): 876 tests, 875 passed, 1 skipped.
  • Host tests: every g17 test passes. The 29 local failures are toolchain-only and also fail on plain main here.

The J616s hang row at b731bf1a34b0 (10/10 PASS) covers the same driver code. The M5 or Neo row is still open.

@github-actions github-actions Bot added needs-review No approving review from Core or Omarchy Mac yet (bot) ci-failing A check failed at the PR head (bot) and removed merge-conflict Conflicts with the base branch (bot) ci-failing A check failed at the PR head (bot) labels Nov 26, 2026
@jgoyvaerts

Copy link
Copy Markdown
Contributor Author

J616s (M4 Pro) hang row at 1b0abfeb7e03: PASS, with the same known caveat as at b731bf1a34b0.

Kernel: our m4.195 test kernel, booted 2026-11-26 19:06 UTC. It is aurora main a851ca0edfc9 with this PR at 1b0abfeb7e03, #2228 at 5c529c9e97e5 and #2724 at a64f33ae2157, plus our carried patches, but none of our own G17 recovery or attribution patches. The run was 19:09-19:14 UTC on the normal Hyprland desktop, default command line.

  • All 10 runs completed. There were 26 recoveries, and deqp-vk hung and was failed (EIO, DeviceLost) in every run. In 4 runs its scheduler was closed for its open client.
  • The firmware blamed a bystander 9 times: quickshell 6, t3code 1, and the off-screen tvbstress bystander 2. Quickshell and t3code were cancelled and replayed. No desktop client failed or was closed.
  • This PR's code at work: 14 "suspects queues" lines and 10 "blames queues" lines.
  • Regression checks: 0 "storm limit" lines, 0 err-level kernel lines, 0 failed units (system and user), 0 new AVC lines. kept_guilty_pairs was 0 before and after every run.

Caveat (the foreign-compute case in Known limits, as in run 8 at b731bf1a34b0): in run 7, generation 19, the firmware blamed the off-screen tvbstress (queue 64), and no suspects line could rule it out. It took one EIO. Its VM was kept, and it kept rendering (2,764 frames, until we stopped it). The next recovery suspected and blamed deqp-vk.

Seen on the desktop, outside this PR: one visible pink flicker in t3code during generations 19-20, which lasted until the window redrew. The kernel had failed a spared render that a recovery interrupted after it started ("interrupted by a GPU recovery after it started; failing it"), and the client presented that frame. That path is main's, not this PR's; it is tracked as its own follow-up.

Not covered: M5, Neo, M4 and M4 Max.

@github-actions github-actions Bot removed the needs-hw-row No hardware row at the PR head (bot) label Nov 26, 2026

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verdict at 1b0abfeb: code OK; merge after the Neo or M5 row at this head.

Blockers: none in the code. The shared-code regression row is still owed: your "Not yet" lists one M5 or Neo run at this head, and the merge policy needs it for shared G17 code. The J616s 10/10 row covers the target.

Checked

  • Since Dj's last approval at cf9355f7, the only change to the PR's own diff is one test call, admits_render(1, 2, None). It follows main's new pairs argument (admission.rs on main has the same signature). The rest is merges of main.
  • The KUnit jobs marked failed at this head were cancelled after 47 min (runner limit), not real failures; I re-ran them.

@RyanTheTide

Copy link
Copy Markdown
Contributor

1b0abfeb7e03 Neo (J700, apple,t8140 / Apple A18 Pro (G17P B1), default cmdline, guarded one-shot) PASS: run-host-tests.py --only g17 227/227 PASS; booted 7.3.0-aurora-pr2905-pr2504-1b0abfeb cleanly (aurora 482600000.gpu RTKit v12 OK), Enforcing, 0 failed units, 0 AVC, 0 kernel err lines (0 GPU faults/recoveries/storm lines), GL (glmark2-gbm --off-screen Zink/Borealis 10368 + 10110) + VK (vulkaninfo + deqp-vk J=1 19/19: api.smoke.* 8/8, compute.pipeline.basic.empty_shader 1/1, memory_model.shared.scalar_types.* 10/10) all PASS; 7.3.0-aurora-fleet89 restored.

@github-actions github-actions Bot removed the ci-failing A check failed at the PR head (bot) label Nov 27, 2026

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Merge-train status at 1b0abfeb: not mergeable yet. The full adversarial review (it's 1.5k lines of recovery code) will come once the missing row is in, so it's done against the head that will merge.

Missing before merge: the run the body lists under Not yet, at this head, on the other G17 generation: Neo (A18 Pro) or an M5. Kill and attribution are shared G17 code, and the body says M5 is excluded but the A18 Pro is untested. We can run the hang row on our Neo if you'd like. Please say so here.

Seen so far: J616s 10/10 hang rows at this head (26 recoveries, no desktop client lost, one collateral EIO with the VM kept), KUnit 875/876, and g17 host tests pass. The known limits are stated plainly.

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verdict at 1b0abfeb: approve.

Blockers: none.

Checked

  • Code: since Dj's last approval, the only change is one test call adapted to main's admits_render(owner, pairs, req) (my comment above).
  • Rows at this head: J616s hang row 10/10 (target), and Neo J700 regression row PASS on the shared G17 path (g17 host tests 227/227, boot, GL + VK smoke, 0 GPU faults or recoveries, 0 failed units).
  • CI: 18/18 green after re-running the cancelled KUnit jobs.
  • The M4 Max and M5 stay listed under "Not yet"; follow-up rows don't hold the merge.

@RyanTheTide
RyanTheTide merged commit 76123f3 into aurora-silicon:main Nov 27, 2026
29 of 59 checks passed
@RyanTheTide

Copy link
Copy Markdown
Contributor

Correction to my merge-train hold above: the Neo (J700) row at 1b0abfeb was already posted (03:12Z) when I wrote it. I missed it. The merge was fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:gpu Area from CODEOWNERS (bot) blast:m4 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants