locking/rtmutex: Add a lockdep assert to catch potential nested blocking
authorThomas Gleixner <tglx@linutronix.de>
Fri, 8 Sep 2023 16:22:53 +0000 (18:22 +0200)
committerPeter Zijlstra <peterz@infradead.org>
Wed, 20 Sep 2023 07:31:14 +0000 (09:31 +0200)
There used to be a BUG_ON(current->pi_blocked_on) in the lock acquisition
functions, but that vanished in one of the rtmutex overhauls.

Bring it back in form of a lockdep assert to catch code paths which take
rtmutex based locks with current::pi_blocked_on != NULL.

Reported-by: Crystal Wood <swood@redhat.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: "Peter Zijlstra (Intel)" <peterz@infradead.org>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20230908162254.999499-7-bigeasy@linutronix.de
kernel/locking/rtmutex.c
kernel/locking/rwbase_rt.c
kernel/locking/spinlock_rt.c

index a3fe05dfd0d8f0fdd8a35863cfe98add37230b8b..4a10e8c16fd2bd691f53871228e556a59f0f781a 100644 (file)
@@ -1784,6 +1784,8 @@ static int __sched rt_mutex_slowlock(struct rt_mutex_base *lock,
 static __always_inline int __rt_mutex_lock(struct rt_mutex_base *lock,
                                           unsigned int state)
 {
+       lockdep_assert(!current->pi_blocked_on);
+
        if (likely(rt_mutex_try_acquire(lock)))
                return 0;
 
index c7258cb32d91b6c69082de7702a3b7beedc2dde8..34a59569db6bed137b811fc8c72cf123d6399c5b 100644 (file)
@@ -133,6 +133,8 @@ static int __sched __rwbase_read_lock(struct rwbase_rt *rwb,
 static __always_inline int rwbase_read_lock(struct rwbase_rt *rwb,
                                            unsigned int state)
 {
+       lockdep_assert(!current->pi_blocked_on);
+
        if (rwbase_read_trylock(rwb))
                return 0;
 
index 842037b2ba5480f4d8557f946ce626c8867bda3a..38e292454fccb5380914cc75061ec7c8306b6709 100644 (file)
@@ -37,6 +37,8 @@
 
 static __always_inline void rtlock_lock(struct rt_mutex_base *rtm)
 {
+       lockdep_assert(!current->pi_blocked_on);
+
        if (unlikely(!rt_mutex_cmpxchg_acquire(rtm, NULL, current)))
                rtlock_slowlock(rtm);
 }