All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] random setup cleanups
@ 2025-11-10 13:04 Pavel Begunkov
  2025-11-10 13:04 ` [PATCH 1/4] io_uring: add helper calculating region byte size Pavel Begunkov
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Pavel Begunkov @ 2025-11-10 13:04 UTC (permalink / raw)
  To: io-uring; +Cc: asml.silence

Simple cleanups extracted from another series. Nothing noteworthy
apart from that I needed Patch 1 in a couple of places already,
but it's still a good follow up to recent fixes.

Pavel Begunkov (4):
  io_uring: add helper calculating region byte size
  io_uring: pass sq entires in the params struct
  io_uring: use mem_is_zero to check ring params
  io_uring: move flags check to io_uring_sanitise_params

 io_uring/io_uring.c | 22 ++++++++++++----------
 io_uring/io_uring.h |  2 +-
 io_uring/memmap.c   |  4 ++--
 io_uring/memmap.h   |  5 +++++
 io_uring/register.c |  2 +-
 5 files changed, 21 insertions(+), 14 deletions(-)

-- 
2.49.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/4] io_uring: add helper calculating region byte size
  2025-11-10 13:04 [PATCH 0/4] random setup cleanups Pavel Begunkov
@ 2025-11-10 13:04 ` Pavel Begunkov
  2025-11-10 13:04 ` [PATCH 2/4] io_uring: pass sq entires in the params struct Pavel Begunkov
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Pavel Begunkov @ 2025-11-10 13:04 UTC (permalink / raw)
  To: io-uring; +Cc: asml.silence

There has been type related issues with region size calculation, add an
utility helper function that returns the size and handles type
conversions right.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 io_uring/memmap.c | 4 ++--
 io_uring/memmap.h | 5 +++++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/io_uring/memmap.c b/io_uring/memmap.c
index 24da17a5f08f..dc4bfc5b6fb8 100644
--- a/io_uring/memmap.c
+++ b/io_uring/memmap.c
@@ -134,7 +134,7 @@ static int io_region_init_ptr(struct io_mapped_region *mr)
 static int io_region_pin_pages(struct io_mapped_region *mr,
 			       struct io_uring_region_desc *reg)
 {
-	unsigned long size = mr->nr_pages << PAGE_SHIFT;
+	size_t size = io_region_size(mr);
 	struct page **pages;
 	int nr_pages;
 
@@ -154,7 +154,7 @@ static int io_region_allocate_pages(struct io_mapped_region *mr,
 				    unsigned long mmap_offset)
 {
 	gfp_t gfp = GFP_KERNEL_ACCOUNT | __GFP_ZERO | __GFP_NOWARN;
-	size_t size = (size_t) mr->nr_pages << PAGE_SHIFT;
+	size_t size = io_region_size(mr);
 	unsigned long nr_allocated;
 	struct page **pages;
 
diff --git a/io_uring/memmap.h b/io_uring/memmap.h
index a6c63ca2c6f1..d2a940682d19 100644
--- a/io_uring/memmap.h
+++ b/io_uring/memmap.h
@@ -43,4 +43,9 @@ static inline void io_region_publish(struct io_ring_ctx *ctx,
 	*dst_region = *src_region;
 }
 
+static inline size_t io_region_size(struct io_mapped_region *mr)
+{
+	return (size_t)mr->nr_pages << PAGE_SHIFT;
+}
+
 #endif
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/4] io_uring: pass sq entires in the params struct
  2025-11-10 13:04 [PATCH 0/4] random setup cleanups Pavel Begunkov
  2025-11-10 13:04 ` [PATCH 1/4] io_uring: add helper calculating region byte size Pavel Begunkov
@ 2025-11-10 13:04 ` Pavel Begunkov
  2025-11-10 13:04 ` [PATCH 3/4] io_uring: use mem_is_zero to check ring params Pavel Begunkov
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Pavel Begunkov @ 2025-11-10 13:04 UTC (permalink / raw)
  To: io-uring; +Cc: asml.silence

There is no need to pass the user requested number of SQ entries
separately from the main parameter structure io_uring_params. Initialise
it at the beginning and stop passing it in favour of struct
io_uring_params::sq_entries.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 io_uring/io_uring.c | 11 +++++++----
 io_uring/io_uring.h |  2 +-
 io_uring/register.c |  2 +-
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index d11d0e9723a1..023b0e3a829c 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -3479,8 +3479,10 @@ static int io_uring_sanitise_params(struct io_uring_params *p)
 	return 0;
 }
 
