Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

lockdep/lib/tests: Test dynamic key registration

Make sure that the lockdep_register_key() and lockdep_unregister_key()
code is tested when running the lockdep tests.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Johannes Berg <johannes@sipsolutions.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: Waiman Long <longman@redhat.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: johannes.berg@intel.com
Cc: tj@kernel.org
Link: https://lkml.kernel.org/r/20190214230058.196511-24-bvanassche@acm.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Bart Van Assche and committed by
Ingo Molnar
f214737b d93ac78b

+17 -5
+2
tools/lib/lockdep/include/liblockdep/common.h
··· 45 45 void lock_release(struct lockdep_map *lock, int nested, 46 46 unsigned long ip); 47 47 void lockdep_reset_lock(struct lockdep_map *lock); 48 + void lockdep_register_key(struct lock_class_key *key); 49 + void lockdep_unregister_key(struct lock_class_key *key); 48 50 extern void debug_check_no_locks_freed(const void *from, unsigned long len); 49 51 50 52 #define STATIC_LOCKDEP_MAP_INIT(_name, _key) \
+6 -5
tools/lib/lockdep/include/liblockdep/mutex.h
··· 7 7 8 8 struct liblockdep_pthread_mutex { 9 9 pthread_mutex_t mutex; 10 + struct lock_class_key key; 10 11 struct lockdep_map dep_map; 11 12 }; 12 13 ··· 28 27 return pthread_mutex_init(&lock->mutex, __mutexattr); 29 28 } 30 29 31 - #define liblockdep_pthread_mutex_init(mutex, mutexattr) \ 32 - ({ \ 33 - static struct lock_class_key __key; \ 34 - \ 35 - __mutex_init((mutex), #mutex, &__key, (mutexattr)); \ 30 + #define liblockdep_pthread_mutex_init(mutex, mutexattr) \ 31 + ({ \ 32 + lockdep_register_key(&(mutex)->key); \ 33 + __mutex_init((mutex), #mutex, &(mutex)->key, (mutexattr)); \ 36 34 }) 37 35 38 36 static inline int liblockdep_pthread_mutex_lock(liblockdep_pthread_mutex_t *lock) ··· 55 55 static inline int liblockdep_pthread_mutex_destroy(liblockdep_pthread_mutex_t *lock) 56 56 { 57 57 lockdep_reset_lock(&lock->dep_map); 58 + lockdep_unregister_key(&lock->key); 58 59 return pthread_mutex_destroy(&lock->mutex); 59 60 } 60 61
+9
tools/lib/lockdep/tests/ABBA.c
··· 14 14 15 15 pthread_mutex_destroy(&b); 16 16 pthread_mutex_destroy(&a); 17 + 18 + pthread_mutex_init(&a, NULL); 19 + pthread_mutex_init(&b, NULL); 20 + 21 + LOCK_UNLOCK_2(a, b); 22 + LOCK_UNLOCK_2(b, a); 23 + 24 + pthread_mutex_destroy(&b); 25 + pthread_mutex_destroy(&a); 17 26 }