From: Kanchan Joshi <joshi.k@samsung.com>
To: hch@lst.de, kbusch@kernel.org, axboe@kernel.dk
Cc: linux-nvme@lists.infradead.org, gost.dev@samsung.com,
joshiiitr@gmail.com
Subject: [PATCH 2/3] nvme: enable uring-passthrough for admin commands
Date: Tue, 17 May 2022 11:01:46 +0530 [thread overview]
Message-ID: <20220517053147.7925-3-joshi.k@samsung.com> (raw)
In-Reply-To: <20220517053147.7925-1-joshi.k@samsung.com>
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
next prev parent reply other threads:[~2022-05-17 6:50 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20220517053710epcas5p374ddc759e51f3adb243a5e98f5038699@epcas5p3.samsung.com>
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 8:15 ` Christoph Hellwig
2022-05-17 5:31 ` Kanchan Joshi [this message]
2022-05-17 8:15 ` [PATCH 2/3] nvme: enable uring-passthrough for admin commands Christoph Hellwig
2022-05-17 13:50 ` Kanchan Joshi
2022-05-18 7:29 ` Christoph Hellwig
2022-05-19 9:52 ` Kanchan Joshi
2022-05-17 5:31 ` [PATCH 3/3] nvme: admin command uring-passthrough on controller node Kanchan Joshi
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=20220517053147.7925-3-joshi.k@samsung.com \
--to=joshi.k@samsung.com \
--cc=axboe@kernel.dk \
--cc=gost.dev@samsung.com \
--cc=hch@lst.de \
--cc=joshiiitr@gmail.com \
--cc=kbusch@kernel.org \
--cc=linux-nvme@lists.infradead.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