Skip to contentSkip to conversation

io_uring passthough for nvme

PATCH In review Pankaj Raghav 4 participants 14 messages May 3, 2022 – May 4, 2022 1 message not in the archive

Subsystems (5)
VFS Block layer Tracing NVMe +1 more subsystems
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): CGME20220503184911eucas1p1beb172219537d78fcaf2a1417f532cf7@eucas1p1.samsung.com

#1 lore raw

v3 cover io_uring passthough for nvme

From: Kanchan Joshi <[email protected]>

NOTE: Sending on behalf of Kanchan as he is having some trouble sending emails.

This iteration is against io_uring-big-sqe brach (linux-block). On top of a739b2354 ("io_uring: enable CQE32").

fio testing branch:
https://github.com/joshkan/fio/tree/big-cqe-pt.v3

Changes since v2:
- Rewire uring-cmd infrastructure on top of new big CQE
- Prep patch (refactored) and feedback from Christoph
- Add new opcode and structure in nvme for uring-cmd
- Enable vectored-io

Changes since v1:
https://lore.kernel.org/linux-nvme/[email protected]/
- Trim down by removing patches for polling, fixed-buffer and bio-cache
- Add big CQE and move uring-cmd to use that
- Remove indirect (pointer) submission

v1:
https://lore.kernel.org/linux-nvme/[email protected]/

Anuj Gupta (1):
nvme: add vectored-io support for uring-cmd

Christoph Hellwig (1):
nvme: refactor nvme_submit_user_cmd()

Jens Axboe (2):
fs,io_uring: add infrastructure for uring-cmd
block: wire-up support for passthrough plugging

Kanchan Joshi (1):
nvme: wire-up uring-cmd support for io-passthru on char-device.

 block/blk-mq.c                  |  90 +++++++-------
 drivers/nvme/host/core.c        |   1 +
 drivers/nvme/host/ioctl.c       | 212 +++++++++++++++++++++++++++++++-
 drivers/nvme/host/multipath.c   |   1 +
 drivers/nvme/host/nvme.h        |   3 +
 fs/io_uring.c                   |  81 ++++++++++--
 include/linux/fs.h              |   2 +
 include/linux/io_uring.h        |  29 +++++
 include/uapi/linux/io_uring.h   |   8 +-
 include/uapi/linux/nvme_ioctl.h |  29 +++++
 10 files changed, 399 insertions(+), 57 deletions(-)
Signature · 1 line
2.25.1
#2 lore raw

PATCH v3 1/5 fs,io_uring: add infrastructure for uring-cmd

From: Jens Axboe <[email protected]>

file_operations->uring_cmd is a file private handler, similar to ioctls but hopefully a lot more sane and useful.

IORING_OP_URING_CMD is a file private kind of request. io_uring doesn't know what is in this command type, it's for the provider of ->uring_cmd() to deal with. This operation can be issued only on the ring that is setup with both IORING_SETUP_SQE128 and IORING_SETUP_CQE32 flags.

---
 fs/io_uring.c                 | 81 ++++++++++++++++++++++++++++++++---
 include/linux/fs.h            |  2 +
 include/linux/io_uring.h      | 29 +++++++++++++
 include/uapi/linux/io_uring.h |  8 +++-
 4 files changed, 112 insertions(+), 8 deletions(-)
fs/io_uring.c +74 -7
index c7e3f7e74d92..b774e6eac538 100644
@@ -202,13 +202,6 @@ struct io_rings {
 	struct io_uring_cqe	cqes[] ____cacheline_aligned_in_smp;
 };
 
-enum io_uring_cmd_flags {
-	IO_URING_F_COMPLETE_DEFER	= 1,
-	IO_URING_F_UNLOCKED		= 2,
-	/* int's last bit, sign checks are usually faster than a bit test */
-	IO_URING_F_NONBLOCK		= INT_MIN,
-};
-
 struct io_mapped_ubuf {
 	u64		ubuf;
 	u64		ubuf_end;
@@ -969,6 +962,7 @@ struct io_kiocb {
 		struct io_xattr		xattr;
 		struct io_socket	sock;
 		struct io_nop		nop;
+		struct io_uring_cmd	uring_cmd;
 	};
 
 	u8				opcode;
@@ -1254,6 +1248,10 @@ static const struct io_op_def io_op_defs[] = {
 	[IORING_OP_SOCKET] = {
 		.audit_skip		= 1,
 	},
+	[IORING_OP_URING_CMD] = {
+		.needs_file		= 1,
+		.plug			= 1,
+	},
 };
 
 /* requests with any of those set should undergo io_disarm_next() */
@@ -1393,6 +1391,8 @@ const char *io_uring_get_opcode(u8 opcode)
 		return "GETXATTR";
 	case IORING_OP_SOCKET:
 		return "SOCKET";
+	case IORING_OP_URING_CMD:
+		return "URING_CMD";
 	case IORING_OP_LAST:
 		return "INVALID";
 	}
@@ -4907,6 +4907,66 @@ static int io_linkat(struct io_kiocb *req, unsigned int issue_flags)
 	return 0;
 }
 
+static void io_uring_cmd_work(struct io_kiocb *req, bool *locked)
+{
+	req->uring_cmd.driver_cb(&req->uring_cmd);
+}
+
+void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
+			void (*driver_cb)(struct io_uring_cmd *))
+{
+	struct io_kiocb *req = container_of(ioucmd, struct io_kiocb, uring_cmd);
+
+	req->uring_cmd.driver_cb = driver_cb;
+	req->io_task_work.func = io_uring_cmd_work;
+	io_req_task_work_add(req, !!(req->ctx->flags & IORING_SETUP_SQPOLL));
+}
+EXPORT_SYMBOL_GPL(io_uring_cmd_complete_in_task);
+
+/*
+ * Called by consumers of io_uring_cmd, if they originally returned
+ * -EIOCBQUEUED upon receiving the command.
+ */
+void io_uring_cmd_done(struct io_uring_cmd *ioucmd, ssize_t ret, ssize_t res2)
+{
+	struct io_kiocb *req = container_of(ioucmd, struct io_kiocb, uring_cmd);
+
+	if (ret < 0)
+		req_set_fail(req);
+	__io_req_complete32(req, 0, ret, 0, res2, 0);
+}
+EXPORT_SYMBOL_GPL(io_uring_cmd_done);
+
+static int io_uring_cmd_prep(struct io_kiocb *req,
+			     const struct io_uring_sqe *sqe)
+{
+	struct io_uring_cmd *ioucmd = &req->uring_cmd;
+
+	if (req->ctx->flags & IORING_SETUP_IOPOLL)
+		return -EOPNOTSUPP;
+	/* do not support uring-cmd without big SQE/CQE */
+	if (!(req->ctx->flags & IORING_SETUP_SQE128))
+		return -EOPNOTSUPP;
+	if (!(req->ctx->flags & IORING_SETUP_CQE32))
+		return -EOPNOTSUPP;
+	ioucmd->cmd = (void *) &sqe->cmd;
+	ioucmd->cmd_op = READ_ONCE(sqe->cmd_op);
+	ioucmd->flags = 0;
+	return 0;
+}
+
+static int io_uring_cmd(struct io_kiocb *req, unsigned int issue_flags)
+{
+	struct file *file = req->file;
+	struct io_uring_cmd *ioucmd = &req->uring_cmd;
+
+	if (!req->file->f_op->uring_cmd)
+		return -EOPNOTSUPP;
+	ioucmd->flags |= issue_flags;
+	file->f_op->uring_cmd(ioucmd);
+	return 0;
+}
+
 static int io_shutdown_prep(struct io_kiocb *req,
 			    const struct io_uring_sqe *sqe)
 {
@@ -7764,6 +7824,8 @@ static int io_req_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 		return io_getxattr_prep(req, sqe);
 	case IORING_OP_SOCKET:
 		return io_socket_prep(req, sqe);
+	case IORING_OP_URING_CMD:
+		return io_uring_cmd_prep(req, sqe);
 	}
 
 	printk_once(KERN_WARNING "io_uring: unhandled opcode %d\n",
@@ -8085,6 +8147,9 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags)
 	case IORING_OP_SOCKET:
 		ret = io_socket(req, issue_flags);
 		break;
