Skip to content

Commit 4aaa9bc

Browse files
isilenceaxboe
authored andcommitted
io_uring/query: introduce rings info query
Same problem as with zcrx in the previous patch, the user needs to know SQ/CQ header sizes to allocated memory before setup to use it for user provided rings, i.e. IORING_SETUP_NO_MMAP, however that information is only returned after registration, hence the user is guessing kernel implementation details. Return the header size and alignment, which is split with the same motivation, to allow the user to know the real structure size without alignment in case there will be more flexible placement schemes in the future. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 2647e2e commit 4aaa9bc

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

include/uapi/linux/io_uring/query.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct io_uring_query_hdr {
1919
enum {
2020
IO_URING_QUERY_OPCODES = 0,
2121
IO_URING_QUERY_ZCRX = 1,
22+
IO_URING_QUERY_SCQ = 2,
2223

2324
__IO_URING_QUERY_MAX,
2425
};
@@ -57,4 +58,11 @@ struct io_uring_query_zcrx {
5758
__u64 __resv2;
5859
};
5960

61+
struct io_uring_query_scq {
62+
/* The SQ/CQ rings header size */
63+
__u64 hdr_size;
64+
/* The alignment for the header */
65+
__u64 hdr_alignment;
66+
};
67+
6068
#endif

io_uring/query.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
union io_query_data {
1010
struct io_uring_query_opcode opcodes;
1111
struct io_uring_query_zcrx zcrx;
12+
struct io_uring_query_scq scq;
1213
};
1314

1415
#define IO_MAX_QUERY_SIZE sizeof(union io_query_data)
@@ -43,6 +44,15 @@ static ssize_t io_query_zcrx(union io_query_data *data)
4344
return sizeof(*e);
4445
}
4546

47+
static ssize_t io_query_scq(union io_query_data *data)
48+
{
49+
struct io_uring_query_scq *e = &data->scq;
50+
51+
e->hdr_size = sizeof(struct io_rings);
52+
e->hdr_alignment = SMP_CACHE_BYTES;
53+
return sizeof(*e);
54+
}
55+
4656
static int io_handle_query_entry(struct io_ring_ctx *ctx,
4757
union io_query_data *data, void __user *uhdr,
4858
u64 *next_entry)
@@ -74,6 +84,9 @@ static int io_handle_query_entry(struct io_ring_ctx *ctx,
7484
case IO_URING_QUERY_ZCRX:
7585
ret = io_query_zcrx(data);
7686
break;
87+
case IO_URING_QUERY_SCQ:
88+
ret = io_query_scq(data);
89+
break;
7790
}
7891

7992
if (ret >= 0) {

0 commit comments

Comments
 (0)