* [PATCH 0/3] More lock context annotation fixes
@ 2026-03-13 17:15 Bart Van Assche
2026-03-13 17:15 ` [PATCH 1/3] locking: Fix rwlock support in <linux/spinlock_up.h> Bart Van Assche
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Bart Van Assche @ 2026-03-13 17:15 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Ingo Molnar, Will Deacon, Boqun Feng, Waiman Long, linux-kernel,
Marco Elver, Bart Van Assche
Hi Peter,
This patch series includes additional fixes for lock context annotations for
locking primitives. Please consider this patch series for inclusion in the
upstream kernel.
Thanks,
Bart.
Bart Van Assche (3):
locking: Fix rwlock support in <linux/spinlock_up.h>
locking: Add lock context support in do_raw_{read,write}_trylock()
locking: Add lock context annotations in the spinlock implementation
include/linux/rwlock.h | 14 ++++++++++++--
include/linux/spinlock_up.h | 20 ++++++++++----------
kernel/locking/spinlock.c | 12 ++++++++----
3 files changed, 30 insertions(+), 16 deletions(-)
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/3] locking: Fix rwlock support in <linux/spinlock_up.h>
2026-03-13 17:15 [PATCH 0/3] More lock context annotation fixes Bart Van Assche
@ 2026-03-13 17:15 ` Bart Van Assche
2026-03-18 8:02 ` [tip: locking/core] " tip-bot2 for Bart Van Assche
2026-03-13 17:15 ` [PATCH 2/3] locking: Add lock context support in do_raw_{read,write}_trylock() Bart Van Assche
2026-03-13 17:15 ` [PATCH 3/3] locking: Add lock context annotations in the spinlock implementation Bart Van Assche
2 siblings, 1 reply; 9+ messages in thread
From: Bart Van Assche @ 2026-03-13 17:15 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Ingo Molnar, Will Deacon, Boqun Feng, Waiman Long, linux-kernel,
Marco Elver, Bart Van Assche, Grant Grundler, Andrew Morton,
Arjan van de Ven, Benoit Boissinot
Architecture support for rwlocks must be available whether or not
CONFIG_DEBUG_SPINLOCK has been defined. Move the definitions of the
arch_{read,write}_{lock,trylock,unlock}() macros such that these become
visbile if CONFIG_DEBUG_SPINLOCK=n.
This patch prepares for converting do_raw_{read,write}_trylock() into
inline functions. Without this patch that conversion triggers a build
failure for UP architectures, e.g. arm-ep93xx. I used the following
kernel configuration to build the kernel for that architecture:
CONFIG_ARCH_MULTIPLATFORM=y
CONFIG_ARCH_MULTI_V7=n
CONFIG_ATAGS=y
CONFIG_MMU=y
CONFIG_ARCH_MULTI_V4T=y
CONFIG_CPU_LITTLE_ENDIAN=y
CONFIG_ARCH_EP93XX=y
Fixes: fb1c8f93d869 ("[PATCH] spinlock consolidation")
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
include/linux/spinlock_up.h | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/include/linux/spinlock_up.h b/include/linux/spinlock_up.h
index 1e84e71ca495..3a50976471d7 100644
--- a/include/linux/spinlock_up.h
+++ b/include/linux/spinlock_up.h
@@ -48,16 +48,6 @@ static inline void arch_spin_unlock(arch_spinlock_t *lock)
lock->slock = 1;
}
-/*
- * Read-write spinlocks. No debug version.
- */
-#define arch_read_lock(lock) do { barrier(); (void)(lock); } while (0)
-#define arch_write_lock(lock) do { barrier(); (void)(lock); } while (0)
-#define arch_read_trylock(lock) ({ barrier(); (void)(lock); 1; })
-#define arch_write_trylock(lock) ({ barrier(); (void)(lock); 1; })
-#define arch_read_unlock(lock) do { barrier(); (void)(lock); } while (0)
-#define arch_write_unlock(lock) do { barrier(); (void)(lock); } while (0)
-
#else /* DEBUG_SPINLOCK */
#define arch_spin_is_locked(lock) ((void)(lock), 0)
/* for sched/core.c and kernel_lock.c: */
@@ -68,4 +58,14 @@ static inline void arch_spin_unlock(arch_spinlock_t *lock)
#define arch_spin_is_contended(lock) (((void)(lock), 0))
+/*
+ * Read-write spinlocks. No debug version.
+ */
+#define arch_read_lock(lock) do { barrier(); (void)(lock); } while (0)
+#define arch_write_lock(lock) do { barrier(); (void)(lock); } while (0)
+#define arch_read_trylock(lock) ({ barrier(); (void)(lock); 1; })
+#define arch_write_trylock(lock) ({ barrier(); (void)(lock); 1; })
+#define arch_read_unlock(lock) do { barrier(); (void)(lock); } while (0)
+#define arch_write_unlock(lock) do { barrier(); (void)(lock); } while (0)
+
#endif /* __LINUX_SPINLOCK_UP_H */
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/3] locking: Add lock context support in do_raw_{read,write}_trylock()
2026-03-13 17:15 [PATCH 0/3] More lock context annotation fixes Bart Van Assche
2026-03-13 17:15 ` [PATCH 1/3] locking: Fix rwlock support in <linux/spinlock_up.h> Bart Van Assche
@ 2026-03-13 17:15 ` Bart Van Assche
2026-03-17 13:49 ` Marco Elver
2026-03-18 8:02 ` [tip: locking/core] " tip-bot2 for Bart Van Assche
2026-03-13 17:15 ` [PATCH 3/3] locking: Add lock context annotations in the spinlock implementation Bart Van Assche
2 siblings, 2 replies; 9+ messages in thread
From: Bart Van Assche @ 2026-03-13 17:15 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Ingo Molnar, Will Deacon, Boqun Feng, Waiman Long, linux-kernel,
Marco Elver, Bart Van Assche
Convert do_raw_{read,write}_trylock() from macros into inline functions
and annotate these inline functions with __cond_acquires_shared() or
__cond_acquires() as appropriate. This change is necessary to build
kernel drivers or subsystems that use rwlock synchronization objects with
lock context analysis enabled. The return type 'int' matches the return
type for CONFIG_DEBUG_SPINLOCK=y.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
include/linux/rwlock.h | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/include/linux/rwlock.h b/include/linux/rwlock.h
index 21ceefc4a49f..4e67cd934d8f 100644
--- a/include/linux/rwlock.h
+++ b/include/linux/rwlock.h
@@ -37,10 +37,20 @@ extern int do_raw_write_trylock(rwlock_t *lock) __cond_acquires(true, lock);
extern void do_raw_write_unlock(rwlock_t *lock) __releases(lock);
#else
# define do_raw_read_lock(rwlock) do {__acquire_shared(lock); arch_read_lock(&(rwlock)->raw_lock); } while (0)
-# define do_raw_read_trylock(rwlock) arch_read_trylock(&(rwlock)->raw_lock)
+static inline int do_raw_read_trylock(rwlock_t *rwlock)
+ __cond_acquires_shared(true, rwlock)
+ __no_context_analysis
+{
+ return arch_read_trylock(&(rwlock)->raw_lock);
+}
# define do_raw_read_unlock(rwlock) do {arch_read_unlock(&(rwlock)->raw_lock); __release_shared(lock); } while (0)
# define do_raw_write_lock(rwlock) do {__acquire(lock); arch_write_lock(&(rwlock)->raw_lock); } while (0)
-# define do_raw_write_trylock(rwlock) arch_write_trylock(&(rwlock)->raw_lock)
+static inline int do_raw_write_trylock(rwlock_t *rwlock)
+ __cond_acquires(true, rwlock)
+ __no_context_analysis
+{
+ return arch_write_trylock(&(rwlock)->raw_lock);
+}
# define do_raw_write_unlock(rwlock) do {arch_write_unlock(&(rwlock)->raw_lock); __release(lock); } while (0)
#endif
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/3] locking: Add lock context annotations in the spinlock implementation
2026-03-13 17:15 [PATCH 0/3] More lock context annotation fixes Bart Van Assche
2026-03-13 17:15 ` [PATCH 1/3] locking: Fix rwlock support in <linux/spinlock_up.h> Bart Van Assche
2026-03-13 17:15 ` [PATCH 2/3] locking: Add lock context support in do_raw_{read,write}_trylock() Bart Van Assche
@ 2026-03-13 17:15 ` Bart Van Assche
2026-03-17 13:42 ` Marco Elver
2026-03-18 8:02 ` [tip: locking/core] " tip-bot2 for Bart Van Assche
2 siblings, 2 replies; 9+ messages in thread
From: Bart Van Assche @ 2026-03-13 17:15 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Ingo Molnar, Will Deacon, Boqun Feng, Waiman Long, linux-kernel,
Marco Elver, Bart Van Assche
Make the spinlock implementation compatible with lock context analysis
(CONTEXT_ANALYSIS := 1) by adding lock context annotations to the
_raw_##op##_...() macros.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
kernel/locking/spinlock.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/kernel/locking/spinlock.c b/kernel/locking/spinlock.c
index 7685defd7c52..b42d293da38b 100644
--- a/kernel/locking/spinlock.c
+++ b/kernel/locking/spinlock.c
@@ -64,8 +64,9 @@ EXPORT_PER_CPU_SYMBOL(__mmiowb_state);
* time (making _this_ CPU preemptible if possible), and we also signal
* towards that other CPU that it should break the lock ASAP.
*/
-#define BUILD_LOCK_OPS(op, locktype) \
+#define BUILD_LOCK_OPS(op, locktype, lock_ctx_op) \
static void __lockfunc __raw_##op##_lock(locktype##_t *lock) \
+ lock_ctx_op(lock) \
{ \
for (;;) { \
preempt_disable(); \
@@ -78,6 +79,7 @@ static void __lockfunc __raw_##op##_lock(locktype##_t *lock) \
} \
\
static unsigned long __lockfunc __raw_##op##_lock_irqsave(locktype##_t *lock) \
+ lock_ctx_op(lock) \
{ \
unsigned long flags; \
\
@@ -96,11 +98,13 @@ static unsigned long __lockfunc __raw_##op##_lock_irqsave(locktype##_t *lock) \
} \
\
static void __lockfunc __raw_##op##_lock_irq(locktype##_t *lock) \
+ lock_ctx_op(lock) \
{ \
_raw_##op##_lock_irqsave(lock); \
} \
\
static void __lockfunc __raw_##op##_lock_bh(locktype##_t *lock) \
+ lock_ctx_op(lock) \
{ \
unsigned long flags; \
\
@@ -123,11 +127,11 @@ static void __lockfunc __raw_##op##_lock_bh(locktype##_t *lock) \
* __[spin|read|write]_lock_irqsave()
* __[spin|read|write]_lock_bh()
*/
-BUILD_LOCK_OPS(spin, raw_spinlock);
+BUILD_LOCK_OPS(spin, raw_spinlock, __acquires);
#ifndef CONFIG_PREEMPT_RT
-BUILD_LOCK_OPS(read, rwlock);
-BUILD_LOCK_OPS(write, rwlock);
+BUILD_LOCK_OPS(read, rwlock, __acquires_shared);
+BUILD_LOCK_OPS(write, rwlock, __acquires);
#endif
#endif
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 3/3] locking: Add lock context annotations in the spinlock implementation
2026-03-13 17:15 ` [PATCH 3/3] locking: Add lock context annotations in the spinlock implementation Bart Van Assche
@ 2026-03-17 13:42 ` Marco Elver
2026-03-18 8:02 ` [tip: locking/core] " tip-bot2 for Bart Van Assche
1 sibling, 0 replies; 9+ messages in thread
From: Marco Elver @ 2026-03-17 13:42 UTC (permalink / raw)
To: Bart Van Assche
Cc: Peter Zijlstra, Ingo Molnar, Will Deacon, Boqun Feng, Waiman Long,
linux-kernel
On Fri, 13 Mar 2026 at 18:15, Bart Van Assche <bvanassche@acm.org> wrote:
>
> Make the spinlock implementation compatible with lock context analysis
> (CONTEXT_ANALYSIS := 1) by adding lock context annotations to the
CONTEXT_ANALYSIS := y
> _raw_##op##_...() macros.
>
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> ---
> kernel/locking/spinlock.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/locking/spinlock.c b/kernel/locking/spinlock.c
> index 7685defd7c52..b42d293da38b 100644
> --- a/kernel/locking/spinlock.c
> +++ b/kernel/locking/spinlock.c
> @@ -64,8 +64,9 @@ EXPORT_PER_CPU_SYMBOL(__mmiowb_state);
> * time (making _this_ CPU preemptible if possible), and we also signal
> * towards that other CPU that it should break the lock ASAP.
> */
> -#define BUILD_LOCK_OPS(op, locktype) \
> +#define BUILD_LOCK_OPS(op, locktype, lock_ctx_op) \
> static void __lockfunc __raw_##op##_lock(locktype##_t *lock) \
> + lock_ctx_op(lock) \
> { \
> for (;;) { \
> preempt_disable(); \
> @@ -78,6 +79,7 @@ static void __lockfunc __raw_##op##_lock(locktype##_t *lock) \
> } \
> \
> static unsigned long __lockfunc __raw_##op##_lock_irqsave(locktype##_t *lock) \
> + lock_ctx_op(lock) \
> { \
> unsigned long flags; \
> \
> @@ -96,11 +98,13 @@ static unsigned long __lockfunc __raw_##op##_lock_irqsave(locktype##_t *lock) \
> } \
> \
> static void __lockfunc __raw_##op##_lock_irq(locktype##_t *lock) \
> + lock_ctx_op(lock) \
> { \
> _raw_##op##_lock_irqsave(lock); \
> } \
> \
> static void __lockfunc __raw_##op##_lock_bh(locktype##_t *lock) \
> + lock_ctx_op(lock) \
> { \
> unsigned long flags; \
> \
> @@ -123,11 +127,11 @@ static void __lockfunc __raw_##op##_lock_bh(locktype##_t *lock) \
> * __[spin|read|write]_lock_irqsave()
> * __[spin|read|write]_lock_bh()
> */
> -BUILD_LOCK_OPS(spin, raw_spinlock);
> +BUILD_LOCK_OPS(spin, raw_spinlock, __acquires);
>
> #ifndef CONFIG_PREEMPT_RT
> -BUILD_LOCK_OPS(read, rwlock);
> -BUILD_LOCK_OPS(write, rwlock);
> +BUILD_LOCK_OPS(read, rwlock, __acquires_shared);
> +BUILD_LOCK_OPS(write, rwlock, __acquires);
> #endif
>
> #endif
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/3] locking: Add lock context support in do_raw_{read,write}_trylock()
2026-03-13 17:15 ` [PATCH 2/3] locking: Add lock context support in do_raw_{read,write}_trylock() Bart Van Assche
@ 2026-03-17 13:49 ` Marco Elver
2026-03-18 8:02 ` [tip: locking/core] " tip-bot2 for Bart Van Assche
1 sibling, 0 replies; 9+ messages in thread
From: Marco Elver @ 2026-03-17 13:49 UTC (permalink / raw)
To: Bart Van Assche
Cc: Peter Zijlstra, Ingo Molnar, Will Deacon, Boqun Feng, Waiman Long,
linux-kernel
On Fri, Mar 13, 2026 at 10:15AM -0700, Bart Van Assche wrote:
> Convert do_raw_{read,write}_trylock() from macros into inline functions
> and annotate these inline functions with __cond_acquires_shared() or
> __cond_acquires() as appropriate. This change is necessary to build
> kernel drivers or subsystems that use rwlock synchronization objects with
> lock context analysis enabled. The return type 'int' matches the return
> type for CONFIG_DEBUG_SPINLOCK=y.
>
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> ---
> include/linux/rwlock.h | 14 ++++++++++++--
> 1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/rwlock.h b/include/linux/rwlock.h
> index 21ceefc4a49f..4e67cd934d8f 100644
> --- a/include/linux/rwlock.h
> +++ b/include/linux/rwlock.h
> @@ -37,10 +37,20 @@ extern int do_raw_write_trylock(rwlock_t *lock) __cond_acquires(true, lock);
> extern void do_raw_write_unlock(rwlock_t *lock) __releases(lock);
> #else
> # define do_raw_read_lock(rwlock) do {__acquire_shared(lock); arch_read_lock(&(rwlock)->raw_lock); } while (0)
> -# define do_raw_read_trylock(rwlock) arch_read_trylock(&(rwlock)->raw_lock)
> +static inline int do_raw_read_trylock(rwlock_t *rwlock)
> + __cond_acquires_shared(true, rwlock)
> + __no_context_analysis
> +{
> + return arch_read_trylock(&(rwlock)->raw_lock);
> +}
> # define do_raw_read_unlock(rwlock) do {arch_read_unlock(&(rwlock)->raw_lock); __release_shared(lock); } while (0)
> # define do_raw_write_lock(rwlock) do {__acquire(lock); arch_write_lock(&(rwlock)->raw_lock); } while (0)
> -# define do_raw_write_trylock(rwlock) arch_write_trylock(&(rwlock)->raw_lock)
> +static inline int do_raw_write_trylock(rwlock_t *rwlock)
> + __cond_acquires(true, rwlock)
> + __no_context_analysis
> +{
> + return arch_write_trylock(&(rwlock)->raw_lock);
> +}
> # define do_raw_write_unlock(rwlock) do {arch_write_unlock(&(rwlock)->raw_lock); __release(lock); } while (0)
> #endif
The pre-existing annotations were wrong (from Sparse era, introduced in
b97c4bc16734a) - I think you need to include this to build with
CONFIG_DEBUG_SPINLOCK=n now:
diff --git a/include/linux/rwlock.h b/include/linux/rwlock.h
index 3d1834ef15d5..9e577e649bf9 100644
--- a/include/linux/rwlock.h
+++ b/include/linux/rwlock.h
@@ -36,22 +36,22 @@ do { \
extern int do_raw_write_trylock(rwlock_t *lock);
extern void do_raw_write_unlock(rwlock_t *lock) __releases(lock);
#else
-# define do_raw_read_lock(rwlock) do {__acquire_shared(lock); arch_read_lock(&(rwlock)->raw_lock); } while (0)
+# define do_raw_read_lock(rwlock) do {__acquire_shared(rwlock); arch_read_lock(&(rwlock)->raw_lock); } while (0)
static inline int do_raw_read_trylock(rwlock_t *rwlock)
__cond_acquires_shared(true, rwlock)
__no_context_analysis
{
return arch_read_trylock(&(rwlock)->raw_lock);
}
-# define do_raw_read_unlock(rwlock) do {arch_read_unlock(&(rwlock)->raw_lock); __release_shared(lock); } while (0)
-# define do_raw_write_lock(rwlock) do {__acquire(lock); arch_write_lock(&(rwlock)->raw_lock); } while (0)
+# define do_raw_read_unlock(rwlock) do {arch_read_unlock(&(rwlock)->raw_lock); __release_shared(rwlock); } while (0)
+# define do_raw_write_lock(rwlock) do {__acquire(rwlock); arch_write_lock(&(rwlock)->raw_lock); } while (0)
static inline int do_raw_write_trylock(rwlock_t *rwlock)
__cond_acquires(true, rwlock)
__no_context_analysis
{
return arch_write_trylock(&(rwlock)->raw_lock);
}
-# define do_raw_write_unlock(rwlock) do {arch_write_unlock(&(rwlock)->raw_lock); __release(lock); } while (0)
+# define do_raw_write_unlock(rwlock) do {arch_write_unlock(&(rwlock)->raw_lock); __release(rwlock); } while (0)
#endif
/*
diff --git a/include/linux/rwlock_api_smp.h b/include/linux/rwlock_api_smp.h
index 61a852609eab..25dfee624cf1 100644
--- a/include/linux/rwlock_api_smp.h
+++ b/include/linux/rwlock_api_smp.h
@@ -116,6 +116,7 @@ _raw_write_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
#endif
static inline int __raw_read_trylock(rwlock_t *lock)
+ __cond_acquires_shared(true, lock)
{
preempt_disable();
if (do_raw_read_trylock(lock)) {
@@ -127,6 +128,7 @@ static inline int __raw_read_trylock(rwlock_t *lock)
}
static inline int __raw_write_trylock(rwlock_t *lock)
+ __cond_acquires(true, lock)
{
preempt_disable();
if (do_raw_write_trylock(lock)) {
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [tip: locking/core] locking: Add lock context annotations in the spinlock implementation
2026-03-13 17:15 ` [PATCH 3/3] locking: Add lock context annotations in the spinlock implementation Bart Van Assche
2026-03-17 13:42 ` Marco Elver
@ 2026-03-18 8:02 ` tip-bot2 for Bart Van Assche
1 sibling, 0 replies; 9+ messages in thread
From: tip-bot2 for Bart Van Assche @ 2026-03-18 8:02 UTC (permalink / raw)
To: linux-tip-commits
Cc: Bart Van Assche, Peter Zijlstra (Intel), x86, linux-kernel
The following commit has been merged into the locking/core branch of tip:
Commit-ID: b06e988c4c52ce8750616ea9b23c8bd3b611b931
Gitweb: https://git.kernel.org/tip/b06e988c4c52ce8750616ea9b23c8bd3b611b931
Author: Bart Van Assche <bvanassche@acm.org>
AuthorDate: Fri, 13 Mar 2026 10:15:09 -07:00
Committer: Peter Zijlstra <peterz@infradead.org>
CommitterDate: Mon, 16 Mar 2026 13:16:50 +01:00
locking: Add lock context annotations in the spinlock implementation
Make the spinlock implementation compatible with lock context analysis
(CONTEXT_ANALYSIS := 1) by adding lock context annotations to the
_raw_##op##_...() macros.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20260313171510.230998-4-bvanassche@acm.org
---
kernel/locking/spinlock.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/kernel/locking/spinlock.c b/kernel/locking/spinlock.c
index 7685def..b42d293 100644
--- a/kernel/locking/spinlock.c
+++ b/kernel/locking/spinlock.c
@@ -64,8 +64,9 @@ EXPORT_PER_CPU_SYMBOL(__mmiowb_state);
* time (making _this_ CPU preemptible if possible), and we also signal
* towards that other CPU that it should break the lock ASAP.
*/
-#define BUILD_LOCK_OPS(op, locktype) \
+#define BUILD_LOCK_OPS(op, locktype, lock_ctx_op) \
static void __lockfunc __raw_##op##_lock(locktype##_t *lock) \
+ lock_ctx_op(lock) \
{ \
for (;;) { \
preempt_disable(); \
@@ -78,6 +79,7 @@ static void __lockfunc __raw_##op##_lock(locktype##_t *lock) \
} \
\
static unsigned long __lockfunc __raw_##op##_lock_irqsave(locktype##_t *lock) \
+ lock_ctx_op(lock) \
{ \
unsigned long flags; \
\
@@ -96,11 +98,13 @@ static unsigned long __lockfunc __raw_##op##_lock_irqsave(locktype##_t *lock) \
} \
\
static void __lockfunc __raw_##op##_lock_irq(locktype##_t *lock) \
+ lock_ctx_op(lock) \
{ \
_raw_##op##_lock_irqsave(lock); \
} \
\
static void __lockfunc __raw_##op##_lock_bh(locktype##_t *lock) \
+ lock_ctx_op(lock) \
{ \
unsigned long flags; \
\
@@ -123,11 +127,11 @@ static void __lockfunc __raw_##op##_lock_bh(locktype##_t *lock) \
* __[spin|read|write]_lock_irqsave()
* __[spin|read|write]_lock_bh()
*/
-BUILD_LOCK_OPS(spin, raw_spinlock);
+BUILD_LOCK_OPS(spin, raw_spinlock, __acquires);
#ifndef CONFIG_PREEMPT_RT
-BUILD_LOCK_OPS(read, rwlock);
-BUILD_LOCK_OPS(write, rwlock);
+BUILD_LOCK_OPS(read, rwlock, __acquires_shared);
+BUILD_LOCK_OPS(write, rwlock, __acquires);
#endif
#endif
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [tip: locking/core] locking: Add lock context support in do_raw_{read,write}_trylock()
2026-03-13 17:15 ` [PATCH 2/3] locking: Add lock context support in do_raw_{read,write}_trylock() Bart Van Assche
2026-03-17 13:49 ` Marco Elver
@ 2026-03-18 8:02 ` tip-bot2 for Bart Van Assche
1 sibling, 0 replies; 9+ messages in thread
From: tip-bot2 for Bart Van Assche @ 2026-03-18 8:02 UTC (permalink / raw)
To: linux-tip-commits
Cc: Bart Van Assche, Peter Zijlstra (Intel), x86, linux-kernel
The following commit has been merged into the locking/core branch of tip:
Commit-ID: c4d3b8c77d85082d32250c505beb1d9e46ee47ee
Gitweb: https://git.kernel.org/tip/c4d3b8c77d85082d32250c505beb1d9e46ee47ee
Author: Bart Van Assche <bvanassche@acm.org>
AuthorDate: Fri, 13 Mar 2026 10:15:08 -07:00
Committer: Peter Zijlstra <peterz@infradead.org>
CommitterDate: Mon, 16 Mar 2026 13:16:50 +01:00
locking: Add lock context support in do_raw_{read,write}_trylock()
Convert do_raw_{read,write}_trylock() from macros into inline functions
and annotate these inline functions with __cond_acquires_shared() or
__cond_acquires() as appropriate. This change is necessary to build
kernel drivers or subsystems that use rwlock synchronization objects with
lock context analysis enabled. The return type 'int' matches the return
type for CONFIG_DEBUG_SPINLOCK=y.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20260313171510.230998-3-bvanassche@acm.org
---
include/linux/rwlock.h | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/include/linux/rwlock.h b/include/linux/rwlock.h
index 21ceefc..4e67cd9 100644
--- a/include/linux/rwlock.h
+++ b/include/linux/rwlock.h
@@ -37,10 +37,20 @@ extern int do_raw_write_trylock(rwlock_t *lock) __cond_acquires(true, lock);
extern void do_raw_write_unlock(rwlock_t *lock) __releases(lock);
#else
# define do_raw_read_lock(rwlock) do {__acquire_shared(lock); arch_read_lock(&(rwlock)->raw_lock); } while (0)
-# define do_raw_read_trylock(rwlock) arch_read_trylock(&(rwlock)->raw_lock)
+static inline int do_raw_read_trylock(rwlock_t *rwlock)
+ __cond_acquires_shared(true, rwlock)
+ __no_context_analysis
+{
+ return arch_read_trylock(&(rwlock)->raw_lock);
+}
# define do_raw_read_unlock(rwlock) do {arch_read_unlock(&(rwlock)->raw_lock); __release_shared(lock); } while (0)
# define do_raw_write_lock(rwlock) do {__acquire(lock); arch_write_lock(&(rwlock)->raw_lock); } while (0)
-# define do_raw_write_trylock(rwlock) arch_write_trylock(&(rwlock)->raw_lock)
+static inline int do_raw_write_trylock(rwlock_t *rwlock)
+ __cond_acquires(true, rwlock)
+ __no_context_analysis
+{
+ return arch_write_trylock(&(rwlock)->raw_lock);
+}
# define do_raw_write_unlock(rwlock) do {arch_write_unlock(&(rwlock)->raw_lock); __release(lock); } while (0)
#endif
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [tip: locking/core] locking: Fix rwlock support in <linux/spinlock_up.h>
2026-03-13 17:15 ` [PATCH 1/3] locking: Fix rwlock support in <linux/spinlock_up.h> Bart Van Assche
@ 2026-03-18 8:02 ` tip-bot2 for Bart Van Assche
0 siblings, 0 replies; 9+ messages in thread
From: tip-bot2 for Bart Van Assche @ 2026-03-18 8:02 UTC (permalink / raw)
To: linux-tip-commits
Cc: Bart Van Assche, Peter Zijlstra (Intel), x86, linux-kernel
The following commit has been merged into the locking/core branch of tip:
Commit-ID: 756a0e011cfca0b45a48464aa25b05d9a9c2fb0b
Gitweb: https://git.kernel.org/tip/756a0e011cfca0b45a48464aa25b05d9a9c2fb0b
Author: Bart Van Assche <bvanassche@acm.org>
AuthorDate: Fri, 13 Mar 2026 10:15:07 -07:00
Committer: Peter Zijlstra <peterz@infradead.org>
CommitterDate: Mon, 16 Mar 2026 13:16:50 +01:00
locking: Fix rwlock support in <linux/spinlock_up.h>
Architecture support for rwlocks must be available whether or not
CONFIG_DEBUG_SPINLOCK has been defined. Move the definitions of the
arch_{read,write}_{lock,trylock,unlock}() macros such that these become
visbile if CONFIG_DEBUG_SPINLOCK=n.
This patch prepares for converting do_raw_{read,write}_trylock() into
inline functions. Without this patch that conversion triggers a build
failure for UP architectures, e.g. arm-ep93xx. I used the following
kernel configuration to build the kernel for that architecture:
CONFIG_ARCH_MULTIPLATFORM=y
CONFIG_ARCH_MULTI_V7=n
CONFIG_ATAGS=y
CONFIG_MMU=y
CONFIG_ARCH_MULTI_V4T=y
CONFIG_CPU_LITTLE_ENDIAN=y
CONFIG_ARCH_EP93XX=y
Fixes: fb1c8f93d869 ("[PATCH] spinlock consolidation")
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20260313171510.230998-2-bvanassche@acm.org
---
include/linux/spinlock_up.h | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/include/linux/spinlock_up.h b/include/linux/spinlock_up.h
index 1e84e71..3a50976 100644
--- a/include/linux/spinlock_up.h
+++ b/include/linux/spinlock_up.h
@@ -48,16 +48,6 @@ static inline void arch_spin_unlock(arch_spinlock_t *lock)
lock->slock = 1;
}
-/*
- * Read-write spinlocks. No debug version.
- */
-#define arch_read_lock(lock) do { barrier(); (void)(lock); } while (0)
-#define arch_write_lock(lock) do { barrier(); (void)(lock); } while (0)
-#define arch_read_trylock(lock) ({ barrier(); (void)(lock); 1; })
-#define arch_write_trylock(lock) ({ barrier(); (void)(lock); 1; })
-#define arch_read_unlock(lock) do { barrier(); (void)(lock); } while (0)
-#define arch_write_unlock(lock) do { barrier(); (void)(lock); } while (0)
-
#else /* DEBUG_SPINLOCK */
#define arch_spin_is_locked(lock) ((void)(lock), 0)
/* for sched/core.c and kernel_lock.c: */
@@ -68,4 +58,14 @@ static inline void arch_spin_unlock(arch_spinlock_t *lock)
#define arch_spin_is_contended(lock) (((void)(lock), 0))
+/*
+ * Read-write spinlocks. No debug version.
+ */
+#define arch_read_lock(lock) do { barrier(); (void)(lock); } while (0)
+#define arch_write_lock(lock) do { barrier(); (void)(lock); } while (0)
+#define arch_read_trylock(lock) ({ barrier(); (void)(lock); 1; })
+#define arch_write_trylock(lock) ({ barrier(); (void)(lock); 1; })
+#define arch_read_unlock(lock) do { barrier(); (void)(lock); } while (0)
+#define arch_write_unlock(lock) do { barrier(); (void)(lock); } while (0)
+
#endif /* __LINUX_SPINLOCK_UP_H */
^ permalink raw reply related [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-03-18 8:02 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-13 17:15 [PATCH 0/3] More lock context annotation fixes Bart Van Assche
2026-03-13 17:15 ` [PATCH 1/3] locking: Fix rwlock support in <linux/spinlock_up.h> Bart Van Assche
2026-03-18 8:02 ` [tip: locking/core] " tip-bot2 for Bart Van Assche
2026-03-13 17:15 ` [PATCH 2/3] locking: Add lock context support in do_raw_{read,write}_trylock() Bart Van Assche
2026-03-17 13:49 ` Marco Elver
2026-03-18 8:02 ` [tip: locking/core] " tip-bot2 for Bart Van Assche
2026-03-13 17:15 ` [PATCH 3/3] locking: Add lock context annotations in the spinlock implementation Bart Van Assche
2026-03-17 13:42 ` Marco Elver
2026-03-18 8:02 ` [tip: locking/core] " tip-bot2 for Bart Van Assche
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox