Skip to content

Commit ac31c7f

Browse files
committed
futex: Provide distinct return value when owner is exiting
attach_to_pi_owner() returns -EAGAIN for various cases: - Owner task is exiting - Futex value has changed The caller drops the held locks (hash bucket, mmap_sem) and retries the operation. In case of the owner task exiting this can result in a live lock. As a preparatory step for seperating those cases, provide a distinct return value (EBUSY) for the owner exiting case. No functional change. 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 3f186d9 commit ac31c7f

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

kernel/futex.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,11 +1182,11 @@ static int handle_exit_race(u32 __user *uaddr, u32 uval,
11821182
u32 uval2;
11831183

11841184
/*
1185-
* If the futex exit state is not yet FUTEX_STATE_DEAD, wait
1186-
* for it to finish.
1185+
* If the futex exit state is not yet FUTEX_STATE_DEAD, tell the
1186+
* caller that the alleged owner is busy.
11871187
*/
11881188
if (tsk && tsk->futex_state != FUTEX_STATE_DEAD)
1189-
return -EAGAIN;
1189+
return -EBUSY;
11901190

11911191
/*
11921192
* Reread the user space value to handle the following situation:
@@ -2092,12 +2092,13 @@ static int futex_requeue(u32 __user *uaddr1, unsigned int flags,
20922092
if (!ret)
20932093
goto retry;
20942094
goto out;
2095+
case -EBUSY:
20952096
case -EAGAIN:
20962097
/*
20972098
* Two reasons for this:
2098-
* - Owner is exiting and we just wait for the
2099+
* - EBUSY: Owner is exiting and we just wait for the
20992100
* exit to complete.
2100-
* - The user space value changed.
2101+
* - EAGAIN: The user space value changed.
21012102
*/
21022103
double_unlock_hb(hb1, hb2);
21032104
hb_waiters_dec(hb2);
@@ -2843,12 +2844,13 @@ static int futex_lock_pi(u32 __user *uaddr, unsigned int flags,
28432844
goto out_unlock_put_key;
28442845
case -EFAULT:
28452846
goto uaddr_faulted;
2847+
case -EBUSY:
28462848
case -EAGAIN:
28472849
/*
28482850
* Two reasons for this:
2849-
* - Task is exiting and we just wait for the
2851+
* - EBUSY: Task is exiting and we just wait for the
28502852
* exit to complete.
2851-
* - The user space value changed.
2853+
* - EAGAIN: The user space value changed.
28522854
*/
28532855
queue_unlock(hb);
28542856
put_futex_key(&q.key);

0 commit comments

Comments
 (0)