All of lore.kernel.org
 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 3/5] drm/nova: use `zerocopy` in fwsec.rs
Date: Mon, 6 Jul 2026 21:43:08 +1000	[thread overview]
Message-ID: <akuUWHkAPHC31Va5@nvdebian.thelocal> (raw)
In-Reply-To: <20260702120324.40388-4-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/fwsec.rs, replace the following `transmute` traits with
> their `zerocopy` equivalents:
> 
> - `transmute::FromBytes` -> `zerocopy::FromBytes`
> - `transmute::AsBytes` -> `zerocopy::IntoBytes`
> - add `zerocopy::KnownLayout` where necessary

Argh, ok. It makes more sense when there are more things in the list :-) That
said I'd also be ok without, but either is fine.

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/fwsec.rs | 49 ++++++-------------------
>  1 file changed, 12 insertions(+), 37 deletions(-)
> 
> diff --git a/drivers/gpu/nova-core/firmware/fwsec.rs b/drivers/gpu/nova-core/firmware/fwsec.rs
> index 95e0dd77746b..1b75cdc02256 100644
> --- a/drivers/gpu/nova-core/firmware/fwsec.rs
> +++ b/drivers/gpu/nova-core/firmware/fwsec.rs
> @@ -19,11 +19,7 @@
>          self,
>          Device, //
>      },
> -    prelude::*,
> -    transmute::{
> -        AsBytes,
> -        FromBytes, //
> -    },
> +    prelude::*, //
>  };
>  
>  use crate::{
> @@ -49,26 +45,22 @@
>  const NVFW_FALCON_APPIF_ID_DMEMMAPPER: u32 = 0x4;
>  
>  #[repr(C)]
> -#[derive(Debug)]
> +#[derive(Debug, FromBytes)]
>  struct FalconAppifHdrV1 {
>      version: u8,
>      header_size: u8,
>      entry_size: u8,
>      entry_count: u8,
>  }
> -// SAFETY: Any byte sequence is valid for this struct.
> -unsafe impl FromBytes for FalconAppifHdrV1 {}
>  
>  #[repr(C, packed)]
> -#[derive(Debug)]
> +#[derive(Debug, FromBytes)]
>  struct FalconAppifV1 {
>      id: u32,
>      dmem_base: u32,
>  }
> -// SAFETY: Any byte sequence is valid for this struct.
> -unsafe impl FromBytes for FalconAppifV1 {}
>  
> -#[derive(Debug)]
> +#[derive(Debug, FromBytes, IntoBytes, zerocopy_derive::KnownLayout)]
>  #[repr(C, packed)]
>  struct FalconAppifDmemmapperV3 {
>      signature: u32,
> @@ -89,12 +81,8 @@ struct FalconAppifDmemmapperV3 {
>      ucode_cmd_mask1: u32,
>      multi_tgt_tbl: u32,
>  }
> -// SAFETY: Any byte sequence is valid for this struct.
> -unsafe impl FromBytes for FalconAppifDmemmapperV3 {}
> -// SAFETY: This struct doesn't contain uninitialized bytes and doesn't have interior mutability.
> -unsafe impl AsBytes for FalconAppifDmemmapperV3 {}
>  
> -#[derive(Debug)]
> +#[derive(Debug, FromBytes, IntoBytes, zerocopy_derive::KnownLayout)]
>  #[repr(C, packed)]
>  struct ReadVbios {
>      ver: u32,
> @@ -103,12 +91,8 @@ struct ReadVbios {
>      size: u32,
>      flags: u32,
>  }
> -// SAFETY: Any byte sequence is valid for this struct.
> -unsafe impl FromBytes for ReadVbios {}
> -// SAFETY: This struct doesn't contain uninitialized bytes and doesn't have interior mutability.
> -unsafe impl AsBytes for ReadVbios {}
>  
> -#[derive(Debug)]
> +#[derive(Debug, FromBytes, IntoBytes, zerocopy_derive::KnownLayout)]
>  #[repr(C, packed)]
>  struct FrtsRegion {
>      ver: u32,
> @@ -117,22 +101,15 @@ struct FrtsRegion {
>      size: u32,
>      ftype: u32,
>  }
> -// SAFETY: Any byte sequence is valid for this struct.
> -unsafe impl FromBytes for FrtsRegion {}
> -// SAFETY: This struct doesn't contain uninitialized bytes and doesn't have interior mutability.
> -unsafe impl AsBytes for FrtsRegion {}
>  
>  const NVFW_FRTS_CMD_REGION_TYPE_FB: u32 = 2;
>  
>  #[repr(C, packed)]
> +#[derive(FromBytes, IntoBytes, zerocopy_derive::KnownLayout)]
>  struct FrtsCmd {
>      read_vbios: ReadVbios,
>      frts_region: FrtsRegion,
>  }
> -// SAFETY: Any byte sequence is valid for this struct.
> -unsafe impl FromBytes for FrtsCmd {}
> -// SAFETY: This struct doesn't contain uninitialized bytes and doesn't have interior mutability.
> -unsafe impl AsBytes for FrtsCmd {}
>  
>  const NVFW_FALCON_APPIF_DMEMMAPPER_CMD_FRTS: u32 = 0x15;
>  const NVFW_FALCON_APPIF_DMEMMAPPER_CMD_SB: u32 = 0x19;
> @@ -151,11 +128,9 @@ pub(crate) enum FwsecCommand {
>  
>  /// A single signature that can be patched into a FWSEC image.
>  #[repr(transparent)]
> +#[derive(FromBytes)]
>  pub(crate) struct Bcrt30Rsa3kSignature([u8; BCRT30_RSA3K_SIG_SIZE]);
>  
> -/// SAFETY: A signature is just an array of bytes.
> -unsafe impl FromBytes for Bcrt30Rsa3kSignature {}
> -
>  impl From<[u8; BCRT30_RSA3K_SIG_SIZE]> for Bcrt30Rsa3kSignature {
>      fn from(sig: [u8; BCRT30_RSA3K_SIG_SIZE]) -> Self {
>          Self(sig)
> @@ -228,7 +203,7 @@ fn new_fwsec(bios: &Vbios, cmd: FwsecCommand) -> Result<Self> {
>  
>          let hdr = ucode
>              .get(hdr_offset..)
> -            .and_then(FalconAppifHdrV1::from_bytes_prefix)
> +            .and_then(|b| FalconAppifHdrV1::read_from_prefix(b).ok())
>              .ok_or(EINVAL)?
>              .0;
>  
> @@ -246,7 +221,7 @@ fn new_fwsec(bios: &Vbios, cmd: FwsecCommand) -> Result<Self> {
>  
>              let app = ucode
>                  .get(entry_offset..)
> -                .and_then(FalconAppifV1::from_bytes_prefix)
> +                .and_then(|b| FalconAppifV1::read_from_prefix(b).ok())
>                  .ok_or(EINVAL)?
>                  .0;
>  
> @@ -263,7 +238,7 @@ fn new_fwsec(bios: &Vbios, cmd: FwsecCommand) -> Result<Self> {
>  
>              let dmem_mapper = ucode
>                  .get_mut(dmem_mapper_offset..)
> -                .and_then(FalconAppifDmemmapperV3::from_bytes_mut_prefix)
> +                .and_then(|b| FalconAppifDmemmapperV3::mut_from_prefix(b).ok())
>                  .ok_or(EINVAL)?
>                  .0;
>  
> @@ -281,7 +256,7 @@ fn new_fwsec(bios: &Vbios, cmd: FwsecCommand) -> Result<Self> {
>  
>              let frts_cmd = ucode
>                  .get_mut(frts_cmd_offset..)
> -                .and_then(FrtsCmd::from_bytes_mut_prefix)
> +                .and_then(|b| FrtsCmd::mut_from_prefix(b).ok())
>                  .ok_or(EINVAL)?
>                  .0;
>  
> -- 
> 2.34.1
> 

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

Thread overview: 14+ 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
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 [this message]
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
  -- strict thread matches above, loose matches on Subject: below --
2026-07-01 17:40 [PATCH " Pedro Yudi Honda
2026-07-01 17:40 ` [PATCH v2 3/5] drm/nova: use `zerocopy` in fwsec.rs Pedro Yudi Honda
2026-07-01 17:48   ` sashiko-bot

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=akuUWHkAPHC31Va5@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.