interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

Fix GB10 UEFI PCI discovery: shared root-bridge open plus failure diagnostics in the report

merged 2fc8e589409b4194 #56 · opened 2026-09-24 12:47 UTC · closed 2026-09-24 14:00 UTC · merged 2026-09-24 14:00 UTC

Imported from GitHub aien-dev/aienux#56, by Copilot

Base a1babb4d25544b9b5ab4becd4ba97cf45f42a2c9 · Head 2758b38960f9ce297ca458accf17e5b7aac839eb

Merged on GitHub as 79d2d00518af1c2bcd272a6ad25787f6a0aa3189; reachable from main d01b2f19cccf3e173a6bdb3541813d467f537a76 (observed 2026-11-18T16:35:40Z)

Copilot wrote on 2026-09-24 12:47 UTC

$ bash scripts/verify_all.sh      # Spark (aarch64), head e03b49c; 2758b38 changes docs only
test result: ok (all workspace suites, incl. diagnostics_report_refused_opens_segments_and_bar_state)
PASS  image is this commit / left firmware and entered the kernel / pre-exit report printed
PASS  final report on the SPCR console / no panic or fault
PASS  swTPM live boot reached kernel alive and final report
PASS  Soak run 1/3, 2/3, 3/3: clean boot & reset
PASS  Corrupted binary cleanly rejected by firmware without reaching kernel alive
PASS  Recovery banner displayed / 100% RAM disk verified / Internal NVMe confirmed unmounted
rc=0

The first native boot reported gb10: unavailable even though Linux sees 10de:2e12 at 000f:01:00.0. Leading hypothesis (unconfirmed on hardware until the next native boot): discover_gb10 opened PciRootBridgeIo exclusively, which firmware refuses with ACCESS_DENIED while its PCI bus driver holds the protocol ByDriver — every root bridge was silently skipped. This PR fixes the open mode and records why discovery failed (bridges seen, opens refused, segments, BAR state) in the boot reports. Characterization only: no GPU initialization or commands.

Changes

crates/aienos-boot/src/handoff.rs

  • Open PciRootBridgeIo shared (GetProtocol) instead of exclusively — the same pattern this file already uses for the GOP console. Only reads are performed, which is safe while boot services run.
  • Keep the Config A fast path (segment 15, bus 1, dev 0, fn 0), then walk every bus in each root bridge's firmware-declared bus range, falling back to the root bus when no range is published (same coverage as the old enumerate(), but observable).
  • Return a bounded Gb10Discovery record alongside the identity; on failure its lines are written to both the pre-exit report (BOOTREPORT.TXT + console) and the post-exit firmware-variable report:
gb10: unavailable
gb10_pci_root_bridges: 4
gb10_pci_root_open[0]: refused (ACCESS_DENIED)
gb10_pci_root[1]: segment 15 devices 6 bridges 1 windows 1
gb10_pci_candidate[1]: command_status 0x00100004 bar0 0x00000000:0x00000000

The candidate line distinguishes an unprogrammed BAR (the other plausible cause) from a missed match, since it only appears when the 10de:2e12 pair was seen but failed the BAR/command check.

crates/aienos-accel/src/lib.rs

  • Host-testable diagnostic types and renderer (RootBridgeOutcome, RootBridgeScan, write_discovery_diagnostics) with a unit test pinning the exact report lines, so the format is validated without booting hardware.

Docs and evidence

  • docs/GB10_NATIVE_STATUS.md now describes the shared open and the recorded diagnostics.
  • evidence/m2_first_boot_2026-09-24.md gap entry updated with the confirmed root cause and the new report fields.
  • Fixes #23

Follow-up commit 2758b38: evidence file reverted (existing evidence is not edited); ACCESS_DENIED stated as hypothesis in GB10_NATIVE_STATUS.md.

SECURITY_IMPACT: BOUNDARY

Apply it

git checkout -b patch-2fc8e589409b4194 a1babb4d25544b9b5ab4becd4ba97cf45f42a2c9
curl -fsSL https://interplane.io/drakestapleton/aienux/patches/2fc8e589409b4194.patch | git am

Raw patch (mbox) · Diff

