Skip to content

Commit 3b4ba66

Browse files
Waiman-Longingomolnar
authored andcommitted
locking/rwsem: Enhance DEBUG_RWSEMS_WARN_ON() macro
Currently, the DEBUG_RWSEMS_WARN_ON() macro just dumps a stack trace when the rwsem isn't in the right state. It does not show the actual states of the rwsem. This may not be that helpful in the debugging process. Enhance the DEBUG_RWSEMS_WARN_ON() macro to also show the current content of the rwsem count and owner fields to give more information about what is wrong with the rwsem. The debug_locks_off() function is called as is done inside DEBUG_LOCKS_WARN_ON(). Signed-off-by: Waiman Long <longman@redhat.com> Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Acked-by: Davidlohr Bueso <dbueso@suse.de> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Borislav Petkov <bp@alien8.de> Cc: Davidlohr Bueso <dave@stgolabs.net> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Tim Chen <tim.c.chen@linux.intel.com> Cc: Will Deacon <will.deacon@arm.com> Link: http://lkml.kernel.org/r/20190404174320.22416-7-longman@redhat.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent a68e2c4 commit 3b4ba66

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

‎kernel/locking/rwsem.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ EXPORT_SYMBOL(down_write_killable_nested);
198198

199199
void up_read_non_owner(struct rw_semaphore *sem)
200200
{
201-
DEBUG_RWSEMS_WARN_ON(!((unsigned long)sem->owner & RWSEM_READER_OWNED));
201+
DEBUG_RWSEMS_WARN_ON(!((unsigned long)sem->owner & RWSEM_READER_OWNED),
202+
sem);
202203
__up_read(sem);
203204
}
204205

‎kernel/locking/rwsem.h‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,15 @@
2727
#define RWSEM_ANONYMOUSLY_OWNED (1UL << 1)
2828

2929
#ifdef CONFIG_DEBUG_RWSEMS
30-
# define DEBUG_RWSEMS_WARN_ON(c) DEBUG_LOCKS_WARN_ON(c)
30+
# define DEBUG_RWSEMS_WARN_ON(c, sem) do { \
31+
if (WARN_ONCE(c, "DEBUG_RWSEMS_WARN_ON(%s): count = 0x%lx, owner = 0x%lx, curr 0x%lx, list %sempty\n",\
32+
#c, atomic_long_read(&(sem)->count), \
33+
(long)((sem)->owner), (long)current, \
34+
list_empty(&(sem)->wait_list) ? "" : "not ")) \
35+
debug_locks_off(); \
36+
} while (0)
3137
#else
32-
# define DEBUG_RWSEMS_WARN_ON(c)
38+
# define DEBUG_RWSEMS_WARN_ON(c, sem)
3339
#endif
3440

3541
/*
@@ -168,7 +174,7 @@ static inline void __down_read(struct rw_semaphore *sem)
168174
if (unlikely(atomic_long_inc_return_acquire(&sem->count) <= 0)) {
169175
rwsem_down_read_failed(sem);
170176
DEBUG_RWSEMS_WARN_ON(!((unsigned long)sem->owner &
171-
RWSEM_READER_OWNED));
177+
RWSEM_READER_OWNED), sem);
172178
} else {
173179
rwsem_set_reader_owned(sem);
174180
}
@@ -180,7 +186,7 @@ static inline int __down_read_killable(struct rw_semaphore *sem)
180186
if (IS_ERR(rwsem_down_read_failed_killable(sem)))
181187
return -EINTR;
182188
DEBUG_RWSEMS_WARN_ON(!((unsigned long)sem->owner &
183-
RWSEM_READER_OWNED));
189+
RWSEM_READER_OWNED), sem);
184190
} else {
185191
rwsem_set_reader_owned(sem);
186192
}
@@ -251,7 +257,8 @@ static inline void __up_read(struct rw_semaphore *sem)
251257
{
252258
long tmp;
253259

254-
DEBUG_RWSEMS_WARN_ON(!((unsigned long)sem->owner & RWSEM_READER_OWNED));
260+
DEBUG_RWSEMS_WARN_ON(!((unsigned long)sem->owner & RWSEM_READER_OWNED),
261+
sem);
255262
rwsem_clear_reader_owned(sem);
256263
tmp = atomic_long_dec_return_release(&sem->count);
257264
if (unlikely(tmp < -1 && (tmp & RWSEM_ACTIVE_MASK) == 0))
@@ -263,7 +270,7 @@ static inline void __up_read(struct rw_semaphore *sem)
263270
*/
264271
static inline void __up_write(struct rw_semaphore *sem)
265272
{
266-
DEBUG_RWSEMS_WARN_ON(sem->owner != current);
273+
DEBUG_RWSEMS_WARN_ON(sem->owner != current, sem);
267274
rwsem_clear_owner(sem);
268275
if (unlikely(atomic_long_sub_return_release(RWSEM_ACTIVE_WRITE_BIAS,
269276
&sem->count) < 0))
@@ -284,7 +291,7 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
284291
* read-locked region is ok to be re-ordered into the
285292
* write side. As such, rely on RELEASE semantics.
286293
*/
287-
DEBUG_RWSEMS_WARN_ON(sem->owner != current);
294+
DEBUG_RWSEMS_WARN_ON(sem->owner != current, sem);
288295
tmp = atomic_long_add_return_release(-RWSEM_WAITING_BIAS, &sem->count);
289296
rwsem_set_reader_owned(sem);
290297
if (tmp < 0)

0 commit comments

Comments
 (0)