Skip to content

drm/asahi: g17: stop aliasing the render context at low addresses - #3941

Merged
RyanTheTide merged 1 commit into
aurora-silicon:mainfrom
jgoyvaerts:g17p/no-low-context-aliases
Dec 2, 2026
Merged

RyanTheTide merged 1 commit into
aurora-silicon:mainfrom
jgoyvaerts:g17p/no-low-context-aliases

Conversation

@jgoyvaerts

Copy link
Copy Markdown
Contributor

What: On G17P, stop mapping a second, GPU-writable copy of each client's render context at VA 0, and stop requiring userspace to bind six more copies of it at 0x18000..0x74000. Nothing reads those copies, because the hardware adds the 0x10_0000_0000 base itself. This removes the per-VM registry that tracked them (+55 -424 lines).
Tested: J616s M4 Pro (T6040, firmware 25G83) at 969bbd2, applied to our downstream 7.3 kernel:

  • VA 0 reads zero and a store there is dropped.
  • 39,372 dEQP-VK cases with two Mesa builds and 1,393 GLES3/GLES3.1 cases match the baselines.
  • 0 GPU recoveries and 0 GPU kernel errors.
    Risk: two-way door · G17P Macs except M5: M4 Pro and M4 Max (T6040/T6041), MacBook Neo (T8140). Userspace that still binds the low ranges keeps working: those become ordinary binds. The uAPI is unchanged apart from a doc note.
    Not yet:
  • Runs on the M4 Max and the Neo. If you can, the robustness2, compute and draw lists on your Neo and M4 Max would cover them.
  • Ray query and mesh workloads, and games.
  • Mesa stops binding the low ranges in a separate PR, once kernels with this change have shipped. Older kernels refuse compute binds without them.
Details

Before this change:

  • On a G17P client's first compute bind, install_job_context_aliases() mapped the first 64 KiB of the render context (bound by userspace at 0x10_0000_0000) a second time at VA 0, PROT_GPU_SHARED_RW.
  • It failed the bind with ENOENT/EFAULT unless userspace had also bound CONTEXT_VIEWS 1-6 at their low addresses, backed by the same pages.
  • A per-VM registry (mmu/context.rs) tracked the canonical binds for that check, on every bind, unmap, deferred unmap and object close.
  • vm_bind refused single-page binds over the canonical ranges.

Why nothing needs the copies:

  • The firmware is told the base: the HwData words at 0x10 and 0x18 are 0x10_0000_0000 (g17/fw/initdata.rs).
  • The tiling and VDM registers are offsets from that base (USER_BASE in g17/fw/render.rs).
  • The compute registers (cdm_va, usc_base) carry full addresses (g17/fw/compute.rs).
  • So no command points into 0..0x74000.

What changes:

  • The writable copy at VA 0 also meant a shader's null-pointer store overwrote the context's Bind0 image. VA 0..0x10000 stays a reserved driver range (client_reserved_ranges) and is now unmapped. With soft faults, a load there reads zero and a store is dropped.
  • Removed: the aliases, the registry and its hooks in mmu.rs, mmu/bind.rs, mmu/lifetime.rs (including append_driver_mappings, whose only caller was the alias install) and file.rs, CONTEXT_VIEWS in hw/t8140.rs, and the G17 notes in g17/mod.rs and the DRM_ASAHI_FEATURE_SOFT_FAULTS documentation.
  • translate_iova, translate_pages and translate_each move unchanged from mmu/context.rs into mmu.rs.
  • M5 never installed the aliases and is unchanged.
Evidence

Build.

  • aurora_defconfig: drivers/gpu/drm/asahi/ compiles with no new warnings.
  • KUnit (arm64 qemu, asahi suites): 963 run, 962 pass, 1 skip.
  • checkpatch: 0 errors. Its one warning is the generic MAINTAINERS note for a deleted file; MAINTAINERS has no asahi entry.

A/B before this change, same Mac and default command line, one kernel. A test-only switch skipped the aliases for clients created after it was set; the desktop kept its own.

aliases installed aliases skipped
VA 0, 512 words the context's Bind0 (0x80 at +0) zero
store to VA 0, then read — dropped, reads zero, Bind0 unchanged
dEQP-VK, 8 lists, 39,372 cases, system Mesa baseline 0 cases differ
same lists, Mesa without the low binds — 0 cases differ; 0x18000/0x58000/0x68000 read zero
GLES3 392 + GLES3.1 ssbo/compute/image/sync subset 1,001 (gallium) 392/392, 1001/1001 392/392, 1001/1001, 0 results differ
GPU recoveries / kernel fault lines 0 / 0 0 / 0

The 8 lists:

list cases
compute (every 4th) 16,889
ssbo 12,225
robustness2 subset 1,364
buffer_access 1,212
line rasterization 797
texturing 233
draw (every 5th) 5,895
graphicsfuzz 757

At this change (969bbd2, no switch):

  • VA 0 reads zero. A 512-word store to VA 0 completes and reads back zero. Bind0 at 0x10_0000_0000 is unchanged.
  • The Mesa without the low binds reads zero at 0x0, 0x18000, 0x58000 and 0x68000.
  • dEQP-VK, all 8 lists, both Mesa builds: 0 cases differ from the stored baselines.
  • GLES3 392/392 and GLES3.1 subset 1001/1001.
  • 0 GPU recoveries and 0 GPU kernel lines.
  • The desktop (gallium) ran on this kernel throughout.

Regression on the same boot:

  • SELinux is not enabled on this machine.
  • One failed unit, speakersafetyd, which also fails on earlier kernels here and is unrelated.
  • Two kernel error lines, both outside the GPU driver: a busy btrfs loop device, also seen on the previous boot, and a Wi-Fi station-info error.
  • This boot also carried asahi.mem_limit_pct=25 for an unrelated test. This change reads no parameter, and the A/B above ran on the default command line.

Tools.

  • dEQP-VK through deqp-runner, -j 10.
  • dEQP-GLES3/GLES31 on EGL pbuffers.
  • A small Vulkan probe that reads and stores raw GPU addresses through buffer device addresses.

On a G17P client's first compute bind the driver mapped the first 64 KiB
of the render context, which userspace binds at 0x10_0000_0000, a second
time at VA 0, GPU-writable. It also refused the bind unless userspace had
bound six more ranges of that object a second time at 0x18000..0x74000.
A per-VM registry tracked the canonical binds for that check, on every
bind, unmap and object close.

Nothing reads those copies. The hardware adds the 0x10_0000_0000 base
itself: the HwData words at 0x10 and 0x18 hold it, the tiling and VDM
registers are offsets from it, and the compute registers carry full
addresses. Measured on the M4 Pro (T6040, firmware 25G83) with the
aliases skipped and with userspace not binding the low ranges at all:
GPU VA 0..0x74000 reads zero, 39,372 dEQP-VK cases (compute, SSBO,
robustness, line rasterization, texturing, draw, graphicsfuzz) and
1,393 GLES3 and GLES3.1 cases (including compute, SSBO and images)
give the same results as with the aliases, with no fault or GPU
recovery.

The writable copy at VA 0 also let a shader's null-pointer store
overwrite the context's Bind0 image. VA 0..0x10000 stays reserved and is
now unmapped, so a load there reads zero and a store is dropped.

Remove the aliases, the registry and its hooks, CONTEXT_VIEWS, and the
G17 note in the SOFT_FAULTS documentation. Userspace that still binds
the low ranges keeps working: those are ordinary binds of its own.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
@jgoyvaerts
jgoyvaerts requested review from a team and DjDeveloperr as code owners December 2, 2026 14:19

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed 969bbd2e08bf across drivers/gpu/drm/asahi/ (file.rs, g17/mod.rs, g17/queue/compute.rs, hw/t8140.rs, mmu.rs, mmu/bind.rs, mmu/context.rs, mmu/lifetime.rs) and include/uapi/drm/asahi_drm.h.

Code audit looks very clean:

  • No leftover references to CONTEXT_VIEWS, context_bindings, install_job_context_aliases, append_driver_mappings, or validate_context_binding.
  • translate_iova(), translate_pages(), and translate_each() move verbatim from deleted mmu/context.rs into mmu.rs.
  • Lock-drop ordering in mmu/bind.rs (drop(inner); drop(commit);) and mmu/lifetime.rs is preserved, and client_reserved_ranges() keeps 0..0x10000 reserved/unmapped so null-pointer stores no longer clobber Bind0.
  • Strong J616s M4 Pro evidence (39,372 dEQP-VK cases with both Mesa builds + 1,393 GLES3/3.1 cases, 0 faults/recoveries, plus honest **Not yet:** for M4 Max / Neo).

