Rust for Linux List
 help / color / mirror / Atom feed
From: Alistair Popple <apopple@nvidia.com>
To: rust-for-linux@vger.kernel.org, nova-gpu <nova-gpu@lists.linux.dev>
Cc: Alistair Popple <apopple@nvidia.com>,
	M Henning <mhenning@darkrefraction.com>,
	Danilo Krummrich <dakr@kernel.org>,
	Alice Ryhl <aliceryhl@google.com>,
	David Airlie <airlied@gmail.com>,
	Alexandre Courbot <acourbot@nvidia.com>,
	Benno Lossin <lossin@kernel.org>, Gary Guo <gary@garyguo.net>,
	Eliot Courtney <ecourtney@nvidia.com>,
	John Hubbard <jhubbard@nvidia.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org
Subject: [PATCH v6 11/13] drm: nova: Report GPU name in GPU info
Date: Wed,  9 Sep 2026 16:45:04 +1000	[thread overview]
Message-ID: <20260909064506.910162-12-apopple@nvidia.com> (raw)
In-Reply-To: <20260909064506.910162-1-apopple@nvidia.com>

Add the full GPU name to the GPU info structure. The name is copied from
the validated, NUL-terminated string nova-core already extracts from the
GSP static info rather than from the raw firmware bytes.

GpuInfo::new() is deliberately fallible here. A malformed name string
from the GSP is unexpected and is reported to userspace as an error
rather than being silently replaced with an empty name.

Signed-off-by: Alistair Popple <apopple@nvidia.com>

---

Changes since v5:

 - Use the existing validated gpu_name() accessor instead of exposing the
   raw bytes, as suggested by Danilo
 - Keep GpuInfo::new() fallible so that unexpected GSP errors such as a
   bad name string fail the ioctl instead of falling back to an empty name

Changes since v4:

 - New for v5
---
 drivers/gpu/drm/nova/file.rs          | 21 ++++++++++++++++++++-
 drivers/gpu/nova-core/gsp/commands.rs |  5 ++---
 include/uapi/drm/nova_drm.h           |  5 +++++
 3 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/nova/file.rs b/drivers/gpu/drm/nova/file.rs
index dad3c83c920b..4753d9bca13b 100644
--- a/drivers/gpu/drm/nova/file.rs
+++ b/drivers/gpu/drm/nova/file.rs
@@ -25,6 +25,21 @@
 #[repr(transparent)]
 struct GpuInfo(uapi::drm_nova_info_gpu);
 
+/// Copies `name` into the zero initialised, fixed size uAPI buffer `dst`, keeping it
+/// NUL-terminated.
+///
+/// Fails with [`ENAMETOOLONG`] if `name` does not fit in `dst` with room for the terminator.
+fn copy_name(dst: &mut [u8], name: &str) -> Result {
+    let bytes = name.as_bytes();
+
+    if bytes.len() >= dst.len() {
+        return Err(ENAMETOOLONG);
+    }
+    dst[..bytes.len()].copy_from_slice(bytes);
+
+    Ok(())
+}
+
 impl GpuInfo {
     /// Collects the GPU information reported to userspace.
     ///
@@ -37,11 +52,15 @@ fn new(reg_data: &DrmRegData<'_>) -> Result<Self> {
         let spec = reg_data.api.with(|api| api.get_ref().spec());
         let gsp_static_info = reg_data.api.with(|api| api.get_ref().gsp_static_info());
 
-        let info = uapi::drm_nova_info_gpu {
+        let mut info = uapi::drm_nova_info_gpu {
             architecture: spec.chipset.arch() as u32,
             chipid: spec.chipset as u32,
             vram_size: gsp_static_info.vram_size(),
+            ..Default::default()
         };
+
+        copy_name(&mut info.gpu_name, gsp_static_info.gpu_name().map_err(|_| EINVAL)?)?;
+
         Ok(Self(info))
     }
 }
diff --git a/drivers/gpu/nova-core/gsp/commands.rs b/drivers/gpu/nova-core/gsp/commands.rs
index 5c1f9d296198..00cfcef260c5 100644
--- a/drivers/gpu/nova-core/gsp/commands.rs
+++ b/drivers/gpu/nova-core/gsp/commands.rs
@@ -241,12 +241,11 @@ fn read(
 
 /// Error type for [`GetGspStaticInfoReply::gpu_name`].
 #[derive(Debug)]
-pub(crate) enum GpuNameError {
+pub enum GpuNameError {
     /// The GPU name string does not contain a null terminator.
     NoNullTerminator(FromBytesUntilNulError),
 
     /// The GPU name string contains invalid UTF-8.
-    #[expect(dead_code)]
     InvalidUtf8(Utf8Error),
 }
 
@@ -255,7 +254,7 @@ impl GetGspStaticInfoReply {
     ///
     /// Returns an error if the string given by the GSP does not contain a null terminator or
     /// contains invalid UTF-8.
-    pub(crate) fn gpu_name(&self) -> core::result::Result<&str, GpuNameError> {
+    pub fn gpu_name(&self) -> core::result::Result<&str, GpuNameError> {
         CStr::from_bytes_until_nul(&self.gpu_name)
             .map_err(GpuNameError::NoNullTerminator)?
             .to_str()
diff --git a/include/uapi/drm/nova_drm.h b/include/uapi/drm/nova_drm.h
index 946bd4bf8fbd..c692cacaa552 100644
--- a/include/uapi/drm/nova_drm.h
+++ b/include/uapi/drm/nova_drm.h
@@ -186,6 +186,11 @@ struct drm_nova_info_gpu {
 	 * regions.
 	 */
 	__u64 vram_size;
+
+	/**
+	 * @gpu_name: NUL-terminated full GPU name.
+	 */
+	__u8 gpu_name[64];
 };
 
 #define DRM_NOVA_GETPARAM		0x00
-- 
2.54.0


  parent reply	other threads:[~2026-09-09  6:46 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-09  6:44 [PATCH v6 00/13] gpu: nova: Export parameters from nova-core to nova-drm Alistair Popple
2026-09-09  6:44 ` [PATCH v6 01/13] rust: auxiliary: let registration_data_with() closures return covariant sub-fields Alistair Popple
2026-09-09  6:44 ` [PATCH v6 02/13] gpu: nova-core: Add public driver API to nova-core Alistair Popple
2026-09-09  6:44 ` [PATCH v6 03/13] drm: nova: Add DRM registration data Alistair Popple
2026-09-09  6:44 ` [PATCH v6 04/13] drm: nova: Add GPU architecture enum to nova-drm UAPI Alistair Popple
2026-09-09  6:44 ` [PATCH v6 05/13] drm: nova: Add chipid " Alistair Popple
2026-09-09  6:44 ` [PATCH v6 06/13] rust: uaccess: add UserSliceWriter::write_truncated() Alistair Popple
2026-09-09  6:45 ` [PATCH v6 07/13] drm: nova: Add an info ioctl Alistair Popple
2026-09-09  6:45 ` [PATCH v6 08/13] drm: nova: Add usable VRAM size to GPU info Alistair Popple
2026-09-09  6:45 ` [PATCH v6 09/13] drm: nova: Use nova-core to read VRAM_BAR_SIZE parameter Alistair Popple
2026-09-09  6:45 ` [PATCH v6 10/13] drm: nova: Expose a render node Alistair Popple
2026-09-09  6:45 ` Alistair Popple [this message]
2026-09-09  6:45 ` [PATCH v6 12/13] drm: nova: Report GPU short name in GPU info Alistair Popple
2026-09-09  6:45 ` [PATCH v6 13/13] drm: nova: Report GPU GID " Alistair Popple

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260909064506.910162-12-apopple@nvidia.com \
    --to=apopple@nvidia.com \
    --cc=acourbot@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=dakr@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=ecourtney@nvidia.com \
    --cc=gary@garyguo.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=jhubbard@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=mhenning@darkrefraction.com \
    --cc=nova-gpu@lists.linux.dev \
    --cc=rafael@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox