• Jens Axboe's avatar
    io-wq: fix wakeup race when adding new work · 87df7fb9
    Jens Axboe authored
    When new work is added, io_wqe_enqueue() checks if we need to wake or
    create a new worker. But that check is done outside the lock that
    otherwise synchronizes us with a worker going to sleep, so we can end
    up in the following situation:
    
    CPU0				CPU1
    lock
    insert work
    unlock
    atomic_read(nr_running) != 0
    				lock
    				atomic_dec(nr_running)
    no wakeup needed
    
    Hold the wqe lock around the "need to wakeup" check. Then we can also get
    rid of the temporary work_flags variable, as we know the work will remain
    valid as long as we hold the lock.
    
    Cc: stable@vger.kernel.org
    Reported-by: default avatarAndres Freund <andres@anarazel.de>
    Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
    87df7fb9
io-wq.c 28.7 KB