* [PATCH 0/2] locking/rwlock: Fix non-debug lock context annotations
@ 2026-12-04 21:58 Bart Van Assche
2026-12-04 21:58 ` [PATCH 1/2] locking/rwlock: Pass rwlock to __acquire*() and __release*() Bart Van Assche
2026-12-04 21:58 ` [PATCH 2/2] locking/rwlock: Report lock acquisition in non-debug do_raw_*_trylock() Bart Van Assche
0 siblings, 2 replies; 3+ messages in thread
From: Bart Van Assche @ 2026-12-04 21:58 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Ingo Molnar, Will Deacon, Boqun Feng, Waiman Long, linux-kernel,
Marco Elver, Christoph Hellwig, Bart Van Assche
Hi Peter and Marco,
This patch series fixes two issues in the lock context annotations of
the !CONFIG_DEBUG_SPINLOCK definitions of the rwlock primitives in
<linux/rwlock.h>:
- do_raw_{read,write}_lock() and do_raw_{read,write}_unlock() pass the
hardcoded identifier lock instead of the macro parameter rwlock to
__acquire*() and __release*().
- do_raw_{read,write}_trylock() use __no_context_analysis instead of
reporting lock acquisition explicitly, as do_raw_spin_trylock() does.
These patches have been build-tested with Clang 24 for x86_64 with
CONFIG_WARN_CONTEXT_ANALYSIS=y, both with and without CONFIG_PREEMPT_RT.
Please consider these patches for the next merge window.
Thank you,
Bart.
Bart Van Assche (2):
locking/rwlock: Pass rwlock to __acquire*() and __release*()
locking/rwlock: Report lock acquisition in non-debug
do_raw_*_trylock()
include/linux/rwlock.h | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH 1/2] locking/rwlock: Pass rwlock to __acquire*() and __release*()
2026-12-04 21:58 [PATCH 0/2] locking/rwlock: Fix non-debug lock context annotations Bart Van Assche
@ 2026-12-04 21:58 ` Bart Van Assche
2026-12-04 21:58 ` [PATCH 2/2] locking/rwlock: Report lock acquisition in non-debug do_raw_*_trylock() Bart Van Assche
1 sibling, 0 replies; 3+ messages in thread
From: Bart Van Assche @ 2026-12-04 21:58 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Ingo Molnar, Will Deacon, Boqun Feng, Waiman Long, linux-kernel,
Marco Elver, Christoph Hellwig, Bart Van Assche, Luca Barbieri,
Thomas Gleixner, Andrew Morton
The !CONFIG_DEBUG_SPINLOCK definitions of do_raw_read_lock(),
do_raw_read_unlock(), do_raw_write_lock(), and do_raw_write_unlock() in
include/linux/rwlock.h pass the hardcoded identifier lock instead of the
macro parameter rwlock to __acquire*() and __release*(). This compiles
only by coincidence when callers name their local rwlock_t pointer lock.
Pass the macro parameter rwlock instead.
Fixes: b97c4bc16734 ("locking: Make sparse work with inline spinlocks and rwlocks")
Fixes: f16a802d402d ("locking/rwlock, spinlock: Support Clang's context analysis")
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
include/linux/rwlock.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/include/linux/rwlock.h b/include/linux/rwlock.h
index 4e67cd934d8f..396eb022bbd1 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) __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_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
/*
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH 2/2] locking/rwlock: Report lock acquisition in non-debug do_raw_*_trylock()
2026-12-04 21:58 [PATCH 0/2] locking/rwlock: Fix non-debug lock context annotations Bart Van Assche
2026-12-04 21:58 ` [PATCH 1/2] locking/rwlock: Pass rwlock to __acquire*() and __release*() Bart Van Assche
@ 2026-12-04 21:58 ` Bart Van Assche
1 sibling, 0 replies; 3+ messages in thread
From: Bart Van Assche @ 2026-12-04 21:58 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Ingo Molnar, Will Deacon, Boqun Feng, Waiman Long, linux-kernel,
Marco Elver, Christoph Hellwig, Bart Van Assche
Report lock acquisition explicitly in the !CONFIG_DEBUG_SPINLOCK
definitions of do_raw_{read,write}_trylock() instead of using
__no_context_analysis. This allows the compiler to verify that the
function bodies match their __cond_acquires*() annotations and matches
do_raw_spin_trylock() in include/linux/spinlock.h.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
include/linux/rwlock.h | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/include/linux/rwlock.h b/include/linux/rwlock.h
index 396eb022bbd1..beae43c4655c 100644
--- a/include/linux/rwlock.h
+++ b/include/linux/rwlock.h
@@ -39,17 +39,25 @@ extern int do_raw_write_trylock(rwlock_t *lock) __cond_acquires(true, lock);
# 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);
+ int ret = arch_read_trylock(&(rwlock)->raw_lock);
+
+ if (ret)
+ __acquire_shared(rwlock);
+
+ return ret;
}
# 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);
+ int ret = arch_write_trylock(&(rwlock)->raw_lock);
+
+ if (ret)
+ __acquire(rwlock);
+
+ return ret;
}
# define do_raw_write_unlock(rwlock) do {arch_write_unlock(&(rwlock)->raw_lock); __release(rwlock); } while (0)
#endif
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-04 21:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 21:58 [PATCH 0/2] locking/rwlock: Fix non-debug lock context annotations Bart Van Assche
2026-12-04 21:58 ` [PATCH 1/2] locking/rwlock: Pass rwlock to __acquire*() and __release*() Bart Van Assche
2026-12-04 21:58 ` [PATCH 2/2] locking/rwlock: Report lock acquisition in non-debug do_raw_*_trylock() 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