All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] uring-passthrough for admin commands
       [not found] <CGME20220517053710epcas5p374ddc759e51f3adb243a5e98f5038699@epcas5p3.samsung.com>
@ 2022-05-17  5:31 ` Kanchan Joshi
       [not found]   ` <CGME20220517053711epcas5p40f48777253119633d99c8b2b905793ff@epcas5p4.samsung.com>
                     ` (2 more replies)
  0 siblings, 3 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

During the review rounds and LSFMM, it emerged that uring-passthrough
for admin-commands will also be useful. So this series wires that up.

Prepared against for-next (linux-block) on top of
commit cef3f8e4ed04 (Merge branch 'for-5.19/block'...).

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

Patch 3 enables the same for controller char device (/dev/nvmeX).

Kanchan Joshi (3):
  nvme: helper for uring-passthrough checks
  nvme: enable uring-passthrough for admin commands
  nvme: admin command uring-passthrough on controller node

 drivers/nvme/host/core.c        |  1 +
 drivers/nvme/host/ioctl.c       | 83 +++++++++++++++++++++++++++++----
 drivers/nvme/host/nvme.h        |  1 +
 include/uapi/linux/nvme_ioctl.h |  1 +
 4 files changed, 77 insertions(+), 9 deletions(-)

-- 
2.25.1



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/3] nvme: helper for uring-passthrough checks
       [not found]   ` <CGME20220517053711epcas5p40f48777253119633d99c8b2b905793ff@epcas5p4.samsung.com>
@ 2022-05-17  5:31     ` Kanchan Joshi
  2022-05-17  8:15       ` Christoph Hellwig
  0 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
       [not found]   ` <CGME20220517053712epcas5p20c6a2b123709d7df1a1df8c9b1c91125@epcas5p2.samsung.com>
@ 2022-05-17  5:31     ` Kanchan Joshi
  2022-05-17  8:15       ` Christoph Hellwig
  0 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
       [not found]   ` <CGME20220517053713epcas5p4770bb3699f7a0c5884c14633659e8cd2@epcas5p4.samsung.com>
@ 2022-05-17  5:31     ` Kanchan Joshi
  0 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

* Re: [PATCH 2/3] nvme: enable uring-passthrough for admin commands
  2022-05-17  5:31     ` [PATCH 2/3] nvme: enable uring-passthrough for admin commands Kanchan Joshi
@ 2022-05-17  8:15       ` Christoph Hellwig
  2022-05-17 13:50         ` Kanchan Joshi
  0 siblings, 1 reply; 9+ messages in thread
From: Christoph Hellwig @ 2022-05-17  8:15 UTC (permalink / raw)
  To: Kanchan Joshi; +Cc: hch, kbusch, axboe, linux-nvme, gost.dev, joshiiitr

On Tue, May 17, 2022 at 11:01:46AM +0530, Kanchan Joshi wrote:
> 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).

