io_uring: fix mis-refcounting linked timeouts
authorPavel Begunkov <asml.silence@gmail.com>
Fri, 3 Jul 2020 19:15:06 +0000 (22:15 +0300)
committerJens Axboe <axboe@kernel.dk>
Sun, 5 Jul 2020 21:07:35 +0000 (15:07 -0600)
commit6df1db6b542436c6d429caa66e1045862fa36155
treed89e1b5a8d3dba341bef5a0c4a0035b8ce9424fd
parentc2c4c83c58cbca23527fee93b49738a5a84272a1
io_uring: fix mis-refcounting linked timeouts

io_prep_linked_timeout() sets REQ_F_LINK_TIMEOUT altering refcounting of
the following linked request. After that someone should call
io_queue_linked_timeout(), otherwise a submission reference of the linked
timeout won't be ever dropped.

That's what happens in io_steal_work() if io-wq decides to postpone linked
request with io_wqe_enqueue(). io_queue_linked_timeout() can also be
potentially called twice without synchronisation during re-submission,
e.g. io_rw_resubmit().

There are the rules, whoever did io_prep_linked_timeout() must also call
io_queue_linked_timeout(). To not do it twice, io_prep_linked_timeout()
will return non NULL only for the first call. That's controlled by
REQ_F_LINK_TIMEOUT flag.

Also kill REQ_F_QUEUE_TIMEOUT.

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