Skip to content

drm/asahi: g18: end a render at once when its parameter buffer growth is refused - #2758

Merged
RyanTheTide merged 7 commits into
aurora-silicon:integration/aurorafrom
sithglan:thomas/g18-pb-grow-failfast
Nov 22, 2026
Merged

RyanTheTide merged 7 commits into
aurora-silicon:integration/aurorafrom
sithglan:thomas/g18-pb-grow-failfast

Conversation

@sithglan

Copy link
Copy Markdown
Contributor

Stacked on #2242 (parameter buffer growth). Review the last commit.

This is the follow-up from Ryan's review of #2242. A TVB grow request can be answered "not grown": either the client is at its memory limit, or the PB is at its ring limit. The tiler that asked then stays stalled, and the render ended only when the 10 s job watchdog requested a recovery. Jobs run one at a time, so every other client sat through each of those stalls too.

The session now remembers a "not grown" answer. wait_job() requests the recovery on its next poll, the same recovery the watchdog would request. The refused render still fails with EIO, but within milliseconds. A successful growth, or a stale request from before the current recovery epoch, changes nothing.

Tests (M6 Mac mini, J873g). As in #2242's rows, the code was ported onto the J873 desktop tree, kernel 7.3.0-aurora-j873-avd-usb4-perf+.

row #2242 alone with this PR
client_mem_limit_pct=3, a 5M-triangle scene next to a 20k client 8 renders end by the 10 s watchdog; the 20k client runs 6000 frames in 92 s (65 fps) G18_GROW_REFUSED ... ms=28 and ms=15, each followed by a recovery done in 5.4 ms; 0 watchdogs; the 20k client runs 6000 frames in 12.1 s (494 fps), err=0
default limits: 5M scene, 20k, 5M again, both at once PB grows to 1144 blocks, 0 refusals, 0 watchdogs the same: 71 grows to 1144 blocks, 0 refusals, 0 watchdogs, 0 job failures, same frame times
  • Refused client: it gets EIO on its next submit and stops. Afterwards a 20k client runs at 495 fps, and the desktop on the same GPU kept running.
  • Build: drivers/gpu/drm/asahi/ builds with the same warnings as before, all in other files.

cc @DjDeveloperr @RyanTheTide @Acelogic @LiamRay10

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Reviewed the last commit (4db28d0). Thanks for doing this so quickly.

The control flow is right. growth_refused is cleared when wait_job() starts. It is only acted on while no recovery is running, because the else if sits behind if let Some(ended) = recovery, so a second refusal during a recovery can't stack another one. A stale request from an older epoch returns before the flag is set. The memory-limit row shows exactly what was asked: 494 fps instead of 65 for the neighbour and 0 watchdogs.

One case to check before merge: the flag is also set for Ok(0), "PB at its limit", the ring limit rather than the memory limit. The commit assumes the tiler always stays stalled after a "not grown" reply. If the firmware instead finishes the pass some other way when the ring is full (a partial render, say), this change now kills renders that would have completed. Neither row hits that path (0 refusals at default limits). A row that drives the PB to its ring limit with #2242 alone would settle it: if the render ends only by the watchdog there, the commit is right as is. If it completes, only the memory-limit refusal should request the recovery.

The commit message could also say that the refused client's render ends with EIO and the client sees it on its next submit, as the description says.

Assisted-by: LLM (Claude:Opus 5.5)

The G18 render path backs the tiler's parameter buffer with 8 blocks
(4 MiB) and never grows it. When a scene needs more, the firmware posts
event type 6, a TVB grow request in the M5 TvbGrowEventRecord layout,
and the tiler waits for the host. Nothing answered, so the frame stalled
until the 10 s job watchdog requested a recovery, and the client's
submit failed with EIO. Zooming into Google Maps in Firefox or Chromium
on the J873 (M6 Mac mini) hits this.

Answer the request as the M5 driver does for a firmware-requested
growth (Manager::commit_growth without a descriptor): back 16 more
blocks as one object, write their first page numbers into the block
table at the ring slots after the total cursor, advance total and
committed, and reply with a TvbGrowReply (device-control opcode 8,
grew = 1) plus the 0x84/0x11 control doorbell. The firmware builds the
page-list entries itself. A "not grown" reply leaves the tiler stalled,
so it is only sent when growth fails or the buffer is at its limit.

