Re: [patch -rt] Fix infinite loop with 2.6.31.4-rt14 V2

From: Darren Hart
Date: Fri Oct 23 2009 - 16:41:29 EST


Dinakar Guniguntala wrote:
> Application threads calling futex_wait_requeue_pi run in an infinite loop
> in the kernel if the futex value changes during the call. The following
> patch fixes the problem.

The key bit here being that EAGAIN == EWOULDBLOCK - who thought that was a good idea?

>
> Signed-off-by: Dinakar Guniguntala <dino@xxxxxxxxxx>
> Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
> Cc: Darren Hart <dvhltc@xxxxxxxxxx>

Signed-off-by: Darren Hart <dvhltc@xxxxxxxxxx>

Adding the usual CC list for futexes as well as stable:

Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxx>
CC: Eric Dumazet <eric.dumazet@xxxxxxxxx>
CC: John Stultz <johnstul@xxxxxxxxxx>
CC: stable@xxxxxxxxxx

>
> ---
> kernel/futex.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> Index: linux-2.6.31.4-rt14-lbf-f1/kernel/futex.c
> ===================================================================
> --- linux-2.6.31.4-rt14-lbf-f1.orig/kernel/futex.c
> +++ linux-2.6.31.4-rt14-lbf-f1/kernel/futex.c
> @@ -2188,6 +2188,12 @@ retry:
> spin_lock(&hb->lock);
> ret = handle_early_requeue_pi_wakeup(hb, &q, &key2, to);
> spin_unlock(&hb->lock);
> + if (ret == -EAGAIN) {
> + /* Retry on spurious wakeup */
> + put_futex_key(fshared, &q.key);
> + put_futex_key(fshared, &key2);
> + goto retry;
> + }
> if (ret)
> goto out_put_keys;
>
> @@ -2264,9 +2270,6 @@ out_put_keys:
> out_key2:
> put_futex_key(fshared, &key2);
>
> - /* Spurious wakeup ? */
> - if (ret == -EAGAIN)
> - goto retry;
> out:
> if (to) {
> hrtimer_cancel(&to->timer);


--
Darren Hart
IBM Linux Technology Center
Real-Time Linux Team
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/