public inbox for [email protected]
 help / color / mirror / Atom feed
* [RFC PATCH 0/8] cleanup struct io_uring_sqe layout
@ 2022-08-12  8:34 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
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Stefan Metzmacher @ 2022-08-12  8:34 UTC (permalink / raw)
  To: io-uring, axboe; +Cc: Stefan Metzmacher

Hi Jens,

with all the nested structs, unions and scalar fields in
struct io_uring_sqe, it becomes more and more confusing to
find which fields are used by what opcode for
what and which fields are useable for new opcodes.

I started with some patches to move to a model where we have
a signle top level union with structures for each opcode
(in reality per .prep() function).

At the same time we leave the existing legacy layout as is
and enforce fields are are of the same type and at the same offset.

I only started with the first few files, but in the end
the kernel should no longer use the legacy elements.

The new stuff would look like this:

struct io_uring_sqe {
    union {

        /* This is the legacy structure */
        struct {
                __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 */
                ...
        };

        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;
        };

        /* 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;

        ...
};

At least for me it would make things much easier to understand.
Whould that be something useful?
If so we could go that way for all prep() functions and
in the end also convert liburing.

Stefan Metzmacher (8):
  io_uring: move the current struct io_uring_sqe members to legacy sub
    struct
  io_uring: add a generic structure for struct io_uring_sqe
  io_uring: check legacy layout of struct io_uring_sqe with
    BUILD_BUG_SQE_LEGACY*
  io_uring: only make use generic struct io_uring_sqe elements for
    tracing
  io_uring: only access generic struct io_uring_sqe elements in
    io_uring.c
  io_uring: add BUILD_BUG_SQE_HDR_COMMON() macro
  io_uring: introduce struct io_uring_sqe_rw for all io_prep_rw() using
    opcodes
  io_uring: introduce struct io_uring_sqe_{fsync,sfr,fallocate}

 include/trace/events/io_uring.h |  30 ++---
 include/uapi/linux/io_uring.h   | 223 +++++++++++++++++++++++---------
 io_uring/io_uring.c             | 205 ++++++++++++++++++++++-------
 io_uring/rw.c                   |  26 +++-
 io_uring/sync.c                 |  58 ++++++---
 5 files changed, 394 insertions(+), 148 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [RFC PATCH 1/8] io_uring: move the current struct io_uring_sqe members to legacy sub struct
  2022-08-12  8:34 [RFC PATCH 0/8] cleanup struct io_uring_sqe layout Stefan Metzmacher
@ 2022-08-12  8:34 ` Stefan Metzmacher
  2022-08-12  8:34 ` [RFC PATCH 2/8] io_uring: add a generic structure for struct io_uring_sqe Stefan Metzmacher
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Stefan Metzmacher @ 2022-08-12  8:34 UTC (permalink / raw)
  To: io-uring, axboe; +Cc: Stefan Metzmacher

Adding more and more opcodes makes the layout of struct io_uring_sqe
really complex and very hard to keep an overview what fields are
required to be the same for all opcodes and which can be adjusted
per opcode.

Adding unnamed union and struct, doesn't change anything to current
callers.

Check with 'git show -w' it's mainly just an indentation change.

The next patches will fill the union with specific structure for
each .prep() function.

Signed-off-by: Stefan Metzmacher <[email protected]>
---
 include/uapi/linux/io_uring.h | 129 ++++++++++++++++++----------------
 1 file changed, 67 insertions(+), 62 deletions(-)

diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h
index 1463cfecb56b..83f16bce3dc7 100644
--- a/include/uapi/linux/io_uring.h
+++ b/include/uapi/linux/io_uring.h
@@ -16,72 +16,77 @@
  * IO submission data structure (Submission Queue Entry)
  */
 struct io_uring_sqe {
-	__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 */
 	union {
-		__u64	off;	/* offset into file */
-		__u64	addr2;
+		/* This is the legacy structure */
 		struct {
-			__u32	cmd_op;
-			__u32	__pad1;
+			__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 */
+			union {
+				__u64	off;	/* offset into file */
+				__u64	addr2;
+				struct {
+					__u32	cmd_op;
+					__u32	__pad1;
+				};
+			};
+			union {
+				__u64	addr;	/* pointer to buffer or iovecs */
+				__u64	splice_off_in;
+			};
+			__u32	len;		/* buffer size or number of iovecs */
+			union {
+				__kernel_rwf_t	rw_flags;
+				__u32		fsync_flags;
+				__u16		poll_events;	/* compatibility */
+				__u32		poll32_events;	/* word-reversed for BE */
+				__u32		sync_range_flags;
+				__u32		msg_flags;
+				__u32		timeout_flags;
+				__u32		accept_flags;
+				__u32		cancel_flags;
+				__u32		open_flags;
+				__u32		statx_flags;
+				__u32		fadvise_advice;
+				__u32		splice_flags;
+				__u32		rename_flags;
+				__u32		unlink_flags;
+				__u32		hardlink_flags;
+				__u32		xattr_flags;
+				__u32		msg_ring_flags;
+			};
+			__u64	user_data;	/* data to be passed back at completion time */
+			/* pack this to avoid bogus arm OABI complaints */
+			union {
+				/* index into fixed buffers, if used */
+				__u16	buf_index;
+				/* for grouped buffer selection */
+				__u16	buf_group;
+			} __attribute__((packed));
+			/* personality to use, if used */
+			__u16	personality;
+			union {
+				__s32	splice_fd_in;
+				__u32	file_index;
+				struct {
+					__u16	notification_idx;
+					__u16	addr_len;
+				};
+			};
+			union {
+				struct {
+					__u64	addr3;
+					__u64	__pad2[1];
+				};
+				/*
+				 * If the ring is initialized with IORING_SETUP_SQE128, then
+				 * this field is used for 80 bytes of arbitrary command data
+				 */
+				__u8	cmd[0];
+			};
 		};
 	};
-	union {
-		__u64	addr;	/* pointer to buffer or iovecs */
-		__u64	splice_off_in;
-	};
-	__u32	len;		/* buffer size or number of iovecs */
-	union {
-		__kernel_rwf_t	rw_flags;
-		__u32		fsync_flags;
-		__u16		poll_events;	/* compatibility */
-		__u32		poll32_events;	/* word-reversed for BE */
-		__u32		sync_range_flags;
-		__u32		msg_flags;
-		__u32		timeout_flags;
-		__u32		accept_flags;
-		__u32		cancel_flags;
-		__u32		open_flags;
-		__u32		statx_flags;
-		__u32		fadvise_advice;
-		__u32		splice_flags;
-		__u32		rename_flags;
-		__u32		unlink_flags;
-		__u32		hardlink_flags;
-		__u32		xattr_flags;
-		__u32		msg_ring_flags;
-	};
-	__u64	user_data;	/* data to be passed back at completion time */
-	/* pack this to avoid bogus arm OABI complaints */
-	union {
-		/* index into fixed buffers, if used */
-		__u16	buf_index;
-		/* for grouped buffer selection */
-		__u16	buf_group;
-	} __attribute__((packed));
-	/* personality to use, if used */
-	__u16	personality;
-	union {
-		__s32	splice_fd_in;
-		__u32	file_index;
-		struct {
-			__u16	notification_idx;
-			__u16	addr_len;
-		};
-	};
-	union {
-		struct {
-			__u64	addr3;
-			__u64	__pad2[1];
-		};
-		/*
-		 * If the ring is initialized with IORING_SETUP_SQE128, then
-		 * this field is used for 80 bytes of arbitrary command data
-		 */
-		__u8	cmd[0];
-	};
 };
 
