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
93 changes: 67 additions & 26 deletions drivers/gpu/drm/asahi/g17/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ pub(super) fn service<H: Host>(
report_clients(host, request.generation, &entries, request.blamed);

let (listed, exact, fallback) = (entries.listed, entries.exact, entries.fallback);
let (cancelled, blame, leftover, charged) =
let (cancelled, blamed_error, leftover, charged) =
classify(host, entries, request.blamed, attribution, request.generation);
if listed != 0 && host.is_m5() {
// The M5 table only classifies (read_entries): each command is retired from its own
Expand All @@ -414,10 +414,14 @@ pub(super) fn service<H: Host>(
"G17: GPU recovery (reason {:?}): firmware blamed queue {}, {}\n",
sources.firmware_reason(),
qid,
if blame { "failing its oldest render" } else { "attribution cleared it; spared" }
match blamed_error {
None => "attribution cleared it; spared",
Some(error) if error == EIO => "failing its oldest render",
Some(_) => "unconfirmed: discarding its oldest render",
}
);
if blame {
host.settle_blamed_render(qid, EIO);
if let Some(error) = blamed_error {
host.settle_blamed_render(qid, error);
}
}
if cancelled != 0 {
Expand Down Expand Up @@ -515,9 +519,12 @@ fn read_entries<H: Host>(host: &mut H) -> Entries {
/// that landed on a starved bystander would leave the real culprit's spared work immune: never
/// guilty, never poisoned, never forgiven and never killed, until the restart storm limit
/// (2026-11-19 19:12 UTC, 2026-11-20 15:03 UTC).
/// Also returns whether the firmware's blamed QID is still guilty after attribution: a blamed
/// render that had not started while others had (or with no culprit at all) is innocent, and its
/// work is spared like that of every other innocent VM instead of failing with EIO.
/// Also returns the error the firmware's blamed render fails with. None when attribution cleared
/// it: a blamed render that had not started while others had (or with no culprit at all) is
/// innocent, and its work is spared like that of every other innocent VM. ECANCELED when the
/// blame is collateral: the render is discarded and never replayed, and, as for every command a
/// recovery discards, its client is not told (`Completion::report`), so a bystander blamed once
/// keeps its device. EIO when evidence or a repeat confirms the blame, or ownership is unknown.
/// Then whether every guilty VM had failed before this restart and it dropped one of their
/// commands: a failed VM publishes nothing new, so such restarts end with its queued work.
/// Last, whether the restart is charged to the guilty VMs ([`VmStatus::charge_restart`], with
Expand All @@ -530,7 +537,7 @@ fn classify<Q: Queues>(
blamed: Option<u8>,
attribution: Attribution,
generation: u64,
) -> (u128, bool, bool, bool) {
) -> (u128, Option<Error>, bool, bool) {
let mut guilty_qids = entries.guilty | blamed.map_or(0, |qid| 1u128 << qid);
let cancelled = entries.cancelled;
match attribution {
Expand All @@ -544,9 +551,12 @@ fn classify<Q: Queues>(
// 01:46 UTC, m4.179: t3code, then Hyprland), and a slow innocent render can be the oldest
// running one, so the first such blame is collateral and only a repeat makes the VM guilty.
let unconfirmed = matches!(attribution, Attribution::Firmware | Attribution::Suspects(_));
let blame = blamed.is_some_and(|qid| guilty_qids & (1u128 << qid) != 0);
let blamed_error = |collateral: u128| {
blamed.filter(|&qid| guilty_qids & (1u128 << qid) != 0)
.map(|qid| if collateral & (1u128 << qid) != 0 { ECANCELED } else { EIO })
};
if guilty_qids == 0 && !no_culprit {
return (0, blame, false, false);
return (0, blamed_error(0), false, false);
}
let mut guilty: [Option<Arc<VmStatus>>; MAX_GUILTY_VMS] = Default::default();
let mut count = 0;
Expand Down Expand Up @@ -595,7 +605,7 @@ fn classify<Q: Queues>(
}
}
if unresolved || (count == 0 && collateral == 0 && !no_culprit) {
return (0, blame, false, false);
return (0, blamed_error(0), false, false);
}
for qid in (0..QIDS).filter(|qid| collateral & (1u128 << qid) != 0) {
queues.note_collateral(qid, generation);
Expand Down Expand Up @@ -635,7 +645,7 @@ fn classify<Q: Queues>(
let charged = count != 0 && guilty[..count].iter().zip(&held).fold(true, |charged, (status, held)| {
status.as_ref().is_some_and(|status| status.charge_restart(held.get())) && charged
});
(cancelled & !(guilty_qids & !collateral) & spared, blame, leftover, charged)
(cancelled & !(guilty_qids & !collateral) & spared, blamed_error(collateral), leftover, charged)
}


Expand Down Expand Up @@ -947,8 +957,9 @@ mod tests {
/// last recovery gave its work (`Pair::classify`) and its collateral mark
/// (`Pair::note_collateral`), which a retirement of its work clears. A blamed render fails as
/// `settle_blamed_render` fails it: guilty work poisons its VM, work an earlier recovery
/// spared fails without poisoning it (`Completion::poisons`), and work that failed already
/// is not failed again.
/// spared fails without poisoning it (`Completion::poisons`) and, discarded as collateral,
/// without reaching its client (`Completion::report`), and work that failed already is not
/// failed again.
struct Cascade([Option<CascadePair>; 4], u64);

impl Cascade {
Expand Down Expand Up @@ -1002,8 +1013,12 @@ mod tests {
let entries = Entries { exact_qids: dropped, ..Entries::default() };
self.1 += 1;
let generation = self.1;
let (_, blame, leftover, _) = classify(self, entries, Some(blamed), attribution, generation);
// The listed commands fail: a guilty VM's poison it, others' are discarded.
let (_, blamed_error, leftover, _) = classify(self, entries, Some(blamed), attribution, generation);
// The blamed render fails first, inside `service`; the listed commands fail after the
// firmware resumes: a guilty VM's poison it, others' are discarded.
if let Some(error) = blamed_error {
self.settle_blamed_render(blamed, error);
}
for pair in self.0.iter_mut().flatten() {
if !pair.failed && pair.qids.iter().any(|qid| dropped & (1u128 << qid) != 0) {
if pair.class == Some(Class::Guilty) {
Expand All @@ -1012,9 +1027,6 @@ mod tests {
pair.failed = true;
}
}
if blame {
self.settle_blamed_render(blamed, EIO);
}
leftover
}
}
Expand Down Expand Up @@ -1058,7 +1070,10 @@ mod tests {
}
pair.failed = true;
if pair.class == Some(Class::Spared) {
pair.status.report_failure(error);
// A discarded command stays out of the status, as `Completion::report` keeps it.
if error != ECANCELED {
pair.status.report_failure(error);
}
} else {
pair.class = Some(Class::Guilty);
pair.status.record(error);
Expand Down Expand Up @@ -1109,16 +1124,17 @@ mod tests {
queues.restart(41, 1 << 41);
assert!(c.recovery_guilty());
queues.restart(45, 1 << 45);
assert!(!b.recovery_guilty() && b.get() == 0);
assert!(!b.recovery_guilty() && b.get() == 0 && b.reported_error() == 0);
// b's next command retires: blamed again, it is collateral again, its VM unpoisoned.
queues.retire(44);
queues.restart(45, 1 << 45);
assert!(!b.recovery_guilty() && b.get() == 0);
// Blamed a third time with nothing retired since: guilty. Its client already saw a
// lost device at each blame; now its VM is poisoned too.
assert!(!b.recovery_guilty() && b.get() == 0 && b.reported_error() == 0);
// Blamed a third time with nothing retired since: guilty. Only now does its client see
// a lost device, and its VM is poisoned.
queues.restart(45, 1 << 45);
assert!(b.recovery_guilty());
assert_ne!(b.get(), 0);
assert_ne!(b.reported_error(), 0);
}

#[test]
Expand Down Expand Up @@ -1276,11 +1292,36 @@ mod tests {
counted += usize::from(!queues.restart(101, 1 << 101));
assert!(deqp.recovery_guilty() && deqp.get() != 0);
assert!(queues.restart(101, 1 << 101));
assert!(!t3code.recovery_guilty() && t3code.get() == 0);
assert!(!hyprland.recovery_guilty() && hyprland.get() == 0);
assert!(!t3code.recovery_guilty() && t3code.get() == 0 && t3code.reported_error() == 0);
assert!(!hyprland.recovery_guilty() && hyprland.get() == 0 && hyprland.reported_error() == 0);
assert_eq!(counted, 4);
}

#[test]
fn the_m4_201_gen_8_bystander_keeps_its_device() {
// 2026-11-28 23:46:02 UTC (m4.201, storm chain, gen 8, reason 0): deqp-vk's memory_model
// spin (14/15, 32 groups in flight in gens 8 and 9) hangs beside t3code (40/41),
// quickshell (46/47) and other deqp-vk clients. No slot keys, no MMU fault, and the
// oldest running render had other VMs' compute beside it, so only the firmware named a
// queue: t3code's 41, whose tiler had started, flagged guilty and cancelled. Its oldest
// render failed with EIO and t3code saw a lost device. Gen 9 then blamed deqp-vk's 11.
let (deqp, t3code, quickshell, other) = (vm(), vm(), vm(), vm());
let mut queues =
Cascade::new([([14, 15], &deqp), ([40, 41], &t3code), ([46, 47], &quickshell), ([10, 11], &other)]);
queues.restart(41, (1 << 15) | (1 << 41) | (1 << 47) | (1 << 11));
// The blamed render is discarded, never replayed, and t3code keeps its device.
assert!(!t3code.recovery_guilty() && t3code.get() == 0 && t3code.reported_error() == 0);
queues.submit(40);
queues.restart(11, (1 << 15) | (1 << 11));
assert!(!other.recovery_guilty() && other.get() == 0 && other.reported_error() == 0);
assert!(t3code.reported_error() == 0 && quickshell.reported_error() == 0);
// The mark stays: blamed again with nothing of it retired, t3code's VM is guilty and
// its client is told.
queues.restart(41, 1 << 41);
assert!(t3code.recovery_guilty());
assert_ne!(t3code.reported_error(), 0);
}

#[test]
fn unknown_25g83_keys_still_preserve_firmware_blame() {
let mut host = Halted::new(false);
Expand Down
6 changes: 3 additions & 3 deletions drivers/gpu/drm/asahi/g17/runtime/render/settle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ impl crate::g17::Firmware {
.and_then(|pair| pair.oldest_packet());
if let Some(packet) = packet {
// Unclassified work counts as innocent, and a blamed group must never be replayed.
// Work an earlier recovery spared is collateral here (classify() blames before its
// collateral check) and stays spared, so its failure stays non-sticky; the blame
// itself is recorded apart from the class, and refuses any replay of it.
// Collateral work stays spared: its failure stays non-sticky, and with ECANCELED
// (`recovery::classify`) its client is not told. The blame itself is recorded apart
// from the class, and refuses any replay of it.
packet.completion.note_blamed();
if !packet.completion.spared() {
packet.completion.classify(crate::g17::recovery::Class::Guilty);
Expand Down
Loading