Re: [PATCH v3] nvme: allow 64-bit results in passthru commands

2019-09-25 Thread Christoph Hellwig
Looks fine:

Reviewed-by: Christoph Hellwig 


Re: [PATCH v3] nvme: allow 64-bit results in passthru commands

2019-09-24 Thread Keith Busch
On Tue, Sep 24, 2019 at 11:05:36AM -0700, Sagi Grimberg wrote:
> Looks fine to me,
> 
> Reviewed-by: Sagi Grimberg 
> 
> Keith, Christoph?

Looks good to me, too.

Reviewed-by: Keith Busch 


Re: [PATCH v3] nvme: allow 64-bit results in passthru commands

2019-09-24 Thread Sagi Grimberg

Looks fine to me,

Reviewed-by: Sagi Grimberg 

Keith, Christoph?


[PATCH v3] nvme: allow 64-bit results in passthru commands

2019-09-24 Thread Marta Rybczynska
It is not possible to get 64-bit results from the passthru commands,
what prevents from getting for the Capabilities (CAP) property value.

As a result, it is not possible to implement IOL's NVMe Conformance
test 4.3 Case 1 for Fabrics targets [1] (page 123).

This issue has been already discussed [2], but without a solution.

This patch solves the problem by adding new ioctls with a new
passthru structure, including 64-bit results. The older ioctls stay
unchanged.

[1] 
https://www.iol.unh.edu/sites/default/files/testsuites/nvme/UNH-IOL_NVMe_Conformance_Test_Suite_v11.0.pdf
[2] http://lists.infradead.org/pipermail/linux-nvme/2018-June/018791.html

Signed-off-by: Marta Rybczynska 
---
 drivers/nvme/host/core.c| 108 ++--
 include/uapi/linux/nvme_ioctl.h |  23 +
 2 files changed, 115 insertions(+), 16 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 1ede176..ac6a787 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -856,7 +856,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, u32 *result, unsigned timeout)
+   u32 meta_seed, u64 *result, unsigned timeout)
 {
bool write = nvme_is_write(cmd);
struct nvme_ns *ns = q->queuedata;
@@ -897,7 +897,7 @@ static int nvme_submit_user_cmd(struct request_queue *q,
else
ret = nvme_req(req)->status;
if (result)
-   *result = le32_to_cpu(nvme_req(req)->result.u32);
+   *result = le64_to_cpu(nvme_req(req)->result.u64);
if (meta && !ret && !write) {
if (copy_to_user(meta_buffer, meta, meta_len))
ret = -EFAULT;
@@ -1344,6 +1344,54 @@ static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct 
nvme_ns *ns,
struct nvme_command c;
unsigned timeout = 0;
u32 effects;
+   u64 result;
+   int status;
+
+   if (!capable(CAP_SYS_ADMIN))
+   return -EACCES;
+   if (copy_from_user(, ucmd, sizeof(cmd)))
+   return -EFAULT;
+   if (cmd.flags)
+   return -EINVAL;
+
+   memset(, 0, sizeof(c));
+   c.common.opcode = cmd.opcode;
+   c.common.flags = cmd.flags;
+   c.common.nsid = cpu_to_le32(cmd.nsid);
+   c.common.cdw2[0] = cpu_to_le32(cmd.cdw2);
+   c.common.cdw2[1] = cpu_to_le32(cmd.cdw3);
+   c.common.cdw10 = cpu_to_le32(cmd.cdw10);
+   c.common.cdw11 = cpu_to_le32(cmd.cdw11);
+   c.common.cdw12 = cpu_to_le32(cmd.cdw12);
+   c.common.cdw13 = cpu_to_le32(cmd.cdw13);
+   c.common.cdw14 = cpu_to_le32(cmd.cdw14);
+   c.common.cdw15 = cpu_to_le32(cmd.cdw15);
+
+   if (cmd.timeout_ms)
+   timeout = msecs_to_jiffies(cmd.timeout_ms);
+
+   effects = nvme_passthru_start(ctrl, ns, cmd.opcode);
+   status = nvme_submit_user_cmd(ns ? ns->queue : ctrl->admin_q, ,
+   (void __user *)(uintptr_t)cmd.addr, cmd.data_len,
+   (void __user *)(uintptr_t)cmd.metadata,
+   cmd.metadata_len, 0, , timeout);
+   nvme_passthru_end(ctrl, effects);
+
+   if (status >= 0) {
+   if (put_user(result, >result))
+   return -EFAULT;
+   }
+
+   return status;
+}
+
+static int nvme_user_cmd64(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
+   struct nvme_passthru_cmd64 __user *ucmd)
+{
+   struct nvme_passthru_cmd64 cmd;
+   struct nvme_command c;
+   unsigned timeout = 0;
+   u32 effects;
int status;
 
if (!capable(CAP_SYS_ADMIN))
@@ -1414,6 +1462,41 @@ static void nvme_put_ns_from_disk(struct nvme_ns_head 
*head, int idx)
srcu_read_unlock(>srcu, idx);
 }
 
+static bool is_ctrl_ioctl(unsigned int cmd)
+{
+   if (cmd == NVME_IOCTL_ADMIN_CMD || cmd == NVME_IOCTL_ADMIN64_CMD)
+   return true;
+   if (is_sed_ioctl(cmd))
+   return true;
+   return false;
+}
+
+static int nvme_handle_ctrl_ioctl(struct nvme_ns *ns, unsigned int cmd,
+ void __user *argp,
+ struct nvme_ns_head *head,
+ int srcu_idx)
+{
+   struct nvme_ctrl *ctrl = ns->ctrl;
+   int ret;
+
+   nvme_get_ctrl(ns->ctrl);
+   nvme_put_ns_from_disk(head, srcu_idx);
+
+   switch (cmd) {
+   case NVME_IOCTL_ADMIN_CMD:
+   ret = nvme_user_cmd(ctrl, NULL, argp);
+   break;
+   case NVME_IOCTL_ADMIN64_CMD:
+   ret = nvme_user_cmd64(ctrl, NULL, argp);
+   break;
+   default:
+   ret = sed_ioctl(ctrl->opal_dev, cmd, argp);
+   break;
+