Provenance

This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record:

github-import 1
aien-dev/aienux
56
2758b38960f9ce297ca458accf17e5b7aac839eb
{"kind":"github-import","owner":"aien-dev","repo":"aienux","number":56,"url":"https://github.com/aien-dev/aienux/pull/56","export_sha256":"222ed873664c8b6770fec92487a3521a4b5f81629ee6399038e519facf854bee","imported_utc":"2026-11-18T16:35:40Z"}

Changes

diff --git a/crates/aienos-accel/src/lib.rs b/crates/aienos-accel/src/lib.rs
index fe548acb..c112d7a5 100644
--- a/crates/aienos-accel/src/lib.rs
+++ b/crates/aienos-accel/src/lib.rs
@@ -1,5 +1,7 @@
 #![no_std]
 
+use core::fmt::Write;
+
 /// PCI identity observed for the GB10 GPU in the DGX Spark.
 pub const NVIDIA_VENDOR_ID: u16 = 0x10de;
 pub const GB10_DEVICE_ID: u16 = 0x2e12;
@@ -58,9 +60,72 @@ pub struct Gb10Identity {
     pub pmc_boot_42: u32,
 }
 
+/// Outcome for one PCI root bridge during GB10 discovery, carried into the
+/// boot reports so a missed discovery says why.
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub enum RootBridgeOutcome {
+    /// The firmware refused the open of `PciRootBridgeIo` (status name).
+    OpenRefused(&'static str),
+    Scanned(RootBridgeScan),
+}
+
+/// What the scan of one PCI root bridge observed.
+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
+pub struct RootBridgeScan {
+    pub segment: u32,
+    pub devices: u16,
+    pub bridges: u16,
+    /// Bridges with a valid secondary..subordinate bus window.
+    pub windows: u16,
+    /// A GB10 vendor/device match that failed the BAR check: raw
+    /// command/status and BAR0 low/high, so the report shows the BAR state.
+    pub rejected_candidate: Option<(u32, u32, u32)>,
+}
+
+/// Report lines explaining why discovery produced no GB10 identity:
+/// bridges seen, opens refused, segments, bridge windows, and BAR state.
+/// `handles` is the number of `PciRootBridgeIo` handles, if known.
+pub fn write_discovery_diagnostics(
+    out: &mut impl Write,
+    handles: Option<u16>,
+    roots: &[Option<RootBridgeOutcome>],
+) {
+    match handles {
+        Some(n) => {
+            let _ = writeln!(out, "gb10_pci_root_bridges: {n}");
+        }
+        None => {
+            let _ = writeln!(out, "gb10_pci_root_bridges: lookup failed");
+            return;
+        }
+    }
+    for (index, outcome) in roots.iter().flatten().enumerate() {
+        match outcome {
+            RootBridgeOutcome::OpenRefused(status) => {
+                let _ = writeln!(out, "gb10_pci_root_open[{index}]: refused ({status})");
+            }
+            RootBridgeOutcome::Scanned(scan) => {
+                let _ = writeln!(
+                    out,
+                    "gb10_pci_root[{index}]: segment {} devices {} bridges {} windows {}",
+                    scan.segment, scan.devices, scan.bridges, scan.windows
+                );
+                if let Some((command_status, bar0_low, bar0_high)) = scan.rejected_candidate {
+                    let _ = writeln!(
+                        out,
+                        "gb10_pci_candidate[{index}]: command_status {command_status:#010x} bar0 {bar0_high:#010x}:{bar0_low:#010x}"
+                    );
+                }
+            }
+        }
+    }
+}
+
 #[cfg(test)]
 mod tests {
     use super::*;
+    extern crate std;
+    use std::string::String;
 
     #[test]
     fn validates_gb10_memory_bar() {
@@ -76,4 +141,37 @@ mod tests {
         assert!(Gb10Bar::from_config(location, 0x2e12_10de, 0x4, 0x2400_0004, 0).is_none());
         assert!(Gb10Bar::from_config(location, 0x2e12_10de, 0x6, 0x2400_0000, 0).is_none());
     }
+
+    #[test]
+    fn diagnostics_report_refused_opens_segments_and_bar_state() {
+        let roots = [
+            Some(RootBridgeOutcome::OpenRefused("ACCESS_DENIED")),
+            Some(RootBridgeOutcome::Scanned(RootBridgeScan {
+                segment: 15,
+                devices: 4,
+                bridges: 1,
+                windows: 1,
+                rejected_candidate: Some((0x10_0004, 0, 0)),
+            })),
+            None,
+        ];
+        let mut text = String::new();
+        write_discovery_diagnostics(&mut text, Some(2), &roots);
+        for line in [
+            "gb10_pci_root_bridges: 2",
+            "gb10_pci_root_open[0]: refused (ACCESS_DENIED)",
+            "gb10_pci_root[1]: segment 15 devices 4 bridges 1 windows 1",
+            "gb10_pci_candidate[1]: command_status 0x00100004 bar0 0x00000000:0x00000000",
+        ] {
+            assert!(text.lines().any(|l| l == line), "missing {line:?} in:\n{text}");
+        }
+
+        let mut text = String::new();
+        write_discovery_diagnostics(&mut text, None, &[None]);
+        assert_eq!(text, "gb10_pci_root_bridges: lookup failed\n");
+
+        let mut text = String::new();
+        write_discovery_diagnostics(&mut text, Some(0), &[None]);
+        assert_eq!(text, "gb10_pci_root_bridges: 0\n");
+    }
 }
diff --git a/crates/aienos-boot/src/handoff.rs b/crates/aienos-boot/src/handoff.rs
index bc0b3571..68f02dc8 100644
--- a/crates/aienos-boot/src/handoff.rs
+++ b/crates/aienos-boot/src/handoff.rs
@@ -38,6 +38,7 @@ use uefi::mem::memory_map::{MemoryMap, MemoryType};
 use uefi::prelude::*;
 use uefi::proto::console::gop::{GraphicsOutput, PixelFormat};
 use uefi::proto::media::file::{File, FileAttribute, FileMode};
+use uefi::proto::pci::configuration::ResourceRangeType;
 use uefi::proto::pci::root_bridge::PciRootBridgeIo;
 use uefi::proto::pci::PciIoAddress;
 use uefi::runtime::{ResetType, VariableAttributes, VariableVendor};
@@ -140,10 +141,55 @@ fn save_report_var(bytes: &[u8]) -> Result<u8, &'static str> {
     .map_err(|_| "firmware refused the write")
 }
 
-fn probe_gb10(
+type BridgeScan = aienos_accel::RootBridgeScan;
+type RootOutcome = aienos_accel::RootBridgeOutcome;
+
+/// Outcome of pre-exit GB10 discovery: the identity when found, plus a
+/// bounded record of why it was not (bridges seen, opens refused, segments,
+/// BAR state) so the pre-exit and final reports can say what happened.
+struct Gb10Discovery {
+    identity: Option<aienos_accel::Gb10Identity>,
+    /// Number of handles carrying the `PciRootBridgeIo` protocol, when the
+    /// handle database answered.
+    handles: Option<u16>,
+    roots: [Option<RootOutcome>; MAX_ROOT_BRIDGES],
+}
+
+/// At most this many root bridges are recorded; extras are still searched.
+const MAX_ROOT_BRIDGES: usize = 4;
+
+/// Compact status names for the report (no `Debug` tables in the image).
+fn status_name(status: Status) -> &'static str {
+    match status {
+        Status::ACCESS_DENIED => "ACCESS_DENIED",
+        Status::NOT_FOUND => "NOT_FOUND",
+        Status::INVALID_PARAMETER => "INVALID_PARAMETER",
+        Status::OUT_OF_RESOURCES => "OUT_OF_RESOURCES",
+        Status::UNSUPPORTED => "UNSUPPORTED",
+        _ => "OTHER",
+    }
+}
+
+impl Gb10Discovery {
+    /// Record the outcome of one root bridge, bounded by `MAX_ROOT_BRIDGES`.
+    fn record(&mut self, outcome: RootOutcome) {
+        if let Some(slot) = self.roots.iter_mut().find(|s| s.is_none()) {
+            *slot = Some(outcome);
+        }
+    }
+
+    /// Report lines explaining why no GB10 identity was produced.
+    fn write_diagnostics(&self, out: &mut Report) {
+        aienos_accel::write_discovery_diagnostics(out, self.handles, &self.roots);
+    }
+}
+
+/// Read the config registers needed for the BAR check. `None` when the
+/// vendor/device pair does not match the GB10 or a config read failed.
+fn read_candidate(
     root: &mut PciRootBridgeIo,
     address: PciIoAddress,
-) -> Option<aienos_accel::Gb10Identity> {
+) -> Option<(u32, u32, u32, u32)> {
     let config = |offset| address.with_register(offset);
     let vendor_device = root.pci().read_one::<u32>(config(0)).ok()?;
     if vendor_device != 0x2e12_10de {
@@ -152,7 +198,16 @@ fn probe_gb10(
     let command_status = root.pci().read_one::<u32>(config(4)).ok()?;
     let bar0_low = root.pci().read_one::<u32>(config(0x10)).ok()?;
     let bar0_high = root.pci().read_one::<u32>(config(0x14)).ok()?;
-    let bar = aienos_accel::Gb10Bar::from_config(
+    Some((vendor_device, command_status, bar0_low, bar0_high))
+}
+
+fn probe_gb10(
+    root: &mut PciRootBridgeIo,
+    address: PciIoAddress,
+    scan: &mut BridgeScan,
+) -> Option<aienos_accel::Gb10Identity> {
+    let (vendor_device, command_status, bar0_low, bar0_high) = read_candidate(root, address)?;
+    let bar = match aienos_accel::Gb10Bar::from_config(
         aienos_accel::PciLocation {
             segment: root.segment_nr(),
             bus: address.bus,
@@ -163,7 +218,15 @@ fn probe_gb10(
         command_status,
         bar0_low,
         bar0_high,
-    )?;
+    ) {
+        Some(bar) => bar,
+        None => {
+            // The GB10 was found but its BAR or command register was not
+            // usable; keep the raw values so the report shows the BAR state.
+            scan.rejected_candidate = Some((command_status, bar0_low, bar0_high));
+            return None;
+        }
+    };
     let pmc_boot_0 = root
         .memory()
         .read_one::<u32>(bar.physical_base + aienos_accel::PMC_BOOT_0)
@@ -179,31 +242,138 @@ fn probe_gb10(
     })
 }
 
-fn discover_gb10() -> Option<aienos_accel::Gb10Identity> {
-    let handles = uefi::boot::find_handles::<PciRootBridgeIo>().ok()?;
-    for handle in handles {
-        let Ok(mut root) = uefi::boot::open_protocol_exclusive::<PciRootBridgeIo>(handle) else {
-            continue;
-        };
-        // Config A puts GB10 at segment 15, bus 1, device 0, function 0.
-        // Try that first so the common boot path does not enumerate every bus.
-        if root.segment_nr() == 15 {
-            if let Some(identity) = probe_gb10(&mut root, PciIoAddress::new(1, 0, 0)) {
-                return Some(identity);
+/// Walk every function on one bus of this root bridge.
+/// Returns the GB10 identity when the GB10 is found here.
+fn scan_bus(root: &mut PciRootBridgeIo, bus: u8, scan: &mut BridgeScan) -> Option<aienos_accel::Gb10Identity> {
+    for dev in 0..32u8 {
+        for fun in 0..8u8 {
+            let address = PciIoAddress::new(bus, dev, fun);
+            let config = |offset| address.with_register(offset);
+            let Ok(vendor_device) = root.pci().read_one::<u32>(config(0)) else {
+                continue;
+            };
+            if vendor_device & 0xffff == 0xffff {
+                if fun == 0 {
+                    break; // no function 0: no further functions on this device
+                }
+                continue;
             }
-        }
-        let Ok(tree) = root.enumerate() else {
-            continue;
-        };
-        for address in tree {
-            if let Some(identity) = probe_gb10(&mut root, address) {
-                return Some(identity);
+            scan.devices += 1;
+            if vendor_device == 0x2e12_10de {
+                if let Some(identity) = probe_gb10(root, address, scan) {
+                    return Some(identity);
+                }
+            }
+            let header_type = root
+                .pci()
+                .read_one::<u32>(config(0x0c))
+                .map(|v| ((v >> 16) & 0xff) as u8)
+                .unwrap_or(0);
+            if header_type & 0x7f == 0x01 {
+                scan.bridges += 1;
+                let window = root
+                    .pci()
+                    .read_one::<u32>(config(0x18))
+                    .map(|v| (((v >> 8) & 0xff) as u8, ((v >> 16) & 0xff) as u8))
+                    .unwrap_or((0, 0));
+                if window.0 != 0 && window.1 >= window.0 {
+                    scan.windows += 1;
+                }
+            }
+            if fun == 0 && header_type & 0x80 == 0 {
+                break; // single-function device: skip functions 1..8
             }
         }
     }
     None
 }
 
+/// Read the bus-range resource descriptors of this root bridge, or `None`.
+fn bus_ranges(root: &mut PciRootBridgeIo) -> Option<(u8, u8)> {
+    let mut range: Option<(u8, u8)> = None;
+    for descriptor in root.configuration().ok()? {
+        if descriptor.resource_range_type == ResourceRangeType::Bus {
+            let min = u8::try_from(descriptor.address_min).unwrap_or(u8::MAX);
+            let max = u8::try_from(descriptor.address_max).unwrap_or(u8::MAX);
+            range = Some(match range {
+                Some((lo, hi)) => (lo.min(min), hi.max(max)),
+                None => (min, max),
+            });
+        }
+    }
+    range
+}
+
+/// Scan one root bridge. Returns the GB10 identity and the outcome to record.
+fn scan_root(root: &mut PciRootBridgeIo) -> (Option<aienos_accel::Gb10Identity>, RootOutcome) {
+    let mut scan = BridgeScan {
+        segment: root.segment_nr(),
+        devices: 0,
+        bridges: 0,
+        windows: 0,
+        rejected_candidate: None,
+    };
+    // Config A puts GB10 at segment 15, bus 1, device 0, function 0.
+    // Try that first so the common boot path does not walk every bus.
+    if scan.segment == 15 {
+        if let Some(identity) = probe_gb10(root, PciIoAddress::new(1, 0, 0), &mut scan) {
+            return (Some(identity), RootOutcome::Scanned(scan));
+        }
+    }
+    // No firmware bus descriptors: fall back to the root bus so the scan
+    // still sees devices whose bus numbers firmware never published.
+    let (bus_min, bus_max) = bus_ranges(root).unwrap_or((0, 0));
+    for bus in bus_min..=bus_max {
+        if let Some(identity) = scan_bus(root, bus, &mut scan) {
+            return (Some(identity), RootOutcome::Scanned(scan));
+        }
+    }
+    (None, RootOutcome::Scanned(scan))
+}
+
+fn discover_gb10() -> Gb10Discovery {
+    let mut discovery = Gb10Discovery {
+        identity: None,
+        handles: None,
+        roots: [const { None }; MAX_ROOT_BRIDGES],
+    };
+    let handles = match uefi::boot::find_handles::<PciRootBridgeIo>() {
+        Ok(handles) => handles,
+        Err(_) => return discovery,
+    };
+    discovery.handles = Some(u16::try_from(handles.len()).unwrap_or(u16::MAX));
+    for handle in handles {
+        // Shared (GetProtocol) open: the firmware PCI bus driver holds this
+        // protocol open ByDriver, so an exclusive open is refused with
+        // ACCESS_DENIED. Shared reads are safe here: this boot code only
+        // reads through the protocol, and firmware keeps the protocol
+        // installed until boot services are exited.
+        let mut root = match unsafe {
+            uefi::boot::open_protocol::<PciRootBridgeIo>(
+                OpenProtocolParams {
+                    handle,
+                    agent: uefi::boot::image_handle(),
+                    controller: None,
+                },
+                OpenProtocolAttributes::GetProtocol,
+            )
+        } {
+            Ok(root) => root,
+            Err(e) => {
+                discovery.record(RootOutcome::OpenRefused(status_name(e.status())));
+                continue;
+            }
+        };
+        let (found, outcome) = scan_root(&mut root);
+        discovery.record(outcome);
+        if let Some(identity) = found {
+            discovery.identity = Some(identity);
+            return discovery;
+        }
+    }
+    discovery
+}
+
 /// Reads a firmware ACPI table whose header is at `addr`.
 ///
 /// # Safety
@@ -523,7 +693,8 @@ fn main() -> Status {
     stage(FIRMWARE_ENTRY);
 
     stage(GB10_DISCOVERY);
-    let gb10 = discover_gb10();
+    let gb10_discovery = discover_gb10();
+    let gb10 = gb10_discovery.identity;
 
     stage(ACPI_TOPOLOGY);
     let boot_midr = midr_el1();
@@ -565,6 +736,7 @@ fn main() -> Status {
         }
         None => {
             let _ = writeln!(pre, "gb10: unavailable");
+            gb10_discovery.write_diagnostics(&mut pre);
         }
     }
     write_cpu(&mut pre, cpu, boot_midr, boot_mpidr);
@@ -636,6 +808,9 @@ fn main() -> Status {
     header(&mut report, "final");
     write_index_line(&mut report);
     let _ = write!(report, "{}", kernel_report.as_str());
+    if gb10.is_none() {
+        gb10_discovery.write_diagnostics(&mut report);
+    }
     match progress_saved {
         Ok(_) => {
             let _ = writeln!(report, "progress_record: saved");
diff --git a/docs/GB10_NATIVE_STATUS.md b/docs/GB10_NATIVE_STATUS.md
index 2a0fb184..b103d4f0 100644
--- a/docs/GB10_NATIVE_STATUS.md
+++ b/docs/GB10_NATIVE_STATUS.md
@@ -1,16 +1,32 @@
 # GB10 native execution status
 
 The `aienos-handoff` AArch64 UEFI image now checks the DGX Spark's observed
-GB10 PCI location first, then searches other root bridges if needed. It accepts
-only NVIDIA `10de:2e12` with a programmed 64-bit memory BAR and PCI memory
+GB10 PCI location first, then walks every bus in each root bridge's
+firmware-declared bus range. It opens the UEFI PCI root bridge protocol with a
+shared (`GetProtocol`) open. The leading hypothesis for the first native
+boot's `gb10: unavailable` is that the firmware PCI bus driver holds the
+protocol `ByDriver` and refuses an exclusive open with `ACCESS_DENIED`; this is
+unconfirmed on hardware, and the next native boot's `gb10_pci_root_open[..]`
+lines will confirm or rule it out. It accepts only
+NVIDIA `10de:2e12` with a programmed 64-bit memory BAR and PCI memory
 decoding enabled. Through the UEFI PCI root bridge protocol, it reads the
 read-only PMC `BOOT_0` and `BOOT_42` registers from BAR0. It carries the
 location, BAR address, and register values across `ExitBootServices` into the
 AIENOS kernel's serial boot report. No Linux service is involved in that image.
 
-This image has been built but **has not been booted on hardware**. These
-register reads still use firmware services before handoff. They establish a
-device identity path; they do not initialize the GPU or execute a GPU command.
+When the GB10 is not found, the pre-exit report and the final
+firmware-variable report record why: how many root bridges carry the protocol
+(`gb10_pci_root_bridges`), any refused opens (`gb10_pci_root_open[i]`), and
+per scanned bridge the segment number, device count, bridge count, and valid
+bridge bus windows (`gb10_pci_root[i]`). If the GB10 vendor/device pair was
+seen but rejected, its command/status and BAR0 values are recorded
+(`gb10_pci_candidate[i]`), distinguishing an unprogrammed BAR from a missed
+match.
+
+This image has been built but the fixed discovery path **has not been booted
+on hardware**. These register reads still use firmware services before
+handoff. They establish a device identity path; they do not initialize the
+GPU or execute a GPU command.
 
 To reach independent GPU execution, AIENOS still needs a native MMU mapping for
 GPU MMIO, GPU resource and interrupt management, GB10/GSP firmware loading and