Skip to content

drm/asahi: g17: share per-VM UAT execution context on M5 - #4074

Merged
DjDeveloperr merged 1 commit into
mainfrom
fix/m5-vm-exec-share
Dec 3, 2026
Merged

DjDeveloperr merged 1 commit into
mainfrom
fix/m5-vm-exec-share

Conversation

@erikwb

@erikwb erikwb commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

What: Enable per-VM shared UAT execution contexts (exec_share) on M5 so all logical queues of one client share a single context ID, fixing cross-queue corruption of graphics-stage storage image writes into Gen10 losslessly compressed surfaces in Borealis without disabling M5 storage compression. Also fix three exec_share lifecycle edge cases (concurrent queue-creation race, last-sharer Use::drop root stranding, and numeric VM ID reuse across GPU instances).

Tested: J716c (M5 Max, T6050, G17C) at 6aee22f46165: boots to desktop on default cmdline; 30 passes of dEQP-VK.synchronization*.op.multi_queue.*write_image_fragment* (40,800/40,800 pass, 0 fail vs 1–3 fails/pass on main 13dc5a79c0ec); full dEQP-VK.synchronization.op.multi_queue.* + synchronization2.op.multi_queue.* (29,478/29,478 pass, 0 fail, 0 GPU errors); 8×50 concurrent multi-queue render+compute teardown stress (0 fails, 0 leaked execution contexts). J713 (M4, T8132, G16G) at 6aee22f46165: boots to desktop, dEQP-VK.synchronization.op.multi_queue.* 12,798/12,798 pass, 0 GPU errors. Host tests: 337/337 g17-* pass.

Risk: two-way door · M5 (G17C/G17S/G17D) and G17P (A18 Pro, M4 Pro/Max); shared mmu.rs helper compiled on all Macs

Not yet: G17P (A18 Pro, M4 Pro/Max) hardware run (no G17P Mac in this lab).

Details

Problem

On M5, g17/runtime.rs excluded uat.is_m5() from exec_share::join() and exec_share::offer(), so every VkQueue created on the same VkDevice (same drm_asahi VM) received a distinct UAT execution context ID.

Because GPU caches are tagged by address and context ID, graphics-stage (vertex/fragment) storage image writes into Gen10 losslessly compressed surfaces on one queue could leave dirty lines invisible to a second queue of the same client even after CPU fence wait (vkWaitForFences) or semaphore synchronization. Single-queue runs passed 100%, while cross-queue fragment storage writes reliably failed 1–11 cases per pass in Vulkan CTS (dEQP-VK.synchronization*.op.multi_queue.*write_image_fragment*) and 19/300 iterations in a standalone 128×128 R16G16B16A16_UINT reproducer under compute load.

Changes

  1. Enable exec_share on M5 (drivers/gpu/drm/asahi/g17/runtime.rs, context.rs, exec_share.rs): Remove the !uat.is_m5() exclusion so logical queues of one VM share a single UAT execution context ID and shared 63-bit WorkStates claim mask on M5 just as on G17P, while keeping separate per-queue scheduler pages, QoS slots, and work lists.
  2. Eliminate concurrent queue-creation race (drivers/gpu/drm/asahi/g17/runtime.rs): Move exec_share::offer(vm, &execution) inside shared.state.lock() immediately after new_execution_context() (calling execution.release() if offer fails), so concurrent DRM_ASAHI_QUEUE_CREATE calls on the same VM cannot both miss join() and allocate multiple execution contexts.
  3. Prevent last-sharer UAT root stranding (drivers/gpu/drm/asahi/g17/exec_share.rs): In Use::drop(), call last.release() after unlocking SHARES when removing the last counted sharer. Previously, if a published compute queue closed while a sibling still held the shared root and that sibling later dropped without publishing (or failed construction after joining), Use::drop() removed the SHARES entry without releasing the root, leaving the idle compute binding's Arc<Context> keeping the root current indefinitely.
  4. Match VM instance identity (drivers/gpu/drm/asahi/mmu.rs, g17/exec_share.rs): Add Vm::same_as(&self, other: &Vm) -> bool comparing Arc::ptr_eq(&self.binding, &other.binding) and use it in exec_share::join() so a rebound GPU instance restarting its numeric VM ID counter at 2 cannot join a retained context from a previous instance.
