Repository navigation
drm/asahi: fix the G14 27.2 pool slot lifetime (GB6 firmware crash and pool stall) - #3182
Conversation
…ed twice On G14 firmware 27.2 the firmware keeps a pool slot on a list while it still has stamp stores queued for it. Each queued record names the retired command's JobMeta (stamp pointer, value, slot). A list pass that finds the slot's retirement cursor advanced unlinks the slot, which clears the word the driver reads as "registered", and only after that reads the records it still holds. The driver reused a slot as soon as it was retired and unregistered, and zeroed and re-encoded the command right away. When that happened while the firmware was still reading the old command's records, the firmware stored through a zero or half-written stamp pointer and faulted (RTKit data abort, FAR 0), and the device was lost. Sustained Vulkan compute (Geekbench 6) hit it within minutes once kernels were timed with Vulkan timestamps or the GPU ran at full clock, both of which raise the submission rate and keep the pool full. Give each slot two command buffers and use them in turn. A retired command stays intact while its slot's next command runs. Its buffer is rewritten only after the slot has been retired and unlinked once more, which the firmware does in a later pass than the one that read the old records. The slot's tracking, stream and retirement rules are unchanged. Signed-off-by: Ryan Murray <[email protected]>
When no pool slot becomes free for the command timeout, print the busy and unacknowledged slot masks and, for every slot the firmware still lists or whose cursor differs from its record count, those three values. This is the information needed to tell a firmware that stopped retiring slots from a cursor the driver never advanced. Signed-off-by: Ryan Murray <[email protected]>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
Row: 27e52f6 · J473 (M2 mini, G14G fw 27.2) · PASS: Geekbench 6 Vulkan 8/8 runs back to back, 0 firmware crashes, 0 GPU timeouts, fresh vkcube/vulkaninfo OK after; Vulkan timestamps on, full clock range, default command line, Stage 2 e1073db5. Evidence: lab store traces/gpu/20261125-m2gpu-next/20261126-132653-j473-gb6x-a2/README.md |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Request changes at 27e52f68. Thanks, Ryan, for the J473 runs with timestamps and the full clock range enabled.
One blocker. gpu/v27_2.rs:527 flips the slot’s buffer bit on encode. Suppose A was the last published buffer. The driver encodes into B, then the in-flight allocation fails at g14_v27_2.rs:723. B never reaches firmware and the slot stays free. The next attempt on that slot selects A and clears its JobMeta. There was no intervening retirement or unlink. Select the spare buffer during encoding and commit the bit only when publication is guaranteed. For render, commit both slots after both submissions have staged. A failed-publication retry should select B again.
What I checked
On successful compute submissions, the queue’s retired position releases the busy bit (g14_v27_2.rs:943–945, 813), and slot selection also checks the firmware’s list flag (lines 628–632). The final read of JobMeta depends on the firmware pass ordering you described. Neither queue depth nor the completion stamp establishes it.
Both buffers are slices of one runtime-owned allocation, adding 192 KiB. Recreating a client queue or VM keeps the same pool and bit. A fresh runtime starts with fresh storage and a zero bitmask. Stop deliberately retains the pool for the rest of the boot because the firmware page tables still reference it (g14_v27_2.rs:1064–1069).
At this head only T8112 selects this backend (driver.rs:199–204, 410–415), so the J473 row covers the affected generation. The change adds no runtime switch, delay, or board gate. I reran all nine host ABI tests. The alternation test covers consecutive encodes and misses failed publication.
…ication Encoding a pool command flipped the slot's buffer bit at once. When the publication then failed (for example the in-flight allocation), the command never reached the firmware, but the next attempt on the slot selected the buffer of its last published command and cleared its JobMeta, with no retirement or unlink in between. Always encode into the slot's spare buffer without changing the bit, and flip it only after the command is published: right after the compute submission is published, and for a render pass after both submissions are published. A failed publication is retried in the same spare buffer. Reported-by: Diljit Singh <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
…pping it The firmware keeps a pool slot listed until the slot's retirement cursor equals the number of records it counted for the slot. It can count another record for a retired slot after the driver advanced the cursor. The driver advanced it only once per retirement, so such a slot stayed listed for good. Under sustained load every slot ended up there and the pool stalled: "command pool stalled", with no slot busy or awaiting acknowledgement, and every slot listed with its record count one above its cursor. When the free-slot search finds a slot that is not busy but still listed, advance its cursor to the current count. The slot's last command is kept intact in its buffer, so the earlier unlink this allows is safe. Signed-off-by: Ryan Murray <[email protected]>
|
Row: 1015e9c · J473 (M2 mini, G14G fw 27.2) · PASS: Geekbench 6 Vulkan 8/8 runs back to back, 0 firmware crashes, 0 GPU timeouts, no pool stall, fresh vkcube/vulkaninfo OK after; Vulkan timestamps on, full clock range, default command line, Stage 2 e1073db5. Evidence: lab store traces/gpu/20261125-m2gpu-next/20261126-144235-j473-gb6x-a4f/README.md |
|
@DjDeveloperr thanks, the blocker is right. Fixed in 890aa26: encoding always takes the slot's spare buffer without touching the bit, and the bit flips only after publication (compute: after the submission is published; render: after both submissions are published). A failed publication is retried in the same spare buffer. The host test now covers a failed publication and its retry. The same rows also exposed the rare pool stall. The new stall report showed every free slot still listed with its record count one above its cursor: the firmware counts one more record for a retired slot after we acked. 1015e9c re-advances the cursor of a free but still-listed slot during the free-slot search. That is safe because the slot's last command stays intact in its buffer. Head 1015e9c: GB6 Vulkan 8/8 on the J473, no crash, no stall (row above). |
RyanTheTide
left a comment
There was a problem hiding this comment.
Verdict: MERGE at 1015e9c6 once CI at this head is green and Dj clears his request
Blockers: none. This is a non-author review for the merge policy; GitHub records it as a comment because this account opened the PR.
Checked:
- 890aa26 fixes Dj's blocker from
27e52f68. Encoding now picks the spare buffer withspare_buffer(published, i)and does not touch the bit.mark_published()flips the bit only aftersubmission.publish()on compute. On render it flips both slots afterfs_post/ta_postare published. If the in-flight allocation fails, the retry uses the same spare buffer, and the last published JobMeta is never cleared. The first encode still lands in the second buffer, as before, so slot layout is unchanged on a fresh runtime. - The host test now covers a failed publication and its retry, and still checks that no buffer is shared between slots.
- 1015e9c adds a re-advance in the free-slot search. It only touches slots that are not busy and still listed.
retire()copies tracking +0xc to the cursor, so calling it again is idempotent, and the slot is still skipped in that round. There is no new gate, parameter or delay. - Row at the exact head (J473, GB6 Vulkan 8/8, timestamps on, full clock range, default cmdline, no pool stall), as recorded in the PR comment.
Question (non-blocking): the early unlink is described as safe because the last command stays intact. That holds if the extra record the firmware counts after retirement names the slot's last JobMeta. If it could name the one before last (the spare buffer), the next encode would rewrite it. A line in the commit message saying which command that record refers to, from the stall report, would settle it.
|
On the non-blocking question (which command the late record names): the firmware queues a stamp record only when a command in the slot completes, and the record names that completing command's JobMeta. The slot's spare buffer is never published while the command before last can still add records. A slot is published again only after an unlink, and the unlink needs cursor == count, so every record counted for the command before last is in that count, and those records are read in that same pass. So the extra record seen in the stall report belongs to the slot's last command, the one in the current buffer, which the next encode does not touch. One case this does not exclude: the command before last adding a record after the last command has itself completed. That would need its post-processing to run after a later command's completion in the same slot. I have not seen that in the dumps, and the stall report (records = cursor + 1, one per slot) is consistent with one late record for the last command. If it ever shows up, the stall/crash signature would be the old one at the spare buffer's page offset. |
RyanTheTide
left a comment
There was a problem hiding this comment.
Verdict at 1015e9c6: Dj's blocker from 27e52f68 is resolved. I found nothing blocking in the stall fix. CI: 11 pass, 9 KUnit suites still queued.
Blocker (failed publication reuses the published buffer): fixed in 890aa261.
encode_withnow picksspare_buffer(published, slot)and leaves the bit alone.- Compute:
mark_published(slot)runs only aftersubmission.publish(), and nothing after it can fail. - Render: both slots flip only after
fs_post.publish()andta_post.publish(). An error atencode_with(fs),stage_renderorprepareleaves both bits as they were, so the retry encodes into the same spare. free_slotsreturns two different slots, so the XOR inmark_publishedcannot cancel out for a render pair.
1015e9c6 (re-advance a listed free slot):
retire()only copies the firmware's own count at +0xc into the cursor, so the cursor never runs ahead of the firmware. With a zero count it does nothing.- It is reached only for slots that are not
busy, so no slot with a command in flight is re-advanced. An in-flight slot's cursor still moves only throughacknowledge()after retirement. - The early unlink it allows is covered by the double buffer: the last published command stays intact, and the next encode writes the other buffer, which was retired and unlinked before the current command was published.
- Calling it again on later searches is idempotent.
Non-blocking:
- In
free_slots, aretire()error propagates with?, whileacknowledge()logs and continues. Todayretire()can fail only on an out-of-range index, so it does not matter in practice. - The cursor re-advance has no host test. It models firmware behaviour, so the J473 GB6 8/8 row at
1015e9c6(no stall, no crash, timestamps and full clock range, default cmdline) is the evidence. Please keep the stall report so a regression shows up.
As the PR author's account I can only comment, not approve. Dj, please re-review.
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict: MERGE at 1015e9c61f02
Blockers: none. The point from my last review is fixed in 890aa261. Encoding always takes the slot's spare buffer, and the bit moves only after a successful publish: compute after its submission is published, render after both are. So a failed publication leaves the last published command alone, and the retry reuses the same spare.
Checked: every exit before the publish leaves the bit alone: encode(), stage_compute(), inflight.push(), both encode_with() calls and both stage_render() calls. Nothing that can fail runs between publish() and mark_published(). The stall fix in 1015e9c6 only re-advances the cursor of a free slot the firmware still lists, and retire() stores the recorded count, so a repeat is harmless. CI at this head is green (apple-build, KUnit asahi, host-tests), and the 9 ABI host tests pass locally. Your J473 row at this head: GB6 Vulkan 8/8, no firmware crash, no pool stall. Nit, not blocking: the new test covers pool_command()/spare_buffer() only, so a case through encode_with() with a failed publish would catch a return to flipping at encode time.
Superseded by the review at 1015e9c
Brings the G14 firmware 27.2 recovery up to main 255761f (the source of the m2combo22 kit): pool slot double buffers with the publish-only flip and cursor re-advance (#3182), compute sampler heaps (#3198), the pool stall report and the deep-sleep warm restart. Conflicts were additive: State keeps both the recovery fields and hardware_unreachable/commit_stop, the ABI file keeps both the recovery records and the Globals/compute/pool helpers with both test sets, and run-host-tests.py runs both g14-v27-2-abi-tests.rs and pmp-alloc-tests.rs. Stopped commands keep #3182's slot rule: their slot is retired the normal way, and its next command goes to the slot's other buffer, so the stopped command stays intact until the firmware unlinks the slot again. Signed-off-by: Ryan Murray <[email protected]>
What
On G14 firmware 27.2 (M2 mini J473), the GPU firmware crashes under sustained Vulkan load: an RTKit data abort writing to address 0. After it, every client gets EIO and the device is lost. On current main, Geekbench 6 Vulkan hits it within minutes. Vulkan timestamps (#3086) and the full clock range (#3162) each make it much more frequent, because both raise the submission rate and keep the command pool full.
The cause is the lifetime of pool commands. The firmware keeps a pool slot on a list while it has stamp stores queued for it, and each queued record names the retired command's JobMeta (stamp pointer, value, slot). The pass that unlinks a slot clears the word the driver reads as "registered", and only after that does it read the records. The driver reused a slot as soon as it was retired and unregistered, zeroing and re-encoding its command at once. So the firmware could read a zero or half-written stamp pointer and store through it.
The fix gives each slot two command buffers and uses them in turn. A retired command stays intact while its slot's next command runs. Its buffer is rewritten only after the slot has been retired and unlinked again, which the firmware does in a later pass than the one that read the old records. The slot moves to its other buffer only once a command is published, so a failed publication can't overwrite the last published one (Dj's review).
The same rows exposed a second defect, a rare pool stall. The firmware keeps a slot listed until the slot's cursor equals the number of records it counted, and it can count one more record for a retired slot after we advanced the cursor. We advanced it only once, so slots stayed listed until none were free. The free-slot search now re-advances the cursor of a free but still-listed slot. With the old command kept intact, the earlier unlink is safe. A stall report (per-slot record count, cursor, list flag) stays for any future stall. No parameter, gate or delay.
Tested
g14_v27_2_abi.rs): 9/9 pass, including a property test that a slot never rewrites the command it used last and slots never share a buffer.Risk
Risk: two-way · M2 mini J473 (G14G firmware 27.2). A plain revert undoes it. Low, and local to the G14 27.2 command pool (
gpu/v27_2.rs), which T8103 on 27.2 (#3171) also uses. The cost is 192 KiB more firmware-private memory. Slot choice, retirement and the stall timeout are unchanged. Other GPU generations use separate pools; G16 already requires a later retirement before reuse.Not yet
Evidence
Crash signature, the same in every dump on main and on the first two attempts below: ESR 0x96000044 (write), FAR 0 (once 0x0000ffa800000000). The faulting address register holds the stamp pointer read from the queued record, and x0 is the record. The record always sits at the same page offset, which is a compute command's JobMeta at the pool's 0x80 heap alignment.
Two earlier attempts did not fix it, and both rows are kept:
Both crashed at the same site within 2 runs.
Main-without-fix matrix (GB6 Vulkan, J473): combo18 9/10 runs, combo19 6/9, main with drm/asahi: give the G14 27.2 firmware its power data and run the full GPU range #3162 reverted 2/3, main with timestamps refused + full range 0/1, main with neither feature 6/6.
Row directories: traces/gpu/20261125-m2gpu-next/ on the lab store (gb6x-a1b, gb6x-a2, gb6x-s2, gb6x-s2b, gb6x-m1, earlier gb6x-*), one README per row.