io-wq: fix race between adding work and activating a free worker
authorJens Axboe <axboe@kernel.dk>
Mon, 30 Aug 2021 17:55:22 +0000 (11:55 -0600)
committerJens Axboe <axboe@kernel.dk>
Tue, 31 Aug 2021 17:45:27 +0000 (11:45 -0600)
commit94ffb0a282872c2f4b14f757fa1aef2302aeaabb
tree5d8cdeace9484d67ad0270f97d5e88244a052148
parent87df7fb922d18e96992aa5e824aa34b2065fef59
io-wq: fix race between adding work and activating a free worker

The attempt to find and activate a free worker for new work is currently
combined with creating a new one if we don't find one, but that opens
io-wq up to a race where the worker that is found and activated can
put itself to sleep without knowing that it has been selected to perform
this new work.

Fix this by moving the activation into where we add the new work item,
then we can retain it within the wqe->lock scope and elimiate the race
with the worker itself checking inside the lock, but sleeping outside of
it.

Cc: stable@vger.kernel.org
Reported-by: Andres Freund <andres@anarazel.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
fs/io-wq.c