]> git.baikalelectronics.ru Git - kernel.git/commit
io_uring: fix concurrent parking
authorPavel Begunkov <asml.silence@gmail.com>
Sun, 14 Mar 2021 20:57:12 +0000 (20:57 +0000)
committerJens Axboe <axboe@kernel.dk>
Mon, 15 Mar 2021 15:32:40 +0000 (09:32 -0600)
commit121966f760a853750abc73eb8010dc6a4e9b3fc6
tree68225f0800698772485a206aac799d7c80259047
parent20f4367d17dff1dbd48d33b6f8d22eac6a82aa06
io_uring: fix concurrent parking

If io_sq_thread_park() of one task got rescheduled right after
set_bit(), before it gets back to mutex_lock() there can happen
park()/unpark() by another task with SQPOLL locking again and
continuing running never seeing that first set_bit(SHOULD_PARK),
so won't even try to put the mutex down for parking.

It will get parked eventually when SQPOLL drops the lock for reschedule,
but may be problematic and will get in the way of further fixes.

Account number of tasks waiting for parking with a new atomic variable
park_pending and adjust SHOULD_PARK accordingly. It doesn't entirely
replaces SHOULD_PARK bit with this atomic var because it's convenient
to have it as a bit in the state and will help to do optimisations
later.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
fs/io_uring.c