Repository navigation
drm/asahi: g16: isolate SCS compute to same-VM SCS co-residency - #3045
Conversation
Implement cleanroom G16G (M4) hardware ray tracing support on top of the
M4 production tree, advertising DRM_ASAHI_FEATURE_RENDER_RAY_QUERY and
DRM_ASAHI_FEATURE_BOUNDED_AS_BUILD:
- Add pure RT validation, Gen1 SCS sizing, and intersection table helpers
in g16/rt.rs (with TAIL_ENABLED = 0x2c), plus UAPI flags/reservations in
asahi_drm.h and params.rs.
- Extend command.rs stream parsing and SpanBatch VM admission for render
ray-query stages, compute ray/SCS requests, and AS-build flags without
reintroducing per-span VM locks.
- Add demand-sized SCS UMA pools and freelist placement (0x80000 records
in dedicated SCS windows) across slots.rs, pools.rs, resources.rs,
hw.rs, and fw/buffer.rs, isolating SCS vs base arenas on reuse while
retaining firmware PB/UMA leases across closed-VM reclaim.
- Wire RT register encoding and J773g SCS bracketing (0x017e1 = 1 first,
0x017d9 = 1 last) in encode/{compute,render}.rs and engine.rs, pinning
RT/SCS compute jobs to pipe 0, guarding horizon batching, and applying
the 10 s long-job deadline allowance in recovery/logic.rs. Non-RT
submits remain byte-identical.
- Add test-ray-tracing.py and update asahi-m4 host selftests.
Signed-off-by: Diljit Singh <[email protected]>
…d slots After a firmware compute recovery permanently quarantines compute unit 0, brand-new VMs using the 2-unit SCS compute layout previously pinned themselves to hardware slots 0..2. Their first compute submission claimed and retired on unit 1 (the sole healthy slot in 0..2), leaving unit 1 as pipe 0's undisplaced latest retired lease so the second compute submission saw compute_exhausted_within(2) == true and immediately failed with ECANCELED, poisoning every subsequent fresh process. Track the live quarantined compute mask in Shared::quarantined_compute_mask and route ComputeUnitSet::new_scs onto two healthy hardware slots, preferring the pipe-0-reserved 0..PIPE1_COMPUTE_START range so pipe 1 cannot pin an undisplaced lease on SCS slots, then falling back across the remaining units. Apply the matching quarantined-slot skip when picking base warm PB slots for new render arenas. Signed-off-by: Diljit Singh <[email protected]>
Commit 7a8472835197 ("drm/asahi: g16: route SCS compute and base PB
slots around quarantined slots") replaced the [home, home + 1] warm PB
pair of a new render arena with a quarantine-aware picker.
Verify that with nothing quarantined the picker returns the contiguous
[home, home + 1] pair for every start, and that sixteen render-only VMs
use every warm slot once as home and once as alternate regardless of
earlier round-robin cursor motion.
Signed-off-by: Diljit Singh <[email protected]>
The 26B123 G16G firmware learns which slots run shader-context scratch (SCS) work from a u32 in each start command: StartCompute +0x40, StartTA +0x60 and StartFS +0x78. It ORs the slot into a per-engine SCS mask, appends 0x017d9 = 1 to that kick's register list for masked slots, and when its scheduler goes idle it tears the SCS state down (0x017e0 = 0, the compute and TA windows 0x107a0/0x10798 = 0xff0000, 0x100e8/0x100f0/0x10408/0x10410 = 0x100) unless a masked slot is still busy. The G16 encoders always left the three words zero, so the teardown ran at the first idle after every ray-query kick, while the dispatch was still executing. Compute and ray-generation ray queries then lost traversal mid-dispatch and returned misses without a fault, and fragment and tiling ray queries stalled their stage until the firmware recovered it (events 0x71 and 0x70). macOS 27.2 on Apple M4 sets StartCompute +0x40 on every compute item whose register list opens with 0x017e1 and leaves it clear on all others. This is the M4 counterpart of the G17P kick header's SCS bit (bit 61), which g17 sets for compute and per render stage. Set each word exactly when the stage's register list enables SCS. Non-ray-tracing work is byte-identical. The host check now also requires the flag on ray-query compute, TA and FS sequences and nothing else to change there. Signed-off-by: Diljit Singh <[email protected]>
A render pass slot index is device-global and claimed by one flight at a time, so render microsequences and barrier records need not be allocated per VM. Mapping them with firmware-cached leaf 0x443 inside a per-VM render arena is unsafe on client teardown because KernelMapping::drop() fail-stops an ASC-cached M4 mapping that has no qualified teardown. Allocate render microsequences and barrier records once per pass slot index, on first use, from a device-lifetime allocator that is never dropped (resources::RenderCmds, reached through Factory), and let every VM's PassSlot of that index share them. Each microsequence keeps its own page and the barrier records share one page, matching compute unit barriers: 48 KiB per index (at most 2.25 MiB per boot) instead of 128 KiB per pass slot of every VM. Class::FwCoherent (firmware leaf 0x443 behind a cacheable host mapping, matching macOS 26B123 per-queue command objects) is accepted only by this device-lifetime allocator and never with a client or lower alias. Per-VM arenas and the session allocator reject it, so closing a client can never drop a firmware-cached mapping. Extend the host resource tests to verify that two VMs' pass slot k share one set, no VM arena owns a firmware-cached object, dropping a VM retains the set, and other allocators reject Class::FwCoherent. Pass slot backing drops from 608 to 480 KiB of metadata per VM. Signed-off-by: Diljit Singh <[email protected]>
Move the TA and FS work images, the larger part of what the firmware reads per render, into the per-index device-lifetime RenderCmds records. macOS 26B123 maps its per-queue command objects, work items included, with the firmware-cached leaf 0x443 and maps the same pages into GPU context 0 with the uncached leaf 0xc8b. The work images keep that uncached kernel GPU task lower alias. Because the host writes to the work images through a cacheable mapping while the GPU reads their register lists through the uncached alias, FwObject cleans each store to such an object to the point of coherency (dc cvac, then dsb sy). Only a firmware-cached object with a lower alias performs this clean; the microsequences and barriers, which only the firmware reads, are unchanged. Each pass slot index now holds five device-lifetime pages (80 KiB, at most 3.75 MiB per boot) and every VM pass slot sheds two more pages (448 KiB of metadata). Compute command objects are unchanged because the host reads firmware-written descriptor counters from the compute work image. Signed-off-by: Diljit Singh <[email protected]>
Ray-query compute on G16G runs with shader-context scratch (SCS). Each
compute work item sets the compute engine's SCS state in its register
list: a ray-query item enables the SCS window, and every other item
writes it disabled.
The engine pins ray-query compute to pipe 0 and holds it while compute
runs on pipe 1. It still lets another VM's compute, or the same VM's
non-SCS compute, queue behind a ray-query item on pipe 0, and lets a
ray-query item queue behind such compute.
Such an overlapped ray-query dispatch is reported complete before its
results reach memory. With a ray-query process and a long-ALU process
sharing the GPU, 33,091 to 35,419 of 131,072 rays still held the
buffer's fill pattern when the fence signalled, with every Mesa build
tried. Once the ray-query process exited, the rest of its stores were
written back from the shader cores' L1 cache into its closed VM:
fault bank 4: status 0x283a03a1 va 0x5bf27c5180
(write unmapped level 3 unit 0x1 ctx 29)
attribution: busy=1 ctx=29 flight_matches=0 live_vm=None flights=9
When those writes filled all eight fault banks, the firmware did not
finish the recovery and the GPU stopped.
Let SCS compute (ray queries, and every compute command of a job with
SCS scratch) share the compute engine only with SCS compute of its own
VM. Other compute neither queues behind it nor runs while it is
published; each waits for the other to retire. One ray-query queue
still pipelines its own commands, and renders are not affected.
Signed-off-by: Diljit Singh <[email protected]>
ee2bc3a to
e6d8e0a
Compare
5134fa7 to
d1e55b9
Compare
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
Verdict at Blockers:
Checked: the one commit against its base: |
What: Fixes data loss and the follow-on faults when G16 (M4) ray-query (SCS) compute runs beside other compute: SCS compute now shares the compute engine only with SCS compute of its own VM. Stacked on #3044.
Tested: M4 Mac mini (J773g, G16G B0, 26B123) with the full stacked series on an earlier build, not this head: vk-rt gpubench 98/98, gpubench 440/440,
dEQP-VK.ray_query.*1,382/1,382, 0 faults. Host test-publication 81/81.Risk: two-way · M4 (J773g, J713)
Not yet: a row at the current head; CI, which runs once the base lands and this PR targets
main.Details (original description)
Summary
Fixes data corruption and subsequent unmapped write faults during concurrent ray-query (
SCS) compute and non-SCS / cross-VM compute on Apple M4 (G16G):write unmapped level 3 unit 0x1), exhausting all eight fault banks and wedging firmware recovery.Verification
tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py— 81 passed, 0 failed (includingscs_compute_shares_the_compute_engine_only_with_scs_compute_of_its_vm).scripts/checkpatch.pl --strict: 0 errors, 0 warnings, 0 checks.G16G B0,26B123) silicon:5/5 compute.longheadless): 15,467,486 ray checks, 0 wrong rays, 0 faults, 0 recoveries.vk-rtgpubench: 98/98 PASS (1.127×vs Metal 4;asbuild 1.638×,rays 1.226×,scene 0.965×).gpubenchsuite: 440/440 PASS across 4.00M GPU jobs (0faults,0recoveries,0bad CRCs).dEQP-VK.ray_query.*): 1,382/1,382 PASS (26/26 stress,516/516 builtin,180/180 position_fetch,480AS ops).