linux-rt-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org,
	linux-rt-users <linux-rt-users@vger.kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Carsten Emde <C.Emde@osadl.org>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	John Kacur <jkacur@redhat.com>, Julia Cartwright <julia@ni.com>,
	Daniel Wagner <wagi@monom.org>, Tom Zanussi <zanussi@kernel.org>,
	"Peter Zijlstra (Intel)" <peterz@infradead.org>
Subject: [PATCH RT 19/32] locking/rtmutex: Clean ->pi_blocked_on in the error case
Date: Fri, 17 Jan 2020 12:41:30 -0500	[thread overview]
Message-ID: <20200117174130.269046903@goodmis.org> (raw)
In-Reply-To: 20200117174111.282847363@goodmis.org

4.19.94-rt39-rc1 stable review patch.
If anyone has any objections, please let me know.

------------------

From: Peter Zijlstra <peterz@infradead.org>

[ Upstream commit 0be4ea6e3ce693101be0fbd55a0cc7ce238ab2eb ]

The function rt_mutex_wait_proxy_lock() cleans ->pi_blocked_on in case
of failure (timeout, signal). The same cleanup is required in
__rt_mutex_start_proxy_lock().
In both the cases the tasks was interrupted by a signal or timeout while
acquiring the lock and after the interruption it longer blocks on the
lock.

Fixes: 1a1fb985f2e2b ("futex: Handle early deadlock return correctly")
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 kernel/locking/rtmutex.c | 43 +++++++++++++++++++++++-----------------
 1 file changed, 25 insertions(+), 18 deletions(-)

diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c
index 2a9bf2443acc..63b3d6f306fa 100644
--- a/kernel/locking/rtmutex.c
+++ b/kernel/locking/rtmutex.c
@@ -2320,6 +2320,26 @@ void rt_mutex_proxy_unlock(struct rt_mutex *lock,
 	rt_mutex_set_owner(lock, NULL);
 }
 
