linux-rt-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RT] futex/rtmutex: Cure RT double blocking issue
@ 2017-05-09 15:11 Thomas Gleixner
  2017-05-09 15:49 ` Steven Rostedt
  2017-05-11  2:25 ` Wanpeng Li
  0 siblings, 2 replies; 7+ messages in thread
From: Thomas Gleixner @ 2017-05-09 15:11 UTC (permalink / raw)
  To: LKML
  Cc: Sebastian Sewior, Peter Zijlstra, Steven Rostedt, linux-rt-users,
	Engleder Gerhard

RT has a problem when the wait on a futex/rtmutex got interrupted by a
timeout or a signal. task->pi_blocked_on is still set when returning from
rt_mutex_wait_proxy_lock(). The task must acquire the hash bucket lock
after this.

If the hash bucket lock is contended then the
BUG_ON(rt_mutex_real_waiter(task->pi_blocked_on)) in
task_blocks_on_rt_mutex() will trigger.

This can be avoided by clearing task->pi_blocked_on in the return path of
rt_mutex_wait_proxy_lock() which removes the task from the boosting chain
of the rtmutex. That's correct because the task is not longer blocked on
it.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reported-by: Engleder Gerhard <eg@keba.com>
---
 kernel/locking/rtmutex.c |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)

--- a/kernel/locking/rtmutex.c
+++ b/kernel/locking/rtmutex.c
@@ -2380,6 +2380,7 @@ int rt_mutex_wait_proxy_lock(struct rt_m
 			       struct hrtimer_sleeper *to,
 			       struct rt_mutex_waiter *waiter)
 {
+	struct task_struct *tsk = current;
 	int ret;
 
 	raw_spin_lock_irq(&lock->wait_lock);
@@ -2389,6 +2390,22 @@ int rt_mutex_wait_proxy_lock(struct rt_m
 	/* sleep on the mutex */
 	ret = __rt_mutex_slowlock(lock, TASK_INTERRUPTIBLE, to, waiter, NULL);
 
+	/*
+	 * RT has a problem here when the wait got interrupted by a timeout
+	 * or a signal. task->pi_blocked_on is still set. The task must
+	 * acquire the hash bucket lock when returning from this function.
+	 *
+	 * If the hash bucket lock is contended then the
+	 * BUG_ON(rt_mutex_real_waiter(task->pi_blocked_on)) in
+	 * task_blocks_on_rt_mutex() will trigger. This can be avoided by
+	 * clearing task->pi_blocked_on which removes the task from the
+	 * boosting chain of the rtmutex. That's correct because the task
+	 * is not longer blocked on it.
+	 */
+	raw_spin_lock(&tsk->pi_lock);
+	tsk->pi_blocked_on = NULL;
+	raw_spin_unlock(&tsk->pi_lock);
+
 	raw_spin_unlock_irq(&lock->wait_lock);
 
 	return ret;

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-05-11 16:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-09 15:11 [PATCH RT] futex/rtmutex: Cure RT double blocking issue Thomas Gleixner
2017-05-09 15:49 ` Steven Rostedt
2017-05-11  2:25 ` Wanpeng Li
2017-05-11  7:31   ` Thomas Gleixner
2017-05-11 15:20     ` [PATCH RT v2] " Sebastian Sewior
2017-05-11 15:54       ` Steven Rostedt
2017-05-11 16:05         ` Sebastian Sewior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).