Skip to content

drm/asahi: G14 27.2: bind timestamp buffers, fix timestamp operations, admit sampler heaps and helpers - #3086

Merged
RyanTheTide merged 7 commits into
mainfrom
m2gpu/g14-v27-2-timestamps
Nov 24, 2026
Merged

RyanTheTide merged 7 commits into
mainfrom
m2gpu/g14-v27-2-timestamps

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What: On the G14 firmware 27.2 runtime (M2 mini), three uAPI paths that work on 13.5 were refused or broken:

  • Timestamps: GEM_BIND_OBJECT with USAGE_TIMESTAMPS returned ENOTSUPP, so Vulkan timestamp query pools failed (vkCreateQueryPool -2) and OpenCL profiling failed. The firmware copies the kernel window's second-level entries once, before it starts. The fix links the 64 MiB timestamp aperture's leaf tables, with no mappings, before the window is mirrored, the same way the lower tables are prepared. The common map_timestamp_buffer then maps into the profile's aperture, so binding, retention and unmapping are the 13.5 code.
  • Timestamp operations: the word now names the command's start/end pair, as on 13.5 and M3 27.2. The 27.2 render streams had written the user destinations into it, so the firmware would have written stamps through the user buffer's contents. Compute commands get their pair at +0x2dc, after the internal timestamp pointers, and set JobMeta flush_stamps like the 27.2 render and M3 27.2 compute commands do.
  • Sampler heaps and helper programs: the front end shared with M3 refused render commands that name a sampler heap (ENOTSUPP), so every Zink application lost its device. It also refused compute helper programs (EINVAL). The G14 27.2 builders already encode both in the 13.5 places, so the queue now says so (samplers_and_helpers, like zls_compression_all_layouts). The sampler heap is then validated rather than refused. Every helper descriptor must be either empty, or a tagged program in the queue's USC window plus an 8-byte-aligned argument block the VM maps read-write. M3 queues refuse both as before.

Tested: J473 (M2 mini, G14G, firmware 27.2), kit built from 1135c9ef. This head b77cd168 only changes two code comments on top (shown in the commit). Default cmdline, saved fleet89 Stage 2, GNOME session:

  • gpubench compute.light with GPU timestamps (16-64 commands in flight): 24 of 24 loops, 7/7 ok each, 0 timeouts.
  • gpubench Vulkan: 99 ok / 12 skip / 0 fail (fleet87: 12 ok / 11 fail).
  • gpubench GL native 43/43, Zink 43/43, including render.postfx MSAA4 (fleet87 Zink 39/41, with 2 segfaults).
  • glmark2 native 1893, Zink 1406 (fleet87: Zink crashed, rc=139).
  • Geekbench 6 Vulkan completes all 8 workloads, and piglit shader-mem-barrier passes.
  • Kernel log: 0 rejected, 0 MMU faults, 0 timeouts, 0 Oops. gnome-shell kept its PID, and fresh vkcube and vulkaninfo returned 0.
  • Production was restored and verified.

J413 (M2 Air, 13.5, shares the common timestamp path), same kit: gpubench Vulkan 99 ok / 0 fail, GL native and Zink 43/43, Geekbench 6 Vulkan 8/8, s2idle pass. This is identical to its fleet89 baseline.

Host tests: g14_v27_2_abi.rs 8/8, plus m3-uapi (with the new helper cases), queue-priority and asahi-m4 all pass.

Risk: two-way · J473 and any G14G Mac on 27.2 (all changes), and every Mac using the native graph (the timestamp range moves from a constant to a graph field with the same value). M3 queues keep their refusals. M3 27.2 on main still needs #2147, so no M3 Mac runs this front end from main today.

Not yet:

  • OpenCL end to end: with RUSTICL_ENABLE, Geekbench 6 OpenCL now runs Background Blur and Face Detection on the GPU. It then stops at Horizon Detection in Fedora's libclc (nir_shader not fully linked), which is userspace (fedora-aurora#498).
  • Compute commands that carry a sampler heap are still refused, because the 27.2 compute sampler placement isn't known.
Review history
Evidence

Our own traces, traces/gpu/20261125-m2gpu-next/:

  • 20261125-093451-j473-u1d-m2t7 (J473, this kit): row/hang/it* (the 24 compute loops), gpubench, gl-native, gl-zink, glmark2-*, gb6-*, klog-*.
  • j413-t7 (J413).
  • The hang A/B and revert: *-j473-ab-m2z1, *-j473-ab-m2z2lab, *-j473-ab-m2rv1.
  • The fleet87 baseline is the default-install sweep in traces/gpu/20261124-neon-bench-fleet.

