Skip to content

Commit b4ccc4d

Browse files
committed
io_uring/napi: enable even with a timeout of 0
1 usec is not as short as it used to be, and it makes sense to allow 0 for a busy poll timeout - this means just do one loop to check if we have anything available. Add a separate ->napi_enabled to check if napi has been enabled or not. While at it, move the writing of the ctx napi values after we've copied the old values back to userspace. This ensures that if the call fails, we'll be in the same state as we were before, rather than some indeterminate state. Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 871760e commit b4ccc4d

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

include/linux/io_uring_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ struct io_ring_ctx {
420420
/* napi busy poll default timeout */
421421
unsigned int napi_busy_poll_to;
422422
bool napi_prefer_busy_poll;
423+
bool napi_enabled;
423424

424425
DECLARE_HASHTABLE(napi_ht, 4);
425426
#endif

io_uring/napi.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,12 @@ int io_register_napi(struct io_ring_ctx *ctx, void __user *arg)
227227
if (napi.pad[0] || napi.pad[1] || napi.pad[2] || napi.resv)
228228
return -EINVAL;
229229

230-
WRITE_ONCE(ctx->napi_busy_poll_to, napi.busy_poll_to);
231-
WRITE_ONCE(ctx->napi_prefer_busy_poll, !!napi.prefer_busy_poll);
232-
233230
if (copy_to_user(arg, &curr, sizeof(curr)))
234231
return -EFAULT;
235232

233+
WRITE_ONCE(ctx->napi_busy_poll_to, napi.busy_poll_to);
234+
WRITE_ONCE(ctx->napi_prefer_busy_poll, !!napi.prefer_busy_poll);
235+
WRITE_ONCE(ctx->napi_enabled, true);
236236
return 0;
237237
}
238238

@@ -256,6 +256,7 @@ int io_unregister_napi(struct io_ring_ctx *ctx, void __user *arg)
256256

257257
WRITE_ONCE(ctx->napi_busy_poll_to, 0);
258258
WRITE_ONCE(ctx->napi_prefer_busy_poll, false);
259+
WRITE_ONCE(ctx->napi_enabled, false);
259260
return 0;
260261
}
261262

@@ -300,7 +301,7 @@ void __io_napi_busy_loop(struct io_ring_ctx *ctx, struct io_wait_queue *iowq)
300301
{
301302
iowq->napi_prefer_busy_poll = READ_ONCE(ctx->napi_prefer_busy_poll);
302303

303-
if (!(ctx->flags & IORING_SETUP_SQPOLL) && iowq->napi_busy_poll_to)
304+
if (!(ctx->flags & IORING_SETUP_SQPOLL) && ctx->napi_enabled)
304305
io_napi_blocking_busy_loop(ctx, iowq);
305306
}
306307

0 commit comments

Comments
 (0)