Evidence
  • Base: origin/main 13dc5a79c0ec
  • PR head: 6aee22f46165
  • Host tests (tools/asahi/run-host-tests.py --only g17-): 337/337 passed in 7s
  • Baseline (origin/main 13dc5a79c0ec) on J716c (M5 Max, Borealis Mesa git-75c936dc4a, M5 storage compression on):
    • 5 passes of dEQP-VK.synchronization*.op.multi_queue.*write_image_fragment* (-j 6 --retry-runs 0): 2, 3, 2, 3, 0 failures per pass (10 total failures across 6,800 supported runs).
    • dEQP-VK.synchronization.op.multi_queue.*: 12,797/12,798 pass, 1 fail (binary_semaphore.write_image_fragment_read_copy_image_to_buffer.image_128x128_r8g8b8a8_unorm_concurrent: Memory contents don't match), 9 NotSupported.
  • PR head 6aee22f46165 on J716c (M5 Max, T6050, G17C, Borealis Mesa git-75c936dc4a, M5 storage compression on):
    • One-shot trial boot via chained Stage 2 with dead-man watchdog on default kernel cmdline; Hyprland GPU desktop up.
    • /sys/kernel/debug/aurora-g17/capacity: confirmed 8 barrier-synchronized concurrent threads creating queues on 1 VM incremented logical_queues by +8 and execution_contexts by +1 (all sharing one context ID).
    • 10 + 20 consecutive passes of dEQP-VK.synchronization*.op.multi_queue.*write_image_fragment* (2,014 cases / 1,360 supported per pass, -j 6 --retry-runs 0): 40,800 / 40,800 pass, 0 fail, 0 crash, 0 DeviceLost, 0 dmesg lines (4s/pass).
    • Full dEQP-VK.synchronization.op.multi_queue.* (12,807 cases): 12,798 / 12,798 pass, 9 NotSupported, 0 fail, 0 crash, 0 dmesg lines (1m38s).
    • Full dEQP-VK.synchronization2.op.multi_queue.* (23,760 cases): 16,680 / 16,680 pass, 7,080 NotSupported, 0 fail, 0 crash, 0 dmesg lines (1m54s).
    • 8 concurrent processes × 50 cycles of mixed render+compute multi-queue submit & teardown (400 device lifetimes): 0 fails; post-stress aurora-g17/capacity showed crashed=0, logical_queues used=2, execution_contexts used=2, leaked=0, failures=0, 0 new dmesg GPU lines.
  • PR head 6aee22f46165 on J713 (M4, T8132, G16G):
    • One-shot grub-reboot trial boot; Hyprland desktop up.
    • dEQP-VK.synchronization.op.multi_queue.* (-j 3 --retry-runs 0): 12,798 / 12,798 pass, 9 NotSupported, 0 fail, 0 crash, 0 dmesg lines (1m06s).

Queues belonging to the same VM on M5 were each allocated a distinct UAT
execution context ID because exec_share was gated off on M5. Because GPU
caches are tagged by address and context ID, graphics-stage storage image
writes into Gen10 losslessly compressed surfaces on one queue could leave
dirty cache lines invisible to another queue of the same client even after
fence synchronization, causing cross-queue image corruption.

Enable per-VM execution context sharing on M5 as on G17P, and close three
edge cases in exec_share:
- Register newly created contexts via exec_share::offer() under the runtime
  state lock so concurrent queue creation on one VM cannot allocate multiple
  execution contexts.
- Release the UAT root in exec_share::Use::drop() after unlocking SHARES
  when removing the last user, so a published queue whose sibling later
  drops without publishing cannot strand the shared root in an idle compute
  binding.
- Match VM instance identity via Vm::same_as() in exec_share::join() so a
  rebound GPU instance starting its numeric VM counter at 2 cannot join a
  retained context from a previous instance.

Signed-off-by: Erik Bourget <erik@ebourget.net>
@erikwb
erikwb requested review from a team and DjDeveloperr as code owners December 3, 2026 06:45
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) blast:all 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 6aee22f4: 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 in the PR body at 6aee22f4
Conflicts ok none
PR text ok Risk: two-way · M5 (G17C/G17S/G17D) and G17P (A18 Pro, M4 Pro/Max); shared mmu.rs helper compiled on all Macs