The Timestamp operation of a firmware command stream carries one word
for the user timestamps. In the 13.5 command layout and in the M3 27.2
runtime that word names the command's pair of user start and end
destinations; the firmware reads the destination from that pair. The
G14 27.2 render streams instead stored the start destination in the
start operation and the end destination in the end operation, so the
firmware would have read the user buffer's contents as the pair and
written its stamps wherever they pointed. The compute stream left the
word and the pair empty, so compute commands never got user
timestamps.

No user timestamps reach this runtime yet, since it refuses to bind
timestamp buffers, so neither has been seen. Make the word name the
pair the render commands already carry, or zero without user
timestamps, as the M3 27.2 render and compute encoders do. Give the
compute command its pair after the internal timestamp pointers, where
the 13.5 compute command and the 27.2 render commands keep it, and
pass the packet's compute destinations to it.

The pair placement and the operation word are host-tested.

Signed-off-by: Ryan Murray <[email protected]>
GEM_BIND_OBJECT with USAGE_TIMESTAMPS returned ENOTSUPP on the G14
firmware 27.2 runtime, so Vulkan could not create timestamp query pools
and OpenCL profiling failed. That firmware reaches the kernel window
through its own copy of the window's second-level entries, made once
before it starts (FirmwareWindow::mirror), so a leaf table created
later for a timestamp buffer would never be seen by it.

The graph already keeps its private allocations below the 64 MiB
timestamp aperture that the 27.2 root hands to the firmware. Link the
aperture's leaf tables, with no mappings, before the window is
mirrored, the way the kernel lower tables are prepared for a firmware
that samples its root only at start (Uat::prepare_lower_tables, now
sharing one helper with the new prepare_kernel_tables). Page tables are
only freed with their VM, so the mirrored entries stay valid; leaf
entries written later are cleaned to the point of coherency by the
adopted UAT's page table as for every other firmware mapping.

The graph records its profile's timestamp aperture, and the common
GpuManager::map_timestamp_buffer maps into it: the native aperture as
before, the 27.2 one for the 27.2 profile. The 27.2 backend delegates
to it as it does for its parameters and clock, so timestamp buffers are
bound, retained by the commands that name them and unmapped exactly as
on the 13.5 path.

Signed-off-by: Ryan Murray <[email protected]>
The G14 firmware 27.2 runtime takes its client commands through the
front end shared with the M3 runtime, whose 26.x commands stream their
sampler state and carry no helper program, so that front end refuses
both. On the M2 this refused every render command that names a sampler
heap with ENOTSUPP: Zink renders through Borealis, which always names
its heap, so Zink applications lost the device on their first such
pass. Compute commands with a helper program, which Mesa uses for
scratch and stack setup, were refused with EINVAL by the common compute
translator.

The G14 27.2 render builders already write the sampler heap and both
helper programs where the 13.5 render commands keep them, and the 27.2
compute command carries the 13.5 compute JobParameters1, which holds
the helper. Let a queue say that its builders encode these, as it
already says which depth and stencil compression layouts it encodes,
and set it for the G14 27.2 queues. Their render admission then checks
the sampler heap like the compute translator does instead of refusing
it, and their compute commands take the helper from the client and
write it to the JobParameters1 places the 13.5 compute path fills. The
vertex helper's configuration goes to the tiling parameters, as on
13.5. The M3 queues refuse both as before.

The 27.2 compute command's sampler placement is not known, so compute
commands with a sampler heap are still refused.

Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide
RyanTheTide requested review from a team and DjDeveloperr as code owners November 24, 2026 16:20
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

J473 row: 7521672b (tree e207372c, built as 5e0aa733 before a message-only reword) on the J473 (M2 mini, G14G firmware 27.2): pass. gpubench Vulkan 99 ok / 0 fail, GL native and Zink 43/43, glmark2 Zink 1515, Geekbench 6 Vulkan 8/8, 0 rejected/MMU faults/timeouts, 0 failed units after restore.

J413 row: same three commits before the rebase onto main, on the J413 (M2 Air, 13.5): pass. gpubench Vulkan 99 ok / 0 fail (timestamp and occlusion queries included), Geekbench 6 Vulkan 8/8, s2idle pass, 0 failed units after restore.

