[PATCH 09/27] gpu: nova-core: add build ID headers to debugfs log buffer dumps

From: John Hubbard

Date: Tue Aug 18 2026 - 23:53:29 EST


A raw log buffer dump cannot be decoded without knowing which firmware
build produced it, and which GPU and metadata format it belongs to.
GSP-RM's own decoder takes that from a header ahead of the data, in the
LIBOS_LOG_NVLOG_BUFFER_V2 layout.

Prepend that header to each debugfs dump. The build ID comes from the
BLID tag of gsp.tlv, so request the metadata once when the GSP manager
is created and hand it to the firmware loader rather than requesting it
again during boot. A buffer whose build ID is missing serves its
contents with no header.

Assisted-by: Cursor:claude-opus-5
Signed-off-by: John Hubbard <jhubbard@xxxxxxxxxx>
---
drivers/gpu/nova-core/firmware.rs | 34 +++++
drivers/gpu/nova-core/firmware/gsp.rs | 8 +-
drivers/gpu/nova-core/gpu.rs | 2 +-
drivers/gpu/nova-core/gsp.rs | 185 ++++++++++++++++++++++----
drivers/gpu/nova-core/gsp/boot.rs | 2 +-
5 files changed, 200 insertions(+), 31 deletions(-)

diff --git a/drivers/gpu/nova-core/firmware.rs b/drivers/gpu/nova-core/firmware.rs
index dfd41364cc77..e0befe84aa3e 100644
--- a/drivers/gpu/nova-core/firmware.rs
+++ b/drivers/gpu/nova-core/firmware.rs
@@ -31,6 +31,40 @@
pub(crate) mod riscv;
pub(crate) mod tlv;