The PB grows to at most 254 blocks (127 MiB): the block table before
the shared header holds 256 ring slots. The graphics-pb VA window grows
from 16 to 128 MiB for that; its biased half stays inside the
COMPACT_BIAS + [32 MiB, 2 GiB) that Mesa leaves to the kernel. The new
blocks are homed in the PB's storage VM like the initial ones and are
aliased into the running client's VM; a later client maps every block.

Two per-frame checks assumed the PB and the control ring never change:
the PB row's page count may now grow up to the backed blocks, and the
outer-ring publication expects the primary control ring past the grow
replies published since boot.

A headless GLES test drawing N triangles of about 200 px into 2560x1440
stalled at 60000 triangles before. Now 150000 and 600000 triangles grow
the PB on their first frame and render in 10 and 44 ms afterwards; the
images match llvmpipe apart from single edge pixels, as small scenes do.
One million triangles reach the limit and still stall. Two clients
alternating 600000-triangle frames render all frames. Tiny frames of two
alternating clients take the same time with an 8-block and a 254-block
PB (2.66-2.88 s vs 2.71-2.77 s for 2x2000 frames). Zooming into Google
Maps in Firefox now grows the PB to 40 blocks (20 MiB) without a stall.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
…e is given

The PB's ring is described to the firmware with PB_CAPACITY (1650) slots,
but growth stopped at 254 blocks, because the block table in front of the
shared header held 256 entries. A scene that needs more than 127 MiB of
PB, about 1.1M triangles of the headless test, made the firmware ask again
after a refused grow and then wait until the job watchdog: a 10 s stall
and EIO, as before the growth support. Telling the firmware a lower
maximum (state +0x7c) changed nothing; it does not render partially there.

Make room for the whole ring instead. The block table stays at the start
of the PM graph and holds PB_CAPACITY entries; the shared header, the
counter and the scene records move up behind it (0x3400, 0x3500, 0x4000).
Placing the table behind the scene records, at +0x8000 of a larger graph,
faulted the first frame. PB_MAX_BLOCKS follows PB_CAPACITY, and the
graphics-pb window grows to 832 MiB to hold that many blocks, still inside
the COMPACT_BIAS + [32 MiB, 2 GiB) range Mesa leaves to the kernel. The
job's ring capacity now comes from PB_CAPACITY rather than a second 1650.

The PB is retained with the session, as before: a scene that grows it to
N blocks keeps N * 512 KiB allocated.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
A PB growth was a kernel object: the device and per-client memory limits
never applied to it, and its bytes were counted as nobody's. The PB lives
with the session and is shared by later clients, so one client drawing a
large scene could pin up to 1649 blocks (about 824 MiB) until reboot.

Admit each growth against the requesting client's limit and the device
limit first, as g17 admits its pools, and keep the blocks as that client's
held memory (a user charge on a kernel object). A refused admission fails
the growth with ENOMEM: the firmware gets "not grown", and only the render
that asked fails, as at the block limit. A growth with no client to charge
is refused the same way, so nothing grows unadmitted.

The G18 driver's probe never configured the limits (memacct's configure()
ran only in the other generations' probe), so on the J873 both read 0,
"none", and nothing could be refused. Configure them there too. That
applies the limits to every G18 GEM allocation, not only to PB growth: at
the limit, GEM_CREATE fails with ENOMEM as it does on the other generations.

Grown blocks are not given back. The firmware's ring is only ever
extended: it asks with event 6, and the host answers by writing the new
table slots and advancing total and committed. No message is known that
makes the firmware drop blocks it was given. Lowering total behind its
back would take away slots it may still hold, so until such a message is
found the grown blocks stay with the session, held by the client that
grew them. The limits bound how much that can be.