+	case IORING_OP_URING_CMD:
+		ret = io_uring_cmd(req, issue_flags);
+		break;
 	default:
 		ret = -EINVAL;
 		break;
@@ -12688,6 +12753,8 @@ static int __init io_uring_init(void)
 	BUILD_BUG_ON(ARRAY_SIZE(io_op_defs) != IORING_OP_LAST);
 	BUILD_BUG_ON(__REQ_F_LAST_BIT > 8 * sizeof(int));
 
+	BUILD_BUG_ON(sizeof(struct io_uring_cmd) > 64);
+
 	req_cachep = KMEM_CACHE(io_kiocb, SLAB_HWCACHE_ALIGN | SLAB_PANIC |
 				SLAB_ACCOUNT);
 	return 0;
include/linux/fs.h +2 -0
index bbde95387a23..6b64c07efcf4 100644
@@ -1953,6 +1953,7 @@ struct dir_context {
 #define REMAP_FILE_ADVISORY		(REMAP_FILE_CAN_SHORTEN)
 
 struct iov_iter;
+struct io_uring_cmd;
 
 struct file_operations {
 	struct module *owner;
@@ -1995,6 +1996,7 @@ struct file_operations {
 				   struct file *file_out, loff_t pos_out,
 				   loff_t len, unsigned int remap_flags);
 	int (*fadvise)(struct file *, loff_t, loff_t, int);
+	void (*uring_cmd)(struct io_uring_cmd *ioucmd);
 } __randomize_layout;
 
 struct inode_operations {
include/linux/io_uring.h +29 -0
index 24651c229ed2..a4ff4696cbea 100644
@@ -5,7 +5,28 @@
 #include <linux/sched.h>
 #include <linux/xarray.h>
 
+enum io_uring_cmd_flags {
+	IO_URING_F_COMPLETE_DEFER	= 1,
+	IO_URING_F_UNLOCKED		= 2,
+	/* int's last bit, sign checks are usually faster than a bit test */
+	IO_URING_F_NONBLOCK		= INT_MIN,
+};
+
+struct io_uring_cmd {
+	struct file     *file;
+	void            *cmd;
+	/* for irq-completion - if driver requires doing stuff in task-context*/
+	void (*driver_cb)(struct io_uring_cmd *cmd);
+	u32             flags;
+	u32             cmd_op;
+	u32		unused;
+	u8		pdu[28]; /* available inline for free use */
+};
+
 #if defined(CONFIG_IO_URING)
+void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret, ssize_t res2);
+void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
+			void (*driver_cb)(struct io_uring_cmd *));
 struct sock *io_uring_get_socket(struct file *file);
 void __io_uring_cancel(bool cancel_all);
 void __io_uring_free(struct task_struct *tsk);
@@ -30,6 +51,14 @@ static inline void io_uring_free(struct task_struct *tsk)
 		__io_uring_free(tsk);
 }
 #else
