From: Pavel Begunkov <asml.silence@gmail.com>
To: io-uring@vger.kernel.org
Cc: asml.silence@gmail.com
Subject: [RFC 14/16] io_uring: extract io_create_mem_region
Date: Thu, 6 Nov 2025 17:01:53 +0000 [thread overview]
Message-ID: <587665fd1a5ec94914edec3e7b049afbe1f7898e.1762447538.git.asml.silence@gmail.com> (raw)
In-Reply-To: <cover.1762447538.git.asml.silence@gmail.com>
Extract a helper function for creating a memory region but that can be
used at setup and not only in io_uring_register(). Specifically, it
doesn't check IORING_SETUP_R_DISABLED.
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
io_uring/io_uring.h | 3 +++
io_uring/register.c | 43 +++++++++++++++++++++++++------------------
2 files changed, 28 insertions(+), 18 deletions(-)
diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h
index ed57ab4161db..20f6ca4696c1 100644
--- a/io_uring/io_uring.h
+++ b/io_uring/io_uring.h
@@ -200,6 +200,9 @@ void io_queue_next(struct io_kiocb *req);
void io_task_refs_refill(struct io_uring_task *tctx);
bool __io_alloc_req_refill(struct io_ring_ctx *ctx);
+int io_create_mem_region(struct io_ring_ctx *ctx,
+ struct io_uring_mem_region_reg *reg);
+
void io_activate_pollwq(struct io_ring_ctx *ctx);
static inline void io_lockdep_assert_cq_locked(struct io_ring_ctx *ctx)
diff --git a/io_uring/register.c b/io_uring/register.c
index b43a121e2974..425529a30dd9 100644
--- a/io_uring/register.c
+++ b/io_uring/register.c
@@ -572,10 +572,9 @@ static int io_register_resize_rings(struct io_ring_ctx *ctx, void __user *arg)
return ret;
}
-static int io_register_mem_region(struct io_ring_ctx *ctx, void __user *uarg)
+int io_create_mem_region(struct io_ring_ctx *ctx,
+ struct io_uring_mem_region_reg *reg)
{
- struct io_uring_mem_region_reg __user *reg_uptr = uarg;
- struct io_uring_mem_region_reg reg;
struct io_uring_region_desc __user *rd_uptr;
struct io_uring_region_desc rd;
struct io_mapped_region region = {};
@@ -583,23 +582,12 @@ static int io_register_mem_region(struct io_ring_ctx *ctx, void __user *uarg)
if (io_region_is_set(&ctx->param_region))
return -EBUSY;
- if (copy_from_user(®, reg_uptr, sizeof(reg)))
- return -EFAULT;
- rd_uptr = u64_to_user_ptr(reg.region_uptr);
+ rd_uptr = u64_to_user_ptr(reg->region_uptr);
if (copy_from_user(&rd, rd_uptr, sizeof(rd)))
return -EFAULT;
- if (memchr_inv(®.__resv, 0, sizeof(reg.__resv)))
+ if (memchr_inv(®->__resv, 0, sizeof(reg->__resv)))
return -EINVAL;
- if (reg.flags & ~IORING_MEM_REGION_REG_WAIT_ARG)
- return -EINVAL;
-
- /*
- * This ensures there are no waiters. Waiters are unlocked and it's
- * hard to synchronise with them, especially if we need to initialise
- * the region.
- */
- if ((reg.flags & IORING_MEM_REGION_REG_WAIT_ARG) &&
- !(ctx->flags & IORING_SETUP_R_DISABLED))
+ if (reg->flags & ~IORING_MEM_REGION_REG_WAIT_ARG)
return -EINVAL;
ret = io_create_region(ctx, ®ion, &rd, IORING_MAP_OFF_PARAM_REGION);
@@ -610,7 +598,7 @@ static int io_register_mem_region(struct io_ring_ctx *ctx, void __user *uarg)
return -EFAULT;
}
- if (reg.flags & IORING_MEM_REGION_REG_WAIT_ARG) {
+ if (reg->flags & IORING_MEM_REGION_REG_WAIT_ARG) {
ctx->cq_wait_arg = io_region_get_ptr(®ion);
ctx->cq_wait_size = rd.size;
}
@@ -619,6 +607,25 @@ static int io_register_mem_region(struct io_ring_ctx *ctx, void __user *uarg)
return 0;
}
+static int io_register_mem_region(struct io_ring_ctx *ctx, void __user *uarg)
+{
+ struct io_uring_mem_region_reg __user *reg_uptr = uarg;
+ struct io_uring_mem_region_reg reg;
+
+ if (copy_from_user(®, reg_uptr, sizeof(reg)))
+ return -EFAULT;
+ /*
+ * This ensures there are no waiters. Waiters are unlocked and it's
+ * hard to synchronise with them, especially if we need to initialise
+ * the region.
+ */
+ if ((reg.flags & IORING_MEM_REGION_REG_WAIT_ARG) &&
+ !(ctx->flags & IORING_SETUP_R_DISABLED))
+ return -EINVAL;
+
+ return io_create_mem_region(ctx, ®);
+}
+
static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,
void __user *arg, unsigned nr_args)
__releases(ctx->uring_lock)
--
2.49.0
next prev parent reply other threads:[~2025-11-06 17:02 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-06 17:01 [RFC 00/16] Introduce ring flexible placement Pavel Begunkov
2025-11-06 17:01 ` [RFC 01/16] io_uring: add helper calculating region byte size Pavel Begunkov
2025-11-06 17:01 ` [RFC 02/16] io_uring: pass sq entires in the params struct Pavel Begunkov
2025-11-06 17:01 ` [RFC 03/16] io_uring: use mem_is_zero to check ring params Pavel Begunkov
2025-11-06 17:01 ` [RFC 04/16] io_uring: move flags check to io_uring_sanitise_params Pavel Begunkov
2025-11-06 17:01 ` [RFC 05/16] io_uring: introduce struct io_ctx_config Pavel Begunkov
2025-11-06 17:01 ` [RFC 06/16] io_uring: split out config init helper Pavel Begunkov
2025-11-06 17:01 ` [RFC 07/16] io_uring: add structure keeping ring offsets Pavel Begunkov
2025-11-06 17:01 ` [RFC 08/16] io_uring: pre-calculate scq offsets Pavel Begunkov
2025-11-06 17:01 ` [RFC 09/16] io_uring: inroduce helper for setting user offset Pavel Begunkov
2025-11-06 17:01 ` [RFC 10/16] io_uring: separate cqe array from headers Pavel Begunkov
2025-11-06 17:01 ` [RFC 11/16] io_uring/region: introduce io_region_slice Pavel Begunkov
2025-11-06 17:01 ` [RFC 12/16] io_uring: convert pointer init to io_region_slice Pavel Begunkov
2025-11-06 17:01 ` [RFC 13/16] io_uring: refactor rings_size() Pavel Begunkov
2025-11-06 17:01 ` Pavel Begunkov [this message]
2025-11-06 17:01 ` [RFC 15/16] io_uring: allow creating mem region at setup Pavel Begunkov
2025-11-06 17:01 ` [RFC 16/16] io_uring: introduce SCQ placement Pavel Begunkov
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=587665fd1a5ec94914edec3e7b049afbe1f7898e.1762447538.git.asml.silence@gmail.com \
--to=asml.silence@gmail.com \
--cc=io-uring@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