stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4.4.y] futex,rt_mutex: Restructure rt_mutex_finish_proxy_lock()
@ 2019-03-07 23:59 Zubin Mithra
  2019-03-08 11:01 ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Zubin Mithra @ 2019-03-07 23:59 UTC (permalink / raw)
  To: stable; +Cc: gregkh, groeck, tglx, mingo, peterz, dvhart, zsm

From: Peter Zijlstra <peterz@infradead.org>

commit 38d589f2fd08f1296aea3ce62bebd185125c6d81 upstream

With the ultimate goal of keeping rt_mutex wait_list and futex_q waiters
consistent it's necessary to split 'rt_mutex_futex_lock()' into finer
parts, such that only the actual blocking can be done without hb->lock
held.

Split split_mutex_finish_proxy_lock() into two parts, one that does the
blocking and one that does remove_waiter() when the lock acquire failed.

When the rtmutex was acquired successfully the waiter can be removed in the
acquisiton path safely, since there is no concurrency on the lock owner.

This means that, except for futex_lock_pi(), all wait_list modifications
are done with both hb->lock and wait_lock held.

[bigeasy@linutronix.de: fix for futex_requeue_pi_signal_restart]

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: juri.lelli@arm.com
Cc: bigeasy@linutronix.de
Cc: xlpang@redhat.com
Cc: rostedt@goodmis.org
Cc: mathieu.desnoyers@efficios.com
Cc: jdesfossez@efficios.com
Cc: dvhart@infradead.org
Cc: bristot@redhat.com
Link: http://lkml.kernel.org/r/20170322104152.001659630@infradead.org
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Zubin Mithra <zsm@chromium.org>
---
 kernel/futex.c                  |  7 +++--
 kernel/locking/rtmutex.c        | 52 ++++++++++++++++++++++++++++-----
 kernel/locking/rtmutex_common.h |  9 ++++--
 3 files changed, 56 insertions(+), 12 deletions(-)

diff --git a/kernel/futex.c b/kernel/futex.c
index a26d217c99fe7..0c92c8d34ffa2 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -2923,10 +2923,13 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
 		 */
 		WARN_ON(!q.pi_state);
 		pi_mutex = &q.pi_state->pi_mutex;
-		ret = rt_mutex_finish_proxy_lock(pi_mutex, to, &rt_waiter);
-		debug_rt_mutex_free_waiter(&rt_waiter);
+		ret = rt_mutex_wait_proxy_lock(pi_mutex, to, &rt_waiter);
 
 		spin_lock(q.lock_ptr);
+		if (ret && !rt_mutex_cleanup_proxy_lock(pi_mutex, &rt_waiter))
+			ret = 0;
+
+		debug_rt_mutex_free_waiter(&rt_waiter);
 		/*
 		 * Fixup the pi_state owner and possibly acquire the lock if we
 		 * haven't already.
diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c
index b066724d7a5be..dd173df9ee5e5 100644
--- a/kernel/locking/rtmutex.c
+++ b/kernel/locking/rtmutex.c
@@ -1712,21 +1712,23 @@ struct task_struct *rt_mutex_next_owner(struct rt_mutex *lock)
 }
 
 /**
- * rt_mutex_finish_proxy_lock() - Complete lock acquisition
+ * rt_mutex_wait_proxy_lock() - Wait for lock acquisition
  * @lock:		the rt_mutex we were woken on
  * @to:			the timeout, null if none. hrtimer should already have
  *			been started.
  * @waiter:		the pre-initialized rt_mutex_waiter
  *
- * Complete the lock acquisition started our behalf by another thread.
+ * Wait for the the lock acquisition started on our behalf by
+ * rt_mutex_start_proxy_lock(). Upon failure, the caller must call
+ * rt_mutex_cleanup_proxy_lock().
  *
  * Returns:
  *  0 - success
  * <0 - error, one of -EINTR, -ETIMEDOUT
  *
- * Special API call for PI-futex requeue support
+ * Special API call for PI-futex support
  */
