mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yichong Chen <chenyichong@uniontech.com>
To: Jens Axboe <axboe@kernel.dk>, io-uring@vger.kernel.org
Cc: Pavel Begunkov <asml.silence@gmail.com>,
	linux-kernel@vger.kernel.org,
	Yichong Chen <chenyichong@uniontech.com>
Subject: [PATCH] io_uring/wait: clamp min_events as unsigned
Date: Tue, 24 Nov 2026 13:54:16 +0800	[thread overview]
Message-ID: <20261124055416.1641002-1-chenyichong@uniontech.com> (raw)

io_cqring_wait() clamps min_events with min_t(int, ...), but
io_uring_enter() passes the u32 min_complete straight in. Anything above
INT_MAX is negative by then, so the clamp is a no-op and
io_should_wake() reads cq.tail + min_events as a positive distance from
cq.tail. The wait returns 0 with no events available instead of blocking
for the clamped count; min_complete = 0xffffffff returns immediately,
while 1 and INT_MAX block for the timeout as expected. Clamp as unsigned,
as io_iopoll_check() already does.

Fixes: 816619782bdc ("io_uring: move min_events sanitisation")
Signed-off-by: Yichong Chen <chenyichong@uniontech.com>
---
 io_uring/wait.c | 4 ++--
 io_uring/wait.h | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/io_uring/wait.c b/io_uring/wait.c
index fb1c082993a7..074cdf073ca7 100644
--- a/io_uring/wait.c
+++ b/io_uring/wait.c
@@ -204,7 +204,7 @@ static inline int io_cqring_wait_schedule(struct io_ring_ctx *ctx,
  * Wait until events become available, if we don't already have some. The
  * application must reap them itself, as they reside on the shared cq ring.
  */
-int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, u32 flags,
+int io_cqring_wait(struct io_ring_ctx *ctx, unsigned int min_events, u32 flags,
 		   struct ext_arg *ext_arg)
 {
 	struct io_wait_queue iowq;
@@ -212,7 +212,7 @@ int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, u32 flags,
 	ktime_t start_time;
 	int ret, nr_wait;
 
-	min_events = min_t(int, min_events, ctx->cq_entries);
+	min_events = min(min_events, ctx->cq_entries);
 
 	if (!io_allowed_run_tw(ctx))
 		return -EEXIST;
diff --git a/io_uring/wait.h b/io_uring/wait.h
index eb5ae8a6fc94..07e1e9ea03cd 100644
--- a/io_uring/wait.h
+++ b/io_uring/wait.h
@@ -38,7 +38,7 @@ struct ext_arg {
 	bool iowait;
 };
 
-int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, u32 flags,
+int io_cqring_wait(struct io_ring_ctx *ctx, unsigned int min_events, u32 flags,
 		   struct ext_arg *ext_arg);
 int io_run_task_work_sig(struct io_ring_ctx *ctx);
 void io_cqring_do_overflow_flush(struct io_ring_ctx *ctx);
-- 
2.51.0


                 reply	other threads:[~2026-11-24  5:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261124055416.1641002-1-chenyichong@uniontech.com \
    --to=chenyichong@uniontech.com \
    --cc=asml.silence@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=io-uring@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®