]> www.infradead.org Git - users/hch/block.git/commit
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>
Mon, 30 Aug 2021 17:55:22 +0000 (11:55 -0600)
commitf58d8b759ff8a80cd409bc6c29df9085bc81b8ff
tree91bcdf9057c30c2bee8953f3c6cb4243540e3580
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