public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: "Alexandre Courbot" <acourbot@nvidia.com>
To: "Eliot Courtney" <ecourtney@nvidia.com>
Cc: "Danilo Krummrich" <dakr@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"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>,
	"Trevor Gross" <tmgross@umich.edu>,
	nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
	"Zhi Wang" <zhiw@nvidia.com>
Subject: Re: [PATCH v3 8/9] gpu: nova-core: gsp: support large RPCs via continuation record
Date: Fri, 27 Feb 2026 20:28:57 +0900	[thread overview]
Message-ID: <DGPPJGV28ORE.153NNIZ75WY9P@nvidia.com> (raw)
In-Reply-To: <20260226-cmdq-continuation-v3-8-572ab9916766@nvidia.com>

Hi Eliot,

On Thu Feb 26, 2026 at 8:45 PM JST, Eliot Courtney wrote:
<snip>
> @@ -588,6 +592,39 @@ pub(crate) fn send_command<M>(&mut self, bar: &Bar0, command: M) -> Result
>          Ok(())
>      }
>  
> +    /// Sends `command` to the GSP.
> +    ///
> +    /// The command may be split into multiple messages if it is large.
> +    ///
> +    /// # Errors
> +    ///
> +    /// - `ETIMEDOUT` if space does not become available within the timeout.
> +    /// - `EIO` if the variable payload requested by the command has not been entirely
> +    ///   written to by its [`CommandToGsp::init_variable_payload`] method.
> +    ///
> +    /// Error codes returned by the command initializers are propagated as-is.
> +    pub(crate) fn send_command<M>(&mut self, bar: &Bar0, command: M) -> Result
> +    where
> +        M: CommandToGsp,
> +        Error: From<M::InitError>,
> +    {
> +        let mut state = SplitState::new(&command)?;
> +
> +        self.send_single_command(bar, state.command(command))?;

As we discussed offline these two lines were bothering me a bit, because
we pass `command` twice and there is a possibility (although purely
hypothetical) of API misuse. I think I found a way around it: we turn
`SplitState` into an enum with a `Single` variant, that contains the
original command, and a `Split` one, which contains the truncated
initial command and its continuation records.

This simple change cascades into more simplifications in the new types
introduced by this patch: `SplitCommand` is not an enum anymore, but the
original command with a shorter payload. And the continuation records
are their own self-contained type. This is achieved by allocating two
`KVVec`s when we split, and taking advantage of the `SBuffer` we
conveniently have at hand to fill them both.

I have pushed a branch with this idea implemented on top of yours in [1]
- please check it, but I think it brings a nice (if small) incremental
improvement. It removes the API misuse potential, makes every type
purely single-purpose, and doesn't need `PhantomData` or lifetimes,
making it simpler overall IMHO.

[1] https://github.com/Gnurou/linux/tree/review/continuations

> +
> +        while let Some(continuation) = state.next_continuation_record() {
> +            dev_dbg!(
> +                &self.dev,
> +                "GSP RPC: send continuation: size=0x{:x}\n",
> +                command_size(&continuation),
> +            );

`send_single_command` should already print the command, so I don't think
we need this additional debug print?

> +            // Turbofish needed because the compiler cannot infer M here.
> +            self.send_single_command::<ContinuationRecord<'_>>(bar, continuation)?;
> +        }
> +
> +        Ok(())
> +    }
> +
>      /// Wait for a message to become available on the message queue.
>      ///
>      /// This works purely at the transport layer and does not interpret or validate the message
> diff --git a/drivers/gpu/nova-core/gsp/commands.rs b/drivers/gpu/nova-core/gsp/commands.rs
> index 8f270eca33be..6ffd0b9cbf05 100644
> --- a/drivers/gpu/nova-core/gsp/commands.rs
> +++ b/drivers/gpu/nova-core/gsp/commands.rs
> @@ -4,6 +4,7 @@
>      array,
>      convert::Infallible,
>      ffi::FromBytesUntilNulError,
> +    marker::PhantomData,
>      str::Utf8Error, //
>  };
>  
> @@ -22,13 +23,16 @@
>      driver::Bar0,
>      gsp::{
>          cmdq::{
> +            command_size,
>              Cmdq,
>              CommandToGsp,
>              MessageFromGsp, //
>          },
>          fw::{
>              commands::*,
> -            MsgFunction, //
> +            GspMsgElement,
> +            MsgFunction,
> +            GSP_MSG_QUEUE_ELEMENT_SIZE_MAX, //
>          },
>      },
>      sbuffer::SBufferIter,
> @@ -242,3 +246,141 @@ pub(crate) fn get_gsp_info(cmdq: &mut Cmdq, bar: &Bar0) -> Result<GetGspStaticIn
>          }
>      }
>  }
> +
> +/// The `ContinuationRecord` command.
> +pub(crate) struct ContinuationRecord<'a> {

These new types are to be used by the command queue, and we don't want
to use them elsewhere, so `pub(super)` seems more appropriate to me.

And actually, since they are more command queue infrastructure than pure
"commands" that fulfill a given purpose, I'd suggest moving them into
their own sub-module of `gsp` (named `continuation` or `split` maybe?).
That way they don't get in the way of readers who just want to learn
about GSP commands.

  reply	other threads:[~2026-02-27 11:29 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-26 11:45 [PATCH v3 0/9] gpu: nova-core: gsp: add continuation record support Eliot Courtney
2026-02-26 11:45 ` [PATCH v3 1/9] gpu: nova-core: gsp: sort MsgFunction variants alphabetically Eliot Courtney
2026-02-26 11:45 ` [PATCH v3 2/9] gpu: nova-core: gsp: add mechanism to wait for space on command queue Eliot Courtney
2026-02-26 11:45 ` [PATCH v3 3/9] rust: add EMSGSIZE error code Eliot Courtney
2026-02-26 14:04   ` Miguel Ojeda
2026-02-26 11:45 ` [PATCH v3 4/9] gpu: nova-core: gsp: add checking oversized commands Eliot Courtney
2026-02-26 11:45 ` [PATCH v3 5/9] gpu: nova-core: gsp: clarify invariant on command queue Eliot Courtney
2026-02-26 11:45 ` [PATCH v3 6/9] gpu: nova-core: gsp: unconditionally call variable payload handling Eliot Courtney
2026-02-26 11:45 ` [PATCH v3 7/9] gpu: nova-core: gsp: add command_size helper Eliot Courtney
2026-02-26 11:45 ` [PATCH v3 8/9] gpu: nova-core: gsp: support large RPCs via continuation record Eliot Courtney
2026-02-27 11:28   ` Alexandre Courbot [this message]
2026-03-02  4:46     ` Eliot Courtney
2026-02-26 11:45 ` [PATCH v3 9/9] gpu: nova-core: gsp: add tests for SplitState Eliot Courtney
2026-02-27 11:32   ` Alexandre Courbot
2026-03-02  4:44     ` Eliot Courtney
2026-02-27 11:40   ` 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=DGPPJGV28ORE.153NNIZ75WY9P@nvidia.com \
    --to=acourbot@nvidia.com \
    --cc=a.hindborg@kernel.org \
    --cc=airlied@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=ecourtney@nvidia.com \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@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=zhiw@nvidia.com \
    /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