 /*
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [RFC PATCH 2/8] io_uring: add a generic structure for struct io_uring_sqe
  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
  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
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Stefan Metzmacher @ 2022-08-12  8:34 UTC (permalink / raw)
  To: io-uring, axboe; +Cc: Stefan Metzmacher

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


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [RFC PATCH 3/8] io_uring: check legacy layout of struct io_uring_sqe with BUILD_BUG_SQE_LEGACY*
  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 ` [RFC PATCH 2/8] io_uring: add a generic structure for struct io_uring_sqe Stefan Metzmacher
@ 2022-08-12  8:34 ` 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
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Stefan Metzmacher @ 2022-08-12  8:34 UTC (permalink / raw)
  To: io-uring, axboe; +Cc: Stefan Metzmacher

This makes the next changes easier.

Signed-off-by: Stefan Metzmacher <[email protected]>
---
 io_uring/io_uring.c | 88 +++++++++++++++++++++++----------------------
 1 file changed, 46 insertions(+), 42 deletions(-)

diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 427dde7dfbd1..60426265ee9f 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -3908,6 +3908,10 @@ static int __init io_uring_init(void)
 #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(eoffset, etype, lname) \
+	__BUILD_BUG_VERIFY_OFFSET_SIZE(struct io_uring_sqe, eoffset, sizeof(etype), lname)
+#define BUILD_BUG_SQE_LEGACY_SIZE(eoffset, esize, lname) \
+	__BUILD_BUG_VERIFY_OFFSET_SIZE(struct io_uring_sqe, eoffset, esize, lname)
 #define BUILD_BUG_SQE_LEGACY_ALIAS(eoffset, etype, ename, lname) \
 	__BUILD_BUG_VERIFY_ALIAS(struct io_uring_sqe, eoffset, sizeof(etype), ename, lname)
 
@@ -3941,48 +3945,48 @@ static int __init io_uring_init(void)
 	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);
-	BUILD_BUG_SQE_ELEM(4,  __s32,  fd);
-	BUILD_BUG_SQE_ELEM(8,  __u64,  off);
-	BUILD_BUG_SQE_ELEM(8,  __u64,  addr2);
-	BUILD_BUG_SQE_ELEM(8,  __u32,  cmd_op);
-	BUILD_BUG_SQE_ELEM(12, __u32, __pad1);
-	BUILD_BUG_SQE_ELEM(16, __u64,  addr);
-	BUILD_BUG_SQE_ELEM(16, __u64,  splice_off_in);
-	BUILD_BUG_SQE_ELEM(24, __u32,  len);
-	BUILD_BUG_SQE_ELEM(28,     __kernel_rwf_t, rw_flags);
-	BUILD_BUG_SQE_ELEM(28, /* compat */   int, rw_flags);
-	BUILD_BUG_SQE_ELEM(28, /* compat */ __u32, rw_flags);
-	BUILD_BUG_SQE_ELEM(28, __u32,  fsync_flags);
-	BUILD_BUG_SQE_ELEM(28, /* compat */ __u16,  poll_events);
-	BUILD_BUG_SQE_ELEM(28, __u32,  poll32_events);
-	BUILD_BUG_SQE_ELEM(28, __u32,  sync_range_flags);
-	BUILD_BUG_SQE_ELEM(28, __u32,  msg_flags);
-	BUILD_BUG_SQE_ELEM(28, __u32,  timeout_flags);
-	BUILD_BUG_SQE_ELEM(28, __u32,  accept_flags);
-	BUILD_BUG_SQE_ELEM(28, __u32,  cancel_flags);
-	BUILD_BUG_SQE_ELEM(28, __u32,  open_flags);
-	BUILD_BUG_SQE_ELEM(28, __u32,  statx_flags);
-	BUILD_BUG_SQE_ELEM(28, __u32,  fadvise_advice);
-	BUILD_BUG_SQE_ELEM(28, __u32,  splice_flags);
-	BUILD_BUG_SQE_ELEM(28, __u32,  rename_flags);
-	BUILD_BUG_SQE_ELEM(28, __u32,  unlink_flags);
-	BUILD_BUG_SQE_ELEM(28, __u32,  hardlink_flags);
-	BUILD_BUG_SQE_ELEM(28, __u32,  xattr_flags);
-	BUILD_BUG_SQE_ELEM(28, __u32,  msg_ring_flags);
-	BUILD_BUG_SQE_ELEM(32, __u64,  user_data);
-	BUILD_BUG_SQE_ELEM(40, __u16,  buf_index);
-	BUILD_BUG_SQE_ELEM(40, __u16,  buf_group);
-	BUILD_BUG_SQE_ELEM(42, __u16,  personality);
-	BUILD_BUG_SQE_ELEM(44, __s32,  splice_fd_in);
-	BUILD_BUG_SQE_ELEM(44, __u32,  file_index);
-	BUILD_BUG_SQE_ELEM(44, __u16,  notification_idx);
-	BUILD_BUG_SQE_ELEM(46, __u16,  addr_len);
-	BUILD_BUG_SQE_ELEM(48, __u64,  addr3);
-	BUILD_BUG_SQE_ELEM_SIZE(48, 0, cmd);
-	BUILD_BUG_SQE_ELEM(56, __u64,  __pad2);
+	BUILD_BUG_SQE_LEGACY(0,  __u8,   opcode);
+	BUILD_BUG_SQE_LEGACY(1,  __u8,   flags);
+	BUILD_BUG_SQE_LEGACY(2,  __u16,  ioprio);
+	BUILD_BUG_SQE_LEGACY(4,  __s32,  fd);
+	BUILD_BUG_SQE_LEGACY(8,  __u64,  off);
+	BUILD_BUG_SQE_LEGACY(8,  __u64,  addr2);
+	BUILD_BUG_SQE_LEGACY(8,  __u32,  cmd_op);
+	BUILD_BUG_SQE_LEGACY(12, __u32, __pad1);
+	BUILD_BUG_SQE_LEGACY(16, __u64,  addr);
+	BUILD_BUG_SQE_LEGACY(16, __u64,  splice_off_in);
+	BUILD_BUG_SQE_LEGACY(24, __u32,  len);
+	BUILD_BUG_SQE_LEGACY(28,     __kernel_rwf_t, rw_flags);
+	BUILD_BUG_SQE_LEGACY(28, /* compat */   int, rw_flags);
+	BUILD_BUG_SQE_LEGACY(28, /* compat */ __u32, rw_flags);
+	BUILD_BUG_SQE_LEGACY(28, __u32,  fsync_flags);
+	BUILD_BUG_SQE_LEGACY(28, /* compat */ __u16,  poll_events);
+	BUILD_BUG_SQE_LEGACY(28, __u32,  poll32_events);
+	BUILD_BUG_SQE_LEGACY(28, __u32,  sync_range_flags);
+	BUILD_BUG_SQE_LEGACY(28, __u32,  msg_flags);
+	BUILD_BUG_SQE_LEGACY(28, __u32,  timeout_flags);
+	BUILD_BUG_SQE_LEGACY(28, __u32,  accept_flags);
+	BUILD_BUG_SQE_LEGACY(28, __u32,  cancel_flags);
+	BUILD_BUG_SQE_LEGACY(28, __u32,  open_flags);
+	BUILD_BUG_SQE_LEGACY(28, __u32,  statx_flags);
+	BUILD_BUG_SQE_LEGACY(28, __u32,  fadvise_advice);
+	BUILD_BUG_SQE_LEGACY(28, __u32,  splice_flags);
+	BUILD_BUG_SQE_LEGACY(28, __u32,  rename_flags);
+	BUILD_BUG_SQE_LEGACY(28, __u32,  unlink_flags);
+	BUILD_BUG_SQE_LEGACY(28, __u32,  hardlink_flags);
+	BUILD_BUG_SQE_LEGACY(28, __u32,  xattr_flags);
+	BUILD_BUG_SQE_LEGACY(28, __u32,  msg_ring_flags);
+	BUILD_BUG_SQE_LEGACY(32, __u64,  user_data);
+	BUILD_BUG_SQE_LEGACY(40, __u16,  buf_index);
+	BUILD_BUG_SQE_LEGACY(40, __u16,  buf_group);
+	BUILD_BUG_SQE_LEGACY(42, __u16,  personality);
+	BUILD_BUG_SQE_LEGACY(44, __s32,  splice_fd_in);
+	BUILD_BUG_SQE_LEGACY(44, __u32,  file_index);
+	BUILD_BUG_SQE_LEGACY(44, __u16,  notification_idx);
+	BUILD_BUG_SQE_LEGACY(46, __u16,  addr_len);
+	BUILD_BUG_SQE_LEGACY(48, __u64,  addr3);
+	BUILD_BUG_SQE_LEGACY_SIZE(48, 0, cmd);
+	BUILD_BUG_SQE_LEGACY(56, __u64,  __pad2);
 
 	BUILD_BUG_ON(sizeof(struct io_uring_files_update) !=
 		     sizeof(struct io_uring_rsrc_update));
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [RFC PATCH 4/8] io_uring: only make use generic struct io_uring_sqe elements for tracing
  2022-08-12  8:34 [RFC PATCH 0/8] cleanup struct io_uring_sqe layout Stefan Metzmacher
                   ` (2 preceding siblings ...)
  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 ` 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
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Stefan Metzmacher @ 2022-08-12  8:34 UTC (permalink / raw)
  To: io-uring, axboe; +Cc: Stefan Metzmacher

