Skip to content

Commit d8973c4

Browse files
Philipp Stannerojeda
authored andcommitted
rust: sync: Add abstraction for rcu_barrier()
rcu_barrier() is a frequently used C function which is always safe to be called. Add a safe abstraction for rcu_barrier(). Tested-by: Daniel Almeida <daniel.almeida@collabora.com> Signed-off-by: Philipp Stanner <phasta@kernel.org> Acked-by: Gary Guo <gary@garyguo.net> Reviewed-by: Onur Özkan <work@onurozkan.dev> Acked-by: Danilo Krummrich <dakr@kernel.org> Link: https://patch.msgid.link/20260805145949.938505-5-phasta@kernel.org [ Formatted documentation. Sorted tags. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent 445ac1c commit d8973c4

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

rust/kernel/sync/rcu.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,23 @@ impl Drop for Guard {
5050
pub fn read_lock() -> Guard {
5151
Guard::new()
5252
}
53+
54+
/// Wait until all in-flight `call_rcu()` callbacks complete.
55+
///
56+
/// Note that this primitive does not necessarily wait for an RCU grace period
57+
/// to complete. For example, if there are no RCU callbacks queued anywhere
58+
/// in the system, then [`rcu_barrier()`] is within its rights to return
59+
/// immediately, without waiting for anything, much less an RCU grace period.
60+
/// In fact, [`rcu_barrier()`] will normally not result in any RCU grace periods
61+
/// beyond those that were already destined to be executed.
62+
///
63+
/// In kernels built with `CONFIG_RCU_LAZY=y`, this function also hurries all
64+
/// pending lazy RCU callbacks.
65+
///
66+
/// Note that this is one of the RCU primitives which must not be called in
67+
/// atomic context.
68+
#[inline]
69+
pub fn rcu_barrier() {
70+
// SAFETY: `rcu_barrier()` is always safe to be called. It just might wait for a grace period.
71+
unsafe { bindings::rcu_barrier() };
72+
}

0 commit comments

Comments
 (0)