mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alexandre Courbot <acourbot@nvidia.com>
To: Danilo Krummrich <dakr@kernel.org>,
	Alice Ryhl <aliceryhl@google.com>,
	 David Airlie <airlied@gmail.com>,
	Simona Vetter <simona@ffwll.ch>,
	 Benno Lossin <lossin@kernel.org>, Gary Guo <gary@garyguo.net>
Cc: John Hubbard <jhubbard@nvidia.com>,
	 Alistair Popple <apopple@nvidia.com>,
	Timur Tabi <ttabi@nvidia.com>,
	 Eliot Courtney <ecourtney@nvidia.com>,
	Zhi Wang <zhiw@nvidia.com>,
	 linux-kernel@vger.kernel.org, nova-gpu@lists.linux.dev,
	 rust-for-linux@vger.kernel.org,
	Alexandre Courbot <acourbot@nvidia.com>
Subject: [PATCH v2 5/6] gpu: nova-core: gsp: cmdq: do not use ENOMSG to skip messages
Date: Fri, 06 Nov 2026 16:06:13 +0900	[thread overview]
Message-ID: <20261106-r000_rebase_on_cmdq-rpc-v2-5-e481ea2168ef@nvidia.com> (raw)
In-Reply-To: <20261106-r000_rebase_on_cmdq-rpc-v2-0-e481ea2168ef@nvidia.com>

`await_msg_with` currently relies on its closure returning `ENOMSG` to
signal that the message it received is not the one it was waiting for,
and that it should be dropped. This makes `ENOMSG` an in-band control
signal, as code running inside the closure that returns `ENOMSG` for an
unrelated reason makes the queue skip the message instead of reporting
the error.

Make the closure return `Result<Option<R>>` instead, with `Ok(None)`
meaning that the message is to be dropped. Errors returned by the
closure are now always propagated to the caller, so no error code from
the closure can alter the control flow of the command queue.

Suggested-by: Eliot Courtney <ecourtney@nvidia.com>
Link: https://lore.kernel.org/all/DMN62G2CDG3N.ETT4GRFXWKKU@nvidia.com/
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
 drivers/gpu/nova-core/gsp/cmdq.rs     | 19 ++++++++++---------
 drivers/gpu/nova-core/gsp/cmdq/rpc.rs |  5 +++--
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/nova-core/gsp/cmdq.rs b/drivers/gpu/nova-core/gsp/cmdq.rs
index f3151aa8ea26..e6a46c5b5160 100644
--- a/drivers/gpu/nova-core/gsp/cmdq.rs
+++ b/drivers/gpu/nova-core/gsp/cmdq.rs
@@ -676,27 +676,28 @@ fn consume_element<R>(
     ///
     /// The message is waited for up to [`Cmdq::RECEIVE_TIMEOUT`] from the call.
     ///
-    /// `f` is expected to return `Ok` with the result to return to the caller, and `Err(ENOMSG)` to
-    /// signal that the received message was not the one expected (such messages are dropped). Any
-    /// other error returned by `f` is propagated to the caller.
+    /// `f` is expected to return `Ok(Some(_))` with the result to return to the caller, and
+    /// `Ok(None)` to signal that the received message was not the one expected (such messages are
+    /// dropped). Errors returned by `f` are propagated to the caller.
     ///
     /// # Errors
     ///
     /// - `ETIMEDOUT` if no message satisfying `f` arrives before the deadline, however many other
     ///   messages arrive while waiting.
     /// - `EIO` if a message fails framing or checksum validation.
-    /// - Any error returned by `f` with the exception of `ENOMSG`.
-    fn await_msg_with<R>(&mut self, f: impl Fn(GspParsedMessage<'_>) -> Result<R>) -> Result<R> {
+    /// - Any error returned by `f`.
+    fn await_msg_with<R>(
+        &mut self,
+        f: impl Fn(GspParsedMessage<'_>) -> Result<Option<R>>,
+    ) -> Result<R> {
         let deadline = Instant::<Monotonic>::now() + Cmdq::RECEIVE_TIMEOUT;
         loop {
             let remaining = deadline - Instant::<Monotonic>::now();
             if remaining.is_negative() {
                 break Err(ETIMEDOUT);
             }
-            match self.consume_element(remaining, &f)? {
-                Ok(m) => break Ok(m),
-                Err(ENOMSG) => continue,
-                Err(e) => break Err(e),
+            if let Some(m) = self.consume_element(remaining, &f)?? {
+                break Ok(m);
             }
         }
     }
diff --git a/drivers/gpu/nova-core/gsp/cmdq/rpc.rs b/drivers/gpu/nova-core/gsp/cmdq/rpc.rs
index 6ee28e93586b..d01a9f4f953d 100644
--- a/drivers/gpu/nova-core/gsp/cmdq/rpc.rs
+++ b/drivers/gpu/nova-core/gsp/cmdq/rpc.rs
@@ -377,7 +377,7 @@ fn await_rpc_msg<M: MessageFromGsp>(&mut self) -> Result<M>
                 let mut sbuffer = SBufferIter::new_reader([contents_1, rpc_message.contents.1]);
 
                 M::read(cmd, &mut sbuffer)
-                    .map_err(|e| e.into())
+                    .map_err(Error::from)
                     .inspect(|_| {
                         if !sbuffer.is_empty() {
                             dev_warn!(
@@ -387,10 +387,11 @@ fn await_rpc_msg<M: MessageFromGsp>(&mut self) -> Result<M>
                             );
                         }
                     })
+                    .map(Some)
             } else {
                 rpc_message.log(self.dev);
 
-                Err(ENOMSG)
+                Ok(None)
             }
         };
 

-- 
2.56.0


  parent reply	other threads:[~2026-11-06  7:06 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-06  7:06 [PATCH v2 0/6] gpu: nova-core: gsp: add support for GMC messages Alexandre Courbot
2026-11-06  7:06 ` [PATCH v2 1/6] gpu: nova-core: gsp: fw: add the r000 bindings for the GMC API header Alexandre Courbot
2026-11-06  7:06 ` [PATCH v2 2/6] gpu: nova-core: gsp: add " Alexandre Courbot
2026-11-06  7:06 ` [PATCH v2 3/6] gpu: nova-core: gsp: cmdq: add the GMC send path Alexandre Courbot
2026-11-06  7:06 ` [PATCH v2 4/6] gpu: nova-core: gsp: cmdq: move message trimming into its own function Alexandre Courbot
2026-11-06  9:08   ` Eliot Courtney
2026-11-06  7:06 ` Alexandre Courbot [this message]
2026-11-06  9:09   ` [PATCH v2 5/6] gpu: nova-core: gsp: cmdq: do not use ENOMSG to skip messages Eliot Courtney
2026-11-06  7:06 ` [PATCH v2 6/6] gpu: nova-core: gsp: cmdq: add the GMC receive path Alexandre Courbot
2026-11-06  9:38   ` 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=20261106-r000_rebase_on_cmdq-rpc-v2-5-e481ea2168ef@nvidia.com \
    --to=acourbot@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=apopple@nvidia.com \
    --cc=dakr@kernel.org \
    --cc=ecourtney@nvidia.com \
    --cc=gary@garyguo.net \
    --cc=jhubbard@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=nova-gpu@lists.linux.dev \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=simona@ffwll.ch \
    --cc=ttabi@nvidia.com \
    --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

all inboxes | Powered by JetHome®