mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Gary Guo" <gary@garyguo.net>
To: "Alexandre Courbot" <acourbot@nvidia.com>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>
Cc: "John Hubbard" <jhubbard@nvidia.com>,
	"Alistair Popple" <apopple@nvidia.com>,
	"Joel Fernandes" <joelagnelf@nvidia.com>,
	"Timur Tabi" <ttabi@nvidia.com>, "Edwin Peer" <epeer@nvidia.com>,
	"Eliot Courtney" <ecourtney@nvidia.com>,
	<nouveau@lists.freedesktop.org>, <rust-for-linux@vger.kernel.org>,
	<dri-devel@lists.freedesktop.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v11 09/12] gpu: nova-core: firmware: fix and explain v2 header offsets computations
Date: Mon, 09 Mar 2026 12:10:36 +0000	[thread overview]
Message-ID: <DGY8OSWDD5XN.2S6NSBDDDJX4@garyguo.net> (raw)
In-Reply-To: <20260306-turing_prep-v11-9-8f0042c5d026@nvidia.com>

On Fri Mar 6, 2026 at 4:52 AM GMT, Alexandre Courbot wrote:
> There are no offsets in `FalconUCodeDescV2` to give the non-secure and
> secure IMEM sections start offsets relative to the beginning of the
> firmware object.
>
> The start offsets for both sections were set to `0`, but that is
> obviously incorrect since two different sections cannot start at the
> same offset. Since these offsets were not used by the bootloader, this
> doesn't prevent proper function but is incorrect nonetheless.
>
> Fix this by computing the start of the secure IMEM section relatively to
> the start of the firmware object and setting it properly. Also add and
> improve comments to explain how the values are obtained.
>
> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
> ---
>  drivers/gpu/nova-core/firmware.rs | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/nova-core/firmware.rs b/drivers/gpu/nova-core/firmware.rs
> index c2b24906fb7e..5e56c09cc2df 100644
> --- a/drivers/gpu/nova-core/firmware.rs
> +++ b/drivers/gpu/nova-core/firmware.rs
> @@ -63,7 +63,8 @@ pub(crate) struct FalconUCodeDescV2 {
>      pub(crate) interface_offset: u32,
>      /// Base address at which to load the code segment into 'IMEM'.
>      pub(crate) imem_phys_base: u32,
> -    /// Size in bytes of the code to copy into 'IMEM'.
> +    /// Size in bytes of the code to copy into 'IMEM' (includes both secure and non-secure
> +    /// segments).
>      pub(crate) imem_load_size: u32,
>      /// Virtual 'IMEM' address (i.e. 'tag') at which the code should start.
>      pub(crate) imem_virt_base: u32,
> @@ -205,18 +206,25 @@ fn signature_versions(&self) -> u16 {
>      }
>  
>      fn imem_sec_load_params(&self) -> FalconDmaLoadTarget {
> +        // `imem_sec_base` is the *virtual* start address of the secure IMEM segment, so subtract
> +        // `imem_virt_base` to get its physical offset.
> +        let imem_sec_start = self.imem_sec_base.saturating_sub(self.imem_virt_base);

Why is saturating sub used here? I didn't see any explaination on why the
saturating semantics is preferred over checked ones.

Best,
Gary

> +
>          FalconDmaLoadTarget {
> -            src_start: 0,
> -            dst_start: self.imem_sec_base,
> +            src_start: imem_sec_start,
> +            dst_start: self.imem_phys_base.saturating_add(imem_sec_start),
>              len: self.imem_sec_size,
>          }
>      }
>  
>      fn imem_ns_load_params(&self) -> Option<FalconDmaLoadTarget> {
>          Some(FalconDmaLoadTarget {
> +            // Non-secure code always starts at offset 0.
>              src_start: 0,
>              dst_start: self.imem_phys_base,
> -            len: self.imem_load_size.checked_sub(self.imem_sec_size)?,
> +            // `imem_load_size` includes the size of the secure segment, so subtract it to
> +            // get the correct amount of data to copy.
> +            len: self.imem_load_size.saturating_sub(self.imem_sec_size),
>          })
>      }
>  


  parent reply	other threads:[~2026-03-09 12:10 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-06  4:52 [PATCH v11 00/12] gpu: nova-core: add Turing support Alexandre Courbot
2026-03-06  4:52 ` [PATCH v11 01/12] gpu: nova-core: create falcon firmware DMA objects lazily Alexandre Courbot
2026-03-06  4:52 ` [PATCH v11 02/12] gpu: nova-core: falcon: add constant for memory block alignment Alexandre Courbot
2026-03-06  4:52 ` [PATCH v11 03/12] gpu: nova-core: falcon: rename load parameters to reflect DMA dependency Alexandre Courbot
2026-03-06  6:23   ` Eliot Courtney
2026-03-06  4:52 ` [PATCH v11 04/12] gpu: nova-core: falcon: remove FalconFirmware's dependency on FalconDmaLoadable Alexandre Courbot
2026-03-06  4:52 ` [PATCH v11 05/12] gpu: nova-core: move brom_params and boot_addr to FalconFirmware Alexandre Courbot
2026-03-06  4:52 ` [PATCH v11 06/12] gpu: nova-core: add PIO support for loading firmware images Alexandre Courbot
2026-03-06  4:52 ` [PATCH v11 07/12] gpu: nova-core: falcon: remove unwarranted safety check in dma_load Alexandre Courbot
2026-03-06  4:52 ` [PATCH v11 08/12] gpu: nova-core: firmware: add comments to justify v3 header values Alexandre Courbot
2026-03-09  4:54   ` Eliot Courtney
2026-03-06  4:52 ` [PATCH v11 09/12] gpu: nova-core: firmware: fix and explain v2 header offsets computations Alexandre Courbot
2026-03-09  4:55   ` Eliot Courtney
2026-03-09 12:10   ` Gary Guo [this message]
2026-03-10  1:49     ` Alexandre Courbot
2026-03-06  4:52 ` [PATCH v11 10/12] gpu: nova-core: make Chipset::arch() const Alexandre Courbot
2026-03-06  4:52 ` [PATCH v11 11/12] gpu: nova-core: add gen_bootloader firmware to ModInfoBuilder Alexandre Courbot
2026-03-06  4:52 ` [PATCH v11 12/12] gpu: nova-core: use the Generic Bootloader to boot FWSEC on Turing Alexandre Courbot
2026-03-09  5:07   ` Eliot Courtney
2026-03-09  1:52 ` [PATCH v11 00/12] gpu: nova-core: add Turing support Alexandre Courbot
2026-03-09  2:06   ` John Hubbard
2026-03-09  2:20     ` Alexandre Courbot
2026-03-09 19:48 ` Ewan Chorynski
2026-03-09 20:04   ` John Hubbard
2026-03-09 20:18     ` Timur Tabi
2026-03-09 20:29       ` John Hubbard
2026-03-09 20:39         ` Timur Tabi
2026-03-09 21:00         ` Ewan Chorynski
2026-03-09 21:05           ` Timur Tabi
2026-03-09 21:16             ` Ewan Chorynski
2026-03-09 21:22               ` Timur Tabi

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=DGY8OSWDD5XN.2S6NSBDDDJX4@garyguo.net \
    --to=gary@garyguo.net \
    --cc=acourbot@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=apopple@nvidia.com \
    --cc=dakr@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=ecourtney@nvidia.com \
    --cc=epeer@nvidia.com \
    --cc=jhubbard@nvidia.com \
    --cc=joelagnelf@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nouveau@lists.freedesktop.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=simona@ffwll.ch \
    --cc=ttabi@nvidia.com \
    /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

all inboxes | Powered by JetHome®