Skip to content

drm/asahi: g16: let the firmware unbind a drained compute UMA manager - #4198

Merged
DjDeveloperr merged 1 commit into
mainfrom
fix/g16-unbind-drained-uma
Dec 3, 2026
Merged

DjDeveloperr merged 1 commit into
mainfrom
fix/g16-unbind-drained-uma

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

What: Let the firmware unbind a compute UMA manager once its last command completes, instead of keeping it bound while its VM is idle or gone. This is the most likely cause of the J773g GPU recoveries with several Vulkan processes (linux#3707).

Tested: J773g (M4 mini, T8132), module-only arm with this head's driver diff: the linux#3707 repro recovered on the stock module and ran clean on two boots with this change, 0 recoveries and 0 failed cases over gpubench, the repro kit and the 4-process mix (27,496 cases per boot). ABBA performance: no row slower; #3695's own compute.light procs rows cost 5.2 % (d8) and 7.2 % (d16) (row). Host tests and the arm64 W=1 build of drivers/gpu/drm/asahi/ pass on the merge with main 5bb2f1eed073 (Evidence).

Risk: two-way · M4 (T8132) and M3 (T8122, T6030), which share the g16 backend. It gives back part of #3695's gain on compute.light procs (8 to 12 % with its hold and cached records together); the cached records stay. A plain revert undoes it.

Not yet: a J516s (M3 Pro, T6030) row. The g16 backend is shared, and the firmware's save at drain on top of #3695's cached records has run only on the J773g.

Details

#3695 publishes *counter = submissions + 1 while a VM's shared compute UMA manager has commands in flight, so the firmware doesn't save and unbind the manager when a command completes. When the last one retires the host writes the counter back, but no command completes after that, so the firmware never unbinds it. The manager stays bound in its hardware slot (1 of 32), also after its VM closed.

Two kinds of user share those slots:

  • one shared manager per VM, at slot 1 + (a counter that goes round the 32 slots);
  • the private managers of ray tracing (SCS) compute, at slots 1 and 2 of whatever VM runs it (pick_scs_compute_slots()).

By the code's own note, binding a manager loads the incoming record only and never saves the outgoing one (UmaBound in slots.rs). Before #3695 the outgoing one was always saved and unbound first, because a drained manager had COMPLETED == *counter. The host only checked that no shared command was in flight in the slot (compute_uma_private_ready()), and that stays true with a manager left bound.

*counter is now the submission count again. A later queued command still keeps the manager bound. The rest of #3695 and #3699 is unchanged: ASC-cached device-lifetime slot records, residency tracking, and rebuild without a reseed.

macOS 26B123 keeps *counter == COMPLETED on idle managers: the procs-d8 snapshot that #3695 quotes shows it for all eight. No capture shows it one past the submissions.

Evidence

Hardware arm: this head's diff of the four driver files, byte for byte, applied to the source of the kernel the J773g runs (7.3.0-j773g-main3685+); aurora.ko build ID 7132c4cb.

Merge with main 5bb2f1eed073 (after #4185; tree 9370a502e313): this head's diff applies with the same patch-id. Hosted-CI image, no network: asahi-m4/run-host-tests.py 26 of 26 scripts (test-resources 100 passed), --only g16 2 of 2, --only g15 19 of 19, --only m3-recovery 2 of 2. arm64 LLVM=1 W=1 drivers/gpu/drm/asahi/ (G15 and G16 on, clang 23, rustc 1.100) builds with the same 38 warnings as main. checkpatch.pl --strict: 0 errors, 0 checks; its 2 warnings are the commit id ebc3b149b8ec, which a tree without git can't look up (it is on main).

All on the J773g (M4 mini, G16G), several deqp-vk processes at once.

Kernel g16 code Row Recoveries
main 8ec8740a1e6f + display/PCIe PRs first parent of #3695's merge 4 processes, 366 chunks: 2,304 ray query / ray tracing pipeline, 15,641 + 66,044 graphics/compute cases 0
same same 4 processes, 334 chunks: 15,641 + 67,794 cases, 474 of them small ray-tracing-stage cases mixed with compute and graphics 0
main 786a426ecae9 + PRs outside asahi has #3695 + #3699 4 processes, includes 751 small ray-tracing-stage cases 5 in 105 s
main f7e3388dd07d + #3685 has #3695 + #3699 6 processes, includes 389 small ray-tracing-stage cases 16 in 84 s
  • Between 8ec8740a1e6f and the two recovering kernels, the only change in drivers/gpu/drm/asahi/g16 is drm/asahi: g16: keep compute UMA managers bound and ASC-cached #3695 and drm/asahi: g16: rebuild a drained compute UMA manager without reseeding its pool #3699.

  • All 21 recoveries have event 0xf, which is compute pipe 0. SCS compute only runs there; other compute spreads over 8 pipes (events 15 to 22). So the job that timed out was on the ray tracing pipe.

  • Every one has one flight in flight. 15 have all fault banks zero: the job timed out, it didn't fault.

  • The other 6 latched the same two faults, va 0x7003000c00 and 0x7003000b80 (read unmapped), in the context of the live VM whose job was the one in flight. That is freelist lines 24 and 23 of compute_state(0), the shared manager's freelist. A VM that has only SCS compute maps nothing there. So the GPU used a shared manager's freelist while a VM without a shared manager ran, as if the slot still held the old allocator state.

  • The first recovery came with the first mix of ray-tracing-stage and other cases. The ray query / ray tracing pipeline chunks before it (38 of them) had none, and first cases lost were dEQP-VK.subgroups.*.ray_tracing.*.

  • One process is enough: a clean boot running one deqp-vk process of ray_query cases recovered the same way (event 0xf, all banks zero, 2 flights). The ray tracing units always take slots 1 and 2, and a VM's manager takes the next slot in turn from a device-wide counter, so on a fresh boot the first VMs' managers sit there too. Nothing in the host's check stops a private unit from binding over that manager in the same VM or the next device of the same process.

Not shown yet: that this change alone removes the recoveries, and which job exactly displaced which manager.

Commit ebc3b14 ("drm/asahi: g16: keep compute UMA managers bound and
ASC-cached") kept each VM's compute UMA manager bound between its jobs, by
publishing a submission counter one past the submissions. The firmware
saves and unbinds a manager only when a command finishes with COMPLETED
equal to that counter, so a drained manager stayed bound in its hardware
slot after its VM went idle or away. The slot's next user, such as a
private shader-context scratch (SCS) unit of another VM, then displaced it
without a save.

On the J773g, several Vulkan processes then hit GPU recoveries: 21 in two
runs, every one with event 0xf (compute pipe 0, which all SCS compute
uses). Where a fault was latched, the GPU had read the base compute
freelist at compute_state(0) in the context of the one job in flight, whose
VM doesn't map it. The parent of that change's merge had 0 recoveries.

Publish the submission count itself, as before that commit and as macOS
26B123 does (an idle manager's counter equals COMPLETED). A manager with a
later command queued still stays bound, and the ASC-cached slot records
stay.

Fixes: ebc3b14 ("drm/asahi: g16: keep compute UMA managers bound and ASC-cached")
Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J773g (Apple Mac mini M4, T8132, G16G B0, os-fw 27.2, 24 GB RAM, kernel 7.3.0-j773g-main3685+) ABBA hardware row (work/linux4198-j773g-20261203) for head b0426e1e278daf3be8bc7f6f0fc3009f7556fa92:

  • Stock aurora.ko build ID: cc310d6ff44e0b19c68a005855cf4a0198858ea7 (A1, A2)
  • Candidate #4198 aurora.ko build ID: 7132c4cb7959e4cd0d947dbf09799a5bf7a058e7 (B1, B2)
  • appledrm build ID: c22edd8509b5d2ff9c80e27e2cc367dee769bd8a (all 4 slots)

Cause (linux#3707 recovery repro): CAUSE PASS

Slot Arm Boot ID gpubench kit3707 (S1–S5, 327 procs / 8,216 cases) mix4 (M1–M3, 236 procs / 19,280 cases) Recoveries
A1 stock 03915453-8eda-4059-9feb-6037cc096135 rc=2 (105 results, 5 failed calls, 159 s) rc=4 RECOVERY in S5 (M4 firmware recovery event, event=0xf, fault_scan: all 8 banks zero, flights=1) skipped (boot used up) 1
B1 #4198 53fe5509-d2d2-44eb-b320-653416645b4a rc=2 (105 results, 5 failed calls, 159 s) rc=0 NO RECOVERY (144 s, 0 non-pass) rc=0 NO RECOVERY (148 s, 0 non-pass) 0
B2 #4198 f2aead02-ff8f-4074-8c28-16fc98485d33 rc=2 (105 results, 5 failed calls, 159 s) rc=0 NO RECOVERY (142 s, 0 non-pass) rc=0 NO RECOVERY (148 s, 0 non-pass) 0
A2 stock dc729ff6-8f30-40e9-8a57-cafe0e30b15b rc=2 (105 results, 5 failed calls, 159 s) — (A2 is bench-only) — 0

aurora-g16/stats post-slot on candidate boots:

  • B1: compute_uma: rebuilds 499346 invalidations 320194 idle_invalidations 320194 reseeds 2931; jobs 2554926 ... recoveries 0 hang_kills 0 clustered 0
  • B2: compute_uma: rebuilds 494730 invalidations 315258 idle_invalidations 315258 reseeds 3112; jobs 2517573 ... recoveries 0 hang_kills 0 clustered 0

Performance (linux#3695 ABBA rows): 0 SLOWER flags across all 20 valid rows

  • Note on judge.py exit: row.sh judge exited with KeyError: 'metrics' at judge.py:46 because the kit's 21st benchmark row (sync.signal --mode queues --depths 2 --param kind=queue --param work=compute.light) is rejected identically on all 4 slots by gpubench-vk (unknown --param work), producing 5 status=fail JSONL lines without a metrics key.
  • Evaluating the exact judge.py ABBA formula across all 20 valid rows (skipping the invalid sync.signal CLI row):
    • 0 SLOWER flags (all non-#3695 rows within -0.8% to +2.5%, well below the 5% gate).
    • 2 minor COST rows on #3695's multi-process compute rows (well below the 15% own-row gate):
      • compute.light {} procs d8: 34.73 -> 36.55 us/submit (+5.2%, noise 2.1%)
      • compute.light {} procs d16: 32.93 -> 35.30 us/submit (+7.2%, noise 2.5%)
    • Representative other rows: compute.light queue d1 +1.2%, queue d16 +1.4%, queue d64 +1.0%, queues d8 -0.3%, compute.uber +0.1%, idle.wake (2/20/200 ms) +0.9% / -0.8% / +1.2%, render.light procs d8 +0.1%, render.postfx queue d1/d2 +1.0% / +2.0%.

Stock 7.3.0-j773g-main3685+ (aurora.ko cc310d6f) cleanly restored after B2 (boot 9107f3fa-e9ae-43e8-a7a5-fa34f812eb77).

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Independent review of b0426e1e278d by a reviewing agent that didn't write it. No code blocker. One row left before merge: J516s.

What it does. *counter goes back to the submission count, the protocol main had before #3695, while #3695's cached records stay. A drained shared manager is saved and unbound by the firmware with its last command, so it can't be left bound after its VM is idle or gone.

Checked

  • Order against work in flight. The counter is written once per flight, before wmb(), the WRITE and the doorbell. If a new flight is published while the last command of an older one completes, the firmware either sees the new count and keeps the manager bound, or saves it and later reloads the same record, which the host leaves alone (bind_compute_uma returns the live record and writes nothing). Both are safe. COMPLETED counts completions (init_record lines it up with the next submission), so flights that finish out of order across pipes save the manager only after the last one.
  • If the firmware never saves. Nothing new waits on the firmware. The host takes the slot back on the service stamp, as before. A firmware that didn't save would leave the slot as it is on main today, so it is never worse. A hung command still goes through recovery, and aborted flights still keep their slot quarantined with their commands counted.
  • Locking. No new shared state. Everything changed runs under the engine's &mut self, as before. Retirement now writes nothing, which removes the only error path it had (a failed counter write ended in a fail-stop).
  • Idle power-off. Unchanged: idle passes still invalidate and rebuild. That is now only a precaution, since the firmware also saved the cursors.
  • Forbidden patterns. No runtime switch and no SoC gate. No new constant: the change removes a + 1 and its overflow check.

Hardware. The J773g arm used this head's diff of the four driver files, byte for byte. The repro recovered on the stock module and ran clean on two boots with the change. No row got slower, and the procs d8/d16 cost (5.2 % and 7.2 %) is under the 15 % gate (receipt above). On main after #4185 (5bb2f1eed073) the diff merges cleanly with the same patch-id (tree 9370a502e313).

Local checks on that merge (pc, hosted-CI image, no network): asahi-m4 26 of 26 scripts (test-resources 100 passed), g16 2 of 2, g15 19 of 19, m3-recovery 2 of 2. arm64 LLVM=1 W=1 drivers/gpu/drm/asahi/ with G15 and G16 on builds with the same 38 warnings as main. checkpatch --strict is clean apart from the commit-id lookup.

Left before merge

  1. A J516s (T6030) row. The body lists it, and the g16 backend is shared. The save at drain on top of cached records has run only on T8132 firmware. Run it on main 5bb2f1eed073 + this head, which also covers #4185 together with this change: gpubench compute rows plus a multi-process compute/ray-query CTS mix, 0 recoveries, 0 failed cases, compute_uma rebuilds and reseeds in aurora-g16/stats.

Small note, not pushed so the tested head stays the same: g16/sleep.rs:92 still says "every UMA manager left bound". After this change, a manager is left bound only while its commands run.

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J516s (M3 Pro, T6030, G15S B1, 18 active GPU cores, OS firmware 27.2) paired A/B row: PASS.

Covers #4185 (in main 5bb2f1eed073) and #4198 (b0426e1e278daf3be8bc7f6f0fc3009f7556fa92) together on G15S/27.2.

  • Kernel & stack: 7.3.0-j516s-pr4198 (vmlinux build ID 9b9e755f2d3b75d8e5e4be3dd5913419f815d112), local merge 55fcd2c927afd7ff5564c02f90f34e3a54ca9eb2 (tree ac3cb9c333cc829013922a3bcaff0cf4b8bf4c47) = main 5bb2f1eed073 + #4213 a313071a0aad + #4198 b0426e1e278d (drivers/gpu/drm/asahi/ byte-identical to pure merge tree 9370a502e3135a7e80946d3b742f1420e8fe0b5e). Two arms differ only in aurora.ko:
    • Arm A (base = main 5bb2f1eed073 + #4213): aurora.ko build ID cdba95df580faddb6046dd110fb8f781d647f759, boot b8c9fde2-6211-4043-881e-6b97ba005a4d (2026-12-03T20:15:37Z .. 20:19:32Z)
    • Arm B (arm = + #4198): aurora.ko build ID d41d5868c09c5e24e14f0ee5fbe0649b42262e60, boot e3ac3155-254f-414f-b9df-b2e7049fa6bf (2026-12-03T20:20:14Z .. 20:25:37Z)
  • Userspace: mesa-aurora / vulkan-aurora 26.3.0 (d4ad4a4dce6)

Arm B functional & stress results:

  • Multi-process compute + ray-query/RT Vulkan CTS mix (mix4, 4 processes): 246 processes, 20,280 cases (M1 4210 Pass / 2790 NotSupported, M2 2877 Pass / 2403 NotSupported, M3 4210 Pass / 2790 NotSupported, C1 907 Pass / 93 NotSupported), 0 failed or wrong-result cases, 0 recoveries (89 s).
  • /sys/kernel/debug/aurora-g16/stats after Arm B:
    • health: failed 0 errno 0 degraded 0
    • compute_uma: rebuilds 642796 invalidations 403001 idle_invalidations 403001 reseeds 2181
    • jobs 3289735 job_cmds 3558319 job_max 64 early 240699 recoveries 0 hang_kills 0 clustered 0
    • (Arm A for comparison: compute_uma: rebuilds 699513 invalidations 394363 idle_invalidations 394363 reseeds 1963, jobs 3268938, recoveries 0)
  • Kernel log: 0 GPU, DART/IOMMU, or RTKit faults; 0 recoveries; 0 WARN/BUG/Oops on either arm.

Paired gpubench-vk summary (A1 vs B1, 4 counted passes + warmup; 0 regressions past max(5%, 1.5x noise)):

  • compute.light procs d2/d4/d8/d16: 54.66 -> 56.17 (+2.8%, noise 2.3%), 32.79 -> 33.57 (+2.4%, noise 2.5%), 25.18 -> 25.49 (+1.2%, noise 2.4%), 25.16 -> 25.48 (+1.3%, noise 2.0%) us/submit
  • compute.light queue d1/d16/d64: 107.83 -> 107.48 (-0.3%), 16.15 -> 16.06 (-0.5%), 22.45 -> 21.03 (-6.3%) us/submit
  • compute.light queues d2/d4/d8: 52.48 -> 52.81 (+0.6%), 33.13 -> 33.17 (+0.1%), 24.23 -> 24.19 (-0.2%) us/submit
  • compute.uber uniform queue d4: 125.53 -> 126.36 (+0.7%, noise 1.4%) us/submit
  • idle.wake compute.light 2/20/200 ms: 125.73 -> 128.12 (+1.9%), 163.00 -> 162.17 (-0.5%), 594.70 -> 597.38 (+0.5%) us
  • render.light tri procs d8 / queue d16 / queues d8: 59.64 -> 59.44 (-0.3%), 39.91 -> 39.74 (-0.4%), 42.75 -> 42.50 (-0.6%) us/submit (render.light queue d1: 132.33 -> 150.06 (+13.4% inside 29.3% noise))
  • render.postfx 1080p MSAA4 queue d1/d2: 1176.48 -> 1168.22 (-0.7%), 827.81 -> 826.45 (-0.2%) us/submit

@DjDeveloperr
DjDeveloperr marked this pull request as ready for review December 3, 2026 20:27
@DjDeveloperr
DjDeveloperr requested review from a team as code owners December 3, 2026 20:27
@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-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 b0426e1e: not ready yet

Check Detail
CI at head ok 13 checks passed
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok comment at b0426e1e
Conflicts ok none
PR text ok Risk: two-way · M4 (T8132) and M3 (T8122, T6030), which share the g16 backend. It gives back part of #3695's gain on compute.light procs (8 to 12 % with its hold and cached records together); the cached records stay. A plain revert undoes it.

Areas: area:gpu

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

@DjDeveloperr
DjDeveloperr merged commit 9ea2277 into main Dec 3, 2026
19 checks passed
@DjDeveloperr
DjDeveloperr deleted the fix/g16-unbind-drained-uma branch December 3, 2026 20:27
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Additional J773g (Mac16,10, G16G B0) confirmation via the ray_query chunk-0 (rq333) kit (work/j773g-rq333-segv-kit-20261203, dEQP-VK.ray_query 500-case chunk):

  • Stock 7.3.0-j773g-main3685+ (without #4198, aurora.ko cc310d6f…) — 2/2 GPU firmware recoveries:
    • Boot dfaeecc5 (out-minihw-rec1-dfaeecc5): rc=4 (VERDICT RECOVERY), arm 1 (42c39cdaf75b) aborted at 255/500.
    • Boot c76b4dc2 (out-minihw-rec2-c76b4dc2): rc=4 (VERDICT RECOVERY), arm 1 (42c39cdaf75b) hit DeviceLost at 335/500 (M4 firmware recovery event: [00000004, ..., 0000000f, ...]).
  • linux#4198 (aurora.ko 7132c4cb… on 7.3.0-j773g-main3685+, boot 762c948a, out-minihw-pr4198-762c948a) — 4/4 arms clean (rc=0):
    • arm 1 (42c39cdaf75b, m1607 env, m4cts): 500/500 (Pass: 319, NotSupported: 181, 2.7 s)
    • arm 2 (42c39cdaf75b, clean env, pinned): 500/500 (Pass: 319, NotSupported: 181, 5.4 s)
    • arm 3 (3750a2177184, m1607 env, m4cts): 500/500 (Pass: 319, NotSupported: 181, 2.8 s)
    • arm 4 (3750a2177184, clean env, pinned): 500/500 (Pass: 319, NotSupported: 181, 5.4 s)
    • 0 GPU recoveries, 0 crashes (VERDICT DATA: NO CRASH in any arm, 57 s).

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

1 participant