Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1533574 > unrolled thread

[patch 0/4] rtmutex: Plug unlock vs. requeue race

Started byThomas Gleixner <tglx@linutronix.de>
First post2016-11-30 22:10 +0100
Last post2016-12-01 19:40 +0100
Articles 6 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [patch 0/4] rtmutex: Plug unlock vs. requeue race Thomas Gleixner <tglx@linutronix.de> - 2016-11-30 22:10 +0100
    [patch 4/4] rtmutex: Explain locking rules for  rt_mutex_proxy_unlock()/init_proxy_locked() Thomas Gleixner <tglx@linutronix.de> - 2016-11-30 22:10 +0100
      [tip:locking/core] locking/rtmutex: Explain locking rules for  rt_mutex_proxy_unlock()/init_proxy_locked() tip-bot for Thomas Gleixner <tipbot@zytor.com> - 2016-12-02 12:20 +0100
    [patch 2/4] rtmutex: Use READ_ONCE() in rt_mutex_owner() Thomas Gleixner <tglx@linutronix.de> - 2016-11-30 22:10 +0100
      [tip:locking/core] locking/rtmutex: Use READ_ONCE() in  rt_mutex_owner() tip-bot for Thomas Gleixner <tipbot@zytor.com> - 2016-12-02 11:50 +0100
    Re: [patch 0/4] rtmutex: Plug unlock vs. requeue race Peter Zijlstra <peterz@infradead.org> - 2016-12-01 19:40 +0100

#1533574 — [patch 0/4] rtmutex: Plug unlock vs. requeue race

FromThomas Gleixner <tglx@linutronix.de>
Date2016-11-30 22:10 +0100
Subject[patch 0/4] rtmutex: Plug unlock vs. requeue race
Message-ID<sJkiB-2NQ-13@gated-at.bofh.it>
The following series plugs a subtle race and robustifies the code
further. Aside of that it adds commentry about lockless operations and
removes a confusing extra define.

Thanks,

	tglx

[toc] | [next] | [standalone]


#1533575 — [patch 4/4] rtmutex: Explain locking rules for rt_mutex_proxy_unlock()/init_proxy_locked()

FromThomas Gleixner <tglx@linutronix.de>
Date2016-11-30 22:10 +0100
Subject[patch 4/4] rtmutex: Explain locking rules for rt_mutex_proxy_unlock()/init_proxy_locked()
Message-ID<sJkiB-2NQ-25@gated-at.bofh.it>
In reply to#1533574
While debugging the unlock vs. dequeue race which resulted in state
corruption of futexes the lockless nature of rt_mutex_proxy_unlock()
caused some confusion.

Add commentry to explain why it is safe to do this lockless. Add matching
comments to rt_mutex_init_proxy_locked() for completeness sake.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 kernel/locking/rtmutex.c |   16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

--- a/kernel/locking/rtmutex.c
+++ b/kernel/locking/rtmutex.c
@@ -1617,11 +1617,15 @@ EXPORT_SYMBOL_GPL(__rt_mutex_init);
  * rt_mutex_init_proxy_locked - initialize and lock a rt_mutex on behalf of a
  *				proxy owner
  *
- * @lock: 	the rt_mutex to be locked
+ * @lock:	the rt_mutex to be locked
  * @proxy_owner:the task to set as owner
  *
  * No locking. Caller has to do serializing itself
- * Special API call for PI-futex support
+ *
+ * Special API call for PI-futex support. This initializes the rtmutex and
+ * assigns it to @proxy_owner. Concurrent operations on the rtmutex are not
+ * possible at this point because the pi_state which contains the rtmutex
+ * is not yet visible to other tasks.
  */
 void rt_mutex_init_proxy_locked(struct rt_mutex *lock,
 				struct task_struct *proxy_owner)
