* [PATCH v3 1/3] rust: sync: Add abstraction for synchronize_rcu()
2026-06-24 15:07 [PATCH v3 0/3] Add and use abstraction for synchronize_rcu() Philipp Stanner
@ 2026-06-24 15:07 ` Philipp Stanner
2026-08-07 16:05 ` [tip: locking/core] " tip-bot2 for Philipp Stanner
2026-06-24 15:07 ` [PATCH v3 2/3] rust: revocable: Use safe synchronize_rcu() abstraction Philipp Stanner
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Philipp Stanner @ 2026-06-24 15:07 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
Alexandre Courbot, Onur Özkan, Alexander Viro,
Christian Brauner, Jan Kara, Lyude Paul, Paul E. McKenney,
Frederic Weisbecker, Neeraj Upadhyay, Joel Fernandes,
Josh Triplett, Uladzislau Rezki, Steven Rostedt,
Mathieu Desnoyers, Lai Jiangshan, Zqiang, Christian Schrefl,
Philipp Stanner
Cc: rust-for-linux, linux-kernel, linux-fsdevel, rcu
synchronize_rcu() is a frequently used C function which is always safe
to be called.
Add a safe abstraction for synchronize_rcu().
Signed-off-by: Philipp Stanner <phasta@kernel.org>
Reviewed-by: Onur Özkan <work@onurozkan.dev>
Reviewed-by: Danilo Krummrich <dakr@kernel.org>
Reviewed-by: Gary Guo <gary@garyguo.net>
---
rust/kernel/sync/rcu.rs | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/rust/kernel/sync/rcu.rs b/rust/kernel/sync/rcu.rs
index a32bef6e490b..2bae76d229f0 100644
--- a/rust/kernel/sync/rcu.rs
+++ b/rust/kernel/sync/rcu.rs
@@ -50,3 +50,19 @@ fn drop(&mut self) {
pub fn read_lock() -> Guard {
Guard::new()
}
+
+/// Wait for one RCU grace period.
+///
+/// Waits for all RCU read-side critical sections (such as those established by
+/// a [`rcu::Guard`]) at the moment of the function call to finish.
+///
+/// Does not prevent new read-side critical sections from starting, which may
+/// begin and run while this call is blocking.
+///
+/// Note that this is one of the RCU primitives which must not be called in
+/// atomic context.
+#[inline]
+pub fn synchronize_rcu() {
+ // SAFETY: `synchronize_rcu()` is always safe to be called from process context.
+ unsafe { bindings::synchronize_rcu() };
+}
--
2.54.0
^ permalink raw reply [flat|nested] 8+ messages in thread* [tip: locking/core] rust: sync: Add abstraction for synchronize_rcu()
2026-06-24 15:07 ` [PATCH v3 1/3] rust: sync: Add " Philipp Stanner
@ 2026-08-07 16:05 ` tip-bot2 for Philipp Stanner
0 siblings, 0 replies; 8+ messages in thread
From: tip-bot2 for Philipp Stanner @ 2026-08-07 16:05 UTC (permalink / raw)
To: linux-tip-commits
Cc: Philipp Stanner, work, Danilo Krummrich, Gary Guo, Boqun Feng,
x86, linux-kernel
The following commit has been merged into the locking/core branch of tip:
Commit-ID: 1fb92e0625596985b3941925afe7906fef41214b
Gitweb: https://git.kernel.org/tip/1fb92e0625596985b3941925afe7906fef41214b
Author: Philipp Stanner <phasta@kernel.org>
AuthorDate: Wed, 24 Jun 2026 17:07:02 +02:00
Committer: Boqun Feng <boqun@kernel.org>
CommitterDate: Tue, 04 Aug 2026 05:52:53 -07:00
rust: sync: Add abstraction for synchronize_rcu()
synchronize_rcu() is a frequently used C function which is always safe
to be called.
Add a safe abstraction for synchronize_rcu().
Signed-off-by: Philipp Stanner <phasta@kernel.org>
Reviewed-by: Onur Özkan <work@onurozkan.dev>
Reviewed-by: Danilo Krummrich <dakr@kernel.org>
Reviewed-by: Gary Guo <gary@garyguo.net>
[boqun: Fix rustdoc reported by kernel test robot <lkp@intel.com>]
Signed-off-by: Boqun Feng <boqun@kernel.org>
Link: https://patch.msgid.link/20260624150704.1504001-3-phasta@kernel.org
---
rust/kernel/sync/rcu.rs | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/rust/kernel/sync/rcu.rs b/rust/kernel/sync/rcu.rs
index a32bef6..d867240 100644
--- a/rust/kernel/sync/rcu.rs
+++ b/rust/kernel/sync/rcu.rs
@@ -50,3 +50,19 @@ impl Drop for Guard {
pub fn read_lock() -> Guard {
Guard::new()
}
+
+/// Wait for one RCU grace period.
+///
+/// Waits for all RCU read-side critical sections (such as those established by
+/// a [`Guard`]) at the moment of the function call to finish.
+///
+/// Does not prevent new read-side critical sections from starting, which may
+/// begin and run while this call is blocking.
+///
+/// Note that this is one of the RCU primitives which must not be called in
+/// atomic context.
+#[inline]
+pub fn synchronize_rcu() {
+ // SAFETY: `synchronize_rcu()` is always safe to be called from process context.
+ unsafe { bindings::synchronize_rcu() };
+}
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v3 2/3] rust: revocable: Use safe synchronize_rcu() abstraction
2026-06-24 15:07 [PATCH v3 0/3] Add and use abstraction for synchronize_rcu() Philipp Stanner
2026-06-24 15:07 ` [PATCH v3 1/3] rust: sync: Add " Philipp Stanner
@ 2026-06-24 15:07 ` Philipp Stanner
2026-08-07 16:05 ` [tip: locking/core] " tip-bot2 for Philipp Stanner
2026-06-24 15:07 ` [PATCH v3 3/3] rust: sync: Use safe synchronize_rcu() abstraction in poll Philipp Stanner
2026-06-24 15:30 ` [PATCH v3 0/3] Add and use abstraction for synchronize_rcu() Boqun Feng
3 siblings, 1 reply; 8+ messages in thread
From: Philipp Stanner @ 2026-06-24 15:07 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
Alexandre Courbot, Onur Özkan, Alexander Viro,
Christian Brauner, Jan Kara, Lyude Paul, Paul E. McKenney,
Frederic Weisbecker, Neeraj Upadhyay, Joel Fernandes,
Josh Triplett, Uladzislau Rezki, Steven Rostedt,
Mathieu Desnoyers, Lai Jiangshan, Zqiang, Christian Schrefl,
Philipp Stanner
Cc: rust-for-linux, linux-kernel, linux-fsdevel, rcu
We now have a safe wrapper for the foreign function synchronize_rcu().
Use it in revocable.rs.
Signed-off-by: Philipp Stanner <phasta@kernel.org>
Reviewed-by: Onur Özkan <work@onurozkan.dev>
Reviewed-by: Danilo Krummrich <dakr@kernel.org>
Reviewed-by: Gary Guo <gary@garyguo.net>
---
rust/kernel/revocable.rs | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/rust/kernel/revocable.rs b/rust/kernel/revocable.rs
index 0f4ae673256d..f539603349f1 100644
--- a/rust/kernel/revocable.rs
+++ b/rust/kernel/revocable.rs
@@ -7,7 +7,11 @@
use pin_init::Wrapper;
-use crate::{bindings, prelude::*, sync::rcu, types::Opaque};
+use crate::{
+ prelude::*,
+ sync::rcu,
+ types::Opaque, //
+};
use core::{
marker::PhantomData,
ops::Deref,
@@ -161,8 +165,7 @@ unsafe fn revoke_internal<const SYNC: bool>(&self) -> bool {
if revoke {
if SYNC {
- // SAFETY: Just an FFI call, there are no further requirements.
- unsafe { bindings::synchronize_rcu() };
+ rcu::synchronize_rcu();
}
// SAFETY: We know `self.data` is valid because only one CPU can succeed the
--
2.54.0
^ permalink raw reply [flat|nested] 8+ messages in thread* [tip: locking/core] rust: revocable: Use safe synchronize_rcu() abstraction
2026-06-24 15:07 ` [PATCH v3 2/3] rust: revocable: Use safe synchronize_rcu() abstraction Philipp Stanner
@ 2026-08-07 16:05 ` tip-bot2 for Philipp Stanner
0 siblings, 0 replies; 8+ messages in thread
From: tip-bot2 for Philipp Stanner @ 2026-08-07 16:05 UTC (permalink / raw)
To: linux-tip-commits
Cc: Philipp Stanner, work, Danilo Krummrich, Gary Guo, Boqun Feng,
x86, linux-kernel
The following commit has been merged into the locking/core branch of tip:
Commit-ID: 042278f5fa9e681420ab486d6cbf464e26667461
Gitweb: https://git.kernel.org/tip/042278f5fa9e681420ab486d6cbf464e26667461
Author: Philipp Stanner <phasta@kernel.org>
AuthorDate: Wed, 24 Jun 2026 17:07:03 +02:00
Committer: Boqun Feng <boqun@kernel.org>
CommitterDate: Tue, 04 Aug 2026 05:52:53 -07:00
rust: revocable: Use safe synchronize_rcu() abstraction
We now have a safe wrapper for the foreign function synchronize_rcu().
Use it in revocable.rs.
Signed-off-by: Philipp Stanner <phasta@kernel.org>
Reviewed-by: Onur Özkan <work@onurozkan.dev>
Reviewed-by: Danilo Krummrich <dakr@kernel.org>
Reviewed-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Boqun Feng <boqun@kernel.org>
Link: https://patch.msgid.link/20260624150704.1504001-4-phasta@kernel.org
---
rust/kernel/revocable.rs | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/rust/kernel/revocable.rs b/rust/kernel/revocable.rs
index 0f4ae67..f539603 100644
--- a/rust/kernel/revocable.rs
+++ b/rust/kernel/revocable.rs
@@ -7,7 +7,11 @@
use pin_init::Wrapper;
-use crate::{bindings, prelude::*, sync::rcu, types::Opaque};
+use crate::{
+ prelude::*,
+ sync::rcu,
+ types::Opaque, //
+};
use core::{
marker::PhantomData,
ops::Deref,
@@ -161,8 +165,7 @@ impl<T> Revocable<T> {
if revoke {
if SYNC {
- // SAFETY: Just an FFI call, there are no further requirements.
- unsafe { bindings::synchronize_rcu() };
+ rcu::synchronize_rcu();
}
// SAFETY: We know `self.data` is valid because only one CPU can succeed the
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v3 3/3] rust: sync: Use safe synchronize_rcu() abstraction in poll
2026-06-24 15:07 [PATCH v3 0/3] Add and use abstraction for synchronize_rcu() Philipp Stanner
2026-06-24 15:07 ` [PATCH v3 1/3] rust: sync: Add " Philipp Stanner
2026-06-24 15:07 ` [PATCH v3 2/3] rust: revocable: Use safe synchronize_rcu() abstraction Philipp Stanner
@ 2026-06-24 15:07 ` Philipp Stanner
2026-08-07 16:05 ` [tip: locking/core] " tip-bot2 for Philipp Stanner
2026-06-24 15:30 ` [PATCH v3 0/3] Add and use abstraction for synchronize_rcu() Boqun Feng
3 siblings, 1 reply; 8+ messages in thread
From: Philipp Stanner @ 2026-06-24 15:07 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
Alexandre Courbot, Onur Özkan, Alexander Viro,
Christian Brauner, Jan Kara, Lyude Paul, Paul E. McKenney,
Frederic Weisbecker, Neeraj Upadhyay, Joel Fernandes,
Josh Triplett, Uladzislau Rezki, Steven Rostedt,
Mathieu Desnoyers, Lai Jiangshan, Zqiang, Christian Schrefl,
Philipp Stanner
Cc: rust-for-linux, linux-kernel, linux-fsdevel, rcu
We now have a safe wrapper for the foreign function synchronize_rcu().
Use it in poll.rs.
Signed-off-by: Philipp Stanner <phasta@kernel.org>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Onur Özkan <work@onurozkan.dev>
Reviewed-by: Danilo Krummrich <dakr@kernel.org>
Reviewed-by: Gary Guo <gary@garyguo.net>
---
rust/kernel/sync/poll.rs | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/rust/kernel/sync/poll.rs b/rust/kernel/sync/poll.rs
index 0ec985d560c8..30ebeea1702f 100644
--- a/rust/kernel/sync/poll.rs
+++ b/rust/kernel/sync/poll.rs
@@ -8,7 +8,11 @@
bindings,
fs::File,
prelude::*,
- sync::{CondVar, LockClassKey},
+ sync::{
+ CondVar,
+ LockClassKey,
+ rcu::synchronize_rcu, //
+ }, //
};
use core::{marker::PhantomData, ops::Deref};
@@ -99,8 +103,6 @@ fn drop(self: Pin<&mut Self>) {
unsafe { bindings::__wake_up_pollfree(self.inner.wait_queue_head.get()) };
// Wait for epoll items to be properly removed.
- //
- // SAFETY: Just an FFI call.
- unsafe { bindings::synchronize_rcu() };
+ synchronize_rcu();
}
}
--
2.54.0
^ permalink raw reply [flat|nested] 8+ messages in thread* [tip: locking/core] rust: sync: Use safe synchronize_rcu() abstraction in poll
2026-06-24 15:07 ` [PATCH v3 3/3] rust: sync: Use safe synchronize_rcu() abstraction in poll Philipp Stanner
@ 2026-08-07 16:05 ` tip-bot2 for Philipp Stanner
0 siblings, 0 replies; 8+ messages in thread
From: tip-bot2 for Philipp Stanner @ 2026-08-07 16:05 UTC (permalink / raw)
To: linux-tip-commits
Cc: Philipp Stanner, Alice Ryhl, work, Danilo Krummrich, Gary Guo,
Boqun Feng, x86, linux-kernel
The following commit has been merged into the locking/core branch of tip:
Commit-ID: 47c3367ff096e66f614ed3cdadece26ffc04b5e8
Gitweb: https://git.kernel.org/tip/47c3367ff096e66f614ed3cdadece26ffc04b5e8
Author: Philipp Stanner <phasta@kernel.org>
AuthorDate: Wed, 24 Jun 2026 17:07:04 +02:00
Committer: Boqun Feng <boqun@kernel.org>
CommitterDate: Tue, 04 Aug 2026 05:52:54 -07:00
rust: sync: Use safe synchronize_rcu() abstraction in poll
We now have a safe wrapper for the foreign function synchronize_rcu().
Use it in poll.rs.
Signed-off-by: Philipp Stanner <phasta@kernel.org>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Onur Özkan <work@onurozkan.dev>
Reviewed-by: Danilo Krummrich <dakr@kernel.org>
Reviewed-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Boqun Feng <boqun@kernel.org>
Link: https://patch.msgid.link/20260624150704.1504001-5-phasta@kernel.org
---
rust/kernel/sync/poll.rs | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/rust/kernel/sync/poll.rs b/rust/kernel/sync/poll.rs
index 0ec985d..5aa0ce9 100644
--- a/rust/kernel/sync/poll.rs
+++ b/rust/kernel/sync/poll.rs
@@ -8,7 +8,11 @@ use crate::{
bindings,
fs::File,
prelude::*,
- sync::{CondVar, LockClassKey},
+ sync::{
+ rcu::synchronize_rcu,
+ CondVar,
+ LockClassKey, //
+ }, //
};
use core::{marker::PhantomData, ops::Deref};
@@ -99,8 +103,6 @@ impl PinnedDrop for PollCondVar {
unsafe { bindings::__wake_up_pollfree(self.inner.wait_queue_head.get()) };
// Wait for epoll items to be properly removed.
- //
- // SAFETY: Just an FFI call.
- unsafe { bindings::synchronize_rcu() };
+ synchronize_rcu();
}
}
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3 0/3] Add and use abstraction for synchronize_rcu()
2026-06-24 15:07 [PATCH v3 0/3] Add and use abstraction for synchronize_rcu() Philipp Stanner
` (2 preceding siblings ...)
2026-06-24 15:07 ` [PATCH v3 3/3] rust: sync: Use safe synchronize_rcu() abstraction in poll Philipp Stanner
@ 2026-06-24 15:30 ` Boqun Feng
3 siblings, 0 replies; 8+ messages in thread
From: Boqun Feng @ 2026-06-24 15:30 UTC (permalink / raw)
To: Philipp Stanner
Cc: Miguel Ojeda, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
Daniel Almeida, Tamir Duberstein, Alexandre Courbot,
Onur Özkan, Alexander Viro, Christian Brauner, Jan Kara,
Lyude Paul, Paul E. McKenney, Frederic Weisbecker,
Neeraj Upadhyay, Joel Fernandes, Josh Triplett, Uladzislau Rezki,
Steven Rostedt, Mathieu Desnoyers, Lai Jiangshan, Zqiang,
Christian Schrefl, rust-for-linux, linux-kernel, linux-fsdevel,
rcu
On Wed, Jun 24, 2026 at 05:07:01PM +0200, Philipp Stanner wrote:
> Changes since v2:
> - Compromise docu for "RCU versus atomic context" a bit better
> - Add respective R-b's
>
> Changes since v1:
> - Vertically format imports. (Onur)
> - Make the new function #[inline]. (Alice)
> - Add Alice's R-b.
>
> Philipp Stanner (3):
> rust: sync: Add abstraction for synchronize_rcu()
> rust: revocable: Use safe synchronize_rcu() abstraction
> rust: sync: Use safe synchronize_rcu() abstraction in poll
>
> rust/kernel/revocable.rs | 9 ++++++---
> rust/kernel/sync/poll.rs | 10 ++++++----
> rust/kernel/sync/rcu.rs | 16 ++++++++++++++++
> 3 files changed, 28 insertions(+), 7 deletions(-)
>
Queue it in rust-sync
https://git.kernel.org/pub/scm/linux/kernel/git/boqun/linux.git/ rust-sync
Thank you all!
Regards,
Boqun
>
> base-commit: 43a393185e33e573a374c1d4f7ddf6481484ef8d
> --
> 2.54.0
>
^ permalink raw reply [flat|nested] 8+ messages in thread