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,
dri-devel <dri-devel-bounces@lists.freedesktop.org>
Subject: Re: [PATCH v2 6/8] gpu: nova-core: add NVKV typed encoding
Date: Fri, 11 Sep 2026 20:18:16 +0900 [thread overview]
Message-ID: <DLCG22C6X96C.3A8EKCQAZ37FD@nvidia.com> (raw)
In-Reply-To: <DLC8MGO86DKV.3IIHPUADV9IRY@nvidia.com>
On Fri Sep 11, 2026 at 2:28 PM JST, Eliot Courtney wrote:
> On Fri Sep 11, 2026 at 2:17 PM JST, Alexandre Courbot wrote:
>> On Thu Sep 10, 2026 at 5:10 PM JST, Alexandre Courbot wrote:
>>> On Thu Aug 27, 2026 at 11:12 PM JST, Eliot Courtney wrote:
>>>> For struct-like GMCAPI messages encoding field by field manually is
>>>> noisy. Add some type machinery and a macro to automate encoding of
>>>> struct-like messages. The `Encodeable` trait can be implemented by any
>>>> type to say that it can be encoded into an NVKV `Encoder`. Add a simple
>>>> `nvkv_encode!` macro that works on structs and encodes each field in
>>>> order. Provide some base types, such as `Key` which statically
>>>> associates a NVKV key with some value, to avoid having to make a lot of
>>>> newtypes and implement `Encodeable` on them.
>>>>
>>>> Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
>>>> ---
>>>> drivers/gpu/nova-core/gsp/nvkv.rs | 49 ++++++++-
>>>> drivers/gpu/nova-core/gsp/nvkv/encode.rs | 178 +++++++++++++++++++++++++++++++
>>>> 2 files changed, 226 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/drivers/gpu/nova-core/gsp/nvkv.rs b/drivers/gpu/nova-core/gsp/nvkv.rs
>>>> index cbeee7f376b6..10dcbb9e602c 100644
>>>> --- a/drivers/gpu/nova-core/gsp/nvkv.rs
>>>> +++ b/drivers/gpu/nova-core/gsp/nvkv.rs
>>>> @@ -10,8 +10,13 @@
>>>> //! naturally maps to storing a &str with the GPU name.
>>>>
>>>> #![expect(unused_imports)]
>>>> +#![cfg_attr(not(CONFIG_KUNIT), expect(unused_macros))]
>>>>
>>>> -use core::ops::Deref;
>>>> +use core::marker::PhantomData;
>>>> +use core::ops::{
>>>> + Deref,
>>>> + DerefMut, //
>>>> +};
>>>>
>>>> use kernel::{
>>>> alloc::{
>>>> @@ -92,6 +97,48 @@ fn deref(&self) -> &Self::Target {
>>>> /// The index of an NVKV value.
>>>> pub(crate) type Index = Bounded<u64, 12>;
>>>>
>>>> +/// A static association between an NVKV key `KEY_ID` and the storage of its value.
>>>> +///
>>>> +/// Use with the encoder or decoder macros `nvkv_encode!` and `nvkv_decode!` to let them know how to
>>>> +/// map the value `Key<T, KEY_ID, As>` to/from encoded data. For brevity, `As` inserts an additional
>>>> +/// conversion (`From`) to avoid having to implement [`Encodable`] for many types. For example,
>>>> +/// enums that are easily convertible to a u32 can have `As = u32` and rely on the existing encoding
>>>> +/// for u32.
>>>> +#[repr(transparent)]
>>>> +pub(crate) struct Key<T, const KEY_ID: KeyId, As = T>(pub(crate) T, PhantomData<As>);
>>>
>>> Does the `T` need to be `pub(crate)`? The series builds fine with it
>>> being private.
>>>
>>> Also the relationship between `Key` and `IndexedKey` is a bit unclear
>>> with the current type layout. IIUC `Key` is basically a specialization
>>> of `IndexedKey` with an index of 0. And yet `Key` is declared in the
>>> root `nvkv` module while `IndexedKey` is in the `encode` submodule...
>>> I'm also wondering whether it would make sense to make the relationship
>>> completely explicit by making `Key` a newtype embedding a `IndexedKey`
>>> with the invariant that the index is `0`, but not sure about that one so
>>> your call.
>>
>> Ah, I guess that's because `IndexedKey` is local to `encoder`. In this
>> case keeping it there does indeed make sense. After complaining about
>> the visibility of other declarations, I should have noticed that one
>> too. :P
>>
>> What worries me more is the fact that no index larger than `0` is ever
>> created. This looks more and more like a bug to me.
>
> We currently don't send anything that wants an index other than zero.
> But, in the future we will. The way I did this so far is by having
> 'IndexedKey' which represents the most general thing that can properly
> encode anything accepted by the NVKV format. Since it's cumbersome to
> and rare to use, I added Key as a wrapper on top. It would be possible
> to hard code 0 in the index and only have `Key` but then we'd just have
> to change it later. Since nothing wants to set a non-zero index
> currently, it's private to `encoder`.
But surely we should be able to test the non-zero path, even if we don't
have any real-life user at the moment, right? As this is part of the
NVKV spec, we should ensure this is correct.
If `IndexedKey` is supposed to move down one module when it gains a
user, I think we should place it in its expected destination from the
get-go.
next prev parent reply other threads:[~2026-09-11 11:18 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-27 14:12 [PATCH v2 0/8] gpu: nova-core: add NVKV codec Eliot Courtney
2026-08-27 14:12 ` [PATCH v2 1/8] rust: alloc: add Vec::try_push_init Eliot Courtney
2026-08-27 14:12 ` [PATCH v2 2/8] rust: alloc: add Vec::push_init Eliot Courtney
2026-08-27 14:12 ` [PATCH v2 3/8] rust: alloc: add ArrayVec Eliot Courtney
2026-08-27 14:12 ` [PATCH v2 4/8] gpu: nova-core: add NVKV encoder Eliot Courtney
2026-09-07 15:07 ` Alexandre Courbot
2026-08-27 14:12 ` [PATCH v2 5/8] gpu: nova-core: add NVKV decoder Eliot Courtney
2026-09-09 0:51 ` Alexandre Courbot
2026-09-09 1:13 ` Eliot Courtney
2026-09-09 4:48 ` Alexandre Courbot
2026-09-10 7:47 ` Alexandre Courbot
2026-08-27 14:12 ` [PATCH v2 6/8] gpu: nova-core: add NVKV typed encoding Eliot Courtney
2026-09-10 8:10 ` Alexandre Courbot
2026-09-11 5:17 ` Alexandre Courbot
2026-09-11 5:28 ` Eliot Courtney
2026-09-11 11:18 ` Alexandre Courbot [this message]
2026-08-27 14:12 ` [PATCH v2 7/8] gpu: nova-core: add NVKV typed decoding Eliot Courtney
2026-08-27 14:12 ` [PATCH v2 8/8] gpu: nova-core: add NVKV GSP_INIT schemas Eliot Courtney
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=DLCG22C6X96C.3A8EKCQAZ37FD@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-bounces@lists.freedesktop.org \
--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®