[PATCH] fixup! locking/local_lock, mm: Replace localtry_ helpers with local_trylock_t type
From: Vlastimil Babka
Date: Tue Apr 01 2025 - 09:25:21 EST
---
include/linux/local_lock.h | 5 ++---
include/linux/local_lock_internal.h | 21 +++++++++++++++++++--
2 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/include/linux/local_lock.h b/include/linux/local_lock.h
index 9262109cca51..7ac9385cd475 100644
--- a/include/linux/local_lock.h
+++ b/include/linux/local_lock.h
@@ -52,15 +52,14 @@
__local_unlock_irqrestore(lock, flags)
/**
- * local_trylock_irqsave - Try to acquire a per CPU local lock
+ * local_trylock - Try to acquire a per CPU local lock
* @lock: The lock variable
- * @flags: Storage for interrupt flags
*
* The function can be used in any context such as NMI or HARDIRQ. Due to
* locking constrains it will _always_ fail to acquire the lock in NMI or
* HARDIRQ context on PREEMPT_RT.
*/
-#define local_trylock(lock, flags) __local_trylock(lock, flags)
+#define local_trylock(lock) __local_trylock(lock)
/**
* local_trylock_irqsave - Try to acquire a per CPU local lock, save and disable
diff --git a/include/linux/local_lock_internal.h b/include/linux/local_lock_internal.h
index cc79854206df..5634383c8e9e 100644
--- a/include/linux/local_lock_internal.h
+++ b/include/linux/local_lock_internal.h
@@ -23,7 +23,7 @@ typedef struct {
#endif
/*
* Same layout as local_lock_t with 'acquired' field at the end.
- * (local_trylock_t *) will be casted to (local_lock_t *).
+ * (local_trylock_t *) will be cast to (local_lock_t *).
*/
int acquired;
} local_trylock_t;
@@ -80,7 +80,7 @@ do { \
lockdep_init_map_type(&(lock)->dep_map, #lock, &__key, \
0, LD_WAIT_CONFIG, LD_WAIT_INV, \
LD_LOCK_PERCPU); \
- local_lock_debug_init(lock); \
+ local_lock_debug_init((local_lock_t *)lock); \
} while (0)
#define __spinlock_nested_bh_init(lock) \
@@ -128,6 +128,23 @@ do { \
__local_lock_acquire(lock); \
} while (0)
+#define __local_trylock(lock) \
+ ({ \
+ local_trylock_t *tl; \
+ \
+ preempt_disable(); \
+ tl = this_cpu_ptr(lock); \
+ if (READ_ONCE(tl->acquired) == 1) { \
+ preempt_enable(); \
+ tl = NULL; \
+ } else { \
+ WRITE_ONCE(tl->acquired, 1); \
+ local_trylock_acquire( \
+ (local_lock_t *)tl); \
+ } \
+ !!tl; \
+ })
+
#define __local_trylock_irqsave(lock, flags) \
({ \
local_trylock_t *tl; \
--
2.49.0