Re: [patch] futex: Cure exit race

From: Thomas Gleixner
Date: Mon Dec 10 2018 - 12:44:01 EST

On Mon, 10 Dec 2018, Peter Zijlstra wrote:
> On Mon, Dec 10, 2018 at 04:23:06PM +0100, Thomas Gleixner wrote:
> There is another callers of futex_lock_pi_atomic(),
> futex_proxy_trylock_atomic(), which is part of futex_requeue(), that too
> does a retry loop on -EAGAIN.
> And there is another caller of attach_to_pi_owner(): lookup_pi_state(),
> and that too is in futex_requeue() and handles the retry case properly.
> Yes, this all looks good.
> Acked-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>

Bah. The little devil in the unconcious part of my brain insisted on
thinking further about that EAGAIN loop even despite my attempt to page
that futex horrors out again immediately after sending that patch.

There is another related issue which is even worse than just mildly
confusing user space:

task1->flags |= PF_EXITING;

---> preemption

attach_to_pi_owner() {
if (!task1->flags & PF_EXITING) {
} else {
if (!(tsk->flags & PF_EXITPIDONE))
return -EAGAIN;

Now assume UP or both tasks pinned on the same CPU. That results in a
livelock because task2 is going to loop forever.

No immediate idea how to cure that one w/o creating a mess.