io_uring: disallow defer-tw run w/ no submitters

We try to restrict CQ waiters when IORING_SETUP_DEFER_TASKRUN is set,
but if nothing has been submitted yet it'll allow any waiter, which
violates the contract.

Fixes: c0e0d6ba25 ("io_uring: add IORING_SETUP_DEFER_TASKRUN")
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Reviewed-by: Dylan Yudaken <dylany@fb.com>
Link: https://lore.kernel.org/r/b4f0d3f14236d7059d08c5abe2661ef0b78b5528.1662652536.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Pavel Begunkov 2022-09-08 16:56:53 +01:00 committed by Jens Axboe
parent 76de6749d1
commit 6567506b68
2 changed files with 3 additions and 13 deletions

View File

@ -1169,13 +1169,8 @@ int __io_run_local_work(struct io_ring_ctx *ctx, bool locked)
int ret; int ret;
unsigned int loops = 1; unsigned int loops = 1;
if (unlikely(ctx->submitter_task != current)) { if (unlikely(ctx->submitter_task != current))
/* maybe this is before any submissions */
if (!ctx->submitter_task)
return 0;
return -EEXIST; return -EEXIST;
}
node = io_llist_xchg(&ctx->work_llist, &fake); node = io_llist_xchg(&ctx->work_llist, &fake);
ret = 0; ret = 0;

View File

@ -331,13 +331,8 @@ static inline struct io_kiocb *io_alloc_req(struct io_ring_ctx *ctx)
static inline bool io_allowed_run_tw(struct io_ring_ctx *ctx) static inline bool io_allowed_run_tw(struct io_ring_ctx *ctx)
{ {
if (!(ctx->flags & IORING_SETUP_DEFER_TASKRUN)) return likely(!(ctx->flags & IORING_SETUP_DEFER_TASKRUN) ||
return true; ctx->submitter_task == current);
if (unlikely(ctx->submitter_task != current)) {
/* maybe this is before any submissions */
return !ctx->submitter_task;
}
return true;
} }
#endif #endif