Areas: area:gpu
Merge: gh pr merge 4074 --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.

Publishing the shared root under the device mutex closes the duplicate-creator window, and the binding identity prevents joining an unrelated VM with a matching number. The last-sharer path releases the root while scheduler holds still govern lifetime. The exact J716c multi-queue regression and teardown rows cover the fix, alongside the J713 control.

@github-actions github-actions Bot removed the needs-review No approving review from Core or Omarchy Mac yet (bot) label Dec 3, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor

We take two rows at 6aee22f46165: J714s (M5 Pro, G17S) with base/head write_image_fragment passes, the full multi_queue lists and a GTA V A/B, and J700 (A18 Pro, G17P) with the multi_queue lists and the create/teardown stress. The PR merges on those two plus the J716c and J713 rows already here.

@DjDeveloperr

Copy link
Copy Markdown
Contributor

J714s (Apple M5 Pro / T6050 / G17S B1) verification on exact head 6aee22f46165 vs base 6985e45ab583 — PASS.

Build & Boot Setup

  • Base (7.3.0-m5-4074-base): 6985e45ab583 (vmlinux 1e78d88ba097, aurora.ko 052b4b64fa79), boot 98f9319e-aa59-4644-8a7c-894d37d3e939, SLC 16 planes, CONFIG_TYPEC_TPS6598X_DEBUG_COMMANDS=y.
  • Head (7.3.0-m5-4074-head): 6985e45ab583 + #4074 6aee22f46165 (co-tested with #4060 72df143cd3ae; vmlinux 169ffdfda90b, aurora.ko 6c16abaf65df), boot 5d9b67fc-9125-407b-a906-a9a0208b12ce, SLC 16 planes, CONFIG_TYPEC_TPS6598X_DEBUG_COMMANDS=y.
  • Vulkan CTS ICD: system ICD vk-717a7d62e0 (4c294628cbc2), headless WSI, --procs 2.

1. write_image_fragment 10× Reproducer & Full multi_queue CTS

Suite Base (6985e45ab583) Head (6aee22f46165)
10× write_image_fragment (2,014 cases/pass, 20,140 total) 3 Fail (pass 3, 4, 6 — positive control) 0 Fail (10/10 passes: 1,360 Pass / 654 NotSupported)
Full dEQP-VK.synchronization.internally_synchronized_objects.multi_queue.* (12,807) — 12,798 Pass / 9 NotSupported / 0 Fail (40.27s)
Full dEQP-VK.synchronization2.internally_synchronized_objects.multi_queue.* (23,760) — 16,680 Pass / 7,080 NotSupported / 0 Fail (52.88s)
Combined full multi_queue (36,567) — 29,478 Pass / 7,089 NotSupported / 0 Fail

