mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v4 0/6] gpu: nova-core: gsp: preparatory patches for the r000 firmware
@ 2026-12-01  8:15 Alexandre Courbot
  2026-12-01  8:15 ` [PATCH v4 1/6] gpu: nova-core: gsp: add the r000 queue element header Alexandre Courbot
                   ` (6 more replies)
  0 siblings, 7 replies; 11+ messages in thread
From: Alexandre Courbot @ 2026-12-01  8:15 UTC (permalink / raw)
  To: Danilo Krummrich, Alice Ryhl, David Airlie, Simona Vetter
  Cc: John Hubbard, Alistair Popple, Timur Tabi, Eliot Courtney,
	Zhi Wang, nova-gpu, dri-devel, linux-kernel, Alexandre Courbot

These patches come from John's series switching nova-core to the r000
GSP firmware [1]. They do not depend on the switch itself, and both the
rest of the r000 work and the vGPU series build on them, so I would
like to get them in soon.

Patch 1 adds the r000 queue element header. It has no user yet and was
previously posted on its own [2].

Patch 2 moves the loading of the file referenced by a TLV into the TLV
parser, so the r000 ucodes loader can use it.

Patches 3 to 5 prepare the log buffers code for the extra buffers of
r000, without functional change. Patch 6 adds the LIBOS3 log buffers and
the state monitor buffer. These buffers are valid for r570, which still
boots with them.

Based on drm-rust-next.

[1] https://lore.kernel.org/20260918010719.1176945-1-jhubbard@nvidia.com
[2] https://lore.kernel.org/20261117-msgelement-v1-1-b918ffae5e7b@nvidia.com

Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
Changes in v4:
- Rebase on drm-rust-next, dropping the 6 applied patches.
- Move the TLV loading patch before the log buffer patches.
- Add patch 6 (LIBOS3 log buffers and state monitor buffer).
- Link to v3: https://patch.msgid.link/20261130-nova-r000-staging-v3-0-55aceca8e958@nvidia.com

Changes in v3:
- Move MCTP_MAGIC to an associated const. (Eliot)
- Drop unneeded `#[allow(dead_code)]`. (Eliot)
- Use `assert` instead of `static_assert` in const block. (Eliot)
- Use `from_safe_cast` instead of `u32_as_usize`.
- Avoid unneeded saturating add. (Eliot)
- Remove unneeded `u32::from`. (Eliot)
- Convert `core::result::Result` to just `Result` when moving code. (Eliot)
- Use writer to write the init arguments. (Eliot)
- Deconstruct `self` in `is_empty`. (Eliot)
- Remove unneeded `map_err` in the TLV code. (Eliot)
- Link to v2: https://patch.msgid.link/20261130-nova-r000-staging-v2-0-afd079026a61@nvidia.com

Changes in v2:
- Use an anonymous const for the queue element header checks. (Gary)
- Import offset_of for the queue element header checks. (Gary)
- Derive the zerocopy traits on the queue element header. (Gary)
- Add patches 5 to 11 (log buffers, msgq TX header, TLV loading).
- Use the defined constants in more places on patch 4.
- Link to v1: https://patch.msgid.link/20261127-nova-r000-staging-v1-0-4eaf6e3c0942@nvidia.com

---
John Hubbard (6):
      gpu: nova-core: gsp: add the r000 queue element header
      gpu: nova-core: firmware: tlv: add method to load the file referenced by a TLV
      gpu: nova-core: gsp: logbuffer: add LogBuffers::init_arguments()
      gpu: nova-core: gsp: logbuffer: make LogBuffer generic over its size
      gpu: nova-core: gsp: logbuffer: add RetainedLogBuffers::is_empty()
      gpu: nova-core: gsp: logbuffer: add LIBOS3 log buffers and state monitor buffer

 drivers/gpu/nova-core/firmware/gsp.rs            |  15 +-
 drivers/gpu/nova-core/firmware/tlv.rs            |  40 ++++-
 drivers/gpu/nova-core/gsp.rs                     |  60 +++++---
 drivers/gpu/nova-core/gsp/fw.rs                  | 177 ++++++++++++++++++++++-
 drivers/gpu/nova-core/gsp/fw/r000_00/bindings.rs |  97 +++++++++++++
 drivers/gpu/nova-core/gsp/logbuffer.rs           | 127 ++++++++++++++--
 drivers/gpu/nova-core/mctp.rs                    |  27 +++-
 7 files changed, 489 insertions(+), 54 deletions(-)
---
base-commit: 3adb5e862907afa3d6793e06b882937cce33e6d0
change-id: 20261127-nova-r000-staging-905c7f559e47

Best regards,
--  
Alexandre Courbot <acourbot@nvidia.com>


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v4 1/6] gpu: nova-core: gsp: add the r000 queue element header
  2026-12-01  8:15 [PATCH v4 0/6] gpu: nova-core: gsp: preparatory patches for the r000 firmware Alexandre Courbot