Evidence

traces/gpu/20261125-m2gpu-next/20261125-025538-j473-u1-m2t2, traces/gpu/20261125-m2gpu-next/j413-t1. The PR body has the comparison with the fleet87 sweep.

@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 Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Merge readiness at b77cd168: not ready yet

Check Detail
CI at head no failing: pr-text / pr-text, pr-text / pr-text
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes no requested by DjDeveloperr
Hardware row at head ok in the PR body at b77cd168
Conflicts ok none
PR text ok Risk: two-way · J473 and any G14G Mac on 27.2 (all changes), and every Mac using the native graph (the timestamp range moves from a constant to a graph field with the same value). M3 queues keep their refusals. M3 27.2 on main still needs #2147, so no M3 Mac runs this front end from main today.

Areas: area:gpu

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

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Verdict at 7521672bcdc30572e3f42d2a71e7c3f86d567cae: HOLD on helper admission.

Blockers: m3_submit.rs now admits user-supplied compute and render helpers on the capable queue. The compute path removes the descriptor before translation, where the common translator rejects nonempty helpers. The render validation checks samplers and other resource addresses but has no matching check for the newly admitted helper descriptors. All three descriptors reach the encoder. Please validate each against the submitting GPU VM and the command format before forwarding it, or keep helper admission disabled while landing the timestamp and sampler changes separately.

Checked: The sampler heap uses the existing validator, the timestamp aperture is prepared before mirroring, and the ordinary J473 workload row is recorded. Completion of a valid workload does not exercise helper admission checks. Please repeat the exact J473 target row after the runtime change and identify the matching J413 regression build.

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

Verdict: HOLD at 7521672b

Blockers:

  1. drivers/gpu/drm/asahi/m3/m3_submit.rs:402-419, 472-504: User-supplied helper descriptors (compute.helper, render.vertex_helper, render.fragment_helper) are admitted on samplers_and_helpers queues without validation. The compute path strips payload.helper via core::mem::replace before agx_uapi::translate_compute_command (also zeroing payload.helper before the rejection log on line 409), and validate_render skips the non-empty helper rejection without checking vertex_helper or fragment_helper. Every other user-supplied GPU program/address in m3_submit.rs is checked against QueueUscWindow and AddressSpace (including !driver_range_overlaps). Validate all three helper descriptors before encoding (reject malformed descriptors with binary == 0 and non-zero config/data, verify binary tagging and mapped read coverage inside QueueUscWindow/AddressSpace, and validate config), or keep helper admission disabled and land timestamp binding, timestamp operations, and render sampler heaps separately.
  2. §5 hardware evidence: After updating helper admission, re-run and record the exact-head J473 (G14G, firmware 27.2) row (with SELinux/unit/kernel-error regression counts and helper validation coverage) and identify the exact tested commit SHA/build for the J413 (13.5) regression row.

Checked: §1–§4 and §6 pass (except §2/§3 helper validation blocker above); §5 J473 tree e207372c matches 7521672b, J413 row lacks commit SHA and J473 needs re-run after fix; CI green (host-tests, readiness, pr-text); zero AI attribution; clean human DCO across all 3 commits.

