From: Pavel Begunkov <asml.silence@gmail.com>
To: io-uring@vger.kernel.org
Cc: asml.silence@gmail.com
Subject: [RFC 15/16] io_uring: allow creating mem region at setup
Date: Thu, 6 Nov 2025 17:01:54 +0000 [thread overview]
Message-ID: <6a15ce77a48ccb1b0532f3050354a0a9c7a0543b.1762447538.git.asml.silence@gmail.com> (raw)
In-Reply-To: <cover.1762447538.git.asml.silence@gmail.com>
This patch gives users a way to create a memory region at ring setup
instead of requiring a registration call. First, it can be much more
convenient when the region is used for wait parameters and hence
requires IORING_SETUP_R_DISABLED. I'll also need it in the next patch
for placing SCQ into it.
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
include/uapi/linux/io_uring.h | 7 ++++++-
io_uring/io_uring.c | 26 ++++++++++++++++++++++++++
io_uring/io_uring.h | 1 +
io_uring/register.c | 2 ++
4 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h
index 04797a9b76bc..2da052bd4138 100644
--- a/include/uapi/linux/io_uring.h
+++ b/include/uapi/linux/io_uring.h
@@ -599,11 +599,16 @@ struct io_uring_params {
__u32 sq_thread_idle;
__u32 features;
__u32 wq_fd;
- __u32 resv[3];
+ __u32 resv;
+ __u64 params_ext; /* pointer to struct io_uring_params_ext */
struct io_sqring_offsets sq_off;
struct io_cqring_offsets cq_off;
};
+struct io_uring_params_ext {
+ __u64 mem_region; /* pointer to struct io_uring_mem_region_reg */
+};
+
/*
* io_uring_params->features flags
*/
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index ff52d9f110ce..908c432aaaaa 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -3574,8 +3574,13 @@ int io_uring_fill_params(struct io_uring_params *p)
static int io_prepare_config(struct io_ctx_config *config)
{
struct io_uring_params *p = &config->p;
+ struct io_uring_params_ext __user *ext_user;
int ret;
+ ext_user = u64_to_user_ptr(config->p.params_ext);
+ if (ext_user && copy_from_user(&config->ext, ext_user, sizeof(config->ext)))
+ return -EFAULT;
+
ret = io_uring_sanitise_params(p);
if (ret)
return ret;
@@ -3592,6 +3597,22 @@ static int io_prepare_config(struct io_ctx_config *config)
return 0;
}
+static int io_ctx_init_mem_region(struct io_ring_ctx *ctx,
+ struct io_ctx_config *config)
+{
+ struct io_uring_params_ext *e = &config->ext;
+ struct io_uring_mem_region_reg __user *mr_user;
+ struct io_uring_mem_region_reg mr;
+
+ mr_user = u64_to_user_ptr(e->mem_region);
+ if (!mr_user)
+ return 0;
+
+ if (copy_from_user(&mr, mr_user, sizeof(mr)))
+ return -EFAULT;
+ return io_create_mem_region(ctx, &mr);
+}
+
static __cold int io_uring_create(struct io_ctx_config *config)
{
struct io_uring_params *p = &config->p;
@@ -3661,10 +3682,15 @@ static __cold int io_uring_create(struct io_ctx_config *config)
mmgrab(current->mm);
ctx->mm_account = current->mm;
+ ret = io_ctx_init_mem_region(ctx, config);
+ if (ret)
+ goto err;
+
ret = io_allocate_scq_urings(ctx, config);
if (ret)
goto err;
+
ret = io_sq_offload_create(ctx, p);
if (ret)
goto err;
diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h
index 20f6ca4696c1..c883017b11d3 100644
--- a/io_uring/io_uring.h
+++ b/io_uring/io_uring.h
@@ -30,6 +30,7 @@ struct io_scq_dim {
struct io_ctx_config {
struct io_uring_params p;
+ struct io_uring_params_ext ext;
struct io_scq_dim dims;
struct io_uring_params __user *uptr;
};
diff --git a/io_uring/register.c b/io_uring/register.c
index 425529a30dd9..4affabc416aa 100644
--- a/io_uring/register.c
+++ b/io_uring/register.c
@@ -414,6 +414,8 @@ static int io_register_resize_rings(struct io_ring_ctx *ctx, void __user *arg)
return -EFAULT;
if (p.flags & ~RESIZE_FLAGS)
return -EINVAL;
+ if (p.params_ext)
+ return -EINVAL;
/* properties that are always inherited */
p.flags |= (ctx->flags & COPY_FLAGS);
--
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 ` [RFC 14/16] io_uring: extract io_create_mem_region Pavel Begunkov
2025-11-06 17:01 ` Pavel Begunkov [this message]
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=6a15ce77a48ccb1b0532f3050354a0a9c7a0543b.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