@ 2026-12-01  8:15 ` Alexandre Courbot
  2026-12-01 14:12   ` Danilo Krummrich
  2026-12-01  8:15 ` [PATCH v4 2/6] gpu: nova-core: firmware: tlv: add method to load the file referenced by a TLV Alexandre Courbot
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 11+ messages in thread
From: Alexandre Courbot @ 2026-12-01  8:15 UTC (permalink / raw)
  To: Danilo Krummrich, Alice Ryhl, David Airlie, Simona Vetter
  Cc: John Hubbard, Alistair Popple, Timur Tabi, Eliot Courtney,
	Zhi Wang, nova-gpu, dri-devel, linux-kernel, Alexandre Courbot

From: John Hubbard <jhubbard@nvidia.com>

The upcoming r000 firmware uses a new queue element header that includes
MCTP and NVDM headers describing the type of message (RPC or GMC) that
follows.

Add that header as the `QueueElementHeader` type, along with the two
NVDM types that the GSP queues use and the MCTP version and NVDM vendor
checks that validating it requires.

The type is written out field by field rather than wrapped around the
generated binding, as `GSP_MSG_QUEUE_ELEMENT` keeps a 16-byte encryption
tag, only used with confidential computing, in a union with its last two
fields, making the binding 16 bytes larger than what the GSP expects on
the queues. Static assertions check every field offset and the size of
the type against the binding.

The header has no user yet: it replaces `GspMsgElement` at the transport
level in a later patch that switches to the r000 firmware, and is built
as dead code until then.

Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Co-developed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Reviewed-by: Eliot Courtney <ecourtney@nvidia.com>
---
 drivers/gpu/nova-core/gsp/fw.rs                  | 177 ++++++++++++++++++++++-
 drivers/gpu/nova-core/gsp/fw/r000_00/bindings.rs |  97 +++++++++++++
 drivers/gpu/nova-core/mctp.rs                    |  27 +++-
 3 files changed, 298 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/nova-core/gsp/fw.rs b/drivers/gpu/nova-core/gsp/fw.rs
index e3b8f77b1869..86cf62edec2b 100644
--- a/drivers/gpu/nova-core/gsp/fw.rs
+++ b/drivers/gpu/nova-core/gsp/fw.rs
@@ -33,6 +33,11 @@
     },
 };
 
+use zerocopy_derive::{
+    Immutable,
+    KnownLayout, //
+};
+
 use crate::{
     bounded_enum,
     fb::{
@@ -51,6 +56,11 @@
         },
         GSP_PAGE_SIZE,
     },
+    mctp::{
+        MctpHeader,
+        NvdmHeader,
+        NvdmType, //
+    },
     num::{
         self,
         FromSafeCast, //
@@ -830,7 +840,7 @@ pub(crate) fn msg_length(&self) -> usize {
         size_of::<Self>() + self.rpc_header().rpc_length()
     }
 
-    /// Returns the number of elements (i.e. memory pages) used by this message.
+    /// Returns the number of slots (i.e. memory pages) used by this message.
     pub(crate) fn element_count(&self) -> u32 {
         self.inner.elemCount
     }
@@ -896,6 +906,171 @@ pub(crate) fn function(&self) -> Result<MsgFunction, u32> {
     }
 }
 
+/// Header opening every element of the r000 GSP queues.
+///
+/// A queue element is laid out as follows:
+///
+/// ```text
+///     +------------------------------------+
+///     | Queue element header               |  QueueElementHeader: MCTP magic, element length,
+///     |                                    |  MCTP header, NVDM header, message length.
+///     +------------------------------------+
+///     | Message header                     |  RPC header or GMC API header. The NVDM type
+///     |                                    |  selects between the two.
+///     +------------------------------------+
+///     | Payload                            |  Message-specific data.
+///     +------------------------------------+
+/// ```
+///
+/// This is the `noEncryption` layout of the `GSP_MSG_QUEUE_ELEMENT` binding. That binding keeps
+/// a 16-byte encryption tag, used only with confidential computing, in a union with the two
+/// trailing fields of the queue element header, so wrapping the binding would make every element
+/// 16 bytes larger than what the GSP expects. The fields are therefore declared again here, with
+/// their offsets checked against the binding.
+#[repr(C)]
+#[derive(FromBytes, IntoBytes, Immutable, KnownLayout)]
+pub(crate) struct QueueElementHeader {
+    /// Always [`Self::MCTP_MAGIC`].
+    mctp_magic: u32,
+    /// Length in bytes of the whole element, this header included.
+    ///
+    /// Under confidential computing the GSP pads elements out to whole queue slots, so this can
+    /// be larger than `nvdm_payload_size` plus the size of this header, but never smaller.
+    mctp_payload_size: u32,
+    /// MCTP transport header of the element.
+    mctp_header: MctpHeader,
+    /// NVDM header of the message.
+    nvdm_header: NvdmHeader,
+    /// Length in bytes of the message following this header: the message header and its
+    /// payload.
+    nvdm_payload_size: u32,
+    reserved: u32,
+}
+
+// Static validation of `QueueElementHeader` against its bindings type.
+const _: () = {
+    use core::mem::offset_of;
+
+    // Offsets of `QueueElementHeader`'s fields
+
+    assert!(
+        offset_of!(QueueElementHeader, mctp_magic)
+            == offset_of!(r000_00::GSP_MSG_QUEUE_ELEMENT, mctpMagic)
+    );
+    assert!(
+        offset_of!(QueueElementHeader, mctp_payload_size)
+            == offset_of!(r000_00::GSP_MSG_QUEUE_ELEMENT, mctpPayloadSize)
+    );
+    assert!(
+        offset_of!(QueueElementHeader, mctp_header)
+            == offset_of!(r000_00::GSP_MSG_QUEUE_ELEMENT, mctpHeader)
+    );
+    assert!(
+        offset_of!(QueueElementHeader, nvdm_header)
+            == offset_of!(r000_00::GSP_MSG_QUEUE_ELEMENT, nvdmHeader)
+    );
+
+    /// The `noEncryption` member of the union of `GSP_MSG_QUEUE_ELEMENT`, which holds the two
+    /// trailing fields of [`QueueElementHeader`].
+    type QueueElementNoEncryption = r000_00::GSP_MSG_QUEUE_ELEMENT__bindgen_ty_1__bindgen_ty_2;
+
+    // Offsets of fields under [`QueueElementNoEncryption`] within `GSP_MSG_QUEUE_ELEMENT`.
+
+    const QUEUE_ELEMENT_NO_ENCRYPTION_OFFSET: usize =
+        offset_of!(r000_00::GSP_MSG_QUEUE_ELEMENT, __bindgen_anon_1)
+            + offset_of!(r000_00::GSP_MSG_QUEUE_ELEMENT__bindgen_ty_1, noEncryption);
+
+    assert!(
+        offset_of!(QueueElementHeader, nvdm_payload_size)
+            == QUEUE_ELEMENT_NO_ENCRYPTION_OFFSET
+                + offset_of!(QueueElementNoEncryption, nvdmPayloadSize)
+    );
+    assert!(
+        offset_of!(QueueElementHeader, reserved)
+            == QUEUE_ELEMENT_NO_ENCRYPTION_OFFSET + offset_of!(QueueElementNoEncryption, reserved)
+    );
+
+    // Ensure the size of `QueueElementHeader` matches the `noEncryption` layout.
+
+    assert!(
+        size_of::<QueueElementHeader>()
+            == QUEUE_ELEMENT_NO_ENCRYPTION_OFFSET + size_of::<QueueElementNoEncryption>()
+    );
+};
+
+#[expect(dead_code)]
+impl QueueElementHeader {
+    /// First word of every r000 queue element: `"MCTP"` in ASCII.
+    const MCTP_MAGIC: u32 = 0x4D43_5450;
+
+    /// Creates the queue element header of an element carrying a message of NVDM type `nvdm_type`
+    /// and `message_len` bytes, message header included.
+    ///
+    /// # Errors
+    ///
+    /// - `EOVERFLOW` if a length does not fit its 32-bit field.
+    pub(crate) fn init(nvdm_type: NvdmType, message_len: usize) -> impl Init<Self, Error> {
+        try_init!(QueueElementHeader {
+            mctp_magic: Self::MCTP_MAGIC,
+            mctp_payload_size: size_of::<Self>()
+                .checked_add(message_len)
+                .ok_or(EOVERFLOW)?
+                .try_into()
+                .map_err(|_| EOVERFLOW)?,
+            mctp_header: MctpHeader::single_packet(),
+            nvdm_header: NvdmHeader::new(nvdm_type),
+            nvdm_payload_size: message_len.try_into().map_err(|_| EOVERFLOW)?,
+            reserved: 0,
+        })
+    }
+
+    /// Returns the length of the whole element, this header included.
+    pub(crate) fn element_len(&self) -> usize {
+        usize::from_safe_cast(self.mctp_payload_size)
+    }
+
+    /// Returns the length of the message following this header, message header included.
+    pub(crate) fn message_len(&self) -> usize {
+        usize::from_safe_cast(self.nvdm_payload_size)
+    }
+
+    /// Returns the number of slots (i.e. memory pages) used by this element.
+    pub(crate) fn element_count(&self) -> u32 {
+        self.mctp_payload_size.div_ceil(cv!(GSP_PAGE_SIZE))
+    }
+
+    /// Returns the NVDM type of the message following this header, or `EINVAL` if it is not a
+    /// known one.
+    pub(crate) fn nvdm_type(&self) -> Result<NvdmType> {
+        self.nvdm_header.nvdm_type()
+    }
+
+    /// Validates the framing of the element.
+    ///
+    /// # Errors
+    ///
+    /// - `EIO` if the magic, the MCTP version or the NVDM vendor is wrong, or if the element
+    ///   length is smaller than this header and the message together, or larger than the
+    ///   maximum element size.
+    pub(crate) fn validate(&self) -> Result {
+        if self.mctp_magic != Self::MCTP_MAGIC
+            || !self.mctp_header.has_expected_version()
+            || !self.nvdm_header.has_nvidia_vendor()
+        {
+            return Err(EIO);
+        }
+
+        let element_len = self.element_len();
+        if element_len < size_of::<Self>() + self.message_len()
+            || element_len > GSP_MSG_QUEUE_ELEMENT_SIZE_MAX
+        {
+            return Err(EIO);
+        }
+
+        Ok(())
+    }
+}
+
 bounded_enum! {
     /// Commands of the GMC API.
     #[derive(Debug, Clone, Copy, PartialEq, Eq)]
diff --git a/drivers/gpu/nova-core/gsp/fw/r000_00/bindings.rs b/drivers/gpu/nova-core/gsp/fw/r000_00/bindings.rs
index 552299c98169..959e397c26aa 100644
--- a/drivers/gpu/nova-core/gsp/fw/r000_00/bindings.rs
+++ b/drivers/gpu/nova-core/gsp/fw/r000_00/bindings.rs
@@ -30,6 +30,49 @@ fn fmt(&self, fmt: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
         fmt.write_str("__IncompleteArrayField")
     }
 }
+#[repr(C)]
+pub struct __BindgenUnionField<T>(::core::marker::PhantomData<T>);
+impl<T> __BindgenUnionField<T> {
+    #[inline]
+    pub const fn new() -> Self {
+        __BindgenUnionField(::core::marker::PhantomData)
+    }
+    #[inline]
+    pub unsafe fn as_ref(&self) -> &T {
+        ::core::mem::transmute(self)
+    }
+    #[inline]
+    pub unsafe fn as_mut(&mut self) -> &mut T {
+        ::core::mem::transmute(self)
+    }
+}
+impl<T> ::core::default::Default for __BindgenUnionField<T> {
+    #[inline]
+    fn default() -> Self {
+        Self::new()
+    }
+}
+impl<T> ::core::clone::Clone for __BindgenUnionField<T> {
+    #[inline]
+    fn clone(&self) -> Self {
+        *self
+    }
+}
+impl<T> ::core::marker::Copy for __BindgenUnionField<T> {}
+impl<T> ::core::fmt::Debug for __BindgenUnionField<T> {
+    fn fmt(&self, fmt: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
+        fmt.write_str("__BindgenUnionField")
+    }
+}
+impl<T> ::core::hash::Hash for __BindgenUnionField<T> {
+    fn hash<H: ::core::hash::Hasher>(&self, _state: &mut H) {}
+}
+impl<T> ::core::cmp::PartialEq for __BindgenUnionField<T> {
+    fn eq(&self, _other: &__BindgenUnionField<T>) -> bool {
+        true
+    }
+}
+impl<T> ::core::cmp::Eq for __BindgenUnionField<T> {}
 pub type __u8 = ffi::c_uchar;
 pub type __u16 = ffi::c_ushort;
 pub type __u32 = ffi::c_uint;
@@ -39,6 +82,60 @@ fn fmt(&self, fmt: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
 pub type u32_ = __u32;
 pub type u64_ = __u64;
 #[repr(C)]
+#[derive(Debug, Default, Copy, Clone, MaybeZeroable)]
+pub struct GSP_MSG_QUEUE_ENCRYPTION_TAG {
+    pub authTagBuffer: [u8_; 16usize],
+}
+#[repr(C)]
+#[derive(MaybeZeroable)]
+pub struct GSP_MSG_QUEUE_ELEMENT {
+    pub mctpMagic: u32_,
+    pub mctpPayloadSize: u32_,
+    pub mctpHeader: u32_,
+    pub nvdmHeader: u32_,
+    pub __bindgen_anon_1: GSP_MSG_QUEUE_ELEMENT__bindgen_ty_1,
+}
+#[repr(C)]
+#[derive(MaybeZeroable)]
+pub struct GSP_MSG_QUEUE_ELEMENT__bindgen_ty_1 {
+    pub withEncryption: __BindgenUnionField<GSP_MSG_QUEUE_ELEMENT__bindgen_ty_1__bindgen_ty_1>,
+    pub noEncryption: __BindgenUnionField<GSP_MSG_QUEUE_ELEMENT__bindgen_ty_1__bindgen_ty_2>,
+    pub bindgen_union_field: [u32; 6usize],
+}
+#[repr(C)]
+#[derive(Debug, Default, MaybeZeroable)]
+pub struct GSP_MSG_QUEUE_ELEMENT__bindgen_ty_1__bindgen_ty_1 {
+    pub encryptionTag: GSP_MSG_QUEUE_ENCRYPTION_TAG,
+    pub nvdmPayloadSize: u32_,
+    pub reserved: u32_,
+    pub payload: __IncompleteArrayField<u8_>,
+}
+#[repr(C)]
+#[derive(Debug, Default, MaybeZeroable)]
+pub struct GSP_MSG_QUEUE_ELEMENT__bindgen_ty_1__bindgen_ty_2 {
+    pub nvdmPayloadSize: u32_,
+    pub reserved: u32_,
+    pub payload: __IncompleteArrayField<u8_>,
+}
+impl Default for GSP_MSG_QUEUE_ELEMENT__bindgen_ty_1 {
+    fn default() -> Self {
+        let mut s = ::core::mem::MaybeUninit::<Self>::uninit();
+        unsafe {
+            ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
+            s.assume_init()
+        }
+    }
+}
+impl Default for GSP_MSG_QUEUE_ELEMENT {
+    fn default() -> Self {
+        let mut s = ::core::mem::MaybeUninit::<Self>::uninit();
+        unsafe {
+            ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
+            s.assume_init()
+        }
+    }
+}
+#[repr(C)]
 #[derive(MaybeZeroable)]
 pub struct GMCAPI_HEADER {
     pub command: u32_,
diff --git a/drivers/gpu/nova-core/mctp.rs b/drivers/gpu/nova-core/mctp.rs
index f62e79f56b05..e1331337f9af 100644
--- a/drivers/gpu/nova-core/mctp.rs
+++ b/drivers/gpu/nova-core/mctp.rs
@@ -13,6 +13,11 @@
     prelude::*, //
 };
 
+use zerocopy_derive::{
+    Immutable,
+    KnownLayout, //
+};
+
 use crate::{
     bounded_enum,
     num, //
@@ -28,11 +33,16 @@ pub(crate) enum NvdmType with TryFrom<Bounded<u32, 8>> {
         Cot = 0x14,
         /// FSP command response.
         FspResponse = 0x15,
+        /// RPC message to or from GSP-RM.
+        RmRpc = 0x25,
+        /// GMC (GPU Management Controller) API message to or from GSP-RM.
+        GmcApi = 0x26,
     }
 }
 
 bitfield! {
     /// MCTP transport header for NVIDIA firmware messages.
+    #[derive(FromBytes, IntoBytes, Immutable, KnownLayout)]
     pub(crate) struct MctpHeader(u32) {
         /// Start-of-message bit.
         31:31 som;
@@ -67,6 +77,11 @@ pub(crate) fn single_packet() -> Self {
     pub(crate) fn is_single_packet(self) -> bool {
         self.som().into_bool() && self.eom().into_bool()
     }
+
+    /// Returns `true` if this MCTP header carries the version that this driver uses.
+    pub(crate) fn has_expected_version(self) -> bool {
+        self.version() == Self::VERSION
+    }
 }
 
 /// MCTP message type for PCI vendor-defined messages.
@@ -74,6 +89,7 @@ pub(crate) fn is_single_packet(self) -> bool {
 
 bitfield! {
     /// NVIDIA Vendor-Defined Message header over MCTP.
+    #[derive(FromBytes, IntoBytes, Immutable, KnownLayout)]
     pub(crate) struct NvdmHeader(u32) {
         /// NVDM message type.
         31:24 nvdm_type ?=> NvdmType;
@@ -93,10 +109,17 @@ pub(crate) fn new(nvdm_type: NvdmType) -> Self {
             .with_nvdm_type(nvdm_type)
     }
 
-    /// Validates this header against the expected NVIDIA NVDM format and type.
-    pub(crate) fn validate(self, expected_type: NvdmType) -> bool {
+    /// Returns `true` if this NVDM header belongs to a PCI vendor-defined message from NVIDIA.
+    ///
+    /// The GPU firmware only ever sends such messages, so a mismatch is a sign of corruption.
+    pub(crate) fn has_nvidia_vendor(self) -> bool {
         u8::from(self.msg_type()) == MSG_TYPE_VENDOR_PCI
             && u16::from(self.vendor_id()) == Vendor::NVIDIA.as_raw()
+    }
+
+    /// Validates this header against the expected NVIDIA NVDM format and type.
+    pub(crate) fn validate(self, expected_type: NvdmType) -> bool {
+        self.has_nvidia_vendor()
             && matches!(self.nvdm_type(), Ok(nvdm_type) if nvdm_type == expected_type)
     }
 }

-- 
2.56.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v4 2/6] gpu: nova-core: firmware: tlv: add method to load the file referenced by a TLV
  2026-12-01  8:15 [PATCH v4 0/6] gpu: nova-core: gsp: preparatory patches for the r000 firmware Alexandre Courbot
  2026-12-01  8:15 ` [PATCH v4 1/6] gpu: nova-core: gsp: add the r000 queue element header Alexandre Courbot
@ 2026-12-01  8:15 ` Alexandre Courbot
  2026-12-01  8:15 ` [PATCH v4 3/6] gpu: nova-core: gsp: logbuffer: add LogBuffers::init_arguments() Alexandre Courbot
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Alexandre Courbot @ 2026-12-01  8:15 UTC (permalink / raw)
  To: Danilo Krummrich, Alice Ryhl, David Airlie, Simona Vetter
  Cc: John Hubbard, Alistair Popple, Timur Tabi, Eliot Courtney,
	Zhi Wang, nova-gpu, dri-devel, linux-kernel, Alexandre Courbot

From: John Hubbard <jhubbard@nvidia.com>

The GSP firmware TLV names a separate file in its FILE tag and gives
that file's length in its SIZE tag. The GSP firmware wrapper reads the
two tags and loads the file itself, so no other loader can share that
code.

Move it into the TLV parser as `Tlv::load_file()`, which also fails with
ENODATA when SIZE is zero.

The r000 ucodes loader will be the second user of this.

Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Reviewed-by: Eliot Courtney <ecourtney@nvidia.com>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
 drivers/gpu/nova-core/firmware/gsp.rs | 15 +++----------
 drivers/gpu/nova-core/firmware/tlv.rs | 40 ++++++++++++++++++++++++++++++++---
 2 files changed, 40 insertions(+), 15 deletions(-)

diff --git a/drivers/gpu/nova-core/firmware/gsp.rs b/drivers/gpu/nova-core/firmware/gsp.rs
index 341a8b19aa38..a2db7b6ba131 100644
--- a/drivers/gpu/nova-core/firmware/gsp.rs
+++ b/drivers/gpu/nova-core/firmware/gsp.rs
@@ -6,9 +6,7 @@
         Coherent,
         DmaAddress, //
     },
-    firmware,
-    prelude::*,
-    str::CString,
+    prelude::*, //
 };
 
 use crate::{
@@ -20,8 +18,7 @@
             Tlv,
         },
     },
-    gpu::Chipset,
-    num::FromSafeCast,
+    gpu::Chipset, //
 };
 
 /// The GSP firmware image, its signatures, and the GSP bootloader.
@@ -48,13 +45,7 @@ pub(crate) fn new(
             let tlv = Tlv::new(firmware.data())?;
             dev_dbg!(dev, "loaded gsp firmware v{}\n", tlv.get_string(b"VERS")?);
 
-            let size = usize::from_safe_cast(tlv.get_u32(b"SIZE")?);
-            let mut fw_vvec = VVec::zeroed(size, GFP_KERNEL).map_err(|_| ENOMEM)?;
-
-            let chip_name = chipset.name();
-            let file = tlv.get_string(b"FILE")?;
-            let filename = CString::try_from_fmt(fmt!("nvidia/{chip_name}/gsp/{file}"))?;
-            firmware::request_into_buf(&filename, dev, fw_vvec.as_mut_slice())?;
+            let fw_vvec = tlv.load_file(dev, chipset)?;
 
             let signatures = Coherent::from_slice(dev, tlv.get_bytes(b"SIGN")?, GFP_KERNEL)?;
 
diff --git a/drivers/gpu/nova-core/firmware/tlv.rs b/drivers/gpu/nova-core/firmware/tlv.rs
index 7b879f13a61e..0c2cdd2e5a04 100644
--- a/drivers/gpu/nova-core/firmware/tlv.rs
+++ b/drivers/gpu/nova-core/firmware/tlv.rs
@@ -4,6 +4,7 @@
 use kernel::{
     device,
     firmware,
+    fmt,
     prelude::*,
     str::CString, //
 };
@@ -13,15 +14,18 @@
     num::*, //
 };
 
+/// Returns the path of `file` in `chipset`'s GSP firmware directory.
+fn gsp_firmware_path(chipset: gpu::Chipset, file: fmt::Arguments<'_>) -> Result<CString> {
+    CString::try_from_fmt(fmt!("nvidia/{}/gsp/{}", chipset.name(), file))
+}
+
 /// Requests the GPU firmware TLV `name` suitable for `chipset`.
 pub(crate) fn request_tlv(
     dev: &device::Device,
     chipset: gpu::Chipset,
     name: &str,
 ) -> Result<firmware::Firmware> {
-    let chip_name = chipset.name();
-
-    let filename = CString::try_from_fmt(fmt!("nvidia/{chip_name}/gsp/{name}.tlv"))?;
+    let filename = gsp_firmware_path(chipset, fmt!("{name}.tlv"))?;
 
     dev_dbg!(dev, "loading firmware image {:?}\n", &filename);
 
@@ -198,6 +202,36 @@ fn iter(&self) -> TlvIter<'_, 'a> {
         self.iter().find(|b| b.tag == *tag).ok_or(EINVAL)
     }
 
+    /// Loads the file that the `FILE` tag names from `chipset`'s GSP firmware directory.
+    ///
+    /// The `SIZE` tag gives the file's length, and the returned buffer is that long.
+    ///
+    /// # Errors
+    ///
+    /// - `EINVAL` if `FILE` or `SIZE` is absent, or `FILE` does not hold a valid string.
+    /// - `ENODATA` if `SIZE` is zero.
+    /// - `ENOMEM` if the buffer cannot be allocated.
+    ///
+    /// Errors from the firmware request are propagated as-is.
+    pub(crate) fn load_file(
+        &self,
+        dev: &device::Device,
+        chipset: gpu::Chipset,
+    ) -> Result<VVec<u8>> {
+        let file = self.get_string(b"FILE")?;
+        let path = gsp_firmware_path(chipset, fmt!("{file}"))?;
+
+        let size = usize::from_safe_cast(self.get_u32(b"SIZE")?);
+        if size == 0 {
+            return Err(ENODATA);
+        }
+
+        let mut data = VVec::zeroed(size, GFP_KERNEL)?;
+        firmware::request_into_buf(&path, dev, data.as_mut_slice())?;
+
+        Ok(data)
+    }
+
     /// Return a slice of bytes.
     ///
     /// Returns `EINVAL` if the value is empty.

-- 
2.56.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v4 3/6] gpu: nova-core: gsp: logbuffer: add LogBuffers::init_arguments()
  2026-12-01  8:15 [PATCH v4 0/6] gpu: nova-core: gsp: preparatory patches for the r000 firmware Alexandre Courbot
  2026-12-01  8:15 ` [PATCH v4 1/6] gpu: nova-core: gsp: add the r000 queue element header Alexandre Courbot
  2026-12-01  8:15 ` [PATCH v4 2/6] gpu: nova-core: firmware: tlv: add method to load the file referenced by a TLV Alexandre Courbot
@ 2026-12-01  8:15 ` Alexandre Courbot
  2026-12-01 14:22   ` Danilo Krummrich
  2026-12-01  8:15 ` [PATCH v4 4/6] gpu: nova-core: gsp: logbuffer: make LogBuffer generic over its size Alexandre Courbot
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 11+ messages in thread
From: Alexandre Courbot @ 2026-12-01  8:15 UTC (permalink / raw)
  To: Danilo Krummrich, Alice Ryhl, David Airlie, Simona Vetter
  Cc: John Hubbard, Alistair Popple, Timur Tabi, Eliot Courtney,
	Zhi Wang, nova-gpu, dri-devel, linux-kernel, Alexandre Courbot

From: John Hubbard <jhubbard@nvidia.com>

`Gsp::new()` names each log buffer in the init argument array itself,
which requires the buffers to be visible outside of their module.

Move that code into `LogBuffers::init_arguments()`, using a new
`LibosInitArgs` writer type to fill the arguments while transparently
keeping track of the current position.

No functional change.

Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Co-developed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Reviewed-by: Eliot Courtney <ecourtney@nvidia.com>
---
 drivers/gpu/nova-core/gsp.rs           | 57 +++++++++++++++++++++-------------
 drivers/gpu/nova-core/gsp/logbuffer.rs | 21 +++++++++++--
 2 files changed, 54 insertions(+), 24 deletions(-)

diff --git a/drivers/gpu/nova-core/gsp.rs b/drivers/gpu/nova-core/gsp.rs
index bf0028e52e3c..28bd76626cf6 100644
--- a/drivers/gpu/nova-core/gsp.rs
+++ b/drivers/gpu/nova-core/gsp.rs
@@ -98,6 +98,38 @@ fn init(view: CoherentView<'_, Self>, start: DmaAddress) -> Result<()> {
     }
 }
 
+/// Writer for the `LibosMemoryRegionInitArgument` array passed to the GSP bootloader.
+struct LibosInitArgs<'a> {
+    buf: CoherentBox<'a, [LibosMemoryRegionInitArgument]>,
+    len: usize,
+}
+
+impl<'a> LibosInitArgs<'a> {
+    /// Allocates a zeroed `LibosMemoryRegionInitArgument` array for `dev`.
+    fn new(dev: &'a device::Device<device::Bound>) -> Result<Self> {
+        Ok(Self {
+            buf: CoherentBox::zeroed_slice(
+                dev,
+                GSP_PAGE_SIZE / size_of::<LibosMemoryRegionInitArgument>(),
+                GFP_KERNEL,
+            )?,
+            len: 0,
+        })
+    }
+
+    /// Appends an entry to the array.
+    fn push(&mut self, arg: impl Init<LibosMemoryRegionInitArgument>) -> Result {
+        self.buf.init_at(self.len, arg)?;
+        self.len += 1;
+        Ok(())
+    }
+
+    /// Consumes the writer and returns the underlying coherent DMA allocation.
+    fn finish(self) -> Coherent<'a, [LibosMemoryRegionInitArgument]> {
+        self.buf.into()
+    }
+}
+
 /// GSP runtime data.
 #[pin_data]
 pub(crate) struct Gsp<'gsp> {
@@ -131,27 +163,10 @@ pub(crate) fn new(
                 cmdq <- Cmdq::new(dev, bar),
                 rmargs: Coherent::init(dev, GFP_KERNEL, GspArgumentsPadded::new(&cmdq))?,
                 libos: {
-                    let mut libos = CoherentBox::zeroed_slice(
-                        dev,
-                        GSP_PAGE_SIZE / size_of::<LibosMemoryRegionInitArgument>(),
-                        GFP_KERNEL,
-                    )?;
-
-                    libos.init_at(
-                        0,
-                        LibosMemoryRegionInitArgument::new("LOGINIT", &log_buffers.loginit.0),
-                    )?;
-                    libos.init_at(
-                        1,
-                        LibosMemoryRegionInitArgument::new("LOGINTR", &log_buffers.logintr.0),
-                    )?;
-                    libos.init_at(
-                        2,
-                        LibosMemoryRegionInitArgument::new("LOGRM", &log_buffers.logrm.0),
-                    )?;
-                    libos.init_at(3, LibosMemoryRegionInitArgument::new("RMARGS", rmargs))?;
-
-                    libos.into()
+                    let mut libos = LibosInitArgs::new(dev)?;
+                    log_buffers.init_arguments(&mut libos)?;
+                    libos.push(LibosMemoryRegionInitArgument::new("RMARGS", rmargs))?;
+                    libos.finish()
                 },
                 logs <- log_buffers.into_debugfs_scope(),
             }))
