public inbox for [email protected]
 help / color / mirror / Atom feed
From: Stefan Metzmacher <[email protected]>
To: [email protected], [email protected]
Cc: Stefan Metzmacher <[email protected]>
Subject: [RFC PATCH 2/8] io_uring: add a generic structure for struct io_uring_sqe
Date: Fri, 12 Aug 2022 10:34:26 +0200	[thread overview]
Message-ID: <eab2a418cec03cf74a4a80fd17e9aacc35e91750.1660291547.git.metze@samba.org> (raw)
In-Reply-To: <[email protected]>

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 <[email protected]>
---
 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


  parent reply	other threads:[~2022-08-12  8:35 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-12  8:34 [RFC PATCH 0/8] cleanup struct io_uring_sqe layout Stefan Metzmacher
2022-08-12  8:34 ` [RFC PATCH 1/8] io_uring: move the current struct io_uring_sqe members to legacy sub struct Stefan Metzmacher
2022-08-12  8:34 ` Stefan Metzmacher [this message]
2022-08-12  8:34 ` [RFC PATCH 3/8] io_uring: check legacy layout of struct io_uring_sqe with BUILD_BUG_SQE_LEGACY* Stefan Metzmacher
2022-08-12  8:34 ` [RFC PATCH 4/8] io_uring: only make use generic struct io_uring_sqe elements for tracing Stefan Metzmacher
2022-08-12  8:34 ` [RFC PATCH 5/8] io_uring: only access generic struct io_uring_sqe elements in io_uring.c Stefan Metzmacher
2022-08-12  8:34 ` [RFC PATCH 6/8] io_uring: add BUILD_BUG_SQE_HDR_COMMON() macro Stefan Metzmacher
2022-08-12  8:34 ` [RFC PATCH 7/8] io_uring: introduce struct io_uring_sqe_rw for all io_prep_rw() using opcodes Stefan Metzmacher
2022-08-12  8:34 ` [RFC PATCH 8/8] io_uring: introduce struct io_uring_sqe_{fsync,sfr,fallocate} Stefan Metzmacher

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=eab2a418cec03cf74a4a80fd17e9aacc35e91750.1660291547.git.metze@samba.org \
    [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