rust: lock: introduce `SpinLock`
Subsystems (3)
PATCH 1/1 rust: lock: introduce `SpinLock`
From: Wedson Almeida Filho <[email protected]>
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]>
---
v1 -> v2: No changes
v2 -> v3: No changes
v3 -> v4: No changes
v4 -> v4.1:
- Use __raw_spin_lock_init instead of spin_lock_init_with_key
rust/helpers.c | 24 +++++++ rust/kernel/sync.rs | 2 +- rust/kernel/sync/lock.rs | 1 + rust/kernel/sync/lock/spinlock.rs | 116 ++++++++++++++++++++++++++++++ 4 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 rust/kernel/sync/lock/spinlock.rs
rust/helpers.c +24 -0
@@ -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);
rust/kernel/sync.rs +1 -1
@@ -11,7 +11,7 @@ mod arc;pub mod lock;pub use arc::{Arc ,ArcBorrow ,UniqueArc }; -pub use lock::mutex::Mutex ; +pub use lock::{mutex::Mutex , spinlock::SpinLock };/// Represents a lockdep class. It's a wrapper around C's `lock_class_key`. #[repr(transparent)]
rust/kernel/sync/lock.rs +1 -0
@@ -11,6 +11,7 @@ use core::{cell::UnsafeCell, marker::PhantomData, marker::PhantomPinned};use macros::pin_data;pub mod mutex; +pub mod spinlock;/// The "backend" of a lock. ///
rust/kernel/sync/lock/spinlock.rs new file +116 -0
116 lines not on this page · raw message
Signature · 1 line
2.34.1
Miguel Ojeda
AppliedQuoted 3 lines · Wedson Almeida Filho
This is the
spinlock_tlock backend and allows Rust code to use the kernel spinlock idiomatically.
Applied to rust-next within the main series. Thanks!
Cheers,
Miguel