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 7/8] io_uring: introduce struct io_uring_sqe_rw for all io_prep_rw() using opcodes
Date: Fri, 12 Aug 2022 10:34:31 +0200	[thread overview]
Message-ID: <03b3026be552fe5ddb36c281d75881c3b887c89b.1660291547.git.metze@samba.org> (raw)
In-Reply-To: <[email protected]>

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


  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 ` [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 ` Stefan Metzmacher [this message]
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=03b3026be552fe5ddb36c281d75881c3b887c89b.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