Skip to content

Commit 51731e8

Browse files
bvanasschegregkh
authored andcommitted
locking: Fix rwlock and spinlock lock context annotations
[ Upstream commit 38e18d8 ] Fix two incorrect rwlock_t lock context annotations. Add the raw_spinlock_t lock context annotations that are missing. Fixes: f16a802 ("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 Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 74fe390 commit 51731e8

3 files changed

Lines changed: 8 additions & 5 deletions

File tree

include/linux/rwlock.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ do { \
3030

3131
#ifdef CONFIG_DEBUG_SPINLOCK
3232
extern void do_raw_read_lock(rwlock_t *lock) __acquires_shared(lock);
33-
extern int do_raw_read_trylock(rwlock_t *lock);
33+
extern int do_raw_read_trylock(rwlock_t *lock) __cond_acquires_shared(true, lock);
3434
extern void do_raw_read_unlock(rwlock_t *lock) __releases_shared(lock);
3535
extern void do_raw_write_lock(rwlock_t *lock) __acquires(lock);
36-
extern int do_raw_write_trylock(rwlock_t *lock);
36+
extern int do_raw_write_trylock(rwlock_t *lock) __cond_acquires(true, lock);
3737
extern void do_raw_write_unlock(rwlock_t *lock) __releases(lock);
3838
#else
3939
# define do_raw_read_lock(rwlock) do {__acquire_shared(lock); arch_read_lock(&(rwlock)->raw_lock); } while (0)

include/linux/rwlock_api_smp.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void __lockfunc _raw_write_lock_bh(rwlock_t *lock) __acquires(lock);
2323
void __lockfunc _raw_read_lock_irq(rwlock_t *lock) __acquires_shared(lock);
2424
void __lockfunc _raw_write_lock_irq(rwlock_t *lock) __acquires(lock);
2525
unsigned long __lockfunc _raw_read_lock_irqsave(rwlock_t *lock)
26-
__acquires(lock);
26+
__acquires_shared(lock);
2727
unsigned long __lockfunc _raw_write_lock_irqsave(rwlock_t *lock)
2828
__acquires(lock);
2929
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);
3636
void __lockfunc _raw_write_unlock_irq(rwlock_t *lock) __releases(lock);
3737
void __lockfunc
3838
_raw_read_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
39-
__releases(lock);
39+
__releases_shared(lock);
4040
void __lockfunc
4141
_raw_write_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
4242
__releases(lock);
@@ -116,6 +116,7 @@ _raw_write_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
116116
#endif
117117

118118
static inline int __raw_read_trylock(rwlock_t *lock)
119+
__cond_acquires_shared(true, lock)
119120
{
120121
preempt_disable();
121122
if (do_raw_read_trylock(lock)) {
@@ -127,6 +128,7 @@ static inline int __raw_read_trylock(rwlock_t *lock)
127128
}
128129

129130
static inline int __raw_write_trylock(rwlock_t *lock)
131+
__cond_acquires(true, lock)
130132
{
131133
preempt_disable();
132134
if (do_raw_write_trylock(lock)) {

include/linux/spinlock.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ do { \
178178

179179
#ifdef CONFIG_DEBUG_SPINLOCK
180180
extern void do_raw_spin_lock(raw_spinlock_t *lock) __acquires(lock);
181-
extern int do_raw_spin_trylock(raw_spinlock_t *lock);
181+
extern int do_raw_spin_trylock(raw_spinlock_t *lock) __cond_acquires(true, lock);
182182
extern void do_raw_spin_unlock(raw_spinlock_t *lock) __releases(lock);
183183
#else
184184
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)
189189
}
190190

191191
static inline int do_raw_spin_trylock(raw_spinlock_t *lock)
192+
__cond_acquires(true, lock)
192193
{
193194
int ret = arch_spin_trylock(&(lock)->raw_lock);
194195

0 commit comments

Comments
 (0)