mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Eliot Courtney" <ecourtney@nvidia.com>
To: "Alexandre Courbot" <acourbot@nvidia.com>,
	"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 8/8] gpu: nova-core: add NVKV GSP_INIT schemas
Date: Fri, 18 Sep 2026 22:55:54 +0900	[thread overview]
Message-ID: <DLIHSKKUVP7V.153Z4TTEYFL3Y@nvidia.com> (raw)
In-Reply-To: <DLF12VXN7OUS.1KHT1G0SSR6FW@nvidia.com>

On Mon Sep 14, 2026 at 9:12 PM JST, Alexandre Courbot wrote:
> On Mon Sep 14, 2026 at 2:42 PM JST, Eliot Courtney wrote:
>> On Mon Sep 14, 2026 at 1:11 PM JST, Alexandre Courbot wrote:
>>> On Thu Aug 27, 2026 at 11:12 PM JST, Eliot Courtney wrote:
>>> <...>
>>>> +impl RegKey {
>>>> +    // Define the Key IDs read/written by GSP.
>>>> +    const REGKEY_NAME_KEY: KeyId = 0x3070;
>>>> +    const REGKEY_VALUE_U32_KEY: KeyId = 0x3071;
>>>> +}
>>>> +
>>>> +impl Encodable for KVVec<RegKey> {
>>>> +    fn encode(&self, encoder: &mut Encoder) -> Result {
>>>> +        for regkey in self {
>>>> +            regkey.encode(encoder)?;
>>>> +        }
>>>> +        Ok(())
>>>
>>> Maybe this is just me misunderstanding, but how are the keys
>>> sequentially sent here? Because I don't see any mention of an index, and
>>> `Key::encode` hardcodes `Index::new::<0>()`, so how are these supposed
>>> to be decoded into an array? The `gsp_init_request` test below only adds
>>> one key to its `regkeys`, can we add at least another one to see what
>>> happens and verify that the received content decodes as expected on top
>>> of checking its length?
>>
>> You are not misunderstanding, it's just a bit odd. This is because
>> sequential regkeys are all sent using an index of 0, according to the
>> protocol. I can add a second regkey into the test to demonstrate this.
>> We currently don't and won't soon have a need to decode this kind of
>> repeated index 0 encoding scheme. We have `Accumualted` now, but that
>> relies on the index changing to know when the previous value has been
>> completely sent.
>>
>> To test that the content decodes we'd need to add either a test only
>> Schema for it, or add a schema that isn't (and won't be soon be) used.
>> Alternatively, we can test against the encoded byte content directly.
>> Which do you prefer?
>
> Whichever you think is adequate. :) As long as we test things our
> current code allows us to express.
>
> Although since the NVKV protocol is specified, I think we'll want to
> confirm the fitness of our implementation for the entirety of it, even
> the parts we are not yet using in practice. In that case I suppose it is
> acceptable to have a Schema that is only used in the tests for the sake
> of completeness (even if that means having a temporary
> `#[expect(dead_code]`, as long as the reason is documented).

