diff mbox series

[2/3] io_uring: cap io_sqring_entries() at SQ ring size

Message ID 20230330163347.1645578-3-axboe@kernel.dk (mailing list archive)
State New
Headers show
Series Misc cleanups | expand

Commit Message

Jens Axboe March 30, 2023, 4:33 p.m. UTC
We already do this manually for the !SQPOLL case, do it in general and
we can also dump the ugly min3() in io_submit_sqes().

Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 io_uring/io_uring.c | 2 +-
 io_uring/io_uring.h | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 775b53730c2f..a0b64831c455 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -2434,7 +2434,7 @@  int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr)
 	if (unlikely(!entries))
 		return 0;
 	/* make sure SQ entry isn't read before tail */
-	ret = left = min3(nr, ctx->sq_entries, entries);
+	ret = left = min(nr, entries);
 	io_get_task_refs(left);
 	io_submit_state_start(&ctx->submit_state, left);
 
diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h
index c33f719731ac..193b2db39fe8 100644
--- a/io_uring/io_uring.h
+++ b/io_uring/io_uring.h
@@ -262,9 +262,11 @@  static inline bool io_sqring_full(struct io_ring_ctx *ctx)
 static inline unsigned int io_sqring_entries(struct io_ring_ctx *ctx)
 {
 	struct io_rings *rings = ctx->rings;
+	unsigned int entries;
 
 	/* make sure SQ entry isn't read before tail */
-	return smp_load_acquire(&rings->sq.tail) - ctx->cached_sq_head;
+	entries = smp_load_acquire(&rings->sq.tail) - ctx->cached_sq_head;
+	return min(entries, ctx->sq_entries);
 }
 
 static inline int io_run_task_work(void)