Skip to contentSkip to conversation

gpu: nova-core: debug logging essentials for r000

PATCH New John Hubbard 1 participant 5 messages Sep 18

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover gpu: nova-core: debug logging essentials for r000

Following up on the r000 v3 patchset that I just posted, this provides some key logging enhancements for dmesg output, as well as re-enabling decoding of GSP logs with the new r000 firmware (which has a new log system that needs a little bit more information; specifically, Build IDs).

These are a reworked and refreshed version of the debug-logging patches of the r000 v2 series [1], which Alex asked to be moved into their own patchset.

* Each log dump carries the header that the log decoder expects, with the firmware's build ID, so the decoder matches the dump to the right firmware ELF instead of the user guessing.

* Each GMC debug line prints the command by name and labels a received message as an event or a response, so that this line:

      GSP GMC: receive: seq# 9223372036854775808, command_id=0x10002, length=0xb0

becomes this one:

      GSP GMC: event: seq# 0, command=EXEC_GENERIC_BOOTLOADER (0x10002), length=0xb0

A small preparatory patch keeps the NV_PMC_BOOT_42 implementation field in the GPU spec, so that the log header takes the GPU's architecture and implementation from the register fields, as Open RM does.

The series applies on top of v3 of the r000 series [2], which in turn applies on top of drm-rust-next plus:

* the interrupt tree series for GIN, the GPU Interrupt and Notification unit [3]
* Eliot Courtney's NVKV codec series [4]
* the three-patch radix3 cleanup [5]
* two lint fixes for the generated bindings, both already in mainline

A branch with everything applied:

https://github.com/johnhubbard/linux/tree/nova-core-r615-plus-log-decoding-v0/

[1] https://lore.kernel.org/all/[email protected]/
[2] https://github.com/johnhubbard/linux/tree/nova-core-run-on-r615-or-later-v3/
[3] https://lore.kernel.org/all/[email protected]/
[4] https://lore.kernel.org/all/[email protected]/
[5] https://lore.kernel.org/all/[email protected]/

John Hubbard (4):
gpu: nova-core: record the BOOT_42 implementation field in the GPU
spec
gpu: nova-core: enable decoding of the GSP firmware logs
gpu: nova-core: gsp: print GMC command names in debug logs
gpu: nova-core: gsp: distinguish GMC events from responses in debug
logs

 drivers/gpu/nova-core/firmware/gsp.rs |  54 ++++++-
 drivers/gpu/nova-core/gpu.rs          |   9 +-
 drivers/gpu/nova-core/gsp.rs          | 212 ++++++++++++++++++++++----
 drivers/gpu/nova-core/gsp/boot.rs     |  11 +-
 drivers/gpu/nova-core/gsp/cmdq.rs     |  42 +++--
 drivers/gpu/nova-core/gsp/fw.rs       |  81 +++++++++-
 6 files changed, 355 insertions(+), 54 deletions(-)
Signature · 1 line
2.55.0
#1 lore raw

PATCH 1/4 gpu: nova-core: record the BOOT_42 implementation field in the GPU spec

NV_PMC_BOOT_42, the register that identifies the GPU, carries an architecture field and an implementation field. Open RM keeps the two fields as it reads them, and the GSP log headers that Open RM writes name the GPU by both.

Nova-core combined the two fields into one chipset code at probe and kept only that code, so the implementation number could be recovered only by undoing the combination.

Record the implementation field in the GPU spec beside the chipset code.

Assisted-by LLM
---
 drivers/gpu/nova-core/gpu.rs | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/nova-core/gpu.rs +7 -1
index fd1a74913d7c..cecd8e79430d 100644
@@ -213,10 +213,15 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
     }
 }
 
