Skip to content

Commit

Permalink
io_uring: move min_events sanitisation
Browse files Browse the repository at this point in the history
iopoll and normal waiting already duplicate min_completion truncation,
so move them inside the corresponding routines.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/254adb289cc04638f25d746a7499260fa89a179e.1742829388.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Pavel Begunkov authored and Jens Axboe committed Mar 25, 2025
1 parent d73acd7 commit 8166197
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions io_uring/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -1505,11 +1505,13 @@ static __cold void io_iopoll_try_reap_events(struct io_ring_ctx *ctx)
mutex_unlock(&ctx->uring_lock);
}

static int io_iopoll_check(struct io_ring_ctx *ctx, long min_events)
static int io_iopoll_check(struct io_ring_ctx *ctx, unsigned int min_events)
{
unsigned int nr_events = 0;
unsigned long check_cq;

min_events = min(min_events, ctx->cq_entries);

lockdep_assert_held(&ctx->uring_lock);

if (!io_allowed_run_tw(ctx))
Expand Down Expand Up @@ -2537,6 +2539,8 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, u32 flags,
ktime_t start_time;
int ret;

min_events = min_t(int, min_events, ctx->cq_entries);

if (!io_allowed_run_tw(ctx))
return -EEXIST;
if (io_local_work_pending(ctx))
Expand Down Expand Up @@ -3420,22 +3424,16 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,
mutex_lock(&ctx->uring_lock);
iopoll_locked:
ret2 = io_validate_ext_arg(ctx, flags, argp, argsz);
if (likely(!ret2)) {
min_complete = min(min_complete,
ctx->cq_entries);
if (likely(!ret2))
ret2 = io_iopoll_check(ctx, min_complete);
}
mutex_unlock(&ctx->uring_lock);
} else {
struct ext_arg ext_arg = { .argsz = argsz };

ret2 = io_get_ext_arg(ctx, flags, argp, &ext_arg);
if (likely(!ret2)) {
min_complete = min(min_complete,
ctx->cq_entries);
if (likely(!ret2))
ret2 = io_cqring_wait(ctx, min_complete, flags,
&ext_arg);
}
}

if (!ret) {
Expand Down

0 comments on commit 8166197

Please sign in to comment.