Re: [PATCH 2/2] sched/wait: avoid abort_exclusive_wait() in __wait_on_bit_lock()

From: Peter Zijlstra
Date: Thu Sep 01 2016 - 18:17:57 EST


On Thu, Sep 01, 2016 at 09:01:41PM +0200, Peter Zijlstra wrote:
> On Fri, Aug 26, 2016 at 02:45:52PM +0200, Oleg Nesterov wrote:
>
> > We do not need anything tricky to avoid the race,
>
> The race being:
>
> CPU0 CPU1 CPU2
>
> __wait_on_bit_lock()
> bit_wait_io()
> io_schedule()
>
> clear_bit_unlock()
> __wake_up_common(.nr_exclusive=1)
> list_for_each_entry()
> if (curr->func() && --nr_exclusive)
> break
>
> signal()
>
> if (signal_pending_state()) == TRUE
> return -EINTR
>
> And no progress because CPU1 exits without acquiring the lock and CPU0
> thinks its done because it woke someone.

FWIW, the way the mutex code avoids this issue is by doing the
signal_pending test while holding the q->lock, that way its exclusive
with wakeup.