-/// Structure holding a basic description of the GPU: `Chipset` and `Revision`.
+/// Structure holding a basic description of the GPU: `Chipset`, the implementation field of
+/// `NV_PMC_BOOT_42`, and `Revision`.
 #[derive(Clone, Copy)]
 pub(crate) struct Spec {
     pub(crate) chipset: Chipset,
+    /// Implementation field of `NV_PMC_BOOT_42`, which distinguishes this chipset from the other
+    /// chipsets of its architecture.
+    #[expect(dead_code)]
+    pub(crate) implementation: u8,
     revision: Revision,
 }
 
@@ -259,6 +264,7 @@ impl TryFrom<regs::NV_PMC_BOOT_42> for Spec {
     fn try_from(boot42: regs::NV_PMC_BOOT_42) -> Result<Self> {
         Ok(Self {
             chipset: boot42.chipset()?,
+            implementation: boot42.implementation().into(),
             revision: boot42.into(),
         })
     }
Signature · 1 line
2.55.0
#2 lore raw

PATCH 2/4 gpu: nova-core: enable decoding of the GSP firmware logs

In reply to John Hubbard

Nova-core exports the GSP-RM log buffers over debugfs, and Open RM's log decoder turns a dump into text with the ELF of the firmware that wrote it. The decoder identifies that firmware by a header ahead of each buffer. The header, in the LIBOS_LOG_NVLOG_BUFFER_V2 layout, names the GPU, the firmware task that wrote the buffer, and the GNU build ID of the firmware.

Nova-core wrote no such header, so a dump could not be matched to its firmware, and a decode with the wrong ELF produced garbage rather than an error.

Prepend the header to each debugfs dump, with the build ID read from the BLID tag of gsp.tlv. The log buffers are created before boot loads the firmware from that file, so request the file once when the buffers are created and hand it to the boot sequence. A file without a usable build ID is reported with a warning, and its dumps carry no header.

Also, r000 has several more log buffers that must be provisioned, so do that too.

---
 drivers/gpu/nova-core/firmware/gsp.rs |  54 ++++++-
 drivers/gpu/nova-core/gpu.rs          |   3 +-
 drivers/gpu/nova-core/gsp.rs          | 212 ++++++++++++++++++++++----
 drivers/gpu/nova-core/gsp/boot.rs     |   2 +-
 4 files changed, 234 insertions(+), 37 deletions(-)
drivers/gpu/nova-core/firmware/gsp.rs +50 -4
index a2db7b6ba131..e6ca8d559d7b 100644
@@ -6,6 +6,7 @@
         Coherent,
         DmaAddress, //
     },
+    firmware,
     prelude::*, //
 };
 
@@ -21,6 +22,48 @@
     gpu::Chipset, //
 };
 
+/// Longest build ID that a log dump header carries, matching Open RM's `BUILD_ID_MAX_LENGTH`.
+pub(crate) const BUILD_ID_MAX_LENGTH: usize = 32;
+
+/// Build ID of the GSP firmware, from the `BLID` tag of its TLV.
+pub(crate) struct BuildId {
+    /// The ID, zero-padded to [`BUILD_ID_MAX_LENGTH`] bytes.
+    bytes: [u8; BUILD_ID_MAX_LENGTH],
+    /// Number of valid bytes in `bytes`.
+    len: u32,
+}
+
+impl BuildId {
+    /// Reads the build ID from the `BLID` tag of `tlv`.
+    ///
+    /// Returns `EINVAL` if the tag is absent or empty, or if its value is longer than
+    /// [`BUILD_ID_MAX_LENGTH`] bytes.
+    pub(crate) fn from_tlv(tlv: &Tlv<'_>) -> Result<Self> {
+        let value = tlv.get_bytes(b"BLID")?;
+
+        let mut bytes = [0; BUILD_ID_MAX_LENGTH];
+        bytes
+            .get_mut(..value.len())
+            .ok_or(EINVAL)?
+            .copy_from_slice(value);
+
+        Ok(Self {
+            bytes,
+            len: u32::try_from(value.len())?,
+        })
+    }
+
+    /// Returns the ID, zero-padded to [`BUILD_ID_MAX_LENGTH`] bytes.
+    pub(crate) fn padded(&self) -> &[u8; BUILD_ID_MAX_LENGTH] {
+        &self.bytes
+    }
+
+    /// Returns the number of bytes in the ID.
+    pub(crate) fn len(&self) -> u32 {
+        self.len
+    }
+}
+
 /// The GSP firmware image, its signatures, and the GSP bootloader.
 #[pin_data]
 pub(crate) struct GspFirmware<'a> {
