All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] nvme: add vectored-io support for user-passthru
       [not found] <CGME20220131142354epcas5p3ff940846a88ae6fcfd8f9b3acb421913@epcas5p3.samsung.com>
@ 2022-01-31 14:18 ` Kanchan Joshi
  2022-02-01  8:02   ` Christoph Hellwig
  0 siblings, 1 reply; 4+ messages in thread
From: Kanchan Joshi @ 2022-01-31 14:18 UTC (permalink / raw)
  To: hch, kbusch, axboe, kch; +Cc: linux-nvme, joshiiitr

wire up support for passthru that takes an array of buffers (using
iovec).
Exposed via a new ioctl NVME_IOCTL_IO64_CMD_VEC for which -

1. cmd.addr is base address of user iovec array
2. cmd.vec_cnt is count of iovec array elements

Signed-off-by: Kanchan Joshi <joshi.k@samsung.com>
---
Changes since v1:
- added new ioctl rather than reusing NVME_IOCTL_IO64_CMD (hch)
- dropped block-layer helper and open-coded in nvme instead (hch)
https://lore.kernel.org/linux-nvme/20220127082536.7243-1-joshi.k@samsung.com/

 drivers/nvme/host/ioctl.c       | 44 +++++++++++++++++++++++++++------
 include/uapi/linux/nvme_ioctl.h |  6 ++++-
 2 files changed, 42 insertions(+), 8 deletions(-)

diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c
index 22314962842d..54788b1b098e 100644
--- a/drivers/nvme/host/ioctl.c
+++ b/drivers/nvme/host/ioctl.c
@@ -56,7 +56,7 @@ static void *nvme_add_user_metadata(struct bio *bio, void __user *ubuf,
 static int nvme_submit_user_cmd(struct request_queue *q,
 		struct nvme_command *cmd, void __user *ubuffer,
 		unsigned bufflen, void __user *meta_buffer, unsigned meta_len,
-		u32 meta_seed, u64 *result, unsigned timeout)
+		u32 meta_seed, u64 *result, unsigned timeout, bool vec)
 {
 	bool write = nvme_is_write(cmd);
 	struct nvme_ns *ns = q->queuedata;
@@ -75,8 +75,22 @@ static int nvme_submit_user_cmd(struct request_queue *q,
 	nvme_req(req)->flags |= NVME_REQ_USERCMD;
 
 	if (ubuffer && bufflen) {
-		ret = blk_rq_map_user(q, req, NULL, ubuffer, bufflen,
+		if (!vec)
+			ret = blk_rq_map_user(q, req, NULL, ubuffer, bufflen,
 				GFP_KERNEL);
+		else {
+			struct iovec fast_iov[UIO_FASTIOV];
+			struct iovec *iov = fast_iov;
+			struct iov_iter iter;
+
+			ret = import_iovec(rq_data_dir(req), ubuffer, bufflen,
+					UIO_FASTIOV, &iov, &iter);
+			if (ret < 0)
+				goto out;
+			ret = blk_rq_map_user_iov(q, req, NULL, &iter,
+					GFP_KERNEL);
+			kfree(iov);
+		}
 		if (ret)
 			goto out;
 		bio = req->bio;
@@ -170,7 +184,8 @@ static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio)
 
 	return nvme_submit_user_cmd(ns->queue, &c,
 			nvme_to_user_ptr(io.addr), length,
-			metadata, meta_len, lower_32_bits(io.slba), NULL, 0);
+			metadata, meta_len, lower_32_bits(io.slba), NULL, 0,
+			false);
 }
 
 static bool nvme_validate_passthru_nsid(struct nvme_ctrl *ctrl,
@@ -224,7 +239,7 @@ static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
 	status = nvme_submit_user_cmd(ns ? ns->queue : ctrl->admin_q, &c,
 			nvme_to_user_ptr(cmd.addr), cmd.data_len,
 			nvme_to_user_ptr(cmd.metadata), cmd.metadata_len,
-			0, &result, timeout);
+			0, &result, timeout, false);
 
 	if (status >= 0) {
 		if (put_user(result, &ucmd->result))
@@ -234,8 +249,8 @@ static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
 	return status;
 }
 
-static int nvme_user_cmd64(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
-			struct nvme_passthru_cmd64 __user *ucmd)
+static int nvme_user_cmd64_common(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
+			struct nvme_passthru_cmd64 __user *ucmd, bool vec)
 {
 	struct nvme_passthru_cmd64 cmd;
 	struct nvme_command c;
@@ -270,7 +285,7 @@ static int nvme_user_cmd64(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
 	status = nvme_submit_user_cmd(ns ? ns->queue : ctrl->admin_q, &c,
 			nvme_to_user_ptr(cmd.addr), cmd.data_len,
 			nvme_to_user_ptr(cmd.metadata), cmd.metadata_len,
-			0, &cmd.result, timeout);
+			0, &cmd.result, timeout, vec);
 
 	if (status >= 0) {
 		if (put_user(cmd.result, &ucmd->result))
@@ -278,6 +293,19 @@ static int nvme_user_cmd64(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
 	}
 
 	return status;
+
+}
+
+static int nvme_user_cmd64(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
+			struct nvme_passthru_cmd64 __user *ucmd)
+{
+	return nvme_user_cmd64_common(ctrl, ns, ucmd, false);
+}
+
+static int nvme_user_cmd64_vec(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
+			struct nvme_passthru_cmd64 __user *ucmd)
+{
+	return nvme_user_cmd64_common(ctrl, ns, ucmd, true);
 }
 
 static bool is_ctrl_ioctl(unsigned int cmd)
@@ -341,6 +369,8 @@ static int nvme_ns_ioctl(struct nvme_ns *ns, unsigned int cmd,
 		return nvme_submit_io(ns, argp);
 	case NVME_IOCTL_IO64_CMD:
 		return nvme_user_cmd64(ns->ctrl, ns, argp);
+	case NVME_IOCTL_IO64_CMD_VEC:
+		return nvme_user_cmd64_vec(ns->ctrl, ns, argp);
 	default:
 		return -ENOTTY;
 	}
diff --git a/include/uapi/linux/nvme_ioctl.h b/include/uapi/linux/nvme_ioctl.h
index d99b5a772698..b2e43185e3b5 100644
--- a/include/uapi/linux/nvme_ioctl.h
+++ b/include/uapi/linux/nvme_ioctl.h
@@ -55,7 +55,10 @@ struct nvme_passthru_cmd64 {
 	__u64	metadata;
 	__u64	addr;
 	__u32	metadata_len;
-	__u32	data_len;
+	union {
+		__u32	data_len; /* for non-vectored io */
+		__u32	vec_cnt; /* for vectored io */
+	};
 	__u32	cdw10;
 	__u32	cdw11;
 	__u32	cdw12;
@@ -78,5 +81,6 @@ struct nvme_passthru_cmd64 {
 #define NVME_IOCTL_RESCAN	_IO('N', 0x46)
 #define NVME_IOCTL_ADMIN64_CMD	_IOWR('N', 0x47, struct nvme_passthru_cmd64)
 #define NVME_IOCTL_IO64_CMD	_IOWR('N', 0x48, struct nvme_passthru_cmd64)
+#define NVME_IOCTL_IO64_CMD_VEC	_IOWR('N', 0x49, struct nvme_passthru_cmd64)
 
 #endif /* _UAPI_LINUX_NVME_IOCTL_H */
-- 
2.25.1



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

* Re: [PATCH v2] nvme: add vectored-io support for user-passthru
  2022-01-31 14:18 ` [PATCH v2] nvme: add vectored-io support for user-passthru Kanchan Joshi
@ 2022-02-01  8:02   ` Christoph Hellwig
  2022-02-02  6:52     ` Kanchan Joshi
  0 siblings, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2022-02-01  8:02 UTC (permalink / raw)
  To: Kanchan Joshi; +Cc: hch, kbusch, axboe, kch, linux-nvme, joshiiitr

> +static int nvme_user_cmd64(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
> +			struct nvme_passthru_cmd64 __user *ucmd)
> +{
> +	return nvme_user_cmd64_common(ctrl, ns, ucmd, false);
> +}
> +
> +static int nvme_user_cmd64_vec(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
> +			struct nvme_passthru_cmd64 __user *ucmd)
> +{
> +	return nvme_user_cmd64_common(ctrl, ns, ucmd, true);
>  }

I think we cn skip these tiny wrappers.

>  static bool is_ctrl_ioctl(unsigned int cmd)
> @@ -341,6 +369,8 @@ static int nvme_ns_ioctl(struct nvme_ns *ns, unsigned int cmd,
>  		return nvme_submit_io(ns, argp);
>  	case NVME_IOCTL_IO64_CMD:
>  		return nvme_user_cmd64(ns->ctrl, ns, argp);
> +	case NVME_IOCTL_IO64_CMD_VEC:
> +		return nvme_user_cmd64_vec(ns->ctrl, ns, argp);

Maybe add a rationale why we don't need a new ioctl for admin
commands to the commit log.


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

* Re: [PATCH v2] nvme: add vectored-io support for user-passthru
  2022-02-01  8:02   ` Christoph Hellwig
@ 2022-02-02  6:52     ` Kanchan Joshi
  2022-02-02  7:46       ` Christoph Hellwig
  0 siblings, 1 reply; 4+ messages in thread
From: Kanchan Joshi @ 2022-02-02  6:52 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Kanchan Joshi, Keith Busch, Jens Axboe, kch, linux-nvme

On Tue, Feb 1, 2022 at 1:32 PM Christoph Hellwig <hch@lst.de> wrote:
>
> > +static int nvme_user_cmd64(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
> > +                     struct nvme_passthru_cmd64 __user *ucmd)
> > +{
> > +     return nvme_user_cmd64_common(ctrl, ns, ucmd, false);
> > +}
> > +
> > +static int nvme_user_cmd64_vec(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
> > +                     struct nvme_passthru_cmd64 __user *ucmd)
> > +{
> > +     return nvme_user_cmd64_common(ctrl, ns, ucmd, true);
> >  }
>
> I think we cn skip these tiny wrappers.

With the wrappers, the attempt was to retain nvme_user_cmd64
parameters so that we don't have to change all its invocations.
But sure, I can do away with that.

> >  static bool is_ctrl_ioctl(unsigned int cmd)
> > @@ -341,6 +369,8 @@ static int nvme_ns_ioctl(struct nvme_ns *ns, unsigned int cmd,
> >               return nvme_submit_io(ns, argp);
> >       case NVME_IOCTL_IO64_CMD:
> >               return nvme_user_cmd64(ns->ctrl, ns, argp);
> > +     case NVME_IOCTL_IO64_CMD_VEC:
> > +             return nvme_user_cmd64_vec(ns->ctrl, ns, argp);
>
> Maybe add a rationale why we don't need a new ioctl for admin
> commands to the commit log.

Not many admin commands are buffer-heavy and likely to have lower
invocation frequency too, so I did not think of adding support.
If you foresee this to be useful for some (maybe log-page or
fw-download), I can fold that in.

Thanks,
-- 
Kanchan


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

* Re: [PATCH v2] nvme: add vectored-io support for user-passthru
  2022-02-02  6:52     ` Kanchan Joshi
@ 2022-02-02  7:46       ` Christoph Hellwig
  0 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2022-02-02  7:46 UTC (permalink / raw)
  To: Kanchan Joshi
  Cc: Christoph Hellwig, Kanchan Joshi, Keith Busch, Jens Axboe, kch,
	linux-nvme

On Wed, Feb 02, 2022 at 12:22:53PM +0530, Kanchan Joshi wrote:
> Not many admin commands are buffer-heavy and likely to have lower
> invocation frequency too, so I did not think of adding support.
> If you foresee this to be useful for some (maybe log-page or
> fw-download), I can fold that in.

Just add this rationale to the commit message so that we document it for
future generations.


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

end of thread, other threads:[~2022-02-02  7:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20220131142354epcas5p3ff940846a88ae6fcfd8f9b3acb421913@epcas5p3.samsung.com>
2022-01-31 14:18 ` [PATCH v2] nvme: add vectored-io support for user-passthru Kanchan Joshi
2022-02-01  8:02   ` Christoph Hellwig
2022-02-02  6:52     ` Kanchan Joshi
2022-02-02  7:46       ` Christoph Hellwig

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.