[tip: locking/core] rust: sync: Add abstraction for synchronize_rcu()

"tip-bot2 for Philipp Stanner" <[email protected]>
Newsgroups gmane.linux.kernel
Message-ID <178611874587.708.14611384079551071863.tip-bot2@tip-bot2>
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 <[email protected]>
AuthorDate:    Wed, 24 Jun 2026 17:07:02 +02:00
Committer:     Boqun Feng <[email protected]>
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 <[email protected]>
Reviewed-by: Onur Özkan <[email protected]>
Reviewed-by: Danilo Krummrich <[email protected]>
Reviewed-by: Gary Guo <[email protected]>
[boqun: Fix rustdoc reported by kernel test robot <[email protected]>]
Signed-off-by: Boqun Feng <[email protected]>
Link: https://patch.msgid.link/[email protected]
---
 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() };
+}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.