All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alexandre Courbot" <acourbot@nvidia.com>
To: "Danilo Krummrich" <dakr@kernel.org>
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 v3 02/11] gpu: nova-core: move GSP boot code out of `Gpu` constructor
Date: Wed, 03 Sep 2025 21:29:51 +0900	[thread overview]
Message-ID: <DCJ5ZOH6DO2S.8GGF9FABSVNT@nvidia.com> (raw)
In-Reply-To: <DCJ46WGRUXR8.1GKGGL2568E1X@kernel.org>

On Wed Sep 3, 2025 at 8:05 PM JST, Danilo Krummrich wrote:
> On Wed Sep 3, 2025 at 12:44 PM CEST, Alexandre Courbot wrote:
>> On Wed Sep 3, 2025 at 5:26 PM JST, Danilo Krummrich wrote:
>>> On Wed Sep 3, 2025 at 9:08 AM CEST, Alexandre Courbot wrote:
>>>> On Wed Sep 3, 2025 at 4:53 AM JST, Danilo Krummrich wrote:
>>>>> On Tue Sep 2, 2025 at 4:31 PM CEST, Alexandre Courbot wrote:
>>>>>> diff --git a/drivers/gpu/nova-core/driver.rs b/drivers/gpu/nova-core/driver.rs
>>>>>> index 274989ea1fb4a5e3e6678a08920ddc76d2809ab2..1062014c0a488e959379f009c2e8029ffaa1e2f8 100644
>>>>>> --- a/drivers/gpu/nova-core/driver.rs
>>>>>> +++ b/drivers/gpu/nova-core/driver.rs
>>>>>> @@ -6,6 +6,8 @@
>>>>>>  
>>>>>>  #[pin_data]
>>>>>>  pub(crate) struct NovaCore {
>>>>>> +    // Placeholder for the real `Gsp` object once it is built.
>>>>>> +    pub(crate) gsp: (),
>>>>>>      #[pin]
>>>>>>      pub(crate) gpu: Gpu,
>>>>>>      _reg: auxiliary::Registration,
>>>>>> @@ -40,8 +42,14 @@ fn probe(pdev: &pci::Device<Core>, _info: &Self::IdInfo) -> Result<Pin<KBox<Self
>>>>>>          )?;
>>>>>>  
>>>>>>          let this = KBox::pin_init(
>>>>>> -            try_pin_init!(Self {
>>>>>> +            try_pin_init!(&this in Self {
>>>>>>                  gpu <- Gpu::new(pdev, bar)?,
>>>>>> +                gsp <- {
>>>>>> +                    // SAFETY: `this.gpu` is initialized to a valid value.
>>>>>> +                    let gpu = unsafe { &(*this.as_ptr()).gpu };
>>>>>> +
>>>>>> +                    gpu.start_gsp(pdev)?
>>>>>> +                },
>>>>>
>>>>> Please use pin_chain() [1] for this.
>>>>
>>>> Sorry, but I couldn't figure out how I can use pin_chain here (and
>>>> couldn't find any relevant example in the kernel code either). Can you
>>>> elaborate a bit?
>>>
>>> I thought of just doing the following, which I think should be equivalent (diff
>>> against current nova-next).
>>>
>>> diff --git a/drivers/gpu/nova-core/driver.rs b/drivers/gpu/nova-core/driver.rs
>>> index 274989ea1fb4..6d62867f7503 100644
>>> --- a/drivers/gpu/nova-core/driver.rs
>>> +++ b/drivers/gpu/nova-core/driver.rs
>>> @@ -41,7 +41,9 @@ fn probe(pdev: &pci::Device<Core>, _info: &Self::IdInfo) -> Result<Pin<KBox<Self
>>>
>>>          let this = KBox::pin_init(
>>>              try_pin_init!(Self {
>>> -                gpu <- Gpu::new(pdev, bar)?,
>>> +                gpu <- Gpu::new(pdev, bar)?.pin_chain(|gpu| {
>>> +                    gpu.start_gsp(pdev)
>>> +                }),
>>>                  _reg: auxiliary::Registration::new(
>>>                      pdev.as_ref(),
>>>                      c_str!("nova-drm"),
>>> diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs
>>> index 8caecaf7dfb4..211bc1a5a5b3 100644
>>> --- a/drivers/gpu/nova-core/gpu.rs
>>> +++ b/drivers/gpu/nova-core/gpu.rs
>>> @@ -266,7 +266,7 @@ fn run_fwsec_frts(
>>>      pub(crate) fn new(
>>>          pdev: &pci::Device<device::Bound>,
>>>          devres_bar: Arc<Devres<Bar0>>,
>>> -    ) -> Result<impl PinInit<Self>> {
>>> +    ) -> Result<impl PinInit<Self, Error>> {
>>>          let bar = devres_bar.access(pdev.as_ref())?;
>>>          let spec = Spec::new(bar)?;
>>>          let fw = Firmware::new(pdev.as_ref(), spec.chipset, FIRMWARE_VERSION)?;
>>> @@ -302,11 +302,16 @@ pub(crate) fn new(
>>>
>>>          Self::run_fwsec_frts(pdev.as_ref(), &gsp_falcon, bar, &bios, &fb_layout)?;
>>>
>>> -        Ok(pin_init!(Self {
>>> +        Ok(try_pin_init!(Self {
>>>              spec,
>>>              bar: devres_bar,
>>>              fw,
>>>              sysmem_flush,
>>>          }))
>>>      }
>>> +
>>> +    pub(crate) fn start_gsp(&self, _pdev: &pci::Device<device::Core>) -> Result {
>>> +        // noop
>>> +        Ok(())
>>> +    }
>>>  }
>>>
>>> But maybe it doesn't capture your intend?
>>
>> The issue is that `start_gsp` returns a value (currently a placeholder
>> `()`, but it will change into a real type) that needs to be stored into
>> the newly-introduced `gsp` member of `NovaCore`. I could not figure how
>> how `pin_chain` could help with this (and this is the same problem for
>> the other `unsafe` statements in `firmware/gsp.rs`).
>
> Ok, I see, I think Benno is already working on a solution to access previously
> initialized fields from subsequent initializers.
>
> @Benno: What's the status of this? I haven't seen an issue for that in the
> pin-init GitHub repo, should we create one?
>
> However, in this case I'm a bit confused why we want Gsp next to Gpu? Why not
> just make Gsp a member of Gpu then?

To be honest I am not completely sure about the best layout yet and will
need more visibility to understand whether this is optimal. But
considering that we want to run the GSP boot process over a built `Gpu`
instance, we cannot store the result of said process inside `Gpu` unless
we put it inside e.g. an `Option`. But then the variant will always be
`Some` after `probe` returns, and yet we will have to perform a match
every time we want to access it.

The current separation sounds reasonable to me for the time being, with
`Gpu` containing purely hardware resources obtained without help from
user-space, while `Gsp` is the result of running a bunch of firmwares.
An alternative design would be to store `Gpu` inside `Gsp`, but `Gsp`
inside `Gpu` is trickier due to the build order. No matter what we do,
switching the layout later should be trivial if we don't choose the
best one now.

There is also an easy workaround to the sibling initialization issue,
which is to store `Gpu` and `Gsp` behind `Pin<KBox>` - that way we can
initialize both outside `try_pin_init!`, at the cost of two more heap
allocations over the whole lifetime of the device. If we don't have a
proper solution to the problem now, this might be better than using
`unsafe` as a temporary solution.

The same workaround could also be used for to `GspFirmware` and its page
tables - since `GspFirmware` is temporary and can apparently be
discarded after the GSP is booted, this shouldn't be a big issue. This
will allow the driver to probe, and we can add TODO items to fix that
later if a solution is in sight.

>
> I thought the intent was to keep temporary values local to start_gsp() and not
> store them next to Gpu in the same allocation?

It is not visible in the current patchset, but `start_gsp` will
eventually return the runtime data of the GSP - notably its log buffers
and command queue, which are needed to operate it. All the rest (notably
the loaded firmwares) will be local to `start_gsp` and discarded upon
its return.

  reply	other threads:[~2025-09-03 12:30 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-02 14:31 [PATCH v3 00/11] gpu: nova-core: process and prepare more firmwares to boot GSP Alexandre Courbot
2025-09-02 14:31 ` [PATCH v3 01/11] gpu: nova-core: require `Send` on `FalconEngine` and `FalconHal` Alexandre Courbot
2025-09-02 14:31 ` [PATCH v3 02/11] gpu: nova-core: move GSP boot code out of `Gpu` constructor Alexandre Courbot
2025-09-02 19:53   ` Danilo Krummrich
2025-09-03  7:08     ` Alexandre Courbot
2025-09-03  7:21       ` Alexandre Courbot
2025-09-03  8:26       ` Danilo Krummrich
2025-09-03 10:44         ` Alexandre Courbot
2025-09-03 11:05           ` Danilo Krummrich
2025-09-03 12:29             ` Alexandre Courbot [this message]
2025-09-03 14:53               ` Danilo Krummrich
2025-09-04 15:28                 ` Joel Fernandes
2025-09-02 23:12   ` Danilo Krummrich
2025-09-03  7:10     ` Alexandre Courbot
2025-09-03  8:27       ` Danilo Krummrich
2025-09-09 14:11         ` Alexandre Courbot
2025-09-09 14:43           ` Danilo Krummrich
2025-09-10  4:48             ` Alexandre Courbot
2025-09-10  8:01               ` Danilo Krummrich
2025-09-10 11:18                 ` Alexandre Courbot
2025-09-10 11:22                   ` Alexandre Courbot
2025-09-10 11:22                   ` Danilo Krummrich
2025-09-02 14:31 ` [PATCH v3 03/11] gpu: nova-core: add Chipset::name() method Alexandre Courbot
2025-09-02 14:31 ` [PATCH v3 04/11] gpu: nova-core: firmware: move firmware request code into a function Alexandre Courbot
2025-09-02 14:31 ` [PATCH v3 05/11] gpu: nova-core: firmware: add support for common firmware header Alexandre Courbot
2025-09-02 14:32 ` [PATCH v3 06/11] gpu: nova-core: firmware: process Booter and patch its signature Alexandre Courbot
2025-09-02 14:32 ` [PATCH v3 07/11] gpu: nova-core: firmware: process and prepare the GSP firmware Alexandre Courbot
2025-09-02 14:32 ` [PATCH v3 08/11] gpu: nova-core: firmware: process the GSP bootloader Alexandre Courbot
2025-09-02 14:32 ` [PATCH v3 09/11] gpu: nova-core: firmware: use 570.144 firmware Alexandre Courbot
2025-09-02 14:32 ` [PATCH v3 10/11] gpu: nova-core: Add base files for r570.144 firmware bindings Alexandre Courbot
2025-09-02 14:32 ` [PATCH v3 11/11] gpu: nova-core: compute layout of more framebuffer regions required for GSP Alexandre Courbot

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=DCJ5ZOH6DO2S.8GGF9FABSVNT@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 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.