Skip to content

Commit 4bf5086

Browse files
bvanasscheIngo Molnar
authored andcommitted
locking/lockdep: Verify whether lock objects are small enough to be used as class keys
Signed-off-by: Bart Van Assche <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Johannes Berg <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Paul E. McKenney <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Waiman Long <[email protected]> Cc: Will Deacon <[email protected]> Cc: [email protected] Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent b526b2e commit 4bf5086

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

kernel/locking/lockdep.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,17 @@ static bool assign_lock_key(struct lockdep_map *lock)
758758
{
759759
unsigned long can_addr, addr = (unsigned long)lock;
760760

761+
#ifdef __KERNEL__
762+
/*
763+
* lockdep_free_key_range() assumes that struct lock_class_key
764+
* objects do not overlap. Since we use the address of lock
765+
* objects as class key for static objects, check whether the
766+
* size of lock_class_key objects does not exceed the size of
767+
* the smallest lock object.
768+
*/
769+
BUILD_BUG_ON(sizeof(struct lock_class_key) > sizeof(raw_spinlock_t));
770+
#endif
771+
761772
if (__is_kernel_percpu_address(addr, &can_addr))
762773
lock->key = (void *)can_addr;
763774
else if (__is_module_percpu_address(addr, &can_addr))

0 commit comments

Comments
 (0)