Commit 41890f24 authored by Thomas Gleixner's avatar Thomas Gleixner

futex: Handle spurious wake up

The futex code does not handle spurious wake up in futex_wait and
futex_wait_requeue_pi.

The code assumes that any wake up which was not caused by futex_wake /
requeue or by a timeout was caused by a signal wake up and returns one
of the syscall restart error codes.

In case of a spurious wake up the signal delivery code which deals
with the restart error codes is not invoked and we return that error
code to user space. That causes applications which actually check the
return codes to fail. Blaise reported that on preempt-rt a python test
program run into a exception trap. -rt exposed that due to a built in
spurious wake up accelerator :)

Solve this by checking signal_pending(current) in the wake up path and
handle the spurious wake up case w/o returning to user space.
Reported-by: default avatarBlaise Gassend <blaise@willowgarage.com>
Debugged-by: default avatarDarren Hart <dvhltc@us.ibm.com>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: stable@kernel.org
LKML-Reference: <new-submission>

Conflicts:

	kernel/futex.c
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent d2638539
...@@ -1753,6 +1753,7 @@ static int futex_wait(u32 __user *uaddr, int fshared, ...@@ -1753,6 +1753,7 @@ static int futex_wait(u32 __user *uaddr, int fshared,
current->timer_slack_ns); current->timer_slack_ns);
} }
retry:
/* Prepare to wait on uaddr. */ /* Prepare to wait on uaddr. */
ret = futex_wait_setup(uaddr, val, fshared, &q, &hb); ret = futex_wait_setup(uaddr, val, fshared, &q, &hb);
if (ret) if (ret)
...@@ -1770,9 +1771,14 @@ static int futex_wait(u32 __user *uaddr, int fshared, ...@@ -1770,9 +1771,14 @@ static int futex_wait(u32 __user *uaddr, int fshared,
goto out_put_key; goto out_put_key;
/* /*
* We expect signal_pending(current), but another thread may * We expect signal_pending(current), but we might be the
* have handled it for us already. * victim of a spurious wakeup as well.
*/ */
if (!signal_pending(current)) {
put_futex_key(fshared, &q.key);
goto retry;
}
ret = -ERESTARTSYS; ret = -ERESTARTSYS;
if (!abs_time) if (!abs_time)
goto out_put_key; goto out_put_key;
...@@ -2079,9 +2085,11 @@ int handle_early_requeue_pi_wakeup(struct futex_hash_bucket *hb, ...@@ -2079,9 +2085,11 @@ int handle_early_requeue_pi_wakeup(struct futex_hash_bucket *hb,
*/ */
plist_del(&q->list, &q->list.plist); plist_del(&q->list, &q->list.plist);
/* Handle spurious wakeups gracefully */
ret = -EAGAIN;
if (timeout && !timeout->task) if (timeout && !timeout->task)
ret = -ETIMEDOUT; ret = -ETIMEDOUT;
else else if (signal_pending(current))
ret = -ERESTARTNOINTR; ret = -ERESTARTNOINTR;
} }
return ret; return ret;
...@@ -2163,6 +2171,7 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, int fshared, ...@@ -2163,6 +2171,7 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, int fshared,
q.bitset = bitset; q.bitset = bitset;
q.rt_waiter = &rt_waiter; q.rt_waiter = &rt_waiter;
retry:
key2 = FUTEX_KEY_INIT; key2 = FUTEX_KEY_INIT;
ret = get_futex_key(uaddr2, fshared, &key2, VERIFY_WRITE); ret = get_futex_key(uaddr2, fshared, &key2, VERIFY_WRITE);
if (unlikely(ret != 0)) if (unlikely(ret != 0))
...@@ -2255,6 +2264,9 @@ out_put_keys: ...@@ -2255,6 +2264,9 @@ out_put_keys:
out_key2: out_key2:
put_futex_key(fshared, &key2); put_futex_key(fshared, &key2);
/* Spurious wakeup ? */
if (ret == -EAGAIN)
goto retry;
out: out:
if (to) { if (to) {
hrtimer_cancel(&to->timer); hrtimer_cancel(&to->timer);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment