This is the start to use opcode specific struct io_uring_sqe layouts. It hopefully make it much easier to maintain the struct io_uring_sqe. Signed-off-by: Stefan Metzmacher <metze@xxxxxxxxx> --- include/uapi/linux/io_uring.h | 16 ++++++++++++++++ io_uring/io_uring.c | 9 +++++++++ io_uring/rw.c | 26 +++++++++++++++++++------- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 4dcad4929bc7..690b13229227 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -116,6 +116,22 @@ struct io_uring_sqe { __u64 u64_ofs48; __u64 u64_ofs56; }; + + /* IORING_OP_{READV,WRITEV,READ_FIXED,WRITE_FIXED,READ,WRITE} */ + struct io_uring_sqe_rw { + struct io_uring_sqe_hdr hdr; + + __u64 offset; + __u64 buffer_addr; + __u32 length; + __u32 flags; + + struct io_uring_sqe_common common; + + __u32 u32_ofs44; + __u64 u64_ofs48; + __u64 u64_ofs56; + } rw; }; }; diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 8e1a8800b252..e3336621e667 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -4003,6 +4003,15 @@ static int __init io_uring_init(void) BUILD_BUG_SQE_LEGACY_SIZE(48, 0, cmd); BUILD_BUG_SQE_LEGACY(56, __u64, __pad2); + BUILD_BUG_SQE_HDR_COMMON(struct io_uring_sqe_rw, rw); + BUILD_BUG_SQE_LEGACY_ALIAS(8, __u64, rw.offset, off); + BUILD_BUG_SQE_LEGACY_ALIAS(16, __u64, rw.buffer_addr, addr); + BUILD_BUG_SQE_LEGACY_ALIAS(24, __u32, rw.length, len); + BUILD_BUG_SQE_LEGACY_ALIAS(28, __u32, rw.flags, rw_flags); + BUILD_BUG_SQE_ALIAS(44, __u32, rw.u32_ofs44, u32_ofs44); + BUILD_BUG_SQE_ALIAS(48, __u64, rw.u64_ofs48, u64_ofs48); + BUILD_BUG_SQE_ALIAS(56, __u64, rw.u64_ofs56, u64_ofs56); + BUILD_BUG_ON(sizeof(struct io_uring_files_update) != sizeof(struct io_uring_rsrc_update)); BUILD_BUG_ON(sizeof(struct io_uring_rsrc_update) > diff --git a/io_uring/rw.c b/io_uring/rw.c index 3d732b19b760..5612b03af997 100644 --- a/io_uring/rw.c +++ b/io_uring/rw.c @@ -1,4 +1,5 @@ // SPDX-License-Identifier: GPL-2.0 +#define IO_URING_SQE_HIDE_LEGACY 1 #include <linux/kernel.h> #include <linux/errno.h> #include <linux/fs.h> @@ -33,15 +34,16 @@ static inline bool io_file_supports_nowait(struct io_kiocb *req) return req->flags & REQ_F_SUPPORT_NOWAIT; } -int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe) +int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *_sqe) { + const struct io_uring_sqe_rw *sqe = &_sqe->rw; struct io_rw *rw = io_kiocb_to_cmd(req, struct io_rw); unsigned ioprio; int ret; - rw->kiocb.ki_pos = READ_ONCE(sqe->off); + rw->kiocb.ki_pos = READ_ONCE(sqe->offset); /* used for fixed read/write too - just read unconditionally */ - req->buf_index = READ_ONCE(sqe->buf_index); + req->buf_index = READ_ONCE(sqe->common.buf_info); if (req->opcode == IORING_OP_READ_FIXED || req->opcode == IORING_OP_WRITE_FIXED) { @@ -55,7 +57,7 @@ int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe) io_req_set_rsrc_node(req, ctx, 0); } - ioprio = READ_ONCE(sqe->ioprio); + ioprio = READ_ONCE(sqe->hdr.ioprio); if (ioprio) { ret = ioprio_check_cap(ioprio); if (ret) @@ -66,9 +68,19 @@ int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe) rw->kiocb.ki_ioprio = get_current_ioprio(); } - rw->addr = READ_ONCE(sqe->addr); - rw->len = READ_ONCE(sqe->len); - rw->flags = READ_ONCE(sqe->rw_flags); + rw->addr = READ_ONCE(sqe->buffer_addr); + rw->len = READ_ONCE(sqe->length); + rw->flags = READ_ONCE(sqe->flags); + + /* + * Note for compat reasons we don't check the following + * to be zero: + * + * sqe->u32_ofs44 + * sqe->u64_ofs48 + * sqe->u64_ofs56 + */ + return 0; } -- 2.34.1