+/// Maximum length of a build ID, matching Open RM's `BUILD_ID_MAX_LENGTH`.
+const BUILD_ID_MAX_LENGTH: usize = 32;
+
+/// Build ID extracted from firmware, used to correlate debugfs log buffer dumps
+/// with the correct firmware symbols.
+pub(crate) struct BuildId {
+ bytes: [u8; BUILD_ID_MAX_LENGTH],
+ len: u8,
+}
+
+impl BuildId {
+ /// Constructs a [`BuildId`] from raw descriptor bytes.
+ ///
+ /// Returns `None` if `data` is empty or exceeds [`BUILD_ID_MAX_LENGTH`].
+ pub(crate) fn from_raw(data: &[u8]) -> Option<Self> {
+ if data.is_empty() || data.len() > BUILD_ID_MAX_LENGTH {
+ return None;
+ }
+
+ let mut bytes = [0u8; BUILD_ID_MAX_LENGTH];
+ bytes[..data.len()].copy_from_slice(data);
+
+ Some(Self {
+ bytes,
+ len: data.len() as u8,
+ })
+ }
+
+ /// Returns the build ID bytes.
+ pub(crate) fn as_bytes(&self) -> &[u8] {
+ &self.bytes[..usize::from(self.len)]
+ }
+}
+
/// Structure used to describe some firmwares, notably FWSEC-FRTS.
#[repr(C)]
#[derive(Debug, Clone, FromBytes)]
diff --git a/drivers/gpu/nova-core/firmware/gsp.rs b/drivers/gpu/nova-core/firmware/gsp.rs
index 48c73a676ecb..832debb82767 100644
--- a/drivers/gpu/nova-core/firmware/gsp.rs
+++ b/drivers/gpu/nova-core/firmware/gsp.rs
@@ -16,8 +16,8 @@
radix3::Radix3,
riscv::RiscvFirmware, //
tlv::{
- request_tlv, //
- Tlv,
+ request_tlv,
+ Tlv, //
},
},
gpu::Chipset,
@@ -48,10 +48,10 @@ impl GspFirmware {
pub(crate) fn new<'a>(
dev: &'a device::Device<device::Bound>,
chipset: Chipset,
+ gsp_tlv: &'a firmware::Firmware,
) -> impl PinInit<Self, Error> + 'a {
pin_init::pin_init_scope(move || {
- let firmware = request_tlv(dev, chipset, "gsp")?;
- let tlv = Tlv::new(firmware.data())?;
+ let tlv = Tlv::new(gsp_tlv.data())?;
let fw_version = CString::try_from_fmt(fmt!("{}", tlv.get_string(b"VERS")?))?;
dev_dbg!(
dev,
diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs
index 11a66a597298..c0ba561a3bf1 100644
--- a/drivers/gpu/nova-core/gpu.rs
+++ b/drivers/gpu/nova-core/gpu.rs
@@ -396,7 +396,7 @@ pub(crate) fn new(

vgpu: VgpuManager::new(pdev, spec.chipset, fsp.as_mut()),

- gsp <- Gsp::new(pdev),
+ gsp <- Gsp::new(pdev, spec.chipset),

// This member must be initialized last, so the `UnloadBundle` can never be dropped
// from outside of the constructed `GspResources`, ensuring that the unload sequence
diff --git a/drivers/gpu/nova-core/gsp.rs b/drivers/gpu/nova-core/gsp.rs
index f19a47cf396f..232905638169 100644
--- a/drivers/gpu/nova-core/gsp.rs
+++ b/drivers/gpu/nova-core/gsp.rs
@@ -12,6 +12,7 @@
CoherentView,
DmaAddress, //
},
+ fs::file,
io::{
io_project,
io_write,
@@ -19,7 +20,8 @@
},
pci,
prelude::*,
- sync::Arc, //
+ sync::Arc,
+ uaccess::UserSliceWriter, //
};

pub(crate) mod cmdq;
@@ -45,6 +47,13 @@
sec2::Sec2 as Sec2Falcon,
Falcon, //
},
+ firmware::{
+ tlv::{
+ request_tlv,
+ Tlv, //
+ },
+ BuildId, //
+ },
fsp::Fsp,
gpu::Chipset,
gsp::{
@@ -104,6 +113,50 @@ fn init(view: CoherentView<'_, Self>, start: DmaAddress) -> Result<()> {
}
}

+/// Size of the header prepended to debugfs log buffer dumps.
+///
+/// This header makes each dump self-describing so that decoding tools can
+/// identify the firmware build, GPU architecture, and metadata format without
+/// out-of-band information.
+const LOG_BUFFER_HEADER_SIZE: usize = 0x48;
+
+/// Build a log buffer header from GPU and firmware metadata.
+///
+/// Layout (all little-endian):
+/// 0x00 gpuArch (u32)
+/// 0x04 gpuImpl (u32)
+/// 0x08 version (u32) = 2
+/// 0x0C buildIdLength (u32)
+/// 0x10 taskPrefix[8]
+/// 0x18 localToGlobalTimerDelta (u64) = 0
+/// 0x20 buildId[32]
+/// 0x40 flags (u32) = 1 (packed metadata)
+/// 0x44 reserved (u32) = 0
+fn build_log_buffer_header(
+ chipset: Chipset,
+ build_id: &BuildId,
+ task_prefix: &str,
+) -> [u8; LOG_BUFFER_HEADER_SIZE] {
+ let mut h = [0u8; LOG_BUFFER_HEADER_SIZE];
+ let chipset_val = chipset as u32;
+
+ h[0x00..0x04].copy_from_slice(&(chipset_val >> 4).to_le_bytes());
+ h[0x04..0x08].copy_from_slice(&(chipset_val & 0xF).to_le_bytes());
+ h[0x08..0x0C].copy_from_slice(&2u32.to_le_bytes());
+
+ let bid = build_id.as_bytes();
+ h[0x0C..0x10].copy_from_slice(&(bid.len() as u32).to_le_bytes());
+
+ let prefix = task_prefix.as_bytes();
+ let prefix_len = prefix.len().min(8);
+ h[0x10..0x10 + prefix_len].copy_from_slice(&prefix[..prefix_len]);
+
+ h[0x20..0x20 + bid.len()].copy_from_slice(bid);
+ h[0x40..0x44].copy_from_slice(&1u32.to_le_bytes());
+
+ h
+}
+
/// The logging buffers are byte queues that contain encoded printf-like
/// messages from GSP-RM. They need to be decoded by a special application
/// that can parse the buffers.
@@ -122,7 +175,13 @@ fn init(view: CoherentView<'_, Self>, start: DmaAddress) -> Result<()> {
/// `SIZE` is the buffer size in bytes and `NUM_PAGES` is the same size in GSP pages, checked
/// against each other at build time. Computing one from the other in a type position is not
/// stable Rust, so both are parameters.
-struct LogBuffer<const SIZE: usize, const NUM_PAGES: usize>(Coherent<[u8; SIZE]>);
+///
+/// When a build ID is available, the debugfs file for this buffer prepends
+/// a header so the dump is self-describing.
+struct LogBuffer<const SIZE: usize, const NUM_PAGES: usize> {
+ header: Option<[u8; LOG_BUFFER_HEADER_SIZE]>,
+ buffer: Coherent<[u8; SIZE]>,
+}

/// Log buffer for a task that GSP-RM logs to at its default size.
///
@@ -137,21 +196,72 @@ fn init(view: CoherentView<'_, Self>, start: DmaAddress) -> Result<()> {

impl<const SIZE: usize, const NUM_PAGES: usize> LogBuffer<SIZE, NUM_PAGES> {
/// Creates a new `LogBuffer` mapped on `dev`.
- fn new(dev: &device::Device<device::Bound>) -> Result<Self> {
+ fn new(
+ dev: &device::Device<device::Bound>,
+ chipset: Chipset,
+ build_id: Option<&BuildId>,
+ task_prefix: &str,
+ ) -> Result<Self> {
build_assert!(SIZE == NUM_PAGES * GSP_PAGE_SIZE);

- let obj = Self(Coherent::zeroed(dev, GFP_KERNEL)?);
-
- let start_addr = obj.0.dma_address();
+ let buffer = Coherent::zeroed(dev, GFP_KERNEL)?;

+ let start_addr = buffer.dma_address();
let pte_view = io_project!(
- obj.0,
+ buffer,
[build: size_of::<u64>()..][build: ..NUM_PAGES * size_of::<u64>()]
)
.try_cast::<PteArray<NUM_PAGES>>()?;
PteArray::init(pte_view, start_addr)?;

- Ok(obj)
+ let header = build_id.map(|bid| build_log_buffer_header(chipset, bid, task_prefix));
+
+ Ok(Self { header, buffer })
+ }
+}
+
+impl<const SIZE: usize, const NUM_PAGES: usize> debugfs::BinaryWriter
+ for LogBuffer<SIZE, NUM_PAGES>
+{
+ fn write_to_slice(
+ &self,
+ writer: &mut UserSliceWriter,
+ offset: &mut file::Offset,
+ ) -> Result<usize> {
+ if offset.is_negative() {
+ return Err(EINVAL);
+ }
+
+ let offset_val: usize = (*offset).try_into().map_err(|_| EINVAL)?;
+ let header = self.header.as_ref().map_or(&[][..], |h| h.as_slice());
+ let total_len = header.len() + self.buffer.size();
+
+ if offset_val >= total_len {
+ return Ok(0);
+ }
+
+ let count = (total_len - offset_val).min(writer.len());
+ if count == 0 {
+ return Ok(0);
+ }
+
+ let mut written = 0;
+
+ if offset_val < header.len() {
+ let hdr_count = (header.len() - offset_val).min(count);
+ writer.write_slice(&header[offset_val..offset_val + hdr_count])?;
+ written += hdr_count;
+ }
+
+ if written < count {
+ let buf_start = offset_val.saturating_sub(header.len());
+ let buf_count = count - written;
+ writer.write_dma(&self.buffer, buf_start, buf_count)?;
+ written += buf_count;
+ }
+
+ *offset += written as i64;
+ Ok(written)
}
}

@@ -180,9 +290,11 @@ struct LogBuffers {
/// GSP runtime data.
#[pin_data]
pub(crate) struct Gsp {
+ /// Preloaded GSP firmware TLV metadata used during boot.
+ gsp_tlv: kernel::firmware::Firmware,
/// Libos arguments.
pub(crate) libos: Coherent<[LibosMemoryRegionInitArgument]>,
- /// Log buffers, optionally exposed via debugfs.
+ /// Log buffers for all LIBOS3 tasks, exposed via debugfs.
#[pin]
logs: debugfs::Scope<LogBuffers>,
/// Command queue, shared with the GSP event interrupt handler.
@@ -195,18 +307,32 @@ pub(crate) struct Gsp {

impl Gsp {
// Creates an in-place initializer for a `Gsp` manager for `pdev`.
- pub(crate) fn new(pdev: &pci::Device<device::Bound>) -> impl PinInit<Self, Error> + '_ {
+ pub(crate) fn new(
+ pdev: &pci::Device<device::Bound>,
+ chipset: Chipset,
+ ) -> impl PinInit<Self, Error> + '_ {
pin_init::pin_init_scope(move || {
let dev = pdev.as_ref();

- let loginit = TaskLogBuffer::new(dev)?;
- let logintr = TaskLogBuffer::new(dev)?;
- let logrm = TaskLogBuffer::new(dev)?;
- let logmnoc = TaskLogBuffer::new(dev)?;
- let logroot = SmallLogBuffer::new(dev)?;
- let logrmon = SmallLogBuffer::new(dev)?;
+ let gsp_tlv = request_tlv(dev, chipset, "gsp")?;
+ let tlv = Tlv::new(gsp_tlv.data())?;
+ let build_id = tlv.get_bytes(b"BLID").ok().and_then(BuildId::from_raw);
+ if build_id.is_none() {
+ dev_warn!(
+ pdev,
+ "GSP firmware build ID not found, log buffer headers omitted\n"
+ );
+ }
+
+ let loginit = TaskLogBuffer::new(dev, chipset, build_id.as_ref(), "INIT")?;
+ let logintr = TaskLogBuffer::new(dev, chipset, build_id.as_ref(), "INTR")?;
+ let logrm = TaskLogBuffer::new(dev, chipset, build_id.as_ref(), "RM")?;
+ let logmnoc = TaskLogBuffer::new(dev, chipset, build_id.as_ref(), "MNOC")?;
+ let logroot = SmallLogBuffer::new(dev, chipset, build_id.as_ref(), "ROOT")?;
+ let logrmon = SmallLogBuffer::new(dev, chipset, build_id.as_ref(), "RMON")?;

Ok(try_pin_init!(Self {
+ gsp_tlv,
cmdq: Arc::pin_init(Cmdq::new(dev), GFP_KERNEL)?,
rmargs: Coherent::init(dev, GFP_KERNEL, GspArgumentsPadded::new(cmdq.as_ref()))?,
rm_state_monitor: Coherent::zeroed(dev, GFP_KERNEL)?,
@@ -217,9 +343,18 @@ pub(crate) fn new(pdev: &pci::Device<device::Bound>) -> impl PinInit<Self, Error
GFP_KERNEL,
)?;

- libos.init_at(0, LibosMemoryRegionInitArgument::new("LOGINIT", &loginit.0))?;
- libos.init_at(1, LibosMemoryRegionInitArgument::new("LOGINTR", &logintr.0))?;
- libos.init_at(2, LibosMemoryRegionInitArgument::new("LOGRM", &logrm.0))?;
+ libos.init_at(
+ 0,
+ LibosMemoryRegionInitArgument::new("LOGINIT", &loginit.buffer),
+ )?;
+ libos.init_at(
+ 1,
+ LibosMemoryRegionInitArgument::new("LOGINTR", &logintr.buffer),
+ )?;
+ libos.init_at(
+ 2,
+ LibosMemoryRegionInitArgument::new("LOGRM", &logrm.buffer),
+ )?;
libos.init_at(3, LibosMemoryRegionInitArgument::new("RMARGS", rmargs))?;

libos.into()
@@ -245,12 +380,12 @@ pub(crate) fn new(pdev: &pci::Device<device::Bound>) -> impl PinInit<Self, Error
.expect("DEBUGFS_ROOT not initialized");

log_parent.scope(log_buffers, dev.name(), |logs, dir| {
- dir.read_binary_file(c"loginit", &logs.loginit.0);
- dir.read_binary_file(c"logintr", &logs.logintr.0);
- dir.read_binary_file(c"logrm", &logs.logrm.0);
- dir.read_binary_file(c"logmnoc", &logs.logmnoc.0);
- dir.read_binary_file(c"logroot", &logs.logroot.0);
- dir.read_binary_file(c"logrmon", &logs.logrmon.0);
+ dir.read_binary_file(c"loginit", &logs.loginit);
+ dir.read_binary_file(c"logintr", &logs.logintr);
+ dir.read_binary_file(c"logrm", &logs.logrm);
+ dir.read_binary_file(c"logmnoc", &logs.logmnoc);
+ dir.read_binary_file(c"logroot", &logs.logroot);
+ dir.read_binary_file(c"logrmon", &logs.logrmon);
})
},
}))
diff --git a/drivers/gpu/nova-core/gsp/boot.rs b/drivers/gpu/nova-core/gsp/boot.rs
index e03700ee7bea..a64313dca0a1 100644
--- a/drivers/gpu/nova-core/gsp/boot.rs
+++ b/drivers/gpu/nova-core/gsp/boot.rs
@@ -42,7 +42,7 @@ pub(crate) fn boot(
let dev = pdev.as_ref();
let hal = super::hal::gsp_hal(chipset);

- let gsp_fw = KBox::pin_init(GspFirmware::new(dev, chipset), GFP_KERNEL)?;
+ let gsp_fw = KBox::pin_init(GspFirmware::new(dev, chipset, &self.gsp_tlv), GFP_KERNEL)?;

// Perform the chipset-specific boot sequence, and retrieve the unload bundle.
let unload_bundle = hal.boot(&self, &mut ctx, &gsp_fw)?.or_else(|| {
--
2.55.0