Skip to content

Commit

Permalink
locking/rtmutex: Add a lockdep assert to catch potential nested blocking
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Thomas Gleixner authored and Peter Zijlstra committed Sep 20, 2023
1 parent d14f9e9 commit 45f67f3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions kernel/locking/rtmutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions kernel/locking/rwbase_rt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions kernel/locking/spinlock_rt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 45f67f3

Please sign in to comment.