Re: [PATCH v2 21/24] locking/lockdep: Verify whether lock objects are small enough to be used as class keys

From: Bart Van Assche
Date: Tue Dec 04 2018 - 16:39:19 EST


On Tue, 2018-12-04 at 16:08 -0500, Waiman Long wrote:
+AD4 On 12/03/2018 07:28 PM, Bart Van Assche wrote:
+AD4 +AD4 Cc: Peter Zijlstra +ADw-peterz+AEA-infradead.org+AD4
+AD4 +AD4 Cc: Waiman Long +ADw-longman+AEA-redhat.com+AD4
+AD4 +AD4 Cc: Johannes Berg +ADw-johannes+AEA-sipsolutions.net+AD4
+AD4 +AD4 Signed-off-by: Bart Van Assche +ADw-bvanassche+AEA-acm.org+AD4
+AD4 +AD4 ---
+AD4 +AD4 kernel/locking/lockdep.c +AHw 9 +-+-+-+-+-+-+-+-+-
+AD4 +AD4 1 file changed, 9 insertions(+-)
+AD4 +AD4
+AD4 +AD4 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
+AD4 +AD4 index c936fce5b9d7..b4772e5fc176 100644
+AD4 +AD4 --- a/kernel/locking/lockdep.c
+AD4 +AD4 +-+-+- b/kernel/locking/lockdep.c
+AD4 +AD4 +AEAAQA -727,6 +-727,15 +AEAAQA static bool assign+AF8-lock+AF8-key(struct lockdep+AF8-map +ACo-lock)
+AD4 +AD4 +AHs
+AD4 +AD4 unsigned long can+AF8-addr, addr +AD0 (unsigned long)lock+ADs
+AD4 +AD4
+AD4 +AD4 +- /+ACo
+AD4 +AD4 +- +ACo lockdep+AF8-free+AF8-key+AF8-range() assumes that struct lock+AF8-class+AF8-key
+AD4 +AD4 +- +ACo objects do not overlap. Since we use the address of lock
+AD4 +AD4 +- +ACo objects as class key for static objects, check whether the
+AD4 +AD4 +- +ACo size of lock+AF8-class+AF8-key objects does not exceed the size of
+AD4 +AD4 +- +ACo the smallest lock object.
+AD4 +AD4 +- +ACo-/
+AD4 +AD4 +- BUILD+AF8-BUG+AF8-ON(sizeof(struct lock+AF8-class+AF8-key) +AD4 sizeof(raw+AF8-spinlock+AF8-t))+ADs
+AD4 +AD4 +-
+AD4 +AD4 if (+AF8AXw-is+AF8-kernel+AF8-percpu+AF8-address(addr, +ACY-can+AF8-addr))
+AD4 +AD4 lock-+AD4-key +AD0 (void +ACo)can+AF8-addr+ADs
+AD4 +AD4 else if (+AF8AXw-is+AF8-module+AF8-percpu+AF8-address(addr, +ACY-can+AF8-addr))
+AD4
+AD4 I don't understand what this check is for. lock+AF8-class+AF8-key and spinlock
+AD4 are different objects. Their relative size shouldn't matter.

Hi Waiman,

Peter asked me to add this check.

Bart.