[PATCH 2/2] nvme: use driver pdu command for passthrough

Kanchan Joshi joshiiitr at gmail.com
Wed Mar 17 09:46:59 GMT 2021


On Tue, Mar 16, 2021 at 10:48 PM Keith Busch <kbusch at kernel.org> wrote:
>
> All nvme transport drivers preallocate an nvme command for each request.
> Use that for passthrough commands instead of the stack allocated
> command. All transports must initialize the generic nvme_request's 'cmd'
> to point to the transport specific preallocated command, and modify
> nvme_setup_cmd() to initialize the driver pdu's nvme_command.
>
> Signed-off-by: Keith Busch <kbusch at kernel.org>
> ---
>  drivers/nvme/host/core.c   | 19 ++++++-------------
>  drivers/nvme/host/fc.c     |  5 ++---
>  drivers/nvme/host/nvme.h   |  3 +--
>  drivers/nvme/host/pci.c    |  3 ++-
>  drivers/nvme/host/rdma.c   |  5 +++--
>  drivers/nvme/host/tcp.c    |  5 ++++-
>  drivers/nvme/target/loop.c |  4 +++-
>  7 files changed, 21 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 512e5578c6e4..eb71ef1648a0 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -575,6 +575,9 @@ EXPORT_SYMBOL_NS_GPL(nvme_put_ns, NVME_TARGET_PASSTHRU);
>
>  static inline void nvme_clear_nvme_request(struct request *req)
>  {
> +       struct nvme_command *cmd = nvme_req(req)->cmd;
> +
> +       memset(cmd, 0, sizeof(*cmd));
>         nvme_req(req)->retries = 0;
>         nvme_req(req)->flags = 0;
>         req->rq_flags |= RQF_DONTPREP;
> @@ -595,7 +598,7 @@ static inline void nvme_init_request(struct request *req,
>
>         req->cmd_flags |= REQ_FAILFAST_DRIVER;
>         nvme_clear_nvme_request(req);
> -       nvme_req(req)->cmd = cmd;
> +       memcpy(nvme_req(req)->cmd, cmd, sizeof(*cmd));
>  }
I am wondering if this memcpy() is fine. The "nvme_req(req)->cmd" is a
pointer which may not have storage assigned to it?



More information about the Linux-nvme mailing list