diff --git a/drivers/gpu/nova-core/gsp/logbuffer.rs b/drivers/gpu/nova-core/gsp/logbuffer.rs
index 5455d990ffb4..8ae80fa682a3 100644
--- a/drivers/gpu/nova-core/gsp/logbuffer.rs
+++ b/drivers/gpu/nova-core/gsp/logbuffer.rs
@@ -20,6 +20,8 @@
 
 use crate::{
     gsp::{
+        LibosInitArgs,
+        LibosMemoryRegionInitArgument,
         PteArray,
         GSP_PAGE_SIZE, //
     },
@@ -90,11 +92,11 @@ pub(super) struct LogBuffers<'a> {
     /// Device the buffers belong to.
     dev: &'a device::Device<device::Bound>,
     /// Init log buffer.
-    pub(super) loginit: LogBuffer<'a>,
+    loginit: LogBuffer<'a>,
     /// Interrupts log buffer.
-    pub(super) logintr: LogBuffer<'a>,
+    logintr: LogBuffer<'a>,
     /// RM log buffer.
-    pub(super) logrm: LogBuffer<'a>,
+    logrm: LogBuffer<'a>,
 }
 
 impl<'a> LogBuffers<'a> {
@@ -108,6 +110,19 @@ pub(super) fn new(dev: &'a device::Device<device::Bound>) -> Result<Self> {
         })
     }
 
