Skip to content

drm/asahi: g17: keep firmware-mutable pooled state uncached - #3170

Merged
DjDeveloperr merged 1 commit into
mainfrom
fix/g17-uncached-mutable-fw-state
Nov 25, 2026
Merged

DjDeveloperr merged 1 commit into
mainfrom
fix/g17-uncached-mutable-fw-state

Conversation

@erikwb

@erikwb erikwb commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

What: Keep G17 pooled firmware objects that both the firmware and host write (compute::Graph, compute DescriptorRing, render QueueState, context WorkState, and M5 Scheduler) mapped MEMATTR_UNCACHED instead of converting them to non-coherent MEMATTR_CACHED, fixing dirty firmware cache-line evictions that reverted QueueRecord.job_list_va on compute rebinds and caused VK_ERROR_DEVICE_LOST watchdog timeouts and quarantined queues.
Tested: J716c M5 Max (T6050) at 3025a8dcbf66 (identical tree 0607db4616e9 tested on trial kernel 7.3.0-ewb313+ #8): two 4-way passes of dEQP-VK.synchronization2.op.multi_queue.* (6,000 cases each) passed 5,454/5,454 (546 unsupported, 0 failures, 0 DeviceLost, 0 GPU kernel errors), 8-way stress hit 0 DeviceLost and 0 quarantined slots, Hyprland desktop ran cleanly with 0 new kernel errors; tools/asahi/run-host-tests.py --only g17 93/93 passed.
Risk: two-way door · M4 Pro, M4 Max, M5 Pro, M5 Max, Neo (G17 GPUs)
Not yet: M4 Pro (T6040) / A18 Pro (T8140 / Neo) hardware regression row (hardware not in this lab).

Details

Root cause

Pool::allocate() converts [0..prefix) of pooled G17 firmware objects from MEMATTR_UNCACHED to MEMATTR_CACHED via set_fw_cached_prefix(), while the host accesses them through write-combined mappings. G17 has no firmware cache-flush protocol, and host CPU stores neither snoop nor invalidate dirty lines in the firmware coprocessor's private cache.

When firmware writes runtime state into a firmware-cached page and the host later overwrites fields on the same cache line, the firmware can read stale data from its cache and later evict the dirty line back to DRAM, reverting the host's update:

  • Compute queue graphs (drivers/gpu/drm/asahi/g17/queue/compute.rs): On J716c, rebinding an idle compute queue to a new context through Graph::set_owner() left the firmware's dirty QueueRecord cache line intact. On subsequent mixed render/compute work sharing a WorkNode, QueueRecord.job_list_va in DRAM reverted to the previous context's WorkHead (observed on 4/4 compute timeouts: qid=37, qid=15, qid=14, qid=4). Render linked the WorkNode onto the current context's WorkHead while compute targeted the previous context's WorkHead, leaving completed == submitted with a non-empty job list until the 2 s watchdog failed the client with VK_ERROR_DEVICE_LOST and quarantined the queues. Compute items[1280] also lived inside the cached prefix and wraps every 1,280 entries.
  • Compute descriptor rings (drivers/gpu/drm/asahi/g17/queue/compute.rs): Common M5 firmware clears the accounting counter at +0xfac, and the host rewrites each slot every 32 kicks.
  • Render queue-state objects (drivers/gpu/drm/asahi/g17/queue/render/memory.rs): Both firmware and host write QueueRecord (in-place set_owner() and bind_work_slot() on G17P, and zeroing on pool reuse on all G17 GPUs).
  • Context work-state objects (drivers/gpu/drm/asahi/g17/context.rs): Both firmware and host write WorkNode[0..62] (reused every 63 submissions via WorkStorage::initialize() and zeroed on pool reuse).
  • M5 context scheduler pages (drivers/gpu/drm/asahi/g17/context.rs): Written by firmware and zeroed/reinitialized on pool reuse.

Changes

  1. drivers/gpu/drm/asahi/g17/object.rs: Allow Pool::allocate() with prefix == 0 to keep the mapping MEMATTR_UNCACHED (skipping set_fw_cached_prefix() and its tlbi_all()) while preserving pool reservation, control_fence(), A18 Pro ReturnMark tracking, retain_until_stop(), and O(1) VA reuse. The if prefix == 0 early return is placed after if !reserved so pending pool-fencing work stays cleanly ordered.
  2. drivers/gpu/drm/asahi/g17/queue/compute.rs: Allocate installed compute graphs directly as uncached KernelObjects (they live until firmware stop and no longer consume Family::QueueState pool slots needed by render pairs), pass prefix = 0 for compute DescriptorRing, and add Ordering::Release barriers after Graph::set_owner().
  3. drivers/gpu/drm/asahi/g17/queue/render/memory.rs: Pass prefix = 0 for Family::QueueState and add Ordering::Release barriers after Memory::set_owner().
  4. drivers/gpu/drm/asahi/g17/context.rs: Pass prefix = 0 for Family::WorkState and M5 Family::Scheduler. Leave firmware-read-only render descriptors (which already fall back to uncached on M5 due to the 32-page conversion limit) and QueueConfig pools unchanged.
  5. tools/asahi/g17-object-fence-tests.py: Assert set_fw_cached_prefix is never called for prefix == 0 and add uncached_pooled covering pool leases, ReturnMark, control_fence(), reuse zeroing, retain_until_stop(), and stop_after_firmware().
Evidence

J716c (T6050, M5 Max) hardware row

  • Commit: 3025a8dcbf6625b2a98edf4faa8cadf4262efd6f (tree 0607db4616e98a5e75b5649935d0ee6098a550a7, identical built kernel to f2fc7fd815da; only commit message wording updated).
  • Build: 7.3.0-ewb313+ #8 SMP PREEMPT (one-shot aura-try trial boot, default kernel command line).
  • Userspace: Borealis Vulkan ICD (asahi_icd.aarch64.json), deqp-vk (synchronization2.txt, first 6,000 cases of dEQP-VK.synchronization2.op.multi_queue.*).
Run Concurrency Elapsed Passed Failed Not supported DeviceLost ResourceError GPU dmesg errors Quarantined
Baseline (origin/main) 12-way ~20 s aborted 9/12 procs — 9 procs — multiple watchdog timeouts yes
Patched pass 1 4-way 105.1 s 5,454 0 546 0 0 0 0
Patched pass 2 4-way 110.8 s 5,454 0 546 0 0 0 0
Patched stress 8-way 39.6 s 2,514 5 23 0 5 (58-queue LogicalQueues cap) 0 0
  • Steady-state compute microbenchmark (vkCmdFillBuffer, single queue, 2,000 d1 / 8,000 d64 submissions): d1 = 128.4 us/submit, d64 = 15.4 us/submit.
  • Desktop & capacity after stress: Hyprland running normally (m5-gpu.lua), crashed=0, online=1, physical_qids used=124/128 (tiling=49 fragment=49 compute=26), render_slots quarantined=0, cached_objects_fenced overruns=0, firmware_linked_objects kept=0, 0 new kernel errors (pre-existing aurora-peripherals.service failure unchanged from default boot).

Host tests & checks

  • python3 tools/asahi/run-host-tests.py --only g17: 93/93 passed (2 s), including g17-object-fence-tests and all 5 mutations.
  • ./scripts/checkpatch.pl --strict --git origin/main..HEAD: total: 0 errors, 0 warnings, 0 checks, 269 lines checked.
  • git diff --check origin/main..HEAD: clean.

On G17, Pool::allocate() converts the requested prefix of pooled firmware
objects from MEMATTR_UNCACHED to MEMATTR_CACHED via set_fw_cached_prefix(),
while the host accesses them through write-combined mappings. G17 firmware
has no cache-flush protocol, and host CPU stores neither snoop nor
invalidate dirty lines in the firmware coprocessor's private cache.

When the firmware writes runtime state into a firmware-cached page and the
host later overwrites fields on the same cache line, the firmware can read
stale data from its cache and later evict the dirty line back to DRAM,
reverting the host's update. On J716c (T6050), rebinding an idle compute
queue to a new context through Graph::set_owner() left the firmware's
dirty QueueRecord line intact: on subsequent mixed render/compute work,
QueueRecord.job_list_va in DRAM reverted to the previous context's
WorkHead, stranding shared WorkNodes with completed == submitted and a
non-empty job list until the 2 s watchdog failed the client with
VK_ERROR_DEVICE_LOST and quarantined the queues.

The same dirty-line hazard applies to every pooled G17 object that both
the firmware and the host write:
- Compute queue graphs (QueueRecord rewritten on rebind, items ring
  rewritten on wrap). Because installed compute graphs live until firmware
  stop, allocate them directly as uncached KernelObjects, freeing
  Family::QueueState pool slots for render pairs.
- Compute descriptor rings (M5 common firmware clears the accounting
  counter at +0xfac, and the host rewrites each slot every 32 kicks).
- Render queue-state objects (QueueRecord rewritten on G17P rebind and
  work-slot bind, and zeroed on pool reuse everywhere).
- Context work-state objects (WorkNode slots rewritten every 63
  submissions and zeroed on pool reuse).
- M5 context scheduler pages (zeroed and reinitialized on pool reuse).

Allow Pool::allocate() with prefix == 0 to retain and fence an uncached
mapping without calling set_fw_cached_prefix(), preserving control-ring
fencing, A18 Pro ReturnMark tracking, retain_until_stop(), and O(1) VA
reuse. Pass prefix == 0 for compute DescriptorRing, render QueueState,
WorkState, and M5 Scheduler allocations, leave firmware-read-only render
descriptors (which already fall back to uncached on M5 due to the 32-page
conversion limit) and QueueConfig pools unchanged, add release barriers
after QueueRecord owner rebinds, and cover prefix == 0 pool retention in
tools/asahi/g17-object-fence-tests.py.

Signed-off-by: Erik Bourget <[email protected]>
@erikwb
erikwb requested review from a team and DjDeveloperr as code owners November 25, 2026 18:36
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) blast:m4 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) blast:neo 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 Nov 25, 2026
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Merge readiness at 3025a8dc: ready to merge

