Re: Patch for lost wakeups

From: Oleg Nesterov
Date: Thu Aug 08 2013 - 15:23:48 EST


On 08/08, Linus Torvalds wrote:
>
> As a result, doing a "recalc_sigpending_and_wake(()"

and btw it should die, I think.

> is definitely
> incorrect, because sigpending state cannot actually have changed.

Yes, if we need to wakeup in this case something is already wrong.

> - somebody setting TASK_SLEEPING -> __schedule() testing the
> signal_pending_state()
>
> and as far as I can tell we have proper barriers for those (the
> scheduler gets the rq lock

Yes, but... ttwu() takse another lock, ->pi_lock to test ->state.

This looks racy, even if wmb() actually acts as mb(), we don't
have mb() on the other side and schedule() can miss SIGPENDING?

Unless the task does set_current_state(TASK_INTERRUPTIBLE) which
adds mb(). But, just for example, sigsuspend() relies on schedule().

> smp_wmb();
> raw_spin_lock_irqsave(&p->pi_lock, flags);
> if (!(p->state & state))
>
> before it tests the task state. And the wmb() *together* with the
> spinlock really should be a full memory barrier (nothing can get out
> from the spinlock, and any writes before this had better be serialized
> by the wmb and the write inherent in the spinlock itself). But this is
> definitely some subtle stuff.

So perhaps it makes sense to re-test after s/smp_wmb/smp_mb/ ?

And perhaps we can add smp_mb__before_lock(), we alredy have
smp_mb__after_lock().

And of course, there could be another bug. I just did
"grep recalc_sigpending" and immediately found at least one buggy
user, fs/dlm/user.c which calls it lockless.

> > Every time Xorg hangs up, the status of Xorg is read as following(cat /proc/2597/status):

Gao, could you show /proc/pid/stack just in case?

Oleg.

--
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/