Base failing cases (all 128x128, _concurrent, matching #4069):

  • Pass 3: dEQP-VK.synchronization.op.multi_queue.binary_semaphore.write_image_fragment_read_image_compute_indirect.image_128x128_r16g16b16a16_uint_concurrent_maintenance9
  • Pass 4: dEQP-VK.synchronization2.op.multi_queue.fence.write_image_fragment_read_image_compute_indirect.image_128x128_r16g16b16a16_uint_concurrent
  • Pass 6: dEQP-VK.synchronization2.op.multi_queue.binary_semaphore.write_image_fragment_read_image_compute.image_128x128_r8g8b8a8_unorm_concurrent

2. Concurrent Queue Create/Teardown Stress (head)

  • 4 threads × 25 iterations = 100 devices across 3 queue families: QUEUE_STRESS_PASS (0 errors).
  • /sys/kernel/debug/aurora-g17/capacity pre → post stress: crashed=0, online=1, logical_queues 3/58 → 3/58, render_slots 3/63 → 3/63, retired_render_bindings=0, leaked=0, unsettled=0, failures=0, scheduler_teardown pending=0.

3. GTA V Enhanced A/B (rtgen2n31rc24 6e9190bc5ecd, 2560×1440 Very High RT, FSR Quality, headless :0, Launcher-quiet)

Arm Mean FPS 5-Pass FPS TCMb Start → Max Busy MHz / Util clamp_s / GPU Faults
Base (6985e45ab583) 71.491 [62.753, 66.955, 70.371, 84.220, 73.156] 58.66°C → 103.54°C 1609.4 MHz / 97.35% 0 / 0
Head (6aee22f46165) 71.082 [61.732, 67.140, 70.630, 82.390, 73.520] 61.74°C → 105.18°C 1609.3 MHz / 96.77% 0 / 0

Delta -0.409 FPS (-0.57%) on single non-interleaved A/B with head starting +3.08°C warmer after 4.5 min of continuous CTS+stress (Passes 1, 2, 4 were +0.19 to +0.36 FPS faster on head; Pass 0 util 89.6% vs 99.4% and Pass 3 -1.83 FPS explain the mean delta, within the -0.534 FPS identical-binary warm drift measured across 54.0°C → 60.6°C). 0 GPU faults across both boots; clean handback to stock 7.3.0-m5-pr67 (boot_id=8225dbe8).

@DjDeveloperr

DjDeveloperr commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

J700 (MacBook Neo, A18 Pro, T8140, G17P) at exact head 6aee22f46165, two one-shot trial boots, stock verified after each (12:08Z, 12:25Z). No decision for the whole row: no difference between the arms, but two checks fail on both, so they say nothing about this PR.

Arms: module-only aurora.ko on one Image (7.3.0-pr3681-c1fae1db). Base = GPU driver of main 6985e45ab583. Head = base + this PR + #3429 0663be9696f1 + #4039 1c7275a8414c, so a difference would belong to one of the three.

Check Base Head
GPUBench A/A pairs (submit CPU and latency, 16 metrics) reference all within the bar, ratios 0.954 to 1.024
sync CTS, distro ICD, 23,760 + 12,807 cases 4,266 + 4,266 Pass, 0 Fail identical
capacity debugfs before/after, watchdog PASS PASS
compute channels per owner (#4039), median/peak 1 / 1 1 / 1
queue churn, 8 clients x 8 queues, 50 cycles FAIL at cycle 16-17: vkQueueSubmit2 returns -2, 0 wrong results FAIL, same
multi-queue CTS, aurora-wip ICD, 2 workers stopped at 9,089 of 36,567: GPU work of a client failed (ENOMEM, g17/runtime/backend.rs:75), device lost stopped at 9,112, same line twice

No GPU fault or recovery, no stuck job, no wrong CRC, 0 leaked, 0 crashed on either arm. The same multi-queue lists passed on stock 7.3.0-41 today (0 Fail), so main's driver loses the device where the shipped one doesn't; that is being bisected separately. Not measured here: the M5 (T6050) half, game fps, and whether #4074 helps once main's own failure is out of the way.

Evidence: base 476d6797b92f, head 4348541ca17d (receipt/SHA256SUMS), compare 55011c8b65d1.

@DjDeveloperr
DjDeveloperr merged commit 47bad17 into main Dec 3, 2026
11 checks passed
@DjDeveloperr
DjDeveloperr deleted the fix/m5-vm-exec-share branch December 3, 2026 12:37
@DjDeveloperr

Copy link
Copy Markdown
Contributor

Merged at 6aee22f46165 into main 2533c76f02e3 as 47bad176f093. The merge tree is f10195f0fcdc, the same tree these checks ran on:

Rows: J714s (G17S) pass, J716c (G17C) pass, J713 (G16G) pass, J700 (G17P) no difference between the arms. J700's queue churn and multi-queue CTS checks stop on main as well, so they say nothing about this change; that is a separate main problem.

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:all 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.

3 participants