History

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.

Thomas Gleixner committed 5 years ago

Commit 51711e81 parent 07d91ef1 file · +12 −0Browse files

Showing the changes to kernel/locking (1 of 1 file). Show all

Unified · Split

kernel/locking/rtmutex_api.c+12−0
@@ -214,7 +214,19 @@ EXPORT_SYMBOL_GPL(__rt_mutex_init); · 213 unmodified lines
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