I would really prefer not adding this to the per-namespaces nodes.
The do something controller specific on the namespace node patter is
a massive pain both in terms of code and semantics.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/3] nvme: helper for uring-passthrough checks
  2022-05-17  5:31     ` [PATCH 1/3] nvme: helper for uring-passthrough checks Kanchan Joshi
@ 2022-05-17  8:15       ` Christoph Hellwig
  0 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2022-05-17  8:15 UTC (permalink / raw)
  To: Kanchan Joshi; +Cc: hch, kbusch, axboe, linux-nvme, gost.dev, joshiiitr

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] nvme: enable uring-passthrough for admin commands
  2022-05-17  8:15       ` Christoph Hellwig
@ 2022-05-17 13:50         ` Kanchan Joshi
  2022-05-18  7:29           ` Christoph Hellwig
  0 siblings, 1 reply; 9+ messages in thread
From: Kanchan Joshi @ 2022-05-17 13:50 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Kanchan Joshi, Keith Busch, Jens Axboe, linux-nvme, gost.dev

On Tue, May 17, 2022 at 1:45 PM Christoph Hellwig <hch@lst.de> wrote:
>
> On Tue, May 17, 2022 at 11:01:46AM +0530, Kanchan Joshi wrote:
> > 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).
>
> I would really prefer not adding this to the per-namespaces nodes.
> The do something controller specific on the namespace node patter is
> a massive pain both in terms of code and semantics.

Both block (nvme0n1) and char (ng0n1) nodes allow admin-cmds to be
sent in the same way (with sync passthrough) as this patch does. So
same semantics when we support this for async/uring passthrough, IMHO.

To do passthrough read/write (and other stuff) via ns-generic
interface, uring-application will need information (such as lba
format) which can be obtained only with admin-commands. And if we
don't support what this patch does, it will have to either -

(a) get that information with sync-passthrough from /dev/ng0n1. Since
we clearly separated async-passthrough with separate opcode/struct, it
will need more bookkeeping to keep both sync and async dispatch
engines alive.

or

(b) maintain one more fd (for /dev/nvme0 node) and use that for async
dispatch whenever admin-cmd needs to be sent

Given the implications, is it not better to have this up on ns-char
node and applications get to use everything (io and admin cmds) in
async manner with async-specific opcode/struct only?

I will kill this if you still think it is a bad idea somehow, and move
the code of this to patch 3 (enable only /dev/nvme0). LMK.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] nvme: enable uring-passthrough for admin commands
  2022-05-17 13:50         ` Kanchan Joshi
@ 2022-05-18  7:29           ` Christoph Hellwig
  2022-05-19  9:52             ` Kanchan Joshi
  0 siblings, 1 reply; 9+ messages in thread
From: Christoph Hellwig @ 2022-05-18  7:29 UTC (permalink / raw)
  To: Kanchan Joshi
  Cc: Christoph Hellwig, Kanchan Joshi, Keith Busch, Jens Axboe,
	linux-nvme, gost.dev

Doing the controller based ioctls on a per-namespace node has been really
painful for the existing ioctl.  So I'd much prefer to avoid that, but
I'd be happy to hear more opinions.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] nvme: enable uring-passthrough for admin commands
  2022-05-18  7:29           ` Christoph Hellwig
@ 2022-05-19  9:52             ` Kanchan Joshi
  0 siblings, 0 replies; 9+ messages in thread
From: Kanchan Joshi @ 2022-05-19  9:52 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Kanchan Joshi, Keith Busch, Jens Axboe, linux-nvme, gost.dev

On Wed, May 18, 2022 at 12:59 PM Christoph Hellwig <hch@lst.de> wrote:
>
> Doing the controller based ioctls on a per-namespace node has been really
> painful for the existing ioctl.  So I'd much prefer to avoid that, but
> I'd be happy to hear more opinions.

Not sure if we may get opinions before merge-window expiration.
So I am thinking to respin with only the controller node (and defer ns
one to 5.20). Hope that is fine?


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-05-19  9:53 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20220517053710epcas5p374ddc759e51f3adb243a5e98f5038699@epcas5p3.samsung.com>
2022-05-17  5:31 ` [PATCH 0/3] uring-passthrough for admin commands Kanchan Joshi
     [not found]   ` <CGME20220517053711epcas5p40f48777253119633d99c8b2b905793ff@epcas5p4.samsung.com>
2022-05-17  5:31     ` [PATCH 1/3] nvme: helper for uring-passthrough checks Kanchan Joshi
2022-05-17  8:15       ` Christoph Hellwig
     [not found]   ` <CGME20220517053712epcas5p20c6a2b123709d7df1a1df8c9b1c91125@epcas5p2.samsung.com>
2022-05-17  5:31     ` [PATCH 2/3] nvme: enable uring-passthrough for admin commands Kanchan Joshi
2022-05-17  8:15       ` Christoph Hellwig
2022-05-17 13:50         ` Kanchan Joshi
2022-05-18  7:29           ` Christoph Hellwig
2022-05-19  9:52             ` Kanchan Joshi
     [not found]   ` <CGME20220517053713epcas5p4770bb3699f7a0c5884c14633659e8cd2@epcas5p4.samsung.com>
2022-05-17  5:31     ` [PATCH 3/3] nvme: admin command uring-passthrough on controller node Kanchan Joshi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.