In the long run we might change the output, but for now just
prepare that defining IO_URING_SQE_HIDE_LEGACY would be possible.

Signed-off-by: Stefan Metzmacher <[email protected]>
---
 include/trace/events/io_uring.h | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/include/trace/events/io_uring.h b/include/trace/events/io_uring.h
index c5b21ff0ac85..12ffbe4e69cc 100644
--- a/include/trace/events/io_uring.h
+++ b/include/trace/events/io_uring.h
@@ -520,28 +520,28 @@ TRACE_EVENT(io_uring_req_failed,
 		__field( u64,			addr3		)
 		__field( int,			error		)
 
-		__string( op_str, io_uring_get_opcode(sqe->opcode) )
+		__string( op_str, io_uring_get_opcode(sqe->hdr.opcode) )
 	),
 
 	TP_fast_assign(
 		__entry->ctx		= req->ctx;
 		__entry->req		= req;
-		__entry->user_data	= sqe->user_data;
-		__entry->opcode		= sqe->opcode;
-		__entry->flags		= sqe->flags;
-		__entry->ioprio		= sqe->ioprio;
-		__entry->off		= sqe->off;
-		__entry->addr		= sqe->addr;
-		__entry->len		= sqe->len;
-		__entry->op_flags	= sqe->poll32_events;
-		__entry->buf_index	= sqe->buf_index;
-		__entry->personality	= sqe->personality;
-		__entry->file_index	= sqe->file_index;
-		__entry->pad1		= sqe->__pad2[0];
-		__entry->addr3		= sqe->addr3;
+		__entry->user_data	= sqe->common.user_data;
+		__entry->opcode		= sqe->hdr.opcode;
+		__entry->flags		= sqe->hdr.flags;
+		__entry->ioprio		= sqe->hdr.ioprio;
+		__entry->off		= sqe->u64_ofs08;
+		__entry->addr		= sqe->u64_ofs16;
+		__entry->len		= sqe->u32_ofs24;
+		__entry->op_flags	= sqe->u32_ofs28;
+		__entry->buf_index	= sqe->common.buf_info;
+		__entry->personality	= sqe->common.personality;
+		__entry->file_index	= sqe->u32_ofs44;
+		__entry->pad1		= sqe->u64_ofs56;
+		__entry->addr3		= sqe->u64_ofs48;
 		__entry->error		= error;
 
-		__assign_str(op_str, io_uring_get_opcode(sqe->opcode));
+		__assign_str(op_str, io_uring_get_opcode(sqe->hdr.opcode));
 	),
 
 	TP_printk("ring %p, req %p, user_data 0x%llx, "
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [RFC PATCH 5/8] io_uring: only access generic struct io_uring_sqe elements in io_uring.c
  2022-08-12  8:34 [RFC PATCH 0/8] cleanup struct io_uring_sqe layout Stefan Metzmacher
                   ` (3 preceding siblings ...)
  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 ` Stefan Metzmacher
  2022-08-12  8:34 ` [RFC PATCH 6/8] io_uring: add BUILD_BUG_SQE_HDR_COMMON() macro Stefan Metzmacher
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Stefan Metzmacher @ 2022-08-12  8:34 UTC (permalink / raw)
  To: io-uring, axboe; +Cc: Stefan Metzmacher

Signed-off-by: Stefan Metzmacher <[email protected]>
---
 io_uring/io_uring.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 60426265ee9f..f82173bde393 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -39,6 +39,7 @@
  * Copyright (C) 2018-2019 Jens Axboe
  * Copyright (c) 2018-2019 Christoph Hellwig
  */
+#define IO_URING_SQE_HIDE_LEGACY 1
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/errno.h>
@@ -1837,10 +1838,10 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
 	u8 opcode;
 
 	/* req is partially pre-initialised, see io_preinit_req() */
-	req->opcode = opcode = READ_ONCE(sqe->opcode);
+	req->opcode = opcode = READ_ONCE(sqe->hdr.opcode);
 	/* same numerical values with corresponding REQ_F_*, safe to copy */
-	req->flags = sqe_flags = READ_ONCE(sqe->flags);
-	req->cqe.user_data = READ_ONCE(sqe->user_data);
+	req->flags = sqe_flags = READ_ONCE(sqe->hdr.flags);
+	req->cqe.user_data = READ_ONCE(sqe->common.user_data);
 	req->file = NULL;
 	req->rsrc_node = NULL;
 	req->task = current;
@@ -1857,7 +1858,7 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
 		if (sqe_flags & IOSQE_BUFFER_SELECT) {
 			if (!def->buffer_select)
 				return -EOPNOTSUPP;
-			req->buf_index = READ_ONCE(sqe->buf_group);
+			req->buf_index = READ_ONCE(sqe->common.buf_info);
 		}
 		if (sqe_flags & IOSQE_CQE_SKIP_SUCCESS)
 			ctx->drain_disabled = true;
@@ -1881,7 +1882,7 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
 		}
 	}
 
-	if (!def->ioprio && sqe->ioprio)
+	if (!def->ioprio && sqe->hdr.ioprio)
 		return -EINVAL;
 	if (!def->iopoll && (ctx->flags & IORING_SETUP_IOPOLL))
 		return -EINVAL;
@@ -1889,7 +1890,7 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
 	if (def->needs_file) {
 		struct io_submit_state *state = &ctx->submit_state;
 
-		req->cqe.fd = READ_ONCE(sqe->fd);
+		req->cqe.fd = READ_ONCE(sqe->hdr.fd);
 
 		/*
 		 * Plug now if we have more than 2 IO left after this, and the
@@ -1902,7 +1903,7 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
 		}
 	}
 
-	personality = READ_ONCE(sqe->personality);
+	personality = READ_ONCE(sqe->common.personality);
 	if (personality) {
 		int ret;
 
@@ -3909,11 +3910,11 @@ static int __init io_uring_init(void)
 	__BUILD_BUG_VERIFY_ALIAS(struct io_uring_sqe, eoffset, sizeof(etype), ename, aname)
 
 #define BUILD_BUG_SQE_LEGACY(eoffset, etype, lname) \
-	__BUILD_BUG_VERIFY_OFFSET_SIZE(struct io_uring_sqe, eoffset, sizeof(etype), lname)
+	__BUILD_BUG_VERIFY_OFFSET_SIZE(struct io_uring_sqe, eoffset, sizeof(etype), legacy.lname)
 #define BUILD_BUG_SQE_LEGACY_SIZE(eoffset, esize, lname) \
-	__BUILD_BUG_VERIFY_OFFSET_SIZE(struct io_uring_sqe, eoffset, esize, lname)
+	__BUILD_BUG_VERIFY_OFFSET_SIZE(struct io_uring_sqe, eoffset, esize, legacy.lname)
 #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_VERIFY_ALIAS(struct io_uring_sqe, eoffset, sizeof(etype), ename, legacy.lname)
 
 	BUILD_BUG_ON(sizeof(struct io_uring_sqe_hdr) != 8);
 	BUILD_BUG_SQE_HDR_ELEM(0,  __u8,   opcode);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [RFC PATCH 6/8] io_uring: add BUILD_BUG_SQE_HDR_COMMON() macro
  2022-08-12  8:34 [RFC PATCH 0/8] cleanup struct io_uring_sqe layout Stefan Metzmacher
                   ` (4 preceding siblings ...)
  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 ` 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
  7 siblings, 0 replies; 9+ messages in thread
From: Stefan Metzmacher @ 2022-08-12  8:34 UTC (permalink / raw)
  To: io-uring, axboe; +Cc: Stefan Metzmacher

This will be used in the next commits in order to
check common fields of opcode specific struct io_uring_sqe
union arms.

Signed-off-by: Stefan Metzmacher <[email protected]>
---
 io_uring/io_uring.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index f82173bde393..8e1a8800b252 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -3916,6 +3916,20 @@ static int __init io_uring_init(void)
 #define BUILD_BUG_SQE_LEGACY_ALIAS(eoffset, etype, ename, lname) \
 	__BUILD_BUG_VERIFY_ALIAS(struct io_uring_sqe, eoffset, sizeof(etype), ename, legacy.lname)
 
+#define BUILD_BUG_SQE_HDR_COMMON(subtype, subname) do { \
+	BUILD_BUG_ON(sizeof(subtype) != 64); \
+	BUILD_BUG_SQE_ELEM(0,  subtype, subname); \
+	BUILD_BUG_SQE_ELEM(0,  struct io_uring_sqe_hdr, subname.hdr); \
+	BUILD_BUG_SQE_ALIAS(0,  __u8,   subname.hdr.opcode, hdr.opcode); \
+	BUILD_BUG_SQE_ALIAS(1,  __u8,   subname.hdr.flags, hdr.flags); \
+	BUILD_BUG_SQE_ALIAS(2,  __u16,  subname.hdr.ioprio, hdr.ioprio); \
+	BUILD_BUG_SQE_ALIAS(4,  __s32,  subname.hdr.fd, hdr.fd); \
+	BUILD_BUG_SQE_ELEM(32, struct io_uring_sqe_common, subname.common); \
+	BUILD_BUG_SQE_ALIAS(32, __u64,  subname.common.user_data, common.user_data); \
+	BUILD_BUG_SQE_ALIAS(40, __u16,  subname.common.buf_info, common.buf_info); \
+	BUILD_BUG_SQE_ALIAS(42, __u16,  subname.common.personality, common.personality); \
+} while (0)
+
 	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);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [RFC PATCH 7/8] io_uring: introduce struct io_uring_sqe_rw for all io_prep_rw() using opcodes
  2022-08-12  8:34 [RFC PATCH 0/8] cleanup struct io_uring_sqe layout Stefan Metzmacher
                   ` (5 preceding siblings ...)
  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 ` Stefan Metzmacher
  2022-08-12  8:34 ` [RFC PATCH 8/8] io_uring: introduce struct io_uring_sqe_{fsync,sfr,fallocate} Stefan Metzmacher
  7 siblings, 0 replies; 9+ messages in thread
From: Stefan Metzmacher @ 2022-08-12  8:34 UTC (permalink / raw)
  To: io-uring, axboe; +Cc: Stefan Metzmacher

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


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [RFC PATCH 8/8] io_uring: introduce struct io_uring_sqe_{fsync,sfr,fallocate}
  2022-08-12  8:34 [RFC PATCH 0/8] cleanup struct io_uring_sqe layout Stefan Metzmacher
                   ` (6 preceding siblings ...)
  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 ` Stefan Metzmacher
  7 siblings, 0 replies; 9+ messages in thread
From: Stefan Metzmacher @ 2022-08-12  8:34 UTC (permalink / raw)
  To: io-uring, axboe; +Cc: Stefan Metzmacher

This allows us to use IO_URING_SQE_HIDE_LEGACY in io_uring/sync.c

Signed-off-by: Stefan Metzmacher <[email protected]>
---
 include/uapi/linux/io_uring.h | 48 +++++++++++++++++++++++++++++
 io_uring/io_uring.c           | 33 ++++++++++++++++++++
 io_uring/sync.c               | 58 ++++++++++++++++++++++++++---------
 3 files changed, 124 insertions(+), 15 deletions(-)

diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h
index 690b13229227..6428d97e14fc 100644
--- a/include/uapi/linux/io_uring.h
+++ b/include/uapi/linux/io_uring.h
@@ -132,6 +132,54 @@ struct io_uring_sqe {
 			__u64	u64_ofs48;
 			__u64	u64_ofs56;
 		} rw;
+
+		/* IORING_OP_FSYNC */
+		struct io_uring_sqe_fsync {
+			struct io_uring_sqe_hdr hdr;
+
+			__u64	offset;
+			__u64	u64_ofs16;
+			__u32	length;
+			__u32	flags;
+
+			struct io_uring_sqe_common common;
+
+			__u32	u32_ofs44;
+			__u64	u64_ofs48;
+			__u64	u64_ofs56;
+		} fsync;
+
+		/* IORING_OP_SYNC_FILE_RANGE */
+		struct io_uring_sqe_sfr {
+			struct io_uring_sqe_hdr hdr;
+
+			__u64	offset;
+			__u64	u64_ofs16;
+			__u32	length;
+			__u32	flags;
+
+			struct io_uring_sqe_common common;
+
+			__u32	u32_ofs44;
+			__u64	u64_ofs48;
+			__u64	u64_ofs56;
+		} sfr;
+
+		/* IORING_OP_FALLOCATE */
+		struct io_uring_sqe_fallocate {
+			struct io_uring_sqe_hdr hdr;
+
+			__u64	offset;
+			__u64	length;
+			__u32	mode;
+			__u32	u32_ofs28;
+
+			struct io_uring_sqe_common common;
+
+			__u32	u32_ofs44;
+			__u64	u64_ofs48;
+			__u64	u64_ofs56;
+		} fallocate;
 	};
 };
 
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index e3336621e667..893252701363 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -4012,6 +4012,39 @@ static int __init io_uring_init(void)
 	BUILD_BUG_SQE_ALIAS(48,		__u64, rw.u64_ofs48,	u64_ofs48);
 	BUILD_BUG_SQE_ALIAS(56,		__u64, rw.u64_ofs56,	u64_ofs56);
 
