Re: [patch] futex: Cure exit race

From: Thomas Gleixner
Date: Tue Dec 18 2018 - 04:31:11 EST


On Wed, 12 Dec 2018, Peter Zijlstra wrote:
> On Mon, Dec 10, 2018 at 06:43:51PM +0100, Thomas Gleixner wrote:
> @@ -806,6 +806,8 @@ void __noreturn do_exit(long code)
> * task into the wait for ever nirwana as well.
> */
> tsk->flags |= PF_EXITPIDONE;
> + smp_mb();
> + wake_up_bit(&tsk->flags, 3 /* PF_EXITPIDONE */);

Using ilog2(PF_EXITPIDONE) spares that horrible inline comment and more
importantly selects the right bit. 0x04 is bit 2 ....

> @@ -1187,10 +1236,15 @@ static int attach_to_pi_owner(u32 uval, union futex_key *key,
> * set, we know that the task has finished the
> * cleanup:
> */
> int ret = handle_exit_race(uaddr, uval, p);
>
> raw_spin_unlock_irq(&p->pi_lock);
> - put_task_struct(p);
> +
> + if (ret == -EAGAIN)
> + *pe = p;

Hmm, no. We really want to split the return value for that. EAGAIN is also
returned for other reasons.

Plus requeue_pi() needs the same treatment. I'm staring into it, but all I
came up with so far is horribly ugly.

Thanks,

tglx