io_uring: fix REQ_F_COMP_LOCKED by killing it
authorPavel Begunkov <asml.silence@gmail.com>
Tue, 13 Oct 2020 08:44:00 +0000 (09:44 +0100)
committerJens Axboe <axboe@kernel.dk>
Thu, 15 Oct 2020 17:50:08 +0000 (11:50 -0600)
commit2c4b40a91954a54552151b95aeaf98bb4c8064bf
tree8a792ab4a15cd03f7b27f06594b61c8571d9f32c
parent99cc3a1c73f5c43b03cb17e1f5ba863a7ba316d3
io_uring: fix REQ_F_COMP_LOCKED by killing it

REQ_F_COMP_LOCKED is used and implemented in a buggy way. The problem is
that the flag is set before io_put_req() but not cleared after, and if
that wasn't the final reference, the request will be freed with the flag
set from some other context, which may not hold a spinlock. That means
possible races with removing linked timeouts and unsynchronised
completion (e.g. access to CQ).

Instead of fixing REQ_F_COMP_LOCKED, kill the flag and use
task_work_add() to move such requests to a fresh context to free from
it, as was done with __io_free_req_finish().

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