lkml.org 
[lkml]   [2019]   [Nov]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[tip: locking/core] futex: Sanitize exit state handling
The following commit has been merged into the locking/core branch of tip:

Commit-ID: 8e9a078792b2025e92492431992e4c898b1be36b
Gitweb: https://git.kernel.org/tip/8e9a078792b2025e92492431992e4c898b1be36b
Author: Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Wed, 06 Nov 2019 22:55:42 +01:00
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Fri, 15 Nov 2019 19:10:52 +01:00

futex: Sanitize exit state handling

Instead of having a smp_mb() and an empty lock/unlock of task::pi_lock move
the state setting into to the lock section.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20191106224556.645603214@linutronix.de

---
kernel/futex.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/kernel/futex.c b/kernel/futex.c
index 3488fb0..f618562 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -3703,16 +3703,19 @@ void futex_exit_recursive(struct task_struct *tsk)

void futex_exit_release(struct task_struct *tsk)
{
- tsk->futex_state = FUTEX_STATE_EXITING;
- /*
- * Ensure that all new tsk->pi_lock acquisitions must observe
- * FUTEX_STATE_EXITING. Serializes against attach_to_pi_owner().
- */
- smp_mb();
/*
- * Ensure that we must observe the pi_state in exit_pi_state_list().
+ * Switch the state to FUTEX_STATE_EXITING under tsk->pi_lock.
+ *
+ * This ensures that all subsequent checks of tsk->futex_state in
+ * attach_to_pi_owner() must observe FUTEX_STATE_EXITING with
+ * tsk->pi_lock held.
+ *
+ * It guarantees also that a pi_state which was queued right before
+ * the state change under tsk->pi_lock by a concurrent waiter must
+ * be observed in exit_pi_state_list().
*/
raw_spin_lock_irq(&tsk->pi_lock);
+ tsk->futex_state = FUTEX_STATE_EXITING;
raw_spin_unlock_irq(&tsk->pi_lock);

futex_exec_release(tsk);
\
 
 \ /
  Last update: 2019-11-15 19:20    [W:0.275 / U:0.952 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site