Evidence
  • Timestamp buffer binding (g14_v27_2.rs, gpu.rs, gpu/v27_2.rs, mmu.rs): Sound. prepare_kernel_tables links all L3 tables for IOVA_G14_V27_2_TIMESTAMP_RANGE (0xffffffa181400000..0xffffffa185400000) with clean_poc before FirmwareWindow::mirror/install. GpuManager::map_timestamp_buffer maps uncached (PROT_FW_SHARED_RW), keeps L3 tables on unmap, and invalidates via kernel_vm.slot() == Some(0). GraphProfile::Native keeps IOVA_KERN_TIMESTAMP_RANGE unchanged for G13/G14 12.3/13.5/14.x; G15–G18 paths are unaffected.
  • Timestamp operations (g14_v27_2_abi.rs, g14_v27_2_render.rs, gpu/v27_2.rs, g14_v27_2.rs): Sound. Vertex (+0x5e4), fragment (+0x948), and compute (+0x2dc) pass the pair VA (or 0 when [0, 0]) to both start/end Timestamp ops; compute +0x2dc..+0x2ec does not overlap encoded or firmware-written fields.
  • Render samplers (m3_submit.rs, agx_uapi.rs): validate_sampler enforces count <= 1024, zero-pair consistency, 8-byte alignment, and AddressSpace read coverage; M3 queues keep samplers_and_helpers: false; compute sampler heaps stay rejected with ENOTSUPP.
  • Non-blocking observations:
    • drivers/gpu/drm/asahi/m3/m3_submit.rs:472: DRM_ASAHI_RENDER_VERTEX_SCRATCH (1 << 0) is still rejected with ENOTSUPP and g14_v27_2_render.rs does not set uses_scratch, so Borealis vertex-scratch passes that set both the flag and vertex_helper will still be rejected until wired up.
    • drivers/gpu/drm/asahi/g14_v27_2_render.rs:417, 908: sampler_max (0x564, 0x8c8) is written as r.sampler_count rather than r.sampler_count + 1 as on G14 13.5 (queue/render.rs:872, 1323); worth verifying boundary indexing at sampler_count - 1.
  • Commits & CI: All 3 commits (e11accde9300, 9bc8fcc62648, 7521672bcdc3) authored/committed by Ryan Murray <[email protected]> with valid Signed-off-by:; host-tests, readiness / readiness, and pr-text / pr-text all SUCCESS at 7521672bcdc30572e3f42d2a71e7c3f86d567cae; PR is OPEN, isDraft: false, MERGEABLE.

@github-actions github-actions Bot added the changes-requested A reviewer requested changes (bot) label Nov 24, 2026
The G14 firmware 27.2 queues take render and compute helper programs
from the client and write them into the firmware commands, but nothing
checked them first. The common compute translator refuses any helper,
so the compute path removed the helper before translation, and the
render admission only checked that queues without helper support saw
none.

Check each helper descriptor before a queue takes it. It must either
be empty, or name a tagged program offset that the queue's USC window
maps readable, plus an 8-byte-aligned argument block that the
submitting VM maps read-write. A configuration word or argument block
without a program is refused. The render vertex and fragment helpers
and the compute helper all go through the same check, which sits next
to the sampler validation in the shared UAPI module. Queues that do not
encode helpers refuse them as before.

The m3-uapi host test covers empty, valid, stray, unmapped, misaligned
and read-only descriptors.

Signed-off-by: Ryan Murray <[email protected]>
The G14 firmware 27.2 compute command left its JobMeta flush_stamps
word clear. That did not matter while compute commands carried no user
timestamps. Once they do, a queue of them stops retiring: on the M2 mini,
gpubench compute.light at queue depth 16 timed out within one or two
runs. The firmware had fetched the commands but never retired them, no
MMU fault was pending and no firmware timeout event came.

Set flush_stamps, as the 27.2 render commands already do for their
JobMeta and as the M3 27.2 compute command does when it does not
coalesce. With it, the same loop ran eight times with every case
passing and no timeout.

Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide
RyanTheTide marked this pull request as draft November 24, 2026 18:37
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Status: draft. A compute hang was found with timestamps enabled, so this is not mergeable yet.

Review fixes (pushed):

  • 9579e14b validates every helper descriptor before a G14 27.2 queue takes it. A descriptor must be either empty, or a tagged program offset that the queue's USC window maps readable plus an 8-byte-aligned argument block mapped read-write. This applies to the render vertex and fragment helpers and the compute helper. It is host-tested in m3-uapi.
  • 4a0eae2e sets the compute JobMeta flush_stamps word, as the 27.2 render commands do.

What blocks it: with timestamp binding working, gpubench compute.light (16 or more compute commands in flight, GPU timestamps on) times out one G14 27.2 compute command within one or two runs on the J473 (M2 mini). It fails at 4a0eae2e (kit m2t6) and at 9579e14b (m2t3, with both Stage 2 builds b15 and b17):

  • GPU: compute command timed out, 16 commands outstanding.
  • The firmware either fetched more than it retired, or stopped fetching below the head.
  • FAULT_INFO=0, no firmware timeout event.
  • The whole GPU is then lost, because main has no per-client recovery.

An earlier run at 5e0aa733 happened to pass every depth once. Before this PR gpubench could not run on the J473 at all, so this load was never reached. It is not yet shown whether the hang needs the timestamps or only the queue depth.

