Skip to content

drm/asahi: g16: fail unfinished renders on a failed render's pair - #4032

Merged
DjDeveloperr merged 2 commits into
mainfrom
fix/g16-recovery-pair-renders
Dec 4, 2026
Merged

DjDeveloperr merged 2 commits into
mainfrom
fix/g16-recovery-pair-renders

Conversation

@DjDeveloperr

Copy link
Copy Markdown
Contributor

What: After a GPU recovery, g16 could report success for a render that never ran: a render of another process queued on the same TA/FS queue pair as the one that hung or faulted. Fail those renders.

Tested: No hardware run at the head of this PR. Local checks at a4e1852dc19d: arm64 W=1 build of drivers/gpu/drm/asahi (clang) with the same warnings as main, run-host-tests.py --only asahi-m4 1/1 and --only g16 2/2, checkpatch --strict clean; the new selftest fails without the driver change.

Risk: two-way · M4 (T8132) and M3 (T8122, T6030), which share the g16 backend. After a hang or a fault, a render of another VM that shares the failed render's queue pair now ends with an error instead of a possible false success. Other pairs and compute keep their behaviour.

Not yet: J773g and J516s rows at the head of this PR: (1) one process hangs a render while a second process shares its queue pair (more rendering processes than pairs) and reads its image back: an error is right, success with a missing image is wrong; (2) the same with the second process on its own pair: it must keep running; (3) VK-CTS robustness and GPU-fault groups, base against head.

Details

At the phase-1 halt of a firmware recovery, g16 fails every flight the firmware's affected-work snapshot names, and every unfinished flight of the VM whose fault is latched. Any other unfinished render is only suspect, and it still retires on its ordinary receipt after the resume.

That receipt does not prove the render ran. On the J773g under macOS 26B123, a render command buffer queued behind one that hung never ran (no GPU time, no fragments). After the recovery its notifier record had still counted all of its works, held its last FS work and was unlinked, and the FS service stamp had moved to its target, which is what a normal completion writes. Metal fails such a buffer as an innocent victim.

recovery_prepare_suspects() now collects the queue pairs of the renders the recovery fails, named by the snapshot or owned by the faulting VM, and also fails every render flight on those pairs that was unfinished at the halt. The macOS measurement covers one TA/FS queue pair, so renders on other pairs stay suspect as before.

Evidence

The publication selftest runs the production function for: a render of another VM unfinished on the failed render's pair, with and without a latched fault; the same on another pair; a recovery that fails no render; renders that finished before the halt.

Checks ran on main d1ae4f292b93 plus this branch.

At the phase-1 halt of a firmware recovery, g16 fails every flight the
firmware's affected-work snapshot names, and every unfinished flight of
the VM whose fault is latched. Any other unfinished render is only
suspect: it still retires on its ordinary receipt after the resume.

That receipt does not prove the render ran. On the J773g under macOS
26B123, a render command buffer queued behind one that hung never ran
(no GPU time, no fragments), yet after the one recovery its notifier
record had counted all of its works, held its last FS work and was
unlinked, and the FS service stamp had moved to its target: what a
normal completion writes. Metal fails such a buffer as an innocent
victim. A hang latches no fault, and a render of another VM on the same
TA and FS queues is not of the faulting VM, so g16 can report success
for render work that never ran.

Fail every render flight that is unfinished at the halt on the TA and FS
queue pair of a failed render, whatever its VM. Renders on other pairs
and compute keep their rule.

The publication selftest covers a render of another VM unfinished at the
halt on the failed render's pair, with and without a latched fault, on
another pair, a recovery that fails no render, and renders that finished
before the halt.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners December 3, 2026 01:49
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) blast:m3 Macs affected, from Merge risk (bot) blast:m4 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 3, 2026
@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Merge readiness at 8e659f98: ready to merge

Check Detail
CI at head ok 9 checks passed
Review ok approved by RyanTheTide
Requested changes ok none
Hardware row at head ok comment at 8e659f98
Conflicts ok none
PR text ok Risk: two-way · M4 (T8132) and M3 (T8122, T6030), which share the g16 backend. After a hang or a fault, a render of another VM that shares the failed render's queue pair now ends with an error instead of a possible false success. Other pairs and compute keep their behaviour.

Areas: area:gpu
Merge: gh pr merge 4032 --merge (Owners and Core through the bypass: add --admin).

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

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

Reviewed a4e1852. The recovery snapshot limits collateral failure to unfinished renders on a pair with a failed render. The second pass leaves completed renders, compute and other pairs out of the new rule. The reported host regression distinguishes false success. Hardware rows are pending.

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J516s (M3 Pro) g16batch row: FAIL (judge exit 1). Except for one CPU-time flag that looks like noise, every failure also happens on base.

