Skip to content

Commit 4a8e991

Browse files
committed
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 <[email protected]> Reviewed-by: Ingo Molnar <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 18f6943 commit 4a8e991

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

kernel/futex.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3703,16 +3703,19 @@ void futex_exit_recursive(struct task_struct *tsk)
37033703

37043704
void futex_exit_release(struct task_struct *tsk)
37053705
{
3706-
tsk->futex_state = FUTEX_STATE_EXITING;
3707-
/*
3708-
* Ensure that all new tsk->pi_lock acquisitions must observe
3709-
* FUTEX_STATE_EXITING. Serializes against attach_to_pi_owner().
3710-
*/
3711-
smp_mb();
37123706
/*
3713-
* Ensure that we must observe the pi_state in exit_pi_state_list().
3707+
* Switch the state to FUTEX_STATE_EXITING under tsk->pi_lock.
3708+
*
3709+
* This ensures that all subsequent checks of tsk->futex_state in
3710+
* attach_to_pi_owner() must observe FUTEX_STATE_EXITING with
3711+
* tsk->pi_lock held.
3712+
*
3713+
* It guarantees also that a pi_state which was queued right before
3714+
* the state change under tsk->pi_lock by a concurrent waiter must
3715+
* be observed in exit_pi_state_list().
37143716
*/
37153717
raw_spin_lock_irq(&tsk->pi_lock);
3718+
tsk->futex_state = FUTEX_STATE_EXITING;
37163719
raw_spin_unlock_irq(&tsk->pi_lock);
37173720

37183721
futex_exec_release(tsk);

0 commit comments

Comments
 (0)