io_uring/napi: fix timeout calculation
authorJens Axboe <axboe@kernel.dk>
Mon, 3 Jun 2024 19:56:53 +0000 (13:56 -0600)
committerJens Axboe <axboe@kernel.dk>
Tue, 4 Jun 2024 13:32:45 +0000 (07:32 -0600)
commit415ce0ea55c5a3afea501a773e002be9ed7149f5
tree90ee6986b77512f5dcaee4b805a100169057f186
parent5fc16fa5f13b3c06fdb959ef262050bd810416a2
io_uring/napi: fix timeout calculation

Not quite sure what __io_napi_adjust_timeout() was attemping to do, it's
adjusting both the NAPI timeout and the general overall timeout, and
calculating a value that is never used. The overall timeout is a super
set of the NAPI timeout, and doesn't need adjusting. The only thing we
really need to care about is that the NAPI timeout doesn't exceed the
overall timeout. If a user asked for a timeout of eg 5 usec and NAPI
timeout is 10 usec, then we should not spin for 10 usec.

While in there, sanitize the time checking a bit. If we have a negative
value in the passed in timeout, discard it. Round up the value as well,
so we don't end up with a NAPI timeout for the majority of the wait,
with only a tiny sleep value at the end.

Hence the only case we need to care about is if the NAPI timeout is
larger than the overall timeout. If it is, cap the NAPI timeout at what
the overall timeout is.

Cc: stable@vger.kernel.org
Fixes: 8d0c12a80cde ("io-uring: add napi busy poll support")
Reported-by: Lewis Baker <lewissbaker@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_uring/napi.c