NVIDIA GPU driver infrastructure
 help / color / mirror / Atom feed
From: Alistair Popple <apopple@nvidia.com>
To: Pedro Yudi Honda <niyudi.honda@usp.br>
Cc: dakr@kernel.org, acourbot@nvidia.com, nico.antinori.7@gmail.com,
	 aliceryhl@google.com, airlied@gmail.com, simona@ffwll.ch,
	 dri-devel@lists.freedesktop.org, ojeda@kernel.org,
	rust-for-linux@vger.kernel.org,  nova-gpu@lists.linux.dev
Subject: Re: [PATCH v2 2/5] drm/nova: use `zerocopy` in booter.rs
Date: Mon, 6 Jul 2026 21:39:37 +1000	[thread overview]
Message-ID: <akuSs22rTkn6MXqr@nvdebian.thelocal> (raw)
In-Reply-To: <20260702120324.40388-3-niyudi.honda@gmail.com>

On 2026-07-02 at 22:03 +1000, Pedro Yudi Honda <niyudi.honda@usp.br> wrote...
> From: Pedro Yudi Honda <niyudi.honda@usp.br>
> 
> In firmware/booter.rs, replace the following `transmute` traits with
> their `zerocopy` equivalents:
> 
> - `transmute::FromBytes` -> `zerocopy::FromBytes`

Having a single item list reads a bit strange to me. I'd just say "replace
`transmute::FromBytes` with `zerocopy::FromBytes`" and if you want to list the
types it's replaced for you could. But that's a bit superfluous as it's clear
from the patch anyway.

But that's a small nit really, everything looks ok to me so feel free to add:

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