-int io_uring_fill_params(unsigned entries, struct io_uring_params *p)
+int io_uring_fill_params(struct io_uring_params *p)
 {
+	unsigned entries = p->sq_entries;
+
 	if (!entries)
 		return -EINVAL;
 	if (entries > IORING_MAX_ENTRIES) {
@@ -3542,7 +3544,7 @@ int io_uring_fill_params(unsigned entries, struct io_uring_params *p)
 	return 0;
 }
 
-static __cold int io_uring_create(unsigned entries, struct io_uring_params *p,
+static __cold int io_uring_create(struct io_uring_params *p,
 				  struct io_uring_params __user *params)
 {
 	struct io_ring_ctx *ctx;
@@ -3554,7 +3556,7 @@ static __cold int io_uring_create(unsigned entries, struct io_uring_params *p,
 	if (ret)
 		return ret;
 
-	ret = io_uring_fill_params(entries, p);
+	ret = io_uring_fill_params(p);
 	if (unlikely(ret))
 		return ret;
 
@@ -3693,7 +3695,8 @@ static long io_uring_setup(u32 entries, struct io_uring_params __user *params)
 
 	if (p.flags & ~IORING_SETUP_FLAGS)
 		return -EINVAL;
-	return io_uring_create(entries, &p, params);
+	p.sq_entries = entries;
+	return io_uring_create(&p, params);
 }
 
 static inline int io_uring_allowed(void)
diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h
index 23c268ab1c8f..b2251446497a 100644
--- a/io_uring/io_uring.h
+++ b/io_uring/io_uring.h
@@ -136,7 +136,7 @@ static inline bool io_should_wake(struct io_wait_queue *iowq)
 
 unsigned long rings_size(unsigned int flags, unsigned int sq_entries,
 			 unsigned int cq_entries, size_t *sq_offset);
-int io_uring_fill_params(unsigned entries, struct io_uring_params *p);
+int io_uring_fill_params(struct io_uring_params *p);
 bool io_cqe_cache_refill(struct io_ring_ctx *ctx, bool overflow, bool cqe32);
 int io_run_task_work_sig(struct io_ring_ctx *ctx);
 int io_run_local_work(struct io_ring_ctx *ctx, int min_events, int max_events);
diff --git a/io_uring/register.c b/io_uring/register.c
index 023f5e7a18da..afb924ceb9b6 100644
--- a/io_uring/register.c
+++ b/io_uring/register.c
@@ -416,7 +416,7 @@ static int io_register_resize_rings(struct io_ring_ctx *ctx, void __user *arg)
 	/* properties that are always inherited */
 	p.flags |= (ctx->flags & COPY_FLAGS);
 
-	ret = io_uring_fill_params(p.sq_entries, &p);
+	ret = io_uring_fill_params(&p);
 	if (unlikely(ret))
 		return ret;
 
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/4] io_uring: use mem_is_zero to check ring params
  2025-11-10 13:04 [PATCH 0/4] random setup cleanups Pavel Begunkov
  2025-11-10 13:04 ` [PATCH 1/4] io_uring: add helper calculating region byte size Pavel Begunkov
  2025-11-10 13:04 ` [PATCH 2/4] io_uring: pass sq entires in the params struct Pavel Begunkov
@ 2025-11-10 13:04 ` Pavel Begunkov
  2025-11-10 13:04 ` [PATCH 4/4] io_uring: move flags check to io_uring_sanitise_params Pavel Begunkov
  2025-11-10 22:02 ` [PATCH 0/4] random setup cleanups Jens Axboe
  4 siblings, 0 replies; 6+ messages in thread
From: Pavel Begunkov @ 2025-11-10 13:04 UTC (permalink / raw)
  To: io-uring; +Cc: asml.silence

mem_is_zero() does the job without hand rolled loops, use that to verify
reserved fields of ring params.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 io_uring/io_uring.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 023b0e3a829c..af7b4cbe9850 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -3684,14 +3684,12 @@ static __cold int io_uring_create(struct io_uring_params *p,
 static long io_uring_setup(u32 entries, struct io_uring_params __user *params)
 {
 	struct io_uring_params p;
-	int i;
 
 	if (copy_from_user(&p, params, sizeof(p)))
 		return -EFAULT;
-	for (i = 0; i < ARRAY_SIZE(p.resv); i++) {
-		if (p.resv[i])
-			return -EINVAL;
-	}
+
+	if (!mem_is_zero(&p.resv, sizeof(p.resv)))
+		return -EINVAL;
 
 	if (p.flags & ~IORING_SETUP_FLAGS)
 		return -EINVAL;
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/4] io_uring: move flags check to io_uring_sanitise_params
  2025-11-10 13:04 [PATCH 0/4] random setup cleanups Pavel Begunkov
                   ` (2 preceding siblings ...)
  2025-11-10 13:04 ` [PATCH 3/4] io_uring: use mem_is_zero to check ring params Pavel Begunkov
@ 2025-11-10 13:04 ` Pavel Begunkov
  2025-11-10 22:02 ` [PATCH 0/4] random setup cleanups Jens Axboe
  4 siblings, 0 replies; 6+ messages in thread
From: Pavel Begunkov @ 2025-11-10 13:04 UTC (permalink / raw)
  To: io-uring; +Cc: asml.silence

io_uring_sanitise_params() sanitises most of the setup flags invariants,
move the IORING_SETUP_FLAGS check from io_uring_setup() into it.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 io_uring/io_uring.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index af7b4cbe9850..7e069d56b8a1 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -3430,6 +3430,9 @@ static int io_uring_sanitise_params(struct io_uring_params *p)
 {
 	unsigned flags = p->flags;
 
+	if (flags & ~IORING_SETUP_FLAGS)
+		return -EINVAL;
+
 	/* There is no way to mmap rings without a real fd */
 	if ((flags & IORING_SETUP_REGISTERED_FD_ONLY) &&
 	    !(flags & IORING_SETUP_NO_MMAP))
@@ -3691,8 +3694,6 @@ static long io_uring_setup(u32 entries, struct io_uring_params __user *params)
 	if (!mem_is_zero(&p.resv, sizeof(p.resv)))
 		return -EINVAL;
 
-	if (p.flags & ~IORING_SETUP_FLAGS)
-		return -EINVAL;
 	p.sq_entries = entries;
 	return io_uring_create(&p, params);
 }
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/4] random setup cleanups
  2025-11-10 13:04 [PATCH 0/4] random setup cleanups Pavel Begunkov
                   ` (3 preceding siblings ...)
  2025-11-10 13:04 ` [PATCH 4/4] io_uring: move flags check to io_uring_sanitise_params Pavel Begunkov
@ 2025-11-10 22:02 ` Jens Axboe
  4 siblings, 0 replies; 6+ messages in thread
From: Jens Axboe @ 2025-11-10 22:02 UTC (permalink / raw)
  To: io-uring, Pavel Begunkov


On Mon, 10 Nov 2025 13:04:48 +0000, Pavel Begunkov wrote:
> Simple cleanups extracted from another series. Nothing noteworthy
> apart from that I needed Patch 1 in a couple of places already,
> but it's still a good follow up to recent fixes.
> 
> Pavel Begunkov (4):
>   io_uring: add helper calculating region byte size
>   io_uring: pass sq entires in the params struct
>   io_uring: use mem_is_zero to check ring params
>   io_uring: move flags check to io_uring_sanitise_params
> 
> [...]

Applied, thanks!

[1/4] io_uring: add helper calculating region byte size
      commit: c5b09a6d1dfab3ac97230cc91a32d19a8f692232
[2/4] io_uring: pass sq entires in the params struct
      (no commit info)
[3/4] io_uring: use mem_is_zero to check ring params
      commit: 44d5ba73f6147b36316c713094ef56a7d93e5076
[4/4] io_uring: move flags check to io_uring_sanitise_params
      commit: 4d7352becf5609047112f91883071a289c44e221

Best regards,
-- 
Jens Axboe




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-11-10 22:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-10 13:04 [PATCH 0/4] random setup cleanups Pavel Begunkov
2025-11-10 13:04 ` [PATCH 1/4] io_uring: add helper calculating region byte size Pavel Begunkov
2025-11-10 13:04 ` [PATCH 2/4] io_uring: pass sq entires in the params struct Pavel Begunkov
2025-11-10 13:04 ` [PATCH 3/4] io_uring: use mem_is_zero to check ring params Pavel Begunkov
2025-11-10 13:04 ` [PATCH 4/4] io_uring: move flags check to io_uring_sanitise_params Pavel Begunkov
2025-11-10 22:02 ` [PATCH 0/4] random setup cleanups Jens Axboe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.