Check Detail
CI at head ok 18 checks passed
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head ok in the PR body at 3025a8dc
Conflicts ok none
PR text ok Risk: two-way · M4 Pro, M4 Max, M5 Pro, M5 Max, Neo (G17 GPUs)

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

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

Audited full 307-line diff across all 5 files at 3025a8dcbf66: keeping firmware-mutable pooled G17 objects (Scheduler, WorkState, DescriptorRing, render QueueState) uncached via prefix == 0 in Pool::allocate() while preserving pool leasing/fencing/reuse zeroing/retention, allocating compute::Graph uncached directly, adding Ordering::Release fences after in-place owner/queue-record updates, and covering prefix == 0 in tools/asahi/g17-object-fence-tests.py cleanly addresses the non-coherent firmware writeback hazard. DCO, J716c 5,454/5,454 multi_queue.* + 8-way stress, and 93/93 host tests look solid.

Holding merge until CI completes and a second-generation G17 regression row (M4 Pro or Neo) lands.

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (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

3025a8d J616s (MacBook Pro 16" M4 Pro, T6040, Apple M4 Pro (G16S B1) g17, guarded one-shot default cmdline 7.3.0-aurora-pr3170+, verbatim fleet89 config combining disjoint exact heads #3170 3025a8dcbf66 + #3139 8677cbde1ddc + #3160 b5cc5906a955, all #3170 files 0-line diff vs 3025a8dcbf66) PASS:

  • 8-way concurrent compute+render stress (4x compute.light + 4x render.light): 8/8 ok, 0 DeviceLost, 0 quarantined queues.
  • Vulkan CTS: dEQP-VK.synchronization2.op.multi_queue.binary_semaphore.* 1,422/5,622 Pass / 0 Fail / 4,200 NS; dEQP-VK.synchronization2.op.multi_queue.timeline_semaphore.* 1,422/4,269 Pass / 0 Fail / 2,847 NS; dEQP-VK.query_pool.statistics_query.* 18,770/18,775 Pass / 0 Fail / 5 NS; dEQP-VK.query_pool.concurrent_queries.* 2/2 Pass.
  • Borealis gpubench-vk (render.light 122.55 us, compute.light 99.55 us) + gpubench-gl (render.postfx 1080p 1665 fps, crc=2133faaa valid=true) ok; rtc1 s2idle 1/1 (success=1 fail=0), post-wake VK (126.71/113.13 us) + GL (1635 fps, crc=2133faaa valid=true) ok; 0 AVC, 0 failed units, Enforcing; restored 7.3.0-aurora-fleet89 verified.

@DjDeveloperr
DjDeveloperr merged commit 4b3f0fd into main Nov 25, 2026
20 checks passed
@DjDeveloperr

Copy link
Copy Markdown
Contributor

Tested (J700 MacBook Neo, Apple A18 Pro T8140 / G17P B1, post-merge one-shot kernel row): PASS (correctness, stability) with a ~30–34% light-submission throughput regression flag at exact head 3025a8dcbf6625b2a98edf4faa8cadf4262efd6f (7.3.0-neo-pr3170, vmlinuz SHA-256 db808db7..., aurora.ko SHA-256 cfd87077...).

  • Host tests & boot: 93/93 g17 host tests passed (6/6 g17-object-fence-tests.py), 0 new compiler/rustc warnings on touched lines. Booted cleanly via one-shot grub2-reboot with default 7.3.0-41 cmdline verbatim (wld0 + eDP-1 up, SELinux Enforcing, 0 GPU faults, 0 quarantined slots, 0 WARNs, 0 AVC denials, 0 failed units).
  • Vulkan CTS & correctness (7.3.0-neo-pr3170, system Mesa git-d4ad4a4dce):
    • Full dEQP-VK.synchronization2.op.multi_queue.* (23,760 cases) × 3 full passes: 4,266 Pass, 19,494 NotSupported (single queue family on Borealis G17P), 0 Fail / 0 DeviceLost / 0 recoveries on all 3 runs (1,422 each of binary_semaphore, fence, timeline_semaphore).
    • Offline Geekbench 6.7.1 Vulkan: 8/8 workloads completed, 0 validation errors (GPU busy within 1% of the earlier 7.3.0-neo-wavec kernel).
    • Vulkan compute CRCs: 5/5 matched; 9/9 gpubench-vk smoke rows exited 0.
  • Performance flag (needs follow-up audit vs 4c9c91db): Compared against both -41 and the earlier main+Wave C (7.3.0-neo-wavec, without #3170) kernel on this same machine, light overlapping submissions slowed significantly with unchanged submit CPU time (consistent with higher firmware latency from uncached pooled state):
    • render.light single-queue d4 / d8 / d32: +30% / +33% / +34% slower
    • render.light multi-queue d2 / d4 / d8: +16% / +20% / +21% slower
    • compute.light d4: +31% slower
  • Restore: Rebooted cleanly back to 7.3.0-41.fc44.aurora.aarch64 with byte-exact /boot, ESP, /lib/modules, BLS, rpm -qa, and grubenv restore (0 failed units, sleep guard active).

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) blast:neo 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