Repository navigation
drm/asahi: g17: reuse a given-back compute pool for the next VM - #4275
DjDeveloperr wants to merge 2 commits into
Conversation
When every compute QID is taken, a client that needs a channel takes another VM's idle one. The pool is released to the firmware, its storage is freed, and the new owner allocates, zeroes and maps fresh backing before it can bind. A compute pool is tens of MiB (the M5 directory alone is 8 MiB on the J714s and more on larger boards), so with more clients than channels each handover costs milliseconds, and the J714s cross_instance run makes thousands of them per round. Keep the storage of a pool given back for another VM instead. Once the firmware consumed the release, the queue holds it with the last owner's alias. The re-arm takes it, drops that alias, moves the charge to its own client and clears the storage off the device mutex, as render pools already reuse released storage (cache_reclaimed). It allocates fresh backing only when nothing was kept, the kept storage is too small or the new client cannot take its charge. The event worker frees kept storage that no re-arm took once no compute admission waits or the lower window is under pressure. Pools freed for other reasons (warm cap, idle expiry, a killed or moved queue) are freed as before. The QID budget, render capacity and the release protocol are unchanged. Clearing an M5 backing now skips the directory and block list, which populate_m5() rewrites in full; G17P backing is cleared and its tables written again (repopulate()), as for fresh backing. Signed-off-by: DjDeveloperr <hey@djdev.me>
|
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.
Independent review at head 17d3302. Verdict: looks right. I found no bug that should block this. It can merge once the J714s and J700 rows pass. Three small notes are at the end; none of them needs a change.
Can one VM see another VM's data? No.
- The clear covers every byte. On M5,
reset_for_clientzeroes everything after the directory and block list.populate_m5then rewrites both tables, andencode_directoryandencode_freelistzero their whole region before they write entries (fw/m5/pool.rs:201,:218). The backing size is always a multiple of 16 KiB (the tables are rounded to 0x4000 and blocks are 2-16 MiB), so the client alias maps nothing pastbytes_mut(). On G17P,fill(0)plusrepopulate()produces the same bytes asPoolTables::initon zeroed memory. Reused storage comes out byte-for-byte equal to fresh backing. - The old owner loses its view before anything is cleared. Every client alias of a compute pool lives in
binding.pool_alias(it is mapped only atqueue/compute.rs:832,:2116,:2147and:2601).observe_vacancymoves that alias into the spare, andVacated::into_pagesdrops it before it hands back the pages.KernelMapping::dropunmaps and then flushes the TLB, both for the VM's slot and for every context that names the root (mmu.rs), before it returns. The new VM's alias is made only later, inbind_owner_channel, afterrearm.take_pagesresetsclient_vm, soserves()holds the pool to one VM at a time, as before. - The firmware is done with the storage first. A spare exists only after
control_consumedsaw the FreeListRelease cursor go by. That is the same proof main uses before it frees the pages, and the one growth and render repopulate use before they reuse storage in place.
Lifetime and concurrency: take_compute_spare and the worker's drop_spare both run under the device mutex and both use Option::take, so the spare can't be freed twice. The clear runs off-lock, on storage only the re-arm owns. ComputeDemand lasts across a waiter's retries, and when the last one drops it queues an event pass, which frees the spares that are left. A parked alias keeps the old VM's page tables alive until it is dropped, as a detached exited owner's binding already does today. Unload and device teardown drop the spare along with its queue, alias first. The charge moves before the clear. On a refusal or a failed populate the pages are dropped, and the charge comes off whichever client held it. A spare that is freed without being taken comes off the old client.
Other paths: only require_fresh_backing sets keep_backing, and it has two callers: give_back_foreign and the shared-idle path. Pools freed for the warm cap or idle expiry, killed queues (recycle_settled clears the flag) and moved queues are freed as before. The render M5 spare path also goes through reset_for_client and writes the same bytes as before. There is no new parameter, constant or board gate.
What I ran (pc, host-tests CI container ubuntu2404, rustc 1.96.0, no network):
run-host-tests.py --only g17-at 17d3302: 416/416, with all 11 mutations of the new test killed. No harness outsideg17-reads the three changed files.- The new test against main's three driver files fails, but only structurally (
take_spareis missing). - Two mutations of my own. Dropping the zero-fill in
encode_directoryor inencode_freelistfails the test ("M5: reused storage is exactly fresh backing"), so the "zero only after the tables" shortcut is guarded. Putting main's full clear back still passes, with the same bytes. - Main has no
drivers/gpu/drm/asahiortools/asahichanges since f778d6c (current main d2a4949). The queued kits' head driver tree is 154c9cc3, which is this head's tree, and their base tree is 3680a536, which is main's. Both kit arms are still current.
Notes (no change needed):
rearm_vacant(runtime.rs:1890) takes the spare before its later checks. If the attempt then retries (Some(false)) or the descriptor ring can't be built, the cleared storage is freed and the retry builds fresh backing. This is safe; that one handover just doesn't get the reuse.- If
take_spare(queue/compute.rs:2314) findscan_rearm()false for a moment (source readers) but the later ready check passes, the queue gets fresh backing and the spare stays parked on a populated queue. It is freed when compute demand drops to zero, or a later re-arm of that queue takes it and clears it. It holds at most one spare per queue, and its alias is only the old owner's view of its own data. - The
ComputePoolcomment (freelist.rs:1065-1068) still says another VM gets the queue only after "fresh, zeroed backing" is installed. Kept storage cleared to the same bytes now counts too. Worth a word the next time the file is touched.
|
J700 (Neo, G17P) row at head Boots: baseA
The same clients passed and the same refusals (none) at every N. Evidence (on Mini): Main since this branch: no forward-merge needed. Main is now 52 commits ahead of the merge base Still owed before merge:
|
Signed-off-by: DjDeveloperr <hey@djdev.me>
DjDeveloperr
left a comment
There was a problem hiding this comment.
The ARM64 W=1 build linked on current main. Its newer kill-retirement guard exposed a missing method in the extracted compute-reuse fixture, so I added the fixture stub in d33dbcb. All 30 reuse, capacity, growth and M5 sibling re-arm host runs now pass. The old and new merge trees have identical driver files. The J700 PASS and the sealed J714s ABBA kit therefore still cover the production code.
RyanTheTide
left a comment
There was a problem hiding this comment.
Verdict: REQUEST_CHANGES at d33dbcbfe4b6936a7dc757865664f72303d6839d
Failure: Vacated::into_pages() treats dropping the old KernelMapping as proof of a successful unmap. The production destructor can return with the mapping retained after an unmap error and provides no status to its caller. This path still hands the same backing to the next VM. The fixture verifies drop order, which does not establish that the old mapping was retired. Require confirmed unmap and translation retirement before reuse, and quarantine the backing if retirement fails.
Checked: The release-completion gate precedes the handoff and both layouts clear the storage before normal reuse.
What: When every compute QID is taken, a client that needs a compute channel takes another VM's idle one. Until now each of these handovers freed the old pool's storage and then allocated, zeroed and mapped fresh backing for the new VM before it could bind. A compute pool is tens of MiB (the M5 directory alone is 8 MiB on the J714s, more on bigger boards), and with more clients than channels this happens thousands of times per round: the J714s
cross_instancerun made 4,100-6,200 handovers per clean round, and on the J700 at 40 clients the per-client submit rate dropped about 10x against clients with their own channel.This change keeps the storage of a pool that is given back for another VM. Once the firmware has consumed the pool's release, the queue holds the storage together with the last owner's client alias. The re-arm takes it, drops that alias, moves the charge to its own client and clears the storage off the device mutex, the same way render pools already reuse released storage (
cache_reclaimed). It still builds fresh backing when nothing was kept, the kept storage is too small, or the new client can't take the charge. The event worker frees kept storage that no re-arm took once no compute admission is waiting or the lower window is under pressure. Pools freed for other reasons (warm cap, idle expiry, a killed or moved queue) are freed as before.Clearing reused M5 storage now skips the directory and block list, which
populate_m5()rewrites in full anyway. G17P storage is cleared and its tables are written again withrepopulate().This replaces linux#3985, which gave compute more QIDs. Compute QIDs only go back to render at driver teardown, so that cost render queues later in a boot (J700: 39/40 clients at 40; J775c
queue.exhaust: 40 queues instead of 48). Here the QID budget, render capacity, the release protocol and the isolation between VMs stay the same.Tested:
tools/asahi/g17-compute-handover-reuse-tests.pybuilds the production code against host stubs. It checks that only a give-back for another VM keeps storage, that the old alias is destroyed before the storage is reused (even while the event worker still holds the rest), that a refused charge leaves the storage untouched, and that reused storage is byte-for-byte the same as fresh backing for both the M5 and G17P layouts. It also checks that other vacates free storage as before and that a second give-back never replaces a kept spare. All 11 mutations are killed. The new queue fields are added to the stubs ofg17-growth-tests.py,g17-m5-sibling-rearm-tests.pyandg17-capacity-fault-tests.py.run-host-tests.py --only g17in the CI container (ubuntu2404image, host-tests.yml toolchains): 416/416 (main: 404/404). The asahi-m4 command-stream selftest also passes.drivers/gpu/drm/asahi/on the 7.3.0-main571a6c45 tree: 43 warning blocks with and without this change, 0 new.Risk: two-way · the G17 compute give-back path on every G17 Mac (M5 J714s and J775c, Neo J700, and M4 Pro/Max T6040/T6041). If the clear missed a byte, one VM could read another VM's leftover scratch. The host test compares every byte against fresh backing, and no alias of the old VM survives the re-arm. Kept storage stays charged to the old client until a re-arm takes it, which happens only while a compute admission is waiting.
Not yet:
cross_instancerounds with bind counts,queue.exhaust,dEQP-VK.api.smoke, one deep sleep. SLC on, watchdog armed.queue.exhaust, which should match main.