[PATCH 2/3] nvme: enable uring-passthrough for admin commands

Kanchan Joshi joshi.k at samsung.com
Mon May 16 22:31:46 PDT 2022


Add a new opcode NVME_URING_CMD_ADMIN that userspace can use.
Wire up support for the case when this is issued over generic char
device node (/dev/ngXnY).

Signed-off-by: Kanchan Joshi <joshi.k at samsung.com>
---
 drivers/nvme/host/ioctl.c       | 54 +++++++++++++++++++++++++++++++--
 include/uapi/linux/nvme_ioctl.h |  1 +
 2 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c
index 114b490592b0..0f46dc7381a0 100644
--- a/drivers/nvme/host/ioctl.c
+++ b/drivers/nvme/host/ioctl.c
@@ -569,6 +569,31 @@ static int nvme_uring_cmd_checks(unsigned int issue_flags)
 	return 0;
 }
 
+static inline bool is_ctrl_uring_cmd(unsigned int cmd)
+{
+	return (cmd == NVME_URING_CMD_ADMIN);
+}
+
+static int nvme_ctrl_uring_cmd(struct nvme_ctrl *ctrl,
+			struct io_uring_cmd *ioucmd, unsigned int issue_flags)
+{
+	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_ns_uring_cmd(struct nvme_ns *ns, struct io_uring_cmd *ioucmd,
 			     unsigned int issue_flags)
 {
@@ -577,6 +602,9 @@ static int nvme_ns_uring_cmd(struct nvme_ns *ns, struct io_uring_cmd *ioucmd,
 
 	BUILD_BUG_ON(sizeof(struct nvme_uring_cmd_pdu) > sizeof(ioucmd->pdu));
 
+	if (is_ctrl_uring_cmd(ioucmd->cmd_op))
+		return nvme_ctrl_uring_cmd(ctrl, ioucmd, issue_flags);
+
 	ret = nvme_uring_cmd_checks(issue_flags);
 	if (ret)
 		return ret;
@@ -670,6 +698,22 @@ long nvme_ns_head_chr_ioctl(struct file *file, unsigned int cmd,
 	return ret;
 }
 
+static int nvme_ns_head_ctrl_uring_cmd(struct nvme_ns *ns,
+		struct io_uring_cmd *ioucmd, unsigned int issue_flags,
+		struct nvme_ns_head *head, int srcu_idx)
+	__releases(&head->srcu)
+{
+	struct nvme_ctrl *ctrl = ns->ctrl;
+	int ret;
+
+	nvme_get_ctrl(ctrl);
+	srcu_read_unlock(&head->srcu, srcu_idx);
+	ret = nvme_ctrl_uring_cmd(ctrl, ioucmd, issue_flags);
+
+	nvme_put_ctrl(ctrl);
+	return ret;
+}
+
 int nvme_ns_head_chr_uring_cmd(struct io_uring_cmd *ioucmd,
 		unsigned int issue_flags)
 {
@@ -679,8 +723,14 @@ int nvme_ns_head_chr_uring_cmd(struct io_uring_cmd *ioucmd,
 	struct nvme_ns *ns = nvme_find_path(head);
 	int ret = -EINVAL;
 
-	if (ns)
-		ret = nvme_ns_uring_cmd(ns, ioucmd, issue_flags);
+	if (!ns)
+		goto out_unlock;
+	if (is_ctrl_uring_cmd(ioucmd->cmd_op))
+		return nvme_ns_head_ctrl_uring_cmd(ns, ioucmd, issue_flags,
+				head, srcu_idx);
+
+	ret = nvme_ns_uring_cmd(ns, ioucmd, issue_flags);
+out_unlock:
 	srcu_read_unlock(&head->srcu, srcu_idx);
 	return ret;
 }
diff --git a/include/uapi/linux/nvme_ioctl.h b/include/uapi/linux/nvme_ioctl.h
index 0b1876aa5a59..6bcda1be6456 100644
--- a/include/uapi/linux/nvme_ioctl.h
+++ b/include/uapi/linux/nvme_ioctl.h
@@ -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 */
-- 
2.25.1




More information about the Linux-nvme mailing list