public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: "Eliot Courtney" <ecourtney@nvidia.com>
To: "John Hubbard" <jhubbard@nvidia.com>,
	"Eliot Courtney" <ecourtney@nvidia.com>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>
Cc: "Alistair Popple" <apopple@nvidia.com>,
	"Joel Fernandes" <joelagnelf@nvidia.com>,
	"Timur Tabi" <ttabi@nvidia.com>, <rust-for-linux@vger.kernel.org>,
	<dri-devel@lists.freedesktop.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3 2/9] gpu: nova-core: gsp: add NvStatus enum for RM control errors
Date: Mon, 06 Apr 2026 21:09:34 +0900	[thread overview]
Message-ID: <DHM279KLUL8H.1IRPKG3CQCFJY@nvidia.com> (raw)
In-Reply-To: <f53185ed-5385-4335-af33-ceb347228176@nvidia.com>

On Mon Apr 6, 2026 at 5:05 AM JST, John Hubbard wrote:
> On 3/25/26 5:13 AM, Eliot Courtney wrote:
>> Add NvStatus enum that wraps the raw NV_STATUS u32 codes returned by RM
>> control RPCs.
>> 
>> Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
>> ---
>>   drivers/gpu/nova-core/gsp/fw.rs | 401 ++++++++++++++++++++++++++++++++++++++++
>>   1 file changed, 401 insertions(+)
>> 
>> diff --git a/drivers/gpu/nova-core/gsp/fw.rs b/drivers/gpu/nova-core/gsp/fw.rs
>> index 0c8a74f0e8ac..cb4bda253193 100644
>> --- a/drivers/gpu/nova-core/gsp/fw.rs
>> +++ b/drivers/gpu/nova-core/gsp/fw.rs
>> @@ -97,6 +97,407 @@ pub(in crate::gsp) fn advance_cpu_write_ptr(qs: &Coherent<GspMem>, count: u32) {
>>   pub(crate) const GSP_MSG_QUEUE_ELEMENT_SIZE_MAX: usize =
>>       num::u32_as_usize(bindings::GSP_MSG_QUEUE_ELEMENT_SIZE_MAX);
>>   
>> +/// Status code returned by GSP-RM RPCs.
>> +#[derive(Copy, Clone, Debug, PartialEq, Eq)]
>> +pub(crate) enum NvStatus {
>> +    Ok,
>
> As mentioned in my respose to patch 1, these are hand-written and won't
> automatically pick up anything new from bindgen(1).
>
> If for some reason we don't go directly to generating Rust bindings from
> GSP-RM builds, then we could somewhat mitigate the problem with a
> declarative macro that generates the enum, the From<u32> impl, and the
> From<NvStatus> for Result impl from a single table.
>
> That would at least prevent internal drift between the three, but it
> still would not detect new binding constants.
>
> It would also add yet another macro, sigh.

Yeah I feel we have a lot of macros. But, at least for From<u32> we can
use FromPrimitive once that is ready (see my other email, maybe better
for me to switch it to TryFrom and get rid of Unknown). As for the
mapping, we have to think about it manually somewhere, so either it's
here in a From<> impl, or it's in the bindings generator or upstream of
that.

>
>> +    AlreadySignalled,
>> +    BrokenFb,
> ...
>> +    Unknown(u32),
>> +}
>> +
>> +impl From<NvStatus> for Result {
>> +    fn from(status: NvStatus) -> Self {
>
> This discards the NvStatus variant. The caller sees only a kernel errno.
> We need to retain the rich RM error codes for debugging. For example,
> a caller that gets Err(ENODEV) cannot tell whether RM returned
> CardNotPresent, InvalidDevice, FabricManagerNotPresent, or
> ReductionManagerNotAvailable. Something like:
>
>      fn send(self, ...) -> Result<T::Reply, NvStatus>
>
> would let the caller log or match on the original status, and convert
> to errno only when propagating upward.

SGTM, let me push NvStatus handling a bit up the caller chain then.
I was thinking it might be nice to not carry the openrm naming, and
instead call it e.g. GspMsgRmStatus.

But, I don't think we should use it as is as the error variant of
Result, because it contains 'Ok'. A better shape might be:

GspMsgRmStatus {Ok, Warning(GspMsgRmWarning), Error(GspMsgRmError)}

Another issue is that RmControl::send needs to also propagate the
kernel::error::Error from calling the cmdq. So we would need a wrapping
enum, e.g. enum GspRpcError {Transport(Error), Rm(GspMsgRmError)}. The
(currently unchecked) rpc_result field that comes back from GSP messages
can contain NV_STATUS values (as well as some other ones), so
probably Cmdq should be returning this too.

So if we are fine to just log warnings instead of surfacing them to the
caller, we could do:

fn send(...) -> Result<T::Reply, GspRpcError>

WDYT?

If we go this direction, I might create another patch series for
defining GspRpcError and adding support to Cmdq for returning that,
based on the RPC header's `rpc_result`, since we need to pass that
through here for RM control.

>
>> +        match status {
>> +            NvStatus::Ok => Ok(()),
> ...
>> +
>> +            NvStatus::Timeout => Err(ETIMEDOUT),
>> +
>> +            _ => Err(EIO),
>
> This will cause failures for NV_WARN_* items, which is a problem.
> RM warnings should not be converted into errors.

Do you reckon we will want to do anything other than just log the
warning?

>
> thanks,


  reply	other threads:[~2026-04-06 12:09 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-25 12:13 [PATCH v3 0/9] gpu: nova-core: gsp: add RM control command infrastructure Eliot Courtney
2026-03-25 12:13 ` [PATCH v3 1/9] gpu: nova-core: gsp: add NV_STATUS error code bindings Eliot Courtney
2026-04-05 19:55   ` John Hubbard
2026-04-06  8:54     ` Eliot Courtney
2026-04-06 19:05       ` John Hubbard
2026-03-25 12:13 ` [PATCH v3 2/9] gpu: nova-core: gsp: add NvStatus enum for RM control errors Eliot Courtney
2026-04-05 20:05   ` John Hubbard
2026-04-06 12:09     ` Eliot Courtney [this message]
2026-04-06 19:02       ` John Hubbard
2026-03-25 12:13 ` [PATCH v3 3/9] gpu: nova-core: gsp: expose GSP-RM internal client and subdevice handles Eliot Courtney
2026-03-25 12:13 ` [PATCH v3 4/9] gpu: nova-core: gsp: add RM control RPC structure binding Eliot Courtney
2026-03-25 12:13 ` [PATCH v3 5/9] gpu: nova-core: gsp: add types for RM control RPCs Eliot Courtney
2026-03-25 12:13 ` [PATCH v3 6/9] gpu: nova-core: use KVVec for SBufferIter flush Eliot Courtney
2026-03-25 12:13 ` [PATCH v3 7/9] gpu: nova-core: gsp: add RM control command infrastructure Eliot Courtney
2026-03-25 12:13 ` [PATCH v3 8/9] gpu: nova-core: gsp: add CE fault method buffer size bindings Eliot Courtney
2026-03-25 12:13 ` [PATCH v3 9/9] gpu: nova-core: gsp: add FaultMethodBufferSize RM control command Eliot Courtney
2026-04-05 20:12   ` John Hubbard
2026-04-06  2:30     ` Eliot Courtney
2026-04-05 19:48 ` [PATCH v3 0/9] gpu: nova-core: gsp: add RM control command infrastructure John Hubbard
2026-04-06  2:29   ` 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=DHM279KLUL8H.1IRPKG3CQCFJY@nvidia.com \
    --to=ecourtney@nvidia.com \
    --cc=acourbot@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=apopple@nvidia.com \
    --cc=dakr@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jhubbard@nvidia.com \
    --cc=joelagnelf@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=simona@ffwll.ch \
    --cc=ttabi@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