From dc5e27e60a18f95c569d0ee8eb458ed0ab225bb5 Mon Sep 17 00:00:00 2001 From: Phoebus Date: Wed, 23 Sep 2026 06:05:27 -0700 Subject: [PATCH] fix(nvidia): deterministic live GPU decision, nouveau fallback and fail-safe The live load script previously modprobed the NVIDIA stack for any PCI vendor 0x10de and the build required etc/modprobe.d/phoebus-nvidia.conf that nothing created. Replace the vendor-name check with a deterministic decision computed from the actual display controllers and the bundled branch's capabilities: - phoebus-core gains live_nvidia_plan(): supported GPU -> load the bundled accelerated stack; unsupported GPU -> explicit nouveau fallback; no GPU -> leave auto-detection; fail-safe -> load nothing. - phoebus-installer --live-gpu-plan scans sysfs (overridable for tests) and prints stable key=value lines; probe_nvidia_display_devices() only considers display-class NVIDIA functions. - phoebus-nvidia-load consults it, falls back to nouveau on an unsupported GPU or a failed accelerated load, and never fails the unit; the service honours phoebus.nvidia=off. - build.sh now creates the live modprobe policy, replaces Debian's unconditional nouveau blacklist, and marks the fail-safe entry. --- .../crates/phoebus-core/src/nvidia.rs | 240 ++++++++++++++++++ .../crates/phoebus-core/src/system.rs | 79 ++++-- .../crates/phoebus-executor/src/probe.rs | 65 +++++ .../crates/phoebus-installer/src/main.rs | 48 ++++ .../phoebus-installer/tests/cli_coverage.rs | 60 +++++ installer/live/build.sh | 17 +- 6 files changed, 486 insertions(+), 23 deletions(-) diff --git a/installer-rs/crates/phoebus-core/src/nvidia.rs b/installer-rs/crates/phoebus-core/src/nvidia.rs index 1ab51a2..2164f9b 100644 --- a/installer-rs/crates/phoebus-core/src/nvidia.rs +++ b/installer-rs/crates/phoebus-core/src/nvidia.rs @@ -54,6 +54,13 @@ pub const LIVE_PROPRIETARY_KMOD: &str = "nvidia-kernel-dkms"; /// The Debian package that builds the open kernel module (Turing+ only). pub const LIVE_OPEN_KMOD: &str = "nvidia-open-kernel-dkms"; +/// The newest NVIDIA generation the bundled live branch can drive. +/// +/// Debian's live branch is `550.163.01`, which predates Blackwell (RTX 50xx); +/// it covers Maxwell through Hopper. The live driver decision is therefore +/// bounded by the branch, not by the installed-system policy. +pub const LIVE_BRANCH_MAX_GENERATION: NvidiaGeneration = NvidiaGeneration::Hopper; + /// NVIDIA GPU architecture generation, derived from the PCI device ID. #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] @@ -122,6 +129,26 @@ impl NvidiaGeneration { _ => NvidiaSupport::Open, } } + + /// Whether NVIDIA's open kernel modules are the only choice for this + /// generation. Blackwell cannot be driven by the proprietary kernel + /// modules; Gentoo states `kernel-open` is *required* for 50xx and newer. + pub fn requires_open_modules(self) -> bool { + matches!(self, NvidiaGeneration::Blackwell) + } + + /// Whether this generation can only be served by the proprietary modules. + pub fn requires_proprietary_modules(self) -> bool { + self.support() == NvidiaSupport::Proprietary + } + + /// Whether the bundled live branch (Debian 550) can drive this generation. + /// + /// This is deliberately branch-scoped: a generation the live branch cannot + /// drive must fall back to `nouveau`, never be claimed as accelerated. + pub fn supported_by_live_branch(self) -> bool { + self.support() != NvidiaSupport::Unsupported && self <= LIVE_BRANCH_MAX_GENERATION + } } /// How an NVIDIA generation is served. @@ -166,6 +193,11 @@ pub struct NvidiaDevice { } impl NvidiaDevice { + /// Classify a probed display device into an NVIDIA device. + pub fn from_gpu(gpu: &GpuInfo) -> NvidiaDevice { + nvidia_device(gpu) + } + /// Whether the device is claimed by the selected proprietary/open driver. pub fn is_supported(&self) -> bool { self.generation @@ -471,6 +503,161 @@ fn nvidia_device(gpu: &GpuInfo) -> NvidiaDevice { } } +/// The action the live medium takes before the graphical session starts. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "kebab-case")] +pub enum LiveNvidiaAction { + /// No NVIDIA display device: leave the in-tree drivers to auto-detect. + NoDevice, + /// Fail-safe graphics requested: do not load NVIDIA at all. + Disabled, + /// Every NVIDIA display device is served by the bundled branch. + LoadNvidia, + /// At least one NVIDIA display device is not served: bind `nouveau`. + NouveauFallback, +} + +impl LiveNvidiaAction { + pub fn as_str(self) -> &'static str { + match self { + LiveNvidiaAction::NoDevice => "no-device", + LiveNvidiaAction::Disabled => "disabled", + LiveNvidiaAction::LoadNvidia => "load-nvidia", + LiveNvidiaAction::NouveauFallback => "nouveau-fallback", + } + } +} + +/// The live medium's display-driver decision, computed from the actual PCI +/// display devices and the capabilities of the bundled branch. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct LiveNvidiaPlan { + pub action: LiveNvidiaAction, + /// The module flavor to load, when the accelerated stack is selected. + pub flavor: Option, + /// Kernel modules the load script must modprobe, in dependency order. + pub modules: Vec<&'static str>, + /// Every probed NVIDIA display device. + pub devices: Vec, + /// Devices the bundled branch cannot serve (the `nouveau` set). + pub unclaimed: Vec, + pub reason: String, +} + +impl LiveNvidiaPlan { + /// A stable `key=value` rendering consumed by `phoebus-nvidia-load`. + pub fn render(&self) -> String { + let mut o = String::new(); + o.push_str(&format!("action={}\n", self.action.as_str())); + if let Some(flavor) = self.flavor { + o.push_str(&format!("flavor={}\n", flavor.as_str())); + } + if !self.modules.is_empty() { + o.push_str(&format!("modules={}\n", self.modules.join(" "))); + } + for device in &self.devices { + o.push_str(&format!( + "device={} {}\n", + device.pci_id, + device + .generation + .map(|g| g.as_str()) + .unwrap_or("unknown") + )); + } + for device in &self.unclaimed { + o.push_str(&format!( + "unclaimed={} {}\n", + device.pci_id, + device + .generation + .map(|g| g.as_str()) + .unwrap_or("unknown") + )); + } + o.push_str(&format!("reason={}\n", self.reason)); + o + } +} + +/// Decide the live medium's display-driver action. +/// +/// `fail_safe` is true when the kernel command line requests fail-safe graphics +/// (`nomodeset` or `phoebus.nvidia=off`); recovery intent is authoritative, so +/// no NVIDIA module is loaded in that case even though the service is armed. +pub fn live_nvidia_plan(devices: &[NvidiaDevice], fail_safe: bool) -> LiveNvidiaPlan { + if fail_safe { + return LiveNvidiaPlan { + action: LiveNvidiaAction::Disabled, + flavor: None, + modules: Vec::new(), + devices: devices.to_vec(), + unclaimed: Vec::new(), + reason: "fail-safe graphics requested (nomodeset or phoebus.nvidia=off); \ + not loading the NVIDIA stack" + .into(), + }; + } + if devices.is_empty() { + return LiveNvidiaPlan { + action: LiveNvidiaAction::NoDevice, + flavor: None, + modules: Vec::new(), + devices: Vec::new(), + unclaimed: Vec::new(), + reason: "no NVIDIA display device detected".into(), + }; + } + let unclaimed: Vec = devices + .iter() + .filter(|d| { + !d.generation + .map(|g| g.supported_by_live_branch()) + .unwrap_or(false) + }) + .cloned() + .collect(); + if unclaimed.is_empty() { + LiveNvidiaPlan { + action: LiveNvidiaAction::LoadNvidia, + // The live branch is the proprietary Debian build; the open + // modules have not been shown to build against the pinned live + // kernel, so the accelerated stack loaded at boot is the bundled + // proprietary one. + flavor: Some(NvidiaModuleFlavor::Proprietary), + modules: vec!["nvidia", "nvidia_modeset", "nvidia_uvm", "nvidia_drm"], + devices: devices.to_vec(), + unclaimed: Vec::new(), + reason: format!( + "all {} NVIDIA display device(s) are supported by the bundled live branch", + devices.len() + ), + } + } else { + let names: Vec = unclaimed + .iter() + .map(|d| { + format!( + "{} ({})", + d.pci_id, + d.generation.map(|g| g.as_str()).unwrap_or("unknown") + ) + }) + .collect(); + LiveNvidiaPlan { + action: LiveNvidiaAction::NouveauFallback, + flavor: None, + modules: Vec::new(), + devices: devices.to_vec(), + unclaimed, + reason: format!( + "the bundled live branch cannot drive {}; using the in-tree nouveau driver", + names.join(", ") + ), + } + } +} + /// Parse `vendor:device` (hex) into `(vendor, device)`. pub fn parse_pci_pair(value: &str) -> Option<(u16, u16)> { let (vendor, device) = value.split_once(':')?; @@ -626,4 +813,57 @@ mod tests { assert_eq!(parse_pci_pair("10de:2482"), Some((0x10de, 0x2482))); assert_eq!(parse_pci_pair("zzzz"), None); } + + #[test] + fn live_branch_support_is_bounded_before_blackwell() { + assert!(NvidiaGeneration::Maxwell.supported_by_live_branch()); + assert!(NvidiaGeneration::Hopper.supported_by_live_branch()); + assert!(!NvidiaGeneration::Blackwell.supported_by_live_branch()); + assert!(!NvidiaGeneration::Kepler.supported_by_live_branch()); + assert!(NvidiaGeneration::Blackwell.requires_open_modules()); + assert!(!NvidiaGeneration::Ada.requires_open_modules()); + assert!(NvidiaGeneration::Pascal.requires_proprietary_modules()); + } + + #[test] + fn live_plan_loads_the_stack_only_for_supported_devices() { + let supported = NvidiaDevice::from_gpu(&nvidia("10de:2482", "GA104 [GeForce RTX 3070]")); + let plan = live_nvidia_plan(&[supported], false); + assert_eq!(plan.action, LiveNvidiaAction::LoadNvidia); + assert!(plan.modules.contains(&"nvidia_drm")); + assert!(plan.render().contains("action=load-nvidia")); + + let blackwell = NvidiaDevice::from_gpu(&nvidia("10de:2b85", "GB202 [GeForce RTX 5090]")); + let plan = live_nvidia_plan(&[blackwell], false); + assert_eq!(plan.action, LiveNvidiaAction::NouveauFallback); + assert_eq!(plan.unclaimed.len(), 1); + assert!(plan.render().contains("action=nouveau-fallback")); + } + + #[test] + fn live_plan_falls_back_when_one_of_several_devices_is_unsupported() { + let devices = vec![ + NvidiaDevice::from_gpu(&nvidia("10de:2482", "GA104 [GeForce RTX 3070]")), + NvidiaDevice::from_gpu(&nvidia("10de:2b85", "GB202 [GeForce RTX 5090]")), + ]; + let plan = live_nvidia_plan(&devices, false); + assert_eq!(plan.action, LiveNvidiaAction::NouveauFallback); + assert_eq!(plan.unclaimed.len(), 1); + } + + #[test] + fn live_plan_is_disabled_on_the_fail_safe_entry() { + let device = NvidiaDevice::from_gpu(&nvidia("10de:2482", "GA104 [GeForce RTX 3070]")); + let plan = live_nvidia_plan(&[device], true); + assert_eq!(plan.action, LiveNvidiaAction::Disabled); + assert!(plan.modules.is_empty()); + assert!(plan.reason.contains("fail-safe")); + } + + #[test] + fn live_plan_with_no_nvidia_device_does_nothing() { + let plan = live_nvidia_plan(&[], false); + assert_eq!(plan.action, LiveNvidiaAction::NoDevice); + assert_eq!(plan.render().lines().next(), Some("action=no-device")); + } } diff --git a/installer-rs/crates/phoebus-core/src/system.rs b/installer-rs/crates/phoebus-core/src/system.rs index 599f6e6..2b848ea 100644 --- a/installer-rs/crates/phoebus-core/src/system.rs +++ b/installer-rs/crates/phoebus-core/src/system.rs @@ -1190,28 +1190,55 @@ pub fn default_session_command(profile: DesktopProfile) -> &'static str { pub const LIVE_USER: &str = "phoebus"; /// `phoebus-nvidia-load`: live-only. It runs before the graphical session and -/// loads NVIDIA's accelerated stack only when an NVIDIA display device is -/// present, so systems without one keep the in-tree driver and never record a -/// failed unit. +/// asks the installer for a deterministic decision based on the actual PCI +/// display devices and the bundled branch's capabilities. Systems without an +/// NVIDIA GPU keep the in-tree driver; an unsupported GPU explicitly binds +/// `nouveau`; fail-safe graphics loads nothing. A failed accelerated load is a +/// fallback, never a failed unit. pub const PHOEBUS_NVIDIA_LOAD_SCRIPT: &str = r#"#!/bin/bash -# Load the NVIDIA accelerated driver on the live medium, but only when an -# NVIDIA display controller is actually present. nouveau is blacklisted by -# nvidia-kernel-common, so nothing else claims the GPU first. Debian's -# nvidia-kernel-dkms names the modules nvidia-current*, and its modprobe -# `install` directives map the upstream names used below. +# Select the live medium's display driver before greetd/Mango starts. +# +# `phoebus-installer --live-gpu-plan` classifies every PCI display controller +# and compares it with the bundled branch, then prints: +# action=load-nvidia -> load the bundled accelerated stack +# action=nouveau-fallback-> explicitly bind the in-tree nouveau driver +# action=no-device -> no NVIDIA GPU; leave auto-detection alone +# action=disabled -> fail-safe boot; load no NVIDIA module +# +# `blacklist nouveau` in /etc/modprobe.d stops nouveau *auto-binding* a +# supported GPU; it does not block an explicit `modprobe nouveau`, which is +# exactly what the fallback path uses. Debian's nvidia-kernel-dkms maps the +# upstream module names used here onto nvidia-current*. set -u -if ! grep -lq 0x10de /sys/bus/pci/devices/*/vendor 2>/dev/null; then - echo "phoebus-nvidia: no NVIDIA display device; leaving the in-tree driver in charge" - exit 0 -fi -if ! modprobe nvidia-drm; then - echo "phoebus-nvidia: could not load nvidia-drm; run phoebus-gpu-report" >&2 - exit 1 -fi -# Unified memory is a soft dependency; a failure here is not fatal for the -# desktop but is reported. -modprobe nvidia-uvm || echo "phoebus-nvidia: nvidia-uvm did not load" >&2 -echo "phoebus-nvidia: NVIDIA modules loaded" +BIN=/usr/local/bin/phoebus-installer + +log() { logger -t phoebus-nvidia -- "$*" 2>/dev/null || true; } + +plan="$("$BIN" --live-gpu-plan 2>/dev/null || true)" +action="$(printf '%s\n' "$plan" | sed -n 's/^action=//p' | head -n1)" + +case "$action" in + load-nvidia) + if modprobe nvidia-drm; then + modprobe nvidia-uvm || log "nvidia-uvm did not load (not fatal)" + log "loaded the NVIDIA accelerated driver: $(printf '%s' "$plan" | tr '\n' ';')" + exit 0 + fi + log "NVIDIA initialisation failed; falling back to nouveau" + modprobe nouveau || log "nouveau did not load either; run phoebus-gpu-report" + ;; + nouveau-fallback) + log "NVIDIA GPU is not supported by the bundled branch; using nouveau: $(printf '%s' "$plan" | tr '\n' ';')" + modprobe nouveau || log "nouveau did not load; run phoebus-gpu-report" + ;; + disabled) + log "fail-safe graphics requested; not loading the NVIDIA stack" + ;; + *) + log "no NVIDIA display device; leaving driver auto-detection in charge" + ;; +esac +exit 0 "#; /// `phoebus-nvidia.service`: load the driver before greetd/Mango. @@ -1220,6 +1247,9 @@ Description=Load the NVIDIA accelerated driver (Phoebus live) Documentation=man:nvidia(4) After=systemd-modules-load.service Before=display-manager.service greetd.service +# Recovery intent is authoritative: the fail-safe entry sets +# phoebus.nvidia=off, so the unit does not even run there. +ConditionKernelCommandLine=!phoebus.nvidia=off [Service] Type=oneshot @@ -1911,10 +1941,15 @@ mod tests { #[test] fn live_nvidia_assets_are_bounded_and_ordered_before_greetd() { let load = desktop_asset("nvidia-load").unwrap(); - assert!(load.contains("0x10de")); - assert!(load.contains("modprobe nvidia")); + // The decision comes from the installer, not a vendor-name grep. + assert!(load.contains("--live-gpu-plan")); + assert!(load.contains("nouveau-fallback")); + assert!(load.contains("modprobe nvidia-drm")); + // A failed accelerated load must not fail the boot unit. + assert!(!load.contains("exit 1")); let service = desktop_asset("nvidia-service").unwrap(); assert!(service.contains("Before=display-manager.service greetd.service")); + assert!(service.contains("ConditionKernelCommandLine=!phoebus.nvidia=off")); assert!(service.contains("ExecStart=/usr/local/bin/phoebus-nvidia-load")); let report = desktop_asset("gpu-report").unwrap(); assert!(report.contains("nvidia-smi")); diff --git a/installer-rs/crates/phoebus-executor/src/probe.rs b/installer-rs/crates/phoebus-executor/src/probe.rs index 297b883..04ae97a 100644 --- a/installer-rs/crates/phoebus-executor/src/probe.rs +++ b/installer-rs/crates/phoebus-executor/src/probe.rs @@ -5,6 +5,7 @@ //! independent of `run_cmd`). use std::collections::HashMap; +use std::path::Path; use phoebus_core::disk::{Disk, DiskKind}; use phoebus_core::hardware::{ @@ -236,6 +237,48 @@ pub fn probe_hardware(runner: &dyn ProcessRunner) -> HardwareReport { } } +/// Enumerate NVIDIA display controllers from sysfs. +/// +/// `sysfs` is normally `/sys`; it is a parameter so the live driver decision +/// can be exercised against a fixture without root or the real machine's +/// hardware. Only display-class functions (`class >> 16 == 0x03`: VGA, 3D and +/// Display controllers) from vendor `0x10de` are returned. +pub fn probe_nvidia_display_devices(sysfs: &Path) -> Vec { + let mut out = Vec::new(); + let dir = sysfs.join("bus/pci/devices"); + let Ok(entries) = std::fs::read_dir(&dir) else { + return out; + }; + for entry in entries.flatten() { + let base = entry.path(); + let read = |name: &str| -> Option { + std::fs::read_to_string(base.join(name)) + .ok() + .map(|s| s.trim().to_string()) + }; + let (Some(class), Some(vendor), Some(device)) = (read("class"), read("vendor"), read("device")) + else { + continue; + }; + let parse = |s: &str| u32::from_str_radix(s.trim_start_matches("0x"), 16).ok(); + let (Some(class), Some(vendor), Some(device)) = (parse(&class), parse(&vendor), parse(&device)) + else { + continue; + }; + if (class >> 16) != 0x03 || vendor != 0x10de { + continue; + } + out.push(GpuInfo { + vendor: GpuVendor::Nvidia, + description: format!("NVIDIA display controller {vendor:04x}:{device:04x}"), + pci_id: Some(format!("{vendor:04x}:{device:04x}")), + pci_address: Some(entry.file_name().to_string_lossy().to_string()), + }); + } + out.sort_by(|a, b| a.pci_id.cmp(&b.pci_id)); + out +} + // --------------------------------------------------------------------------- // Disks // --------------------------------------------------------------------------- @@ -557,4 +600,26 @@ mod tests { (None, Some("00:00.0".into())) ); } + + #[test] + fn sysfs_scan_finds_only_nvidia_display_controllers() { + let dir = tempfile::tempdir().unwrap(); + let devices = dir.path().join("bus/pci/devices"); + let write = |addr: &str, class: &str, vendor: &str, device: &str| { + let d = devices.join(addr); + std::fs::create_dir_all(&d).unwrap(); + std::fs::write(d.join("class"), class).unwrap(); + std::fs::write(d.join("vendor"), vendor).unwrap(); + std::fs::write(d.join("device"), device).unwrap(); + }; + write("0000:01:00.0", "0x030000", "0x10de", "0x2482"); + // NVIDIA's HDA audio function on the same card is not a display device. + write("0000:01:00.1", "0x040300", "0x10de", "0x228b"); + // An Intel display controller is left to the in-tree driver. + write("0000:00:02.0", "0x030000", "0x8086", "0x9a60"); + let found = probe_nvidia_display_devices(dir.path()); + assert_eq!(found.len(), 1); + assert_eq!(found[0].pci_id.as_deref(), Some("10de:2482")); + assert_eq!(found[0].pci_address.as_deref(), Some("0000:01:00.0")); + } } diff --git a/installer-rs/crates/phoebus-installer/src/main.rs b/installer-rs/crates/phoebus-installer/src/main.rs index dad4b76..fb7d972 100644 --- a/installer-rs/crates/phoebus-installer/src/main.rs +++ b/installer-rs/crates/phoebus-installer/src/main.rs @@ -134,6 +134,21 @@ struct Cli { #[arg(long, value_name = "FLAVOR", hide = true)] nvidia_flavor: Option, + /// Print the live medium's display-driver decision as stable `key=value` + /// lines and exit. Consumed by the live-only `phoebus-nvidia-load` + /// service; the decision comes from the actual PCI display devices and the + /// bundled branch's capabilities, never from a vendor-name match. + #[arg(long, hide = true)] + live_gpu_plan: bool, + + /// Override the sysfs root used by `--live-gpu-plan` (fixtures/testing). + #[arg(long, value_name = "PATH", hide = true)] + sysfs_root: Option, + + /// Override the kernel command line used by `--live-gpu-plan`. + #[arg(long, value_name = "CMDLINE", hide = true)] + kernel_cmdline: Option, + /// Speak the typed JSON protocol used by the graphical installer frontend /// (stdin/stdout). Not intended for direct interactive use. #[arg(long, hide = true)] @@ -212,6 +227,35 @@ fn verify_live_nvidia_command(cli: &Cli, rootfs: &std::path::Path) -> ExitCode { } } +/// Print the live medium's display-driver decision as stable `key=value` lines. +/// +/// This is the single authority the live-only `phoebus-nvidia-load` service +/// consults. It is deterministic, read-only and outside the AI boundary: the +/// action follows the actual PCI display devices and the bundled branch, and +/// fail-safe graphics (`nomodeset` / `phoebus.nvidia=off`) always wins. +fn live_gpu_plan_command(cli: &Cli) -> ExitCode { + let sysfs = cli + .sysfs_root + .clone() + .unwrap_or_else(|| PathBuf::from("/sys")); + let cmdline = cli + .kernel_cmdline + .clone() + .or_else(|| std::fs::read_to_string("/proc/cmdline").ok()) + .unwrap_or_default(); + let fail_safe = cmdline + .split_whitespace() + .any(|tok| tok == "nomodeset" || tok == "phoebus.nvidia=off"); + let gpus = phoebus_executor::probe::probe_nvidia_display_devices(&sysfs); + let devices: Vec = gpus + .iter() + .map(phoebus_core::nvidia::NvidiaDevice::from_gpu) + .collect(); + let plan = phoebus_core::nvidia::live_nvidia_plan(&devices, fail_safe); + print!("{}", plan.render()); + ExitCode::SUCCESS +} + struct TerminalConfirm; impl Confirmation for TerminalConfirm { @@ -545,6 +589,10 @@ fn run() -> std::result::Result> { }; } + if cli.live_gpu_plan { + return Ok(live_gpu_plan_command(&cli)); + } + if let Some(rootfs) = &cli.verify_live_nvidia { return Ok(verify_live_nvidia_command(&cli, rootfs)); } diff --git a/installer-rs/crates/phoebus-installer/tests/cli_coverage.rs b/installer-rs/crates/phoebus-installer/tests/cli_coverage.rs index cd6db84..5993ba3 100644 --- a/installer-rs/crates/phoebus-installer/tests/cli_coverage.rs +++ b/installer-rs/crates/phoebus-installer/tests/cli_coverage.rs @@ -132,6 +132,66 @@ fn verify_live_nvidia_accepts_a_complete_payload_and_rejects_an_incomplete_one() assert_eq!(out.status.code(), Some(1)); } +#[test] +fn live_gpu_plan_reflects_the_fixture_and_the_fail_safe_cmdline() { + fn write_device(root: &std::path::Path, addr: &str, class: &str, vendor: &str, device: &str) { + let d = root.join("bus/pci/devices").join(addr); + std::fs::create_dir_all(&d).unwrap(); + std::fs::write(d.join("class"), class).unwrap(); + std::fs::write(d.join("vendor"), vendor).unwrap(); + std::fs::write(d.join("device"), device).unwrap(); + } + let run = |sysfs: &std::path::Path, cmdline: &str| -> String { + let out = Command::new(env!("CARGO_BIN_EXE_phoebus-installer")) + .arg("--live-gpu-plan") + .arg("--sysfs-root") + .arg(sysfs) + .arg("--kernel-cmdline") + .arg(cmdline) + .output() + .expect("run --live-gpu-plan"); + assert!(out.status.success()); + String::from_utf8_lossy(&out.stdout).into_owned() + }; + + let supported = tempfile::tempdir().unwrap(); + write_device( + supported.path(), + "0000:01:00.0", + "0x030000", + "0x10de", + "0x2482", + ); + let plan = run(supported.path(), "quiet splash"); + assert!(plan.contains("action=load-nvidia"), "{plan}"); + assert!(plan.contains("device=10de:2482 Ampere"), "{plan}"); + + // Blackwell cannot be driven by the bundled 550 branch. + let blackwell = tempfile::tempdir().unwrap(); + write_device( + blackwell.path(), + "0000:01:00.0", + "0x030000", + "0x10de", + "0x2b85", + ); + let plan = run(blackwell.path(), ""); + assert!(plan.contains("action=nouveau-fallback"), "{plan}"); + assert!(plan.contains("unclaimed=10de:2b85 Blackwell"), "{plan}"); + + // Fail-safe graphics wins even with a supported GPU present. + let plan = run(supported.path(), "quiet nomodeset"); + assert!(plan.contains("action=disabled"), "{plan}"); + let plan = run(supported.path(), "quiet phoebus.nvidia=off"); + assert!(plan.contains("action=disabled"), "{plan}"); + + // No NVIDIA display device -> leave auto-detection alone. + let none = tempfile::tempdir().unwrap(); + write_device(none.path(), "0000:00:02.0", "0x030000", "0x8086", "0x9a60"); + let plan = run(none.path(), ""); + assert!(plan.contains("action=no-device"), "{plan}"); +} + #[test] fn relocated_opencode_manifest_is_pinned_and_complete() { let path = manifest_path(); diff --git a/installer/live/build.sh b/installer/live/build.sh index e310d7d..6797061 100755 --- a/installer/live/build.sh +++ b/installer/live/build.sh @@ -270,6 +270,21 @@ ln -sf /usr/lib/systemd/system/phoebus-nvidia.service \ # with no NVIDIA GPU that can leave a failed unit, so remove it and rely on the # gated service above (which is a no-op without an NVIDIA display device). rm -f "$rootfs/etc/modules-load.d/nvidia.conf" +# The live module policy. nouveau is blacklisted so it cannot *auto-bind* a GPU +# the accelerated stack is meant to drive; the load script explicitly modprobes +# nouveau for an unsupported GPU (a blacklist only suppresses alias-based +# auto-loading). Debian's own nvidia-kernel-common file is replaced so its +# unconditional nouveau options cannot defeat that fallback, and the file the +# payload verifier checks is produced here rather than only on the installed +# Gentoo target. +rm -f "$rootfs/etc/modprobe.d/nvidia-blacklists-nouveau.conf" +install -d -m 0755 "$rootfs/etc/modprobe.d" +cat > "$rootfs/etc/modprobe.d/phoebus-nvidia.conf" <<'NVIDIA' +# NVIDIA accelerated graphics on the Phoebus live medium (generated at build). +blacklist nouveau +options nvidia_drm modeset=1 +softdep nvidia post: nvidia-uvm +NVIDIA # Build-time gate: the assembled rootfs (cached or fresh) MUST carry a complete # NVIDIA payload for its exact kernel, or the build fails. This also writes @@ -437,7 +452,7 @@ t = t.replace('menuentry "Live system (amd64 fail-safe mode)"', # entry is unaffected. This is a recovery path, not the default. t = t.replace( 'nosplash vga=788', - 'nosplash vga=788 nomodeset ' + 'nosplash vga=788 nomodeset phoebus.nvidia=off ' 'modprobe.blacklist=nvidia,nvidia_modeset,nvidia_uvm,nvidia_drm') open(p, "w").write(t) PY