From d07e60facdc8a706e4c2f9092b6da60cbbbe13b0 Mon Sep 17 00:00:00 2001 From: Tyler Smith <74526874+tylertms@users.noreply.github.com> Date: Wed, 18 Nov 2026 04:01:39 -0500 Subject: [PATCH] fix(gpu): a GPU that stops answering is followed by one line naming the recovery its port still allows, none when the port is gone too, else a secondary bus reset through it and a new driver start, or why the fabric would refuse that reset, where the log did not say whether any recovery was possible --- crates/stela-boot-core/src/gpu_loss.rs | 77 ++++++++++++++++++- crates/stela-boot/src/engine/gpu/link.rs | 47 ++++++++++- .../config_space/containment/bus_reset.rs | 25 ++++-- 3 files changed, 136 insertions(+), 13 deletions(-) diff --git a/crates/stela-boot-core/src/gpu_loss.rs b/crates/stela-boot-core/src/gpu_loss.rs index 5913cb91e5..a8220fe516 100644 --- a/crates/stela-boot-core/src/gpu_loss.rs +++ b/crates/stela-boot-core/src/gpu_loss.rs @@ -31,12 +31,15 @@ const SILENT: &str = ": stopped answering"; /// (nouveau's `nvkm_device_gone`). const ANSWERS_AGAIN: &str = ": answers again"; +/// [`link_event`]'s name for a GPU that stopped answering. +pub const STOPPED_ANSWERING: &str = "stopped answering"; + /// What a kernel driver's `line` says of its GPU's link, as the boot log /// names it beside the port's view: that it stopped answering, or that it /// answered again after a silence; `None` for any other line. pub fn link_event(line: &str) -> Option<&'static str> { if line.contains(SILENT) { - Some("stopped answering") + Some(STOPPED_ANSWERING) } else if line.contains(ANSWERS_AGAIN) { Some("answered again after a silence") } else { @@ -44,6 +47,54 @@ pub fn link_event(line: &str) -> Option<&'static str> { } } +/// Which recovery the port above a GPU that stopped answering still +/// allows, for one boot-log line. Stela tries none of them: the session +/// ends at the GPU's first failed reopen. +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum Recovery { + /// The port could not be read. + Unknown, + /// The port above does not answer either. + PortGone, + /// The port answers and a secondary bus reset through it is possible. + BusReset { port: String, link_up: bool }, + /// The port answers, but the fabric would refuse the bus reset. + NoBusReset { why: &'static str, link_up: bool }, +} + +impl core::fmt::Display for Recovery { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let link = |up: bool| { + if up { + "its link is up" + } else { + "its link is down" + } + }; + match self { + Self::Unknown => f.write_str("unknown: the port above it is not read"), + Self::PortGone => f.write_str( + "none from here: the port above it does not answer either, so the power or the \ + platform took the whole link, which no reset Stela can make reaches", + ), + Self::BusReset { port, link_up } => write!( + f, + "possible by a secondary bus reset through port {port} ({}) and a new start of \ + its driver and its GPU firmware, as Linux's AER recovery resets a bus (nouveau \ + has no error handler, so Linux does not restart it); Stela does not try it and \ + the session ends", + link(*link_up) + ), + Self::NoBusReset { why, link_up } => write!( + f, + "none bounded: the port answers ({}), but a secondary bus reset through it is \ + refused: {why}", + link(*link_up) + ), + } + } +} + /// A GPU that serves Metal, as [`verdict`] reads it. #[derive(Clone, Copy, Debug)] pub struct Gpu<'a> { @@ -319,4 +370,28 @@ mod tests { assert!(cut.observe("amdgpu 0000:03:00.0: stopped answering: é")); assert!(cut.of("0000:03:00.0").expect("kept").ends_with(": ")); } + + #[test] + fn a_silent_gpus_recovery_line_says_what_the_port_still_allows() { + assert!(format!("{}", Recovery::PortGone).starts_with("none from here")); + let reset = Recovery::BusReset { + port: String::from("0000:00:01.1"), + link_up: false, + }; + let line = format!("{reset}"); + assert!(line.starts_with("possible by a secondary bus reset through port 0000:00:01.1")); + assert!(line.contains("its link is down")); + let refused = Recovery::NoBusReset { + why: "another driver claimed a function on the PCI function's bus", + link_up: true, + }; + assert!( + format!("{refused}") + .ends_with("refused: another driver claimed a function on the PCI function's bus") + ); + assert_eq!( + link_event("nouveau 0000:01:00.0: stopped answering"), + Some(STOPPED_ANSWERING) + ); + } } diff --git a/crates/stela-boot/src/engine/gpu/link.rs b/crates/stela-boot/src/engine/gpu/link.rs index 0e49cd378c..9c39b50c53 100644 --- a/crates/stela-boot/src/engine/gpu/link.rs +++ b/crates/stela-boot/src/engine/gpu/link.rs @@ -3,9 +3,10 @@ //! boot log, both ends' ASPM, Clock Power Management, LTR and L1 PM //! Substates as the firmware left them and after the claim's reset, and the //! port's view when the GPU stops answering or answers again, which tells a -//! link that went down from a port that lost power with it. The port is -//! read through a read-only mapping of its configuration kept for the boot; -//! only the substates are written, through the fabric that owns the port. +//! link that went down from a port that lost power with it, with the +//! recovery the port still allows. The port is read through a read-only +//! mapping of its configuration kept for the boot; only the substates are +//! written, through the fabric that owns the port. use crate::{native_mmio, output}; use alloc::{format, string::String}; use stela_drivers::bus::pci::{ @@ -16,6 +17,8 @@ use stela_drivers::bus::pci::{ /// fabric that owns it. pub(in crate::engine) struct Port { address: Address, + #[cfg_attr(not(feature = "nvk"), allow(dead_code, reason = "asked at a loss"))] + gpu: Address, config: ObservedConfig, source: &'static native_mmio::Source, } @@ -56,6 +59,7 @@ pub(in crate::engine) fn port_above( match unsafe { ObservedConfig::attach(bridge, window, mapping) } { Ok(config) => Some(Port { address: bridge, + gpu: address, config, source: mmio, }), @@ -112,9 +116,44 @@ pub(in crate::engine) unsafe fn set_substates( /// `GPU ; port
`: what the port above /// a GPU whose driver said `event` of it reads now, which tells whether the -/// port and its link are still up. +/// port and its link are still up, and, when it stopped answering, which +/// recovery the port still allows. #[cfg(feature = "nvk")] pub(in crate::engine) fn log_port_at(name: &str, event: &str, port: Option<&Port>) { let above = port.map_or_else(|| String::from("no port above it is read"), Port::report); output::arguments(format_args!("GPU {name} {event}; {above}\n")); + if event == stela_boot_core::gpu_loss::STOPPED_ANSWERING { + let recovery = match port { + None => stela_boot_core::gpu_loss::Recovery::Unknown, + Some(port) => port.recovery(), + }; + output::arguments(format_args!("GPU {name} recovery: {recovery}\n")); + } +} + +#[cfg(feature = "nvk")] +impl Port { + /// Which recovery the port allows now: none when it does not answer + /// either, else a secondary bus reset through it if the fabric would + /// make one, else why not. + fn recovery(&self) -> stela_boot_core::gpu_loss::Recovery { + use stela_boot_core::gpu_loss::Recovery; + let end = match link_report::read(&self.config) { + Ok(end) => end, + Err(_) => return Recovery::Unknown, + }; + if !end.answers() { + return Recovery::PortGone; + } + let link_up = end + .express + .is_some_and(|express| express.link_status & (1 << 13) != 0); + match self.source.parent_bus_reset_refusal(self.gpu) { + None => Recovery::BusReset { + port: format!("{}", self.address), + link_up, + }, + Some(why) => Recovery::NoBusReset { why, link_up }, + } + } } diff --git a/crates/stela-boot/src/native_mmio/shared/config_space/containment/bus_reset.rs b/crates/stela-boot/src/native_mmio/shared/config_space/containment/bus_reset.rs index bb83f8c2fa..d76d97e0cd 100644 --- a/crates/stela-boot/src/native_mmio/shared/config_space/containment/bus_reset.rs +++ b/crates/stela-boot/src/native_mmio/shared/config_space/containment/bus_reset.rs @@ -138,18 +138,27 @@ impl Source { /// Whether [`Self::reset_parent_bus`] would find a bus it may reset for /// the cold requester at `address`. Reads only. pub(crate) fn parent_bus_reset_available(&self, address: Address) -> bool { + self.parent_bus_reset_refusal(address).is_none() + } + + /// Why [`Self::reset_parent_bus`] would refuse the cold requester at + /// `address` now; `None` when it would find a bus it may reset. Reads + /// only. + pub(crate) fn parent_bus_reset_refusal(&self, address: Address) -> Option<&'static str> { let Ok(cohort) = self.pci_slots.0.try_borrow() else { - return false; + return Some("the PCI fabric is busy"); }; let Cohort::Parked(fabric) = &*cohort else { - return false; + return Some("the PCI fabric is not contained"); }; - members(fabric, address).is_ok_and(|(parent, _)| { - fabric.slots[parent] - .forwarding - .as_ref() - .is_some_and(|forwarding| forwarding.check().is_ok()) - }) + let (parent, _) = match members(fabric, address) { + Ok(members) => members, + Err(why) => return Some(why), + }; + match &fabric.slots[parent].forwarding { + Some(forwarding) if forwarding.check().is_ok() => None, + _ => Some("the bridge's forwarding changed"), + } } /// Set the L1 PM Substates of the link above the cold requester at