From: Joanne Koong <joannelkoong@gmail.com>
To: axboe@kernel.dk
Cc: csander@purestorage.com, asml.silence@gmail.com,
io-uring@vger.kernel.org
Subject: [PATCH v4 5/5] io_uring/rsrc: add io_uring_registered_mem_region_get()
Date: Fri, 27 Mar 2026 10:26:31 -0700 [thread overview]
Message-ID: <20260327172631.3380702-6-joannelkoong@gmail.com> (raw)
In-Reply-To: <20260327172631.3380702-1-joannelkoong@gmail.com>
Add io_uring_registered_mem_region_get() helper to allow io_uring
command handlers to retrieve the ring's registered memory region info
(the vmapped pointer to the region's pages and the size of the region).
The info is returned in a struct io_uring_mem_region_info. If no region
was registered, a zeroed struct is returned. This provides a way for
uring cmd implementations to directly access pre-registered memory for
passing data.
Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
---
include/linux/io_uring/cmd.h | 14 ++++++++++++++
io_uring/rsrc.c | 25 +++++++++++++++++++++++++
2 files changed, 39 insertions(+)
diff --git a/include/linux/io_uring/cmd.h b/include/linux/io_uring/cmd.h
index b4d1d5e8e851..f1027f357ad1 100644
--- a/include/linux/io_uring/cmd.h
+++ b/include/linux/io_uring/cmd.h
@@ -20,6 +20,11 @@ struct io_uring_cmd {
u8 unused[8];
};
+struct io_uring_mem_region_info {
+ void *ptr;
+ unsigned nr_pages;
+};
+
#define io_uring_sqe128_cmd(sqe, type) ({ \
BUILD_BUG_ON(sizeof(type) > ((2 * sizeof(struct io_uring_sqe)) - \
offsetof(struct io_uring_sqe, cmd))); \
@@ -51,6 +56,9 @@ int io_uring_cmd_import_fixed_vec(struct io_uring_cmd *ioucmd,
size_t uvec_segs,
int ddir, struct iov_iter *iter,
unsigned issue_flags);
+struct io_uring_mem_region_info
+io_uring_registered_mem_region_get(struct io_uring_cmd *cmd,
+ unsigned issue_flags);
/*
* Completes the request, i.e. posts an io_uring CQE and deallocates @ioucmd
@@ -132,6 +140,12 @@ static inline int io_uring_cmd_import_fixed_vec(struct io_uring_cmd *ioucmd,
{
return -EOPNOTSUPP;
}
+static inline struct io_uring_mem_region_info
+io_uring_registered_mem_region_get(struct io_uring_cmd *cmd,
+ unsigned issue_flags)
+{
+ return (struct io_uring_mem_region_info) {};
+}
static inline void __io_uring_cmd_done(struct io_uring_cmd *cmd, s32 ret,
u64 ret2, unsigned issue_flags, bool is_cqe32)
{
diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
index cf5638406a0c..7b084823ef68 100644
--- a/io_uring/rsrc.c
+++ b/io_uring/rsrc.c
@@ -1182,6 +1182,31 @@ int io_import_reg_buf(struct io_kiocb *req, struct iov_iter *iter,
return io_import_fixed(ddir, iter, node->buf, buf_addr, len);
}
+struct io_uring_mem_region_info
+io_uring_registered_mem_region_get(struct io_uring_cmd *cmd,
+ unsigned issue_flags)
+{
+ struct io_ring_ctx *ctx = cmd_to_io_kiocb(cmd)->ctx;
+ struct io_uring_mem_region_info info = {};
+
+ /*
+ * The submit lock ensures we don't see partially initialized state if
+ * another thread is currently registering the region. Once registered,
+ * the region is stable for the ring's lifetime (no unregister API
+ * exists), so it's safe to access the returned pointer outside the
+ * lock.
+ */
+ io_ring_submit_lock(ctx, issue_flags);
+
+ info.ptr = ctx->param_region.ptr;
+ info.nr_pages = ctx->param_region.nr_pages;
+
+ io_ring_submit_unlock(ctx, issue_flags);
+
+ return info;
+}
+EXPORT_SYMBOL_GPL(io_uring_registered_mem_region_get);
+
/* Lock two rings at once. The rings must be different! */
static void lock_two_rings(struct io_ring_ctx *ctx1, struct io_ring_ctx *ctx2)
{
--
2.52.0
next prev parent reply other threads:[~2026-03-27 17:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-27 17:26 [PATCH v4 0/5] io_uring: extend bvec registration and add mem region lookup Joanne Koong
2026-03-27 17:26 ` [PATCH v4 1/5] io_uring/rsrc: rename io_buffer_register_bvec()/io_buffer_unregister_bvec() Joanne Koong
2026-03-27 17:26 ` [PATCH v4 2/5] io_uring/rsrc: split io_buffer_register_request() logic Joanne Koong
2026-03-27 17:26 ` [PATCH v4 3/5] io_uring/rsrc: add io_buffer_register_bvec() Joanne Koong
2026-03-27 17:26 ` [PATCH v4 4/5] io_uring/rsrc: rename and export IO_IMU_DEST / IO_IMU_SOURCE Joanne Koong
2026-03-27 17:26 ` Joanne Koong [this message]
2026-04-01 17:26 ` [PATCH v4 5/5] io_uring/rsrc: add io_uring_registered_mem_region_get() Joanne Koong
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=20260327172631.3380702-6-joannelkoong@gmail.com \
--to=joannelkoong@gmail.com \
--cc=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=csander@purestorage.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