Repository navigation
drm/asahi: g17: keep pooled objects mapped until their control fence - #2959
Conversation
The firmware can follow a released object's address until it has consumed the control record that ends the owner's use of it. The object pool honours that fence for cached objects, with two exceptions once a family is full: - With no room for a fresh cached object, allocate() reused the oldest returned object even when its fence was not met yet (counted in the family's overruns, A18 Pro work states excepted). - A fresh object made while its family was full got no cache lease, and its drop unmapped and freed it at once, with no fence at all. Never reuse a returned object before its fence, on any family: with no met fence and no room, allocate() makes a fresh uncached object, as it already did for A18 Pro work states. When an uncached object is dropped, keep it mapped on a per-pool deferred list with control_fence(), the strict fence a cached object would wait for, and unmap it once the firmware has met it. allocate() and every deferred drop reap the list; firmware stop releases what is left, as it does for kept objects. The list entry is reserved when the object is made, so the drop does not allocate; an allocation that cannot reserve it fails. Teardown never runs under the pool mutex. The list holds only objects whose fence the firmware has not met. It is shown in the capacity file as uncached_objects_fenced with its bytes, and a one-time warning is printed past 256 entries. If the firmware stops consuming control records, the objects stay mapped until firmware stop instead of being freed early. The overruns counters stay in the capacity file and now read 0. The object-fence host test now checks, on every family with and without after_release, that a full family hands out an uncached object instead of reusing a waiting one, that a dropped uncached object stays mapped until control_fence() is met and is unmapped then or at firmware stop, and that an uncached object kept until stop leaves the list alone. Its random model records the control-ring witness at every unmap. The differential against the pool before linux#1978 now limits BASE's reuse to met fences. New mutations: overrun-full-family, unmap-uncached, reap-early, stop-keeps-deferred. Signed-off-by: Ryan Murray <[email protected]>
There was a problem hiding this comment.
Formal §1–§6 pre-PR checklist review against 2dedb1a1e82492e1876a8cbd176a7f246f2b9a65.
Summary
The core lifetime mechanics in drivers/gpu/drm/asahi/g17/object.rs are clean and well-structured: pre-reserving deferred capacity at allocation time avoids allocating in Drop, cancel_deferred() keeps deferred_reserved balanced on retain_until_stop(), mapping teardown never runs under the pool mutex, stop_after_firmware() drains deferred and handles late drops safely, and G13/G14/G15/G16/G18 are untouched.
However, there are two concrete blockers that prevent approval / MERGETRAIN-LINUX4:
Blockers
-
§1 / §3 — Unbounded
inner.deferredgrowth & kernel memory / upper-VA exhaustion on unpublished queue churn (M4 Pro/Max, M5, and saturated A18 Pro)- Previously, when a family filled its 64 slots with waiting entries,
Pool::allocate()overran the oldest slot (!room && !marked), bounding kernel GEM backing and upper UAT VA toPOOL_SLOTS/POOL_BYTES. - With this change,
allocate()never reuses a waiting entry and instead allocates a fresh uncachedKernelObject(defer: Some(self.clone())). On drop,defer_object()pins it ininner.deferreduntilcontrol_fence() = CONTROL_PUBLISHED + 1. - Creating and closing a logical queue without submitting work (
Context::new()followed by close where!context.is_published()) publishes no device-control record (teardown::Pending::closeskips unpublished contexts), andobserve_control()is only called on control publication, teardown, or compute pool release. - On M4 Pro / M4 Max / M5 (
objects_after_release = false): after 64 unpublished queue create/destroy cycles, all 64Family::WorkStateslots (and on M5 all 64Family::Schedulerslots as well) sit inreturned[]waiting onCONTROL_PUBLISHED + 1. Every subsequent unpublished queue create/destroy allocates fresh uncached kernel backing + upper UAT VA (32 KiB on M4, 48 KiB on M5) and appends it toinner.deferredwithfence = CONTROL_PUBLISHED + 1. BecauseCONTROL_CONSUMEDnever advances,reap_deferred()can never free a single entry. - On A18 Pro (
objects_after_release = true): the same unbounded growth triggers whenever 64WorkStateslots are held live (inner.reserved[WorkState] == 64) and a 65th queue is created and destroyed without submitting, because uncached objects carry noReturnMarkand always takecontrol_fence(). - Because
gem::new_kernel_object*uses uncappedmemacct::Charge::kernel,defer_object()has no cap (onlypr_warn_once!atKEPT_WARN = 256), and M5 pinsFirmwareuntil reboot (SESSION_RETAINED), an unprivileged userspace loop creating/destroying idle queues can pin arbitrary kernel RAM and exhaust the upper dynamic UAT VA range (UpperVaENOSPC), breaking GPU allocations for all clients on the device. - What is needed: Either avoid deferring objects that were never exposed to firmware (e.g. only arm deferral once exposed / carry exposure tracking for uncached objects and non-
after_releaseGPUs), or enforce a bounded deferred cap / backpressure (or explicit control-ring fence advance) soinner.deferredcannot grow without bound.
- Previously, when a family filled its 64 slots with waiting entries,
-
§1 / §5 — Missing M4 Pro/Max and M5 hardware evidence (and full §5 regression row)
- The PR body explicitly leaves M4 Pro (T6040) under
## Still to run, and provides no M5 (T8142 / T6050 / T6051) test row at all. - Both M4 Pro/Max and M5 run
g17/object.rswithobjects_after_release = false(and M5 additionally poolsFamily::Schedulerand retains the firmware session until reboot), so the no-overrun + deferred-list paths take substantially more traffic there than on A18 Pro. - Per §1 ("Prove the change on every Mac you have that contains the block") and §5 (hardware run with numbers + regression run reporting 0 SELinux denials, 0 failed units, 0 new kernel errors on the default boot), hardware results on M4 Pro/Max and M5—plus the full §5 regression check—are required before approval (or keep the PR as a draft while
Still to runis pending).
- The PR body explicitly leaves M4 Pro (T6040) under
Non-blocking Notes
- Idle retention &
uncached_objects_fenced waiting=accuracy (object.rs:960-975,object.rs:1076):reap_deferred()is only called fromPool::allocate()andPool::defer_object(), not whenobserve_control()advancesCONTROL_CONSUMED(e.g. duringservice_teardown/drain_reclaims). As a result, the trailing wave of deferred objects from a burst stays mapped while the GPU is idle even after its fence is met, until the nextallocate().Pool::write_capacity()printsinner.deferred.len()asuncached_objects_fenced waiting=without filteringfence > witnessed(unlikecached_objects_fenced waiting=on line 1070), so afterwitnessedadvances it counts already-met unreaped entries aswaiting, which also slightly diverges from the commit message ("The list holds only objects whose fence the firmware has not met").
- Quadratic scan in
reap_deferred()(object.rs:961-974):- Scanning from index
0withiter().position(...)on everyswap_removeis O(N²) when unready entries sit at the front ofinner.deferred, and reacquiresself.innerper reaped object. Scanning backwards (or popping ready entries into a local batch and dropping outside the lock) avoids this.
- Scanning from index
Checklist Audit (§1–§6)
| Section | Status | Notes |
|---|---|---|
| §1 No model gating / correctness | FAIL | Uniform across G17 (removes model-gated overrun exception; G13–G16/G18 untouched), lock ordering and Drop/stop paths are sound, but unbounded inner.deferred growth on unpublished queue churn and missing M4/M5 coverage block. |
| §2 Production-ready / scope | PASS (minor) | Clean 3-file diff, no cmdline/module params or hacks; should remain Draft while Still to run is open. |
| §3 Safety / isolation | FAIL | Cross-context isolation is preserved (zeroed on fenced reuse; deferred objects never reused), but unbounded deferred kernel GEM + upper UAT VA growth is an unprivileged local DoS vector. |
| §4 Clean-room & attribution | PASS | Single commit by human author/committer (Ryan Murray <[email protected]>) with human Signed-off-by: only, zero AI trailers in commit, Assisted-by: present in PR body. |
| §5 Evidence | FAIL | Host tests & 4 new mutations pass; Neo (A18 Pro) row passes; M4 Pro/Max still pending, M5 missing, full §5 regression tuple (SELinux denials / failed units / kernel errors) not reported. |
| §6 Naming & CI | PASS | Naming clean (aurora.ko, aurora-g17). Live CI host-tests (Host tests, run 45142201867) is SUCCESS on 2dedb1a1e82492e1876a8cbd176a7f246f2b9a65. |
|
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 2dedb1a1e824
Blockers:
drivers/gpu/drm/asahi/g17/pool.rs:Pool::allocate()no longer reuses a waiting entry; it allocates a fresh uncached object and defers its drop untilcontrol_fence(). A queue created and closed without submitting publishes no control record, so after 64 such cycles on M4 Pro/Max or M5, every further create/close pins another 32–48 KiB of kernel memory and upper UAT VA ininner.deferred, with no cap. An unprivileged loop can then exhaust the upper VA range for every client. Fix: only defer objects that were exposed to firmware, or capinner.deferredand push back.
Rows before merging: pool.rs runs on M4 Pro/Max and M5, so at the new head it needs one run on each, with queues created and closed in a loop and no growth in deferred objects.
Checked: no Apple material, no gates.
Superseded by the review at 2dedb1a
Signed-off-by: Ryan Murray <[email protected]>
An uncached pool object is kept mapped after its drop until the firmware has met control_fence(). A queue created and closed without submitting publishes no control record, so that fence does not move. Once such cycles had filled a family's 64 cache slots with entries waiting for it (M4 Pro/Max and M5 keep the strict fence), every further create/close left another 32-48 KiB work state (and M5 scheduler page) and its upper UAT VA on the deferred list, with no bound: an unprivileged loop could exhaust the upper VA range for every client. Defer only an object whose address reached the firmware. A context attaches one object::Exposure to its work state and its M5 scheduler page (PooledObject::defer_once_exposed) and sets it wherever those addresses can reach the firmware: the work-storage accessors that already mark the A18 Pro work state (work_head_va, a command's node_va), scheduler_va(), the only reader of the scheduler page's address, and publication. An uncached object whose exposure is still unset is named by nothing the firmware reads and is unmapped at its drop; one without an exposure (every other pooled object) keeps waiting for the fence. The capacity file counts the immediate drops (uncached_objects_fenced ... unexposed_freed=). g17-object-fence-tests gains a create/close loop: with the work-state family full of exposed objects waiting for their fence, 4096 contexts created and closed without work each get an uncached work state that is unmapped at once, the deferred list stays empty and no reservation is left; one exposed by a queue record or a command still waits and is unmapped once the fence is met. Source rules pin scheduler_va() as the only reader of the scheduler page address, and the exposures. New mutations defer-unexposed (the previous behaviour) and unexposed-head fail it. Signed-off-by: Ryan Murray <[email protected]>
|
@DjDeveloperr, I've pushed a fix for your blocker using the design you preferred: only objects that were exposed to firmware are deferred. The branch is forward-merged onto main Blocker: unbounded
Where the flag is set (
On the 64 cache slots: on M4/M5 a cached work state still returns with the strict fence (unchanged), so those slots can still fill with waiting entries. That is bounded by The capacity file now counts the immediate drops: Tests (
Mutants (each must fail; all 14 do):
Both new mutants are registered in Merge note: main's #3186/#3065 renamed "uncached" to "unpooled" in the Your non-blocking notes (no reap on Rows owed at 77229d8: M5 (queue create-close loop, no deferred growth: Tested: g17-object-fence-tests (create_close_loop 4096 cycles, waiting=0) and 14/14 mutants killed; run-host-tests 732/732; KUnit asahi 490/494 (4 skip); fleet-config asahi build OK. |
|
M4 Pro (T6040, J616s) row at this head (77229d8). The kernel was the combined fixa5 test kernel, linux main fca33ed plus the heads of #2887 #2959 #3384 #2919 #2393 #2895. No-change smoke:
Pool churn. These are the qpair waves from the Neo row (
On T6040 this workload never fills a family. The peak was 57/64 at the logical-queue cap, so no uncached object was made. The deferred path and Exercising deferral on T6040 would need a client that holds more pool objects per logical queue, so a family fills below the 42-queue cap. The J616s was restored to fleet89 and verified: saved entry unchanged, next_entry empty, test kernel removed, Enforcing, 0 failed units. Evidence (lab store): |
There was a problem hiding this comment.
Verdict: MERGE at 77229d88
Blockers: none (re-run the cancelled pr-text check before landing; 21/21 build/host/KUnit checks green).
Checked:
drivers/gpu/drm/asahi/g17/object.rs&context.rs: commit77229d88cleanly resolves the prior unboundedinner.deferredgrowth blocker by deferring uncached pooled objects only once they have actually been exposed to firmware, keeping pre-reserved drop capacity and control-fence lifetime safety intact.- Host fence tests (
tools/asahi/g17-object-fence-tests.py) and 21/21 CI checks pass; exact-head J616s (M4 Pro / T6040fixa5) hardware row PASS;MERGEABLEonmain. - Checked for Apple material, tool attribution, private serials, and gating: clean; human
Signed-off-bypresent.
Evidence
- Head:
77229d888257(base: main,mergeable: MERGEABLE,+424/-95across 4 files).
|
code-owner ping @DjDeveloperr: closeout merge at |
|
Merging under the 6-point rule (Ryan 09:29, permanent), at |
|
M4 Pro (T6040, J616s, 25G83 firmware, 16K pages) row, as a backport: 2dedb1a and 77229d8 cherry-picked Load: a GPU recovery storm (3 passes, 87 hang cases, 493 recoveries in 16.5 min) next to a running desktop.
One run, so the crash result is evidence, not proof, and the tree also carries other local changes on the kill path, |
Problem
The G17 firmware object pool holds a returned object back until the firmware has consumed the control record that ends its previous owner's use of it. That fence exists because the firmware can still follow a released object's address. Once a family runs out of cache room, the pool stopped holding to it in two ways. allocate() could hand out a returned object whose fence was not met yet (the family's
overrunscounter). And a fresh object made while the family was full had no cache lease, so its drop unmapped and freed it at once, with no fence at all.Change
control_fence(), the fence a cached object would wait for. allocate() and every deferred drop reap the list. Firmware stop releases whatever is left, the same way it releases kept objects.object::Exposureto its work state and its M5 scheduler page. The exposure is set bywork_head_va()/node_va()(expose_work),scheduler_va()and publication. An uncached object whose exposure is still unset is unmapped at its drop. So queues created and closed without work do not grow the list (capacity lineunexposed_freed=).uncached_objects_fenced waiting= bytes=line, and a one-time warning prints if the list grows large. If the firmware stops consuming control records, the objects stay mapped until firmware stop and are not freed early. The existingoverrunscounters stay and now read 0.Testing
tools/asahi/g17-object-fence-tests.py, updated: the new checks fail on the current integration/aurora pool ("an uncached object was unmapped before its fence") and pass with this change.run-host-tests.py --only g17-object-fencepasses 9/9, including the 4 new mutations.drivers/gpu/drm/asahi/builds with the fleet85 release config. No new warnings, none ing17/object.rs.Still to run
Host test details
The full-family scenario now runs on every family with and without
after_release. With only waiting entries, a full family hands out an uncached object instead of one of them. The dropped uncached object stays mapped untilcontrol_fence()is met and is unmapped at the next allocation after that, or at firmware stop. An uncached object kept withretain_until_stopstays off the deferred list.The random model records the control-ring witness at every unmap and checks it against the fence of each deferred object. The differential against the pool before linux#1978 (M4/M5 decisions) now limits BASE's reuse to met fences.
New mutations, each of which must fail the run:
overrun-full-family(reuse a waiting entry),unmap-uncached(free at drop),reap-early(reap one record early),stop-keeps-deferred(firmware stop leaves the list mapped).Neo row details
The patched aurora.ko was built M= against the fleet85 tree and loaded from rootfs on a one-shot boot of the default entry. The stock module ran on production fleet85. Counters come from
/sys/kernel/debug/aurora-g17/capacity, and the deferred-list line was sampled every 50 ms during the patched runs.Each stock run also freed 10 uncached objects at drop. On the patched one-shot boot the desktop was not a GPU client, so the patched runs show more fresh uncached allocations: new objects where the stock pool would have reused a waiting one.
Tested: run-host-tests 732/732 at 77229d8 (g17-object-fence create_close_loop: 4096 create/close cycles leave waiting=0; 14/14 mutants killed incl. defer-unexposed and unexposed-head); KUnit asahi 490/494 (4 skip); fleet-config asahi build OK; Neo rows above predate 77229d8.
Risk: G17 object pool on M4 Pro/Max, M5, A18 Pro; uncached (unpooled) objects now wait for the control fence when exposed and are freed at drop when never exposed; a missed exposure site would free a firmware-named object early (source rules pin the address readers).