io_uring: fix -ENOENT issue with linked timer with short timeout
authorJens Axboe <axboe@kernel.dk>
Mon, 11 Nov 2019 06:34:16 +0000 (23:34 -0700)
committerJens Axboe <axboe@kernel.dk>
Mon, 11 Nov 2019 23:33:22 +0000 (16:33 -0700)
commit76a46e066e2d93bd333599d1c84c605c2c4cc909
tree82fcc39ec1a8553c24ae5d87f679777e494a6bc1
parent768134d4f48109b90f4248feecbeeb7d684e410c
io_uring: fix -ENOENT issue with linked timer with short timeout

If you prep a read (for example) that needs to get punted to async
context with a timer, if the timeout is sufficiently short, the timer
request will get completed with -ENOENT as it could not find the read.

The issue is that we prep and start the timer before we start the read.
Hence the timer can trigger before the read is even started, and the end
result is then that the timer completes with -ENOENT, while the read
starts instead of being cancelled by the timer.

Fix this by splitting the linked timer into two parts:

1) Prep and validate the linked timer
2) Start timer

The read is then started between steps 1 and 2, so we know that the
timer will always have a consistent view of the read request state.

Reported-by: Hrvoje Zeba <zeba.hrvoje@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
fs/io_uring.c