Skip to content

Commit 51711e8

Browse files
KAGA-KOKOingomolnar
authored andcommitted
locking/rtmutex: Prevent lockdep false positive with PI futexes
On PREEMPT_RT the futex hashbucket spinlock becomes 'sleeping' and rtmutex based. That causes a lockdep false positive because some of the futex functions invoke spin_unlock(&hb->lock) with the wait_lock of the rtmutex associated to the pi_futex held. spin_unlock() in turn takes wait_lock of the rtmutex on which the spinlock is based which makes lockdep notice a lock recursion. Give the futex/rtmutex wait_lock a separate key. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Link: https://lore.kernel.org/r/20210815211305.750701219@linutronix.de
1 parent 07d91ef commit 51711e8

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

kernel/locking/rtmutex_api.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,19 @@ EXPORT_SYMBOL_GPL(__rt_mutex_init);
214214
void __sched rt_mutex_init_proxy_locked(struct rt_mutex_base *lock,
215215
struct task_struct *proxy_owner)
216216
{
217+
static struct lock_class_key pi_futex_key;
218+
217219
__rt_mutex_base_init(lock);
220+
/*
221+
* On PREEMPT_RT the futex hashbucket spinlock becomes 'sleeping'
222+
* and rtmutex based. That causes a lockdep false positive, because
223+
* some of the futex functions invoke spin_unlock(&hb->lock) with
224+
* the wait_lock of the rtmutex associated to the pi_futex held.
225+
* spin_unlock() in turn takes wait_lock of the rtmutex on which
226+
* the spinlock is based, which makes lockdep notice a lock
227+
* recursion. Give the futex/rtmutex wait_lock a separate key.
228+
*/
229+
lockdep_set_class(&lock->wait_lock, &pi_futex_key);
218230
rt_mutex_set_owner(lock, proxy_owner);
219231
}
220232

0 commit comments

Comments
 (0)