rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Alexandre Courbot" <acourbot@nvidia.com>
To: "Danilo Krummrich" <dakr@kernel.org>,
	"Alexandre Courbot" <acourbot@nvidia.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"John Hubbard" <jhubbard@nvidia.com>,
	"Alistair Popple" <apopple@nvidia.com>,
	"Joel Fernandes" <joelagnelf@nvidia.com>,
	"Timur Tabi" <ttabi@nvidia.com>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
	nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v5 02/12] gpu: nova-core: move GSP boot code to a dedicated method
Date: Thu, 11 Sep 2025 22:26:08 +0900	[thread overview]
Message-ID: <DCQ074EMFNIK.1OJLWJXWZLDXZ@nvidia.com> (raw)
In-Reply-To: <ce74db34-77bc-4207-94c8-6e0580189448@kernel.org>

On Thu Sep 11, 2025 at 9:46 PM JST, Danilo Krummrich wrote:
> On 9/11/25 2:17 PM, Alexandre Courbot wrote:
>> On Thu Sep 11, 2025 at 8:22 PM JST, Danilo Krummrich wrote:
>>> On 9/11/25 1:04 PM, Alexandre Courbot wrote:
>>>> +    /// Attempt to start the GSP.
>>>> +    ///
>>>> +    /// This is a GPU-dependent and complex procedure that involves loading firmware files from
>>>> +    /// user-space, patching them with signatures, and building firmware-specific intricate data
>>>> +    /// structures that the GSP will use at runtime.
>>>> +    ///
>>>> +    /// Upon return, the GSP is up and running, and its runtime object given as return value.
>>>> +    pub(crate) fn start_gsp(
>>>> +        pdev: &pci::Device<device::Bound>,
>>>> +        bar: &Bar0,
>>>> +        chipset: Chipset,
>>>> +        gsp_falcon: &Falcon<Gsp>,
>>>> +        _sec2_falcon: &Falcon<Sec2>,
>>>> +    ) -> Result<()> {> +        let dev = pdev.as_ref();
>>>> +
>>>> +        let bios = Vbios::new(dev, bar)?;
>>>> +
>>>> +        let fb_layout = FbLayout::new(chipset, bar)?;
>>>> +        dev_dbg!(dev, "{:#x?}\n", fb_layout);
>>>> +
>>>> +        Self::run_fwsec_frts(dev, gsp_falcon, bar, &bios, &fb_layout)?;
>>>> +
>>>> +        // Return an empty placeholder for now, to be replaced with the GSP runtime data.
>>>> +        Ok(())
>>>> +    }
>>>
>>> I'd rather create the Gsp structure already, move the code to Gsp::new() and
>>> return an impl PinInit<Self, Error>. If you don't want to store any of the
>>> object instances you create above yet, you can just stuff all the code into an
>>> initializer code block, as you do in the next patch with
>>> gfw::wait_gfw_boot_completion().
>> 
>> I don't think that would work, or be any better even if it did. The full
>> GSP initialization is pretty complex and all we need to return is one
>> object created at the beginning that doesn't need to be pinned.
>> Moreover, the process is also dependent on the GPU family and completely
>> different on Hopper/Blackwell.
>
> Why would it not work? There is no difference between the code above being
> executed from an initializer block or directly in Gsp::new().

Yeah, that's pretty much my point. :) Why run it in an initializer if
the result doesn't need to be initialized in-place anyway?

>> You can see the whole process on [1]. `libos` is the object that is
>> returned (although its name and type will change). All the rest it
>> loading, preparing and running firmware, and that is done on the GPU. I
>> think it would be very out of place in the GSP module.
>> 
>> It is also very step-by-step: run this firmware, wait for it to
>> complete, run another one, wait for a specific message from the GSP, run
>> the sequencer, etc. And most of this stuff is thrown away once the GSP
>> is running. That's where the limits of what we can do with `pin_init!`
>> are reached, and the GSP object doesn't need to be pinned anyway.
>
> I don't see that, in the code you linked you have a bunch of calls that don't
> return anything that needs to survive, this can be in an initializer block.
>
> And then you have
>
> let mut libos = gsp::GspMemObjects::new(pdev, bar)?;
>
> which only needs the device reference and the bar reference.
>
> So you can easily write this as:
>
> try_pin_init!(Self {
>    _: {
>       // all the throw-away stuff from above
>    },
>    libos <- gsp::GspMemObjects::new(pdev, bar),
>    _: {
>       libos.do_some_stuff_mutable()?;
>    }
> })

Can the second initializer block access variables created in the first?
I suspect we can also initialize `libos` first, and move everything in a
block, but then my question would be why do we need to jump through that
hoop.

>> By keeping the initialization in the GPU, we can keep the GSP object
>> architecture-independent, and I think it makes sense from a design point
>> of view. That's not to say this code should be in `gpu.rs`, maybe we
>> want to move it to a GPU HAL, or if we really want this as part of the
>> GSP a `gsp/boot` module supporting all the different archs. But I'd
>> prefer to think about this when we start supporting several
>> architectures.
>
> Didn't we talk about a struct Gsp that will eventually be returned by
> Self::start_gsp(), or did I make this up in my head?
>
> The way I think about this is that we'll have a struct Gsp that represents the
> entry point in the driver to mess with the GSP command queue.
>
> But either way, this throws up two questions, if Self::start_gsp() return a
> struct GspMemObjects instead (which is probably the same thing with a different
> name), then:
>
> Are we sure this won't need any locks? If it will need locking (which I expect)
> then it needs pin-init.

