From: "Alexandre Courbot" <acourbot@nvidia.com>
To: "Eliot Courtney" <ecourtney@nvidia.com>
Cc: "Danilo Krummrich" <dakr@kernel.org>,
"Lorenzo Stoakes" <ljs@kernel.org>,
"Vlastimil Babka" <vbabka@kernel.org>,
"Liam R. Howlett" <liam@infradead.org>,
"Uladzislau Rezki" <urezki@gmail.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "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>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Onur Özkan" <work@onurozkan.dev>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"John Hubbard" <jhubbard@nvidia.com>,
"Alistair Popple" <apopple@nvidia.com>,
"Timur Tabi" <ttabi@nvidia.com>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v3 7/8] gpu: nova-core: add NVKV typed decoding
Date: Wed, 07 Oct 2026 21:05:28 +0900 [thread overview]
Message-ID: <DLYLCD5IPKGZ.2DMT37GPHPP74@nvidia.com> (raw)
In-Reply-To: <20260928-b4-nvkv-v3-7-f04504c262c2@nvidia.com>
Sorry, some follow-up comments after my previous review.
On Mon Sep 28, 2026 at 5:42 PM JST, Eliot Courtney wrote:
> Similar to the typed encoding layer, add some decoding type machinery.
> Add a simple macro `nvkv_decode!` which implements `Schema` for a struct
> by composing visit calls to each member. Add some common `Schema` kinds,
> such as `Array` which collects an array value into a fixed maximum size
> array, and `Required` which fails a decode if the value is not sent.
>
> Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
> ---
> drivers/gpu/nova-core/gsp/nvkv.rs | 11 +-
> drivers/gpu/nova-core/gsp/nvkv/decode.rs | 622 ++++++++++++++++++++++++++++++-
> 2 files changed, 628 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/nova-core/gsp/nvkv.rs b/drivers/gpu/nova-core/gsp/nvkv.rs
> index 7ac3a459a98b..5791df07a7fa 100644
> --- a/drivers/gpu/nova-core/gsp/nvkv.rs
> +++ b/drivers/gpu/nova-core/gsp/nvkv.rs
> @@ -9,7 +9,7 @@
> //! function calls will map to some struct - for example, f(GPU_NAME_STRING_KEY, 0, b"some gpu")
> //! naturally maps to storing a &str with the GPU name.
>
> -#![expect(unused_imports)]
> +#![cfg_attr(not(CONFIG_KUNIT), expect(unused_imports))]
> #![cfg_attr(not(CONFIG_KUNIT), expect(unused_macros))]
>
> use core::{
> @@ -23,7 +23,8 @@
> use kernel::{
> alloc::{
> allocator::KVmalloc,
> - Allocator, //
> + Allocator,
> + ArrayVec, //
> },
> bitfield,
> num::Bounded,
> @@ -148,6 +149,12 @@ fn default() -> Self {
> }
> }
>
> +/// A schema field for an array value under the NVKV key `KEY_ID`.
> +#[repr(transparent)]
I see that `#[repr(transparent)]` is used several times in this series,
but is there a need for it? Same for the many `#[inline]`s, here I feel
like letting the compiler arrange things as it wants might be the better
call. I know I suggested downgrading from always-inline to just inline,
so maybe we should go all the way here. These are very likely to be
inlined anyway, and worst case I don't think a function call would
induce a big cost.
<...>
> +impl<T: Default, const KEY_ID: KeyId> Schema for Key<T, KEY_ID> {
> + type Target = T;
> +
> + #[inline]
> + fn init() -> impl Init<Self> {
> + Self::default()
> + }
> +
> + #[inline]
> + fn finish(&mut self) -> impl Init<Self::Target, Error> + '_ {
> + Ok(core::mem::take(&mut self.0))
> + }
> +}
Both methods return the built value on the stack, which is fine when we
only deal with scalars but technically we could also store larger
values. How about a `const_assert!` ensuring we don't go beyond, say, 32
bytes for the size of `T` and `Target`?
<...>
> +/// A schema field for a key that must be present.
> +///
> +/// `finish` fails with `EINVAL` if no value arrived for the key.
> +#[repr(transparent)]
> +pub(crate) struct Required<T, const KEY_ID: KeyId>(Key<Option<T>, KEY_ID>);
> +
> +impl<T, const KEY_ID: KeyId> Schema for Required<T, KEY_ID> {
> + type Target = T;
> +
> + #[inline]
> + fn init() -> impl Init<Self> {
> + Self(None.into())
> + }
> +
> + #[inline]
> + fn finish(&mut self) -> impl Init<Self::Target, Error> + '_ {
> + (self.0).0.take().ok_or(EINVAL)
I've experimented a bit with my earlier suggestion of having a wrapping
`Required` type because I wasn't so sure it would work, but it seems to
be indeed doable! Here is my draft implementation:
pub(crate) struct Required<S: Schema> {
inner: S,
parsed: bool,
}
impl<S: Schema> Schema for Required<S> {
type Target = S::Target;
fn init() -> impl Init<Self> {
init!(Self { inner <- S::init(), parsed: false })
}
fn finish(&mut self) -> impl Init<Self::Target, Error> + '_ {
// Reset `self.parsed` to make the schema empty again per the method contract.
let parsed = core::mem::take(&mut self.parsed);
self.inner
.finish()
.chain(move |_| if parsed { Ok(()) } else { Err(EINVAL) })
}
}
impl<'data, S: Schema + Visit<'data>> Visit<'data> for Required<S> {
fn visit(&mut self, key: KeyId, index: Index, value: DecoderValue<'data>) -> Result<bool> {
let consumed = self.inner.visit(key, index, value)?;
self.parsed |= consumed;
Ok(consumed)
}
}
You need to convert all the `Required<T, ...>` into `Required<Key<T,
...>>`, but this reads more logically I think, and now you can combine
`Required` with more types. I believe you could also implement
`Optional` in a similar way.
(you will also need to add a `#[derive(Default)]` to `FbRegionFlags` on
the next patch, but that's not a big deal since it wraps a primitive
type anyway)
next prev parent reply other threads:[~2026-10-07 12:05 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-28 8:42 [PATCH v3 0/8] gpu: nova-core: add NVKV codec Eliot Courtney
2026-09-28 8:42 ` [PATCH v3 1/8] rust: alloc: add Vec::try_push_init Eliot Courtney
2026-10-06 5:52 ` Alexandre Courbot
2026-09-28 8:42 ` [PATCH v3 2/8] rust: alloc: add Vec::push_init Eliot Courtney
2026-10-06 6:10 ` Alexandre Courbot
2026-09-28 8:42 ` [PATCH v3 3/8] rust: alloc: add ArrayVec Eliot Courtney
2026-10-07 6:27 ` Alexandre Courbot
2026-09-28 8:42 ` [PATCH v3 4/8] gpu: nova-core: add NVKV encoder Eliot Courtney
2026-10-07 3:43 ` Alexandre Courbot
2026-10-07 3:48 ` Alexandre Courbot
2026-10-07 11:33 ` John Hubbard
2026-10-07 11:56 ` Alexandre Courbot
2026-09-28 8:42 ` [PATCH v3 5/8] gpu: nova-core: add NVKV decoder Eliot Courtney
2026-10-07 4:51 ` Alexandre Courbot
2026-09-28 8:42 ` [PATCH v3 6/8] gpu: nova-core: add NVKV typed encoding Eliot Courtney
2026-10-07 6:30 ` Alexandre Courbot
2026-09-28 8:42 ` [PATCH v3 7/8] gpu: nova-core: add NVKV typed decoding Eliot Courtney
2026-10-07 6:30 ` Alexandre Courbot
2026-10-07 12:05 ` Alexandre Courbot [this message]
2026-09-28 8:42 ` [PATCH v3 8/8] gpu: nova-core: add NVKV GSP_INIT schemas Eliot Courtney
2026-10-07 10:53 ` 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=DLYLCD5IPKGZ.2DMT37GPHPP74@nvidia.com \
--to=acourbot@nvidia.com \
--cc=a.hindborg@kernel.org \
--cc=airlied@gmail.com \
--cc=aliceryhl@google.com \
--cc=apopple@nvidia.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=ecourtney@nvidia.com \
--cc=gary@garyguo.net \
--cc=jhubbard@nvidia.com \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ljs@kernel.org \
--cc=lossin@kernel.org \
--cc=nova-gpu@lists.linux.dev \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=ttabi@nvidia.com \
--cc=urezki@gmail.com \
--cc=vbabka@kernel.org \
--cc=work@onurozkan.dev \
/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®