[PATCH v3 21/24] locking/lockdep: Verify whether lock objects are small enough to be used as class keys
Cc: Peter Zijlstra Cc: Waiman Long Cc: Johannes Berg Signed-off-by: Bart Van Assche --- kernel/locking/lockdep.c | 9 + 1 file changed, 9 insertions(+) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index 8c69516b1283..a47357d3dca7 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -727,6 +727,15 @@ static bool assign_lock_key(struct lockdep_map *lock) { unsigned long can_addr, addr = (unsigned long)lock; + /* +* lockdep_free_key_range() assumes that struct lock_class_key +* objects do not overlap. Since we use the address of lock +* objects as class key for static objects, check whether the +* size of lock_class_key objects does not exceed the size of +* the smallest lock object. +*/ + BUILD_BUG_ON(sizeof(struct lock_class_key) > sizeof(raw_spinlock_t)); + if (__is_kernel_percpu_address(addr, _addr)) lock->key = (void *)can_addr; else if (__is_module_percpu_address(addr, _addr)) -- 2.20.0.rc2.403.gdbc3b29805-goog
[PATCH v3 21/24] locking/lockdep: Verify whether lock objects are small enough to be used as class keys
Cc: Peter Zijlstra Cc: Waiman Long Cc: Johannes Berg Signed-off-by: Bart Van Assche --- kernel/locking/lockdep.c | 9 + 1 file changed, 9 insertions(+) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index 8c69516b1283..a47357d3dca7 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -727,6 +727,15 @@ static bool assign_lock_key(struct lockdep_map *lock) { unsigned long can_addr, addr = (unsigned long)lock; + /* +* lockdep_free_key_range() assumes that struct lock_class_key +* objects do not overlap. Since we use the address of lock +* objects as class key for static objects, check whether the +* size of lock_class_key objects does not exceed the size of +* the smallest lock object. +*/ + BUILD_BUG_ON(sizeof(struct lock_class_key) > sizeof(raw_spinlock_t)); + if (__is_kernel_percpu_address(addr, _addr)) lock->key = (void *)can_addr; else if (__is_module_percpu_address(addr, _addr)) -- 2.20.0.rc2.403.gdbc3b29805-goog