Sorry, I have been imprecise: I should I said: "it can be moved" rather
than "it doesn't need to be pinned". In that case I don't think
`Gsp::new` needs to return an `impl PinInit`, right?

>
> If it never needs pinning why did you write it as
>
> gsp <- Self::start_gsp(pdev, bar, spec.chipset, gsp_falcon, sec2_falcon)?,
>
> in a patch 3?
>> [1] https://github.com/Gnurou/linux/blob/gsp_init_rebase/drivers/gpu/nova-core/gpu.rs#L305

Ah, I blindly copied that part from your initial suggestion [1] and
forgot to double check that part. We can use `:` here for `gsp`, as the
returned value of `start_gsp` can be moved without any issue. So if we
put it behind a lock at the `Gpu` level, the current pattern should not
be a problem as it can be moved where needed by the `Gpu` initializer.

Now I don't have a precise idea of how we are going to do locking, and
you seem to have given it more thought than I have, so please let me
know if I am still missing something.

[1] https://lore.kernel.org/rust-for-linux/DCOCL398HXDH.3QH9U6UGGIUP1@kernel.org/


  reply	other threads:[~2025-09-11 13:26 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-11 11:04 [PATCH v5 00/12] gpu: nova-core: process and prepare more firmwares to boot GSP Alexandre Courbot
2025-09-11 11:04 ` [PATCH v5 01/12] gpu: nova-core: require `Send` on `FalconEngine` and `FalconHal` Alexandre Courbot
2025-09-11 11:04 ` [PATCH v5 02/12] gpu: nova-core: move GSP boot code to a dedicated method Alexandre Courbot
2025-09-11 11:22   ` Danilo Krummrich
2025-09-11 12:17     ` Alexandre Courbot
2025-09-11 12:46       ` Danilo Krummrich
2025-09-11 13:26         ` Alexandre Courbot [this message]
2025-09-11 14:22           ` Benno Lossin
2025-09-13  1:02           ` Joel Fernandes
2025-09-13 13:30             ` Danilo Krummrich
2025-09-13 17:13               ` Joel Fernandes
2025-09-13 19:53                 ` Danilo Krummrich
2025-09-13 23:02                   ` Joel Fernandes
2025-09-14  7:58                     ` Benno Lossin
2025-09-13 20:37                 ` Miguel Ojeda
2025-09-13 21:16                   ` Joel Fernandes
2025-09-13 21:29                   ` John Hubbard
2025-09-13 22:06                     ` Joel Fernandes
2025-09-14  1:49                       ` Alexandre Courbot
2025-09-14 14:42                         ` Benno Lossin
2025-09-15  4:59                           ` Alexandre Courbot
2025-09-15  6:44                             ` Benno Lossin
2025-09-11 11:04 ` [PATCH v5 03/12] gpu: nova-core: initialize Gpu structure fully in-place Alexandre Courbot
2025-09-11 11:04 ` [PATCH v5 04/12] gpu: nova-core: add Chipset::name() method Alexandre Courbot
2025-09-11 11:04 ` [PATCH v5 05/12] gpu: nova-core: firmware: move firmware request code into a function Alexandre Courbot
2025-09-11 11:23   ` Danilo Krummrich
2025-09-11 12:18     ` Alexandre Courbot
2025-09-11 11:04 ` [PATCH v5 06/12] gpu: nova-core: firmware: add support for common firmware header Alexandre Courbot
2025-09-11 11:04 ` [PATCH v5 07/12] gpu: nova-core: firmware: process Booter and patch its signature Alexandre Courbot
2025-09-11 11:04 ` [PATCH v5 08/12] gpu: nova-core: firmware: process and prepare the GSP firmware Alexandre Courbot
2025-09-11 11:27   ` Danilo Krummrich
2025-09-11 12:29     ` Alexandre Courbot
2025-09-11 12:31       ` Danilo Krummrich
2025-09-11 11:04 ` [PATCH v5 09/12] gpu: nova-core: firmware: process the GSP bootloader Alexandre Courbot
2025-09-11 11:04 ` [PATCH v5 10/12] gpu: nova-core: firmware: use 570.144 firmware Alexandre Courbot
2025-09-11 11:04 ` [PATCH v5 11/12] gpu: nova-core: Add base files for r570.144 firmware bindings Alexandre Courbot
2025-09-11 11:04 ` [PATCH v5 12/12] gpu: nova-core: compute layout of more framebuffer regions required for GSP Alexandre Courbot
2025-09-11 11:28 ` [PATCH v5 00/12] gpu: nova-core: process and prepare more firmwares to boot GSP Danilo Krummrich

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=DCQ074EMFNIK.1OJLWJXWZLDXZ@nvidia.com \
    --to=acourbot@nvidia.com \
    --cc=a.hindborg@kernel.org \
    --cc=airlied@gmail.com \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=apopple@nvidia.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gary@garyguo.net \
    --cc=jhubbard@nvidia.com \
    --cc=joelagnelf@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=nouveau@lists.freedesktop.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tmgross@umich.edu \
    --cc=ttabi@nvidia.com \
    --cc=tzimmermann@suse.de \
    /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;
as well as URLs for NNTP newsgroup(s).