[PATCH 19/24] rust: sync: Add abstraction for synchronize_rcu()
From: Boqun Feng
Date: Fri Jul 31 2026 - 16:38:51 EST
From: Philipp Stanner <phasta@xxxxxxxxxx>
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@xxxxxxxxxx>
Reviewed-by: Onur Özkan <work@xxxxxxxxxxxxx>
Reviewed-by: Danilo Krummrich <dakr@xxxxxxxxxx>
Reviewed-by: Gary Guo <gary@xxxxxxxxxxx>
[boqun: Fix rustdoc reported by kernel test robot <lkp@xxxxxxxxx>]
Signed-off-by: Boqun Feng <boqun@xxxxxxxxxx>
Link: https://patch.msgid.link/20260624150704.1504001-3-phasta@xxxxxxxxxx
---
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..d867240be736 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 [`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.50.1 (Apple Git-155)