mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alexandre Courbot <acourbot@nvidia.com>
To: John Hubbard <jhubbard@nvidia.com>,
	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: Alistair Popple <apopple@nvidia.com>,
	Timur Tabi <ttabi@nvidia.com>,
	 Eliot Courtney <ecourtney@nvidia.com>,
	Zhi Wang <zhiw@nvidia.com>,
	 nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org,
	 linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
	 Alexandre Courbot <acourbot@nvidia.com>
Subject: [PATCH v6 11/15] gpu: nova-core: gsp: cmdq: do not sleep when waiting for a message with timeout 0
Date: Tue, 27 Oct 2026 16:35:54 +0900	[thread overview]
Message-ID: <20261027-cmdq-rpc-v6-11-bed9669724ba@nvidia.com> (raw)
In-Reply-To: <20261027-cmdq-rpc-v6-0-bed9669724ba@nvidia.com>

`read_poll_timeout` can potentially sleep for the specified
`sleep_delta` if `timeout_delta` is `Delta::ZERO` and the system clock
is coarse enough to not register a tick between the time the function
has been called and the time the loop test is done. `wait_for_msg` has a
short test condition and is particularly vulnerable to this condition.

Add a dedicated branch when `timeout` is `Delta::ZERO` to perform the
test without calling `read_poll_timeout` and avoid potentially sleeping
for 1ms.

Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
 drivers/gpu/nova-core/gsp/cmdq.rs | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/nova-core/gsp/cmdq.rs b/drivers/gpu/nova-core/gsp/cmdq.rs
index 9e678715c624..9c2c8fbad045 100644
--- a/drivers/gpu/nova-core/gsp/cmdq.rs
+++ b/drivers/gpu/nova-core/gsp/cmdq.rs
@@ -909,12 +909,24 @@ fn send_command<M>(&mut self, command: M) -> Result
     /// - `EIO` if a message fails framing or checksum validation.
     fn wait_for_msg(&self, timeout: Delta) -> Result<GspMessage<'_>> {
         // Wait for a message to arrive from the GSP.
-        let (slice_1, slice_2) = read_poll_timeout(
-            || Ok(self.gsp_mem.driver_read_area()),
-            |driver_area| !driver_area.0.is_empty(),
-            Delta::from_millis(1),
-            timeout,
-        )
+        let (slice_1, slice_2) = if timeout == Delta::ZERO {
+            // If `timeout == Delta::ZERO`, check the message queue once as `read_poll_timeout` can
+            // potentially sleep if the clock hasn't moved forward while the condition was being
+            // checked.
+            let slices = self.gsp_mem.driver_read_area();
+            if !slices.0.is_empty() {
+                Ok(slices)
+            } else {
+                Err(ETIMEDOUT)
+            }
+        } else {
+            read_poll_timeout(
+                || Ok(self.gsp_mem.driver_read_area()),
+                |driver_area| !driver_area.0.is_empty(),
+                Delta::from_millis(1),
+                timeout,
+            )
+        }
         .map(|(slice_1, slice_2)| (slice_1.as_flattened(), slice_2.as_flattened()))?;
 
         // Extract the `GspMsgElement`.

-- 
2.56.0


  parent reply	other threads:[~2026-10-27  7:36 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27  7:35 [PATCH v6 00/15] gpu: nova-core: gsp: prepare the command queue for r000 dual-message types Alexandre Courbot
2026-10-27  7:35 ` [PATCH v6 01/15] gpu: nova-core: gsp: cmdq: remove stale comment Alexandre Courbot
2026-10-27  7:35 ` [PATCH v6 02/15] gpu: nova-core: gsp: cmdq: simplify framing error description Alexandre Courbot
2026-10-27  7:35 ` [PATCH v6 03/15] gpu: nova-core: gsp: cmdq: validate checksum earlier on receive Alexandre Courbot
2026-10-27  7:35 ` [PATCH v6 04/15] gpu: nova-core: gsp: introduce and use proper RpcMessageHeader type Alexandre Courbot
2026-10-27  7:35 ` [PATCH v6 05/15] gpu: nova-core: gsp: cmdq: group the RPC-specific part of send_single_command Alexandre Courbot
2026-10-27  7:35 ` [PATCH v6 06/15] gpu: nova-core: gsp: cmdq: split the transport part of the send path Alexandre Courbot
2026-10-27  7:35 ` [PATCH v6 07/15] gpu: nova-core: gsp: cmdq: split RPC parsing part of the receive path Alexandre Courbot
2026-10-27  7:35 ` [PATCH v6 08/15] gpu: nova-core: gsp: cmdq: move RPC message logging to RpcMessage Alexandre Courbot
2026-10-27  7:35 ` [PATCH v6 09/15] gpu: nova-core: gsp: cmdq: split the transport part of the receive path Alexandre Courbot
2026-10-27  7:35 ` [PATCH v6 10/15] gpu: nova-core: gsp: cmdq: extract await_msg_with from await_msg Alexandre Courbot
2026-10-27  7:35 ` Alexandre Courbot [this message]
2026-10-27  8:01   ` [PATCH v6 11/15] gpu: nova-core: gsp: cmdq: do not sleep when waiting for a message with timeout 0 Eliot Courtney
2026-10-27  7:35 ` [PATCH v6 12/15] gpu: nova-core: gsp: cmdq: use consume_element to implement drain Alexandre Courbot
2026-10-27  7:35 ` [PATCH v6 13/15] gpu: nova-core: gsp: cmdq: move the RPC code into a sub-module Alexandre Courbot
2026-10-27  7:35 ` [PATCH v6 14/15] gpu: nova-core: gsp: move the RPC commands " Alexandre Courbot
2026-10-27  7:35 ` [PATCH v6 15/15] gpu: nova-core: gsp: add `rpc` to RPC message send/receive methods 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=20261027-cmdq-rpc-v6-11-bed9669724ba@nvidia.com \
    --to=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=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®