Repository navigation
drm/asahi: g17: stop aliasing the render context at low addresses - #3941
Conversation
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>
satchlj
left a comment
There was a problem hiding this comment.
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, orvalidate_context_binding. translate_iova(),translate_pages(), andtranslate_each()move verbatim from deletedmmu/context.rsintommu.rs.- Lock-drop ordering in
mmu/bind.rs(drop(inner); drop(commit);) andmmu/lifetime.rsis preserved, andclient_reserved_ranges()keeps0..0x10000reserved/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.
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
satchlj
left a comment
There was a problem hiding this comment.
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.
|
Built exact head Stage 2 refuses FDT preparation and falls back cleanly before Linux boots: Root cause: Please rebase onto current |
|
Local CI receipt for the red hosted Tree: head
The hosted run tested a merge with main 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 ( |
|
Merging at |
J773g (M4 mini, T8132, G16G B0, OS FW 27.2 / 26B123) — PASS (second-generation G16 row)Tested exact PR head
|
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:
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:
Details
Before this change:
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.ENOENT/EFAULTunless userspace had also boundCONTEXT_VIEWS1-6 at their low addresses, backed by the same pages.mmu/context.rs) tracked the canonical binds for that check, on every bind, unmap, deferred unmap and object close.vm_bindrefused single-page binds over the canonical ranges.Why nothing needs the copies:
g17/fw/initdata.rs).USER_BASEing17/fw/render.rs).cdm_va,usc_base) carry full addresses (g17/fw/compute.rs).What changes:
client_reserved_ranges) and is now unmapped. With soft faults, a load there reads zero and a store is dropped.mmu.rs,mmu/bind.rs,mmu/lifetime.rs(includingappend_driver_mappings, whose only caller was the alias install) andfile.rs,CONTEXT_VIEWSinhw/t8140.rs, and the G17 notes ing17/mod.rsand theDRM_ASAHI_FEATURE_SOFT_FAULTSdocumentation.translate_iova,translate_pagesandtranslate_eachmove unchanged frommmu/context.rsintommu.rs.Evidence
Build.
drivers/gpu/drm/asahi/compiles with no new warnings.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.
The 8 lists:
At this change (969bbd2, no switch):
Regression on the same boot:
speakersafetyd, which also fails on earlier kernels here and is unrelated.asahi.mem_limit_pct=25for an unrelated test. This change reads no parameter, and the A/B above ran on the default command line.Tools.