aboutsummaryrefslogtreecommitdiffstats
path: root/rust/helpers.c
diff options
context:
space:
mode:
authorWedson Almeida Filho <[email protected]>2023-04-19 17:44:26 +0000
committerMiguel Ojeda <[email protected]>2023-04-21 22:20:00 +0000
commitc6d917a498bfef603f41bfc4d31e9699bb2909fc (patch)
treef710485f3aaadc20ffd4437fcd9aa2016462116f /rust/helpers.c
parentrust: lock: introduce `Mutex` (diff)
downloadkernel-c6d917a498bfef603f41bfc4d31e9699bb2909fc.tar.gz
kernel-c6d917a498bfef603f41bfc4d31e9699bb2909fc.zip
rust: lock: introduce `SpinLock`
This is the `spinlock_t` lock backend and allows Rust code to use the kernel spinlock idiomatically. Cc: Peter Zijlstra <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Will Deacon <[email protected]> Cc: Waiman Long <[email protected]> Reviewed-by: Martin Rodriguez Reboredo <[email protected]> Signed-off-by: Wedson Almeida Filho <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]>
Diffstat (limited to 'rust/helpers.c')
-rw-r--r--rust/helpers.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/rust/helpers.c b/rust/helpers.c
index 86af099d2d66..446e3cfdb935 100644
--- a/rust/helpers.c
+++ b/rust/helpers.c
@@ -23,6 +23,7 @@
#include <linux/err.h>
#include <linux/refcount.h>
#include <linux/mutex.h>
+#include <linux/spinlock.h>
__noreturn void rust_helper_BUG(void)
{
@@ -36,6 +37,29 @@ void rust_helper_mutex_lock(struct mutex *lock)
}
EXPORT_SYMBOL_GPL(rust_helper_mutex_lock);
+void rust_helper___spin_lock_init(spinlock_t *lock, const char *name,
+ struct lock_class_key *key)
+{
+#ifdef CONFIG_DEBUG_SPINLOCK
+ __raw_spin_lock_init(spinlock_check(lock), name, key, LD_WAIT_CONFIG);
+#else
+ spin_lock_init(lock);
+#endif
+}
+EXPORT_SYMBOL_GPL(rust_helper___spin_lock_init);
+
+void rust_helper_spin_lock(spinlock_t *lock)
+{
+ spin_lock(lock);
+}
+EXPORT_SYMBOL_GPL(rust_helper_spin_lock);
+
+void rust_helper_spin_unlock(spinlock_t *lock)
+{
+ spin_unlock(lock);
+}
+EXPORT_SYMBOL_GPL(rust_helper_spin_unlock);
+
refcount_t rust_helper_REFCOUNT_INIT(int n)
{
return (refcount_t)REFCOUNT_INIT(n);