From nobody Wed Jun 17 03:57:20 2026 Received: from mail-43172.protonmail.ch (mail-43172.protonmail.ch [185.70.43.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BD1A3EFD1E; Tue, 28 Apr 2026 10:34:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.43.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777372506; cv=none; b=WvEESCMAxCTr9cR2/A5k+wIxLJ7ISi8LlCoZMvIwCyg7iroCMfB3z0zXl/wqu8z9R5nPlMDbmP2N2/7NHp3AgpB2QbbMNyNd5dtoZPtmg6ZuqF5Wp6kVq5g71Bu++g96IcLI1sKfx4T20ugPbhOjp0GSzfP0hhpSEuICsq8wyI4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777372506; c=relaxed/simple; bh=sFsnPP/TjA49FCwCuJLd6D0kqm266fCKXuwd3Kh4q0o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JvBXKD4Tgt9DgWCtwdIwQJ4X2ZDCJ5/jKW7A7uiLpKG/LqtTL/ydhzgMJetz5UCSEZ5FwGJFpJVWxtpFtYm4WlYOK26koRtoidFg+uk+jLgnyk7hKaRWUvWVIx9pQMNwFprFiEW+riPDV9Z6xWlnYNB9t4WLRSH/UHpvImpPt+s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=onurozkan.dev; spf=pass smtp.mailfrom=onurozkan.dev; dkim=pass (2048-bit key) header.d=onurozkan.dev header.i=@onurozkan.dev header.b=KyCb5AOj; arc=none smtp.client-ip=185.70.43.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=onurozkan.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=onurozkan.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=onurozkan.dev header.i=@onurozkan.dev header.b="KyCb5AOj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=onurozkan.dev; s=protonmail; t=1777372486; x=1777631686; bh=7Jzgvk8C4Ksf1LMZ0sj5siyM620cpHaF4e21fQG7iio=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:From:To: Cc:Date:Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=KyCb5AOjXS+nJYxTSSIAmoN4bJRP4iU27Me3C48aD7vKUUX3VMEJjvAKDL0ZutCh1 RtcIljn70TrWlBDEu5tzInXJXck6Xyup4sThW2qxvrVQMStBQNhOG8ynqfw6PC3C2G L5sjvPPTHmR0PbEoez9BIonyAqfmpMk6FRLYyykNBdYUmQ8U5LmTQsI/7icP7qyHOc PmguM5gfXBRUEiTYXevK3507dbi2S5pOLIn01reLn70FqOlcyv9oNI3xwXnGh035jD h9oPZ6zUKByAdxu4nU8z19pYesc2S4QSe2lFxB/LaLkGW/NzNhh+3d4yq0jeMD4YBD 506DmJSASnvjg== X-Pm-Submission-Id: 4g4cJ43855z2ScWp From: =?UTF-8?q?Onur=20=C3=96zkan?= To: rcu@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ojeda@kernel.org, boqun@kernel.org, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu, dakr@kernel.org, peterz@infradead.org, fujita.tomonori@gmail.com, tamird@kernel.org, jiangshanlai@gmail.com, paulmck@kernel.org, josh@joshtriplett.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, =?UTF-8?q?Onur=20=C3=96zkan?= Subject: [PATCH v1 1/3] rust: helpers: add SRCU helpers Date: Tue, 28 Apr 2026 13:34:35 +0300 Message-ID: <20260428103437.156236-2-work@onurozkan.dev> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20260428103437.156236-1-work@onurozkan.dev> References: <20260428103437.156236-1-work@onurozkan.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Add helper wrappers for SRCU functions that are exposed to Rust through generated bindings. Signed-off-by: Onur =C3=96zkan --- 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 + +__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, i= nt idx) +{ + srcu_read_unlock(ssp, idx); +} --=20 2.51.2 From nobody Wed Jun 17 03:57:20 2026 Received: from mail-05.mail-europe.com (mail-05.mail-europe.com [85.9.206.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE92B3E7150; Tue, 28 Apr 2026 10:35:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=85.9.206.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777372513; cv=none; b=Frzcjr+YE0Gn038gHEgZWqB9vqM+6Nr4Tzt03snxOGj7tt8AxNKdupsi+BR4HhDDxkLrRTWcigRUJgT+47x6E5h72R3LGPatnspG3BdxbGKzqwJFWY+rFR+olGOIEB7be4kZ8dehKore49SkBdsSa4qVsD5E3ILVeANN+Z41T5M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777372513; c=relaxed/simple; bh=eBKJ4eIdUeQwhCgd1EPn8hI3NsaQBeJdHKPN1UiZYaU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JFW746VZX6CH3Eq1w20e3ig6gNw5MRxhpZ3r7lR6V2750c2lQdNd2b6aqLBoTRAVd87xL7JKxRxhPJK/v38JgkmK1A9HwCQ89JwoxCp0Dh5jaSGrGPQR6tVwDkxhaaFefUNqmYx+uETkqVLBbblbkatZsul01pPS9OjBweFxz3I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=onurozkan.dev; spf=pass smtp.mailfrom=onurozkan.dev; dkim=pass (2048-bit key) header.d=onurozkan.dev header.i=@onurozkan.dev header.b=hGHCEujM; arc=none smtp.client-ip=85.9.206.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=onurozkan.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=onurozkan.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=onurozkan.dev header.i=@onurozkan.dev header.b="hGHCEujM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=onurozkan.dev; s=protonmail; t=1777372488; x=1777631688; bh=i1szb2YquWuHqykbbXqfPmt5mC/gTJnBG1Oa09riRDc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:From:To: Cc:Date:Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=hGHCEujMtXq5PZCxNITkpIfGPCdsPH46RejzHmyXtC83vDd6PahMCRe5EBgYw1uLD GhLXyjU6znicSdUexV/KEPPh/z9ujWY+olZsGp5VtLB/638xFUbCdksrx02MR5F98c EJArABZSnPMNrsS9YhXS0u1pPk6dk50qYvqUenrm0Jog9/SpqXpjgBF5xgh9VNIlYh 9zRnKOIQI18/2Z1l6uOJHwCHBMdudTEaFSqNaOZzM/baQEGyP+8yT+16RmJ3QiukTa aMMB6Ymnk5sdcf18ovHzaMCRPtEYwJHvBMEbk77CB3eX5LCOHjbi6V09r8D5NrEw11 dEBJPdHqSnPhg== X-Pm-Submission-Id: 4g4cJ63tD6z2ScpS From: =?UTF-8?q?Onur=20=C3=96zkan?= To: rcu@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ojeda@kernel.org, boqun@kernel.org, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu, dakr@kernel.org, peterz@infradead.org, fujita.tomonori@gmail.com, tamird@kernel.org, jiangshanlai@gmail.com, paulmck@kernel.org, josh@joshtriplett.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, =?UTF-8?q?Onur=20=C3=96zkan?= Subject: [PATCH v1 2/3] rust: sync: add SRCU abstraction Date: Tue, 28 Apr 2026 13:34:36 +0300 Message-ID: <20260428103437.156236-3-work@onurozkan.dev> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20260428103437.156236-1-work@onurozkan.dev> References: <20260428103437.156236-1-work@onurozkan.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 =C3=96zkan --- 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; =20 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; =20 /// 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-create= d lock class. +#[macro_export] +macro_rules! new_srcu { + ($($name:literal)?) =3D> { + $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, +} + +impl Srcu { + /// Creates a new SRCU instance. + #[inline] + pub fn new(name: &'static CStr, key: Pin<&'static LockClassKey>) -> im= pl PinInit { + 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 i= nitialized `srcu_struct`. + let idx =3D 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 i= nitialized `srcu_struct`. + unsafe { bindings::synchronize_srcu(self.inner.get()) }; + } + + /// Waits until all pre-existing SRCU readers have completed, expedite= d. + /// + /// This requests a lower-latency grace period than [`Srcu::synchroniz= e`] typically + /// at the cost of higher system-wide overhead. Prefer [`Srcu::synchro= nize`] 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 i= nitialized `srcu_struct`. + unsafe { bindings::synchronize_srcu_expedited(self.inner.get()) }; + } +} + +#[pinned_drop] +impl PinnedDrop for Srcu { + fn drop(self: Pin<&mut Self>) { + let ptr =3D self.inner.get(); + + // SAFETY: `self` is pinned and `ptr` points to a valid initialize= d `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.id= x) }; + } +} --=20 2.51.2 From nobody Wed Jun 17 03:57:20 2026 Received: from mail-244108.protonmail.ch (mail-244108.protonmail.ch [109.224.244.108]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 035B33EF0B3; Tue, 28 Apr 2026 10:35:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=109.224.244.108 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777372512; cv=none; b=K4T3DioI36gp75awtHZ3G2ORTuMq9HUpqEGa4be+qPR9Q+Rj4zmWYbpvCFNL4kDmgecN4BCgrq18tUD2fCg63KklzAHH042riiWjRUv2FjWLisps2xhZmgyTE2rQaA2lY4b3dpoLRpN+wGMPO9Vine9ecAzmnOUpkcMig+9u9sc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777372512; c=relaxed/simple; bh=aLN/nYG9SOkiA4x4g2eZtGH4x/hIBvc7zj9D1ao0FNM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=u9d+r6BBzVgS2YXALCL3X4B1OlczXEowkUYd/ncz4lh8XtA8qquVjRrk6PoMcvGJLMdmKDTs5BT+IX4WUrtaHucqQeV0l+Dkc+i/DFV9x+DJYU7T/YJGASDktouwOlvruLoZkFDr1ZrJPhjJcGA6HjrMmxpJ3OUDg4gwYZ07RL8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=onurozkan.dev; spf=pass smtp.mailfrom=onurozkan.dev; dkim=pass (2048-bit key) header.d=onurozkan.dev header.i=@onurozkan.dev header.b=p+vYSuFz; arc=none smtp.client-ip=109.224.244.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=onurozkan.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=onurozkan.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=onurozkan.dev header.i=@onurozkan.dev header.b="p+vYSuFz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=onurozkan.dev; s=protonmail; t=1777372492; x=1777631692; bh=H3sh8/9rJHMx1+JJUzxq6tpBVaFRS1rv7nPe7gXi5Ow=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:From:To: Cc:Date:Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=p+vYSuFzHl/TYa7yJuu56kGVfY00dHuPjky5xPngap7531Z3kwpOyBsE/d+AfEEO/ dtVkvxU9u4wWXHfbzyQNJUbasXGwY5QOyuLGz7gwRhm9Y0NY/Vod1o3pZ1fVcgfURM zAEPB60TW7cUcQ8rWGKOpeeglGPJSI/uNvLONSHl/t1Sbt8hke7758o5RN2fZhFRR6 9cIpZYPyrGMCaQJOSQc6MlbYMEf7Q7QNANU/ZRQk1Yl7dxPe2nFwFVghgtG9uY+k3b oHHVMaWxriNmP5Fp1fUleyHn+POGvskQAiMMm1grdkbAgOVtLFnQ7ORs/+b67iHNOO jakJsMUAsXFHw== X-Pm-Submission-Id: 4g4cJ84XKTz2ScWp From: =?UTF-8?q?Onur=20=C3=96zkan?= To: rcu@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ojeda@kernel.org, boqun@kernel.org, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu, dakr@kernel.org, peterz@infradead.org, fujita.tomonori@gmail.com, tamird@kernel.org, jiangshanlai@gmail.com, paulmck@kernel.org, josh@joshtriplett.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, =?UTF-8?q?Onur=20=C3=96zkan?= Subject: [PATCH v1 3/3] MAINTAINERS: add Rust SRCU files to SRCU entry Date: Tue, 28 Apr 2026 13:34:37 +0300 Message-ID: <20260428103437.156236-4-work@onurozkan.dev> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20260428103437.156236-1-work@onurozkan.dev> References: <20260428103437.156236-1-work@onurozkan.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Include Rust side implementation files to the SRCU maintainer entry. Signed-off-by: Onur =C3=96zkan --- 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 M: "Paul E. McKenney" M: Josh Triplett +M: Onur =C3=96zkan (RUST) R: Steven Rostedt R: Mathieu Desnoyers 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 =20 SMACK SECURITY MODULE M: Casey Schaufler --=20 2.51.2