For this PR (hang step): case 1 is clean in every round on both arms. In case 2, the other client still gets a lost device in 2 of 3 rounds, the same as base.

Kernel 7.3.0-g16batch, base c09b61228e62, batch tip 95212b64f7eb (#4032 #4033 #4034 #4035; #4056 #4057 in both arms). ABBA, one boot per slot, arm checked by the aurora.ko build id: a1 base d006ff51, b1 batch a9e3e314, b2 batch dd5516d2, a2 base 01025e37.

Same on both arms:

  • VK-CTS: command_buffers 60 pass / 0 fail, draw 4508 / 0, robustness 2183 / 0. 0 tests differ.
  • Stream gate: 6 bad root addresses, 0 accepted. +4, +2 and the kernel range get EINVAL, unmapped gets ENOENT (base does the same). The next clean run is valid.
  • Hang case 1 (9 clients + a hung render): bad 0, err 0 in all 6 rounds.
  • 48 clients open/close: 0 failed. pb kept 4-7 epochs, the same range on both arms. s2idle 1/1 on a1 and b1.

Why the judge says FAIL:

  • Long jobs: the first 2.5 s job ends in a GPU firmware recovery (fault_scan: GPU powered down, event 0x71) and a lost device. This happens in all four slots, on base and batch alike. The 1 recovery and 5 GPU kernel lines before the hang step come from this. The J516s can't judge the long-job check.
  • Hang case 2 (one client + a hung render): the other client gets a lost device in 2 of 3 rounds on batch, and in 2 of 3 on base. The batch doesn't make it worse, and it doesn't fix it on the J516s.
  • Speed: render.light d8 submit_cpu_us median went from 4.45 to 6.91 µs (+55 %). At d8, us_per_submit is +0.6 % and p95 is 17.8 / 17.2 µs. The other submit_cpu_us rows swing 30-40 % both ways (d32 -41 %, render.mdi +33 %), so this looks like noise. The slot pair was not re-run. gpu_us is within 0.6 % on every row. us_per_submit is within 2.6 %, except render.mdi d1 at +7.2 % (noise 13.5 %).

The J516s is back on its stock kernel (7.3.0-f3822, boot 98468598), and the kit is removed from it.

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J516s render.light d8 recheck (batch merge tip 95212b64f7eb against base c09b61228e62, one boot each: base 70f9b303, batch 6a96f1dc, 5 repeats per core): pinned to a P-core, submit_cpu_us is 4.88 base and 4.88 batch; pinned to an E-core, 7.67 and 7.58; unpinned, 4.75 and 4.92 (+3.6 %); us_per_submit within 1 %; 0 new faults. The earlier +55 % (4.45 to 6.91 µs) is the submit thread landing on an E-core (E/P = 1.56x), not this change, so the d8 flag is cleared. Evidence work/g16batch-20261203/results/j516s/d8-recheck/.

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

The J516s run lost the different-pair client on both arms, so it did not prove isolation. The remaining row at a4e1852dc19d is the J773g control versus batch run. Confirm that a guilty render with unfinished same-pair work returns errors, with no falsely successful output, and that an innocent client on a verified different pair survives. Record the pair placement and the matched robustness and fault checks.

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed needs-hw-row No hardware row at the PR head (bot) labels Dec 3, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J773g (Mac mini M4, T8132, G16G B0) g16batch ABBA hardware row — kit VERDICT FAIL (INCOMPLETE for #4032 proof / no regression vs base)

Tested in g16batch-20261203 (SHA256SUMS 5d61509ed258dd96, kit.sh --check 30/30 ok, kernel 7.3.0-g16batch, ABBA slots a1/b1/b2/a2, base c09b61228e62 vs batch 95212b64f7eb including #4032 at exact head a4e1852dc19d).

  • Hang test (a2 base vs b2 batch):
    • Case 1 (9 innocent render clients + 1 hung render, 3 rounds):
      • Base a2: ok=4170/4023/4050, bad=0, err=0 (guilty_rc=42, innocent_rcs=all 0).
      • Batch b2: ok=4174/4014/4042, bad=0, err=0 (guilty_rc=42, innocent_rcs=all 0).
      • Neither arm reproduced a bad > 0 stale-image signal in case 1.
    • Case 2 (1 innocent render client + 1 hung render, 3 rounds):
      • Base a2: r1 ok=909 bad=0 err=1 (rc=42), r2 ok=4198 bad=0 err=0, r3 ok=910 bad=0 err=1 (rc=42).
      • Batch b2: r1 ok=4213 bad=0 err=0, r2 ok=911 bad=0 err=1 (rc=42), r3 ok=903 bad=0 err=1 (rc=42).
      • In b2 r3 (event=0x77 on pair 3, render_pairs delta pair 0 +903, pair 3 +1) and b2 r2 (event=0x71), the innocent client failed with ECANCELED (g16/job.rs:210) alongside guilty EIO (g16/job.rs:215), matching base a2 r1 (event=0x77) and r3 (event=0x75) which hit the exact same ECANCELED on g16/job.rs:210 in 2/3 rounds.
      • Kit judge.py flagged b2 case 2 r2/r3 as FAIL (1 errors on a client with its own pair).
  • Health & regressions: WARN=0, FAILED_UNITS=0, health: failed 0 errno 0 degraded 0 on all 4 slots; 0 ABBA benchmark regressions across 82 rows; VK-CTS command_buffers (131/131), draw (4913/4913), robustness (4939/4939) all 0 diff / 0 new fails. (Note: kit longjob g16pair long 2500 6 timed out identically with rc=42 on all 4 slots a1/b1/b2/a2, accounting for the 1 pre-hang recovery on each slot.)

@github-actions github-actions Bot removed the ready-to-merge Meets the merge policy: merge it (bot) label Dec 3, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Follow-up to the J773g g16batch row above.

The case-2 ECANCELED is not caused by this PR. It happens on base c09b61228e62 and on main 7303d70ea68d (same code):

  1. Each rendering VM gets two PB allocator slots at its first render, pick_base_pb_slots(next_pb_slot++). VM n gets slots {n, n+1}, so a VM's first slot is the previous VM's second slot.
  2. The hung render starts on that shared slot. Its aborted flight quarantines the slot for good.
  3. The recovery invalidates every PB epoch, so the innocent needs a fresh epoch, and a fresh epoch only goes on a displaced slot. The innocent's own slot isn't displaced, because no other client retires a render after it. Its other slot is the quarantined one. The spare slots (16-19) are only added when a job is submitted, and the innocent's next render was submitted before the hang.
  4. So exhausted_for_mask_mode() is true for that queued render, and engine.rs:1325-1346 cancels it. That is the ECANCELED at g16/job.rs:210.

It only happens when the hung render took the innocent's second slot, which explains 2 of 3 rounds. The event code doesn't matter. With 9 clients (case 1), other clients' renders free the slot, so case 1 never hit it. The fix is not small: a queued render must be able to use a spare that is added after it was submitted. It needs its own PR and row.

This PR's case can't be built across processes. render_pair_for() only gives a VM a pair that has no renders in flight, so two processes never share a pair while work is in flight. The case this PR changes happens inside one process: renders on a second queue of the hung process, queued behind the hung render on the same pair. A hang doesn't latch a fault, so on base those renders retire as successes.

A new J773g proof kit runs that case. It uses one VkDevice with two queues: a hang on queue A and 3 checked renders on queue B behind it. It reads each fence's result from the kernel through a sync_file, because Mesa reports every wait as device lost once the VM fails, which would hide a false success. A control client renders on another pair during each round. Pass for this PR: 0 false successes on the 4032 or batch arm, and the control keeps rendering. It reuses the 7.3.0-g16batch kernel and its base/4032/batch modules, takes about 3 minutes per boot, and runs last in a boot. M4 will run it.

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Hardware row at head a4e1852dc19d (tested in g16batch merge 95212b64f7eb on 7.3.0-g16batch, aurora-base.ko 1f43c0ef3f95 boot 2d4769f8-4a5c-452a-998d-0ddfb21efdb0 vs aurora-batch.ko 6e2cd6dbc069 boot c9c5bcf4-c901-4dd6-a518-b669cf529c22) on J773g (M4 mini, G16G B0, 27.2): FAIL / VOID (pre-#4198/#4240 g16batch baseline).

Kit: work/j773g-g16-4032-proof-20261203 (--check 8/8 ok).
Receipt: work/j773g-g16-4032-proof-20261203/results/{base,batch,verdict.txt}.

Findings:

  • Both base and batch failed after rc=2 (gpubench-vk vkQueueSubmit -4 / ECANCELED at g16/job.rs:210) after the S/A hang rounds stranded PB pairs (render_owners: quarantined 7, pb: kept 1), matching the pre-#4240 PB-pair exhaustion bug in g16batch's aurora.ko:
    • base: A1 triggered recovery 4 (ECANCELED on g16pair, plasma-login-gr, kwin_wayland, exhausted_for_mask_mode true x3, latch ECANCELED x6), leaving A2, A3 (ok=0 err=1) and after (rc=2) failing with ECANCELED.
    • batch: S3 hit recovery 3 (event=0x70, flights=3, EIO on plasma-login-gr and g16proof, ECANCELED on kwin_wayland and g16pair, PB pair overlap {13}), leaving A1–A3 (ok=0 err=1) and after (rc=2) failing with ECANCELED.
  • Case S did not reproduce the #4032 false-success failure on base: base S1..S3 all reported b_ok=0 b_bad=0 b_err=3 (same as batch S1..S3: b_ok=0 b_bad=0 b_err=3, hang_status=-5).
  • WARN=0, health: failed 0 errno 0 degraded 0 on both arms; proof.sh line 41 also logged /sys/kernel/tracing/events/g16proof/enable: No such file or directory.
  • Not rerun on g16batch; needs a post-#4198/#4240 kernel/module build to get a clean J773g #4032 row.

Bring the branch up to main c042c5f. The merge is clean, and
nothing main changed in g16 since d1ae4f2 (#4198, #4240 and
others) touches the code this branch changes, so nothing was dropped
or adjusted.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@github-actions github-actions Bot added needs-hw-row No hardware row at the PR head (bot) and removed ready-to-merge Meets the merge policy: merge it (bot) labels Dec 4, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J773g (Mac mini M4, 27.2) row at head 8e659f9: PASS.
Kernel 7.3.0-j773g-w4248 (main 89ec99a Image) with module-only aurora.ko arms, 5 boots a1 b1 c1 b2 a2 (a = main c042c5f, b = #4034, c = this PR). Kit work/j773g-g16-4034-4032-main-v4-20261204; run results/run-20261204T045135Z in the v3 dir, judged by v4.

  • c1: perf rows, 10 s long job (124 renders, 0 bad), 3 hang rounds (two same-process two-queue rounds with fences read from sync_files, one drm/asahi: g16: add a recovery PB slot for a render accepted before a hang #4240 round): 3 recoveries, 0 hang kills, control clients clean, 0 of 6 queue-B renders reported success with a wrong image. The fresh render after the hangs passed, no WARN, no unexpected GPU kernel line, the GPU had no other client.
  • Against main (a1, a2), us: compute.light d1 103.5 vs 102.7/109.5; d16 22.61 vs 22.64/22.63; concurrent.cr interleave d4 62.59 vs 62.13/62.94; idle.wake d1 192.1 vs 191.1/191.6; render.light d1 129.9 vs 129.6/127.5; d16 54.47 vs 54.25/52.00; long job 80.55 vs 80.55/80.54 ms. All within tolerance. sync.signal host d1 is too noisy on this kernel to judge (main 256/173).
  • Main did not reproduce the false success (0 of 12 queue-B renders on a1 + a2). That is expected: two processes never have renders in flight on one pair, so this row is non-regression. The case itself is covered by the PR's selftest, which fails without the change.

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed needs-hw-row No hardware row at the PR head (bot) labels Dec 4, 2026
@DjDeveloperr
DjDeveloperr merged commit 8ae72dc into main Dec 4, 2026
10 checks passed
@DjDeveloperr
DjDeveloperr deleted the fix/g16-recovery-pair-renders branch December 4, 2026 09:16
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Merged as 8ae72dc at head 8e659f9.

Merge-tree check before the merge: main be72f78 + 8e659f9, tree fb26bc113f09, clean merge on the GitHub compare base c042c5f.

  • arm64 LLVM (clang 23.1.3, rustc 1.100.1, prepared aurora-bindgen), from a warm asahi.config tree (DRM_ASAHI options equal to apple-build's): make modules_prepare, then make W=1 drivers/gpu/drm/asahi/ and make W=1 drivers/gpu/drm/asahi/aurora.ko on main and on the merge. Both pass. 42 warnings on each side, the same set, so 0 new. aurora.ko main 944ec95e, merge fdafa6df.
  • Host tests in the host-tests.yml image (ubuntu 24.04, rust 1.96.0): run-host-tests.py --only g16 4/4, --only asahi-m4 1/1 (test-publication.py ok, including cross_vm_recovery_prepare_isolates_blame_to_faulting_vm), --only g15 19/19.
  • Main moved to 85777c1 before the merge (bcm4377, t8122 DT, one host-test registration). The merged tree equals the tested one in drivers/gpu/drm/asahi, the asahi-m4 selftests, rust/ and include/.

Hardware gate: the J773g row PASS at this head, posted above at 05:15Z (kit work/j773g-g16-4034-4032-main-v4-20261204).

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:m3 Macs affected, from Merge risk (bot) blast:m4 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) ready-to-merge Meets the merge policy: merge it (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants