Some code uses nested locking of different spinlocks that share a
lock class. That results in false positives because spin_lock_init()
forces these instances to share a lock class. Make it possible to
avoid these false positives by allowing spinlock users to specify
the lock class at runtime.

Cc: Ingo Molnar <mi...@kernel.org>
Cc: Will Deacon <will.dea...@arm.com>
Signed-off-by: Bart Van Assche <bvanass...@acm.org>
---
 include/linux/spinlock.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/include/linux/spinlock.h b/include/linux/spinlock.h
index e089157dcf97..09b3e27ed21d 100644
--- a/include/linux/spinlock.h
+++ b/include/linux/spinlock.h
@@ -99,10 +99,19 @@ do {                                                        
        \
                                                                \
        __raw_spin_lock_init((lock), #lock, &__key);            \
 } while (0)
+#define raw_spin_lock_init_key(lock, key)                      \
+       __raw_spin_lock_init((lock), #lock, key)
 
 #else
+
 # define raw_spin_lock_init(lock)                              \
        do { *(lock) = __RAW_SPIN_LOCK_UNLOCKED(lock); } while (0)
+static inline void raw_spin_lock_init_key(struct raw_spinlock *lock,
+                                         struct lock_class_key *key)
+{
+       *(lock) = __RAW_SPIN_LOCK_UNLOCKED(lock);
+}
+
 #endif
 
 #define raw_spin_is_locked(lock)       arch_spin_is_locked(&(lock)->raw_lock)
@@ -324,6 +333,12 @@ do {                                                       
\
        raw_spin_lock_init(&(_lock)->rlock);            \
 } while (0)
 
+#define spin_lock_init_key(_lock, _key)                        \
+do {                                                   \
+       spinlock_check(_lock);                          \
+       raw_spin_lock_init_key(&(_lock)->rlock, _key);  \
+} while (0)
+
 static __always_inline void spin_lock(spinlock_t *lock)
 {
        raw_spin_lock(&lock->rlock);
-- 
2.21.0.rc0.258.g878e2cd30e-goog

Reply via email to