drm/tyr: implement GPU reset API
Subsystems (6)
Onur Özkan
maintainerv2 cover drm/tyr: implement GPU reset API
This series adds GPU reset handling support for Tyr in a new module drivers/gpu/drm/tyr/driver.rs which encapsulates the low-level reset controller internals and exposes a ResetHandle API to the driver.
This series is based on Alice's "Creation of workqueues in Rust" [1] series.
Changes since v1:
- Removed OrderedQueue and using Alice's workqueue implementation [1] instead.
- Added Resettable trait with pre_reset and post_reset hooks to be implemented by reset-managed hardwares.
- Added SRCU abstraction and used it to synchronize the reset work and hardware access.
3 important points:
- There is no hardware using this API yet.
- On post_reset() failure, we don't do anything for now. We should unplug the GPU (that's what Panthor does) but we don't have the infrastructure for that yet (see [2]).
- In schedule(), similar to panthor_device_schedule_reset(), we should have a PM check but similar to the note above, we don't have the infrastructure for that yet.
Onur Özkan (4):
rust: add SRCU abstraction
MAINTAINERS: add Rust SRCU files to SRCU entry
rust: add Work::disable_sync
drm/tyr: add reset management API
MAINTAINERS | 3 + drivers/gpu/drm/tyr/driver.rs | 40 +--- drivers/gpu/drm/tyr/reset.rs | 293 +++++++++++++++++++++++++++ drivers/gpu/drm/tyr/reset/hw_gate.rs | 155 ++++++++++++++ drivers/gpu/drm/tyr/tyr.rs | 1 + rust/helpers/helpers.c | 1 + rust/helpers/srcu.c | 18 ++ rust/kernel/sync.rs | 2 + rust/kernel/sync/srcu.rs | 109 ++++++++++ rust/kernel/workqueue/mod.rs | 15 ++ 10 files changed, 607 insertions(+), 30 deletions(-) create mode 100644 drivers/gpu/drm/tyr/reset.rs create mode 100644 drivers/gpu/drm/tyr/reset/hw_gate.rs create mode 100644 rust/helpers/srcu.c create mode 100644 rust/kernel/sync/srcu.rs
Signature · 1 line
2.51.2
Onur Özkan
maintainerPATCH v2 3/4 rust: add Work::disable_sync
Adds Work::disable_sync() as a safe wrapper for disable_work_sync().
Drivers can use this during teardown to stop new queueing and wait for queued or running work to finish before dropping related resources.
--- rust/kernel/workqueue/mod.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
rust/kernel/workqueue/mod.rs +15 -0
@@ -582,6 +582,21 @@ pub unsafe fn raw_get(ptr: *const Self) -> *mut bindings::work_struct {// the compiler does not complain that the `work` field is unused. unsafe {Opaque ::cast_into (core::ptr::addr_of!((*ptr).work)) } } + +/// Disables this work item and waits for queued/running executions to finish. +/// +/// # Note +/// +/// Should be called from a sleepable context if the work was last queued on a non-BH +/// workqueue. +#[inline] +pub fn disable_sync (&self) { +let ptr: *const Self = self; +// SAFETY: `self` points to a valid initialized work. +let raw_work =unsafe {Self ::raw_get (ptr) }; +// SAFETY: `raw_work` is a valid embedded `work_struct`. +unsafe { bindings::disable_work_sync (raw_work) }; + } }/// Declares that a type contains a [`Work<T, ID>`].
Signature · 1 line
2.51.2
Onur Özkan
maintainerPATCH v2 4/4 drm/tyr: add reset management API
In reply to Onur ÖzkanAdd Tyr reset handling on top of the Rust SRCU abstraction and use a hardware gate to serialize reset-sensitive accesses against asynchronous reset work.
This introduces ResetHandle, HwGate, and HwGuard, runs reset work on a dedicated ordered workqueue and drains in-flight accesses before running the reset sequence.
--- drivers/gpu/drm/tyr/driver.rs | 40 +--- drivers/gpu/drm/tyr/reset.rs | 293 +++++++++++++++++++++++++++ drivers/gpu/drm/tyr/reset/hw_gate.rs | 155 ++++++++++++++ drivers/gpu/drm/tyr/tyr.rs | 1 + 4 files changed, 459 insertions(+), 30 deletions(-) create mode 100644 drivers/gpu/drm/tyr/reset.rs create mode 100644 drivers/gpu/drm/tyr/reset/hw_gate.rs
drivers/gpu/drm/tyr/driver.rs +10 -30
@@ -6,11 +6,8 @@ OptionalClk, // }, device::{ - Bound, Core, - Device, // }, - devres::Devres, dma::{ Device as DmaDevice, DmaMask, //
@@ -21,10 +18,6 @@ ioctl, UnregisteredDevice, // }, - io::{ - poll, - Io, // - }, new_mutex, of, platform,
@@ -37,17 +30,16 @@ Arc, Mutex, // }, - time, // };use crate ::{ file::TyrDrmFileData , fw::Firmware , gem::BoData , - gpu, gpu::GpuInfo , mmu::Mmu , - regs::gpu_control::*,// + regs::gpu_control::*, + reset,// };pub (crate )type IoMem = kernel::io::mem::IoMem <SZ_2M >;
@@ -62,6 +54,11 @@#[pin_data] pub (crate )struct TyrDrmDeviceData { +// `ResetHandle::drop()` drains queued/running works and this must happen +// before clocks/regulators are dropped. So keep this field before them to +// ensure the correct drop order. +pub (crate ) reset: reset::ResetHandle , +pub (crate ) pdev:ARef <platform::Device >,pub (crate ) fw:Arc <Firmware >,
@@ -90,24 +87,6 @@ unsafe impl Send for TyrDrmDeviceData {}// SAFETY: This will be removed in a future patch. unsafe impl Sync for TyrDrmDeviceData {} -fn issue_soft_reset (dev: &Device <Bound >, iomem: &Devres <IoMem >) ->Result { -let io = (*iomem).access (dev)?; - io.write_reg (GPU_COMMAND ::reset (ResetMode ::SoftReset )); - - poll::read_poll_timeout ( - || { -let io = (*iomem).access (dev)?; -Ok (io.read (GPU_IRQ_RAWSTAT )) - }, - |status| status.reset_completed (), - time::Delta ::from_millis (1 ), - time::Delta ::from_millis (100 ), - ) - .inspect_err (|_|dev_err! (dev,"GPU reset failed." ))?; - -Ok (()) -} - kernel::of_device_table!(OF_TABLE ,MODULE_OF_TABLE ,
@@ -140,8 +119,7 @@ fn probe(let request = pdev.io_request_by_index (0 ).ok_or (ENODEV )?;let iomem =Arc ::pin_init (request.iomap_sized ::<SZ_2M >(),GFP_KERNEL )?; -issue_soft_reset (pdev.as_ref (), &iomem)?; - gpu::l2_power_on (pdev.as_ref (), &iomem)?; + reset::run_reset (pdev.as_ref (), &iomem)?;let gpu_info =GpuInfo ::new (pdev.as_ref (), &iomem)?; gpu_info.log (pdev.as_ref ());
@@ -156,6 +134,7 @@ fn probe(let uninit_ddev =UnregisteredDevice ::<TyrDrmDriver >::new (pdev.as_ref ())?;let platform:ARef <platform::Device > = pdev.into (); +let reset = reset::ResetHandle ::new (platform.clone (), iomem.clone ())?;let mmu =Mmu ::new (pdev, iomem.as_arc_borrow (), &gpu_info)?;
@@ -181,6 +160,7 @@ fn probe( _mali: mali_regulator, _sram: sram_regulator, }), + reset, gpu_info, });
drivers/gpu/drm/tyr/reset.rs new file +293 -0
293 lines not on this page · raw message
drivers/gpu/drm/tyr/reset/hw_gate.rs new file +155 -0
155 lines not on this page · raw message
drivers/gpu/drm/tyr/tyr.rs +1 -0
@@ -14,6 +14,7 @@mod gpu;mod mmu;mod regs; +mod reset;mod slot;mod vm;
Signature · 1 line
2.51.2
Onur Özkan
maintainerQuoted 30 lines · On Thu, 16 Apr 2026 20:17:26 +0300 Onur Özkan <[email protected]> wrote:
This series adds GPU reset handling support for Tyr in a new module
drivers/gpu/drm/tyr/driver.rswhich encapsulates the low-level reset controller internals and exposes a ResetHandle API to the driver.This series is based on Alice's "Creation of workqueues in Rust" [1] series.
Changes since v1:
- Removed OrderedQueue and using Alice's workqueue implementation [1] instead.
- Added Resettable trait withpre_resetandpost_resethooks to be implemented by reset-managed hardwares.
- Added SRCU abstraction and used it to synchronize the reset work and hardware access.3 important points:
- There is no hardware using this API yet.
- Onpost_reset()failure, we don't do anything for now. We should unplug the GPU (that's what Panthor does) but we don't have the infrastructure for that yet (see [2]).
- Inschedule(), similar topanthor_device_schedule_reset(), we should have a PM check but similar to the note above, we don't have the infrastructure for that yet.Onur Özkan (4):
rust: add SRCU abstraction
MAINTAINERS: add Rust SRCU files to SRCU entry
rust: addWork::disable_sync
drm/tyr: add reset management API
Quoted 19 lines
MAINTAINERS | 3 + drivers/gpu/drm/tyr/driver.rs | 40 +--- drivers/gpu/drm/tyr/reset.rs | 293 +++++++++++++++++++++++++++ drivers/gpu/drm/tyr/reset/hw_gate.rs | 155 ++++++++++++++ drivers/gpu/drm/tyr/tyr.rs | 1 + rust/helpers/helpers.c | 1 + rust/helpers/srcu.c | 18 ++ rust/kernel/sync.rs | 2 + rust/kernel/sync/srcu.rs | 109 ++++++++++ rust/kernel/workqueue/mod.rs | 15 ++ 10 files changed, 607 insertions(+), 30 deletions(-) create mode 100644 drivers/gpu/drm/tyr/reset.rs create mode 100644 drivers/gpu/drm/tyr/reset/hw_gate.rs create mode 100644 rust/helpers/srcu.c create mode 100644 rust/kernel/sync/srcu.rsSignature · 1 line
2.51.2
I messed up when sending the series (part of it was sent as a separate series [1]. I will resend this properly, sorry for the noise.
[1]: https://lore.kernel.org/all/[email protected]/
-Onur
Onur Özkan
maintainerPATCH RESEND v2 1/4 rust: add SRCU abstraction
In reply to Onur ÖzkanAdd a Rust abstraction for sleepable RCU (SRCU), backed by srcu_struct. Provide FFI helpers and a safe wrapper with a guard-based API for read-side critical sections.
--- rust/helpers/helpers.c | 1 + rust/helpers/srcu.c | 18 +++++++ rust/kernel/sync.rs | 2 + rust/kernel/sync/srcu.rs | 109 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 130 insertions(+) create mode 100644 rust/helpers/srcu.c create mode 100644 rust/kernel/sync/srcu.rs
rust/helpers/helpers.c +1 -0
@@ -60,6 +60,7 @@#include "signal.c" #include "slab.c" #include "spinlock.c" +#include "srcu.c" #include "sync.c" #include "task.c" #include "time.c"
rust/helpers/srcu.c new file +18 -0
@@ -0,0 +1,18 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <linux/srcu.h> + +__rust_helper int rust_helper_init_srcu_struct(struct srcu_struct *ssp) +{ +return init_srcu_struct (ssp); +} + +__rust_helper int rust_helper_srcu_read_lock(struct srcu_struct *ssp) +{ +return srcu_read_lock (ssp); +} + +__rust_helper void rust_helper_srcu_read_unlock(struct srcu_struct *ssp, int idx) +{ +srcu_read_unlock (ssp, idx); +}
rust/kernel/sync.rs +2 -0
@@ -21,6 +21,7 @@pub mod rcu;mod refcount;mod set_once; +pub mod srcu;pub use arc::{Arc ,ArcBorrow ,UniqueArc };pub use completion::Completion ;
@@ -31,6 +32,7 @@pub use locked_by::LockedBy ;pub use refcount::Refcount ;pub use set_once::SetOnce ; +pub use srcu::Srcu ;/// Represents a lockdep class. ///
rust/kernel/sync/srcu.rs new file +109 -0
109 lines not on this page · raw message
Signature · 1 line
2.51.2
Onur Özkan
maintainerPATCH RESEND v2 2/4 MAINTAINERS: add Rust SRCU files to SRCU entry
Add the Rust SRCU helper and abstraction files to the SRCU entry and add Onur Özkan as a maintainer for the Rust SRCU pieces.
--- MAINTAINERS | 3 +++ 1 file changed, 3 insertions(+)
MAINTAINERS +3 -0
@@ -24403,6 +24403,7 @@ F: drivers/net/can/slcan/ SLEEPABLE READ-COPY UPDATE (SRCU) M: Lai Jiangshan <[email protected]> +M: Onur Özkan <[email protected]> (RUST) M: "Paul E. McKenney" <[email protected]> M: Josh Triplett <[email protected]> R: Steven Rostedt <[email protected]>
@@ -24413,6 +24414,8 @@ W: http://www.rdrop.com/users/paulmck/RCU/ T: git git://git.kernel.org/pub/scm/linux/kernel/git/rcu/linux.git rcu/dev F: include/linux/srcu*.h F: kernel/rcu/srcu*.c +F: rust/helpers/srcu.c +F: rust/kernel/sync/srcu.rs SMACK SECURITY MODULE M: Casey Schaufler <[email protected]>
Signature · 1 line
2.51.2
Boqun Feng
maintainerQuoted 49 lines · Onur Özkan
Quoted 46 lines · On Thu, 16 Apr 2026 20:17:26 +0300 Onur Özkan <[email protected]> wrote:
This series adds GPU reset handling support for Tyr in a new module
drivers/gpu/drm/tyr/driver.rswhich encapsulates the low-level reset controller internals and exposes a ResetHandle API to the driver.This series is based on Alice's "Creation of workqueues in Rust" [1] series.
Changes since v1:
- Removed OrderedQueue and using Alice's workqueue implementation [1] instead.
- Added Resettable trait withpre_resetandpost_resethooks to be implemented by reset-managed hardwares.
- Added SRCU abstraction and used it to synchronize the reset work and hardware access.3 important points:
- There is no hardware using this API yet.
- Onpost_reset()failure, we don't do anything for now. We should unplug the GPU (that's what Panthor does) but we don't have the infrastructure for that yet (see [2]).
- Inschedule(), similar topanthor_device_schedule_reset(), we should have a PM check but similar to the note above, we don't have the infrastructure for that yet.Onur Özkan (4):
rust: add SRCU abstraction
MAINTAINERS: add Rust SRCU files to SRCU entry
rust: addWork::disable_sync
drm/tyr: add reset management APIMAINTAINERS | 3 + drivers/gpu/drm/tyr/driver.rs | 40 +--- drivers/gpu/drm/tyr/reset.rs | 293 +++++++++++++++++++++++++++ drivers/gpu/drm/tyr/reset/hw_gate.rs | 155 ++++++++++++++ drivers/gpu/drm/tyr/tyr.rs | 1 + rust/helpers/helpers.c | 1 + rust/helpers/srcu.c | 18 ++ rust/kernel/sync.rs | 2 + rust/kernel/sync/srcu.rs | 109 ++++++++++ rust/kernel/workqueue/mod.rs | 15 ++ 10 files changed, 607 insertions(+), 30 deletions(-) create mode 100644 drivers/gpu/drm/tyr/reset.rs create mode 100644 drivers/gpu/drm/tyr/reset/hw_gate.rs create mode 100644 rust/helpers/srcu.c create mode 100644 rust/kernel/sync/srcu.rs
Quoted 7 lines
Quoted 3 lines
Signature · 1 line
2.51.2I messed up when sending the series (part of it was sent as a separate series [1]. I will resend this properly, sorry for the noise.
FWIW, I didn't receive your patch #3 (even from my subscription on rust-for-linux list).
Could you add a doc test for disable_sync(), I'm curious about it because you may disable a work that has not be executed yet, and wouldn't that be leaking memory (IIUC, we rely on Arc::drop() in WorkItemPointer::run() to decrease the refcounts), but maybe I'm missing something subtle.
Regards,
Boqun
Quoted 4 lines
[1]: https://lore.kernel.org/all/[email protected]/
-Onur
Onur Özkan
maintainerQuoted 54 lines · On Thu, 16 Apr 2026 11:45:56 -0700 Boqun Feng <[email protected]> wrote:
Quoted 53 lines · Onur Özkan
Quoted 49 lines · On Thu, 16 Apr 2026 20:17:26 +0300 Onur Özkan <[email protected]> wrote:
This series adds GPU reset handling support for Tyr in a new module
drivers/gpu/drm/tyr/driver.rswhich encapsulates the low-level reset controller internals and exposes a ResetHandle API to the driver.This series is based on Alice's "Creation of workqueues in Rust" [1] series.
Changes since v1:
- Removed OrderedQueue and using Alice's workqueue implementation [1] instead.
- Added Resettable trait withpre_resetandpost_resethooks to be implemented by reset-managed hardwares.
- Added SRCU abstraction and used it to synchronize the reset work and hardware access.3 important points:
- There is no hardware using this API yet.
- Onpost_reset()failure, we don't do anything for now. We should unplug the GPU (that's what Panthor does) but we don't have the infrastructure for that yet (see [2]).
- Inschedule(), similar topanthor_device_schedule_reset(), we should have a PM check but similar to the note above, we don't have the infrastructure for that yet.Onur Özkan (4):
rust: add SRCU abstraction
MAINTAINERS: add Rust SRCU files to SRCU entry
rust: addWork::disable_sync
drm/tyr: add reset management APIMAINTAINERS | 3 + drivers/gpu/drm/tyr/driver.rs | 40 +--- drivers/gpu/drm/tyr/reset.rs | 293 +++++++++++++++++++++++++++ drivers/gpu/drm/tyr/reset/hw_gate.rs | 155 ++++++++++++++ drivers/gpu/drm/tyr/tyr.rs | 1 + rust/helpers/helpers.c | 1 + rust/helpers/srcu.c | 18 ++ rust/kernel/sync.rs | 2 + rust/kernel/sync/srcu.rs | 109 ++++++++++ rust/kernel/workqueue/mod.rs | 15 ++ 10 files changed, 607 insertions(+), 30 deletions(-) create mode 100644 drivers/gpu/drm/tyr/reset.rs create mode 100644 drivers/gpu/drm/tyr/reset/hw_gate.rs create mode 100644 rust/helpers/srcu.c create mode 100644 rust/kernel/sync/srcu.rsSignature · 1 line
2.51.2
Quoted 7 lines
Quoted 3 lines
I messed up when sending the series (part of it was sent as a separate series [1]. I will resend this properly, sorry for the noise.
FWIW, I didn't receive your patch #3 (even from my subscription on rust-for-linux list).
Interesting, it's actually sent to rust-for-linux list [1]. But yeah, I totally messed up with sending this series...
[1]: https://lore.kernel.org/all/[email protected]/
Quoted 5 lines
Could you add a doc test for
disable_sync(), I'm curious about it because you may disable a work that has not be executed yet, and wouldn't that be leaking memory (IIUC, we rely onArc::drop()inWorkItemPointer::run()to decrease the refcounts), but maybe I'm missing something subtle.
I was expecting the C call to handle the teardown properly over the pointer but I wasn't aware about the Rust side internals on the workqueue abstraction. I will check that in more detail during next week and I will definitely add the test on v3.
Thanks,
Onur
Quoted 8 lines
Regards,
BoqunQuoted 4 lines
[1]: https://lore.kernel.org/all/[email protected]/
-Onur
Gary Guo
maintainerRe: [PATCH v2 RESEND 1/4] rust: add SRCU abstraction
In reply to Onur ÖzkanQuoted 41 lines · Onur Özkan
Add a Rust abstraction for sleepable RCU (SRCU), backed by
srcu_struct. Provide FFI helpers and a safe wrapper with a guard-based API for read-side critical sections.Signed-off-by Onur Özkan <[email protected]>--- rust/helpers/helpers.c | 1 + rust/helpers/srcu.c | 18 +++++++ rust/kernel/sync.rs | 2 + rust/kernel/sync/srcu.rs | 109 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 130 insertions(+) create mode 100644 rust/helpers/srcu.c create mode 100644 rust/kernel/sync/srcu.rsrust/helpers/helpers.c +1
-0@@ -60,6 +60,7 @@#include "signal.c" #include "slab.c" #include "spinlock.c" +#include "srcu.c" #include "sync.c" #include "task.c" #include "time.c" rust/helpers/srcu.c new file +9
-0@@ -0,0 +1,18 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <linux/srcu.h> + +__rust_helper int rust_helper_init_srcu_struct(struct srcu_struct *ssp) +{ +return init_srcu_struct (ssp); +} +
rust/helpers/srcu.c line 18
Quoted 10 lines
rust/helpers/srcu.c new file +9
-0+__rust_helper int rust_helper_srcu_read_lock(struct srcu_struct *ssp) +{ +return srcu_read_lock (ssp); +} + +__rust_helper void rust_helper_srcu_read_unlock(struct srcu_struct *ssp, int idx) +{ +srcu_read_unlock (ssp, idx); +}
^
Quoted 40 lines
rust/kernel/sync.rs +2
-0@@ -21,6 +21,7 @@pub mod rcu;mod refcount;mod set_once; +pub mod srcu;pub use arc::{Arc ,ArcBorrow ,UniqueArc };pub use completion::Completion ;@@ -31,6 +32,7 @@pub use locked_by::LockedBy ;pub use refcount::Refcount ;pub use set_once::SetOnce ; +pub use srcu::Srcu ;/// Represents a lockdep class. /// rust/kernel/sync/srcu.rs new file +14
-0@@ -0,0 +1,109 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Sleepable read-copy update (SRCU) abstraction. +//! +//! C header: [`include/linux/srcu.h`](srctree/include/linux/srcu.h) + +use crate ::{ + bindings, + error::to_result, + prelude::*, + types::{ +NotThreadSafe , +Opaque ,// + },
rust/kernel/sync/srcu.rs line 24
Quoted 10 lines
rust/kernel/sync/srcu.rs new file +10
-0+}; + +use pin_init::pin_data; + +/// Creates an [`Srcu`] initialiser. +#[macro_export] +macro_rules! new_srcu { + () => { + $crate::sync::Srcu ::new () + };
There's no need to create macro just for the sake of creating a macro. Although, as Boqun already pointed out, macro will be needed for lockdep.
Quoted 5 lines
rust/kernel/sync/srcu.rs new file +5
-0+} + +/// Sleepable read-copy update primitive. +/// +/// SRCU readers may sleep while holding the read-side guard.
rust/kernel/sync/srcu.rs line 39
Quoted 10 lines
rust/kernel/sync/srcu.rs new file +10
-0+#[repr(transparent)] +#[pin_data( PinnedDrop )] +pub struct Srcu { +#[pin] + inner:Opaque <bindings::srcu_struct >, +} + +impl Srcu { +/// Creates a new SRCU instance. +pub fn new () ->impl PinInit <Self ,Error > {
Most of the methods here can be #[inline]
Quoted 46 lines
rust/kernel/sync/srcu.rs new file +46
-0+try_pin_init! (Self { + inner <-Opaque ::try_ffi_init (|ptr: *mut bindings::srcu_struct | { +// SAFETY: `ptr` points to valid uninitialised memory for a `srcu_struct`. +to_result (unsafe { bindings::init_srcu_struct (ptr) }) + }), + }) + } + +/// Enters an SRCU read-side critical section. +pub fn read_lock (&self) ->Guard <'_> { +// SAFETY: By the type invariants, `self.inner.get()` is a valid initialized `srcu_struct`. +let idx =unsafe { bindings::srcu_read_lock (self.inner.get ()) }; + +Guard { + srcu: self, + idx, + _nts:NotThreadSafe , + } + } + +/// Waits until all pre-existing SRCU readers have completed. +pub fn synchronize (&self) { +// SAFETY: By the type invariants, `self.inner.get()` is a valid initialized `srcu_struct`. +unsafe { bindings::synchronize_srcu (self.inner.get ()) }; + } + +/// Waits until all pre-existing SRCU readers have completed, expedited. +/// +/// This requests a lower-latency grace period than [`Srcu::synchronize`] typically +/// at the cost of higher system-wide overhead. Prefer [`Srcu::synchronize`] by default +/// and use this variant only when reducing reset or teardown latency is more important +/// than the extra cost. +pub fn synchronize_expedited (&self) { +// SAFETY: By the type invariants, `self.inner.get()` is a valid initialized `srcu_struct`. +unsafe { bindings::synchronize_srcu_expedited (self.inner.get ()) }; + } +} + +#[pinned_drop] +impl PinnedDrop for Srcu { +fn drop (self:Pin <&mut Self >) { +// SAFETY: `self` is pinned and `inner` contains a valid initialized `srcu_struct`. +unsafe { bindings::cleanup_srcu_struct (self.as_ref ().get_ref ().inner.get ()) }; + } +} +
rust/kernel/sync/srcu.rs line 95
Quoted 10 lines
rust/kernel/sync/srcu.rs new file +10
-0+// SAFETY: `srcu_struct` may be shared and used across threads. +unsafe impl Send for Srcu {} +// SAFETY: `srcu_struct` may be shared and used concurrently. +unsafe impl Sync for Srcu {} + +/// Guard for an active SRCU read-side critical section on a particular [`Srcu`]. +pub struct Guard <'a> { + srcu: &'aSrcu , + idx: core::ffi::c_int , + _nts:NotThreadSafe ,
I'd prefer this to be _not_send so it's self-documenting on why you need this.
Best,
Gary
Quoted 14 lines
rust/kernel/sync/srcu.rs new file +14
-0+} + +impl Guard <'_> { +/// Explicitly exits the SRCU read-side critical section. +pub fn unlock (self) {} +} + +impl Drop for Guard <'_> { +fn drop (&mut self) { +// SAFETY: `Guard` is only constructible through `Srcu::read_lock()`, +// which returns a valid index for the SRCU instance. +unsafe { bindings::srcu_read_unlock (self.srcu.inner.get (), self.idx) }; + } +}
Onur Özkan
maintainerQuoted 61 lines · On Thu, 16 Apr 2026 11:45:56 -0700 Boqun Feng <[email protected]> wrote:
Quoted 49 lines · Onur Özkan
Quoted 46 lines · On Thu, 16 Apr 2026 20:17:26 +0300 Onur Özkan <[email protected]> wrote:
This series adds GPU reset handling support for Tyr in a new module
drivers/gpu/drm/tyr/driver.rswhich encapsulates the low-level reset controller internals and exposes a ResetHandle API to the driver.This series is based on Alice's "Creation of workqueues in Rust" [1] series.
Changes since v1:
- Removed OrderedQueue and using Alice's workqueue implementation [1] instead.
- Added Resettable trait withpre_resetandpost_resethooks to be implemented by reset-managed hardwares.
- Added SRCU abstraction and used it to synchronize the reset work and hardware access.3 important points:
- There is no hardware using this API yet.
- Onpost_reset()failure, we don't do anything for now. We should unplug the GPU (that's what Panthor does) but we don't have the infrastructure for that yet (see [2]).
- Inschedule(), similar topanthor_device_schedule_reset(), we should have a PM check but similar to the note above, we don't have the infrastructure for that yet.Onur Özkan (4):
rust: add SRCU abstraction
MAINTAINERS: add Rust SRCU files to SRCU entry
rust: addWork::disable_sync
drm/tyr: add reset management APIMAINTAINERS | 3 + drivers/gpu/drm/tyr/driver.rs | 40 +--- drivers/gpu/drm/tyr/reset.rs | 293 +++++++++++++++++++++++++++ drivers/gpu/drm/tyr/reset/hw_gate.rs | 155 ++++++++++++++ drivers/gpu/drm/tyr/tyr.rs | 1 + rust/helpers/helpers.c | 1 + rust/helpers/srcu.c | 18 ++ rust/kernel/sync.rs | 2 + rust/kernel/sync/srcu.rs | 109 ++++++++++ rust/kernel/workqueue/mod.rs | 15 ++ 10 files changed, 607 insertions(+), 30 deletions(-) create mode 100644 drivers/gpu/drm/tyr/reset.rs create mode 100644 drivers/gpu/drm/tyr/reset/hw_gate.rs create mode 100644 rust/helpers/srcu.c create mode 100644 rust/kernel/sync/srcu.rsQuoted 7 lines
Quoted 3 lines
Signature · 1 line
2.51.2I messed up when sending the series (part of it was sent as a separate series [1]. I will resend this properly, sorry for the noise.
FWIW, I didn't receive your patch #3 (even from my subscription on rust-for-linux list).
Quoted 9 lines
Could you add a doc test for
disable_sync(), I'm curious about it because you may disable a work that has not be executed yet, and wouldn't that be leaking memory (IIUC, we rely onArc::drop()inWorkItemPointer::run()to decrease the refcounts), but maybe I'm missing something subtle.Regards,
Boqun
Hi Boqun,
I fixed the leak issue and this change now has its own series at [1]. I couldn't figure an easy way to write the doc-test tho, it started to add too much complextiy and I didn't think it's worth it.
- Onur
[1]: https://lore.kernel.org/all/[email protected]
Quoted 4 lines
Quoted 4 lines
[1]: https://lore.kernel.org/all/[email protected]/
-Onur