introduce io_uring querying
v3 cover introduce io_uring querying
Introduce a versatile interface to query auxilary io_uring parameters. It will be used to close a couple of API gaps, but in this series can only tell what request and register opcodes, features and setup flags are available. It'll replace IORING_REGISTER_PROBE but with a much more convenient interface. Patch 3 for API description.
Can be tested with:
https://github.com/isilence/liburing.git io_uring/query-v2
v3: - Rebase
- Add review tags
- Remove copyright notice
v2: - Add enter and sqe flags to IO_URING_QUERY_OPCODES
- Zero unused parts of user structures (beyond returned hdr.size).
- Don't colocate hdr and and query specific info. The header now points to it via query_data.
Pavel Begunkov (3):
io_uring: add helper for *REGISTER_SEND_MSG_RING
io_uring: add macros for avaliable flags
io_uring: introduce io_uring querying
include/uapi/linux/io_uring.h | 3 + include/uapi/linux/io_uring/query.h | 41 +++++++++++++ io_uring/Makefile | 2 +- io_uring/io_uring.c | 32 +--------- io_uring/io_uring.h | 57 ++++++++++++++++++ io_uring/query.c | 93 +++++++++++++++++++++++++++++ io_uring/query.h | 9 +++ io_uring/register.c | 39 +++++++----- 8 files changed, 232 insertions(+), 44 deletions(-) create mode 100644 include/uapi/linux/io_uring/query.h create mode 100644 io_uring/query.c create mode 100644 io_uring/query.h
Signature · 1 line
2.49.0
PATCH v3 1/3 io_uring: add helper for *REGISTER_SEND_MSG_RING
Move handling of IORING_REGISTER_SEND_MSG_RING into a separate function in preparation to growing io_uring_register_blind().
--- io_uring/register.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-)
io_uring/register.c +19 -14
@@ -874,6 +874,23 @@ struct file *io_uring_register_get_file(unsigned int fd, bool registered)return ERR_PTR (-EOPNOTSUPP ); } +static int io_uring_register_send_msg_ring (void __user *arg,unsigned int nr_args) +{ +struct io_uring_sqe sqe; + +if (!arg || nr_args !=1 ) +return -EINVAL ; +if (copy_from_user (&sqe, arg,sizeof (sqe))) +return -EFAULT ; +/* no flags supported */ +if (sqe.flags) +return -EINVAL ; +if (sqe.opcode !=IORING_OP_MSG_RING ) +return -EINVAL ; + +return io_uring_sync_msg_ring (&sqe); +} +/* * "blind" registration opcodes are ones where there's no ring given, and * hence the source fd must be -1.
@@ -882,21 +899,9 @@ static int io_uring_register_blind(unsigned int opcode, void __user *arg, unsigned int nr_args) {switch (opcode) { -case IORING_REGISTER_SEND_MSG_RING : { -struct io_uring_sqe sqe; - -if (!arg || nr_args !=1 ) -return -EINVAL ; -if (copy_from_user (&sqe, arg,sizeof (sqe))) -return -EFAULT ; -/* no flags supported */ -if (sqe.flags) -return -EINVAL ; -if (sqe.opcode ==IORING_OP_MSG_RING ) -return io_uring_sync_msg_ring (&sqe); - } +case IORING_REGISTER_SEND_MSG_RING : +return io_uring_register_send_msg_ring (arg, nr_args); } -return -EINVAL ; }
Signature · 1 line
2.49.0
PATCH v3 2/3 io_uring: add macros for avaliable flags
In reply to Pavel BegunkovAdd constants for supported setup / request / feature flags as well as the feature mask. They'll be used in the next patch.
--- io_uring/io_uring.c | 32 +++---------------------- io_uring/io_uring.h | 57 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 29 deletions(-)
io_uring/io_uring.c +3 -29
@@ -108,9 +108,6 @@#define SQE_COMMON_FLAGS (IOSQE_FIXED_FILE | IOSQE_IO_LINK | \ IOSQE_IO_HARDLINK | IOSQE_ASYNC) -#define SQE_VALID_FLAGS (SQE_COMMON_FLAGS | IOSQE_BUFFER_SELECT | \ - IOSQE_IO_DRAIN | IOSQE_CQE_SKIP_SUCCESS) -#define IO_REQ_LINK_FLAGS (REQ_F_LINK | REQ_F_HARDLINK)#define IO_REQ_CLEAN_FLAGS (REQ_F_BUFFER_SELECTED | REQ_F_NEED_CLEANUP | \
@@ -3462,12 +3459,7 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,struct file *file;long ret; -if (unlikely (flags & ~(IORING_ENTER_GETEVENTS |IORING_ENTER_SQ_WAKEUP | -IORING_ENTER_SQ_WAIT |IORING_ENTER_EXT_ARG | -IORING_ENTER_REGISTERED_RING | -IORING_ENTER_ABS_TIMER | -IORING_ENTER_EXT_ARG_REG | -IORING_ENTER_NO_IOWAIT ))) +if (unlikely (flags & ~IORING_ENTER_FLAGS ))return -EINVAL ;/*
@@ -3875,15 +3867,7 @@ static __cold int io_uring_create(unsigned entries, struct io_uring_params *p,if (ret) goto err; - p->features =IORING_FEAT_SINGLE_MMAP |IORING_FEAT_NODROP | -IORING_FEAT_SUBMIT_STABLE |IORING_FEAT_RW_CUR_POS | -IORING_FEAT_CUR_PERSONALITY |IORING_FEAT_FAST_POLL | -IORING_FEAT_POLL_32BITS |IORING_FEAT_SQPOLL_NONFIXED | -IORING_FEAT_EXT_ARG |IORING_FEAT_NATIVE_WORKERS | -IORING_FEAT_RSRC_TAGS |IORING_FEAT_CQE_SKIP | -IORING_FEAT_LINKED_FILE |IORING_FEAT_REG_REG_RING | -IORING_FEAT_RECVSEND_BUNDLE |IORING_FEAT_MIN_TIMEOUT | -IORING_FEAT_RW_ATTR |IORING_FEAT_NO_IOWAIT ; + p->features =IORING_FEAT_FLAGS ;if (copy_to_user (params, p,sizeof (*p))) { ret = -EFAULT ;
@@ -3948,18 +3932,8 @@ static long io_uring_setup(u32 entries, struct io_uring_params __user *params)return -EINVAL ; } -if (p.flags & ~(IORING_SETUP_IOPOLL |IORING_SETUP_SQPOLL | -IORING_SETUP_SQ_AFF |IORING_SETUP_CQSIZE | -IORING_SETUP_CLAMP |IORING_SETUP_ATTACH_WQ | -IORING_SETUP_R_DISABLED |IORING_SETUP_SUBMIT_ALL | -IORING_SETUP_COOP_TASKRUN |IORING_SETUP_TASKRUN_FLAG | -IORING_SETUP_SQE128 |IORING_SETUP_CQE32 | -IORING_SETUP_SINGLE_ISSUER |IORING_SETUP_DEFER_TASKRUN | -IORING_SETUP_NO_MMAP |IORING_SETUP_REGISTERED_FD_ONLY | -IORING_SETUP_NO_SQARRAY |IORING_SETUP_HYBRID_IOPOLL | -IORING_SETUP_CQE_MIXED )) +if (p.flags & ~IORING_SETUP_FLAGS )return -EINVAL ; -return io_uring_create (entries, &p, params); }
io_uring/io_uring.h +57 -0
63 lines not on this page · raw message
Signature · 1 line
2.49.0
PATCH v3 3/3 io_uring: introduce io_uring querying
In reply to Pavel BegunkovThere are many parameters users might want to query about io_uring like available request types or the ring sizes. This patch introduces an interface for such slow path queries.
It was written with several requirements in mind:
- Can be used with or without an io_uring instance. Asking for supported setup flags before creating an instance as well as qeurying info about an already created ring are valid use cases.
- Should be moderately fast. For example, users might use it to periodically retrieve ring attributes at runtime. As a consequence, it should be able to query multiple attributes in a single syscall.
- Backward and forward compatible.
- Should be reasobably easy to use.
- Reduce the kernel code size for introducing new query types.
It's implemented as a new registration opcode IORING_REGISTER_QUERY. The user passes one or more query strutctures linked together, each represented by struct io_uring_query_hdr. The header stores common control fields needed for processing and points to query type specific information.
The header contains
- The query type
- The result field, which on return contains the error code for the query
- Pointer to the query type specific information
- The size of the query structure. The kernel will only populate up to the size, which helps with backward compatibility. The kernel can also reduce the size, so if the current kernel is older than the inteface the user tries to use, it'll get only the supported bits.
- next_entry field is used to chain multiple queries.
Apart from common registeration syscall failures, it can only immediately return an error code in case when the headers are incorrect or any other addresses and invalid. That usually mean that the userspace doesn't use the API right and should be corrected. All query type specific errors are returned in the header's result field.
As an example, the patch adds a single query type for now, i.e. IO_URING_QUERY_OPCODES, which tells what register / request / etc. opcodes are supported, but there are particular plans to extend it.
Note: there is a request probing interface via IORING_REGISTER_PROBE, but it's a mess. It requires the user to create a ring first, it only works for requests, and requires dynamic allocations.
--- include/uapi/linux/io_uring.h | 3 + include/uapi/linux/io_uring/query.h | 41 +++++++++++++ io_uring/Makefile | 2 +- io_uring/query.c | 93 +++++++++++++++++++++++++++++ io_uring/query.h | 9 +++ io_uring/register.c | 6 ++ 6 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 include/uapi/linux/io_uring/query.h create mode 100644 io_uring/query.c create mode 100644 io_uring/query.h
include/uapi/linux/io_uring.h +3 -0
@@ -686,6 +686,9 @@ enum io_uring_register_op {IORING_REGISTER_MEM_REGION =34 , +/* query various aspects of io_uring, see linux/io_uring/query.h */ +IORING_REGISTER_QUERY =35 , +/* this goes last */ IORING_REGISTER_LAST,
include/uapi/linux/io_uring/query.h new file +41 -0
41 lines not on this page · raw message
io_uring/Makefile +1 -1
@@ -13,7 +13,7 @@ obj-$(CONFIG_IO_URING) += io_uring.o opdef.o kbuf.o rsrc.o notif.o \ sync.o msg_ring.o advise.o openclose.o \ statx.o timeout.o cancel.o \ waitid.o register.o truncate.o \ - memmap.o alloc_cache.o + memmap.o alloc_cache.o query.o obj-$(CONFIG_IO_URING_ZCRX) += zcrx.o obj-$(CONFIG_IO_WQ) += io-wq.o obj-$(CONFIG_FUTEX) += futex.o
io_uring/query.c new file +93 -0
93 lines not on this page · raw message
io_uring/query.h new file +9 -0
@@ -0,0 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef IORING_QUERY_H +#define IORING_QUERY_H + +#include <linux/io_uring_types.h> + +int io_query (struct io_ring_ctx *ctx,void __user *arg,unsigned nr_args); + +#endif
io_uring/register.c +6 -0
@@ -31,6 +31,7 @@#include "msg_ring.h" #include "memmap.h" #include "zcrx.h" +#include "query.h" #define IORING_MAX_RESTRICTIONS (IORING_RESTRICTION_LAST + \ IORING_REGISTER_LAST + IORING_OP_LAST)
@@ -832,6 +833,9 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,break ; ret =io_register_mem_region (ctx, arg);break ; +case IORING_REGISTER_QUERY : + ret =io_query (ctx, arg, nr_args); +break ;default : ret = -EINVAL ;break ;
@@ -901,6 +905,8 @@ static int io_uring_register_blind(unsigned int opcode, void __user *arg,switch (opcode) {case IORING_REGISTER_SEND_MSG_RING :return io_uring_register_send_msg_ring (arg, nr_args); +case IORING_REGISTER_QUERY : +return io_query (NULL , arg, nr_args); }return -EINVAL ; }
Signature · 1 line
2.49.0
Pavel,
Quoted 5 lines
Introduce a versatile interface to query auxilary
io_uringparameters. It will be used to close a couple of API gaps, but in this series can only tell what request and register opcodes, features and setup flags are available. It'll replaceIORING_REGISTER_PROBEbut with a much more convenient interface. Patch 3 for API description.
Signature · 1 line
Martin K. Petersen
Quoted 10 lines · Martin K. Petersen
Pavel,
Quoted 5 lines
Introduce a versatile interface to query auxilary
io_uringparameters. It will be used to close a couple of API gaps, but in this series can only tell what request and register opcodes, features and setup flags are available. It'll replaceIORING_REGISTER_PROBEbut with a much more convenient interface. Patch 3 for API description.Reviewed-by Martin K. Petersen <[email protected]>
Thanks for review.
And apologies, I forgot to CC you and Gabriel on the series.
Signature · 1 line
Pavel Begunkov
Quoted 9 lines · Pavel Begunkov
Introduce a versatile interface to query auxilary
io_uringparameters. It will be used to close a couple of API gaps, but in this series can only tell what request and register opcodes, features and setup flags are available. It'll replaceIORING_REGISTER_PROBEbut with a much more convenient interface. Patch 3 for API description.Can be tested with:
[...]
Applied, thanks!
[1/3] io_uring: add helper for *REGISTER_SEND_MSG_RING
commit: da8bc3c81c71eb8906dafca805db1a2639665116
[2/3] io_uring: add macros for avaliable flags
commit: 63805d0a9b9670ade00c4f49e4fe093668b31ba5
[3/3] io_uring: introduce io_uring querying
commit: c265ae75f900cea4e415230a77b5d152377627ddBest regards,
Signature · 1 line
Jens Axboe