From a4e1852dc19d684090a6f988fecae2ede5db262f Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Wed, 2 Dec 2026 20:12:05 -0500 Subject: [PATCH] drm/asahi: g16: fail unfinished renders on a failed render's pair At the phase-1 halt of a firmware recovery, g16 fails every flight the firmware's affected-work snapshot names, and every unfinished flight of the VM whose fault is latched. Any other unfinished render is only suspect: it still retires on its ordinary receipt after the resume. That receipt does not prove the render ran. On the J773g under macOS 26B123, a render command buffer queued behind one that hung never ran (no GPU time, no fragments), yet after the one recovery its notifier record had counted all of its works, held its last FS work and was unlinked, and the FS service stamp had moved to its target: what a normal completion writes. Metal fails such a buffer as an innocent victim. A hang latches no fault, and a render of another VM on the same TA and FS queues is not of the faulting VM, so g16 can report success for render work that never ran. Fail every render flight that is unfinished at the halt on the TA and FS queue pair of a failed render, whatever its VM. Renders on other pairs and compute keep their rule. The publication selftest covers a render of another VM unfinished at the halt on the failed render's pair, with and without a latched fault, on another pair, a recovery that fails no render, and renders that finished before the halt. Signed-off-by: DjDeveloperr --- drivers/gpu/drm/asahi/g16/engine.rs | 37 ++++++++++++++----- .../drivers/gpu/asahi-m4/test-publication.py | 35 +++++++++++++++++- 2 files changed, 61 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/asahi/g16/engine.rs b/drivers/gpu/drm/asahi/g16/engine.rs index 90c3f360c2411..89d751ec786a7 100644 --- a/drivers/gpu/drm/asahi/g16/engine.rs +++ b/drivers/gpu/drm/asahi/g16/engine.rs @@ -1075,6 +1075,11 @@ impl Firmware { /// A command unfinished when recovery started may have been aborted without appearing /// in the snapshot. Keep it until either its full receipt or its passed-abort proof. + /// + /// A render unfinished at the halt on a failed render's queue pair fails as well, + /// whatever its VM. While it recovers, the firmware completes the notifier records of the + /// render work it aborts as if that work had finished, and moves the service stamps to its + /// targets, so no later receipt proves that the render ran. pub(crate) fn recovery_prepare_suspects( &mut self, stage: [u32; sizes::STAGES], @@ -1087,21 +1092,21 @@ impl Firmware { self.engine.ta_target, self.engine.fs_target, ); + let render_unfinished = |renders: u32, ta: u32, fs: u32, pair: usize| { + renders != 0 + && (!reached(stage[sizes::render_stage(pair, 0)], ta, ta_target[pair]) + || !reached(stage[sizes::render_stage(pair, 1)], fs, fs_target[pair])) + }; + // The queue pairs of the renders this recovery fails. + let mut failed_pairs = 0u32; // Every unfinished flight, including compute queued behind the oldest on either pipe. for f in self.engine.flights.iter_mut() { let pipe = (f.compute_pipe as usize).min(sizes::COMPUTE_PIPES - 1); let pair = (f.render_pair as usize).min(sizes::RENDER_PAIRS - 1); + // `recovery_prepare` failed the flights the snapshot names. + let mut failed = f.doomed && f.recovery_suspect; let unfinished = (f.computes != 0 && !reached(stage[2 + pipe], f.target, target[pipe])) - || (f.renders != 0 - && (!reached( - stage[sizes::render_stage(pair, 0)], - f.ta_target, - ta_target[pair], - ) || !reached( - stage[sizes::render_stage(pair, 1)], - f.fs_target, - fs_target[pair], - ))); + || render_unfinished(f.renders, f.ta_target, f.fs_target, pair); if unfinished { f.recovery_suspect = true; f.recovery_started_ns = now_ns(); @@ -1109,8 +1114,20 @@ impl Firmware { f.unsettled_polls = 0; if fault_asid.is_some_and(|asid| asid >= 1 && asid == f.job.vm.slot) { f.doomed = true; + failed = true; } } + if failed && f.renders != 0 { + failed_pairs |= 1 << pair; + } + } + for f in self.engine.flights.iter_mut() { + let pair = (f.render_pair as usize).min(sizes::RENDER_PAIRS - 1); + if failed_pairs & (1 << pair) != 0 + && render_unfinished(f.renders, f.ta_target, f.fs_target, pair) + { + f.doomed = true; + } } Ok(()) } diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py b/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py index 5464950cbc937..5aed24cc251db 100644 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-publication.py @@ -2762,7 +2762,9 @@ def item(declaration): assert!(!fw.engine.flights[1].doomed); assert!(fw.engine.flights[1].recovery_suspect); - // Two co-resident cross-VM renders: VM 1 faults on FS 0x100 while VM 2 has live render 0x200. + // Two co-resident cross-VM renders: VM 1 faults on FS 0x100 while VM 2 has live render + // 0x200 on the same queue pair. The firmware may complete VM 2's unfinished render + // without running it, so that render fails as well. let mut r2_ta = [0u32; 16]; let mut r2_fs = [0u32; 16]; r2_ta[0] = 0x200; r2_fs[0] = 0x200; @@ -2791,6 +2793,37 @@ def item(declaration): assert_eq!(fw.recovery_prepare(1, 0x71, 0x100, st(0x200, 0, 0, 0)), Ok(())); assert_eq!(fw.recovery_prepare_suspects(st(0x200, 0, 0, 0), 0x71, Some(1)), Ok(())); assert!(fw.engine.flights[0].doomed); + assert!(fw.engine.flights[1].doomed); + assert!(fw.engine.flights[1].recovery_suspect); + let reset = |fw: &mut RecFirmware| for f in fw.engine.flights.iter_mut() { + f.doomed = false; + f.recovery_suspect = false; + }; + // The same with no fault latched (a hang): the snapshot names VM 1's render. + reset(&mut fw); + assert_eq!(fw.recovery_prepare(1, 0x71, 0x100, st(0x200, 0, 0, 0)), Ok(())); + assert_eq!(fw.recovery_prepare_suspects(st(0x200, 0, 0, 0), 0x71, None), Ok(())); + assert!(fw.engine.flights[0].doomed); + assert!(fw.engine.flights[1].doomed); + // A render of another VM that finished before the halt is neither suspect nor failed. + reset(&mut fw); + assert_eq!(fw.recovery_prepare_suspects(st(0x200, 0x200, 0, 0), 0x71, Some(1)), Ok(())); + assert!(!fw.engine.flights[0].recovery_suspect); + assert!(!fw.engine.flights[1].recovery_suspect); + assert!(!fw.engine.flights[1].doomed); + // No render failed: an unfinished render stays suspect until its receipt. + reset(&mut fw); + assert_eq!(fw.recovery_prepare_suspects(st(0, 0, 0, 0), 15, None), Ok(())); + assert!(fw.engine.flights[0].recovery_suspect && !fw.engine.flights[0].doomed); + assert!(fw.engine.flights[1].recovery_suspect && !fw.engine.flights[1].doomed); + // An unfinished render on another queue pair stays suspect too. + reset(&mut fw); + fw.engine.flights[1].render_pair = 1; + fw.engine.ta_target[1] = 0x200; + fw.engine.fs_target[1] = 0x200; + assert_eq!(fw.recovery_prepare(1, 0x71, 0x100, st(0x200, 0, 0, 0)), Ok(())); + assert_eq!(fw.recovery_prepare_suspects(st(0x200, 0, 0, 0), 0x71, Some(1)), Ok(())); + assert!(fw.engine.flights[0].doomed); assert!(!fw.engine.flights[1].doomed); assert!(fw.engine.flights[1].recovery_suspect); }