[PATCH v2 10/31] gpu: nova-core: add build ID headers to debugfs log buffer dumps

From: John Hubbard

Date: Fri Aug 21 2026 - 22:00:03 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
Reviewed-by: Timur Tabi <ttabi@xxxxxxxxxx>
Signed-off-by: John Hubbard <jhubbard@xxxxxxxxxx>
---
drivers/gpu/nova-core/firmware.rs | 34 +++++
drivers/gpu/nova-core/firmware/gsp.rs | 9 +-
drivers/gpu/nova-core/gpu.rs | 2 +-
drivers/gpu/nova-core/gsp.rs | 183 ++++++++++++++++++++++----
drivers/gpu/nova-core/gsp/boot.rs | 2 +-
5 files changed, 199 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 754df6849e43..298959e98c33 100644
--- a/drivers/gpu/nova-core/firmware/gsp.rs
+++ b/drivers/gpu/nova-core/firmware/gsp.rs
@@ -6,6 +6,7 @@
Coherent,
DmaAddress, //
},
+ firmware,
prelude::*,
str::CString,
};
@@ -15,8 +16,8 @@
radix3::Radix3,
riscv::RiscvFirmware, //
tlv::{
- request_tlv, //
- Tlv,
+ request_tlv,
+ Tlv, //
},
},
gpu::Chipset, //
@@ -46,10 +47,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 de5cf3914949..79fec8664ea9 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::{
@@ -103,6 +112,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.
@@ -117,7 +170,13 @@ fn init(view: CoherentView<'_, Self>, start: DmaAddress) -> Result<()> {
/// then pp points to index into the buffer where the next logging entry will
/// be written. Therefore, the logging data is valid if:
/// 1 <= pp < sizeof(buffer)/sizeof(u64)
-struct LogBuffer<const NUM_PAGES: usize>(Coherent<[[u8; GSP_PAGE_SIZE]; NUM_PAGES]>);
+///
+/// When a build ID is available, the debugfs file for this buffer prepends
+/// a header so the dump is self-describing.
+struct LogBuffer<const NUM_PAGES: usize> {
+ header: Option<[u8; LOG_BUFFER_HEADER_SIZE]>,
+ buffer: Coherent<[[u8; GSP_PAGE_SIZE]; NUM_PAGES]>,
+}

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

impl<const NUM_PAGES: usize> LogBuffer<NUM_PAGES> {
/// Creates a new `LogBuffer` mapped on `dev`.
- fn new(dev: &device::Device<device::Bound>) -> Result<Self> {
- let obj = Self(Coherent::zeroed(dev, GFP_KERNEL)?);
-
- let start_addr = obj.0.dma_address();
+ fn new(
+ dev: &device::Device<device::Bound>,
+ chipset: Chipset,
+ build_id: Option<&BuildId>,
+ task_prefix: &str,
+ ) -> Result<Self> {
+ let buffer = Coherent::zeroed(dev, GFP_KERNEL)?;

+ let start_addr = buffer.dma_address();
let pte_view = io_project!(
- obj.0,
+ buffer,
[build: 0][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 NUM_PAGES: usize> debugfs::BinaryWriter for LogBuffer<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)
}
}

@@ -173,9 +281,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.
@@ -188,18 +298,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)?,
@@ -210,9 +334,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()
@@ -238,12 +371,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 874f6e9499f0..dfc5be27384a 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)?;

self.cmdq
.send_command_no_wait(bar, commands::SetSystemInfo::new(pdev, chipset))?;
--
2.55.0