From: "Danilo Krummrich" <dakr@kernel.org>
To: "Alistair Popple" <apopple@nvidia.com>
Cc: <nova-gpu@lists.linux.dev>, "Alice Ryhl" <aliceryhl@google.com>,
"David Airlie" <airlied@gmail.com>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Benno Lossin" <lossin@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Eliot Courtney" <ecourtney@nvidia.com>,
"John Hubbard" <jhubbard@nvidia.com>,
<linux-kernel@vger.kernel.org>, <dri-devel@lists.freedesktop.org>,
<rust-for-linux@vger.kernel.org>
Subject: Re: [RFC 1/3] gpu: nova-core: Add auxiliary bus registration data to nova-core
Date: Sun, 05 Jul 2026 15:00:27 +0200 [thread overview]
Message-ID: <DJQNN9FRZN3C.3DQE4H9HAZ8W6@kernel.org> (raw)
In-Reply-To: <20260703064526.3630668-2-apopple@nvidia.com>
On Fri Jul 3, 2026 at 8:45 AM CEST, Alistair Popple wrote:
> diff --git a/drivers/gpu/nova-core/auxdata.rs b/drivers/gpu/nova-core/auxdata.rs
> new file mode 100644
> index 000000000000..266b5ce4ee89
> --- /dev/null
> +++ b/drivers/gpu/nova-core/auxdata.rs
I think it'd just call it something along the lines of api.rs, as this is going
to be the file where the entry points into nova-core will live.
> @@ -0,0 +1,12 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +//! Nova-core auxbus data. Contains all the methods used by the auxbus drivers
> +//! to interact with nova-core.
> +
> +use crate::gpu::Gpu;
> +
> +/// Auxiliary bus registration data. Used by the auxbus drivers to call methods on
> +/// the GPU.
> +pub struct AuxData<'bound> {
Since this will also be the data type that will be exposed as an API entry point
into nova-core, I'd rather call it e.g. NovaCoreApi.
We should provide an assoicated function NovaCoreApi::of(), which takes an &'a
auxiliary::Device<Bound> as argument and returns &'a NovaCoreApi<'a> (at least
as long as the type remains covariant).
This makes it a bit cleaner since it keeps the type assertion local to a single
place and makes it transparent to nova-drm that this also is the
auxiliary::Registration private data of nova-core.
(I'm already working on getting rid of the type ID check, but going through
NovaCoreApi::of() is cleaner regardless.)
> + pub(crate) _gpu: &'bound Gpu<'bound>,
I'd store this as Pin<&'bound Gpu<'bound>> as it better documents the pinning
guarantee and allows calling Pin<&Self> methods on Gpu.
> @@ -78,7 +82,7 @@ fn probe<'bound>(
> pdev.enable_device_mem()?;
> pdev.set_master();
>
> - Ok(try_pin_init!(NovaCore {
> + Ok(try_pin_init!(&this in NovaCore {
This change shouldn't be needed.
> bar: pdev.iomap_region_sized::<BAR0_SIZE>(0, c"nova-core/bar0")?,
> // TODO: Use `&bar` self-referential pin-init syntax once available.
> //
> @@ -86,15 +90,32 @@ fn probe<'bound>(
> // (`try_pin_init!()` initializes fields in declaration order), lives at a pinned
> // stable address, and is dropped after `gpu` (struct field drop order).
> gpu <- Gpu::new(pdev, unsafe { &*core::ptr::from_ref(bar) }),
> - _reg: auxiliary::Registration::new(
> - pdev.as_ref(),
> - c"nova-drm",
> - // TODO[XARR]: Use XArray or perhaps IDA for proper ID allocation/recycling. For
> - // now, use a simple atomic counter that never recycles IDs.
> - AUXILIARY_ID_COUNTER.fetch_add(1, Relaxed),
> - crate::MODULE_NAME,
> - (),
> - )?,
> +
> + // SAFETY:
> + // - `NovaCore` is dropped when the device is unbound; i.e.
> + // `mem::forget()` is never called on it.
> + // - `gpu` is initialized above, lives at a pinned stable
> + // address, and is dropped after `_reg` (struct field drop
> + // order).
> + _reg: unsafe {
> + auxiliary::Registration::new_with_lt(
> + pdev.as_ref(),
> + c"nova-drm",
> + // TODO[XARR]: Use XArray or perhaps IDA for proper ID allocation/recycling.
> + // For now, use a simple atomic counter that never recycles IDs.
> + AUXILIARY_ID_COUNTER.fetch_add(1, Relaxed),
> + crate::MODULE_NAME,
> + AuxData {
> + // TODO: Use `&gpu` self-referential pin-init syntax once available.
> + //
> + // SAFETY: `this.gpu` is initialized before this expression is evaluated
> + // (`try_pin_init!()` initializes fields in declaration order), lives at
> + // a pinned stable address, and is dropped after `_reg` (struct field
> + // drop order).
> + _gpu: &*core::ptr::from_ref(&this.as_ref().gpu),
This is UB, we can't create a reference from 'this' before it is fully
initialized.
gpu: &*core::ptr::from_ref(gpu.as_ref().get_ref()),
should work instead and also gets us rid of this entirely. Or rather
gpu: Pin::new_unchecked(
&*core::ptr::from_ref(gpu.as_ref().get_ref()),
),
if stored as Pin<&'bound Gpu<'bound>>.
> + },
> + )?
> + },
> }))
> })
> }
next prev parent reply other threads:[~2026-07-05 13:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-03 6:45 [RFC 0/3] gpu: nova: Export parameters from nova-core to nova-drm Alistair Popple
2026-07-03 6:45 ` [RFC 1/3] gpu: nova-core: Add auxiliary bus registration data to nova-core Alistair Popple
2026-07-05 13:00 ` Danilo Krummrich [this message]
2026-07-05 17:09 ` Danilo Krummrich
2026-07-06 3:20 ` Alistair Popple
2026-07-03 6:45 ` [RFC 2/3] drm: nova: Add GETPARAM parameter to read the GPU chipset Alistair Popple
2026-07-03 6:45 ` [RFC 3/3] drm: nova: Add a GETPARAM parameter to read usable VRAM size Alistair Popple
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=DJQNN9FRZN3C.3DQE4H9HAZ8W6@kernel.org \
--to=dakr@kernel.org \
--cc=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=aliceryhl@google.com \
--cc=apopple@nvidia.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=ecourtney@nvidia.com \
--cc=gary@garyguo.net \
--cc=jhubbard@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=nova-gpu@lists.linux.dev \
--cc=rust-for-linux@vger.kernel.org \
/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