-int rt_mutex_finish_proxy_lock(struct rt_mutex *lock,
+int rt_mutex_wait_proxy_lock(struct rt_mutex *lock,
 			       struct hrtimer_sleeper *to,
 			       struct rt_mutex_waiter *waiter)
 {
@@ -1739,9 +1741,6 @@ int rt_mutex_finish_proxy_lock(struct rt_mutex *lock,
 	/* sleep on the mutex */
 	ret = __rt_mutex_slowlock(lock, TASK_INTERRUPTIBLE, to, waiter);
 
-	if (unlikely(ret))
-		remove_waiter(lock, waiter);
-
 	/*
 	 * try_to_take_rt_mutex() sets the waiter bit unconditionally. We might
 	 * have to fix that up.
@@ -1752,3 +1751,42 @@ int rt_mutex_finish_proxy_lock(struct rt_mutex *lock,
 
 	return ret;
 }
+
+/**
+ * rt_mutex_cleanup_proxy_lock() - Cleanup failed lock acquisition
+ * @lock:		the rt_mutex we were woken on
+ * @waiter:		the pre-initialized rt_mutex_waiter
+ *
+ * Attempt to clean up after a failed rt_mutex_wait_proxy_lock().
+ *
+ * Unless we acquired the lock; we're still enqueued on the wait-list and can
+ * in fact still be granted ownership until we're removed. Therefore we can
+ * find we are in fact the owner and must disregard the
+ * rt_mutex_wait_proxy_lock() failure.
+ *
+ * Returns:
+ *  true  - did the cleanup, we done.
+ *  false - we acquired the lock after rt_mutex_wait_proxy_lock() returned,
+ *          caller should disregards its return value.
+ *
+ * Special API call for PI-futex support
+ */
+bool rt_mutex_cleanup_proxy_lock(struct rt_mutex *lock,
+				 struct rt_mutex_waiter *waiter)
+{
+	bool cleanup = false;
+
+	raw_spin_lock_irq(&lock->wait_lock);
+	/*
+	 * Unless we're the owner; we're still enqueued on the wait_list.
+	 * So check if we became owner, if not, take us off the wait_list.
+	 */
+	if (rt_mutex_owner(lock) != current) {
+		remove_waiter(lock, waiter);
+		fixup_rt_mutex_waiters(lock);
+		cleanup = true;
+	}
+	raw_spin_unlock_irq(&lock->wait_lock);
+
+	return cleanup;
+}
diff --git a/kernel/locking/rtmutex_common.h b/kernel/locking/rtmutex_common.h
index e317e1cbb3eba..774b64dba29eb 100644
--- a/kernel/locking/rtmutex_common.h
+++ b/kernel/locking/rtmutex_common.h
@@ -106,9 +106,12 @@ extern void rt_mutex_proxy_unlock(struct rt_mutex *lock,
 extern int rt_mutex_start_proxy_lock(struct rt_mutex *lock,
 				     struct rt_mutex_waiter *waiter,
 				     struct task_struct *task);
-extern int rt_mutex_finish_proxy_lock(struct rt_mutex *lock,
-				      struct hrtimer_sleeper *to,
-				      struct rt_mutex_waiter *waiter);
+extern int rt_mutex_wait_proxy_lock(struct rt_mutex *lock,
+			       struct hrtimer_sleeper *to,
+			       struct rt_mutex_waiter *waiter);
+extern bool rt_mutex_cleanup_proxy_lock(struct rt_mutex *lock,
+				 struct rt_mutex_waiter *waiter);
+
 extern int rt_mutex_timed_futex_lock(struct rt_mutex *l, struct hrtimer_sleeper *to);
 extern bool rt_mutex_futex_unlock(struct rt_mutex *lock,
 				  struct wake_q_head *wqh);
-- 
2.21.0.360.g471c308f928-goog


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

* Re: [PATCH v4.4.y] futex,rt_mutex: Restructure rt_mutex_finish_proxy_lock()
  2019-03-07 23:59 [PATCH v4.4.y] futex,rt_mutex: Restructure rt_mutex_finish_proxy_lock() Zubin Mithra
@ 2019-03-08 11:01 ` Greg KH
  2019-03-11 20:54   ` Guenter Roeck
  0 siblings, 1 reply; 4+ messages in thread
From: Greg KH @ 2019-03-08 11:01 UTC (permalink / raw)
  To: Zubin Mithra; +Cc: stable, groeck, tglx, mingo, peterz, dvhart

On Thu, Mar 07, 2019 at 03:59:04PM -0800, Zubin Mithra wrote:
> From: Peter Zijlstra <peterz@infradead.org>
> 
> commit 38d589f2fd08f1296aea3ce62bebd185125c6d81 upstream
> 
> With the ultimate goal of keeping rt_mutex wait_list and futex_q waiters
> consistent it's necessary to split 'rt_mutex_futex_lock()' into finer
> parts, such that only the actual blocking can be done without hb->lock
> held.
> 
> Split split_mutex_finish_proxy_lock() into two parts, one that does the
> blocking and one that does remove_waiter() when the lock acquire failed.
> 
> When the rtmutex was acquired successfully the waiter can be removed in the
> acquisiton path safely, since there is no concurrency on the lock owner.
> 
> This means that, except for futex_lock_pi(), all wait_list modifications
> are done with both hb->lock and wait_lock held.
> 
> [bigeasy@linutronix.de: fix for futex_requeue_pi_signal_restart]
> 
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> Cc: juri.lelli@arm.com
> Cc: bigeasy@linutronix.de
> Cc: xlpang@redhat.com
> Cc: rostedt@goodmis.org
> Cc: mathieu.desnoyers@efficios.com
> Cc: jdesfossez@efficios.com
> Cc: dvhart@infradead.org
> Cc: bristot@redhat.com
> Link: http://lkml.kernel.org/r/20170322104152.001659630@infradead.org
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Signed-off-by: Zubin Mithra <zsm@chromium.org>
> ---
>  kernel/futex.c                  |  7 +++--
>  kernel/locking/rtmutex.c        | 52 ++++++++++++++++++++++++++++-----
>  kernel/locking/rtmutex_common.h |  9 ++++--
>  3 files changed, 56 insertions(+), 12 deletions(-)

Why is this needed for 4.4.y and not 4.9.y?  What bug/issue does it
resolve?

From the changelog text, all it looks like it is doing here is
reorganizing the code a bit.

confused,

greg k-h

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

* Re: [PATCH v4.4.y] futex,rt_mutex: Restructure rt_mutex_finish_proxy_lock()
  2019-03-08 11:01 ` Greg KH
@ 2019-03-11 20:54   ` Guenter Roeck
  2019-03-11 21:54     ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Guenter Roeck @ 2019-03-11 20:54 UTC (permalink / raw)
  To: Greg KH
  Cc: Zubin Mithra, # v4 . 10+, Guenter Roeck, Thomas Gleixner,
	Ingo Molnar, peterz, dvhart

Hi Greg,

On Fri, Mar 8, 2019 at 3:01 AM Greg KH <gregkh@linuxfoundation.org> wrote:
>
> On Thu, Mar 07, 2019 at 03:59:04PM -0800, Zubin Mithra wrote:
> > From: Peter Zijlstra <peterz@infradead.org>
> >
> > commit 38d589f2fd08f1296aea3ce62bebd185125c6d81 upstream
> >
> > With the ultimate goal of keeping rt_mutex wait_list and futex_q waiters
> > consistent it's necessary to split 'rt_mutex_futex_lock()' into finer
> > parts, such that only the actual blocking can be done without hb->lock
> > held.
> >
> > Split split_mutex_finish_proxy_lock() into two parts, one that does the
> > blocking and one that does remove_waiter() when the lock acquire failed.
> >
> > When the rtmutex was acquired successfully the waiter can be removed in the
> > acquisiton path safely, since there is no concurrency on the lock owner.
> >
> > This means that, except for futex_lock_pi(), all wait_list modifications
> > are done with both hb->lock and wait_lock held.
> >
> > [bigeasy@linutronix.de: fix for futex_requeue_pi_signal_restart]
> >
> > Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> > Cc: juri.lelli@arm.com
> > Cc: bigeasy@linutronix.de
> > Cc: xlpang@redhat.com
> > Cc: rostedt@goodmis.org
> > Cc: mathieu.desnoyers@efficios.com
> > Cc: jdesfossez@efficios.com
> > Cc: dvhart@infradead.org
> > Cc: bristot@redhat.com
> > Link: http://lkml.kernel.org/r/20170322104152.001659630@infradead.org
> > Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> > Signed-off-by: Zubin Mithra <zsm@chromium.org>
> > ---
> >  kernel/futex.c                  |  7 +++--
> >  kernel/locking/rtmutex.c        | 52 ++++++++++++++++++++++++++++-----
> >  kernel/locking/rtmutex_common.h |  9 ++++--
> >  3 files changed, 56 insertions(+), 12 deletions(-)
>
> Why is this needed for 4.4.y and not 4.9.y?  What bug/issue does it
> resolve?
>
> From the changelog text, all it looks like it is doing here is
> reorganizing the code a bit.
>
> confused,
>

Was this clarified with v2, or do you still have questions/concerns ?

Thanks,
Guenter

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

* Re: [PATCH v4.4.y] futex,rt_mutex: Restructure rt_mutex_finish_proxy_lock()
  2019-03-11 20:54   ` Guenter Roeck
@ 2019-03-11 21:54     ` Greg KH
  0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2019-03-11 21:54 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Zubin Mithra, # v4 . 10+, Guenter Roeck, Thomas Gleixner,
	Ingo Molnar, peterz, dvhart

On Mon, Mar 11, 2019 at 01:54:09PM -0700, Guenter Roeck wrote:
> Hi Greg,
> 
> On Fri, Mar 8, 2019 at 3:01 AM Greg KH <gregkh@linuxfoundation.org> wrote:
> >
> > On Thu, Mar 07, 2019 at 03:59:04PM -0800, Zubin Mithra wrote:
> > > From: Peter Zijlstra <peterz@infradead.org>
> > >
> > > commit 38d589f2fd08f1296aea3ce62bebd185125c6d81 upstream
> > >
> > > With the ultimate goal of keeping rt_mutex wait_list and futex_q waiters
> > > consistent it's necessary to split 'rt_mutex_futex_lock()' into finer
> > > parts, such that only the actual blocking can be done without hb->lock
> > > held.
> > >
> > > Split split_mutex_finish_proxy_lock() into two parts, one that does the
> > > blocking and one that does remove_waiter() when the lock acquire failed.
> > >
> > > When the rtmutex was acquired successfully the waiter can be removed in the
> > > acquisiton path safely, since there is no concurrency on the lock owner.
> > >
> > > This means that, except for futex_lock_pi(), all wait_list modifications
> > > are done with both hb->lock and wait_lock held.
> > >
> > > [bigeasy@linutronix.de: fix for futex_requeue_pi_signal_restart]
> > >
> > > Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> > > Cc: juri.lelli@arm.com
> > > Cc: bigeasy@linutronix.de
> > > Cc: xlpang@redhat.com
> > > Cc: rostedt@goodmis.org
> > > Cc: mathieu.desnoyers@efficios.com
> > > Cc: jdesfossez@efficios.com
> > > Cc: dvhart@infradead.org
> > > Cc: bristot@redhat.com
> > > Link: http://lkml.kernel.org/r/20170322104152.001659630@infradead.org
> > > Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> > > Signed-off-by: Zubin Mithra <zsm@chromium.org>
> > > ---
> > >  kernel/futex.c                  |  7 +++--
> > >  kernel/locking/rtmutex.c        | 52 ++++++++++++++++++++++++++++-----
> > >  kernel/locking/rtmutex_common.h |  9 ++++--
> > >  3 files changed, 56 insertions(+), 12 deletions(-)
> >
> > Why is this needed for 4.4.y and not 4.9.y?  What bug/issue does it
> > resolve?
> >
> > From the changelog text, all it looks like it is doing here is
> > reorganizing the code a bit.
> >
> > confused,
> >
> 
> Was this clarified with v2, or do you still have questions/concerns ?

It's all good, sorry, on the road this week, so catching up on stable
patches is going to take a while...

greg k-h

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

end of thread, other threads:[~2019-03-11 21:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-07 23:59 [PATCH v4.4.y] futex,rt_mutex: Restructure rt_mutex_finish_proxy_lock() Zubin Mithra
2019-03-08 11:01 ` Greg KH
2019-03-11 20:54   ` Guenter Roeck
2019-03-11 21:54     ` Greg KH

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).