The ring keeps one slot empty to tell a full ring from an empty one, so
PB_MAX_BLOCKS is PB_CAPACITY - 1.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
The parameter buffer growth code added to this file in the previous
commits kept several statements per line, like the rest of the file.
Format the whole file with rustfmt (the tree's .rustfmt.toml), so the
next change to it can be read and reviewed line by line. No functional
change; rustfmt --check passes and the driver builds with the same
warnings as before.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
@sithglan
sithglan force-pushed the thomas/g18-pb-grow-failfast branch from 4db28d0 to 519f007 Compare November 22, 2026 05:46
@sithglan

Copy link
Copy Markdown
Contributor Author

@RyanTheTide rebased with #2242 onto integration/aurora 24dc422773c9. The new head is 519f007e7f0e.

Ring limit (Ok(0)): not settled yet. The row you describe runs #2242 alone, with a scene past PB_MAX_BLOCKS:

  • 1649 blocks of the 1650-slot ring;
  • the 5M-triangle scene stops at 1144, so it needs about 7.5M triangles.

The row needs the J873g's GPU module swapped, and that Mac is in use right now. I'll run it when it's free and post the result. If the render completes there, I'll limit the recovery to the memory-limit refusal, as you suggest.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adversarial review of top commit 519f007e7f0e (stacked on #2242) against the pre-PR checklist.

0 code/policy/attribution/CI blockers. Holding only for prerequisite #2242 and the remaining §5 hardware rows on live head 519f007e7f0e.

Verified

  • §1–§3 (Control flow & safety): growth_refused is cleared at wait_job() entry, stale-epoch grow requests return before setting it, and else if core::mem::take(&mut self.growth_refused) sits behind if let Some(ended) = recovery so a refusal during an active recovery cannot stack another recovery.
  • Note to watch during stress testing (non-blocking): wait_job() triggers self.recover(label, true) immediately on the same poll iteration after answer_tvb_grow() publishes TvbGrowReply(..., false) + CONTROL_NOTIFY on EP_GFX_INTERRUPTS (incrementing control_published). Because subsequent submissions check control_counters() == control_retired() (initdata/application.rs:40), this relies on GFX firmware consuming the TvbGrowReply before/during recovery in FIFO order on EP_GFX_INTERRUPTS. Your 6000-frame J873g run confirms that held in practice, but it's worth verifying across the ring-limit test too.
  • §4 (Clean-room & attribution): Clean across all 5 commits in the branch (Thomas Glanzmann human author/committer + Signed-off-by: only, zero AI trailers in commits; Assisted-by: in PR body).
  • §6 (Naming) & CI: Clean; host-tests passed on 519f007e7f0e.

Remaining prerequisites & §5 hardware rows needed for approval

  • Stacking prerequisite: #2242 (whose 4 commits are carried in this PR targeting integration/aurora) must land first.
  • J873g Ok(0) PB ring-limit row (> PB_MAX_BLOCKS, ~7.5M triangles on #2242 alone vs #2758): settle whether firmware stalls until the watchdog or completes partially at the ring limit (as noted by @RyanTheTide and already queued); if it completes partially, narrow growth_refused to memory-limit/error refusals only.
  • Post-rebase verification + §5 regression row on 519f007e7f0e: re-verify after the G18Session conflict resolution with #1652, including explicit §5 regression counts (0 SELinux denials, 0 failed units, 0 new kernel errors).

Assisted-by: LLM (Gemini 4 Neon)

@sithglan

Copy link
Copy Markdown
Contributor Author

@RyanTheTide the ring-limit row (Ok(0)). At the ring limit the firmware doesn't finish the pass. With #2242 alone the render ends only by the watchdog, so the commit is right as is.

Setup. J873g, kernel 7.3.0-aurora-j873-avd-usb4-perf+.

#2242 alone this PR
renders refused at the ring limit 22 4
G18_APP_PB_STALL (logged at 5 s) 22 0
render ended by the 10 s watchdog, 22 of 22 G18_GROW_REFUSED ... ms=112: requesting recovery, 4 of 4
renders that completed 0 (pixel 00000000) 0
one asyncbench run about 102 s about 1 s
  • Nothing moves after the "not grown" reply. Between 1 s and 10 s into the wait, G18_APP_WAIT shows the same outer and inner queue counters and the same stamps. No partial render is published, and the tiler is still stalled when the watchdog fires.
  • What the client sees with this PR. Each refused render ends with EIO 4–8 ms after the recovery request. The client's next submit fails with EIO, and Mesa then stops submitting for that context.
  • @DjDeveloperr's note on TvbGrowReply ordering. The reply followed by the immediate recovery held in all 4 cases:
    • Each process's second job was accepted and kicked, then got its own growth request.
    • The clients that ran next on the same boot ran without a job failure (drawbench, and the vertex-output checks from mesa#622).
    • At the end of the boot there were 0 failed units and 0 AVC denials.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upgrading to APPROVE at live head 519f007e7f0e4c1bb1b2f75c1b47fc0f90daeb60 after the newly posted J873g ring-limit and regression rows (#issuecomment-7077031525).

§5 Hardware Verification Now Complete (519f007e7f0e)

  • Ring-limit (Ok(0)) A/B on J873g (8M & 10M triangles, > 1648-block ring): With #2242 alone, 22/22 refused renders stalled (G18_APP_PB_STALL at 5 s) until the 10 s watchdog (~102 s/run, 0 completed, pixel 00000000), confirming firmware never partially completes at the ring limit. With #2758, 4/4 ended via G18_GROW_REFUSED ... ms=112 with recovery in 4–8 ms (0 stalls, 0 watchdogs, ~1 s/run) — confirming growth_refused is right to cover Ok(0) as well as memory-limit refusals.
  • TvbGrowReply + immediate recovery FIFO ordering: Held across all 4 ring-limit refusals and subsequent clients (drawbench, mesa#622 vertex-output checks) on the same boot with 0 job failures.
  • Regression counts: 0 failed units, 0 AVC denials, 0 job failures (alongside the default-limits row: 71 grows to 1144 blocks, 0 refusals, 0 watchdogs).

Checklist & Merge Ordering

  • §1–§6 & CI: All checks pass; host-tests is COMPLETED / SUCCESS on 519f007e7f0e; all 5 commits carry human author/committer and human Signed-off-by: only.
  • Stacking note: Merge after (or together with) already-approved prerequisite #2242 (c48d68d78dff, currently OPEN and approved by @RyanTheTide).

Assisted-by: LLM (Gemini 4 Neon)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merge-train adversarial review (MERGETRAIN-LINUX3) at 519f007, together with #2242 (c48d68d, which is an ancestor of this head): NO BLOCKERS for either. Both merge cleanly onto integration. The train merges #2758 on Dj's APPROVE, and that lands #2242's commits with it.

Notes:

…rol ring

reply_tvb_grow() placed the TvbGrowReply at the 26A428 control ring
offset, a fixed constant. The shared-memory layout is per firmware build
since the InitData profiles, and the IdlePowerOff record next to it
already takes the ring from self.layouts. With 26B123, which the J873g
loads today, the reply went to the wrong place: the tiler waited for it
and every render that needed a second parameter buffer block stalled
until the watchdog.

Take the ring from the admitted profile, as IdlePowerOff does.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
… is refused

When a TVB grow request is answered "not grown" (the client is at its
memory limit, or the PB is at its ring limit), the tiler that asked stays
stalled. The render then ended only when the 10 s job watchdog requested
a recovery. Jobs run one at a time, so every other client waited out each
of those stalls too: in the refusal row of the parameter buffer growth
change, a 20000-triangle client next to a refused 5M-triangle scene
averaged 65 fps over 92 s instead of about 490.

Remember a refused answer in the session, and have wait_job() request the
recovery on its next poll, the same recovery the watchdog would request.
The refused render fails with EIO as before, only now within milliseconds;
its client sees the error on its next submit.
A growth that succeeds, or a request from before the current recovery
epoch, changes nothing.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
@sithglan
sithglan force-pushed the thomas/g18-pb-grow-failfast branch from 519f007 to 61f7b3d Compare November 22, 2026 11:28
@sithglan

Copy link
Copy Markdown
Contributor Author

@RyanTheTide @DjDeveloperr both notes, and the smoke found a real bug, so the heads moved:

The smoke on the merged tip.

Same smoke with the fix (asyncbench, frames/s):

triangles before the fix with it
200 / 20000 1351 / 282 1351 / 289
1000000 0 frames, watchdog 18.9, err=0
5000000 0 frames, watchdog 3.6 (280 ms per frame), err=0
8000000 (past the ring) watchdog not grown: PB at its limit, then G18_GROW_REFUSED ... ms=144, EIO
  • The PB grew in 103 steps up to 1649 blocks.
  • 0 watchdogs and 0 failed units with the fix.
  • Kernel errors: only the boot-time lines this stack always has (btcentauri, ASoC Secondary, the P-state 10 has no OPP lines, two i2c NACKs).
  • The M6 is back on its default kernel.

The nit: the grow-request queue. New last commit in #2758, "answer a repeated grow request once, keep the rest in the ring":

  • An identical request that is already queued is dropped, as G17's queue_tvb_grow() does.
  • A new request that finds the four entries taken stays in the event ring: the drain stops for that ring, the session answers the queued ones, and the next drain takes it. So a full queue no longer fails every later drain.
  • The smoke above runs this commit too, though one ring never held more than one request.

Both heads build (arm64, LLVM 22) and checkpatch --strict is clean.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merge-train re-review (MERGETRAIN-LINUX3) at 61f7b3d, which includes #2242 at 83ccd92: NO BLOCKERS. Against 519f007 the tree delta is one file, g18/initdata/mod.rs:

  • reply_tvb_grow() now takes the ring from self.layouts.shared.control_ring[0] instead of the fixed 26A428 offset. That matches the IdlePowerOff record next to it, and it is the right fix for the watchdog stall on the 1M-triangle smoke.
  • Queue: a duplicate request is dropped, as on G17. On a full queue the break comes before the consumer-cursor write in drain_reports(), so the record stays in the ring for the next drain and nothing is lost. A full queue no longer fails every later drain, which closes our earlier nit.

Nit, not blocking: while a grow record is held, any completion-stamp events behind it in the same ring also wait for the next drain. That is fine as long as answering the queued grows always leads to another drain. If the session only drains on a new interrupt, the comment could say what guarantees that next drain.

Dj's earlier APPROVE was at 519f007. The train merges this head once Dj approves it.

… the ring

The drain held at most four grow requests until the session answered
them. A fifth one in the same pass failed the drain with EBUSY before the
session could answer any of them, and since every later drain met the
same full queue, the device could not recover until a reboot.

An identical request that is already queued is now dropped, as G17's
queue_tvb_grow() does, so the firmware repeating a request gets one
reply. A new request that finds the queue full stays in the event ring:
the drain stops for that ring, the session answers the queued ones, and
the next drain takes it.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
@sithglan
sithglan force-pushed the thomas/g18-pb-grow-failfast branch from 61f7b3d to 37631b5 Compare November 22, 2026 12:24
@sithglan

Copy link
Copy Markdown
Contributor Author

@RyanTheTide on the nit: the session drains on every poll of its waits, not on an interrupt. wait_job() calls poll_faults() each time round its 20/200/1000 µs ladder, and the other waits call check_faults(); both start with drain(). So a grow record held in the ring, and any completion stamps behind it, are drained one poll after the queued grows are answered. The comment at the break now says so. The new head is 37631b53dbe4: comment only, the code is unchanged against 61f7b3d3, and it builds.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed live head 37631b53dbe49b3c0d04061a76520c5587787a26 against 519f007e and the pre-PR checklist (§1–§6). READY TO MERGE (cleared for MERGETRAIN-LINUX3).

Verified

  • Delta 519f007e..37631b53dbe4 (drivers/gpu/drm/asahi/g18/initdata/mod.rs):
    • reply_tvb_grow() now writes into self.layouts.shared.control_ring[0] (matching publish_idle_wake()) instead of the fixed 26A428 offset, fixing the 26B123 control-ring mismatch caught by the merged-tip smoke.
    • drain_reports() deduplicates repeated identical G18TvbGrowRequest entries and breaks before advancing report_counts or the ring consumer cursor when self.tvb_grow.len() >= TVB_GROW_QUEUE, so overflow leaves the record in the ring for the next poll (poll_faults() / check_faults()) instead of poisoning subsequent drains with EBUSY. The comment-only update from 61f7b3d3 to 37631b53dbe4 accurately documents the polling guarantee.
  • §4 Commit hygiene: All 7 commits carry human author/committer (Thomas Glanzmann <thomas@glanzmann.de>) and Signed-off-by:, with zero AI commit trailers.
  • §5 Hardware evidence: Merged-tip J873g (26B123) smoke on integration/aurora d1b022dc34fb + #1797 + #2758 passes 200/20k/1M/5M triangles (PB grew in 103 steps to 1649 blocks, err=0) and ends 8M triangles cleanly at the ring limit via G18_GROW_REFUSED ... ms=144 -> EIO (0 watchdogs, 0 failed units), in addition to the prior memory-limit and ring-limit A/B rows.
  • CI: Host tests/host-tests green.

Assisted-by: LLM (Gemini 4 Neon)

@RyanTheTide
RyanTheTide merged commit 5f1a255 into aurora-silicon:integration/aurora Nov 22, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants