[tip: locking/core] locking: Fix rwlock and spinlock lock context annotations

tip-bot2 for Bart Van Assche posted 1 patch 1 month, 2 weeks ago
include/linux/rwlock.h         | 4 ++--
include/linux/rwlock_api_smp.h | 6 ++++--
include/linux/spinlock.h       | 3 ++-
3 files changed, 8 insertions(+), 5 deletions(-)
[tip: locking/core] locking: Fix rwlock and spinlock lock context annotations
Posted by tip-bot2 for Bart Van Assche 1 month, 2 weeks ago
The following commit has been merged into the locking/core branch of tip:

Commit-ID:     38e18d825f7281fdc16d3241df5115ce6eaeaf79
Gitweb:        https://git.kernel.org/tip/38e18d825f7281fdc16d3241df5115ce6eaeaf79
Author:        Bart Van Assche <bvanassche@acm.org>
AuthorDate:    Wed, 25 Feb 2026 10:32:41 -08:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Fri, 27 Feb 2026 16:40:19 +01:00

locking: Fix rwlock and spinlock lock context annotations

Fix two incorrect rwlock_t lock context annotations. Add the raw_spinlock_t
lock context annotations that are missing.

Fixes: f16a802d402d ("locking/rwlock, spinlock: Support Clang's context analysis")
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Marco Elver <elver@google.com>
Link: https://patch.msgid.link/20260225183244.4035378-2-bvanassche@acm.org
---
 include/linux/rwlock.h         | 4 ++--
 include/linux/rwlock_api_smp.h | 6 ++++--
 include/linux/spinlock.h       | 3 ++-
 3 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/include/linux/rwlock.h b/include/linux/rwlock.h
index 3390d21..21ceefc 100644
--- a/include/linux/rwlock.h
+++ b/include/linux/rwlock.h
@@ -30,10 +30,10 @@ do {								\
 
 #ifdef CONFIG_DEBUG_SPINLOCK
  extern void do_raw_read_lock(rwlock_t *lock) __acquires_shared(lock);
- extern int do_raw_read_trylock(rwlock_t *lock);
+ extern int do_raw_read_trylock(rwlock_t *lock) __cond_acquires_shared(true, lock);
  extern void do_raw_read_unlock(rwlock_t *lock) __releases_shared(lock);
  extern void do_raw_write_lock(rwlock_t *lock) __acquires(lock);
- extern int do_raw_write_trylock(rwlock_t *lock);
+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)
diff --git a/include/linux/rwlock_api_smp.h b/include/linux/rwlock_api_smp.h
index 61a8526..9e02a5f 100644
--- a/include/linux/rwlock_api_smp.h
+++ b/include/linux/rwlock_api_smp.h
@@ -23,7 +23,7 @@ void __lockfunc _raw_write_lock_bh(rwlock_t *lock)	__acquires(lock);
 void __lockfunc _raw_read_lock_irq(rwlock_t *lock)	__acquires_shared(lock);
 void __lockfunc _raw_write_lock_irq(rwlock_t *lock)	__acquires(lock);
 unsigned long __lockfunc _raw_read_lock_irqsave(rwlock_t *lock)
-							__acquires(lock);
+							__acquires_shared(lock);
 unsigned long __lockfunc _raw_write_lock_irqsave(rwlock_t *lock)
 							__acquires(lock);
 int __lockfunc _raw_read_trylock(rwlock_t *lock)	__cond_acquires_shared(true, lock);
@@ -36,7 +36,7 @@ void __lockfunc _raw_read_unlock_irq(rwlock_t *lock)	__releases_shared(lock);
 void __lockfunc _raw_write_unlock_irq(rwlock_t *lock)	__releases(lock);
 void __lockfunc
 _raw_read_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
-							__releases(lock);
+							__releases_shared(lock);
 void __lockfunc
 _raw_write_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
 							__releases(lock);
@@ -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)) {
diff --git a/include/linux/spinlock.h b/include/linux/spinlock.h
index e1e2f14..241277c 100644
--- a/include/linux/spinlock.h
+++ b/include/linux/spinlock.h
@@ -178,7 +178,7 @@ do {									\
 
 #ifdef CONFIG_DEBUG_SPINLOCK
  extern void do_raw_spin_lock(raw_spinlock_t *lock) __acquires(lock);
- extern int do_raw_spin_trylock(raw_spinlock_t *lock);
+ extern int do_raw_spin_trylock(raw_spinlock_t *lock) __cond_acquires(true, lock);
  extern void do_raw_spin_unlock(raw_spinlock_t *lock) __releases(lock);
 #else
 static inline void do_raw_spin_lock(raw_spinlock_t *lock) __acquires(lock)
@@ -189,6 +189,7 @@ static inline void do_raw_spin_lock(raw_spinlock_t *lock) __acquires(lock)
 }
 
 static inline int do_raw_spin_trylock(raw_spinlock_t *lock)
+	__cond_acquires(true, lock)
 {
 	int ret = arch_spin_trylock(&(lock)->raw_lock);
 
Re: [tip: locking/core] locking: Fix rwlock and spinlock lock context annotations
Posted by Bart Van Assche 1 month ago
On 2/28/26 2:56 AM, tip-bot2 for Bart Van Assche wrote:
> The following commit has been merged into the locking/core branch of tip:
> 
> Commit-ID:     38e18d825f7281fdc16d3241df5115ce6eaeaf79
> Gitweb:        https://git.kernel.org/tip/38e18d825f7281fdc16d3241df5115ce6eaeaf79
> Author:        Bart Van Assche <bvanassche@acm.org>
> AuthorDate:    Wed, 25 Feb 2026 10:32:41 -08:00
> Committer:     Peter Zijlstra <peterz@infradead.org>
> CommitterDate: Fri, 27 Feb 2026 16:40:19 +01:00
> 
> locking: Fix rwlock and spinlock lock context annotations

Hi Peter,

Thank you for having queued this patch.

Since some of my other patches depend on this patch, will this patch be
sent to Linus during the current rc cycle? I'm asking this because I
can't find this patch in Linus' master branch:

$ git fetch origin
$ git log --reverse --format=oneline v6.19..origin/master 
include/linux/rwlock_api_smp.h
f16a802d402d735a55731f8c94952b3bbb5ddfe8 locking/rwlock, spinlock: 
Support Clang's context analysis
e4588c25c9d122b5847b88e18b184404b6959160 compiler-context-analysis: 
Remove __cond_lock() function-like helper
7a562d5d2396c9c78fbbced7ae81bcfcfa0fde3f (tag: locking-core-2026-02-08) 
locking/rwlock: Fix write_trylock_irqsave() with CONFIG_INLINE_WRITE_TRYLOCK

Thanks,

Bart.