[PATCH v2 5/6] gpu: nova-core: gsp: cmdq: do not use ENOMSG to skip messages

From: Alexandre Courbot

Date: Fri Nov 06 2026 - 02:12:55 EST


`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@xxxxxxxxxx>
Link: https://lore.kernel.org/all/DMN62G2CDG3N.ETT4GRFXWKKU@xxxxxxxxxx/
Signed-off-by: Alexandre Courbot <acourbot@xxxxxxxxxx>
---
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