+	BUILD_BUG_SQE_HDR_COMMON(struct io_uring_sqe_fsync, fsync);
+	BUILD_BUG_SQE_LEGACY_ALIAS(8,	__u64, fsync.offset,	off);
+	BUILD_BUG_SQE_LEGACY_ALIAS(16,	__u64, fsync.u64_ofs16,	addr);
+	BUILD_BUG_SQE_ALIAS(16,		__u64, fsync.u64_ofs16,	u64_ofs16);
+	BUILD_BUG_SQE_LEGACY_ALIAS(24,	__u32, fsync.length,	len);
+	BUILD_BUG_SQE_LEGACY_ALIAS(28,	__u32, fsync.flags,	fsync_flags);
+	BUILD_BUG_SQE_LEGACY_ALIAS(44,	__u32, fsync.u32_ofs44,	splice_fd_in);
+	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_SQE_HDR_COMMON(struct io_uring_sqe_sfr, sfr);
+	BUILD_BUG_SQE_LEGACY_ALIAS(8,	__u64, sfr.offset,	off);
+	BUILD_BUG_SQE_LEGACY_ALIAS(16,	__u64, sfr.u64_ofs16,	addr);
+	BUILD_BUG_SQE_ALIAS(16,		__u64, sfr.u64_ofs16,	u64_ofs16);
+	BUILD_BUG_SQE_LEGACY_ALIAS(24,	__u32, sfr.length,	len);
+	BUILD_BUG_SQE_LEGACY_ALIAS(28,	__u32, sfr.flags,	fsync_flags);
+	BUILD_BUG_SQE_LEGACY_ALIAS(44,	__u32, sfr.u32_ofs44,	splice_fd_in);
+	BUILD_BUG_SQE_ALIAS(44,		__u32, sfr.u32_ofs44,	u32_ofs44);
+	BUILD_BUG_SQE_ALIAS(48,		__u64, sfr.u64_ofs48,	u64_ofs48);
+	BUILD_BUG_SQE_ALIAS(56,		__u64, sfr.u64_ofs56,	u64_ofs56);
+
+	BUILD_BUG_SQE_HDR_COMMON(struct io_uring_sqe_fallocate, fallocate);
+	BUILD_BUG_SQE_LEGACY_ALIAS(8,	__u64, fallocate.offset,	off);
+	BUILD_BUG_SQE_LEGACY_ALIAS(16,	__u64, fallocate.length,	addr);
+	BUILD_BUG_SQE_LEGACY_ALIAS(24,	__u32, fallocate.mode,		len);
+	BUILD_BUG_SQE_LEGACY_ALIAS(28,	__u32, fallocate.u32_ofs28,	rw_flags);
+	BUILD_BUG_SQE_ALIAS(28,		__u32, fallocate.u32_ofs28,	u32_ofs28);
+	BUILD_BUG_SQE_LEGACY_ALIAS(44,	__u32, fallocate.u32_ofs44,	splice_fd_in);
+	BUILD_BUG_SQE_ALIAS(44,		__u32, fallocate.u32_ofs44,	u32_ofs44);
+	BUILD_BUG_SQE_ALIAS(48,		__u64, fallocate.u64_ofs48,	u64_ofs48);
+	BUILD_BUG_SQE_ALIAS(56,		__u64, fallocate.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/sync.c b/io_uring/sync.c
index 64e87ea2b8fb..ba8e3a91a1ab 100644
--- a/io_uring/sync.c
+++ b/io_uring/sync.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>
@@ -22,16 +23,25 @@ struct io_sync {
 	int				mode;
 };
 
-int io_sfr_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
+int io_sfr_prep(struct io_kiocb *req, const struct io_uring_sqe *_sqe)
 {
+	const struct io_uring_sqe_sfr *sqe = &_sqe->sfr;
 	struct io_sync *sync = io_kiocb_to_cmd(req, struct io_sync);
 
-	if (unlikely(sqe->addr || sqe->buf_index || sqe->splice_fd_in))
+	/*
+	 * Note for compat reasons we don't check the following
+	 * to be zero:
+	 *
+	 * sqe->u64_ofs48
+	 * sqe->u64_ofs56
+	 */
+	if (unlikely(sqe->u64_ofs16 || sqe->common.buf_info || sqe->u32_ofs44))
 		return -EINVAL;
 
-	sync->off = READ_ONCE(sqe->off);
-	sync->len = READ_ONCE(sqe->len);
-	sync->flags = READ_ONCE(sqe->sync_range_flags);
+	sync->off = READ_ONCE(sqe->offset);
+	sync->len = READ_ONCE(sqe->length);
+	sync->flags = READ_ONCE(sqe->flags);
+
 	return 0;
 }
 
@@ -49,19 +59,28 @@ int io_sync_file_range(struct io_kiocb *req, unsigned int issue_flags)
 	return IOU_OK;
 }
 
-int io_fsync_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
+int io_fsync_prep(struct io_kiocb *req, const struct io_uring_sqe *_sqe)
 {
+	const struct io_uring_sqe_fsync *sqe = &_sqe->fsync;
 	struct io_sync *sync = io_kiocb_to_cmd(req, struct io_sync);
 
-	if (unlikely(sqe->addr || sqe->buf_index || sqe->splice_fd_in))
+	/*
+	 * Note for compat reasons we don't check the following
+	 * to be zero:
+	 *
+	 * sqe->u64_ofs48
+	 * sqe->u64_ofs56
+	 */
+	if (unlikely(sqe->u64_ofs16 || sqe->common.buf_info || sqe->u32_ofs44))
 		return -EINVAL;
 
-	sync->flags = READ_ONCE(sqe->fsync_flags);
+	sync->flags = READ_ONCE(sqe->flags);
 	if (unlikely(sync->flags & ~IORING_FSYNC_DATASYNC))
 		return -EINVAL;
 
-	sync->off = READ_ONCE(sqe->off);
-	sync->len = READ_ONCE(sqe->len);
+	sync->off = READ_ONCE(sqe->offset);
+	sync->len = READ_ONCE(sqe->length);
+
 	return 0;
 }
 
@@ -81,16 +100,25 @@ int io_fsync(struct io_kiocb *req, unsigned int issue_flags)
 	return IOU_OK;
 }
 
-int io_fallocate_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
+int io_fallocate_prep(struct io_kiocb *req, const struct io_uring_sqe *_sqe)
 {
+	const struct io_uring_sqe_fallocate *sqe = &_sqe->fallocate;
 	struct io_sync *sync = io_kiocb_to_cmd(req, struct io_sync);
 
-	if (sqe->buf_index || sqe->rw_flags || sqe->splice_fd_in)
+	/*
+	 * Note for compat reasons we don't check the following
+	 * to be zero:
+	 *
+	 * sqe->u64_ofs48
+	 * sqe->u64_ofs56
+	 */
+	if (sqe->common.buf_info || sqe->u32_ofs28 || sqe->u32_ofs44)
 		return -EINVAL;
 
-	sync->off = READ_ONCE(sqe->off);
-	sync->len = READ_ONCE(sqe->addr);
-	sync->mode = READ_ONCE(sqe->len);
+	sync->off = READ_ONCE(sqe->offset);
+	sync->len = READ_ONCE(sqe->length);
+	sync->mode = READ_ONCE(sqe->mode);
+
 	return 0;
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-08-12  8:35 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [RFC PATCH 2/8] io_uring: add a generic structure for struct io_uring_sqe Stefan Metzmacher
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox