Repository navigation
drm/asahi: g16: share the live VMs between processes and charge VM arenas to their client - #2895
RyanTheTide wants to merge 2 commits into
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 <ryan@aurorasilicon.org>
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 <ryan@aurorasilicon.org>
|
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) |
DjDeveloperr
left a comment
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:
Assisted-by: LLM (Gemini 4 Neon)
|
Merge readiness at
Areas: Updated by pr-readiness on every push, edit and review, and every 30 minutes. Rules: merge policy · labels. |
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.