Repository navigation
drm/asahi: grow a TVB buffer only while the firmware is not using it - #2468
Conversation
The firmware buffer manager owns a TVB buffer while scenes on it are in
flight. The render path grew the buffer for every render that needed
more blocks (min_tvb_blocks, or the overflow statistics), even with the
previous scenes of the same buffer still running: ensure_blocks()
appended blocks to the live block list and the render then sent an
InitBuffer for the bound slot. ensure_blocks() already holds back the
page count while scenes are active ("only if the buffer manager is
idle"), but the block list and the InitBuffer still changed under the
running scenes.
A fresh context starts with a small buffer and a layered render needs
7 + 2 * layers blocks when it is clustered, so a 3D blit grows it on
almost every pass, while the previous pass still tiles. On the M1 Pro
(G13S, two clusters) with several such contexts at once, the tiler
then writes to VA 0 (TE, VCE or dPM fault, then a GPU timeout).
Size the buffer for every render of a submission before any of it is
published, and only once the queue's earlier work, the only other user
of the buffer, has completed: a required grow waits for the queue's
last job, a grow from the overflow statistics only happens on an idle
queue (the firmware handles a full heap itself). The first render of
the submission then re-initialises the slot with the new size.
Signed-off-by: Ryan Murray <[email protected]>
DjDeveloperr
left a comment
There was a problem hiding this comment.
Thanks Ryan. The diagnosis is convincing, and sizing the TVB once per submission before anything is published is the right shape. A few things need to change first.
Must fix
-
User-triggerable panic. The new first pass calls
render_min_tvb_blocks()(queue/mod.rs:898) on a render command that has not been validated.get_tiling_params()computesx_max: (width - 1)andte_screen: ((tiles_y - 1) << 12) | (tiles_x - 1)(render.rs:165-167), and thewidth_px == 0/height_px == 0check only runs later insubmit_render()(render.rs:228). WithCONFIG_RUST_OVERFLOW_CHECKS=y(the default, and set in our 7.3.0 config), any client can oops the kernel from the submit ioctl with a zero-width render, while the queue mutex is held. Please move the flags and dimension checks intoget_tiling_params(), so every caller has them. -
last_outdoes not prove the TVB is idle. It is the fence of the queue's last job, whatever that job contained. A compute-only job without a VDM barrier can complete before the render job ahead of it (the FIXME at queue/mod.rs:850 says as much, and the kernel does not force that barrier). Thenbusyis false while that render still uses the buffer, and we grow it under the firmware again. The same happens if the last job failed inrun()before reaching the firmware: its fence carries an error while the job before it still runs. Please track the finished fence of the last submission that contained a render, and use it forbusyand for the wait. Renders complete in order on the fragment queue, andJobFencecovers both halves. Please also treat an error status as not proven idle. -
render_min_tvb_blocks()went in betweensubmit_render()'s doc comment plus#[expect(clippy::too_many_arguments)]andsubmit_render()itself (render.rs:184-203). The new function now has the wrong doc text and an unfulfilled expectation, and the 10-argumentsubmit_render()lost its expectation, soCLIPPY=1warns twice. Please move the new function above the doc comment.
Should fix
-
The grow wait (queue/mod.rs:762-783) is uninterruptible and fails the submission with ETIMEDOUT after 5 s. Earlier work can legitimately take longer: the scheduler timeout is 100 s, compute timeouts are configurable, and the previous job may still be waiting on its in-fences. Mesa turns a failed submit into device lost. The wait also holds off the freezer during suspend. Please wait interruptibly and return ERESTARTSYS. file.rs already passes it through quietly, and nothing has been published at that point, so the restart is clean. Please drop the 5 s cap, or use the scheduler timeout.
-
Statistics-driven growth now only happens when the queue is idle at submit time. A GPU-bound client with frames in flight is rarely idle there, so its TVB can stay at the dimension minimum and keep doing partial renders. Before this PR it grew while busy (unsafely, but it grew). Suggestion: peek
max_pageswithout resetting it, and fold the 3x target into the required size, so a stats grow waits once like a required grow. Growth is 3x per step, so that is a handful of waits per queue lifetime. Also, after the wait at line 942,busyis stale, so the stats grow is skipped right after we made the queue idle. -
The slot re-initialisation can be lost. The grow is published at lines 944-948, but the InitBuffer only goes out with the first render's commands. If the submission then fails, the next submission sees
need == falseandtvb_grown == false, and with the same slotrebind() == false, so the slot keeps the old size. Failure points after the grow: the command-count check, a barrier index,read_supported(), flags or timestamps insubmit_render(), or ENOMEM afterauto_grow_idle()already grew. A pending-init flag on the queue, cleared only afterjob.push(), fixes it.
Nits
- The
TVBStatsmessages went away with the removed render.rs block, andDebugFlags::TVBStatshas no users now. Please log the grow (old and new blocks, reason) insubmit(). get_tiling_params()does not needpub(super). Its new caller is in the same impl.wait_last_out_for_grow()duplicateswait_submitted(). One helper would do.
Evidence
- The M1 Pro rows ran a test module with an A/B debug bit in an unchanged kernel. Please confirm that code matches 3525bfc, or rerun about 10 runs of the same load on a build of this head, and attach the build log. No integration/aurora CI job compiles drm/asahi.
- This path serves G13, G14 and G14X only. The G14G control is single-cluster and never takes the clustered
7 + 2 * layerspath, so please add a G14X row (M2 Pro or Max): the same load plus the deqp subset. - For item 5, a GPU-bound geometry-heavy run on G13S, before and after, with frame time and TVB size from
TVBStats.
Leaving the firmware DestroyContext crash for a follow-up is fine. A separate issue for it would help.
The TVB sizing pass in Queue::submit() calls render_min_tvb_blocks(), and with it get_tiling_params(), on every render command of a submission before submit_render() has checked the command. With CONFIG_RUST_OVERFLOW_CHECKS, a render with a width or height of 0 then panics on `width - 1` / `tiles_x - 1` inside the submit ioctl, with the queue lock held. Move the flag and dimension checks from submit_render() into get_tiling_params(), so every caller gets EINVAL for such a command before any arithmetic on its size. Add KUnit cases for zero, oversized and unknown-flag renders, and for the clustered layered TVB minimum. Also put render_min_tvb_blocks() above submit_render()'s doc comment and #[expect(clippy::too_many_arguments)], which it had split from submit_render(), and make get_tiling_params() private again. Fixes: 3525bfc ("drm/asahi: grow a TVB buffer only while the firmware is not using it") Signed-off-by: Ryan Murray <[email protected]>
|
Build provenance for the M1 Pro / M2 rows above, plus a build of this PR's head. The rows were not built from 3525bfc. They used a module-only build on top of the production fleet74 kernel:
The 79 "after" mix runs used test builds of the same module (same base, the fix plus test-only trace/debug bits, the fix switched by a debug bit so one binary gave both arms). Build of the PR head. A module built from 3525bfc can't be loaded on fleet74: integration's drm/asahi calls
Build logs and the exact recipe for both builds: https://gist.github.com/RyanTheTide/81d48cc8fd5b3861c250f09fd09290e7 (full kernel log, drm/asahi excerpt, and the log of the module used for the rows). Still to run: the M1 Pro load (10 mix runs) on this 3525bfc kernel. I'll post the result here. |
The TVB grow waited for, or tested, the queue's last job. That job may not hold the TVB at all: a compute-only job without a VDM barrier can complete while the render ahead of it still runs, and a job that failed in run() before reaching the firmware carries an error while the job before it still runs. The buffer was then grown under the firmware again. Track the finished fences of the submissions that contain a render. Renders complete in order on the fragment queue and a job's fence covers all of its commands, so a render submission that completed without error proves every earlier render done; one that failed proves nothing about the ones before it. A grow waits for all renders up to the newest that completed cleanly. The wait is interruptible and returns ERESTARTSYS on a signal, instead of failing the submission with ETIMEDOUT after 5 s (Mesa reports a failed submit as a lost device, and earlier work may legitimately run longer). It runs before the job, its VM binding or its fence exist, so the ioctl restarts cleanly. The command count is checked before it. Growth from the overflow statistics only happened on an idle queue, so a GPU-bound client kept partial renders. Read the statistics without resetting them and fold their 3x target into the size the submission needs, so they grow with one wait per growth step, and reset them only once the buffer grew. The slot re-initialisation after a grow went out only with the first render of the same submission. If that submission then failed, the next one saw no grow and kept the old slot size. Keep it pending on the queue until a job with a render has been pushed. Log each grow (old and new size, what asked for it) under TVBStats, and share one fence wait helper with the queue's close path. Fixes: 3525bfc ("drm/asahi: grow a TVB buffer only while the firmware is not using it") Signed-off-by: Ryan Murray <[email protected]>
|
Pushed 38bd5b1 and 3d6b26b on top of 3525bfc (new commits, no rebase). Item by item:
Provenance: every M1 Pro row in the updated description ran exactly 3d6b26b, as the whole kernel 7.3.0-aurora-pr2468fix with its in-tree aurora.ko. The before/after perf rows and the 3525bfc control used external aurora.ko builds against that same kernel. The full from-scratch build log is in https://gist.github.com/RyanTheTide/8e219be16565f338d7c43c4b31595ce0. Results: 30 churn runs with 0 VA-0 faults, the deqp subset identical to stock, and glmark2 7513 before vs 7554 at this head. Still open: the M2 rows (that Mac is down right now) and a G14X row. The firmware crash is tracked in #2506. Its rate is higher on this integration kernel, about the same for 3525bfc alone (11 of 20 runs) as for this head (16 of 30). Assisted-by: LLM (Claude:Opus 5.5) |
|
M2 (J413, T8112, G14G single cluster) row at 3d6b26b: PASS, no regression. Same whole-kernel build as the M1 Pro rows (7.3.0-aurora-pr2468fix at 3d6b26b, in-tree aurora.ko), installed as a non-default entry; production fleet74 as the reference.
Churn = 4 long-lived 3D-blit renderers (2880 cases each) plus 4 VkDevice create/destroy churners, ~1000 churn processes per run (30,317 on the head, 29,953 on stock). The single stock abort (run 21, RTKit crash, GPU dead until reboot) is the separate firmware crash in #2506; 1/30 vs 0/30 is not a meaningful difference. glmark2-es2-gbm off-screen 2560x1600, same kernel, base module (pre-PR) vs head module, 5 reps each:
The M2 does take the overflow-driven grow: 6 grows from 32 to 76 blocks in each bench run (same submissions on base and head), handled with 0 faults, 0 timeouts and 0 firmware crashes. The clustered (G14X) path still needs a G14X row. Method and evidence
|
QueueJob::run() can fail on either side of publishing its commands to the firmware, and the scheduler then signals the job's finished fence with that error right away. The TVB grow treated every such fence as "never ran" and dropped it, and the slot init a grow attaches to the next render was cleared once that render was pushed. Two holes: - A failure after run_job() published commands (the doorbell send failed) leaves work the firmware may still pick up. Its vertex or compute half was rolled back, so no fence will ever signal its end. Dropping the entry let a later submission grow the buffer under it. - A render that carries the slot init and fails before publishing anything (e.g. ENOMEM in WorkQueue::submit()) loses that init, while later renders, built without one, go on to reach the firmware with a slot that does not match the grown buffer. Each render job now shares a small TvbJob with its queue: run() marks it published right before the first run_job(), and a failing init carrier that published nothing reports its init lost. The queue classifies its render fences as pending, done, failed-unpublished or failed-published: a failed-published entry stays until a later clean completion proves it done (renders complete in order on the fragment queue), and a grow that finds one as the newest outstanding render fails the submission with ECANCELED instead of waiting on a fence that has already signalled. A render that relies on a lost init fails in run() with ECANCELED before it publishes anything, and the next submission re-initialises the slot. The classification and pruning are pure functions with KUnit cases. Fixes: 3525bfc ("drm/asahi: grow a TVB buffer only while the firmware is not using it") Signed-off-by: Ryan Murray <[email protected]>
|
Pushed 2077fde on top of 3d6b26b (new commit, no rebase). It answers the error-path question: you were right, both cases were holes. Failure after publishing. Slot init lost before publishing. The init a grow attaches to the next render was cleared once that render was pushed. If that render then failed before publishing (the realistic case is an allocation failure in The classification and pruning are pure functions with KUnit cases (5 new, all pass; asahi suite 347 pass, 2 skipped). CLIPPY=1 reports 0 lints in the touched files. Rows at 2077fde (whole kernel
The M1 Pro abort rate matches what the integration base showed before (16/30 at 3d6b26b). On the M2, the matched A/B puts both heads at 1/20. Fault injection (test-only module parameter, not in this PR): every 2nd render that carries a slot init fails
Method, provenance, files
|
DjDeveloperr
left a comment
There was a problem hiding this comment.
Approving at 2077fde. All six review points are addressed, and Joshua's error-path question is closed by the new commit. A render whose post-publish failure is signalled with an error now keeps its TVB entry until a later clean completion, so a grow against it fails with ECANCELED instead of rewriting a live buffer. A render that relies on a slot init which never reached the firmware fails before publishing, and the next submission re-initialises. The pruning is a pure function with KUnit cases. Evidence: full-kernel build at this head (7.3.0-aurora-pr2468fix2), M1 Pro and M2 churn with 0 VA-0 faults and 0 timeouts, M2 matched A/B equal on #2506 aborts, and fault injection with 161 dropped inits and 0 faults. The G14X row from an M2 Pro/Max is post-merge verification. #2506 and #2546 stay separate.
Problem
On the M1 Pro (G13S, two GPU clusters), several short-lived GPU clients rendering at once make the tiler write to
VA 0 (TE, VCE or dPM "Unmapped" fault at address 0x0, then a GPU timeout and a failed job). This is the transient
3D blit CTS failure on G13S.
The cause is TVB growth while the buffer is in use. A fresh client's TVB starts at 8 blocks, and a clustered
layered render needs 7 + 2 * layers blocks, so a 3D blit grows the buffer on almost every pass while the
previous pass on the same buffer is still running. Growing appends blocks to the live block list, and the render
then sends an InitBuffer for the bound buffer-manager slot, both while the firmware owns the buffer.
ensure_blocks()already holds back the page count in that case, but nothing else.Change
Size the TVB for every render of a submission before any of it is published, and only once no earlier render of
the queue can still use the buffer:
get_tiling_params()now validates the render's flags and size, so the sizing pass (which runs beforesubmit_render()) rejects a zero-sized render with EINVAL instead of overflowing.to the newest one that completed without error (renders complete in order on the fragment queue; a failed one
proves nothing about the ones before it).
fence exist, so the ioctl restarts cleanly.
(one wait per 3x step). The statistics are reset only once the buffer grew.
that fails after a grow does not lose it.
run()keeps the buffer owned when some of its commands may have reached the firmware(marked published before the first
run_job()): it stays in the set until a later clean completion, and a growthat meets it fails with ECANCELED. A render that carried the slot init and failed before publishing reports the
init lost; renders relying on it fail with ECANCELED before publishing and the next submission re-initialises.
Testing
Head 2077fde, whole kernel 7.3.0-aurora-pr2468fix2 (same config/toolchain):
faults, 0 GPU timeouts on both. M2 same-kernel module A/B 3d6b26b vs 2077fde: 1/20 aborts each.
run()before publishing), M2: 161 drops, 28renders cancelled, re-init each time, 0 faults/timeouts.
Head 3d6b26b, whole kernel 7.3.0-aurora-pr2468fix (fleet74 config, drm/asahi Rust, overflow checks on), booted
on the M1 Pro:
short processes, 0 VA-0 faults, 0 GPU timeouts, 8-9 s per run
466 NotSupported, 0 changed)
terrain 427 vs 425 fps; overflow-driven grows still happen on the busy client (4x 32 -> 84 blocks, as before)
427/427; clippy: 0 lints in the touched files
Earlier rows (fleet74 kernel with the first commit as a test module, see the provenance comment): before 11 runs /
30 VA-0 timeouts, after 79 runs / 0; M2 (G14G) control identical on both.
Still to run
7 + 2 * layerspath is not taken on the single-cluster M2.run()before publishing wedges the queue (workqueue commit order), with orwithout this PR: drm/asahi: a job that fails in run() before publishing breaks its queue's event order #2546.
drm/asahi: G13S GPU firmware crash after DestroyContext under client churn #2506.
Reviewer detail: review items and evidence
Review at 3525bfc, answered by 38bd5b1 and 3d6b26b:
get_tiling_params(); KUnitasahi_render_tiling_params(zero/oversized/unknown-flag -> EINVAL, 1x1 and 16K valid, clustered 7 + 2 * layers); hardware zero-size submit
test on the M1 Pro: 6/6 EINVAL.
last_outis not a TVB idle proof: replaced bytvb_users, the pending finished fences of render submissionsafter the newest one that completed cleanly. A clean completion drops it and every older entry; an error drops
only that entry. The grow waits newest first until the list is empty.
render_min_tvb_blocks()moved abovesubmit_render()'s doc comment and#[expect];get_tiling_params()private again. Clippy at 3525bfc showed the two lints (render.rs:203 too_many_arguments, render.rs:186
unfulfilled expectation); at this head there are none in the touched files.
MAX_SCHEDULE_TIMEOUT, ERESTARTSYS. The command-count check and the whole sizing pass nowrun before
start_op(),bind_vm()and the fence, so nothing exists yet when it restarts.stats_target_blocks()peeksmax_pageswithout resetting; the target is folded into the required size;reset_stats()only after the grow. No stalebusy: there is no separate idle check any more.tvb_init_pendingon the queue, set by a grow, passed to the first render, cleared only afterjob.push().Nits: TVBStats grow log in
submit();wait_fence()shared by the close path and the grow.Firmware-crash rate on this kernel, same load: head 16/30 runs, the first commit alone 11/20 runs (fleet74 with
the first commit: 9/47), so the higher rate comes with the newer integration base, not with these commits.
Build log (full kernel from scratch at 3d6b26b), KUnit, host tests, clippy:
https://gist.github.com/RyanTheTide/8e219be16565f338d7c43c4b31595ce0
How the cause was found: a per-submission trace (lock-free ring in a test build, dumped only at fault time) for
every faulting queue showed tiny heap use (overflow_count 0, max_pages 11) and the block count going
8 -> 15 -> 19 -> 21 -> 23 -> 31 -> 39, driven by min_tvb_blocks while the previous scene was in flight, with the
fault on the latest grown render. Ruled out on hardware: serialising each queue's first render, the legacy inline
submit and receive fast paths, deferring only the InitBuffer. A bigger initial TVB (64 blocks) also removes the
faults at unchanged speed, which confirms growth as the cause. Waiting for the buffer's scene count to reach 0
would deadlock: the work queue keeps the last completed command (and its scene) until a later one completes.
Assisted-by: LLM (Claude:Opus 5.5)