+static inline void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret,
+		ssize_t ret2)
+{
+}
+static inline void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
+			void (*driver_cb)(struct io_uring_cmd *))
+{
+}
 static inline struct sock *io_uring_get_socket(struct file *file)
 {
 	return NULL;
include/uapi/linux/io_uring.h +7 -1
index 881e508767f8..c081511119bf 100644
@@ -22,10 +22,12 @@ struct io_uring_sqe {
 	union {
 		__u64	off;	/* offset into file */
 		__u64	addr2;
+		__u32	cmd_op;
 	};
 	union {
 		__u64	addr;	/* pointer to buffer or iovecs */
 		__u64	splice_off_in;
+		__u16	cmd_len;
 	};
 	__u32	len;		/* buffer size or number of iovecs */
 	union {
@@ -61,7 +63,10 @@ struct io_uring_sqe {
 		__s32	splice_fd_in;
 		__u32	file_index;
 	};
-	__u64	addr3;
+	union {
+		__u64	addr3;
+		__u64	cmd;
+	};
 	__u64	__pad2[1];
 
 	/*
@@ -160,6 +165,7 @@ enum io_uring_op {
 	IORING_OP_FGETXATTR,
 	IORING_OP_GETXATTR,
 	IORING_OP_SOCKET,
+	IORING_OP_URING_CMD,
 
 	/* this goes last, obviously */
 	IORING_OP_LAST,
Signature · 1 line
2.25.1
#3 lore raw

Re: [PATCH v3 1/5] fs,io_uring: add infrastructure for uring-cmd

This mostly looks good, but a few comments an an (untested) patch to fix these complaints below:

Review

Quoted 5 lines
(quoted diff) +5 -0
+struct io_uring_cmd {
+	struct file     *file;
+	void            *cmd;
+	/* for irq-completion - if driver requires doing stuff in task-context*/
+	void (*driver_cb)(struct io_uring_cmd *cmd);

I'd rename this task_Work_cb or similar, as driver is not very meaningful.

Review

Quoted 4 lines
(quoted diff) +4 -0
+	u32             flags;
+	u32             cmd_op;
+	u32		unused;
+	u8		pdu[28]; /* available inline for free use */

The unused field here is not only unused, but also messed up the alignment so that any pointer in pdu will not be properly aligned on 64-bit platforms and tjus might cause crashes on some platforms.

For now we can just remove it, but I really want to get rid of the pdu thing that causes these problems, but I will not hold the series off for that and plan to look into that later.

Also a lot of the fields here were using spaces instead of tabs for indentation.

Review

Quoted 5 lines
(quoted diff) +1 -0
 	union {
 		__u64	addr;	/* pointer to buffer or iovecs */
 		__u64	splice_off_in;
+		__u16	cmd_len;
 	};

This field isn't actually used and can be removed.

Review struct io_uring_sqe { · line 70

Quoted 12 lines
(quoted diff) +4 -1
 	__u32	len;		/* buffer size or number of iovecs */
 	union {
@@ -61,7 +63,10 @@ struct io_uring_sqe {
 		__s32	splice_fd_in;
 		__u32	file_index;
 	};
-	__u64	addr3;
+	union {
+		__u64	addr3;
+		__u64	cmd;
+	};
 	__u64	__pad2[1];

The way how the tail of the structure is handled here is a mess. I think something like a union of two structs for the small and large case would be much better, so that cmd can be the actual array for the data that can be used directly and without the nasty cast (that also casted away the constness):

fs/io_uring.c +7 -7
index b774e6eac5384..fe24d606ca306 100644
@@ -4544,7 +4544,7 @@ static int io_getxattr_prep(struct io_kiocb *req,
 	if (ret)
 		return ret;
 
-	path = u64_to_user_ptr(READ_ONCE(sqe->addr3));
+	path = u64_to_user_ptr(READ_ONCE(sqe->small.addr3));
 
 	ix->filename = getname_flags(path, LOOKUP_FOLLOW, NULL);
 	if (IS_ERR(ix->filename)) {
@@ -4645,7 +4645,7 @@ static int io_setxattr_prep(struct io_kiocb *req,
 	if (ret)
 		return ret;
 
-	path = u64_to_user_ptr(READ_ONCE(sqe->addr3));
+	path = u64_to_user_ptr(READ_ONCE(sqe->small.addr3));
 
 	ix->filename = getname_flags(path, LOOKUP_FOLLOW, NULL);
 	if (IS_ERR(ix->filename)) {
@@ -4909,15 +4909,15 @@ static int io_linkat(struct io_kiocb *req, unsigned int issue_flags)
 
 static void io_uring_cmd_work(struct io_kiocb *req, bool *locked)
 {
-	req->uring_cmd.driver_cb(&req->uring_cmd);
+	req->uring_cmd.task_work_cb(&req->uring_cmd);
 }
 
 void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
-			void (*driver_cb)(struct io_uring_cmd *))
+			void (*task_work_cb)(struct io_uring_cmd *))
 {
 	struct io_kiocb *req = container_of(ioucmd, struct io_kiocb, uring_cmd);
 
-	req->uring_cmd.driver_cb = driver_cb;
+	req->uring_cmd.task_work_cb = task_work_cb;
 	req->io_task_work.func = io_uring_cmd_work;
 	io_req_task_work_add(req, !!(req->ctx->flags & IORING_SETUP_SQPOLL));
 }
@@ -4949,7 +4949,7 @@ static int io_uring_cmd_prep(struct io_kiocb *req,
 		return -EOPNOTSUPP;
 	if (!(req->ctx->flags & IORING_SETUP_CQE32))
 		return -EOPNOTSUPP;
-	ioucmd->cmd = (void *) &sqe->cmd;
+	ioucmd->cmd = sqe->big.cmd;
 	ioucmd->cmd_op = READ_ONCE(sqe->cmd_op);
 	ioucmd->flags = 0;
 	return 0;
@@ -12735,7 +12735,7 @@ static int __init io_uring_init(void)
 	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(48, __u64,  addr3);
+	BUILD_BUG_SQE_ELEM(48, __u64,  small.addr3);
 
 	BUILD_BUG_ON(sizeof(struct io_uring_files_update) !=
 		     sizeof(struct io_uring_rsrc_update));
include/linux/io_uring.h +8 -9
index a4ff4696cbead..7274884859910 100644
@@ -13,20 +13,19 @@ enum io_uring_cmd_flags {
 };
 
 struct io_uring_cmd {
-	struct file     *file;
-	void            *cmd;
-	/* for irq-completion - if driver requires doing stuff in task-context*/
-	void (*driver_cb)(struct io_uring_cmd *cmd);
-	u32             flags;
-	u32             cmd_op;
-	u32		unused;
+	struct file	*file;
+	const u8	*cmd;
+	/* callback to defer completions to task context */
+	void (*task_work_cb)(struct io_uring_cmd *cmd);
+	u32		flags;
+	u32		cmd_op;
 	u8		pdu[28]; /* available inline for free use */
 };
 
 #if defined(CONFIG_IO_URING)
 void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret, ssize_t res2);
 void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
-			void (*driver_cb)(struct io_uring_cmd *));
+			void (*task_work_cb)(struct io_uring_cmd *));
 struct sock *io_uring_get_socket(struct file *file);
 void __io_uring_cancel(bool cancel_all);
 void __io_uring_free(struct task_struct *tsk);
@@ -56,7 +55,7 @@ static inline void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret,
 {
 }
 static inline void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
-			void (*driver_cb)(struct io_uring_cmd *))
+			void (*task_work_cb)(struct io_uring_cmd *))
 {
 }
 static inline struct sock *io_uring_get_socket(struct file *file)
include/trace/events/io_uring.h +2 -2
index 630982b3c34c5..b1f64c2412935 100644
@@ -539,8 +539,8 @@ TRACE_EVENT(io_uring_req_failed,
 		__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->addr3		= sqe->small.addr3;
+		__entry->pad1		= sqe->small.__pad2[0];
 		__entry->error		= error;
 	),
 
include/uapi/linux/io_uring.h +12 -10
index c081511119bfa..bd4221184f594 100644
@@ -27,7 +27,6 @@ struct io_uring_sqe {
 	union {
 		__u64	addr;	/* pointer to buffer or iovecs */
 		__u64	splice_off_in;
-		__u16	cmd_len;
 	};
 	__u32	len;		/* buffer size or number of iovecs */
 	union {
@@ -64,16 +63,19 @@ struct io_uring_sqe {
 		__u32	file_index;
 	};
 	union {
-		__u64	addr3;
-		__u64	cmd;
+		struct {
+			__u64	addr3;
+			__u64	__pad2[1];
+		} small;
+
+		/*
+		 * If the ring is initialized with IORING_SETUP_SQE128, then
+		 * this field is used for 80 bytes of arbitrary command data.
+		 */
+		struct {
+			__u8	cmd[0];
+		} big;
 	};
-	__u64	__pad2[1];
-
-	/*
-	 * If the ring is initialized with IORING_SETUP_SQE128, then this field
-	 * contains 64-bytes of padding, doubling the size of the SQE.
-	 */
-	__u64	__big_sqe_pad[0];
 };
 
 enum {
#4 lore raw

Re: [PATCH v3 1/5] fs,io_uring: add infrastructure for uring-cmd

Quoted 13 lines · Christoph Hellwig

This mostly looks good, but a few comments an an (untested) patch to fix these complaints below:

Review

Quoted 5 lines
(quoted diff) +5 -0
+struct io_uring_cmd {
+     struct file     *file;
+     void            *cmd;
+     /* for irq-completion - if driver requires doing stuff in task-context*/
+     void (*driver_cb)(struct io_uring_cmd *cmd);

I'd rename this task_Work_cb or similar, as driver is not very meaningful.

Quoted 8 lines

include/linux/io_uring.h enum io_uring_cmd_flags {

Quoted 4 lines
include/linux/io_uring.h +4 -0
+     u32             flags;
+     u32             cmd_op;
+     u32             unused;
+     u8              pdu[28]; /* available inline for free use */

The unused field here is not only unused, but also messed up the alignment so that any pointer in pdu will not be properly aligned on 64-bit platforms and tjus might cause crashes on some platforms.

Indeed, thanks. Since we are going to remove that, we can give that space to pdu for now i.e. pdu[32].This will help in removing "packed" attribute in nvme pdu (which is 32 bytes without packing).

Quoted 161 lines

For now we can just remove it, but I really want to get rid of the pdu thing that causes these problems, but I will not hold the series off for that and plan to look into that later.
Also a lot of the fields here were using spaces instead of tabs for indentation.

Quoted 5 lines
      union {
              __u64   addr;   /* pointer to buffer or iovecs */
              __u64   splice_off_in;
+             __u16   cmd_len;
      };

This field isn't actually used and can be removed.

Review struct io_uring_sqe { · line 70

Quoted 12 lines

__u32 len; /* buffer size or number of iovecs */
union {

(quoted diff) +4 -1
@@ -61,7 +63,10 @@ struct io_uring_sqe {
              __s32   splice_fd_in;
              __u32   file_index;
      };
-     __u64   addr3;
+     union {
+             __u64   addr3;
+             __u64   cmd;
+     };
      __u64   __pad2[1];

The way how the tail of the structure is handled here is a mess. I think something like a union of two structs for the small and large case would be much better, so that cmd can be the actual array for the data that can be used directly and without the nasty cast (that also casted away the constness):

fs/io_uring.c +7 -7
index b774e6eac5384..fe24d606ca306 100644
@@ -4544,7 +4544,7 @@ static int io_getxattr_prep(struct io_kiocb *req,
        if (ret)
                return ret;
 
-       path = u64_to_user_ptr(READ_ONCE(sqe->addr3));
+       path = u64_to_user_ptr(READ_ONCE(sqe->small.addr3));
 
        ix->filename = getname_flags(path, LOOKUP_FOLLOW, NULL);
        if (IS_ERR(ix->filename)) {
@@ -4645,7 +4645,7 @@ static int io_setxattr_prep(struct io_kiocb *req,
        if (ret)
                return ret;
 
-       path = u64_to_user_ptr(READ_ONCE(sqe->addr3));
+       path = u64_to_user_ptr(READ_ONCE(sqe->small.addr3));
 
        ix->filename = getname_flags(path, LOOKUP_FOLLOW, NULL);
        if (IS_ERR(ix->filename)) {
@@ -4909,15 +4909,15 @@ static int io_linkat(struct io_kiocb *req, unsigned int issue_flags)
 
 static void io_uring_cmd_work(struct io_kiocb *req, bool *locked)
 {
-       req->uring_cmd.driver_cb(&req->uring_cmd);
+       req->uring_cmd.task_work_cb(&req->uring_cmd);
 }
 
 void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
-                       void (*driver_cb)(struct io_uring_cmd *))
+                       void (*task_work_cb)(struct io_uring_cmd *))
 {
        struct io_kiocb *req = container_of(ioucmd, struct io_kiocb, uring_cmd);
 
-       req->uring_cmd.driver_cb = driver_cb;
+       req->uring_cmd.task_work_cb = task_work_cb;
        req->io_task_work.func = io_uring_cmd_work;
        io_req_task_work_add(req, !!(req->ctx->flags & IORING_SETUP_SQPOLL));
 }
@@ -4949,7 +4949,7 @@ static int io_uring_cmd_prep(struct io_kiocb *req,
                return -EOPNOTSUPP;
        if (!(req->ctx->flags & IORING_SETUP_CQE32))
                return -EOPNOTSUPP;
-       ioucmd->cmd = (void *) &sqe->cmd;
+       ioucmd->cmd = sqe->big.cmd;
        ioucmd->cmd_op = READ_ONCE(sqe->cmd_op);
        ioucmd->flags = 0;
        return 0;
@@ -12735,7 +12735,7 @@ static int __init io_uring_init(void)
        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(48, __u64,  addr3);
+       BUILD_BUG_SQE_ELEM(48, __u64,  small.addr3);
 
        BUILD_BUG_ON(sizeof(struct io_uring_files_update) !=
                     sizeof(struct io_uring_rsrc_update));
include/linux/io_uring.h +8 -9
index a4ff4696cbead..7274884859910 100644
@@ -13,20 +13,19 @@ enum io_uring_cmd_flags {
 };
 
 struct io_uring_cmd {
-       struct file     *file;
-       void            *cmd;
-       /* for irq-completion - if driver requires doing stuff in task-context*/
-       void (*driver_cb)(struct io_uring_cmd *cmd);
-       u32             flags;
-       u32             cmd_op;
-       u32             unused;
+       struct file     *file;
+       const u8        *cmd;
+       /* callback to defer completions to task context */
+       void (*task_work_cb)(struct io_uring_cmd *cmd);
+       u32             flags;
+       u32             cmd_op;
        u8              pdu[28]; /* available inline for free use */
 };
 
 #if defined(CONFIG_IO_URING)
 void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret, ssize_t res2);
 void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
-                       void (*driver_cb)(struct io_uring_cmd *));
+                       void (*task_work_cb)(struct io_uring_cmd *));
 struct sock *io_uring_get_socket(struct file *file);
 void __io_uring_cancel(bool cancel_all);
 void __io_uring_free(struct task_struct *tsk);
@@ -56,7 +55,7 @@ static inline void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret,
 {
 }
 static inline void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
-                       void (*driver_cb)(struct io_uring_cmd *))
+                       void (*task_work_cb)(struct io_uring_cmd *))
 {
 }
 static inline struct sock *io_uring_get_socket(struct file *file)
include/trace/events/io_uring.h +2 -2
index 630982b3c34c5..b1f64c2412935 100644
@@ -539,8 +539,8 @@ TRACE_EVENT(io_uring_req_failed,
                __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->addr3          = sqe->small.addr3;
+               __entry->pad1           = sqe->small.__pad2[0];
                __entry->error          = error;
        ),
 
include/uapi/linux/io_uring.h +0 -1
index c081511119bfa..bd4221184f594 100644
@@ -27,7 +27,6 @@ struct io_uring_sqe {
        union {
                __u64   addr;   /* pointer to buffer or iovecs */
                __u64   splice_off_in;
-               __u16   cmd_len;
        };
        __u32   len;            /* buffer size or number of iovecs */
        union {

include/uapi/linux/io_uring.h struct io_uring_sqe { · line 69

Quoted 9 lines
include/uapi/linux/io_uring.h +4 -2
@@ -64,16 +63,19 @@ struct io_uring_sqe {
                __u32   file_index;
        };
        union {
-               __u64   addr3;
-               __u64   cmd;
+               struct {
+                       __u64   addr3;
+                       __u64   __pad2[1];
+               } small;

Thinking if this can cause any issue for existing users of addr3, i.e. in the userspace side? Since it needs to access this field with small.addr3.
Jens - is xattr infra already frozen?

Quoted 18 lines
include/uapi/linux/io_uring.h +7 -7
+               /*
+                * If the ring is initialized with IORING_SETUP_SQE128, then
+                * this field is used for 80 bytes of arbitrary command data.
+                */
+               struct {
+                       __u8    cmd[0];
+               } big;
        };
-       __u64   __pad2[1];
-
-       /*
-        * If the ring is initialized with IORING_SETUP_SQE128, then this field
-        * contains 64-bytes of padding, doubling the size of the SQE.
-        */
-       __u64   __big_sqe_pad[0];
 };
 
 enum {
Signature · 1 line
Joshi
#5 lore raw

Re: [PATCH v3 1/5] fs,io_uring: add infrastructure for uring-cmd

Quoted 15 lines
Quoted 15 lines
include/uapi/linux/io_uring.h +1 -3
@@ -27,7 +27,6 @@ struct io_uring_sqe {
        union {
                __u64   addr;   /* pointer to buffer or iovecs */
                __u64   splice_off_in;
-               __u16   cmd_len;
        };
        __u32   len;            /* buffer size or number of iovecs */
        union {
@@ -64,16 +63,19 @@ struct io_uring_sqe {
                __u32   file_index;
        };
        union {
-               __u64   addr3;
-               __u64   cmd;
+               struct {
Quoted 8 lines

include/uapi/linux/io_uring.h struct io_uring_sqe { · line 69

Quoted 3 lines
include/uapi/linux/io_uring.h +3 -0
+                       __u64   addr3;
+                       __u64   __pad2[1];
+               } small;

Thinking if this can cause any issue for existing users of addr3, i.e. in the userspace side? Since it needs to access this field with small.addr3.
Jens - is xattr infra already frozen?

If this breaks anything, we can avoid that by not touching addr3 at all.
And instead keep "__u64 __pad2[1]" and "__u8 cmd[0]" in the union.
That means 72 bytes of space, but it is enough for the new nvme struct (nvme_uring_cmd) which is also 72 bytes.
Does this sound fine?

maintainer
#6 lore raw

Re: [PATCH v3 1/5] fs,io_uring: add infrastructure for uring-cmd

In reply to Kanchan Joshi
Quoted 7 lines · Kanchan Joshi
Quoted 7 lines
include/uapi/linux/io_uring.h +1 -2
@@ -64,16 +63,19 @@ struct io_uring_sqe {
                __u32   file_index;
        };
        union {
-               __u64   addr3;
-               __u64   cmd;
+               struct {
Quoted 8 lines

include/uapi/linux/io_uring.h struct io_uring_sqe { · line 69

Quoted 3 lines
include/uapi/linux/io_uring.h +3 -0
+                       __u64   addr3;
+                       __u64   __pad2[1];
+               } small;

Thinking if this can cause any issue for existing users of addr3, i.e. in the userspace side? Since it needs to access this field with small.addr3.
Jens - is xattr infra already frozen?

It's not, as it's not upstream yet. But I don't think we need to change it, just make the two structs unnamed instead. That also avoids awkward small/big prefixes.

Signature · 1 line
Jens Axboe
maintainer
#7 lore raw

Re: [PATCH v3 1/5] fs,io_uring: add infrastructure for uring-cmd

In reply to Pankaj Raghav
Quoted 9 lines · Pankaj Raghav

From: Jens Axboe <[email protected]>

file_operations->uring_cmd is a file private handler, similar to ioctls but hopefully a lot more sane and useful.

IORING_OP_URING_CMD is a file private kind of request. io_uring doesn't know what is in this command type, it's for the provider of ->uring_cmd() to deal with. This operation can be issued only on the ring that is setup with both IORING_SETUP_SQE128 and IORING_SETUP_CQE32 flags.

A few minor comments below.

Quoted 11 lines
fs/io_uring.c +7 -0
index c7e3f7e74d92..b774e6eac538 100644
+static int io_uring_cmd_prep(struct io_kiocb *req,
+			     const struct io_uring_sqe *sqe)
+{
+	struct io_uring_cmd *ioucmd = &req->uring_cmd;
+
+	if (req->ctx->flags & IORING_SETUP_IOPOLL)
+		return -EOPNOTSUPP;

fs/io_uring.c static int io_linkat(struct io_kiocb *req, unsigned int issue_flags) · line 4956

Quoted 10 lines
fs/io_uring.c +10 -0
+	/* do not support uring-cmd without big SQE/CQE */
+	if (!(req->ctx->flags & IORING_SETUP_SQE128))
+		return -EOPNOTSUPP;
+	if (!(req->ctx->flags & IORING_SETUP_CQE32))
+		return -EOPNOTSUPP;
+	ioucmd->cmd = (void *) &sqe->cmd;
+	ioucmd->cmd_op = READ_ONCE(sqe->cmd_op);
+	ioucmd->flags = 0;
+	return 0;
+}

I'd define

	struct io_ring_ctx *ctx = req->ctx;

here. And you should read 'rw_flags' and return -EINVAL if it's set, so we can be backwards compatible if flags are added later. Probably read eg sqe->ioprio as well as that isn't directly applicable (it'd just be set in the command directly) and -EINVAL if that is set. Ala:

static int io_uring_cmd_prep(struct io_kiocb *req,
const struct io_uring_sqe *sqe)

{
	struct io_uring_cmd *ioucmd = &req->uring_cmd;
	struct io_ring_ctx *ctx = req->ctx;

	if (ctx->flags & IORING_SETUP_IOPOLL)
		return -EOPNOTSUPP;
	/* do not support uring-cmd without big SQE/CQE */
	if (!(ctx->flags & IORING_SETUP_SQE128))
		return -EOPNOTSUPP;
	if (!(ctx->flags & IORING_SETUP_CQE32))
		return -EOPNOTSUPP;
	if (sqe->ioprio || sqe->rw_flags
		return -EINVAL;

	ioucmd->cmd = (void *) &sqe->cmd;
	ioucmd->cmd_op = READ_ONCE(sqe->cmd_op);
	ioucmd->flags = 0;
	return 0;
}

fs/io_uring.c static int io_linkat(struct io_kiocb *req, unsigned int issue_flags) · line 4968

Quoted 11 lines
fs/io_uring.c +11 -0
+static int io_uring_cmd(struct io_kiocb *req, unsigned int issue_flags)
+{
+	struct file *file = req->file;
+	struct io_uring_cmd *ioucmd = &req->uring_cmd;
+
+	if (!req->file->f_op->uring_cmd)
+		return -EOPNOTSUPP;
+	ioucmd->flags |= issue_flags;
+	file->f_op->uring_cmd(ioucmd);
+	return 0;
+}

We should pass in issue_flags here, it's a property of the call path, not the command itself:

static int io_uring_cmd(struct io_kiocb *req, unsigned int issue_flags)

{
	struct file *file = req->file;
	struct io_uring_cmd *ioucmd = &req->uring_cmd;

	if (!req->file->f_op->uring_cmd)
		return -EOPNOTSUPP;
	file->f_op->uring_cmd(ioucmd, issue_flags);
	return 0;
}

and then get rid of ioucmd->flags, that can get re-added as the copy of sqe->rw_flags when we need that.

Agree with Christoph on the things he brought up. If possible, please just respin this patch with the suggested changes and we can queue it up.

Signature · 1 line
Jens Axboe
#8 lore raw

PATCH v3 2/5 block: wire-up support for passthrough plugging

In reply to Pankaj Raghav

From: Jens Axboe <[email protected]>

Add support for plugging in passthrough path. When plugging is enabled, the requests are added to a plug instead of getting dispatched to the driver. And when the plug is finished, the whole batch gets dispatched via ->queue_rqs which turns out to be more efficient. Otherwise dispatching used to happen via ->queue_rq, one request at a time.

---
 block/blk-mq.c | 90 ++++++++++++++++++++++++++------------------------
 1 file changed, 47 insertions(+), 43 deletions(-)
block/blk-mq.c +47 -43
index 84d749511f55..e432e7e8fe20 100644
@@ -2340,6 +2340,40 @@ void __blk_mq_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
 	blk_mq_hctx_mark_pending(hctx, ctx);
 }
 
+/*
+ * Allow 2x BLK_MAX_REQUEST_COUNT requests on plug queue for multiple
+ * queues. This is important for md arrays to benefit from merging
+ * requests.
+ */
+static inline unsigned short blk_plug_max_rq_count(struct blk_plug *plug)
+{
+	if (plug->multiple_queues)
+		return BLK_MAX_REQUEST_COUNT * 2;
+	return BLK_MAX_REQUEST_COUNT;
+}
+
+static void blk_add_rq_to_plug(struct blk_plug *plug, struct request *rq)
+{
+	struct request *last = rq_list_peek(&plug->mq_list);
+
+	if (!plug->rq_count) {
+		trace_block_plug(rq->q);
+	} else if (plug->rq_count >= blk_plug_max_rq_count(plug) ||
+		   (!blk_queue_nomerges(rq->q) &&
+		    blk_rq_bytes(last) >= BLK_PLUG_FLUSH_SIZE)) {
+		blk_mq_flush_plug_list(plug, false);
+		trace_block_plug(rq->q);
+	}
+
+	if (!plug->multiple_queues && last && last->q != rq->q)
+		plug->multiple_queues = true;
+	if (!plug->has_elevator && (rq->rq_flags & RQF_ELV))
+		plug->has_elevator = true;
+	rq->rq_next = NULL;
+	rq_list_add(&plug->mq_list, rq);
+	plug->rq_count++;
+}
+
 /**
  * blk_mq_request_bypass_insert - Insert a request at dispatch list.
  * @rq: Pointer to request to be inserted.
@@ -2353,16 +2387,20 @@ void blk_mq_request_bypass_insert(struct request *rq, bool at_head,
 				  bool run_queue)
 {
 	struct blk_mq_hw_ctx *hctx = rq->mq_hctx;
+	struct blk_plug *plug = current->plug;
 
-	spin_lock(&hctx->lock);
-	if (at_head)
-		list_add(&rq->queuelist, &hctx->dispatch);
-	else
-		list_add_tail(&rq->queuelist, &hctx->dispatch);
-	spin_unlock(&hctx->lock);
-
-	if (run_queue)
-		blk_mq_run_hw_queue(hctx, false);
+	if (plug) {
+		blk_add_rq_to_plug(plug, rq);
+	} else {
+		spin_lock(&hctx->lock);
+		if (at_head)
+			list_add(&rq->queuelist, &hctx->dispatch);
+		else
+			list_add_tail(&rq->queuelist, &hctx->dispatch);
+		spin_unlock(&hctx->lock);
+		if (run_queue)
+			blk_mq_run_hw_queue(hctx, false);
+	}
 }
 
 void blk_mq_insert_requests(struct blk_mq_hw_ctx *hctx, struct blk_mq_ctx *ctx,
@@ -2676,40 +2714,6 @@ void blk_mq_try_issue_list_directly(struct blk_mq_hw_ctx *hctx,
 		hctx->queue->mq_ops->commit_rqs(hctx);
 }
 
-/*
- * Allow 2x BLK_MAX_REQUEST_COUNT requests on plug queue for multiple
- * queues. This is important for md arrays to benefit from merging
- * requests.
- */
-static inline unsigned short blk_plug_max_rq_count(struct blk_plug *plug)
-{
-	if (plug->multiple_queues)
-		return BLK_MAX_REQUEST_COUNT * 2;
-	return BLK_MAX_REQUEST_COUNT;
-}
-
-static void blk_add_rq_to_plug(struct blk_plug *plug, struct request *rq)
-{
-	struct request *last = rq_list_peek(&plug->mq_list);
-
-	if (!plug->rq_count) {
-		trace_block_plug(rq->q);
-	} else if (plug->rq_count >= blk_plug_max_rq_count(plug) ||
-		   (!blk_queue_nomerges(rq->q) &&
-		    blk_rq_bytes(last) >= BLK_PLUG_FLUSH_SIZE)) {
-		blk_mq_flush_plug_list(plug, false);
-		trace_block_plug(rq->q);
-	}
-
-	if (!plug->multiple_queues && last && last->q != rq->q)
-		plug->multiple_queues = true;
-	if (!plug->has_elevator && (rq->rq_flags & RQF_ELV))
-		plug->has_elevator = true;
-	rq->rq_next = NULL;
-	rq_list_add(&plug->mq_list, rq);
-	plug->rq_count++;
-}
-
 static bool blk_mq_attempt_bio_merge(struct request_queue *q,
 				     struct bio *bio, unsigned int nr_segs)
 {
Signature · 1 line
2.25.1
maintainer Reviewed-by on v3 2/5
#9 lore raw

Re: [PATCH v3 2/5] block: wire-up support for passthrough plugging

block/blk-mq.c void blk_mq_request_bypass_insert(struct request *rq, bool at_head, · line 2394

Quoted 3 lines
block/blk-mq.c +3 -0
+	if (plug) {
+		blk_add_rq_to_plug(plug, rq);
+	} else {

I'd just do an eary return after the blk_add_rq_to_plug call and leave the rest of the code untouched and unindented.

Otherwise this looks good:

#10 lore raw

PATCH v3 3/5 nvme: refactor nvme_submit_user_cmd()

In reply to Pankaj Raghav

From: Christoph Hellwig <[email protected]>

Divide the work into two helpers, namely nvme_alloc_user_request and nvme_execute_user_rq. This is a prep patch, that will help wiring up uring-cmd support in nvme.

---
 drivers/nvme/host/ioctl.c | 47 ++++++++++++++++++++++++++++++++++-----
 1 file changed, 42 insertions(+), 5 deletions(-)
drivers/nvme/host/ioctl.c +42 -5
index 554566371ffa..3531de8073a6 100644
@@ -19,6 +19,13 @@ static void __user *nvme_to_user_ptr(uintptr_t ptrval)
 	return (void __user *)ptrval;
 }
 
+static inline void *nvme_meta_from_bio(struct bio *bio)
+{
+	struct bio_integrity_payload *bip = bio_integrity(bio);
+
+	return bip ? bvec_virt(bip->bip_vec) : NULL;
+}
+
 static void *nvme_add_user_metadata(struct bio *bio, void __user *ubuf,
 		unsigned len, u32 seed, bool write)
 {
@@ -53,10 +60,10 @@ static void *nvme_add_user_metadata(struct bio *bio, void __user *ubuf,
 	return ERR_PTR(ret);
 }
 
-static int nvme_submit_user_cmd(struct request_queue *q,
+static struct request *nvme_alloc_user_request(struct request_queue *q,
 		struct nvme_command *cmd, void __user *ubuffer,
 		unsigned bufflen, void __user *meta_buffer, unsigned meta_len,
-		u32 meta_seed, u64 *result, unsigned timeout, bool vec)
+		u32 meta_seed, unsigned timeout, bool vec)
 {
 	bool write = nvme_is_write(cmd);
 	struct nvme_ns *ns = q->queuedata;
@@ -68,7 +75,7 @@ static int nvme_submit_user_cmd(struct request_queue *q,
 
 	req = blk_mq_alloc_request(q, nvme_req_op(cmd), 0);
 	if (IS_ERR(req))
-		return PTR_ERR(req);
+		return req;
 	nvme_init_request(req, cmd);
 
 	if (timeout)
@@ -108,7 +115,26 @@ static int nvme_submit_user_cmd(struct request_queue *q,
 		}
 	}
 
+	return req;
+
+out_unmap:
+	if (bio)
+		blk_rq_unmap_user(bio);
+out:
+	blk_mq_free_request(req);
+	return ERR_PTR(ret);
+}
+
+static int nvme_execute_user_rq(struct request *req, void __user *meta_buffer,
+		unsigned meta_len, u64 *result)
+{
+	struct bio *bio = req->bio;
+	bool write = bio_op(bio) == REQ_OP_DRV_OUT;
+	int ret;
+	void *meta = nvme_meta_from_bio(bio);
+
 	ret = nvme_execute_passthru_rq(req);
+
 	if (result)
 		*result = le64_to_cpu(nvme_req(req)->result.u64);
 	if (meta && !ret && !write) {
@@ -116,14 +142,25 @@ static int nvme_submit_user_cmd(struct request_queue *q,
 			ret = -EFAULT;
 	}
 	kfree(meta);
- out_unmap:
 	if (bio)
 		blk_rq_unmap_user(bio);
- out:
 	blk_mq_free_request(req);
 	return ret;
 }
 
+static int nvme_submit_user_cmd(struct request_queue *q,
+		struct nvme_command *cmd, void __user *ubuffer,
+		unsigned bufflen, void __user *meta_buffer, unsigned meta_len,
+		u32 meta_seed, u64 *result, unsigned timeout, bool vec)
+{
+	struct request *req;
+
+	req = nvme_alloc_user_request(q, cmd, ubuffer, bufflen, meta_buffer,
+			meta_len, meta_seed, timeout, vec);
+	if (IS_ERR(req))
+		return PTR_ERR(req);
+	return nvme_execute_user_rq(req, meta_buffer, meta_len, result);
+}
 
 static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio)
 {
Signature · 1 line
2.25.1
#11 lore raw

PATCH v3 4/5 nvme: wire-up uring-cmd support for io-passthru on char-device.

In reply to Pankaj Raghav

From: Kanchan Joshi <[email protected]>

Introduce handler for fops->uring_cmd(), implementing async passthru on char device (/dev/ngX). The handler supports newly introduced operation NVME_URING_CMD_IO. This operates on a new structure nvme_uring_cmd, which is similiar to struct nvme_passthru_cmd64 but without the embedded 8b result field. This is not needed since uring-cmd allows to return additional result to user-space via big-CQE.

---
 drivers/nvme/host/core.c        |   1 +
 drivers/nvme/host/ioctl.c       | 166 +++++++++++++++++++++++++++++++-
 drivers/nvme/host/multipath.c   |   1 +
 drivers/nvme/host/nvme.h        |   3 +
 include/uapi/linux/nvme_ioctl.h |  25 +++++
 5 files changed, 193 insertions(+), 3 deletions(-)
drivers/nvme/host/core.c +1 -0
index e1846d04817f..682df98db341 100644
@@ -3699,6 +3699,7 @@ static const struct file_operations nvme_ns_chr_fops = {
 	.release	= nvme_ns_chr_release,
 	.unlocked_ioctl	= nvme_ns_chr_ioctl,
 	.compat_ioctl	= compat_ptr_ioctl,
+	.uring_cmd	= nvme_ns_chr_uring_cmd,
 };
 
 static int nvme_add_ns_cdev(struct nvme_ns *ns)
drivers/nvme/host/ioctl.c +163 -3

208 lines not on this page · raw message

drivers/nvme/host/multipath.c +1 -0
index d464fdf978fb..d3e2440d8abb 100644
@@ -437,6 +437,7 @@ static const struct file_operations nvme_ns_head_chr_fops = {
 	.release	= nvme_ns_head_chr_release,
 	.unlocked_ioctl	= nvme_ns_head_chr_ioctl,
 	.compat_ioctl	= compat_ptr_ioctl,
+	.uring_cmd	= nvme_ns_head_chr_uring_cmd,
 };
 
 static int nvme_add_ns_head_cdev(struct nvme_ns_head *head)
drivers/nvme/host/nvme.h +3 -0
index a2b53ca63335..57c9adb97ce9 100644
@@ -16,6 +16,7 @@
 #include <linux/rcupdate.h>
 #include <linux/wait.h>
 #include <linux/t10-pi.h>
+#include <linux/io_uring.h>
 
 #include <trace/events/block.h>
 
@@ -782,6 +783,8 @@ long nvme_ns_head_chr_ioctl(struct file *file, unsigned int cmd,
 		unsigned long arg);
 long nvme_dev_ioctl(struct file *file, unsigned int cmd,
 		unsigned long arg);
+void nvme_ns_chr_uring_cmd(struct io_uring_cmd *ioucmd);
+void nvme_ns_head_chr_uring_cmd(struct io_uring_cmd *ioucmd);
 int nvme_getgeo(struct block_device *bdev, struct hd_geometry *geo);
 
 extern const struct attribute_group *nvme_ns_id_attr_groups[];
include/uapi/linux/nvme_ioctl.h +25 -0
index b2e43185e3b5..04e458c649ab 100644
@@ -70,6 +70,28 @@ struct nvme_passthru_cmd64 {
 	__u64	result;
 };
 
+/* same as struct nvme_passthru_cmd64, minus the 8b result field */
+struct nvme_uring_cmd {
+	__u8	opcode;
+	__u8	flags;
+	__u16	rsvd1;
+	__u32	nsid;
+	__u32	cdw2;
+	__u32	cdw3;
+	__u64	metadata;
+	__u64	addr;
+	__u32	metadata_len;
+	__u32	data_len;
+	__u32	cdw10;
+	__u32	cdw11;
+	__u32	cdw12;
+	__u32	cdw13;
+	__u32	cdw14;
+	__u32	cdw15;
+	__u32	timeout_ms;
+	__u32   rsvd2;
+};
+
 #define nvme_admin_cmd nvme_passthru_cmd
 
 #define NVME_IOCTL_ID		_IO('N', 0x40)
@@ -83,4 +105,7 @@ struct nvme_passthru_cmd64 {
 #define NVME_IOCTL_IO64_CMD	_IOWR('N', 0x48, struct nvme_passthru_cmd64)
 #define NVME_IOCTL_IO64_CMD_VEC	_IOWR('N', 0x49, struct nvme_passthru_cmd64)
 
+/* io_uring async commands: */
+#define NVME_URING_CMD_IO	_IOWR('N', 0x80, struct nvme_uring_cmd)
+
 #endif /* _UAPI_LINUX_NVME_IOCTL_H */
Signature · 1 line
2.25.1
maintainer Reviewed-by on v3 4/5
#12 lore raw

Re: [PATCH v3 4/5] nvme: wire-up uring-cmd support for io-passthru on char-device.

Quoted 4 lines · Pankaj Raghav

operation NVME_URING_CMD_IO. This operates on a new structure nvme_uring_cmd, which is similiar to struct nvme_passthru_cmd64 but without the embedded 8b result field. This is not needed since uring-cmd allows to return additional result to user-space via big-CQE.

So let's have a discussion for everyone on whether to reuse the existing struct or not.

Pros for reusing:

- any application that is passing around a nvme_passthru_cmd64 doesn't need to do special marshalling

Cons:

- these fields are pointless

I'm fine going either way, we just need to think about the implications.

Otherwise this looks good:

#13 lore raw

PATCH v3 5/5 nvme: add vectored-io support for uring-cmd

In reply to Pankaj Raghav

From: Anuj Gupta <[email protected]>

wire up support for async passthru that takes an array of buffers (using iovec). Exposed via a new op NVME_URING_CMD_IO_VEC. Same 'struct nvme_uring_cmd' is to be used with -

1. cmd.addr as base address of user iovec array
2. cmd.vec_cnt as count of iovec array elements

---
 drivers/nvme/host/ioctl.c       | 9 ++++++---
 include/uapi/linux/nvme_ioctl.h | 6 +++++-
 2 files changed, 11 insertions(+), 4 deletions(-)
drivers/nvme/host/ioctl.c +6 -3
index e428d692375a..ffc695aa5ba3 100644
@@ -409,7 +409,7 @@ static int nvme_user_cmd64(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
 }
 
 static int nvme_uring_cmd_io(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
-		struct io_uring_cmd *ioucmd)
+		struct io_uring_cmd *ioucmd, bool vec)
 {
 	struct nvme_uring_cmd *cmd =
 		(struct nvme_uring_cmd *)ioucmd->cmd;
@@ -446,7 +446,7 @@ static int nvme_uring_cmd_io(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
 	req = nvme_alloc_user_request(q, &c, nvme_to_user_ptr(cmd->addr),
 			cmd->data_len, nvme_to_user_ptr(cmd->metadata),
 			cmd->metadata_len, 0, cmd->timeout_ms ?
-			msecs_to_jiffies(cmd->timeout_ms) : 0, 0, rq_flags,
+			msecs_to_jiffies(cmd->timeout_ms) : 0, vec, rq_flags,
 			blk_flags);
 	if (IS_ERR(req))
 		return PTR_ERR(req);
@@ -556,7 +556,10 @@ static void nvme_ns_uring_cmd(struct nvme_ns *ns, struct io_uring_cmd *ioucmd)
 
 	switch (ioucmd->cmd_op) {
 	case NVME_URING_CMD_IO:
-		ret = nvme_uring_cmd_io(ns->ctrl, ns, ioucmd);
+		ret = nvme_uring_cmd_io(ns->ctrl, ns, ioucmd, false);
+		break;
+	case NVME_URING_CMD_IO_VEC:
+		ret = nvme_uring_cmd_io(ns->ctrl, ns, ioucmd, true);
 		break;
 	default:
 		ret = -ENOTTY;
include/uapi/linux/nvme_ioctl.h +5 -1
index 04e458c649ab..938e0a0bf46f 100644
@@ -81,7 +81,10 @@ struct nvme_uring_cmd {
 	__u64	metadata;
 	__u64	addr;
 	__u32	metadata_len;
-	__u32	data_len;
+	union {
+		__u32	data_len; /* for non-vectored io */
+		__u32	vec_cnt; /* for vectored io */
+	};
 	__u32	cdw10;
 	__u32	cdw11;
 	__u32	cdw12;
@@ -107,5 +110,6 @@ struct nvme_uring_cmd {
 
 /* io_uring async commands: */
 #define NVME_URING_CMD_IO	_IOWR('N', 0x80, struct nvme_uring_cmd)
+#define NVME_URING_CMD_IO_VEC	_IOWR('N', 0x81, struct nvme_uring_cmd)
 
 #endif /* _UAPI_LINUX_NVME_IOCTL_H */
Signature · 1 line
2.25.1
maintainer Reviewed-by on v3 5/5
#14 lore raw

Re: [PATCH v3 5/5] nvme: add vectored-io support for uring-cmd

include/uapi/linux/nvme_ioctl.h struct nvme_uring_cmd { · line 87

Quoted 4 lines
include/uapi/linux/nvme_ioctl.h +4 -0
+	union {
+		__u32	data_len; /* for non-vectored io */
+		__u32	vec_cnt; /* for vectored io */
+	};

Nothing ever uses vec_cnt, so I don't think there is any point in adding this union.

The rest looks good to me: