Skip to content

Commit 8166197

Browse files
isilenceaxboe
authored andcommitted
io_uring: move min_events sanitisation
iopoll and normal waiting already duplicate min_completion truncation, so move them inside the corresponding routines. Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/254adb289cc04638f25d746a7499260fa89a179e.1742829388.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent d73acd7 commit 8166197

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

io_uring/io_uring.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,11 +1505,13 @@ static __cold void io_iopoll_try_reap_events(struct io_ring_ctx *ctx)
15051505
mutex_unlock(&ctx->uring_lock);
15061506
}
15071507

1508-
static int io_iopoll_check(struct io_ring_ctx *ctx, long min_events)
1508+
static int io_iopoll_check(struct io_ring_ctx *ctx, unsigned int min_events)
15091509
{
15101510
unsigned int nr_events = 0;
15111511
unsigned long check_cq;
15121512

1513+
min_events = min(min_events, ctx->cq_entries);
1514+
15131515
lockdep_assert_held(&ctx->uring_lock);
15141516

15151517
if (!io_allowed_run_tw(ctx))
@@ -2537,6 +2539,8 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, u32 flags,
25372539
ktime_t start_time;
25382540
int ret;
25392541

2542+
min_events = min_t(int, min_events, ctx->cq_entries);
2543+
25402544
if (!io_allowed_run_tw(ctx))
25412545
return -EEXIST;
25422546
if (io_local_work_pending(ctx))
@@ -3420,22 +3424,16 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,
34203424
mutex_lock(&ctx->uring_lock);
34213425
iopoll_locked:
34223426
ret2 = io_validate_ext_arg(ctx, flags, argp, argsz);
3423-
if (likely(!ret2)) {
3424-
min_complete = min(min_complete,
3425-
ctx->cq_entries);
3427+
if (likely(!ret2))
34263428
ret2 = io_iopoll_check(ctx, min_complete);
3427-
}
34283429
mutex_unlock(&ctx->uring_lock);
34293430
} else {
34303431
struct ext_arg ext_arg = { .argsz = argsz };
34313432

34323433
ret2 = io_get_ext_arg(ctx, flags, argp, &ext_arg);
3433-
if (likely(!ret2)) {
3434-
min_complete = min(min_complete,
3435-
ctx->cq_entries);
3434+
if (likely(!ret2))
34363435
ret2 = io_cqring_wait(ctx, min_complete, flags,
34373436
&ext_arg);
3438-
}
34393437
}
34403438

34413439
if (!ret) {

0 commit comments

Comments
 (0)