Next:

  • Instrument the G14 27.2 command pool: slot reuse against the firmware's link state, and the doorbell when fetched equals retired below the head.
  • Compare with our own macOS 27.2 capture of a deep compute queue.
  • Meanwhile, the Zink fix (sampler heaps and validated helpers) goes in a separate PR without the timestamp commits.
Evidence

traces/gpu/20261125-m2gpu-next/: *-j473-u1b-m2t3, *-r-m2t3, *-rs2b15-m2t3, *-r2-m2t5lab (lab), *-u1c-m2t6, in particular row/hang/klog-it*.txt and klog-gpubench-vk.txt. The J413 13.5 regression at 4a0eae2e (j413-t6) matches its fleet88 baseline: gpubench Vulkan 99 ok / 0 fail, GL native and Zink 43/43.

@github-actions github-actions Bot removed changes-requested A reviewer requested changes (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 24, 2026
…tamps

# Conflicts:
#	drivers/gpu/drm/asahi/g14_v27_2_abi.rs
The comments added with the compute flush_stamps word said that a clear
word stalls a compute queue that writes user timestamps. A later A/B on
the M2 mini showed that those hangs came from the raised GPU
performance-state cap (reverted in #3091). With the cap restored, the
same compute loop ran 24 times clean. Say only why the word is set: the
27.2 render commands and the M3 27.2 compute command set it.

Comment-only change.

Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide
RyanTheTide marked this pull request as ready for review November 24, 2026 23:08
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

J473 row: b77cd168 (kit built from 1135c9ef; the head only adds a comment-only commit) on the J473 (M2 mini, G14G firmware 27.2): pass. compute.light with timestamps 24/24 loops, gpubench Vulkan 99 ok / 0 fail, GL native and Zink 43/43, Geekbench 6 Vulkan 8/8, 0 timeouts, 0 failed units after restore.

J413 row: b77cd168 (same kit) on the J413 (M2 Air, 13.5): pass. gpubench Vulkan 99 ok / 0 fail, GL native and Zink 43/43, Geekbench 6 Vulkan 8/8, 0 failed units after restore.

Evidence

traces/gpu/20261125-m2gpu-next/20261125-093451-j473-u1d-m2t7, traces/gpu/20261125-m2gpu-next/j413-t7

@github-actions github-actions Bot added changes-requested A reviewer requested changes (bot) ci-failing A check failed at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 24, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Independent review at b77cd1686972. The earlier unchecked-helper finding is addressed in the current source. The compute and both render paths validate helpers before submitting them. They use the submitting VM’s permitted mappings, and the legacy configuration word is accepted only with a validated program and data block. The M3 queue retains its prior admission rules. No new blocking source finding.

I verified that the only delta from the hardware-tested parent 1135c9efd2f0 is two comment edits, and reran the G14 ABI tests, 8/8 passed. The J473 archive records 24/24 timestamp compute loops with all seven depths passing on each loop, 168 samples and zero timeouts. The same kit booted on the J413 firmware-13.5 regression path, completed its Vulkan run and short wake, and restored saved fleet89. OpenCL still stops in the Fedora libclc workload. Please re-review the exact current head after the active hosted job finishes.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

@DjDeveloperr, your blocker at 7521672b (helper descriptors admitted unvalidated) is fixed by 9579e14b, and the current head is b77cd168.

  • agx_uapi::validate_helper checks every helper before a samplers_and_helpers queue takes it. That covers the compute helper and both render helpers. A helper is either empty, or a tagged program offset that QueueUscWindow::full_program finds readable in the submitting VM's USC window, plus an 8-byte-aligned argument block mapped read-write in that VM.
  • A configuration word or argument block without a program is refused.
  • The compute path validates before it takes the descriptor out of the translator's input. The render path validates after the program checks.
  • M3 queues refuse helpers as before.
  • The m3-uapi host test covers empty, valid, stray-config, stray-data, unmapped-program, misaligned, unmapped-data and read-only descriptors.

MERGETRAIN6's independent pass at b77cd168 found no blocking issue. The exact-head J473 and J413 rows are in the comment above. Could you re-review at b77cd168?

@RyanTheTide
RyanTheTide merged commit 4f65cab into main Nov 24, 2026
3 of 7 checks passed
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Merged at b77cd168 per the merge policy (CI green, exact-head J473 and J413 rows, independent review with no blocking finding). @DjDeveloperr, any further review items will become follow-up PRs.

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) changes-requested A reviewer requested changes (bot) ci-failing A check failed at the PR head (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.

2 participants