@@ -36,13 +79,16 @@ pub(crate) struct GspFirmware<'a> {
 impl<'a> GspFirmware<'a> {
     /// Loads the GSP firmware binaries, map them into `dev`'s address-space, and creates the page
     /// tables expected by the GSP bootloader to load it.
-    pub(crate) fn new(
+    ///
+    /// `gsp_tlv` is the TLV of the GSP firmware, which names the image file and carries the
+    /// signatures.
+    pub(crate) fn new<'tlv>(
         dev: &'a device::Device<device::Bound>,
         chipset: Chipset,
-    ) -> impl PinInit<Self, Error> + 'a {
+        gsp_tlv: &'tlv firmware::Firmware,
+    ) -> impl PinInit<Self, Error> + use<'a, 'tlv> {
         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())?;
             dev_dbg!(dev, "loaded gsp firmware v{}\n", tlv.get_string(b"VERS")?);
 
             let fw_vvec = tlv.load_file(dev, chipset)?;
drivers/gpu/nova-core/gpu.rs +1 -2
index cecd8e79430d..173c57179b39 100644
@@ -220,7 +220,6 @@ pub(crate) struct Spec {
     pub(crate) chipset: Chipset,
     /// Implementation field of `NV_PMC_BOOT_42`, which distinguishes this chipset from the other
     /// chipsets of its architecture.
-    #[expect(dead_code)]
     pub(crate) implementation: u8,
     revision: Revision,
 }
@@ -424,7 +423,7 @@ pub(crate) fn new<'a>(
 
                 vgpu: VgpuManager::new(pdev, spec.chipset, fsp.as_mut()),
 
-                gsp <- Gsp::new(pdev, bar),
+                gsp <- Gsp::new(pdev, *spec, bar),
 
                 // This member must be initialized last, so that the unload bundle can never be
                 // dropped from outside the constructed `GspResources`, and the unload sequence runs
drivers/gpu/nova-core/gsp.rs +182 -30

309 lines not on this page · raw message

drivers/gpu/nova-core/gsp/boot.rs +1 -1
index 5da3d134eec7..6f8f330a0297 100644
@@ -362,7 +362,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)?;
 
         let generic_bootloader = hal.generic_bootloader(dev, chipset, gsp_falcon.imem_size())?;
 
Signature · 1 line
2.55.0
#3 lore raw

PATCH 3/4 gpu: nova-core: gsp: print GMC command names in debug logs

In reply to John Hubbard

The GMC (GPU Management Controller) API names each command in the GMCAPI_COMMANDS enum of the firmware bindings, and a message carries the enum's numeric id.

The GMC send, receive and error lines printed the bare id, so a reader had to look 0x10001 up in the bindings to learn that it was GSP_INIT:

    GSP GMC: send: seq# 0, command_id=0x10001, length=0xf8

Print the name beside the id, from a type that wraps an id for formatting, so that the ids stay plain integers at the send and receive interfaces:

    GSP GMC: send: seq# 0, command=GSP_INIT (0x10001), length=0xf8
Assisted-by LLM
---
 drivers/gpu/nova-core/gsp/boot.rs |  9 ++--
 drivers/gpu/nova-core/gsp/cmdq.rs | 13 +++---
 drivers/gpu/nova-core/gsp/fw.rs   | 70 +++++++++++++++++++++++++++++++
 3 files changed, 82 insertions(+), 10 deletions(-)