+static void fixup_rt_mutex_blocked(struct rt_mutex *lock)
+{
+	struct task_struct *tsk = current;
+	/*
+	 * 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);
+}
+
 /**
  * __rt_mutex_start_proxy_lock() - Start lock acquisition for another task
  * @lock:		the rt_mutex to take
@@ -2392,6 +2412,9 @@ int __rt_mutex_start_proxy_lock(struct rt_mutex *lock,
 		ret = 0;
 	}
 
+	if (ret)
+		fixup_rt_mutex_blocked(lock);
+
 	debug_rt_mutex_print_deadlock(waiter);
 
 	return ret;
@@ -2472,7 +2495,6 @@ int rt_mutex_wait_proxy_lock(struct rt_mutex *lock,
 			       struct hrtimer_sleeper *to,
 			       struct rt_mutex_waiter *waiter)
 {
-	struct task_struct *tsk = current;
 	int ret;
 
 	raw_spin_lock_irq(&lock->wait_lock);
@@ -2484,23 +2506,8 @@ int rt_mutex_wait_proxy_lock(struct rt_mutex *lock,
 	 * have to fix that up.
 	 */
 	fixup_rt_mutex_waiters(lock);
-	/*
-	 * 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.
-	 */
-	if (ret) {
-		raw_spin_lock(&tsk->pi_lock);
-		tsk->pi_blocked_on = NULL;
-		raw_spin_unlock(&tsk->pi_lock);
-	}
+	if (ret)
+		fixup_rt_mutex_blocked(lock);
 
 	raw_spin_unlock_irq(&lock->wait_lock);
 
-- 
2.24.1



  parent reply	other threads:[~2020-01-17 17:42 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-17 17:41 [PATCH RT 00/32] Linux 4.19.94-rt39-rc1 Steven Rostedt
2020-01-17 17:41 ` [PATCH RT 01/32] i2c: exynos5: Remove IRQF_ONESHOT Steven Rostedt
2020-01-17 17:41 ` [PATCH RT 02/32] i2c: hix5hd2: " Steven Rostedt
2020-01-17 17:41 ` [PATCH RT 03/32] sched/deadline: Ensure inactive_timer runs in hardirq context Steven Rostedt
2020-01-17 17:41 ` [PATCH RT 04/32] thermal/x86_pkg_temp: make pkg_temp_lock a raw spinlock Steven Rostedt
2020-01-17 17:41 ` [PATCH RT 05/32] dma-buf: Use seqlock_t instread disabling preemption Steven Rostedt
2020-01-17 17:41 ` [PATCH RT 06/32] KVM: arm/arm64: Let the timer expire in hardirq context on RT Steven Rostedt
2020-01-17 17:41 ` [PATCH RT 07/32] x86: preempt: Check preemption level before looking at lazy-preempt Steven Rostedt
2020-01-17 17:41 ` [PATCH RT 08/32] hrtimer: Use READ_ONCE to access timer->base in hrimer_grab_expiry_lock() Steven Rostedt
2020-01-17 17:41 ` [PATCH RT 09/32] hrtimer: Dont grab the expiry lock for non-soft hrtimer Steven Rostedt
2020-01-17 17:41 ` [PATCH RT 10/32] hrtimer: Prevent using hrtimer_grab_expiry_lock() on migration_base Steven Rostedt
2020-01-17 17:41 ` [PATCH RT 11/32] hrtimer: Add a missing bracket and hide `migration_base on !SMP Steven Rostedt
2020-01-17 17:41 ` [PATCH RT 12/32] posix-timers: Unlock expiry lock in the early return Steven Rostedt
2020-01-17 17:41 ` [PATCH RT 14/32] sched: __set_cpus_allowed_ptr: Check cpus_mask, not cpus_ptr Steven Rostedt
2020-01-17 17:41 ` [PATCH RT 15/32] sched: Remove dead __migrate_disabled() check Steven Rostedt
2020-01-17 17:41 ` [PATCH RT 16/32] sched: migrate disable: Protect cpus_ptr with lock Steven Rostedt
2020-01-17 17:41 ` [PATCH RT 17/32] lib/smp_processor_id: Dont use cpumask_equal() Steven Rostedt
2020-01-17 17:41 ` [PATCH RT 18/32] futex: Make the futex_hash_bucket spinlock_t again and bring back its old state Steven Rostedt
2020-01-17 17:41 ` Steven Rostedt [this message]
2020-01-17 17:41 ` [PATCH RT 20/32] lib/ubsan: Dont seralize UBSAN report Steven Rostedt
2020-01-17 17:41 ` [PATCH RT 21/32] kmemleak: Change the lock of kmemleak_object to raw_spinlock_t Steven Rostedt
2020-01-17 17:41 ` [PATCH RT 22/32] sched: migrate_enable: Use select_fallback_rq() Steven Rostedt
2020-01-17 17:41 ` [PATCH RT 23/32] sched: Lazy migrate_disable processing Steven Rostedt
2020-01-17 17:41 ` [PATCH RT 24/32] sched: migrate_enable: Use stop_one_cpu_nowait() Steven Rostedt
2020-01-22  8:31   ` Sebastian Andrzej Siewior
2020-01-22 11:33     ` Steven Rostedt
2020-01-22 18:39       ` Scott Wood
2020-01-22 19:07         ` Steven Rostedt
2020-01-17 17:41 ` [PATCH RT 25/32] Revert "cpufreq: drop K8s driver from beeing selected" Steven Rostedt
2020-01-22  8:38   ` Sebastian Andrzej Siewior
2020-01-22 11:34     ` Steven Rostedt
2020-01-17 17:41 ` [PATCH RT 26/32] Revert "ARM: Initialize split page table locks for vector page" Steven Rostedt
2020-01-17 17:41 ` [PATCH RT 28/32] locking: Make spinlock_t and rwlock_t a RCU section on RT Steven Rostedt
2020-01-17 17:41 ` [PATCH RT 29/32] sched/core: migrate_enable() must access takedown_cpu_task on !HOTPLUG_CPU Steven Rostedt
2020-01-17 17:41 ` [PATCH RT 30/32] lib/smp_processor_id: Adjust check_preemption_disabled() Steven Rostedt
2020-01-17 17:41 ` [PATCH RT 31/32] sched: migrate_enable: Busy loop until the migration request is completed Steven Rostedt
2020-01-17 17:41 ` [PATCH RT 32/32] Linux 4.19.94-rt39-rc1 Steven Rostedt
     [not found] ` <20200117174131.455165326@goodmis.org>
2020-01-22  8:43   ` [PATCH RT 27/32] x86/fpu: Dont cache access to fpu_fpregs_owner_ctx Sebastian Andrzej Siewior
2020-01-22 11:34     ` Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200117174130.269046903@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=C.Emde@osadl.org \
    --cc=bigeasy@linutronix.de \
    --cc=jkacur@redhat.com \
    --cc=julia@ni.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=wagi@monom.org \
    --cc=zanussi@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).