summaryrefslogtreecommitdiff
path: root/rust/helpers
diff options
context:
space:
mode:
authorBoqun Feng <boqun.feng@gmail.com>2025-09-04 21:41:36 -0700
committerPeter Zijlstra <peterz@infradead.org>2025-09-15 09:38:34 +0200
commitd9ea5a41cef80dc8103f4114b072b27364f2e06a (patch)
treec00263765c7e37f63fd2a2015ac843fbac3ad5c3 /rust/helpers
parent84c6d36bcaf98a8c0533cd334a624d536d20879b (diff)
rust: sync: Add memory barriers
Memory barriers are building blocks for concurrent code, hence provide a minimal set of them. The compiler barrier, barrier(), is implemented in inline asm instead of using core::sync::atomic::compiler_fence() because memory models are different: kernel's atomics are implemented in inline asm therefore the compiler barrier should be implemented in inline asm as well. Also it's currently only public to the kernel crate until there's a reasonable driver usage. Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Elle Rhumsaa <elle@weathered-steel.dev> Link: https://lore.kernel.org/all/20250719030827.61357-10-boqun.feng@gmail.com/
Diffstat (limited to 'rust/helpers')
-rw-r--r--rust/helpers/barrier.c18
-rw-r--r--rust/helpers/helpers.c1
2 files changed, 19 insertions, 0 deletions
diff --git a/rust/helpers/barrier.c b/rust/helpers/barrier.c
new file mode 100644
index 000000000000..cdf28ce8e511
--- /dev/null
+++ b/rust/helpers/barrier.c
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <asm/barrier.h>
+
+void rust_helper_smp_mb(void)
+{
+ smp_mb();
+}
+
+void rust_helper_smp_wmb(void)
+{
+ smp_wmb();
+}
+
+void rust_helper_smp_rmb(void)
+{
+ smp_rmb();
+}
diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c
index 7053f9245759..85ad14b81925 100644
--- a/rust/helpers/helpers.c
+++ b/rust/helpers/helpers.c
@@ -9,6 +9,7 @@
#include "atomic.c"
#include "auxiliary.c"
+#include "barrier.c"
#include "blk.c"
#include "bug.c"
#include "build_assert.c"