Alright, I will add a test for this which adds a test only Schema for
regkey. In doing so though, I noticed that with the current design to
write a Schema for regkeys, it's fairly easy to end up with `Target =
(KVVec<KVVec<u8>>, KVVec<u32>)` which is not very nice.

I thought it might be nice to allow the possibility to borrow from the
encoded stream. Then we can at least have `Target = (KVVec<&'d [u8]>,
KVVec<u32>);` (Or use an ArrayVec and avoid forced heap allocation
entirely, but regkey is one of the locations where no clear max # of
them exists AFAICT).

The next version of this series will include this, basically means
adding an (optional) lifetime to the schema that represents the lifetime
of the data. To avoid infecting every struct with this lifetime if it's
just doing copying, I've split Schema into a Schema trait and a
Visit<'data> trait (otherwise you can't refer to Schema::Target without
being able to name a specific lifetime). The Visit<'data> trait is
generic over the 'data lifetime, whereas the Schema trait is not. If you
want 'data lifetime semantics you can add a 'data lifetime to your
struct that implements Schema and plumb that lifetime to the
Visit<'data> implementation. If not, you just let Visit<'data> work for
all lifetimes. The macro handles this transparently. It's not a big
change in LOC but it lets us avoid a copy.

What I'm envisioning is that we do one copy out of the command queue to
provide the encoded stream as a single slice. Then, Schemas can take
borrows of that if they want to. Then, when we convert to the `Target`
output type it can be copied into the final type we want. So that leaves
us with two copies, which is in line with variable length handling for
the r570 Cmdq code (GspSequence, ContinuationRecords).

I considered an additional approach where we deserialize directly from
the command queue ring buffer memory, but that means we need to handle
two slices all the way up into the Schema implementations, so it's a
larger change. Anyway, it's not incompatible with the approach in this
patch series or the approach I mention above, and would let us get down
to one copy for variable length data. We could consider doing that later
if we really want.

I was also looking at if maybe we can do the bidirectional type thing
without overcomplicating the macro, because it ended up being quite
gross to add round-trip-like tests like you suggested, since you need to
basically duplicate the struct. If you have the macro generate the
Schema struct and the storage struct, plus the encode impl, you can
avoid this. I tried a serde-like syntax which actually ends up being
doable with just macro_rules! altho is more complicated. That ends up
looking like this:

```
nvkv! {
    struct GspInitRequest<'a> {
        #[nvkv(key = GspInitRequest::PCI_DEVICE_ID_KEY)]
        pci_device_id: u32,

        #[nvkv(key = GspInitRequest::PCI_SUBDEVICE_ID_KEY)]
        pci_sub_device_id: u32,

...

        #[nvkv(kind = Repeated<RegKeySchema<'a>, { RegKey::REGKEY_NAME_KEY }>)]
        regkeys: KVVec<RegKey<'a>>,

        #[nvkv(kind = Optional<VfInfoSchema>)]
        vf_info: Option<VfInfo>,
    }
}
```

Another version avoids the macro complication, although it's less
obvious what the field types are on inspection (they are declared by the
macro using Schema::Target):

```
nvkv! {
    struct GspInitRequest<'a> {
        pci_device_id: Required<u32, { GspInitRequest::PCI_DEVICE_ID_KEY }>,
        pci_sub_device_id: Required<u32, { GspInitRequest::PCI_SUBDEVICE_ID_KEY }>,
...
        regkeys: Repeated<RegKeySchema<'a>, { RegKey::REGKEY_NAME_KEY }>,
        vf_info: Optional<VfInfoSchema>,
    }
}
```

Anyway sorry for the wall of text, any preferences on the above? Or we
leave it as is with the separate nvkv_encode/nvkv_decode macros with
some fairly verbose/gross round-trip tests.


      reply	other threads:[~2026-09-18 13:56 UTC|newest]

Thread overview: 37+ 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-09-14  4:44     ` Eliot Courtney
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-14  4:45         ` Eliot Courtney
2026-09-10  7:47   ` Alexandre Courbot
2026-09-14  5:45     ` Eliot Courtney
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
2026-09-14  4:46           ` Eliot Courtney
2026-08-27 14:12 ` [PATCH v2 7/8] gpu: nova-core: add NVKV typed decoding Eliot Courtney
2026-09-14  3:46   ` Alexandre Courbot
2026-09-14  6:55     ` Eliot Courtney
2026-09-14  7:04       ` John Hubbard
2026-09-14  7:16         ` Eliot Courtney
2026-09-14 12:06           ` Alexandre Courbot
2026-09-17  5:02             ` Eliot Courtney
2026-09-17  7:53       ` Gary Guo
2026-09-17  8:37         ` Alexandre Courbot
2026-09-17  8:52           ` Gary Guo
2026-09-17 11:42             ` Eliot Courtney
2026-09-17 14:12               ` Gary Guo
2026-08-27 14:12 ` [PATCH v2 8/8] gpu: nova-core: add NVKV GSP_INIT schemas Eliot Courtney
2026-09-14  4:11   ` Alexandre Courbot
2026-09-14  5:42     ` Eliot Courtney
2026-09-14 12:12       ` Alexandre Courbot
2026-09-18 13:55         ` Eliot Courtney [this message]

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=DLIHSKKUVP7V.153Z4TTEYFL3Y@nvidia.com \
    --to=ecourtney@nvidia.com \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --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=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®