Skip to contentSkip to conversation

uring-passthrough for admin commands

PATCH Superseded Kanchan Joshi 2 participants 6 messages May 20, 2022 1 message not in the archive NVMe

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

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

#1 lore raw

v2 cover uring-passthrough for admin commands

The series enables uring-passthrough for admin-commands.

Patch 1 is prep.
Patch 2 adds new opcode for admin uring-passthrough, and enables it on nvme controller dev(/dev/nvmeX). It reuses the code of io-command passthrough, with the only difference that commands are issued on admin queue.

Changes since v1:
- drop the code that supports this op over ns char device
- apply reviewed-by tag

Kanchan Joshi (2):
nvme: helper for uring-passthrough checks
nvme: enable uring-passthrough for admin commands

 drivers/nvme/host/core.c        |  1 +
 drivers/nvme/host/ioctl.c       | 44 +++++++++++++++++++++++++++------
 drivers/nvme/host/nvme.h        |  1 +
 include/uapi/linux/nvme_ioctl.h |  1 +
 4 files changed, 39 insertions(+), 8 deletions(-)
Signature · 1 line
2.25.1
#2 lore raw

PATCH v2 1/2 nvme: helper for uring-passthrough checks

Factor out a helper consolidating the error checks, and fix typo in a comment too. This is in preparation to support admin commands on this path.

---
 drivers/nvme/host/ioctl.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
drivers/nvme/host/ioctl.c +16 -8
index 7b0e2c9cdcae..114b490592b0 100644
@@ -556,22 +556,30 @@ long nvme_ns_chr_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 	return __nvme_ioctl(ns, cmd, (void __user *)arg);
 }
 