drivers/gpu/nova-core/gsp/boot.rs +5 -4
index 6f8f330a0297..8848feebb9db 100644
@@ -42,6 +42,7 @@
         cmdq::Cmdq,
         commands,
         fw::{
+            GmcCommand,
             GspArgumentsPadded,
             GMCAPI_CMD_EXEC_GENERIC_BOOTLOADER,
             GMCAPI_CMD_EXEC_HS_BINARY, //
@@ -169,8 +170,8 @@ fn dispatch_gmc_boot_event(
             _ => {
                 dev_err!(
                     self.dev,
-                    "Unexpected GMC boot event: command_id={:#010x}\n",
-                    command_id
+                    "Unexpected GMC boot event: command={}\n",
+                    GmcCommand(command_id)
                 );
                 return Err(EINVAL);
             }
@@ -179,8 +180,8 @@ fn dispatch_gmc_boot_event(
         handled.and_then(|()| self.core_resume()).inspect_err(|e| {
             dev_err!(
                 self.dev,
-                "GMC boot event {:#010x} failed: {:?}\n",
-                command_id,
+                "GMC boot event {} failed: {:?}\n",
+                GmcCommand(command_id),
                 e
             );
         })
drivers/gpu/nova-core/gsp/cmdq.rs +7 -6
index dd0b3dfc6f37..2b53b1e6cebf 100644
@@ -52,6 +52,7 @@
     driver::Bar0,
     gsp::{
         fw::{
+            GmcCommand,
             GspGmcMsgElement,
             GspMsgElement,
             MsgFunction,
@@ -884,9 +885,9 @@ fn send_gmc(&mut self, command_id: u32, payload: &[u8], max_response_size: u32)
 
         dev_dbg!(
             &self.dev,
-            "GSP GMC: send: seq# {}, command_id=0x{:x}, length=0x{:x}\n",
+            "GSP GMC: send: seq# {}, command={}, length=0x{:x}\n",
             rpc_seq,
-            command_id,
+            GmcCommand(command_id),
             dst.header.length(),
         );
 
@@ -1063,9 +1064,9 @@ fn log_event(&self, function: Result<MsgFunction, u32>, seq: u32) {
     fn log_gmc_event(&self, header: &GspGmcMsgElement) {
         dev_warn!(
             &self.dev,
-            "GSP GMC: dropping unclaimed message (seq {}, command_id=0x{:x})\n",
+            "GSP GMC: dropping unclaimed message (seq {}, command={})\n",
             header.gmc.sequence,
-            header.gmc.command_id(),
+            GmcCommand(header.gmc.command_id()),
         );
     }
 
@@ -1269,9 +1270,9 @@ fn consume_element<R>(
             ),
             QueueElement::Gmc(message) => dev_dbg!(
                 &self.dev,
-                "GSP GMC: receive: seq# {}, command_id=0x{:x}, length=0x{:x}\n",
+                "GSP GMC: receive: seq# {}, command={}, length=0x{:x}\n",
                 message.header.gmc.sequence,
-                message.header.gmc.command_id(),
+                GmcCommand(message.header.gmc.command_id()),
                 message.header.length(),
             ),
         }
drivers/gpu/nova-core/gsp/fw.rs +70 -0

82 lines not on this page · raw message

Signature · 1 line
2.55.0
#4 lore raw

PATCH 4/4 gpu: nova-core: gsp: distinguish GMC events from responses in debug logs

In reply to John Hubbard

GSP-RM numbers its GMC events from bit 63 upward, apart from the driver's request numbers, and marks a response with a flag in the command word.

The GMC receive debug line printed the raw sequence and labeled every element a receive:

    GSP GMC: receive: seq# 9223372036854775808, command=EXEC_GENERIC_BOOTLOADER (0x10002), length=0xb0
    GSP GMC: receive: seq# 0, command=GSP_INIT (0x10001), length=0x450

Print the sequence with bit 63 cleared, and label each received element an event or a response by the flag:

    GSP GMC: event: seq# 0, command=EXEC_GENERIC_BOOTLOADER (0x10002), length=0xb0
    GSP GMC: response: seq# 0, command=GSP_INIT (0x10001), length=0x450
Assisted-by LLM
---
 drivers/gpu/nova-core/gsp/cmdq.rs | 35 +++++++++++++++++++++++--------
 drivers/gpu/nova-core/gsp/fw.rs   | 11 +++++++++-
 2 files changed, 36 insertions(+), 10 deletions(-)
drivers/gpu/nova-core/gsp/cmdq.rs +26 -9
index 2b53b1e6cebf..530ad51304ce 100644
@@ -1062,10 +1062,17 @@ fn log_event(&self, function: Result<MsgFunction, u32>, seq: u32) {
     /// Logs a GMC message that no caller is waiting for: a response to a request that has already
     /// timed out, or an event that arrives outside the boot sequence.
     fn log_gmc_event(&self, header: &GspGmcMsgElement) {
+        let kind = if header.gmc.is_response() {
+            "response"
+        } else {
+            "event"
+        };
+
         dev_warn!(
             &self.dev,
-            "GSP GMC: dropping unclaimed message (seq {}, command={})\n",
-            header.gmc.sequence,
+            "GSP GMC: dropping unclaimed {} (seq# {}, command={})\n",
+            kind,
+            header.gmc.sequence_number(),
             GmcCommand(header.gmc.command_id()),
         );
     }
@@ -1268,13 +1275,23 @@ fn consume_element<R>(
                 message.header.function(),
                 message.header.length(),
             ),
-            QueueElement::Gmc(message) => dev_dbg!(
-                &self.dev,
-                "GSP GMC: receive: seq# {}, command={}, length=0x{:x}\n",
-                message.header.gmc.sequence,
-                GmcCommand(message.header.gmc.command_id()),
-                message.header.length(),
-            ),
+            QueueElement::Gmc(message) => {
+                let gmc = &message.header.gmc;
+                let kind = if gmc.is_response() {
+                    "response"
+                } else {
+                    "event"
+                };
+
+                dev_dbg!(
+                    &self.dev,
+                    "GSP GMC: {}: seq# {}, command={}, length=0x{:x}\n",
+                    kind,
+                    gmc.sequence_number(),
+                    GmcCommand(gmc.command_id()),
+                    message.header.length(),
+                )
+            }
         }
 
         let result = f(self, element);
drivers/gpu/nova-core/gsp/fw.rs +10 -1
index 106d71f95fc3..ec474a175ee6 100644
@@ -729,6 +729,10 @@ pub(crate) struct GmcApiHeader {
 /// Flag bit of [`GmcApiHeader::command`] that GSP-RM sets on a response.
 const GMCAPI_COMMAND_FLAGS_RESPONSE: u32 = 0x0100_0000;
 
+/// First sequence number of the space that GSP-RM numbers its events from, so that an event's
+/// number cannot collide with a request's. Requests are numbered from zero.
+const GMC_EVENT_SEQUENCE_BASE: u64 = 1 << 63;
+
 /// GMC request that carries the system information and registry keys to GSP-RM. GSP-RM answers
 /// it with the static GPU configuration once it has finished starting.
 pub(crate) const GMCAPI_CMD_GSP_INIT: u32 = bindings::GMCAPI_COMMANDS_GMCAPI_CMD_GSP_INIT;
@@ -776,10 +780,15 @@ pub(crate) fn command_id(&self) -> u32 {
     }
 
     /// Returns `true` if GSP-RM sent this header as a response rather than an event.
-    fn is_response(&self) -> bool {
+    pub(crate) fn is_response(&self) -> bool {
         self.command & GMCAPI_COMMAND_FLAGS_RESPONSE != 0
     }
 
+    /// Returns the sequence number without the bit that marks an event's sequence space.
+    pub(crate) fn sequence_number(&self) -> u64 {
+        self.sequence & !GMC_EVENT_SEQUENCE_BASE
+    }
+
     /// Returns the `NV_STATUS` that a response carries.
     ///
     /// The value is meaningful only when [`Self::is_response`] is `true`. In a request, the same
Signature · 1 line
2.55.0