Re: [PATCH v12 1/9] nvme-core: Clear any SGL flags in passthru commands
From: Keith Busch
Date: Mon Apr 20 2020 - 18:26:56 EST
On Mon, Apr 20, 2020 at 10:46:52AM -0600, Logan Gunthorpe wrote:
> The host driver should decide whether to use SGLs or PRPs and they
> currently assume the flags are cleared after the call to
> nvme_setup_cmd(). However, passed-through commands may erroneously
> set these bits; so clear them for all cases.
>
> Signed-off-by: Logan Gunthorpe <logang@xxxxxxxxxxxx>
> Reviewed-by: Sagi Grimberg <sagi@xxxxxxxxxxx>
> ---
> drivers/nvme/host/core.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 91c1bd659947..f5283b300e87 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -756,6 +756,8 @@ blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req,
> case REQ_OP_DRV_IN:
> case REQ_OP_DRV_OUT:
> memcpy(cmd, nvme_req(req)->cmd, sizeof(*cmd));
> + /* passthru commands should let the driver set the SGL flags */
> + cmd->common.flags &= ~NVME_CMD_SGL_ALL;
> break;
Is this really necessary? The passthrough handler currently rejects user
commands that set command flags:
static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
struct nvme_passthru_cmd __user *ucmd)
{
...
if (cmd.flags)
return -EINVAL;