From: Pavel Begunkov <[email protected]>
To: [email protected]
Cc: [email protected], Anuj Gupta <[email protected]>,
Kanchan Joshi <[email protected]>
Subject: [PATCH 1/4] io_uring: add structure for registered arguments
Date: Mon, 30 Dec 2024 13:30:21 +0000 [thread overview]
Message-ID: <dda0a555cee9b774ef3833273c98a288744562a8.1735301337.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>
A preparation patch making infra for wait arguments a bit more general
to use in in following patches.
Signed-off-by: Pavel Begunkov <[email protected]>
---
include/linux/io_uring_types.h | 9 +++++++--
io_uring/io_uring.c | 23 +++--------------------
io_uring/io_uring.h | 16 ++++++++++++++++
io_uring/register.c | 4 ++--
4 files changed, 28 insertions(+), 24 deletions(-)
diff --git a/include/linux/io_uring_types.h b/include/linux/io_uring_types.h
index 493a8f7fa8e4..49008f00d064 100644
--- a/include/linux/io_uring_types.h
+++ b/include/linux/io_uring_types.h
@@ -83,6 +83,11 @@ struct io_mapped_region {
unsigned flags;
};
+struct io_reg_args {
+ void *ptr;
+ size_t size;
+};
+
/*
* Arbitrary limit, can be raised if need be
*/
@@ -332,8 +337,8 @@ struct io_ring_ctx {
struct io_ev_fd __rcu *io_ev_fd;
unsigned cq_extra;
- void *cq_wait_arg;
- size_t cq_wait_size;
+ struct io_reg_args wait_args;
+
} ____cacheline_aligned_in_smp;
/*
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 5535a72b0ce1..e2b6b256fc9a 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -3178,25 +3178,6 @@ void __io_uring_cancel(bool cancel_all)
io_uring_cancel_generic(cancel_all, NULL);
}
-static struct io_uring_reg_wait *io_get_ext_arg_reg(struct io_ring_ctx *ctx,
- const struct io_uring_getevents_arg __user *uarg)
-{
- unsigned long size = sizeof(struct io_uring_reg_wait);
- unsigned long offset = (uintptr_t)uarg;
- unsigned long end;
-
- if (unlikely(offset % sizeof(long)))
- return ERR_PTR(-EFAULT);
-
- /* also protects from NULL ->cq_wait_arg as the size would be 0 */
- if (unlikely(check_add_overflow(offset, size, &end) ||
- end > ctx->cq_wait_size))
- return ERR_PTR(-EFAULT);
-
- offset = array_index_nospec(offset, ctx->cq_wait_size - size);
- return ctx->cq_wait_arg + offset;
-}
-
static int io_validate_ext_arg(struct io_ring_ctx *ctx, unsigned flags,
const void __user *argp, size_t argsz)
{
@@ -3233,7 +3214,9 @@ static int io_get_ext_arg(struct io_ring_ctx *ctx, unsigned flags,
if (ext_arg->argsz != sizeof(struct io_uring_reg_wait))
return -EINVAL;
- w = io_get_ext_arg_reg(ctx, argp);
+
+ w = io_args_get_ptr(&ctx->wait_args, (uintptr_t)argp,
+ sizeof(struct io_uring_reg_wait));
if (IS_ERR(w))
return PTR_ERR(w);
diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h
index 032758b28d78..a18da74f18e8 100644
--- a/io_uring/io_uring.h
+++ b/io_uring/io_uring.h
@@ -514,4 +514,20 @@ static inline bool io_has_work(struct io_ring_ctx *ctx)
return test_bit(IO_CHECK_CQ_OVERFLOW_BIT, &ctx->check_cq) ||
io_local_work_pending(ctx);
}
+
+static inline void *io_args_get_ptr(struct io_reg_args *args,
+ unsigned long offset, size_t size)
+{
+ unsigned long end;
+
+ if (unlikely(offset % sizeof(long)))
+ return ERR_PTR(-EFAULT);
+
+ /* also protects from NULL as the size would be 0 */
+ if (unlikely(check_add_overflow(offset, size, &end) || end > args->size))
+ return ERR_PTR(-EFAULT);
+
+ return args->ptr + array_index_nospec(offset, args->size - size);
+}
+
#endif
diff --git a/io_uring/register.c b/io_uring/register.c
index f1698c18c7cb..b926eb053408 100644
--- a/io_uring/register.c
+++ b/io_uring/register.c
@@ -604,8 +604,8 @@ static int io_register_mem_region(struct io_ring_ctx *ctx, void __user *uarg)
}
if (reg.flags & IORING_MEM_REGION_REG_WAIT_ARG) {
- ctx->cq_wait_arg = io_region_get_ptr(&ctx->param_region);
- ctx->cq_wait_size = rd.size;
+ ctx->wait_args.ptr = io_region_get_ptr(&ctx->param_region);
+ ctx->wait_args.size = rd.size;
}
return 0;
}
--
2.47.1
next prev parent reply other threads:[~2024-12-30 13:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-30 13:30 [RFC 0/4] pre-mapped rw attributes Pavel Begunkov
2024-12-30 13:30 ` Pavel Begunkov [this message]
2024-12-30 13:30 ` [PATCH 2/4] io_uring: add registered request arguments Pavel Begunkov
2024-12-30 13:30 ` [PATCH 3/4] io_uring/rw: use READ_ONCE with rw attributes Pavel Begunkov
2024-12-30 13:30 ` [PATCH 4/4] io_uring/rw: pre-mapped " 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=dda0a555cee9b774ef3833273c98a288744562a8.1735301337.git.asml.silence@gmail.com \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/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