public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: Keith Busch <kbusch@meta.com>
To: <io-uring@vger.kernel.org>, <axboe@kernel.dk>, <csander@purestorage.com>
Cc: Keith Busch <kbusch@kernel.org>
Subject: [PATCHv6 1/6] liburing: provide uring_cmd prep function
Date: Wed, 22 Oct 2025 10:19:19 -0700	[thread overview]
Message-ID: <20251022171924.2326863-2-kbusch@meta.com> (raw)
In-Reply-To: <20251022171924.2326863-1-kbusch@meta.com>

From: Keith Busch <kbusch@kernel.org>

The uring_cmd needs to ensure __pad1 is clear, which is a reserved field
for opcode. If a prior submission for a different opcode at that same
entry did use that field, the command would fail the kernel's checks if
the caller didn't explicity clear it. Provide an init helper for this
opcode.

Also, the nvme uring_cmd tests had a couple places setting the sqe addr
and length, which are unused fields, so they shouldn't have been doing
that, though it had been harmless to do so since the kernel isn't
checking these fields.

Provide a helper function specific to the uring_cmd preparation.

Signed-off-by: Keith Busch <kbusch@kernel.org>
---
 src/include/liburing.h      | 19 +++++++++++++++----
 test/io_uring_passthrough.c | 18 ++++++------------
 2 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/src/include/liburing.h b/src/include/liburing.h
index c80bffd3..757c3057 100644
--- a/src/include/liburing.h
+++ b/src/include/liburing.h
@@ -1517,6 +1517,19 @@ IOURINGINLINE void io_uring_prep_socket_direct_alloc(struct io_uring_sqe *sqe,
 	__io_uring_set_target_fixed_file(sqe, IORING_FILE_INDEX_ALLOC - 1);
 }
 
+IOURINGINLINE void io_uring_prep_uring_cmd(struct io_uring_sqe *sqe,
+					   __u32 cmd_op,
+					   int fd)
+	LIBURING_NOEXCEPT
+{
+	sqe->opcode = IORING_OP_URING_CMD;
+	sqe->fd = fd;
+	sqe->cmd_op = cmd_op;
+	sqe->__pad1 = 0;
+	sqe->addr = 0ul;
+	sqe->len = 0;
+}
+
 /*
  * Prepare commands for sockets
  */
@@ -1529,11 +1542,10 @@ IOURINGINLINE void io_uring_prep_cmd_sock(struct io_uring_sqe *sqe,
 					  int optlen)
 	LIBURING_NOEXCEPT
 {
-	io_uring_prep_rw(IORING_OP_URING_CMD, sqe, fd, NULL, 0, 0);
+	io_uring_prep_uring_cmd(sqe, cmd_op, fd);
 	sqe->optval = (unsigned long) (uintptr_t) optval;
 	sqe->optname = optname;
 	sqe->optlen = optlen;
-	sqe->cmd_op = cmd_op;
 	sqe->level = level;
 }
 
@@ -1607,8 +1619,7 @@ IOURINGINLINE void io_uring_prep_cmd_discard(struct io_uring_sqe *sqe,
 					     uint64_t offset, uint64_t nbytes)
 	LIBURING_NOEXCEPT
 {
-	io_uring_prep_rw(IORING_OP_URING_CMD, sqe, fd, 0, 0, 0);
-	sqe->cmd_op = BLOCK_URING_CMD_DISCARD;
+	io_uring_prep_uring_cmd(sqe, BLOCK_URING_CMD_DISCARD, fd);
 	sqe->addr = offset;
 	sqe->addr3 = nbytes;
 }
diff --git a/test/io_uring_passthrough.c b/test/io_uring_passthrough.c
index beaa81ad..0442b3a3 100644
--- a/test/io_uring_passthrough.c
+++ b/test/io_uring_passthrough.c
@@ -141,18 +141,16 @@ static int __test_io(const char *file, struct io_uring *ring, int tc, int read,
 
 		if (sqthread)
 			use_fd = 0;
+		if (nonvec)
+			io_uring_prep_uring_cmd(sqe, NVME_URING_CMD_IO, use_fd);
+		else
+			io_uring_prep_uring_cmd(sqe, NVME_URING_CMD_IO_VEC, use_fd);
 		if (fixed && (i & 1))
 			do_fixed = 0;
 		if (do_fixed)
 			sqe->buf_index = 0;
 		if (async)
 			sqe->flags |= IOSQE_ASYNC;
-		if (nonvec)
-			sqe->cmd_op = NVME_URING_CMD_IO;
-		else
-			sqe->cmd_op = NVME_URING_CMD_IO_VEC;
-		sqe->fd = use_fd;
-		sqe->opcode = IORING_OP_URING_CMD;
 		if (do_fixed)
 			sqe->uring_cmd_flags |= IORING_URING_CMD_FIXED;
 		sqe->user_data = ((uint64_t)offset << 32) | i;
@@ -328,9 +326,7 @@ static int test_invalid_passthru_submit(const char *file)
 	}
 
 	sqe = io_uring_get_sqe(&ring);
-	io_uring_prep_read(sqe, fd, vecs[0].iov_base, vecs[0].iov_len, 0);
-	sqe->cmd_op = NVME_URING_CMD_IO;
-	sqe->opcode = IORING_OP_URING_CMD;
+	io_uring_prep_uring_cmd(sqe, NVME_URING_CMD_IO, fd);
 	sqe->user_data = 1;
 	cmd = (struct nvme_uring_cmd *)sqe->cmd;
 	memset(cmd, 0, sizeof(struct nvme_uring_cmd));
@@ -401,10 +397,8 @@ static int test_io_uring_submit_enters(const char *file)
 		__u32 nlb;
 
 		sqe = io_uring_get_sqe(&ring);
-		io_uring_prep_readv(sqe, fd, &vecs[i], 1, offset);
+		io_uring_prep_uring_cmd(sqe, NVME_URING_CMD_IO, fd);
 		sqe->user_data = i;
-		sqe->opcode = IORING_OP_URING_CMD;
-		sqe->cmd_op = NVME_URING_CMD_IO;
 		cmd = (struct nvme_uring_cmd *)sqe->cmd;
 		memset(cmd, 0, sizeof(struct nvme_uring_cmd));
 
-- 
2.47.3


  reply	other threads:[~2025-10-22 17:21 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-22 17:19 [PATCHv6 0/6] liburing: support for mixed sqes Keith Busch
2025-10-22 17:19 ` Keith Busch [this message]
2025-10-22 17:19 ` [PATCHv6 2/6] Add support IORING_SETUP_SQE_MIXED Keith Busch
2025-10-22 17:35   ` Jens Axboe
2025-10-22 17:19 ` [PATCHv6 3/6] test: add nop testing for IORING_SETUP_SQE_MIXED Keith Busch
2025-10-22 17:19 ` [PATCHv6 4/6] test: add mixed sqe test for uring commands Keith Busch
2025-10-22 17:19 ` [PATCHv6 5/6] test/fdinfo: flush sq prior to reading Keith Busch
2025-10-22 17:19 ` [PATCHv6 6/6] test/fdinfo: add mixed sqe option to fdinfo test Keith Busch
2025-10-22 17:40 ` [PATCHv6 0/6] liburing: support for mixed sqes Jens Axboe

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=20251022171924.2326863-2-kbusch@meta.com \
    --to=kbusch@meta.com \
    --cc=axboe@kernel.dk \
    --cc=csander@purestorage.com \
    --cc=io-uring@vger.kernel.org \
    --cc=kbusch@kernel.org \
    /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