> Update call sites accordingly.
>
> Signed-off-by: Pedro Yudi Honda <niyudi.honda@usp.br>
> ---
>  drivers/gpu/nova-core/firmware/booter.rs | 26 +++++++-----------------
>  1 file changed, 7 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/gpu/nova-core/firmware/booter.rs b/drivers/gpu/nova-core/firmware/booter.rs
> index acb7f4d8a532..fe9389b84b90 100644
> --- a/drivers/gpu/nova-core/firmware/booter.rs
> +++ b/drivers/gpu/nova-core/firmware/booter.rs
> @@ -10,8 +10,7 @@
>  use kernel::{
>      device,
>      dma::Coherent,
> -    prelude::*,
> -    transmute::FromBytes, //
> +    prelude::*, //
>  };
>  
>  use crate::{
> @@ -43,7 +42,7 @@ fn frombytes_at<S: FromBytes + Sized>(slice: &[u8], offset: usize) -> Result<S>
>      let end = offset.checked_add(size_of::<S>()).ok_or(EINVAL)?;
>      slice
>          .get(offset..end)
> -        .and_then(S::from_bytes_copy)
> +        .and_then(|b| S::read_from_bytes(b).ok())
>          .ok_or(EINVAL)
>  }
>  
> @@ -52,7 +51,7 @@ fn frombytes_at<S: FromBytes + Sized>(slice: &[u8], offset: usize) -> Result<S>
>  /// Such firmwares have an application-specific payload that needs to be patched with a given
>  /// signature.
>  #[repr(C)]
> -#[derive(Debug, Clone)]
> +#[derive(Debug, Clone, FromBytes)]
>  struct HsHeaderV2 {
>      /// Offset to the start of the signatures.
>      sig_prod_offset: u32,
> @@ -75,9 +74,6 @@ struct HsHeaderV2 {
>      header_size: u32,
>  }
>  
> -// SAFETY: all bit patterns are valid for this type, and it doesn't use interior mutability.
> -unsafe impl FromBytes for HsHeaderV2 {}
> -
>  /// Heavy-Secured Firmware image container.
>  ///
>  /// This provides convenient access to the fields of [`HsHeaderV2`] that are actually indices to
> @@ -144,6 +140,7 @@ fn signatures_iter(&'a self) -> Result<impl Iterator<Item = BooterSignature<'a>>
>  
>  /// Signature parameters, as defined in the firmware.
>  #[repr(C)]
> +#[derive(FromBytes)]
>  struct HsSignatureParams {
>      /// Fuse version to use.
>      fuse_ver: u32,
> @@ -153,9 +150,6 @@ struct HsSignatureParams {
>      ucode_id: u32,
>  }
>  
> -// SAFETY: all bit patterns are valid for this type, and it doesn't use interior mutability.
> -unsafe impl FromBytes for HsSignatureParams {}
> -
>  impl HsSignatureParams {
>      /// Returns the signature parameters contained in `hs_fw`.
>      ///
> @@ -170,14 +164,14 @@ fn new(hs_fw: &HsFirmwareV2<'_>) -> Result<Self> {
>          hs_fw
>              .fw
>              .get(start..end)
> -            .and_then(Self::from_bytes_copy)
> +            .and_then(|b| Self::read_from_bytes(b).ok())
>              .ok_or(EINVAL)
>      }
>  }
>  
>  /// Header for code and data load offsets.
>  #[repr(C)]
> -#[derive(Debug, Clone)]
> +#[derive(Debug, Clone, FromBytes)]
>  struct HsLoadHeaderV2 {
>      // Offset at which the code starts.
>      os_code_offset: u32,
> @@ -191,9 +185,6 @@ struct HsLoadHeaderV2 {
>      num_apps: u32,
>  }
>  
> -// SAFETY: all bit patterns are valid for this type, and it doesn't use interior mutability.
> -unsafe impl FromBytes for HsLoadHeaderV2 {}
> -
>  impl HsLoadHeaderV2 {
>      /// Returns the load header contained in `hs_fw`.
>      ///
> @@ -205,7 +196,7 @@ fn new(hs_fw: &HsFirmwareV2<'_>) -> Result<Self> {
>  
>  /// Header for app code loader.
>  #[repr(C)]
> -#[derive(Debug, Clone)]
> +#[derive(Debug, Clone, FromBytes)]
>  struct HsLoadHeaderV2App {
>      /// Offset at which to load the app code.
>      offset: u32,
> @@ -213,9 +204,6 @@ struct HsLoadHeaderV2App {
>      len: u32,
>  }
>  
> -// SAFETY: all bit patterns are valid for this type, and it doesn't use interior mutability.
> -unsafe impl FromBytes for HsLoadHeaderV2App {}
> -
>  impl HsLoadHeaderV2App {
>      /// Returns the [`HsLoadHeaderV2App`] for app `idx` of `hs_fw`.
>      ///
> -- 
> 2.34.1
> 

  reply	other threads:[~2026-07-06 11:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-02 12:03 [RESEND PATCH v2 0/5] drm/nova: replace `transmute` with `zerocopy` Pedro Yudi Honda
2026-07-02 12:03 ` [PATCH v2 1/5] drm/nova: use `zerocopy` in firmware.rs Pedro Yudi Honda
2026-07-06  7:15   ` Alistair Popple
2026-07-02 12:03 ` [PATCH v2 2/5] drm/nova: use `zerocopy` in booter.rs Pedro Yudi Honda
2026-07-06 11:39   ` Alistair Popple [this message]
2026-07-02 12:03 ` [PATCH v2 3/5] drm/nova: use `zerocopy` in fwsec.rs Pedro Yudi Honda
2026-07-06 11:43   ` Alistair Popple
2026-07-02 12:03 ` [PATCH v2 4/5] drm/nova: use `zerocopy` in bootloader.rs Pedro Yudi Honda
2026-07-06 11:44   ` Alistair Popple
2026-07-02 12:03 ` [PATCH v2 5/5] drm/nova: use `zerocopy` in riscv.rs Pedro Yudi Honda
2026-07-06 11:44   ` Alistair Popple
2026-07-04 13:00 ` [RESEND PATCH v2 0/5] drm/nova: replace `transmute` with `zerocopy` Miguel Ojeda

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=akuSs22rTkn6MXqr@nvdebian.thelocal \
    --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=nico.antinori.7@gmail.com \
    --cc=niyudi.honda@usp.br \
    --cc=nova-gpu@lists.linux.dev \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=simona@ffwll.ch \
    /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