This makes it visible, which fields are used by every opcode. Until everything is converted individual files can define IO_URING_SQE_HIDE_LEGACY in order to hide all legacy fields under a named union arm. Signed-off-by: Stefan Metzmacher <metze@xxxxxxxxx> --- include/uapi/linux/io_uring.h | 30 +++++++++++++++++++++++ io_uring/io_uring.c | 46 +++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 83f16bce3dc7..4dcad4929bc7 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -15,6 +15,12 @@ /* * IO submission data structure (Submission Queue Entry) */ +#ifdef IO_URING_SQE_HIDE_LEGACY +#define __io_uring_sqe_legacy legacy +#else +#define __io_uring_sqe_legacy +#endif + struct io_uring_sqe { union { /* This is the legacy structure */ @@ -85,6 +91,30 @@ struct io_uring_sqe { */ __u8 cmd[0]; }; + } __io_uring_sqe_legacy; + + struct { /* This is the structure showing the generic fields */ + struct io_uring_sqe_hdr { + __u8 opcode; /* type of operation for this sqe */ + __u8 flags; /* IOSQE_ flags */ + __u16 ioprio; /* ioprio for the request */ + __s32 fd; /* file descriptor to do IO on */ + } __attribute__((packed)) hdr; + + __u64 u64_ofs08; + __u64 u64_ofs16; + __u32 u32_ofs24; + __u32 u32_ofs28; + + struct io_uring_sqe_common { + __u64 user_data; /* data to be passed back at completion time */ + __u16 buf_info; /* buf_index or buf_group */ + __u16 personality; /* the personality to run this request under */ + } __attribute__((packed)) common; + + __u32 u32_ofs44; + __u64 u64_ofs48; + __u64 u64_ofs56; }; }; }; diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index ebfdb2212ec2..427dde7dfbd1 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -3890,11 +3890,57 @@ static int __init io_uring_init(void) BUILD_BUG_ON(sizeof_field(stype, ename) != esize); \ } while (0) +#define __BUILD_BUG_VERIFY_ALIAS(stype, eoffset, esize, ename, aname) do { \ + __BUILD_BUG_VERIFY_OFFSET_SIZE(stype, eoffset, esize, ename); \ + BUILD_BUG_ON(sizeof_field(stype, ename) != sizeof_field(stype, aname)); \ + BUILD_BUG_ON(offsetof(stype, ename) != offsetof(stype, aname)); \ +} while (0) + +#define BUILD_BUG_SQE_HDR_ELEM(eoffset, etype, ename) \ + __BUILD_BUG_VERIFY_OFFSET_SIZE(struct io_uring_sqe_hdr, eoffset, sizeof(etype), ename) +#define BUILD_BUG_SQE_COMMON_ELEM(eoffset, etype, ename) \ + __BUILD_BUG_VERIFY_OFFSET_SIZE(struct io_uring_sqe_common, eoffset, sizeof(etype), ename) + #define BUILD_BUG_SQE_ELEM(eoffset, etype, ename) \ __BUILD_BUG_VERIFY_OFFSET_SIZE(struct io_uring_sqe, eoffset, sizeof(etype), ename) #define BUILD_BUG_SQE_ELEM_SIZE(eoffset, esize, ename) \ __BUILD_BUG_VERIFY_OFFSET_SIZE(struct io_uring_sqe, eoffset, esize, ename) +#define BUILD_BUG_SQE_ALIAS(eoffset, etype, ename, aname) \ + __BUILD_BUG_VERIFY_ALIAS(struct io_uring_sqe, eoffset, sizeof(etype), ename, aname) + +#define BUILD_BUG_SQE_LEGACY_ALIAS(eoffset, etype, ename, lname) \ + __BUILD_BUG_VERIFY_ALIAS(struct io_uring_sqe, eoffset, sizeof(etype), ename, lname) + + BUILD_BUG_ON(sizeof(struct io_uring_sqe_hdr) != 8); + BUILD_BUG_SQE_HDR_ELEM(0, __u8, opcode); + BUILD_BUG_SQE_HDR_ELEM(1, __u8, flags); + BUILD_BUG_SQE_HDR_ELEM(2, __u16, ioprio); + BUILD_BUG_SQE_HDR_ELEM(4, __s32, fd); + + BUILD_BUG_ON(sizeof(struct io_uring_sqe_common) != 12); + BUILD_BUG_SQE_COMMON_ELEM(0, __u64, user_data); + BUILD_BUG_SQE_COMMON_ELEM(8, __u16, buf_info); + BUILD_BUG_SQE_COMMON_ELEM(10, __u16, personality); + BUILD_BUG_ON(sizeof(struct io_uring_sqe) != 64); + /* generic layout */ + BUILD_BUG_SQE_ELEM(0, struct io_uring_sqe_hdr, hdr); + BUILD_BUG_SQE_LEGACY_ALIAS(0, __u8, hdr.opcode, opcode); + BUILD_BUG_SQE_LEGACY_ALIAS(1, __u8, hdr.flags, flags); + BUILD_BUG_SQE_LEGACY_ALIAS(2, __u16, hdr.ioprio, ioprio); + BUILD_BUG_SQE_LEGACY_ALIAS(4, __s32, hdr.fd, fd); + BUILD_BUG_SQE_ELEM(8, __u64, u64_ofs08); + BUILD_BUG_SQE_ELEM(16, __u64, u64_ofs16); + BUILD_BUG_SQE_ELEM(24, __u32, u32_ofs24); + BUILD_BUG_SQE_ELEM(28, __u32, u32_ofs28); + BUILD_BUG_SQE_ELEM(32, struct io_uring_sqe_common, common); + BUILD_BUG_SQE_LEGACY_ALIAS(32, __u64, common.user_data, user_data); + BUILD_BUG_SQE_LEGACY_ALIAS(40, __u16, common.buf_info, buf_index); + BUILD_BUG_SQE_LEGACY_ALIAS(42, __u16, common.personality, personality); + BUILD_BUG_SQE_ELEM(44, __u32, u32_ofs44); + BUILD_BUG_SQE_ELEM(48, __u64, u64_ofs48); + BUILD_BUG_SQE_ELEM(56, __u64, u64_ofs56); + /* Legacy layout */ BUILD_BUG_SQE_ELEM(0, __u8, opcode); BUILD_BUG_SQE_ELEM(1, __u8, flags); BUILD_BUG_SQE_ELEM(2, __u16, ioprio); -- 2.34.1