+    /// Appends the log buffers to `libos`, under the names that GSP-RM looks them up by.
+    pub(super) fn init_arguments(&self, libos: &mut LibosInitArgs<'_>) -> Result {
+        libos.push(LibosMemoryRegionInitArgument::new(
+            "LOGINIT",
+            &self.loginit.0,
+        ))?;
+        libos.push(LibosMemoryRegionInitArgument::new(
+            "LOGINTR",
+            &self.logintr.0,
+        ))?;
+        libos.push(LibosMemoryRegionInitArgument::new("LOGRM", &self.logrm.0))
+    }
+
     /// Exposes the buffers in debugfs, in a directory named after their device.
     pub(super) fn into_debugfs_scope(self) -> impl PinInit<debugfs::Scope<Self>> + 'a {
         let dev = self.dev;

-- 
2.56.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v4 4/6] gpu: nova-core: gsp: logbuffer: make LogBuffer generic over its size
  2026-12-01  8:15 [PATCH v4 0/6] gpu: nova-core: gsp: preparatory patches for the r000 firmware Alexandre Courbot
                   ` (2 preceding siblings ...)
  2026-12-01  8:15 ` [PATCH v4 3/6] gpu: nova-core: gsp: logbuffer: add LogBuffers::init_arguments() Alexandre Courbot
@ 2026-12-01  8:15 ` Alexandre Courbot
  2026-12-01  8:15 ` [PATCH v4 5/6] gpu: nova-core: gsp: logbuffer: add RetainedLogBuffers::is_empty() Alexandre Courbot
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Alexandre Courbot @ 2026-12-01  8:15 UTC (permalink / raw)
  To: Danilo Krummrich, Alice Ryhl, David Airlie, Simona Vetter
  Cc: John Hubbard, Alistair Popple, Timur Tabi, Eliot Courtney,
	Zhi Wang, nova-gpu, dri-devel, linux-kernel, Alexandre Courbot

From: John Hubbard <jhubbard@nvidia.com>

The r000 firmware has more log buffers than r570, of two sizes.

Make `LogBuffer` generic over its number of pages. An array length
cannot be computed from a const parameter, so the buffer becomes an
array of pages instead of an array of bytes, and a snapshot is copied
page by page.

No functional change.

Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Reviewed-by: Eliot Courtney <ecourtney@nvidia.com>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
 drivers/gpu/nova-core/gsp/logbuffer.rs | 38 +++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/nova-core/gsp/logbuffer.rs b/drivers/gpu/nova-core/gsp/logbuffer.rs
index 8ae80fa682a3..4aba4919d110 100644
--- a/drivers/gpu/nova-core/gsp/logbuffer.rs
+++ b/drivers/gpu/nova-core/gsp/logbuffer.rs
@@ -30,7 +30,6 @@
 
 /// Number of GSP pages to use in a RM log buffer.
 const RM_LOG_BUFFER_NUM_PAGES: usize = 0x10;
-const LOG_BUFFER_SIZE: usize = RM_LOG_BUFFER_NUM_PAGES * GSP_PAGE_SIZE;
 
 /// The logging buffers are byte queues that contain encoded printf-like
 /// messages from GSP-RM.  They need to be decoded by a special application
@@ -46,9 +45,17 @@
 /// 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)
-pub(super) struct LogBuffer<'a>(pub(super) Coherent<'a, [u8; LOG_BUFFER_SIZE]>);
+pub(super) struct LogBuffer<'a, const NUM_PAGES: usize>(
+    pub(super) Coherent<'a, [[u8; GSP_PAGE_SIZE]; NUM_PAGES]>,
+);
 
-impl<'a> LogBuffer<'a> {
+/// A log buffer at the default size, [`RM_LOG_BUFFER_NUM_PAGES`] pages.
+///
+/// Matches the registry defaults for the init, interrupt and RM tasks
+/// (`NV_REG_STR_RM_GSP_LOG_BUFFER_SIZE_TASK_*_DEFAULT`).
+type TaskLogBuffer<'a> = LogBuffer<'a, RM_LOG_BUFFER_NUM_PAGES>;
+
+impl<'a, const NUM_PAGES: usize> LogBuffer<'a, NUM_PAGES> {
     /// Creates a new `LogBuffer` mapped on `dev`.
     fn new(dev: &'a device::Device<device::Bound>) -> Result<Self> {
         let obj = Self(Coherent::zeroed(dev, GFP_KERNEL)?);
@@ -57,9 +64,9 @@ fn new(dev: &'a device::Device<device::Bound>) -> Result<Self> {
 
         let pte_view = io_project!(
             obj.0,
-            [build: size_of::<u64>()..][build: ..RM_LOG_BUFFER_NUM_PAGES * size_of::<u64>()]
+            [build: 0][build: size_of::<u64>()..][build: ..NUM_PAGES * size_of::<u64>()]
         )
-        .try_cast::<PteArray<RM_LOG_BUFFER_NUM_PAGES>>()?;
+        .try_cast::<PteArray<NUM_PAGES>>()?;
         PteArray::init(pte_view, start_addr)?;
 
         Ok(obj)
@@ -67,7 +74,7 @@ fn new(dev: &'a device::Device<device::Bound>) -> Result<Self> {
 
     /// Copies the buffer, or returns an empty vector if the GSP never wrote to it.
     fn snapshot(&self) -> Result<VVec<u8>> {
-        let put = io_project!(self.0, [build: ..size_of::<u64>()])
+        let put = io_project!(self.0, [build: 0][build: ..size_of::<u64>()])
             .try_cast::<u64>()?
             .read_val();
         if put == 0 {
@@ -78,8 +85,11 @@ fn snapshot(&self) -> Result<VVec<u8>> {
         // GSP that failed to boot may still be writing.
         dma_mb(Read);
 
-        let mut snapshot = VVec::zeroed(LOG_BUFFER_SIZE, GFP_KERNEL)?;
-        io_project!(self.0, [build: ..]).copy_to_slice(&mut snapshot);
+        let mut snapshot = VVec::zeroed(NUM_PAGES * GSP_PAGE_SIZE, GFP_KERNEL)?;
+        for (i, page) in snapshot.chunks_exact_mut(GSP_PAGE_SIZE).enumerate() {
+            // PANIC: `snapshot` holds `NUM_PAGES` pages, so `i` is below `NUM_PAGES`.
+            io_project!(self.0, [panic: i][build: ..]).copy_to_slice(page);
+        }
 
         // The copy reads "put" again, unordered against the data, so keep the value read above.
         snapshot[..size_of::<u64>()].copy_from_slice(&put.to_ne_bytes());
@@ -92,11 +102,11 @@ pub(super) struct LogBuffers<'a> {
     /// Device the buffers belong to.
     dev: &'a device::Device<device::Bound>,
     /// Init log buffer.
-    loginit: LogBuffer<'a>,
+    loginit: TaskLogBuffer<'a>,
     /// Interrupts log buffer.
-    logintr: LogBuffer<'a>,
+    logintr: TaskLogBuffer<'a>,
     /// RM log buffer.
-    logrm: LogBuffer<'a>,
+    logrm: TaskLogBuffer<'a>,
 }
 
 impl<'a> LogBuffers<'a> {
@@ -104,9 +114,9 @@ impl<'a> LogBuffers<'a> {
     pub(super) fn new(dev: &'a device::Device<device::Bound>) -> Result<Self> {
         Ok(Self {
             dev,
-            loginit: LogBuffer::new(dev)?,
-            logintr: LogBuffer::new(dev)?,
-            logrm: LogBuffer::new(dev)?,
+            loginit: TaskLogBuffer::new(dev)?,
+            logintr: TaskLogBuffer::new(dev)?,
+            logrm: TaskLogBuffer::new(dev)?,
         })
     }
 

-- 
2.56.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v4 5/6] gpu: nova-core: gsp: logbuffer: add RetainedLogBuffers::is_empty()
  2026-12-01  8:15 [PATCH v4 0/6] gpu: nova-core: gsp: preparatory patches for the r000 firmware Alexandre Courbot
                   ` (3 preceding siblings ...)
  2026-12-01  8:15 ` [PATCH v4 4/6] gpu: nova-core: gsp: logbuffer: make LogBuffer generic over its size Alexandre Courbot
@ 2026-12-01  8:15 ` Alexandre Courbot
  2026-12-01  8:15 ` [PATCH v4 6/6] gpu: nova-core: gsp: logbuffer: add LIBOS3 log buffers and state monitor buffer Alexandre Courbot
  2026-12-01 14:23 ` [PATCH v4 0/6] gpu: nova-core: gsp: preparatory patches for the r000 firmware Danilo Krummrich
  6 siblings, 0 replies; 11+ messages in thread
From: Alexandre Courbot @ 2026-12-01  8:15 UTC (permalink / raw)
  To: Danilo Krummrich, Alice Ryhl, David Airlie, Simona Vetter
  Cc: John Hubbard, Alistair Popple, Timur Tabi, Eliot Courtney,
	Zhi Wang, nova-gpu, dri-devel, linux-kernel, Alexandre Courbot

From: John Hubbard <jhubbard@nvidia.com>

Move the check for retained logs that the GSP never wrote to into a
helper, so that it stays in one place when buffers are added.

No functional change.

Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Reviewed-by: Eliot Courtney <ecourtney@nvidia.com>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
 drivers/gpu/nova-core/gsp/logbuffer.rs | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/nova-core/gsp/logbuffer.rs b/drivers/gpu/nova-core/gsp/logbuffer.rs
index 4aba4919d110..124e6aee2c63 100644
--- a/drivers/gpu/nova-core/gsp/logbuffer.rs
+++ b/drivers/gpu/nova-core/gsp/logbuffer.rs
@@ -161,7 +161,7 @@ fn retain(&self) -> Result {
             logrm: self.logrm.snapshot()?,
         };
 
-        if logs.loginit.is_empty() && logs.logintr.is_empty() && logs.logrm.is_empty() {
+        if logs.is_empty() {
             return Ok(());
         }
 
@@ -207,6 +207,20 @@ struct RetainedLogBuffers {
     logrm: VVec<u8>,
 }
 
+impl RetainedLogBuffers {
+    /// Returns `true` if the GSP never wrote to any of the buffers.
+    fn is_empty(&self) -> bool {
+        let Self {
+            name: _,
+            loginit,
+            logintr,
+            logrm,
+        } = self;
+
+        loginit.is_empty() && logintr.is_empty() && logrm.is_empty()
+    }
+}
+
 /// Copies of the log buffers of all GPUs that are no longer bound.
 pub(crate) struct RetainedLogs(KVec<Pin<KBox<debugfs::Scope<RetainedLogBuffers>>>>);
 

-- 
2.56.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v4 6/6] gpu: nova-core: gsp: logbuffer: add LIBOS3 log buffers and state monitor buffer
  2026-12-01  8:15 [PATCH v4 0/6] gpu: nova-core: gsp: preparatory patches for the r000 firmware Alexandre Courbot
                   ` (4 preceding siblings ...)
  2026-12-01  8:15 ` [PATCH v4 5/6] gpu: nova-core: gsp: logbuffer: add RetainedLogBuffers::is_empty() Alexandre Courbot
@ 2026-12-01  8:15 ` Alexandre Courbot
  2026-12-01  8:48   ` Eliot Courtney
  2026-12-01 14:23 ` [PATCH v4 0/6] gpu: nova-core: gsp: preparatory patches for the r000 firmware Danilo Krummrich
  6 siblings, 1 reply; 11+ messages in thread
From: Alexandre Courbot @ 2026-12-01  8:15 UTC (permalink / raw)
  To: Danilo Krummrich, Alice Ryhl, David Airlie, Simona Vetter
  Cc: John Hubbard, Alistair Popple, Timur Tabi, Eliot Courtney,
	Zhi Wang, nova-gpu, dri-devel, linux-kernel, Alexandre Courbot

From: John Hubbard <jhubbard@nvidia.com>

GSP-RM runs on LibOS, and each LibOS task logs into a buffer that the
driver provides and names in the init argument array. On GA102 and
later, the r000 firmware runs LIBOS3, version 3 of LibOS, which has six
logging tasks. LIBOS3 also expects one more page, the state monitor
buffer, in which GSP-RM reports its own state. On Turing and GA100 the
r000 firmware runs LIBOS2, which maps only the init and RM log buffers
and skips the names that it does not have.

Nova-core allocates log buffers for three of the six tasks, and no state
monitor buffer.

Allocate the three missing log buffers and the state monitor buffer, and
name every log buffer in the init argument array. Give each new log a
debugfs file next to the existing ones, and retain it after unbind under
the same module parameter as the existing ones.

This is part of the r000 support. As it comes before the switch, the
r570 firmware is passed the three new log buffers too, and nothing uses
the state monitor buffer until the switch.

Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Co-developed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
 drivers/gpu/nova-core/gsp.rs           |  3 ++
 drivers/gpu/nova-core/gsp/logbuffer.rs | 64 ++++++++++++++++++++++++++++++++--
 2 files changed, 64 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/nova-core/gsp.rs b/drivers/gpu/nova-core/gsp.rs
index 28bd76626cf6..27ff2e8b7f5e 100644
--- a/drivers/gpu/nova-core/gsp.rs
+++ b/drivers/gpu/nova-core/gsp.rs
@@ -143,6 +143,8 @@ pub(crate) struct Gsp<'gsp> {
     pub(crate) cmdq: Cmdq<'gsp>,
     /// RM arguments.
     rmargs: Coherent<'gsp, GspArgumentsPadded>,
+    /// Buffer in which GSP-RM reports its own state.
+    rm_state_monitor: Coherent<'gsp, [u8; GSP_PAGE_SIZE]>,
 }
 
 impl<'gsp> Gsp<'gsp> {
@@ -162,6 +164,7 @@ pub(crate) fn new(
             Ok(try_pin_init!(Self {
                 cmdq <- Cmdq::new(dev, bar),
                 rmargs: Coherent::init(dev, GFP_KERNEL, GspArgumentsPadded::new(&cmdq))?,
+                rm_state_monitor: Coherent::zeroed(dev, GFP_KERNEL)?,
                 libos: {
                     let mut libos = LibosInitArgs::new(dev)?;
                     log_buffers.init_arguments(&mut libos)?;
diff --git a/drivers/gpu/nova-core/gsp/logbuffer.rs b/drivers/gpu/nova-core/gsp/logbuffer.rs
index 124e6aee2c63..5a9d5bd9992f 100644
--- a/drivers/gpu/nova-core/gsp/logbuffer.rs
+++ b/drivers/gpu/nova-core/gsp/logbuffer.rs
@@ -51,10 +51,14 @@ pub(super) struct LogBuffer<'a, const NUM_PAGES: usize>(
 
 /// A log buffer at the default size, [`RM_LOG_BUFFER_NUM_PAGES`] pages.
 ///
-/// Matches the registry defaults for the init, interrupt and RM tasks
+/// Matches the registry defaults for the init, interrupt, RM and MNOC tasks
 /// (`NV_REG_STR_RM_GSP_LOG_BUFFER_SIZE_TASK_*_DEFAULT`).
 type TaskLogBuffer<'a> = LogBuffer<'a, RM_LOG_BUFFER_NUM_PAGES>;
 
+/// A single-page log buffer, the size of the logs of the root task and of the RM state monitor
+/// task.
+type SmallLogBuffer<'a> = LogBuffer<'a, 1>;
+
 impl<'a, const NUM_PAGES: usize> LogBuffer<'a, NUM_PAGES> {
     /// Creates a new `LogBuffer` mapped on `dev`.
     fn new(dev: &'a device::Device<device::Bound>) -> Result<Self> {
@@ -98,6 +102,10 @@ fn snapshot(&self) -> Result<VVec<u8>> {
     }
 }
 
+/// The log buffers to which GSP-RM writes its debug output, one per LIBOS3 task.
+///
+/// The r000 firmware runs LIBOS3 on GA102 and later, and LIBOS2 on Turing and GA100. LIBOS2 maps
+/// only the init and RM log buffers, and skips the names that it does not have.
 pub(super) struct LogBuffers<'a> {
     /// Device the buffers belong to.
     dev: &'a device::Device<device::Bound>,
@@ -107,6 +115,12 @@ pub(super) struct LogBuffers<'a> {
     logintr: TaskLogBuffer<'a>,
     /// RM log buffer.
     logrm: TaskLogBuffer<'a>,
+    /// MNOC log buffer.
+    logmnoc: TaskLogBuffer<'a>,
+    /// Root task log buffer.
+    logroot: SmallLogBuffer<'a>,
+    /// RM state monitor task log buffer.
+    logrmon: SmallLogBuffer<'a>,
 }
 
 impl<'a> LogBuffers<'a> {
@@ -117,6 +131,9 @@ pub(super) fn new(dev: &'a device::Device<device::Bound>) -> Result<Self> {
             loginit: TaskLogBuffer::new(dev)?,
             logintr: TaskLogBuffer::new(dev)?,
             logrm: TaskLogBuffer::new(dev)?,
+            logmnoc: TaskLogBuffer::new(dev)?,
+            logroot: SmallLogBuffer::new(dev)?,
+            logrmon: SmallLogBuffer::new(dev)?,
         })
     }
 
@@ -130,7 +147,19 @@ pub(super) fn init_arguments(&self, libos: &mut LibosInitArgs<'_>) -> Result {
             "LOGINTR",
             &self.logintr.0,
         ))?;
-        libos.push(LibosMemoryRegionInitArgument::new("LOGRM", &self.logrm.0))
+        libos.push(LibosMemoryRegionInitArgument::new("LOGRM", &self.logrm.0))?;
+        libos.push(LibosMemoryRegionInitArgument::new(
+            "LOGMNOC",
+            &self.logmnoc.0,
+        ))?;
+        libos.push(LibosMemoryRegionInitArgument::new(
+            "LOGROOT",
+            &self.logroot.0,
+        ))?;
+        libos.push(LibosMemoryRegionInitArgument::new(
+            "LOGRMON",
+            &self.logrmon.0,
+        ))
     }
 
     /// Exposes the buffers in debugfs, in a directory named after their device.
@@ -145,6 +174,9 @@ pub(super) fn into_debugfs_scope(self) -> impl PinInit<debugfs::Scope<Self>> + '
             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);
         })
     }
 
@@ -159,6 +191,9 @@ fn retain(&self) -> Result {
             loginit: self.loginit.snapshot()?,
             logintr: self.logintr.snapshot()?,
             logrm: self.logrm.snapshot()?,
+            logmnoc: self.logmnoc.snapshot()?,
+            logroot: self.logroot.snapshot()?,
+            logrmon: self.logrmon.snapshot()?,
         };
 
         if logs.is_empty() {
@@ -181,6 +216,15 @@ fn retain(&self) -> Result {
             if !logs.logrm.is_empty() {
                 dir.read_binary_file(c"logrm", &logs.logrm);
             }
+            if !logs.logmnoc.is_empty() {
+                dir.read_binary_file(c"logmnoc", &logs.logmnoc);
+            }
+            if !logs.logroot.is_empty() {
+                dir.read_binary_file(c"logroot", &logs.logroot);
+            }
+            if !logs.logrmon.is_empty() {
+                dir.read_binary_file(c"logrmon", &logs.logrmon);
+            }
         }))?;
 
         retained.push(scope)
@@ -205,6 +249,12 @@ struct RetainedLogBuffers {
     logintr: VVec<u8>,
     /// RM log buffer, empty if never written to.
     logrm: VVec<u8>,
+    /// MNOC log buffer, empty if never written to.
+    logmnoc: VVec<u8>,
+    /// Root task log buffer, empty if never written to.
+    logroot: VVec<u8>,
+    /// RM state monitor task log buffer, empty if never written to.
+    logrmon: VVec<u8>,
 }
 
 impl RetainedLogBuffers {
@@ -215,9 +265,17 @@ fn is_empty(&self) -> bool {
             loginit,
             logintr,
             logrm,
+            logmnoc,
+            logroot,
+            logrmon,
         } = self;
 
-        loginit.is_empty() && logintr.is_empty() && logrm.is_empty()
+        loginit.is_empty()
+            && logintr.is_empty()
+            && logrm.is_empty()
+            && logmnoc.is_empty()
+            && logroot.is_empty()
+            && logrmon.is_empty()
     }
 }
 

-- 
2.56.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v4 6/6] gpu: nova-core: gsp: logbuffer: add LIBOS3 log buffers and state monitor buffer
  2026-12-01  8:15 ` [PATCH v4 6/6] gpu: nova-core: gsp: logbuffer: add LIBOS3 log buffers and state monitor buffer Alexandre Courbot
@ 2026-12-01  8:48   ` Eliot Courtney
  0 siblings, 0 replies; 11+ messages in thread
From: Eliot Courtney @ 2026-12-01  8:48 UTC (permalink / raw)
  To: Alexandre Courbot, Danilo Krummrich, Alice Ryhl, David Airlie,
	Simona Vetter
  Cc: John Hubbard, Alistair Popple, Timur Tabi, Eliot Courtney,
	Zhi Wang, nova-gpu, dri-devel, linux-kernel, dri-devel

On Tue Dec 1, 2026 at 5:15 PM JST, Alexandre Courbot wrote:
> From: John Hubbard <jhubbard@nvidia.com>
>
> GSP-RM runs on LibOS, and each LibOS task logs into a buffer that the
> driver provides and names in the init argument array. On GA102 and
> later, the r000 firmware runs LIBOS3, version 3 of LibOS, which has six
> logging tasks. LIBOS3 also expects one more page, the state monitor
> buffer, in which GSP-RM reports its own state. On Turing and GA100 the
> r000 firmware runs LIBOS2, which maps only the init and RM log buffers
> and skips the names that it does not have.
>
> Nova-core allocates log buffers for three of the six tasks, and no state
> monitor buffer.
>
> Allocate the three missing log buffers and the state monitor buffer, and
> name every log buffer in the init argument array. Give each new log a
> debugfs file next to the existing ones, and retain it after unbind under
> the same module parameter as the existing ones.
>
> This is part of the r000 support. As it comes before the switch, the
> r570 firmware is passed the three new log buffers too, and nothing uses
> the state monitor buffer until the switch.
>
> Signed-off-by: John Hubbard <jhubbard@nvidia.com>
> Co-developed-by: Alexandre Courbot <acourbot@nvidia.com>
> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
> ---

Reviewed-by: Eliot Courtney <ecourtney@nvidia.com>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v4 1/6] gpu: nova-core: gsp: add the r000 queue element header
  2026-12-01  8:15 ` [PATCH v4 1/6] gpu: nova-core: gsp: add the r000 queue element header Alexandre Courbot
@ 2026-12-01 14:12   ` Danilo Krummrich
  0 siblings, 0 replies; 11+ messages in thread
From: Danilo Krummrich @ 2026-12-01 14:12 UTC (permalink / raw)
  To: Alexandre Courbot
  Cc: Alice Ryhl, David Airlie, Simona Vetter, John Hubbard,
	Alistair Popple, Timur Tabi, Eliot Courtney, Zhi Wang, nova-gpu,
	dri-devel, linux-kernel

On Tue Dec 1, 2026 at 9:15 AM CET, Alexandre Courbot wrote:
> +    pub(crate) fn validate(&self) -> Result {
> +        if self.mctp_magic != Self::MCTP_MAGIC
> +            || !self.mctp_header.has_expected_version()
> +            || !self.nvdm_header.has_nvidia_vendor()
> +        {
> +            return Err(EIO);
> +        }
> +
> +        let element_len = self.element_len();
> +        if element_len < size_of::<Self>() + self.message_len()
> +            || element_len > GSP_MSG_QUEUE_ELEMENT_SIZE_MAX
> +        {
> +            return Err(EIO);
> +        }
> +
> +        Ok(())
> +    }
> +}

[...]

> -    /// Validates this header against the expected NVIDIA NVDM format and type.
> -    pub(crate) fn validate(self, expected_type: NvdmType) -> bool {
> +    /// Returns `true` if this NVDM header belongs to a PCI vendor-defined message from NVIDIA.
> +    ///
> +    /// The GPU firmware only ever sends such messages, so a mismatch is a sign of corruption.
> +    pub(crate) fn has_nvidia_vendor(self) -> bool {
>          u8::from(self.msg_type()) == MSG_TYPE_VENDOR_PCI
>              && u16::from(self.vendor_id()) == Vendor::NVIDIA.as_raw()
> +    }
> +
> +    /// Validates this header against the expected NVIDIA NVDM format and type.
> +    pub(crate) fn validate(self, expected_type: NvdmType) -> bool {
> +        self.has_nvidia_vendor()
>              && matches!(self.nvdm_type(), Ok(nvdm_type) if nvdm_type == expected_type)
>      }
>  }

NIT: I find has_nvidia_vendor() slighly confusing, as it reads as if it can
legitimately return false. I think it should either be validate() and
validate_type(), or define validate() as done by this patch and rename
has_nvidia_vendor() to has_expected_vendor(), matching has_expected_version().

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v4 3/6] gpu: nova-core: gsp: logbuffer: add LogBuffers::init_arguments()
  2026-12-01  8:15 ` [PATCH v4 3/6] gpu: nova-core: gsp: logbuffer: add LogBuffers::init_arguments() Alexandre Courbot
@ 2026-12-01 14:22   ` Danilo Krummrich
  0 siblings, 0 replies; 11+ messages in thread
