Repository navigation
drm/asahi: g16: share the live VMs between processes and charge VM arenas to their client - #2895
Conversation
…iles Every G16 user VM holds one of the device's 63 TTBAT slots for its lifetime. The live-VM limit was counted per open file only, so it did not bound how many of the slots one process holds, and VM creation by other clients could fail with ENOSPC until that process exits. Count the live VMs against the process that created them as well, by the rule the queues already use (queue_share): a process may always hold half of the VMs, and more only while a reserve stays free for the others, or while it is the only process holding any. The count follows the VM's live token, so a VM whose handle is closed but whose binding is still deferred keeps counting. The eight-per-file limit stays. queue_share gains Shares, the same per-process count kept under its owner's lock, so the registry can apply the rule to its own resource. Add a host test that runs the production reservation and release against mocks: VMs stay available to a new process and the compositor beside a process holding many, a VM given back can be created again, and a process alone may still use every VM. The previous reservation and a share that is never given back are mutants. Signed-off-by: Ryan Murray <[email protected]>
A G16 VM's first render or compute submission builds its private arena (the two PB heaps, TPC, tilemap, pools and slot storage: about 0.7 GiB for a rendering VM) from kernel objects. They were counted only in the device's kernel total, never against the client, so neither the per-client limit nor fdinfo saw them. Hand the client's memory accounting to the backend when the VM is created (new_vm_for_file() gets the file's memacct client) and set it on the VM before the registry and the arenas see it. Private objects of a client VM are then admitted against that client's limit (ENOMEM past it, failing the submission that needed the arena) and held as its user memory instead of kernel memory, so they are counted once. The session's own objects and VMs without a client are unchanged. Signed-off-by: Ryan Murray <[email protected]>
|
Review at 4915f4b. Read through at 4915f4b. Isolation is unchanged. Each user VM still binds its own TTBAT slot for its whole life (
|
|
Review at 4915f4b (non-author). Changes requested on the first commit. The second reads right but has no evidence yet. 29e6583 (share VMs per process)
4915f4b (charge arenas)
Slot release on every path (including release from another process), key reuse (the entry holds an mm reference), the lock order ( Assisted-by: LLM (Claude:Opus 5.5) |
There was a problem hiding this comment.
Formal §1–§6 pre-PR checklist review at live head 4915f4b23ac42feaa7065fb6dc1493c7e2cf0117.
Live CI Status
host-tests: FAILED (462/463 passed; run45084522436). While the newg16-vm-share-tests(control+--mutations) passed, the existingasahi-m4selftesttools/testing/selftests/drivers/gpu/asahi-m4/test-vm-registry.pyfailed to compile with 4rustcerrors (E0061,E0063,E0433,E0609, including missingprocessesfield inRegistryinitializer) becauseg16/vm.rschangedRegistry,Reservation, andrelease()without updatingtest-vm-registry.py.
Blockers
- CI failure (
tools/testing/selftests/drivers/gpu/asahi-m4/test-vm-registry.py): Update the existingasahi-m4registry selftest harness to match the updatedRegistry(processes: Mutex<Shares>),Reservation, andrelease(file_id, process)signatures sohost-testsis green. - Lone-holder DoS gap for non-reclaimable TTBAT slots (
drivers/gpu/drm/asahi/queue_share.rs:55,g16/vm.rs:240):queue_share::may_takeallowsheld == total, so a single GPU client starting before the compositor (e.g., a headless/compute daemon at boot) can claim all 63 exclusive TTBAT slots (MAX_VMS). Unlike queues, G16 VMs pin their TTBAT slot until closed (and deferred/failed VMs retain it longer), locking out the compositor and any subsequent process withENOSPC. Either preservereserve(max)even for a lone holder for non-reclaimable VM slots, or justify why the escape is safe (while still ensuringrobust_isolationwithlimit == 1works). Also clarify in the commit message that keying bymmmeansfork()ed children each get a freshmmand 3 children can still exhaust all 63 slots. GFP_NOWAITallocation errors masked asENOSPC(drivers/gpu/drm/asahi/g16/vm.rs:206,236,240-250):Shares::new()is not preallocated (unlikefilesat L200), yettake_current(limit, GFP_NOWAIT)allocates inside a sleepableMutex, and L245-249 collapses everyErr(_)(includingENOMEM) intoENOSPC. PreallocateShareswithMAX_VMScapacity or allocate withGFP_KERNEL, and map onlyEBUSYtoENOSPCwhile propagatingENOMEM.- Early
Chargepush before fallible steps (drivers/gpu/drm/asahi/g16/object.rs:426-445):charge.set_held(true)andself.charges.push(charge, GFP_KERNEL)?happen beforeregistration_guard(),prepare_new_object(),vmap(), the 3map_in_range/map_atcalls, andArc::new(). If any of those fail on anObjectscontainer that is not immediately dropped,backingis freed whilechargeremains held as phantom resident/committed bytes. Sinceself.charges.reserve(1, GFP_KERNEL)?already ran at L428, defercharge.set_held(true)andself.charges.push(...)until right beforeself.retained.push(...)at L537. - Missing arena-charge test coverage:
tools/asahi/g16-vm-share-tests.pycovers onlyRegistry::reserve/release+queue_share; there is no host or KUnit test verifyingalloc_private_inadmit/refuse/release and rollback accounting. - §5 Evidence (zero hardware runs): No hardware rows have been run yet. Before merge, provide J713 (M4) and J773g (M4 Mac mini) default-cmdline rows covering: (a) multi-client VM exhaustion beside compositor + third client, (b) two-client VA isolation / fault attribution, (c) before/after
fdinfo(drm-total-system) and sysfsgpu_memoryaround first render (plus 8 GiB client-limit sanity check), (d) multi-context dEQP + standard regression run (0 SELinux denials, 0 failed units, 0 new kernel errors).
Checked & Clean + djdev/g16-* Stack Overlap Notes
- Locking & refcounts (
g16/vm.rs:231-270): Lock ordering (files→processes) is consistent acrossreserve()andrelease(), andrelease()dropsOption<Process>(and itsOption<ARef<Mm>>) outside both locks.Objectsfield drop order (retained,mappingsbeforecharges) releases backing before uncharging. - §1/§2/§3/§4/§6: Pass (no model gating, default cmdline, no hardcoded safety limits; both commits carry human
Signed-off-byonly with zero AI trailers andAssisted-byin PR body; clean naming). Minor nit:file.rs:713calls.with_memory_client(...)after G16 already set it ing16::vm::new_vm(needed for non-G16 backends; a short comment avoids confusion). - Overlap with
djdev/g16-*stack (#2787,#2826,#2852):- File overlap:
drivers/gpu/drm/asahi/file.rsoverlaps with#2826(Wave 6:SyncItem/Objectcmdbuf reuse &SUBMITpath; disjoint from#2895L712vm_create).drivers/gpu/drm/asahi/g16/mod.rsoverlaps with#2787(Wave 2–5) and#2826(Wave 6) inShared/Driver/FAST_POLL_WORK(disjoint from#2895L619–629new_vm/new_vm_for_file). Zero file overlap with#2852(Wave 7). No textual merge conflicts expected. - Symbol/semantic interaction with
#2826:#2826's demand-grown extension tiers (RenderExtArena,PoolExtArena,ComputeArenaext) allocate throughfactory.objects(vm)→Objects::alloc_private_in(), so they automatically inherit client charging viaLEDGER.admit. Best-effort.ok()growth preserves base slots at the limit, though note repeated submissions at the limit will re-hitadmitand incrementLEDGER.refused.
- File overlap:
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict: FINISH, then merge at 4915f4b23ac4
Blockers:
- CI is red:
tools/testing/selftests/drivers/gpu/asahi-m4/test-vm-registry.pystill uses the oldRegistrysignatures. Update it forprocesses: Mutex<Shares>,Reservationandrelease(file_id, process). drivers/gpu/drm/asahi/queue_share.rs:55withg16/vm.rs:240:may_takeallowsheld == total, and G16 VMs keep their TTBAT slot until closed. So one client that starts before the compositor can take all 63 slots, and later clients, the compositor included, get none. Fix: hold back a share for other processes, as the queue share does.drivers/gpu/drm/asahi/g16/object.rs:426-445: the charge is marked held and pushed before the fallible steps (registration_guard(),prepare_new_object(),vmap(), the map calls). If one fails on a container that lives on, the backing is freed while the charge stays held. Fix: push the charge after the last fallible step.- Missing rows: one M4 (J713 or the J773g) at the head with several clients beside the compositor and fdinfo memory checked around the first render, and, since
file.rsandqueue_share.rsare shared, one run on another generation showing no change.
Checked: no Apple material, no gates. Lock order (files → processes) is consistent, and release() drops the process outside the locks. Nit: GFP_NOWAIT failures are reported as ENOSPC (g16/vm.rs:245-249).
Superseded by the review at 4915f4b
…e they live Review follow-up. The live-VM share took the queues' rule, which lets a process alone take every slot. Queues come and go, but a G16 VM keeps its TTBAT slot until it is closed, so one client started before the compositor could hold all 63 and leave none for anything started later. VMs now take may_take_held(): a process alone still leaves the reserve (7 of 63) for the others. Queues keep their rule. The arena charge was marked held and pushed before the fallible steps (registration_guard(), prepare_new_object(), vmap(), the mappings). If one failed on a container that lives on, the backing was freed and the charge stayed held. Hold and push it once the object is retained. A refused share is ENOSPC, as before; an allocation failure under the registry lock now stays ENOMEM instead of reading as ENOSPC. Update the host tests: test-vm-registry.py for the new Registry, Reservation and release() signatures (CI was red), with the VM share by queue_share.rs's own rule and a case for the reserve a lone process leaves; g16-vm-share-tests.py for the same, with a mutant for the old rule. Both pass; all three mutants fail. Signed-off-by: Ryan Murray <[email protected]>
# Conflicts: # drivers/gpu/drm/asahi/g16/object.rs # tools/asahi/run-host-tests.py # tools/testing/selftests/drivers/gpu/asahi-m4/test-vm-registry.py
|
Fixed at ed937d4 (fix commit 1533415 plus a merge of
|
|
Row at This is the 'one run on another generation showing no change' for the shared file.rs/queue_share.rs. The M4 multi-client fdinfo row is still owed. DetailBoth rows ran on the default cmdline with the kernel booted once as a non-default entry, then back to fleet89, which was verified afterwards (saved entry, empty next_entry, kernel removed, 0 failed, Enforcing). Per Mac: SELinux Enforcing, 0 failed units, 0 AVC, 0 err-level kernel lines, 0 oops; Wi-Fi ping OK; s2idle (rtc1, 15 s) rc=0 with ping and a 64 MiB direct NVMe read after the wake; Apple SoC watchdog armed with time left counting (44 s and 58 s of systemd's 60 s); dEQP-VK |
The main merge brought test-resources.py fixtures that build the production LiveToken from vm.rs. With this branch the token carries the creating process and Registry::release() takes it, so the fixtures no longer compiled (E0063/E0061, asahi-m4 host test red). Give the mock tokens process 0 and the mock Registry::release() the process argument. Signed-off-by: Ryan Murray <[email protected]>
|
CI fix at 2606f52: the asahi-m4 host test was red because main's Tested: |
|
M4 Pro (T6040, J616s) multi-client row at this head (2606f52). The kernel was the combined fixa5 test kernel, linux main fca33ed plus the heads of #2887 #2959 #3384 #2919 #2393 #2895. Eight of the ten files this PR changes are byte-identical to this head. The other two:
In both, the combined file is this head plus only main's or the other PRs' lines, with none of this PR's lines missing. One-shot BLS entry, default command line. Scope: the J616s runs the G17 backend, so the G16 arena charge itself is not exercised here. This row covers the shared paths this PR changes on every backend: the per-process Concurrent clients for 70 s beside gnome-shell. Each client's DRM fdinfo and the G17 capacity sharing lines were read every 5 s.
For 0-60 s at least three clients (glmark2, gpubench, dEQP) ran beside gnome-shell. fdinfo looked sane:
Counters before vs after were identical:
Same boot:
The J616s was restored to fleet89 and verified: saved entry unchanged, next_entry empty, test kernel removed, Enforcing, 0 failed units. Evidence (lab store): |
|
G16 row at Clients. The compositor plus 6 concurrent GPU clients for about 70 s:
Up to 19 DRM fds in one sample, 34 distinct DRM client ids over the run.
Arena charge around a client's first render. The probe creates its device, VM, buffers and pipelines, then holds before submitting. fdinfo is read there and again right after its first render:
The device ledger moves the same way. At peak load, fleet85 counts the arenas as kernel memory ( Back to baseline: not exactly, because of main's
Unrelated to this PR, under GPU load on fixa6: about 280 Not covered here: the J773g row, VM exhaustion, two-client VA isolation/fault attribution and the 8 GiB per-client limit. The clients ran as the greeter user on the fixa6 boot (no auto-login after the reboot) and as the desktop user on the control. Evidence (lab store): |
There was a problem hiding this comment.
Verdict: MERGE at 2606f52b
Blockers: none (20/20 CI green and exact-head G16/T6040 multi-client hardware rows PASS; ready to merge).
Checked:
- Prior CI & ownership blockers resolved cleanly (
2606f52bupdatestools/testing/selftests/drivers/gpu/asahi-m4/test-vm-registry.pyforLiveTokenprocess ownership;15334152bounds per-process VM slots and charges private arenas once across shared VMs). - Hardware rows & CI: 20/20 CI checks green (
SUCCESS),MERGEABLEonmain, and exact-head multi-client rows PASS on both J616s (M4 Pro / T6040,fixa5) and J713 (M4 Air / G16G,fixa6). - Checked for Apple material, tool attribution, private serials, and gating: clean; human
Signed-off-bypresent.
Evidence
- Head:
2606f52b8c95(base: main,mergeable: MERGEABLE,+476/-43across 10 files).
|
code-owner ping <@422957901716652033> / @DjDeveloperr: merge train at |
|
Merging under the 6-point rule (Ryan 09:29, permanent), at |
Problem
On G16 (M4), every user VM holds one of the device's 63 TTBAT slots for its lifetime, and the live-VM limit is counted per open file only. A process can open the render node any number of times, so that limit doesn't bound how many slots one process holds. Separately, a VM's private arena (about 0.7 GiB for a rendering VM) is made of kernel objects that count only towards the device's kernel total. The client's memory limit and fdinfo never see them.
Change
queue_sharealready applies to queues: a process may always hold half of the VMs, and more only while a reserve stays free for the others or while it is the only process holding any. The 8-per-file limit stays.queue_sharegainsShares, the same per-process count under the owner's lock.new_vm_for_file()now receives the file's memacct client, and G16 sets it on the VM before the registry and the arenas see it. A client VM's private objects are admitted against that client's limit (ENOMEM past it) and held as its user memory instead of kernel memory, so they are counted once.No new parameters, no chip or board gates. Other backends ignore the new
new_vm_for_file()argument, as before.Testing
tools/asahi/g16-vm-share-tests.py, registered inrun-host-tests.py. It compiles the productionRegistry::reserve/releaseand thequeue_sharerule against mocks. It checks that VMs stay available to a new process and to the compositor while one process holds many, that a VM given back can be created again, and that a process alone can still use every VM.--mutations: the previous reservation and a share that is never given back both fail (2/2).aurora.obuilds with the fleet release config (all backends), with no new warnings.Still to run
drm-total-systemaround a client's first render: it should grow by the arena size with the series and not without it. Also checkgpu_memory.Notes for review
mm, as inqueue_share; a reference to themmkeeps the key from being reused while VMs count against it. VMs created without a process context (new_vm, file id 0) count under key 0, as they counted under file 0 before.processeslock insidefiles;release()drops the returned process (and its mm reference) after both locks.Charge::user(commit, None)+set_held(true), as the G17 shared pools do (lower_user_charged), withnew_kernel_object_wc_user_chargedso the device total does not count them twice. The charge lives in the arena'sObjectsand is released with its backing.