* [PATCH 1/3] nvme: helper for uring-passthrough checks
2022-05-17 5:31 ` [PATCH 0/3] uring-passthrough for admin commands Kanchan Joshi
@ 2022-05-17 5:31 ` Kanchan Joshi
2022-05-17 8:15 ` Christoph Hellwig
2022-05-17 5:31 ` [PATCH 2/3] nvme: enable uring-passthrough for admin commands Kanchan Joshi
2022-05-17 5:31 ` [PATCH 3/3] nvme: admin command uring-passthrough on controller node Kanchan Joshi
2 siblings, 1 reply; 9+ messages in thread
From: Kanchan Joshi @ 2022-05-17 5:31 UTC (permalink / raw)
To: hch, kbusch, axboe; +Cc: linux-nvme, gost.dev, joshiiitr
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.
Signed-off-by: Kanchan Joshi <joshi.k@samsung.com>
---
drivers/nvme/host/ioctl.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c
index 7b0e2c9cdcae..114b490592b0 100644
--- a/drivers/nvme/host/ioctl.c
+++ b/drivers/nvme/host/ioctl.c
@@ -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:
--
2.25.1
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 2/3] nvme: enable uring-passthrough for admin commands
2022-05-17 5:31 ` [PATCH 0/3] uring-passthrough for admin commands Kanchan Joshi
2022-05-17 5:31 ` [PATCH 1/3] nvme: helper for uring-passthrough checks Kanchan Joshi
@ 2022-05-17 5:31 ` Kanchan Joshi
2022-05-17 8:15 ` Christoph Hellwig
2022-05-17 5:31 ` [PATCH 3/3] nvme: admin command uring-passthrough on controller node Kanchan Joshi
2 siblings, 1 reply; 9+ messages in thread
From: Kanchan Joshi @ 2022-05-17 5:31 UTC (permalink / raw)
To: hch, kbusch, axboe; +Cc: linux-nvme, gost.dev, joshiiitr
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@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
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 3/3] nvme: admin command uring-passthrough on controller node
2022-05-17 5:31 ` [PATCH 0/3] uring-passthrough for admin commands Kanchan Joshi
2022-05-17 5:31 ` [PATCH 1/3] nvme: helper for uring-passthrough checks Kanchan Joshi
2022-05-17 5:31 ` [PATCH 2/3] nvme: enable uring-passthrough for admin commands Kanchan Joshi
@ 2022-05-17 5:31 ` Kanchan Joshi
2 siblings, 0 replies; 9+ messages in thread
From: Kanchan Joshi @ 2022-05-17 5:31 UTC (permalink / raw)
To: hch, kbusch, axboe; +Cc: linux-nvme, gost.dev, joshiiitr
Enable uring-passthrough for admin commands when issued on controller
(/dev/nvmeX) node.
Signed-off-by: Kanchan Joshi <joshi.k@samsung.com>
---
drivers/nvme/host/core.c | 1 +
drivers/nvme/host/ioctl.c | 7 +++++++
drivers/nvme/host/nvme.h | 1 +
3 files changed, 9 insertions(+)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 510e3860358b..23479cf866cc 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3145,6 +3145,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,
diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c
index 0f46dc7381a0..833b285b1b04 100644
--- a/drivers/nvme/host/ioctl.c
+++ b/drivers/nvme/host/ioctl.c
@@ -736,6 +736,13 @@ 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;
+
+ return nvme_ctrl_uring_cmd(ctrl, ioucmd, issue_flags);
+}
+
static int nvme_dev_user_cmd(struct nvme_ctrl *ctrl, void __user *argp)
{
struct nvme_ns *ns;
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 086ccbdd7003..26d35c557588 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -787,6 +787,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;
--
2.25.1
^ permalink raw reply related [flat|nested] 9+ messages in thread