From: Danilo Krummrich @ 2026-12-01 14:22 UTC (permalink / raw)
  To: Alexandre Courbot
  Cc: Alice Ryhl, David Airlie, Simona Vetter, John Hubbard,
	Alistair Popple, Timur Tabi, Eliot Courtney, Zhi Wang, nova-gpu,
	dri-devel, linux-kernel

On Tue Dec 1, 2026 at 9:15 AM CET, Alexandre Courbot wrote:
> +/// Writer for the `LibosMemoryRegionInitArgument` array passed to the GSP bootloader.
> +struct LibosInitArgs<'a> {
> +    buf: CoherentBox<'a, [LibosMemoryRegionInitArgument]>,
> +    len: usize,
> +}
> +
> +impl<'a> LibosInitArgs<'a> {
> +    /// Allocates a zeroed `LibosMemoryRegionInitArgument` array for `dev`.
> +    fn new(dev: &'a device::Device<device::Bound>) -> Result<Self> {
> +        Ok(Self {
> +            buf: CoherentBox::zeroed_slice(
> +                dev,
> +                GSP_PAGE_SIZE / size_of::<LibosMemoryRegionInitArgument>(),
> +                GFP_KERNEL,
> +            )?,
> +            len: 0,
> +        })
> +    }
> +
> +    /// Appends an entry to the array.
> +    fn push(&mut self, arg: impl Init<LibosMemoryRegionInitArgument>) -> Result {
> +        self.buf.init_at(self.len, arg)?;
> +        self.len += 1;
> +        Ok(())
> +    }
> +
> +    /// Consumes the writer and returns the underlying coherent DMA allocation.
> +    fn finish(self) -> Coherent<'a, [LibosMemoryRegionInitArgument]> {
> +        self.buf.into()
> +    }
> +}

NIT: Should this be named LibosBuilder instead? Or since it's not exactly the
builder pattern maybe just LibosWriter?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v4 0/6] gpu: nova-core: gsp: preparatory patches for the r000 firmware
  2026-12-01  8:15 [PATCH v4 0/6] gpu: nova-core: gsp: preparatory patches for the r000 firmware Alexandre Courbot
                   ` (5 preceding siblings ...)
  2026-12-01  8:15 ` [PATCH v4 6/6] gpu: nova-core: gsp: logbuffer: add LIBOS3 log buffers and state monitor buffer Alexandre Courbot
@ 2026-12-01 14:23 ` Danilo Krummrich
  6 siblings, 0 replies; 11+ messages in thread
From: Danilo Krummrich @ 2026-12-01 14:23 UTC (permalink / raw)
  To: Alexandre Courbot
  Cc: Alice Ryhl, David Airlie, Simona Vetter, John Hubbard,
	Alistair Popple, Timur Tabi, Eliot Courtney, Zhi Wang, nova-gpu,
	dri-devel, linux-kernel

On Tue Dec 1, 2026 at 9:15 AM CET, Alexandre Courbot wrote:
> These patches come from John's series switching nova-core to the r000
> GSP firmware [1]. They do not depend on the switch itself, and both the
> rest of the r000 work and the vGPU series build on them, so I would
> like to get them in soon.
>
> Patch 1 adds the r000 queue element header. It has no user yet and was
> previously posted on its own [2].
>
> Patch 2 moves the loading of the file referenced by a TLV into the TLV
> parser, so the r000 ucodes loader can use it.
>
> Patches 3 to 5 prepare the log buffers code for the extra buffers of
> r000, without functional change. Patch 6 adds the LIBOS3 log buffers and
> the state monitor buffer. These buffers are valid for r570, which still
> boots with them.
>
> Based on drm-rust-next.
>
> [1] https://lore.kernel.org/20260918010719.1176945-1-jhubbard@nvidia.com
> [2] https://lore.kernel.org/20261117-msgelement-v1-1-b918ffae5e7b@nvidia.com
>
> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>

I left two nits, otherwise

Reviewed-by: Danilo Krummrich <dakr@kernel.org>

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-12-01 14:23 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-01  8:15 [PATCH v4 0/6] gpu: nova-core: gsp: preparatory patches for the r000 firmware Alexandre Courbot
2026-12-01  8:15 ` [PATCH v4 1/6] gpu: nova-core: gsp: add the r000 queue element header Alexandre Courbot
2026-12-01 14:12   ` Danilo Krummrich
2026-12-01  8:15 ` [PATCH v4 2/6] gpu: nova-core: firmware: tlv: add method to load the file referenced by a TLV Alexandre Courbot
2026-12-01  8:15 ` [PATCH v4 3/6] gpu: nova-core: gsp: logbuffer: add LogBuffers::init_arguments() Alexandre Courbot
2026-12-01 14:22   ` Danilo Krummrich
2026-12-01  8:15 ` [PATCH v4 4/6] gpu: nova-core: gsp: logbuffer: make LogBuffer generic over its size Alexandre Courbot
2026-12-01  8:15 ` [PATCH v4 5/6] gpu: nova-core: gsp: logbuffer: add RetainedLogBuffers::is_empty() Alexandre Courbot
2026-12-01  8:15 ` [PATCH v4 6/6] gpu: nova-core: gsp: logbuffer: add LIBOS3 log buffers and state monitor buffer Alexandre Courbot
2026-12-01  8:48   ` Eliot Courtney
2026-12-01 14:23 ` [PATCH v4 0/6] gpu: nova-core: gsp: preparatory patches for the r000 firmware Danilo Krummrich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®