Holding APPROVE until CI (apple-build, KUnit asahi, host-tests, pr-text, readiness) finishes green. One minor evidence note: the exact-head 969bbd2e08b boot carried asahi.mem_limit_pct=25 (while the pre-change A/B ran on the default command line) — if convenient, a quick default-cmdline sanity pass at 969bbd2e08b would make exact-head default-cmdline evidence airtight.

@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 Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Merge readiness at 969bbd2e: not ready yet

Check Detail
CI at head no failing: host-tests
Review ok approved by satchlj
Requested changes ok none
Hardware row at head ok in the PR body at 969bbd2e
Conflicts ok none
PR text ok Risk: two-way · G17P Macs except M5: M4 Pro and M4 Max (T6040/T6041), MacBook Neo (T8140). Userspace that still binds the low ranges keeps working: those become ordinary binds. The uAPI is unchanged apart from a doc note.

Areas: area:gpu

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

@github-actions github-actions Bot added the ci-failing A check failed at the PR head (bot) label Dec 2, 2026

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Flipping to APPROVE at 969bbd2e08bf.

apple-build, KUnit asahi, pr-text, and readiness are all green. Verified the host-tests run 46901295230 failure log: the only failing jobs were the pre-#3939 apple-dcp / display-sleep-merge-tests (dcp->ext272) fixtures (now fixed on main by #3939); all GPU/asahi host tests passed (a rerun or merge with main will clear host-tests). LGTM.

@satchlj

satchlj commented Dec 2, 2026

Copy link
Copy Markdown
Member

Built exact head 969bbd2e08bf (tools/aurora-bindgen, 0 bindgen warnings) and ran a default-cmdline one-shot trial on M5 Max (J775c, T6050, G17C B1, Stage 2 aura 1.0.0b19).

Stage 2 refuses FDT preparation and falls back cleanly before Linux boots:

DCP: T6050: dcpext0 handed off: bw-scratch 0x2c000
DCP: T6050: no /chosen/framebuffer@10fd805c000 simple-framebuffer
DCP: T6050: display handoff refused; the boot framebuffer keeps the display
FDT: live RTKit: no node for alias dcpext0
FDT: couldn't describe the live DCP RTKit session
Failed to prepare FDT!
No valid payload found

Root cause: 969bbd2e08bf is branched off cd5cb0485700 (335 commits behind main), so its t6050-j775c.dtb predates #3682 (dcpext0 alias / HDMI handoff expected by aura 1.0.0b19) as well as merged G17 GPU commits (#3775, #3833, #3862, #3920). host-tests CI is also failing at this head.

Please rebase onto current main — once updated, I can run the exact-head default-cmdline J775c trial (Vulkan CTS, gpubench-rt-vk, llama-bench, and s2idle) immediately.

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

Copy link
Copy Markdown
Contributor

Local CI receipt for the red hosted host-tests (run 46901295230). The failure doesn't come from this PR.

Tree: head 969bbd2e08bf merged onto main 3820bed1b9bd. The merge is clean. Merge tree 57292bb12b1f, local merge commit 293e93c07463. The run used a container matching host-tests.yml (Ubuntu 24.04, clang 18.1.3, gcc 13.3.0, rustc 1.96.0, Python 3.14.10) with --network=none.

  • python3 -I tools/asahi/run-host-tests.py --jobs 10: 959/959 pass on the merge.
  • run-host-tests.py --only apple-dcp: passes on main 3820bed1b9bd and on the merge, 101/101 TAP cases each.
  • run-host-tests.py --only display-sleep-merge: passes on both.

The hosted run tested a merge with main 340bb06c1ddc, from before #3939 fixed the apple-dcp and display-sleep-merge-tests fixtures (ext272). Current main has that fix.

I haven't merged it, because the hardware rows aren't complete. Besides the G17P alias code, the change removes hooks from the bind, unmap and close paths that every GPU generation runs (file.rs, mmu.rs, mmu/bind.rs, mmu/lifetime.rs). The only row so far is the M4 Pro (G17P), so it still needs a row from another generation. The M5 Max trial above never reached Linux because this branch's base predates the current T6050 device trees. A run of this commit merged with current main would avoid that.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merging at 969bbd2e08bf (B2 merge train, 12-01 merge bar). Approval at this head: satchlj. Row: in the PR body at 969bbd2. CI: linux train L25 (candidate 9a7e32597c82 on main 515377d): Apple driver build pass + changed .c objs pass + DTBs pass + KUnit pass (dcp-topology, asahi; confirms #3153 -Werror,-Wunused-function fix) + host tests pass (g17 329/329). Revert: git revert -m 1 <merge commit>.

@RyanTheTide
RyanTheTide merged commit e0dabb4 into aurora-silicon:main Dec 2, 2026
11 of 12 checks passed
@DjDeveloperr

Copy link
Copy Markdown
Contributor

J773g (M4 mini, T8132, G16G B0, OS FW 27.2 / 26B123) — PASS (second-generation G16 row)

Tested exact PR head 969bbd2e08bf5a02bba2efae4a3ee37aee3e69fe merged --no-ff onto origin/main 515377db2a76845168a03e2d2b2dfb8828f66e35 (merge commit 1b012a51a5f5f27778a07bf76ed7c818888719a9, merge tree c2eb591461ae618036d2c65d0a498656c550ab64, 0 conflicts, 9 files changed: file.rs, mmu.rs, mmu/bind.rs, mmu/lifetime.rs, mmu/context.rs deleted, etc.).

  • Kernel: 7.3.0-j773g-pr3941-969bbd2e (warm arm64 build, CONFIG_DRM_ASAHI=m, CONFIG_DRM_ASAHI_G16=y, panic=10, WDT armed 178 s), boot_id=187c9159-3e6a-4409-95e8-b5146ba5c358
  • Userspace: Mesa 26.3.0-devel (git-d4ad4a4dce) (Borealis Vulkan 1.4.363 + OpenGL ES 3.2), DP-3 3840x2160@60, plasmalogin=active
  • GPU smoke (gpubench-vk --verify + glmark2-es2-wayland):
    • render.light (queue d1), compute.light (queue d1), mem.buffer (queue d1), mem.image (queue d1): all "status":"ok", all CRCs valid
    • Multi-process bind/unmap/close churn (compute.light, procs d4 x3 iterations): all "status":"ok", CRCs valid (bc4eccbd)
    • glmark2-es2-wayland --off-screen: build 6774 FPS, texture 6809 FPS, Score 6790
  • Vulkan dEQP (bind/unmap/mapping/lifetime coverage):
    • dEQP-VK.api.smoke.*: 8/8 PASS (0 Fail)
    • dEQP-VK.memory.mapping.* (full): 4466/4466 PASS (0 Fail, 0 NotSupported)
    • dEQP-VK.memory.* (213 sampled across alloc/bind/map/unmap): 167/213 PASS, 0 Fail, 46 NotSupported
    • dEQP-VK.api.object_management.single.device_memory*: 1/1 PASS (0 Fail)
    • dEQP-VK.sparse_resources.* (205 sampled + 5 sparse_binding): 0 Fail (210 NotSupported — sparseBinding/shaderResourceResidency not advertised on Borealis G16)
  • GLES3 & EGL dEQP (Wayland hidden pbuffer):
    • dEQP-GLES3.functional.{buffer.map,buffer.write,lifetime}.* (159 sampled): 159/159 PASS (0 Fail)
    • dEQP-EGL.functional.{create_context,create_surface.pbuffer}.* (43 cases): 33/43 PASS, 0 Fail, 10 NotSupported
  • Kernel & GPU health:
    • aurora-g16: G16: UAT leaf self-check passed (9 classes), firmware READY, 0 GPU recoveries, 0 GPU faults/errors (AURORA_DMESG_ERRS=0)
    • WARN_BUG_OOPS_SERROR=0, FAILED_UNITS=0
  • Handback: Rebooted cleanly back to verified steady stock 7.3.0-ARCH-m4main-6c83a2a6.

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) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants