Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions drivers/gpu/drm/asahi/g16/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,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],
Expand All @@ -1090,30 +1095,42 @@ 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();
f.gate_passed_ns = None;
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(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2894,7 +2894,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;
Expand Down Expand Up @@ -2923,6 +2925,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);
}
Expand Down
Loading