From f4ec0b785161caa56a99f2bba2fef6156cf084c1 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Thu, 26 Nov 2026 10:48:38 +1100 Subject: [PATCH 1/4] drm/asahi: keep a G14 27.2 pool command intact until its slot is reused 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 --- drivers/gpu/drm/asahi/g14_v27_2_abi.rs | 31 ++++++++++++++++++++++++++ drivers/gpu/drm/asahi/gpu/v27_2.rs | 18 +++++++++++---- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/asahi/g14_v27_2_abi.rs b/drivers/gpu/drm/asahi/g14_v27_2_abi.rs index 313607d3a6c70..bb89a2ed6eeb8 100644 --- a/drivers/gpu/drm/asahi/g14_v27_2_abi.rs +++ b/drivers/gpu/drm/asahi/g14_v27_2_abi.rs @@ -146,11 +146,42 @@ pub(crate) fn encode_compute_timestamps(cmd: &mut [u8], cmd_va: u64, timestamps: user_timestamp_pointer(cmd_va + COMPUTE_USER_TIMESTAMPS as u64, timestamps) } +/// The command buffer a pool slot uses: each slot owns two, `2 * slot` and `2 * slot + 1`, +/// and alternates between them. The firmware may still read a retired command's JobMeta for +/// stamp stores it queued after it unlinked the slot, so a slot's next command must not +/// overwrite it. +pub(crate) fn pool_command(slot: usize, second: bool) -> usize { + 2 * slot + usize::from(second) +} + #[cfg_attr(not(test), kunit_tests(asahi_g14_fw_queues))] #[cfg_attr(test, allow(dead_code))] mod tests { use super::*; + #[test] + fn a_slot_never_rewrites_the_command_it_used_last() { + const SLOTS: usize = 48; + let mut owner = [usize::MAX; 2 * SLOTS]; + let mut alternate = 0u64; + let mut last = [usize::MAX; SLOTS]; + for round in 0..5 { + for slot in 0..SLOTS { + alternate ^= 1 << slot; + let c = pool_command(slot, alternate & (1 << slot) != 0); + assert!(c < 2 * SLOTS); + // Two buffers per slot, never shared with another slot. + assert!(owner[c] == usize::MAX || owner[c] == slot); + owner[c] = slot; + // Consecutive uses of a slot take different buffers. + if round > 0 { + assert_ne!(c, last[slot]); + } + last[slot] = c; + } + } + } + #[test] fn head_wraps_and_keeps_one_entry_free() { assert_eq!(queue_head(8, 7, 7, 2), Ok(1)); diff --git a/drivers/gpu/drm/asahi/gpu/v27_2.rs b/drivers/gpu/drm/asahi/gpu/v27_2.rs index fc1514c61a8e4..ef33c1eea5ffe 100644 --- a/drivers/gpu/drm/asahi/gpu/v27_2.rs +++ b/drivers/gpu/drm/asahi/gpu/v27_2.rs @@ -477,7 +477,10 @@ const COMMAND_STRIDE: usize = 0x1000; const STREAM_STRIDE: usize = 0x400; pub(crate) struct CommandPool { + /// Two command buffers per slot, used in turn (`g14_v27_2_abi::pool_command`). commands: fw::types::GpuArray, + /// Which of its two command buffers each slot used last, one bit per slot. + alternate: u64, streams: fw::types::GpuArray, tracking: fw::types::GpuArray, cursors: fw::types::GpuArray, @@ -487,7 +490,7 @@ pub(crate) struct CommandPool { impl CommandPool { pub(crate) fn new(alloc: &mut KernelAllocators, cfg: &'static hw::HwConfig) -> Result { - let commands = alloc.private.array_empty::(POOL_SLOTS * COMMAND_STRIDE)?; + let commands = alloc.private.array_empty::(2 * POOL_SLOTS * COMMAND_STRIDE)?; let streams = alloc.private.array_empty::(POOL_SLOTS * STREAM_STRIDE)?; let mut tracking = alloc.private.array_empty::(POOL_SLOTS * 0x100)?; // One 64-byte line per retirement cursor, so no firmware write can reach a neighbour. @@ -498,7 +501,8 @@ impl CommandPool { put64(chunk, 0, base + 0x40 * i as u64); } crate::pgtable::clean_poc(tracking.as_slice().as_ptr(), tracking.as_slice().len()); - Ok(Self { commands, streams, tracking, cursors, stamps, preempt1: cfg.compute_preempt1_size as u64 }) + Ok(Self { commands, alternate: 0, streams, tracking, cursors, stamps, + preempt1: cfg.compute_preempt1_size as u64 }) } /// Builds slot `i` for `job` and returns the command's firmware VA. @@ -516,7 +520,13 @@ impl CommandPool { encode: impl FnOnce(&mut [u8], &mut [u8], crate::g14_v27_2_render::Common) -> Result, ) -> Result { if i >= POOL_SLOTS { return Err(EINVAL); } - let cmd_va = self.commands.gpu_va().get() + (i * COMMAND_STRIDE) as u64; + // The firmware may read a retired command's JobMeta after it has unlinked the slot + // (for the stamp stores it still has queued), so the next command of the slot goes + // to the slot's other buffer. A buffer is rewritten only after the slot has been + // retired and unlinked once more, which the firmware does in a later pass. + self.alternate ^= 1 << i; + let c = g14_v27_2_abi::pool_command(i, self.alternate & (1 << i) != 0); + let cmd_va = self.commands.gpu_va().get() + (c * COMMAND_STRIDE) as u64; let stream_va = self.streams.gpu_va().get() + (i * STREAM_STRIDE) as u64; let tracking_va = self.tracking.gpu_va().get() + (i * 0x100) as u64; let timestamps_va = self.stamps.gpu_va().get() + (i * 0x80) as u64; @@ -526,7 +536,7 @@ impl CommandPool { let stamps = &mut self.stamps.as_mut_slice()[i * 0x80..(i + 1) * 0x80]; stamps.fill(0); crate::pgtable::clean_poc(stamps.as_ptr(), stamps.len()); - let cmd = &mut self.commands.as_mut_slice()[i * COMMAND_STRIDE..(i + 1) * COMMAND_STRIDE]; + let cmd = &mut self.commands.as_mut_slice()[c * COMMAND_STRIDE..(c + 1) * COMMAND_STRIDE]; cmd.fill(0); let stream = &mut self.streams.as_mut_slice()[i * STREAM_STRIDE..(i + 1) * STREAM_STRIDE]; stream.fill(0); From 27e52f68bb19c24b665cc4557ff77cacc461868d Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Thu, 26 Nov 2026 13:24:08 +1100 Subject: [PATCH 2/4] drm/asahi: report G14 27.2 pool slot state when the pool stalls 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 --- drivers/gpu/drm/asahi/g14_v27_2.rs | 11 ++++++++++- drivers/gpu/drm/asahi/gpu/v27_2.rs | 12 ++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/asahi/g14_v27_2.rs b/drivers/gpu/drm/asahi/g14_v27_2.rs index 68ee7faa50efc..ed4c281443bbc 100644 --- a/drivers/gpu/drm/asahi/g14_v27_2.rs +++ b/drivers/gpu/drm/asahi/g14_v27_2.rs @@ -666,7 +666,16 @@ impl Runtime { Ok(Some(slots)) => slots, Ok(None) => return, Err(err) => { - dev_err!(self.dev, "GPU: command pool stalled: {:?}\n", err); + dev_err!(self.dev, "GPU: command pool stalled: {:?} busy={:#x} unacked={:#x} inflight={} rendering={}\n", + err, state.busy, state.unacked, state.inflight.len(), state.rendering.is_some()); + for slot in 0..POOL_SLOTS { + if let Ok((count, cursor, linked)) = state.pool.describe(slot) { + if linked != 0 || count != cursor { + dev_err!(self.dev, "GPU: slot {}: records={} cursor={} linked={}\n", + slot, count, cursor, linked); + } + } + } self.fail_all(state, err); return; } diff --git a/drivers/gpu/drm/asahi/gpu/v27_2.rs b/drivers/gpu/drm/asahi/gpu/v27_2.rs index ef33c1eea5ffe..1759e7fb4262b 100644 --- a/drivers/gpu/drm/asahi/gpu/v27_2.rs +++ b/drivers/gpu/drm/asahi/gpu/v27_2.rs @@ -570,6 +570,18 @@ impl CommandPool { Ok(true) } + /// Slot `i`'s record count (+0xc), its retirement cursor and whether the firmware still + /// holds it in the queue's tracking list (+0x94), for a stall report. + pub(crate) fn describe(&self, i: usize) -> Result<(u32, u32, u32)> { + if i >= POOL_SLOTS { return Err(EINVAL); } + crate::pgtable::clean_invalidate_poc(self.tracking.as_slice()[i * 0x100..].as_ptr(), 0x100); + crate::pgtable::clean_invalidate_poc(self.cursors.as_slice()[i * 0x40..].as_ptr(), 0x40); + crate::pgtable::poc_barrier(); + Ok((self.tracking.shared_index(i * 0x100 + 0xc)?.load(Ordering::Acquire), + self.cursors.shared_index(i * 0x40)?.load(Ordering::Acquire), + self.tracking.shared_index(i * 0x100 + 0x94)?.load(Ordering::Acquire))) + } + /// Whether the firmware still holds slot `i` in the queue's tracking list (+0x94). pub(crate) fn registered(&self, i: usize) -> Result { if i >= POOL_SLOTS { return Err(EINVAL); } From 890aa2614a21afbb8c5dd726039f8e1d42aa32fb Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Thu, 26 Nov 2026 14:06:49 +1100 Subject: [PATCH 3/4] drm/asahi: move a G14 27.2 pool slot to its other buffer only on publication 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 Signed-off-by: Ryan Murray --- drivers/gpu/drm/asahi/g14_v27_2.rs | 4 ++++ drivers/gpu/drm/asahi/g14_v27_2_abi.rs | 26 ++++++++++++++++++-------- drivers/gpu/drm/asahi/gpu/v27_2.rs | 23 +++++++++++++++-------- 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/asahi/g14_v27_2.rs b/drivers/gpu/drm/asahi/g14_v27_2.rs index ed4c281443bbc..7bde3c145f6eb 100644 --- a/drivers/gpu/drm/asahi/g14_v27_2.rs +++ b/drivers/gpu/drm/asahi/g14_v27_2.rs @@ -724,6 +724,7 @@ impl Runtime { publication_error: None, started: Instant::now(), _bind: bind }, GFP_KERNEL)?; packet.mark_published(); submission.publish(); + state.pool.mark_published(slot); state.last = stamp; state.sequence += 1; state.unacked &= !(1 << slot); @@ -784,6 +785,9 @@ impl Runtime { // Queue the fragment dependency before kicking the tiler that satisfies it. fs_post.publish(); ta_post.publish(); + for slot in slots { + state.pool.mark_published(slot); + } for slot in slots { state.busy |= 1 << slot; state.unacked &= !(1 << slot); diff --git a/drivers/gpu/drm/asahi/g14_v27_2_abi.rs b/drivers/gpu/drm/asahi/g14_v27_2_abi.rs index bb89a2ed6eeb8..816539f3580b1 100644 --- a/drivers/gpu/drm/asahi/g14_v27_2_abi.rs +++ b/drivers/gpu/drm/asahi/g14_v27_2_abi.rs @@ -154,29 +154,39 @@ pub(crate) fn pool_command(slot: usize, second: bool) -> usize { 2 * slot + usize::from(second) } +/// Whether slot `slot`'s next command goes to its second buffer: the one it did not last +/// publish, given one bit per slot set when the last published command used the second. +/// Encoding does not change the bits, so a command that is encoded but never published is +/// replaced in the same spare buffer. +pub(crate) fn spare_buffer(published: u64, slot: usize) -> bool { + published & (1 << slot) == 0 +} + #[cfg_attr(not(test), kunit_tests(asahi_g14_fw_queues))] #[cfg_attr(test, allow(dead_code))] mod tests { use super::*; #[test] - fn a_slot_never_rewrites_the_command_it_used_last() { + fn a_slot_never_rewrites_the_command_it_published_last() { const SLOTS: usize = 48; let mut owner = [usize::MAX; 2 * SLOTS]; - let mut alternate = 0u64; + let mut published = 0u64; let mut last = [usize::MAX; SLOTS]; - for round in 0..5 { + for round in 0..6 { for slot in 0..SLOTS { - alternate ^= 1 << slot; - let c = pool_command(slot, alternate & (1 << slot) != 0); + let c = pool_command(slot, spare_buffer(published, slot)); assert!(c < 2 * SLOTS); // Two buffers per slot, never shared with another slot. assert!(owner[c] == usize::MAX || owner[c] == slot); owner[c] = slot; - // Consecutive uses of a slot take different buffers. - if round > 0 { - assert_ne!(c, last[slot]); + // Never the buffer the slot last published. + assert_ne!(c, last[slot]); + // Every third slot's publication fails once: the retry takes the same spare. + if (slot + round) % 3 == 0 { + assert_eq!(pool_command(slot, spare_buffer(published, slot)), c); } + published ^= 1 << slot; last[slot] = c; } } diff --git a/drivers/gpu/drm/asahi/gpu/v27_2.rs b/drivers/gpu/drm/asahi/gpu/v27_2.rs index 1759e7fb4262b..4d16adc052a95 100644 --- a/drivers/gpu/drm/asahi/gpu/v27_2.rs +++ b/drivers/gpu/drm/asahi/gpu/v27_2.rs @@ -479,8 +479,8 @@ const STREAM_STRIDE: usize = 0x400; pub(crate) struct CommandPool { /// Two command buffers per slot, used in turn (`g14_v27_2_abi::pool_command`). commands: fw::types::GpuArray, - /// Which of its two command buffers each slot used last, one bit per slot. - alternate: u64, + /// Which of its two command buffers each slot last published, one bit per slot. + published: u64, streams: fw::types::GpuArray, tracking: fw::types::GpuArray, cursors: fw::types::GpuArray, @@ -501,7 +501,7 @@ impl CommandPool { put64(chunk, 0, base + 0x40 * i as u64); } crate::pgtable::clean_poc(tracking.as_slice().as_ptr(), tracking.as_slice().len()); - Ok(Self { commands, alternate: 0, streams, tracking, cursors, stamps, + Ok(Self { commands, published: 0, streams, tracking, cursors, stamps, preempt1: cfg.compute_preempt1_size as u64 }) } @@ -521,11 +521,12 @@ impl CommandPool { ) -> Result { if i >= POOL_SLOTS { return Err(EINVAL); } // The firmware may read a retired command's JobMeta after it has unlinked the slot - // (for the stamp stores it still has queued), so the next command of the slot goes - // to the slot's other buffer. A buffer is rewritten only after the slot has been - // retired and unlinked once more, which the firmware does in a later pass. - self.alternate ^= 1 << i; - let c = g14_v27_2_abi::pool_command(i, self.alternate & (1 << i) != 0); + // (for the stamp stores it still has queued), so the slot's next command goes to its + // other buffer. A buffer is rewritten only after the slot has been retired and + // unlinked once more, which the firmware does in a later pass. Encoding always + // takes the spare; `published` moves it only once the firmware can see the command, + // so a publication that fails leaves the last published buffer alone. + let c = g14_v27_2_abi::pool_command(i, g14_v27_2_abi::spare_buffer(self.published, i)); let cmd_va = self.commands.gpu_va().get() + (c * COMMAND_STRIDE) as u64; let stream_va = self.streams.gpu_va().get() + (i * STREAM_STRIDE) as u64; let tracking_va = self.tracking.gpu_va().get() + (i * 0x100) as u64; @@ -550,6 +551,12 @@ impl CommandPool { Ok(cmd_va) } + /// Slot `i`'s command, encoded in its spare buffer, is now visible to the firmware: the + /// next encode of the slot takes the other buffer. + pub(crate) fn mark_published(&mut self, i: usize) { + if i < POOL_SLOTS { self.published ^= 1 << i; } + } + /// Retirement: advance slot `i`'s cursor to the value the firmware recorded at /// tracking +0xc, so its retirement scan unlinks the slot from the queue's list. /// From 1015e9c61f02fe095b0ff9b49d0a76214277004e Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Thu, 26 Nov 2026 14:22:42 +1100 Subject: [PATCH 4/4] drm/asahi: re-advance a listed G14 27.2 pool slot's cursor before skipping 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 --- drivers/gpu/drm/asahi/g14_v27_2.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/gpu/drm/asahi/g14_v27_2.rs b/drivers/gpu/drm/asahi/g14_v27_2.rs index 7bde3c145f6eb..5a59faa3be813 100644 --- a/drivers/gpu/drm/asahi/g14_v27_2.rs +++ b/drivers/gpu/drm/asahi/g14_v27_2.rs @@ -627,6 +627,11 @@ impl Runtime { let slot = (state.next_slot + k) % POOL_SLOTS; if state.busy & (1 << slot) != 0 { continue; } if state.pool.registered(slot)? { + // The firmware can count another record for a retired slot after its cursor + // was advanced, and keeps the slot listed until the cursor matches again: + // advance it to the current count. The slot's last command stays intact in + // its buffer, so an early unlink is harmless. + state.pool.retire(slot)?; state.skipped += 1; continue; }