-static int nvme_ns_uring_cmd(struct nvme_ns *ns, struct io_uring_cmd *ioucmd,
-			     unsigned int issue_flags)
+static int nvme_uring_cmd_checks(unsigned int issue_flags)
 {
-	struct nvme_ctrl *ctrl = ns->ctrl;
-	int ret;
-
-	BUILD_BUG_ON(sizeof(struct nvme_uring_cmd_pdu) > sizeof(ioucmd->pdu));
-
 	/* IOPOLL not supported yet */
 	if (issue_flags & IO_URING_F_IOPOLL)
 		return -EOPNOTSUPP;
 
-	/* NVMe passthrough requires bit SQE/CQE support */
+	/* NVMe passthrough requires big SQE/CQE support */
 	if ((issue_flags & (IO_URING_F_SQE128|IO_URING_F_CQE32)) !=
 	    (IO_URING_F_SQE128|IO_URING_F_CQE32))
 		return -EOPNOTSUPP;
+	return 0;
+}
+
+static int nvme_ns_uring_cmd(struct nvme_ns *ns, struct io_uring_cmd *ioucmd,
+			     unsigned int issue_flags)
+{
+	struct nvme_ctrl *ctrl = ns->ctrl;
+	int ret;
+
+	BUILD_BUG_ON(sizeof(struct nvme_uring_cmd_pdu) > sizeof(ioucmd->pdu));
+
+	ret = nvme_uring_cmd_checks(issue_flags);
+	if (ret)
+		return ret;
 
 	switch (ioucmd->cmd_op) {
 	case NVME_URING_CMD_IO:
Signature · 1 line
2.25.1
#3 lore raw

PATCH v2 2/2 nvme: enable uring-passthrough for admin commands

In reply to Kanchan Joshi

Add a new opcode NVME_URING_CMD_ADMIN that userspace can use. Wire up support for the case when this is issued on controller node (/dev/nvmeX).

---
 drivers/nvme/host/core.c        |  1 +
 drivers/nvme/host/ioctl.c       | 20 ++++++++++++++++++++
 drivers/nvme/host/nvme.h        |  1 +
 include/uapi/linux/nvme_ioctl.h |  1 +
 4 files changed, 23 insertions(+)
drivers/nvme/host/core.c +1 -0
index b7095ef6586b..895f70d8f56c 100644
@@ -3148,6 +3148,7 @@ static const struct file_operations nvme_dev_fops = {
 	.release	= nvme_dev_release,
 	.unlocked_ioctl	= nvme_dev_ioctl,
 	.compat_ioctl	= compat_ptr_ioctl,
+	.uring_cmd	= nvme_dev_uring_cmd,
 };
 
 static ssize_t nvme_sysfs_reset(struct device *dev,
drivers/nvme/host/ioctl.c +20 -0
index 114b490592b0..7902fd5c69e1 100644
@@ -686,6 +686,26 @@ int nvme_ns_head_chr_uring_cmd(struct io_uring_cmd *ioucmd,
 }
 #endif /* CONFIG_NVME_MULTIPATH */
 
+int nvme_dev_uring_cmd(struct io_uring_cmd *ioucmd, unsigned int issue_flags)
+{
+	struct nvme_ctrl *ctrl = ioucmd->file->private_data;
+	int ret;
+
+	ret = nvme_uring_cmd_checks(issue_flags);
+	if (ret)
+		return ret;
+
+	switch (ioucmd->cmd_op) {
+	case NVME_URING_CMD_ADMIN:
+		ret = nvme_uring_cmd_io(ctrl, NULL, ioucmd, issue_flags, false);
+		break;
+	default:
+		ret = -ENOTTY;
+	}
+
+	return ret;
+}
+
 static int nvme_dev_user_cmd(struct nvme_ctrl *ctrl, void __user *argp)
 {
 	struct nvme_ns *ns;
drivers/nvme/host/nvme.h +1 -0
index d60024032012..9b72b6ecf33c 100644
@@ -788,6 +788,7 @@ int nvme_ns_chr_uring_cmd(struct io_uring_cmd *ioucmd,
 int nvme_ns_head_chr_uring_cmd(struct io_uring_cmd *ioucmd,
 		unsigned int issue_flags);
 int nvme_getgeo(struct block_device *bdev, struct hd_geometry *geo);
+int nvme_dev_uring_cmd(struct io_uring_cmd *ioucmd, unsigned int issue_flags);
 
 extern const struct attribute_group *nvme_ns_id_attr_groups[];
 extern const struct pr_ops nvme_pr_ops;
include/uapi/linux/nvme_ioctl.h +1 -0
index 0b1876aa5a59..6bcda1be6456 100644
@@ -108,5 +108,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)
+#define NVME_URING_CMD_ADMIN	_IOWR('N', 0x82, struct nvme_uring_cmd)
 
 #endif /* _UAPI_LINUX_NVME_IOCTL_H */
Signature · 1 line
2.25.1
maintainer Reviewed-by on the v2 series
#4 lore raw
In reply to Kanchan Joshi
Quoted 7 lines · Kanchan Joshi

The series enables uring-passthrough for admin-commands.

Patch 1 is prep.
Patch 2 adds new opcode for admin uring-passthrough, and enables it on nvme controller dev(/dev/nvmeX). It reuses the code of io-command passthrough, with the only difference that commands are issued on admin queue.

Looks good:

Can we add vectored admin commands as well, please? We basically get them for free, so I see no reason not to add them.

#5 lore raw
Quoted 9 lines · Christoph Hellwig
Quoted 7 lines · Kanchan Joshi

The series enables uring-passthrough for admin-commands.

Patch 1 is prep.
Patch 2 adds new opcode for admin uring-passthrough, and enables it on nvme controller dev(/dev/nvmeX). It reuses the code of io-command passthrough, with the only difference that commands are issued on admin queue.

Quoted 6 lines

Looks good:

Can we add vectored admin commands as well, please? We basically get them for free, so I see no reason not to add them.

Sure. By free, you mean this I suppose:

drivers/nvme/host/ioctl.c +3 -0
@@ -699,6 +699,9 @@ int nvme_dev_uring_cmd(struct io_uring_cmd *ioucmd, unsigned int issue_flags)
       case NVME_URING_CMD_ADMIN:
               ret = nvme_uring_cmd_io(ctrl, NULL, ioucmd, issue_flags, false);
               break;
+       case NVME_URING_CMD_ADMIN_VEC:
+               ret = nvme_uring_cmd_io(ctrl, NULL, ioucmd, issue_flags, true);
+               break;
 

anything else? I will fold this in, and submit v3 before Jens takes a look.

#6 lore raw
Quoted 11 lines · Kanchan Joshi

Sure. By free, you mean this I suppose:

drivers/nvme/host/ioctl.c +3 -0
@@ -699,6 +699,9 @@ int nvme_dev_uring_cmd(struct io_uring_cmd *ioucmd, unsigned int issue_flags)
       case NVME_URING_CMD_ADMIN:
               ret = nvme_uring_cmd_io(ctrl, NULL, ioucmd, issue_flags, false);
               break;
+       case NVME_URING_CMD_ADMIN_VEC:
+               ret = nvme_uring_cmd_io(ctrl, NULL, ioucmd, issue_flags, true);
+               break;
 
Quoted 2 lines

anything else? I will fold this in, and submit v3 before Jens takes a look.

We need a definition for NVME_URING_CMD_ADMIN_VEC, but yes, that's it.