* [PATCH v1 1/3] rust: helpers: add SRCU helpers
2026-04-28 10:34 [PATCH v1 0/3] rust: add SRCU abstraction Onur Özkan
@ 2026-04-28 10:34 ` Onur Özkan
2026-04-28 10:34 ` [PATCH v1 2/3] rust: sync: add SRCU abstraction Onur Özkan
2026-04-28 10:34 ` [PATCH v1 3/3] MAINTAINERS: add Rust SRCU files to SRCU entry Onur Özkan
2 siblings, 0 replies; 4+ messages in thread
From: Onur Özkan @ 2026-04-28 10:34 UTC (permalink / raw)
To: rcu, rust-for-linux, linux-kernel
Cc: ojeda, boqun, gary, bjorn3_gh, lossin, a.hindborg, aliceryhl,
tmgross, dakr, peterz, fujita.tomonori, tamird, jiangshanlai,
paulmck, josh, rostedt, mathieu.desnoyers, Onur Özkan
Add helper wrappers for SRCU functions that are exposed to Rust
through generated bindings.
Signed-off-by: Onur Özkan <work@onurozkan.dev>
---
rust/helpers/helpers.c | 1 +
rust/helpers/srcu.c | 24 ++++++++++++++++++++++++
2 files changed, 25 insertions(+)
create mode 100644 rust/helpers/srcu.c
diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c
index 875a9788ad40..052fef89d5f0 100644
--- a/rust/helpers/helpers.c
+++ b/rust/helpers/helpers.c
@@ -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"
diff --git a/rust/helpers/srcu.c b/rust/helpers/srcu.c
new file mode 100644
index 000000000000..e9f723d7f8c9
--- /dev/null
+++ b/rust/helpers/srcu.c
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/srcu.h>
+
+__rust_helper int rust_helper_init_srcu_struct_with_key(struct srcu_struct *ssp,
+ const char *name,
+ struct lock_class_key *key)
+{
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+ return __init_srcu_struct(ssp, name, key);
+#else /* !CONFIG_DEBUG_LOCK_ALLOC */
+ return init_srcu_struct(ssp);
+#endif /* CONFIG_DEBUG_LOCK_ALLOC */
+}
+
+__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);
+}
--
2.51.2
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH v1 2/3] rust: sync: add SRCU abstraction
2026-04-28 10:34 [PATCH v1 0/3] rust: add SRCU abstraction Onur Özkan
2026-04-28 10:34 ` [PATCH v1 1/3] rust: helpers: add SRCU helpers Onur Özkan
@ 2026-04-28 10:34 ` Onur Özkan
2026-04-28 10:34 ` [PATCH v1 3/3] MAINTAINERS: add Rust SRCU files to SRCU entry Onur Özkan
2 siblings, 0 replies; 4+ messages in thread
From: Onur Özkan @ 2026-04-28 10:34 UTC (permalink / raw)
To: rcu, rust-for-linux, linux-kernel
Cc: ojeda, boqun, gary, bjorn3_gh, lossin, a.hindborg, aliceryhl,
tmgross, dakr, peterz, fujita.tomonori, tamird, jiangshanlai,
paulmck, josh, rostedt, mathieu.desnoyers, Onur Özkan
Add a Rust abstraction for sleepable RCU.
Add a Rust abstraction for sleepable RCU (SRCU), backed by C srcu_struct.
Provide FFI helpers and a safe wrapper with a guard-based API for read-side
critical sections.
Signed-off-by: Onur Özkan <work@onurozkan.dev>
---
rust/kernel/sync.rs | 2 +
rust/kernel/sync/srcu.rs | 121 +++++++++++++++++++++++++++++++++++++++
2 files changed, 123 insertions(+)
create mode 100644 rust/kernel/sync/srcu.rs
diff --git a/rust/kernel/sync.rs b/rust/kernel/sync.rs
index 993dbf2caa0e..0d6a5f1300c3 100644
--- a/rust/kernel/sync.rs
+++ b/rust/kernel/sync.rs
@@ -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.
///
diff --git a/rust/kernel/sync/srcu.rs b/rust/kernel/sync/srcu.rs
new file mode 100644
index 000000000000..4be1748b219d
--- /dev/null
+++ b/rust/kernel/sync/srcu.rs
@@ -0,0 +1,121 @@
+// SPDX-License-Identifier: GPL-2.0
+
+//! Sleepable read-copy update (SRCU) support.
+//!
+//! C header: [`include/linux/srcu.h`](srctree/include/linux/srcu.h)
+
+use crate::{
+ bindings,
+ error::to_result,
+ prelude::*,
+ sync::LockClassKey,
+ types::{
+ NotThreadSafe,
+ Opaque, //
+ },
+};
+
+use pin_init::pin_data;
+
+/// Creates an [`Srcu`] initialiser with the given name and a newly-created lock class.
+#[macro_export]
+macro_rules! new_srcu {
+ ($($name:literal)?) => {
+ $crate::sync::Srcu::new($crate::optional_name!($($name)?), $crate::static_lock_class!())
+ };
+}
+pub use new_srcu;
+
+/// Sleepable read-copy update primitive.
+///
+/// SRCU readers may sleep while holding the read-side guard.
+#[repr(transparent)]
+#[pin_data(PinnedDrop)]
+pub struct Srcu {
+ #[pin]
+ inner: Opaque<bindings::srcu_struct>,
+}
+
+impl Srcu {
+ /// Creates a new SRCU instance.
+ #[inline]
+ pub fn new(name: &'static CStr, key: Pin<&'static LockClassKey>) -> impl PinInit<Self, Error> {
+ 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_with_key(ptr, name.as_char_ptr(), key.as_ptr())
+ })
+ }),
+ })
+ }
+
+ /// Enters an SRCU read-side critical section.
+ #[inline]
+ 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,
+ _not_send: NotThreadSafe,
+ }
+ }
+
+ /// Waits until all pre-existing SRCU readers have completed.
+ #[inline]
+ 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.
+ #[inline]
+ 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>) {
+ let ptr = self.inner.get();
+
+ // SAFETY: `self` is pinned and `ptr` points to a valid initialized `srcu_struct`.
+ unsafe { bindings::srcu_barrier(ptr) };
+ // SAFETY: Same as above.
+ unsafe { bindings::cleanup_srcu_struct(ptr) };
+ }
+}
+
+/// Guard for an active SRCU read-side critical section on a particular [`Srcu`].
+///
+/// # Invariants
+///
+/// `idx` is the index returned by `srcu_read_lock()` for `srcu`.
+pub struct Guard<'a> {
+ srcu: &'a Srcu,
+ idx: i32,
+ _not_send: NotThreadSafe,
+}
+
+impl Guard<'_> {
+ /// Explicitly releases the SRCU read-side critical section.
+ #[inline]
+ 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) };
+ }
+}
--
2.51.2
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH v1 3/3] MAINTAINERS: add Rust SRCU files to SRCU entry
2026-04-28 10:34 [PATCH v1 0/3] rust: add SRCU abstraction Onur Özkan
2026-04-28 10:34 ` [PATCH v1 1/3] rust: helpers: add SRCU helpers Onur Özkan
2026-04-28 10:34 ` [PATCH v1 2/3] rust: sync: add SRCU abstraction Onur Özkan
@ 2026-04-28 10:34 ` Onur Özkan
2 siblings, 0 replies; 4+ messages in thread
From: Onur Özkan @ 2026-04-28 10:34 UTC (permalink / raw)
To: rcu, rust-for-linux, linux-kernel
Cc: ojeda, boqun, gary, bjorn3_gh, lossin, a.hindborg, aliceryhl,
tmgross, dakr, peterz, fujita.tomonori, tamird, jiangshanlai,
paulmck, josh, rostedt, mathieu.desnoyers, Onur Özkan
Include Rust side implementation files to the SRCU maintainer
entry.
Signed-off-by: Onur Özkan <work@onurozkan.dev>
---
MAINTAINERS | 3 +++
1 file changed, 3 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index 9c93fa23654c..8c1588e2f6fe 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -24405,6 +24405,7 @@ SLEEPABLE READ-COPY UPDATE (SRCU)
M: Lai Jiangshan <jiangshanlai@gmail.com>
M: "Paul E. McKenney" <paulmck@kernel.org>
M: Josh Triplett <josh@joshtriplett.org>
+M: Onur Özkan <work@onurozkan.dev> (RUST)
R: Steven Rostedt <rostedt@goodmis.org>
R: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
L: rcu@vger.kernel.org
@@ -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 <casey@schaufler-ca.com>
--
2.51.2
^ permalink raw reply related [flat|nested] 4+ messages in thread