@@ -1635,10 +1639,14 @@ void rt_mutex_init_proxy_locked(struct r
 /**
  * rt_mutex_proxy_unlock - release a lock on behalf of owner
  *
- * @lock: 	the rt_mutex to be locked
+ * @lock:	the rt_mutex to be locked
  *
  * No locking. Caller has to do serializing itself
- * Special API call for PI-futex support
+ *
+ * Special API call for PI-futex support. This merily cleans up the rtmutex
+ * (debugging) state. Concurrent operations on this rt_mutex are not
+ * possible because it belongs to the pi_state which is about to be freed
+ * and it is not longer visible to other tasks.
  */
 void rt_mutex_proxy_unlock(struct rt_mutex *lock,
 			   struct task_struct *proxy_owner)

[toc] | [prev] | [next] | [standalone]


#1534847 — [tip:locking/core] locking/rtmutex: Explain locking rules for rt_mutex_proxy_unlock()/init_proxy_locked()

Fromtip-bot for Thomas Gleixner <tipbot@zytor.com>
Date2016-12-02 12:20 +0100
Subject[tip:locking/core] locking/rtmutex: Explain locking rules for rt_mutex_proxy_unlock()/init_proxy_locked()
Message-ID<sJU2K-388-27@gated-at.bofh.it>
In reply to#1533575
Commit-ID:  84d82ec5b9046ecdf16031d3e93a66ef50257402
Gitweb:     http://git.kernel.org/tip/84d82ec5b9046ecdf16031d3e93a66ef50257402
Author:     Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Wed, 30 Nov 2016 21:04:45 +0000
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Fri, 2 Dec 2016 11:13:57 +0100

locking/rtmutex: Explain locking rules for rt_mutex_proxy_unlock()/init_proxy_locked()

While debugging the unlock vs. dequeue race which resulted in state
corruption of futexes the lockless nature of rt_mutex_proxy_unlock()
caused some confusion.

Add commentry to explain why it is safe to do this lockless. Add matching
comments to rt_mutex_init_proxy_locked() for completeness sake.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: David Daney <ddaney@caviumnetworks.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sebastian Siewior <bigeasy@linutronix.de>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Will Deacon <will.deacon@arm.com>
Link: http://lkml.kernel.org/r/20161130210030.591941927@linutronix.de
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/locking/rtmutex.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c
index 6e6cab7..2f443ed 100644
--- a/kernel/locking/rtmutex.c
+++ b/kernel/locking/rtmutex.c
@@ -1619,11 +1619,15 @@ EXPORT_SYMBOL_GPL(__rt_mutex_init);
  * rt_mutex_init_proxy_locked - initialize and lock a rt_mutex on behalf of a
  *				proxy owner
  *
- * @lock: 	the rt_mutex to be locked
+ * @lock:	the rt_mutex to be locked
  * @proxy_owner:the task to set as owner
  *
  * No locking. Caller has to do serializing itself
- * Special API call for PI-futex support
+ *
+ * Special API call for PI-futex support. This initializes the rtmutex and
+ * assigns it to @proxy_owner. Concurrent operations on the rtmutex are not
+ * possible at this point because the pi_state which contains the rtmutex
+ * is not yet visible to other tasks.
  */
 void rt_mutex_init_proxy_locked(struct rt_mutex *lock,
 				struct task_struct *proxy_owner)
@@ -1637,10 +1641,14 @@ void rt_mutex_init_proxy_locked(struct rt_mutex *lock,
 /**
  * rt_mutex_proxy_unlock - release a lock on behalf of owner
  *
- * @lock: 	the rt_mutex to be locked
+ * @lock:	the rt_mutex to be locked
  *
  * No locking. Caller has to do serializing itself
- * Special API call for PI-futex support
+ *
+ * Special API call for PI-futex support. This merrily cleans up the rtmutex
+ * (debugging) state. Concurrent operations on this rt_mutex are not
+ * possible because it belongs to the pi_state which is about to be freed
+ * and it is not longer visible to other tasks.
  */
 void rt_mutex_proxy_unlock(struct rt_mutex *lock,
 			   struct task_struct *proxy_owner)

[toc] | [prev] | [next] | [standalone]


#1533578 — [patch 2/4] rtmutex: Use READ_ONCE() in rt_mutex_owner()

FromThomas Gleixner <tglx@linutronix.de>
Date2016-11-30 22:10 +0100
Subject[patch 2/4] rtmutex: Use READ_ONCE() in rt_mutex_owner()
Message-ID<sJkiC-2NQ-31@gated-at.bofh.it>
In reply to#1533574
While debugging the rtmutex unlock vs. dequeue race Will suggested to use
READ_ONCE() in rt_mutex_owner() as it might race against the
cmpxchg_release() in unlock_rt_mutex_safe().

Will: "It's a minor thing which will most likely not matter in practice"

Careful search did not unearth an actual problem in todays code, but it's
better to be safe than surprised.

Suggested-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 kernel/locking/rtmutex_common.h |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

--- a/kernel/locking/rtmutex_common.h
+++ b/kernel/locking/rtmutex_common.h
@@ -75,8 +75,9 @@ task_top_pi_waiter(struct task_struct *p
 
 static inline struct task_struct *rt_mutex_owner(struct rt_mutex *lock)
 {
-	return (struct task_struct *)
-		((unsigned long)lock->owner & ~RT_MUTEX_OWNER_MASKALL);
+	unsigned long owner = (unsigned long) READ_ONCE(lock->owner);
+
+	return (struct task_struct *) (owner & ~RT_MUTEX_OWNER_MASKALL);
 }
 
 /*

[toc] | [prev] | [next] | [standalone]


#1534827 — [tip:locking/core] locking/rtmutex: Use READ_ONCE() in rt_mutex_owner()

Fromtip-bot for Thomas Gleixner <tipbot@zytor.com>
Date2016-12-02 11:50 +0100
Subject[tip:locking/core] locking/rtmutex: Use READ_ONCE() in rt_mutex_owner()
Message-ID<sJTzI-2Il-43@gated-at.bofh.it>
In reply to#1533578
Commit-ID:  1be5d4fa0af34fb7bafa205aeb59f5c7cc7a089d
Gitweb:     http://git.kernel.org/tip/1be5d4fa0af34fb7bafa205aeb59f5c7cc7a089d
Author:     Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Wed, 30 Nov 2016 21:04:42 +0000
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Fri, 2 Dec 2016 11:13:26 +0100

locking/rtmutex: Use READ_ONCE() in rt_mutex_owner()

While debugging the rtmutex unlock vs. dequeue race Will suggested to use
READ_ONCE() in rt_mutex_owner() as it might race against the
cmpxchg_release() in unlock_rt_mutex_safe().

Will: "It's a minor thing which will most likely not matter in practice"

Careful search did not unearth an actual problem in todays code, but it's
better to be safe than surprised.

Suggested-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: David Daney <ddaney@caviumnetworks.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sebastian Siewior <bigeasy@linutronix.de>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: <stable@vger.kernel.org>
Link: http://lkml.kernel.org/r/20161130210030.431379999@linutronix.de
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/locking/rtmutex_common.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/locking/rtmutex_common.h b/kernel/locking/rtmutex_common.h
index 4f5f83c..e317e1c 100644
--- a/kernel/locking/rtmutex_common.h
+++ b/kernel/locking/rtmutex_common.h
@@ -75,8 +75,9 @@ task_top_pi_waiter(struct task_struct *p)
 
 static inline struct task_struct *rt_mutex_owner(struct rt_mutex *lock)
 {
-	return (struct task_struct *)
-		((unsigned long)lock->owner & ~RT_MUTEX_OWNER_MASKALL);
+	unsigned long owner = (unsigned long) READ_ONCE(lock->owner);
+
+	return (struct task_struct *) (owner & ~RT_MUTEX_OWNER_MASKALL);
 }
 
 /*

[toc] | [prev] | [next] | [standalone]


#1534373

FromPeter Zijlstra <peterz@infradead.org>
Date2016-12-01 19:40 +0100
Message-ID<sJEqZ-8du-9@gated-at.bofh.it>
In reply to#1533574
On Wed, Nov 30, 2016 at 09:04:40PM -0000, Thomas Gleixner wrote:
> The following series plugs a subtle race and robustifies the code
> further. Aside of that it adds commentry about lockless operations and
> removes a confusing extra define.

Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web