mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Laura Nao <laura.nao@collabora.com>
To: "Daniel Almeida" <daniel.almeida@collabora.com>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"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>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	"Onur Özkan" <work@onurozkan.dev>
Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
	 rust-for-linux@vger.kernel.org, kernel@collabora.com,
	 Laura Nao <laura.nao@collabora.com>
Subject: [PATCH v7 1/3] drm/tyr: add HwGate::try_access_atomic()
Date: Mon, 23 Nov 2026 15:58:45 +0100	[thread overview]
Message-ID: <20260728-tyr-irq-v2-v7-1-4e172e58e28c@collabora.com> (raw)
In-Reply-To: <20260728-tyr-irq-v2-v7-0-4e172e58e28c@collabora.com>

From: Daniel Almeida <daniel.almeida@collabora.com>

HwGate::access() takes gate_lock, which is a mutex, so it cannot be
called from atomic context. IRQ handlers need to access the GPU
registers, and those are only reachable through the gate.

Add HwGate::try_access_atomic(). It enters SRCU without taking gate_lock
and returns None if the reset worker has closed the gate. close() now
sets a closed flag before waiting for SRCU readers, and HwClosedGuard
clears it when dropped. SRCU guarantees that a reader either sees the
flag set or is waited for.

An IRQ handler that gets None cannot acknowledge its interrupt, so its
interrupt has to stay masked while the gate is closed. Document this on
close(). No caller needs to do this yet: the only reset runs at probe,
before any IRQ handler is registered.

There are no users yet. The Job IRQ handler will be the first one.

Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
---
 drivers/gpu/drm/tyr/reset/hw_gate.rs | 55 ++++++++++++++++++++++++++++++++++--
 1 file changed, 53 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/tyr/reset/hw_gate.rs b/drivers/gpu/drm/tyr/reset/hw_gate.rs
index 201f8c953078..40b38f07c472 100644
--- a/drivers/gpu/drm/tyr/reset/hw_gate.rs
+++ b/drivers/gpu/drm/tyr/reset/hw_gate.rs
@@ -6,10 +6,18 @@
 //! access with reset. Readers hold the mutex while entering SRCU, then release
 //! it before accessing hardware. The reset worker holds the mutex while waiting
 //! for admitted readers and resetting hardware.
+//!
+//! Readers that cannot sleep use [`HwGate::try_access_atomic`] instead. It
+//! enters SRCU without taking the mutex and fails if the reset worker has set
+//! `closed`, which it does before waiting for readers.
 
 use kernel::{
     prelude::*,
     sync::{
+        atomic::{
+            Atomic,
+            Relaxed, //
+        },
         new_mutex,
         srcu,
         Mutex,
@@ -32,6 +40,9 @@ pub(crate) struct HwGate<'hw> {
     /// Drains readers that entered before the reset worker acquired `gate_lock`.
     #[pin]
     srcu: Srcu,
+    /// Set while the reset worker owns the hardware. Checked by readers that
+    /// cannot take `gate_lock`.
+    closed: Atomic<bool>,
 }
 
 impl<'hw> HwGate<'hw> {
@@ -41,6 +52,7 @@ pub(crate) fn new(iomem: IoMem<'hw>) -> impl PinInit<Self, Error> {
             iomem,
             gate_lock <- new_mutex!(()),
             srcu <- kernel::new_srcu!(),
+            closed: Atomic::new(false),
         })
     }
 
@@ -60,15 +72,45 @@ pub(crate) fn access(&self) -> HwAccessGuard<'_, 'hw> {
         }
     }
 
+    /// Enters a reset-sensitive hardware-access section without sleeping.
+    ///
+    /// Returns `None` while the reset worker owns the hardware, in which case
+    /// the caller must skip its hardware access.
+    #[expect(dead_code)]
+    pub(crate) fn try_access_atomic(&self) -> Option<HwAccessGuard<'_, 'hw>> {
+        let srcu = self.srcu.read_lock();
+
+        // `close()` sets `closed` before waiting for readers, so SRCU guarantees
+        // that this reader either sees it set or is waited for.
+        if self.closed.load(Relaxed) {
+            return None;
+        }
+
+        Some(HwAccessGuard {
+            gate: self,
+            _srcu: srcu,
+        })
+    }
+
     /// Stops new readers and drains admitted readers for the reset worker.
     ///
     /// Callers must serialize write-side access. The reset controller's state
     /// machine provides that serialization.
+    ///
+    /// An IRQ handler that uses [`HwGate::try_access_atomic`] cannot acknowledge
+    /// its interrupt while the gate is closed. Callers must mask such an
+    /// interrupt before closing the gate and keep it masked until the gate
+    /// reopens.
     pub(super) fn close(&self) -> HwClosedGuard<'_, 'hw> {
         let gate_lock = self.gate_lock.lock();
 
-        // Holding `gate_lock` prevents new readers from entering SRCU. Readers
-        // admitted before us are enrolled, so wait for their read-side work.
+        // Stop `try_access_atomic()` readers. This must happen before waiting
+        // for readers below.
+        self.closed.store(true, Relaxed);
+
+        // Holding `gate_lock` prevents new readers from entering SRCU through
+        // `access()`. Readers admitted before us are enrolled, so wait for their
+        // read-side work.
         self.srcu.synchronize();
 
         HwClosedGuard {
@@ -104,3 +146,12 @@ pub(super) fn iomem(&self) -> &IoMem<'hw> {
         &self.gate.iomem
     }
 }
+
+impl Drop for HwClosedGuard<'_, '_> {
+    fn drop(&mut self) {
+        // Reopen for `try_access_atomic()`. A reader that races with this and
+        // still sees `closed` set returns `None`, as it would have before the
+        // store.
+        self.gate.closed.store(false, Relaxed);
+    }
+}

-- 
2.39.5


  reply	other threads:[~2026-11-23 14:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 14:58 [PATCH v7 0/3] drm/tyr: add Job IRQ handling Laura Nao
2026-11-23 14:58 ` Laura Nao [this message]
2026-11-23 18:13   ` [PATCH v7 1/3] drm/tyr: add HwGate::try_access_atomic() Onur Özkan
2026-11-23 14:58 ` [PATCH v7 2/3] drm/tyr: add TyrIrq threaded IRQ wrapper Laura Nao
2026-11-23 14:58 ` [PATCH v7 3/3] drm/tyr: add Job IRQ handling Laura Nao

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=20260728-tyr-irq-v2-v7-1-4e172e58e28c@collabora.com \
    --to=laura.nao@collabora.com \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gary@garyguo.net \
    --cc=kernel@collabora.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tamird@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=work@onurozkan.dev \
    /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®