Skip to contentSkip to conversation

nvme: rework __nvme_submit_sync_cmd()

PATCH In review Hannes Reinecke 3 participants 22 messages Feb 9, 2023 – Feb 14, 2023

Subsystems (5)
SCSI Block layer NVMe NVMe target +1 more subsystems
lore
Share & tools
lore

Hannes Reinecke

author maintainer
#0 lore raw

cover nvme: rework __nvme_submit_sync_cmd()

Hi all,

as Jens and hch complained about the argument list to __nvme_submit_sync_cmd() getting too long, here's now a patchset to clean things up.
The first patch is to split off nvme_alloc_request() from __nvme_submit_sync_cmd(), which serves to reduce the number of arguments; it's also a nice cleanup as this function can be utilized to replace some open-coded versions.
Then a patch to allow blk_rq_map_kern() to accept a NULL pointer; that's really trivial and simplifies caller handling.
The third one again is pretty simple, and moves the 'result' handling into nvme_execute_rq(), rather than leave it with the caller.
And with that we can open-code __nvme_submit_sync_cmd() in the callers, and drop the function altogether.
The last patch to allow for retries of the authentication commands is then pretty simple.

As usual, comments and reviews are welcome.

Hannes Reinecke (5):
nvme: split __nvme_submit_sync_cmd()
block: make blk_rq_map_kern() to accept a NULL buffer
nvme: move result handling into nvme_execute_rq()
nvme: open-code __nvme_submit_sync_cmd()
nvme: retry authentication commands if DNR status bit is not set

 block/blk-map.c                |  2 +-
 drivers/block/pktcdvd.c        | 10 ++--
 drivers/nvme/host/auth.c       | 31 ++++++++---
 drivers/nvme/host/core.c       | 96 +++++++++++++++++++++-------------
 drivers/nvme/host/fabrics.c    | 62 +++++++++++++++++-----
 drivers/nvme/host/ioctl.c      |  5 +-
 drivers/nvme/host/nvme.h       |  9 ++--
 drivers/nvme/host/pci.c        |  8 ++-
 drivers/nvme/target/passthru.c |  6 +--
 drivers/scsi/scsi_ioctl.c      |  8 ++-
 drivers/scsi/scsi_lib.c        | 11 ++--
 11 files changed, 155 insertions(+), 93 deletions(-)
Signature · 1 line
2.35.3
author maintainer
#1 lore raw

PATCH 1/5 nvme: split __nvme_submit_sync_cmd()

Split a nvme_alloc_request() function from __nvme_submit_sync_cmd() to reduce the number of arguments.

---
 drivers/nvme/host/auth.c       |  9 +++--
 drivers/nvme/host/core.c       | 60 ++++++++++++++++++++++------------
 drivers/nvme/host/fabrics.c    | 44 ++++++++++++++++++-------
 drivers/nvme/host/nvme.h       |  8 ++---
 drivers/nvme/host/pci.c        |  8 ++---
 drivers/nvme/target/passthru.c |  3 +-
 6 files changed, 85 insertions(+), 47 deletions(-)
drivers/nvme/host/auth.c +6 -3
index 787537454f7f..05d02ab229f7 100644
@@ -62,6 +62,7 @@ static int nvme_auth_submit(struct nvme_ctrl *ctrl, int qid,
 	struct nvme_command cmd = {};
 	blk_mq_req_flags_t flags = nvme_auth_flags_from_qid(qid);
 	struct request_queue *q = nvme_auth_queue_from_qid(ctrl, qid);
+	struct request *req;
 	int ret;
 
 	cmd.auth_common.opcode = nvme_fabrics_command;
@@ -76,9 +77,11 @@ static int nvme_auth_submit(struct nvme_ctrl *ctrl, int qid,
 		cmd.auth_receive.al = cpu_to_le32(data_len);
 	}
 
-	ret = __nvme_submit_sync_cmd(q, &cmd, NULL, data, data_len,
-				     qid == 0 ? NVME_QID_ANY : qid,
-				     0, flags);
+	req = nvme_alloc_request(q, &cmd, qid == 0 ? NVME_QID_ANY : qid, flags);
+	if (IS_ERR(req))
+		return PTR_ERR(req);
+
+	ret = __nvme_submit_sync_cmd(req, NULL, data, data_len, 0);
 	if (ret > 0)
 		dev_warn(ctrl->device,
 			"qid %d auth_send failed with status %d\n", qid, ret);
drivers/nvme/host/core.c +39 -21

119 lines not on this page · raw message

drivers/nvme/host/fabrics.c +32 -12

104 lines not on this page · raw message

drivers/nvme/host/nvme.h +4 -4
index bf46f122e9e1..9b4b3bb69e27 100644
@@ -813,10 +813,10 @@ static inline bool nvme_is_unique_nsid(struct nvme_ctrl *ctrl,
 
 int nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
 		void *buf, unsigned bufflen);
-int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
-		union nvme_result *result, void *buffer, unsigned bufflen,
-		int qid, int at_head,
-		blk_mq_req_flags_t flags);
+struct request *nvme_alloc_request(struct request_queue *q,
+		struct nvme_command *cmd, int qid, blk_mq_req_flags_t flags);
+int __nvme_submit_sync_cmd(struct request *req, union nvme_result *result,
+		void *buffer, unsigned bufflen, int at_head);
 int nvme_set_features(struct nvme_ctrl *dev, unsigned int fid,
 		      unsigned int dword11, void *buffer, size_t buflen,
 		      u32 *result);
drivers/nvme/host/pci.c +3 -5
index a331fbfa9a66..94dcc9b65fec 100644
@@ -1376,13 +1376,12 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req)
 		 nvme_get_opcode_str(nvme_req(req)->cmd->common.opcode),
 		 nvmeq->qid);
 
-	abort_req = blk_mq_alloc_request(dev->ctrl.admin_q, nvme_req_op(&cmd),
-					 BLK_MQ_REQ_NOWAIT);
+	abort_req = nvme_alloc_request(dev->ctrl.admin_q, &cmd,
+			NVME_QID_ANY, BLK_MQ_REQ_NOWAIT);
 	if (IS_ERR(abort_req)) {
 		atomic_inc(&dev->ctrl.abort_limit);
 		return BLK_EH_RESET_TIMER;
 	}
-	nvme_init_request(abort_req, &cmd);
 
 	abort_req->end_io = abort_endio;
 	abort_req->end_io_data = NULL;
@@ -2391,10 +2390,9 @@ static int nvme_delete_queue(struct nvme_queue *nvmeq, u8 opcode)
 	cmd.delete_queue.opcode = opcode;
 	cmd.delete_queue.qid = cpu_to_le16(nvmeq->qid);
 
-	req = blk_mq_alloc_request(q, nvme_req_op(&cmd), BLK_MQ_REQ_NOWAIT);
+	req = nvme_alloc_request(q, &cmd, NVME_QID_ANY, BLK_MQ_REQ_NOWAIT);
 	if (IS_ERR(req))
 		return PTR_ERR(req);
-	nvme_init_request(req, &cmd);
 
 	if (opcode == nvme_admin_delete_cq)
 		req->end_io = nvme_del_cq_end;
drivers/nvme/target/passthru.c +1 -2
index 511c980d538d..aae6d5bb4fd8 100644
@@ -316,12 +316,11 @@ static void nvmet_passthru_execute_cmd(struct nvmet_req *req)
 		timeout = nvmet_req_subsys(req)->admin_timeout;
 	}
 
-	rq = blk_mq_alloc_request(q, nvme_req_op(req->cmd), 0);
+	rq = nvme_alloc_request(q, req->cmd, NVME_QID_ANY, 0);
 	if (IS_ERR(rq)) {
 		status = NVME_SC_INTERNAL;
 		goto out_put_ns;
 	}
-	nvme_init_request(rq, req->cmd);
 
 	if (timeout)
 		rq->timeout = timeout;
Signature · 1 line
2.35.3
#2 lore raw

Re: [PATCH 1/5] nvme: split __nvme_submit_sync_cmd()

drivers/nvme/host/core.c int nvme_execute_rq(struct request *rq, bool at_head) · line 1031

Quoted 13 lines
drivers/nvme/host/core.c +4 -1
+struct request *nvme_alloc_request(struct request_queue *q,
+				   struct nvme_command *cmd, int qid,
+				   blk_mq_req_flags_t flags)
 {
 	struct request *req;
-	int ret;
 
 	if (qid == NVME_QID_ANY)
 		req = blk_mq_alloc_request(q, nvme_req_op(cmd), flags);
 	else
 		req = blk_mq_alloc_request_hctx(q, nvme_req_op(cmd), flags,
 						qid - 1);
+	if (!IS_ERR(req))

As already said last time, please split out a nvme_alloc_request_qid function for the few caller that pass a qid.

maintainer
#3 lore raw

Re: [PATCH 1/5] nvme: split __nvme_submit_sync_cmd()

Quoted 8 lines
Quoted 8 lines
drivers/nvme/host/core.c +3 -1
+struct request *nvme_alloc_request(struct request_queue *q,
+				   struct nvme_command *cmd, int qid,
+				   blk_mq_req_flags_t flags)
  {
  	struct request *req;
-	int ret;
Quoted 9 lines

drivers/nvme/host/core.c int nvme_execute_rq(struct request *rq, bool at_head) · line 1031

Quoted 6 lines

if (qid == NVME_QID_ANY)
req = blk_mq_alloc_request(q, nvme_req_op(cmd), flags);
else
req = blk_mq_alloc_request_hctx(q, nvme_req_op(cmd), flags,
qid - 1);

drivers/nvme/host/core.c +1 -0
+	if (!IS_ERR(req))

As already said last time, please split out a nvme_alloc_request_qid function for the few caller that pass a qid.

Agreed.

author maintainer
#4 lore raw

PATCH 2/5 block: make blk_rq_map_kern() to accept a NULL buffer

In reply to Hannes Reinecke

We really should accept a NULL buffer as argument, avoiding conditional coding in the caller.

---
 block/blk-map.c           |  2 +-
 drivers/block/pktcdvd.c   | 10 ++++------
 drivers/nvme/host/core.c  |  8 +++-----
 drivers/scsi/scsi_ioctl.c |  8 +++-----
 drivers/scsi/scsi_lib.c   | 11 +++++------
 5 files changed, 16 insertions(+), 23 deletions(-)
block/blk-map.c +1 -1
index 859590be077e..4615386b85d3 100644
@@ -783,7 +783,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
 	if (len > (queue_max_hw_sectors(q) << 9))
 		return -EINVAL;
 	if (!len || !kbuf)
-		return -EINVAL;
+		return 0;
 
 	if (!blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf) ||
 	    blk_queue_may_bounce(q))
drivers/block/pktcdvd.c +4 -6
index 2f1a92509271..9e49cca82bfd 100644
@@ -694,12 +694,10 @@ static int pkt_generic_packet(struct pktcdvd_device *pd, struct packet_command *
 		return PTR_ERR(rq);
 	scmd = blk_mq_rq_to_pdu(rq);
 
-	if (cgc->buflen) {
-		ret = blk_rq_map_kern(q, rq, cgc->buffer, cgc->buflen,
-				      GFP_NOIO);
-		if (ret)
-			goto out;
-	}
+	ret = blk_rq_map_kern(q, rq, cgc->buffer, cgc->buflen,
+			      GFP_NOIO);
+	if (ret)
+		goto out;
 
 	scmd->cmd_len = COMMAND_SIZE(cgc->cmd[0]);
 	memcpy(scmd->cmnd, cgc->cmd, CDROM_PACKET_SIZE);
drivers/nvme/host/core.c +3 -5
index ad2bcb412944..78da9c6cbba8 100644
@@ -1044,11 +1044,9 @@ int __nvme_submit_sync_cmd(struct request *req, union nvme_result *result,
 {
 	int ret;
 
-	if (buffer && bufflen) {
-		ret = blk_rq_map_kern(req->q, req, buffer, bufflen, GFP_KERNEL);
-		if (ret)
-			goto out;
-	}
+	ret = blk_rq_map_kern(req->q, req, buffer, bufflen, GFP_KERNEL);
+	if (ret)
+		goto out;
 
 	ret = nvme_execute_rq(req, at_head);
 	if (result && ret >= 0)
drivers/scsi/scsi_ioctl.c +3 -5
index 1126a265d5ee..1e182d71ce74 100644
@@ -581,11 +581,9 @@ static int sg_scsi_ioctl(struct request_queue *q, fmode_t mode,
 		break;
 	}
 
-	if (bytes) {
-		err = blk_rq_map_kern(q, rq, buffer, bytes, GFP_NOIO);
-		if (err)
-			goto error;
-	}
+	err = blk_rq_map_kern(q, rq, buffer, bytes, GFP_NOIO);
+	if (err)
+		goto error;
 
 	blk_execute_rq(rq, false);
 
drivers/scsi/scsi_lib.c +5 -6
index 9ed1ebcb7443..b15ddf6820a3 100644
@@ -221,12 +221,11 @@ int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
 	if (IS_ERR(req))
 		return PTR_ERR(req);
 
-	if (bufflen) {
-		ret = blk_rq_map_kern(sdev->request_queue, req,
-				      buffer, bufflen, GFP_NOIO);
-		if (ret)
-			goto out;
-	}
+	ret = blk_rq_map_kern(sdev->request_queue, req,
+			buffer, bufflen, GFP_NOIO);
+	if (ret)
+		goto out;
+
 	scmd = blk_mq_rq_to_pdu(req);
 	scmd->cmd_len = COMMAND_SIZE(cmd[0]);
 	memcpy(scmd->cmnd, cmd, scmd->cmd_len);
Signature · 1 line
2.35.3
author maintainer
#7 lore raw

PATCH 3/5 nvme: move result handling into nvme_execute_rq()

In reply to Hannes Reinecke

and simplify the calling convention.

---
 drivers/nvme/host/core.c       | 16 ++++++++++------
 drivers/nvme/host/ioctl.c      |  5 +++--
 drivers/nvme/host/nvme.h       |  3 ++-
 drivers/nvme/target/passthru.c |  3 +--
 4 files changed, 16 insertions(+), 11 deletions(-)
drivers/nvme/host/core.c +10 -6
index 78da9c6cbba8..11faebe87764 100644
@@ -1004,15 +1004,21 @@ EXPORT_SYMBOL_GPL(nvme_setup_cmd);
  * >0: nvme controller's cqe status response
  * <0: kernel error in lieu of controller response
  */
-int nvme_execute_rq(struct request *rq, bool at_head)
+int nvme_execute_rq(struct request *rq, union nvme_result *result,
+		    bool at_head)
 {
 	blk_status_t status;
+	int ret;
 
 	status = blk_execute_rq(rq, at_head);
 	if (nvme_req(rq)->flags & NVME_REQ_CANCELLED)
 		return -EINTR;
-	if (nvme_req(rq)->status)
-		return nvme_req(rq)->status;
+	ret = nvme_req(rq)->status;
+	if (ret) {
+		if (result && ret >= 0)
+			*result = nvme_req(rq)->result;
+		return ret;
+	}
 	return blk_status_to_errno(status);
 }
 EXPORT_SYMBOL_NS_GPL(nvme_execute_rq, NVME_TARGET_PASSTHRU);
@@ -1048,9 +1054,7 @@ int __nvme_submit_sync_cmd(struct request *req, union nvme_result *result,
 	if (ret)
 		goto out;
 
-	ret = nvme_execute_rq(req, at_head);
-	if (result && ret >= 0)
-		*result = nvme_req(req)->result;
+	ret = nvme_execute_rq(req, result, at_head);
  out:
 	blk_mq_free_request(req);
 	return ret;
drivers/nvme/host/ioctl.c +3 -2
index 723e7d5b778f..cdba543cbd02 100644
@@ -220,6 +220,7 @@ static int nvme_submit_user_cmd(struct request_queue *q,
 		u64 *result, unsigned timeout, unsigned int flags)
 {
 	struct nvme_ns *ns = q->queuedata;
+	union nvme_result res;
 	struct nvme_ctrl *ctrl;
 	struct request *req;
 	void *meta = NULL;
@@ -243,9 +244,9 @@ static int nvme_submit_user_cmd(struct request_queue *q,
 	ctrl = nvme_req(req)->ctrl;
 
 	effects = nvme_passthru_start(ctrl, ns, cmd->common.opcode);
-	ret = nvme_execute_rq(req, false);
+	ret = nvme_execute_rq(req, &res, false);
 	if (result)
-		*result = le64_to_cpu(nvme_req(req)->result.u64);
+		*result = le64_to_cpu(res.u64);
 	if (meta)
 		ret = nvme_finish_user_metadata(req, meta_buffer, meta,
 						meta_len, ret);
drivers/nvme/host/nvme.h +2 -1
index 9b4b3bb69e27..a63650b00d1a 100644
@@ -1071,7 +1071,8 @@ static inline void nvme_auth_free(struct nvme_ctrl *ctrl) {};
 u32 nvme_command_effects(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
 			 u8 opcode);
 u32 nvme_passthru_start(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u8 opcode);
-int nvme_execute_rq(struct request *rq, bool at_head);
+int nvme_execute_rq(struct request *rq, union nvme_result *result,
+		    bool at_head);
 void nvme_passthru_end(struct nvme_ctrl *ctrl, u32 effects,
 		       struct nvme_command *cmd, int status);
 struct nvme_ctrl *nvme_ctrl_from_file(struct file *file);
drivers/nvme/target/passthru.c +1 -2
index aae6d5bb4fd8..f5ab4d7a8c1f 100644
@@ -221,7 +221,7 @@ static void nvmet_passthru_execute_cmd_work(struct work_struct *w)
 	int status;
 
 	effects = nvme_passthru_start(ctrl, ns, req->cmd->common.opcode);
-	status = nvme_execute_rq(rq, false);
+	status = nvme_execute_rq(rq, &req->cqe->result, false);
 	if (status == NVME_SC_SUCCESS &&
 	    req->cmd->common.opcode == nvme_admin_identify) {
 		switch (req->cmd->identify.cns) {
@@ -238,7 +238,6 @@ static void nvmet_passthru_execute_cmd_work(struct work_struct *w)
 	} else if (status < 0)
 		status = NVME_SC_INTERNAL;
 
-	req->cqe->result = nvme_req(rq)->result;
 	nvmet_req_complete(req, status);
 	blk_mq_free_request(rq);
 
Signature · 1 line
2.35.3
maintainer
#8 lore raw

Re: [PATCH 3/5] nvme: move result handling into nvme_execute_rq()

Quoted 23 lines · Hannes Reinecke

and simplify the calling convention.

---
  drivers/nvme/host/core.c       | 16 ++++++++++------
  drivers/nvme/host/ioctl.c      |  5 +++--
  drivers/nvme/host/nvme.h       |  3 ++-
  drivers/nvme/target/passthru.c |  3 +--
  4 files changed, 16 insertions(+), 11 deletions(-)
drivers/nvme/host/core.c +2 -1
index 78da9c6cbba8..11faebe87764 100644
@@ -1004,15 +1004,21 @@ EXPORT_SYMBOL_GPL(nvme_setup_cmd);
   * >0: nvme controller's cqe status response
   * <0: kernel error in lieu of controller response
   */
-int nvme_execute_rq(struct request *rq, bool at_head)
+int nvme_execute_rq(struct request *rq, union nvme_result *result,
+		    bool at_head)
  {
  	blk_status_t status;

drivers/nvme/host/core.c EXPORT_SYMBOL_GPL(nvme_setup_cmd); · line 1018

Quoted 10 lines
drivers/nvme/host/core.c +4 -2
+	int ret;
 
  	status = blk_execute_rq(rq, at_head);
  	if (nvme_req(rq)->flags & NVME_REQ_CANCELLED)
  		return -EINTR;
-	if (nvme_req(rq)->status)
-		return nvme_req(rq)->status;
+	ret = nvme_req(rq)->status;
+	if (ret) {
+		if (result && ret >= 0)

How can ret be < 0 here?

Why not always take the result, unconditionally?

Is this really necessary though?

Quoted 76 lines
drivers/nvme/host/core.c +4 -3
+			*result = nvme_req(rq)->result;
+		return ret;
+	}
  	return blk_status_to_errno(status);
  }
  EXPORT_SYMBOL_NS_GPL(nvme_execute_rq, NVME_TARGET_PASSTHRU);
@@ -1048,9 +1054,7 @@ int __nvme_submit_sync_cmd(struct request *req, union nvme_result *result,
  	if (ret)
  		goto out;
 
-	ret = nvme_execute_rq(req, at_head);
-	if (result && ret >= 0)
-		*result = nvme_req(req)->result;
+	ret = nvme_execute_rq(req, result, at_head);
   out:
  	blk_mq_free_request(req);
  	return ret;
drivers/nvme/host/ioctl.c +3 -2
index 723e7d5b778f..cdba543cbd02 100644
@@ -220,6 +220,7 @@ static int nvme_submit_user_cmd(struct request_queue *q,
  		u64 *result, unsigned timeout, unsigned int flags)
  {
  	struct nvme_ns *ns = q->queuedata;
+	union nvme_result res;
  	struct nvme_ctrl *ctrl;
  	struct request *req;
  	void *meta = NULL;
@@ -243,9 +244,9 @@ static int nvme_submit_user_cmd(struct request_queue *q,
  	ctrl = nvme_req(req)->ctrl;
 
  	effects = nvme_passthru_start(ctrl, ns, cmd->common.opcode);
-	ret = nvme_execute_rq(req, false);
+	ret = nvme_execute_rq(req, &res, false);
  	if (result)
-		*result = le64_to_cpu(nvme_req(req)->result.u64);
+		*result = le64_to_cpu(res.u64);
  	if (meta)
  		ret = nvme_finish_user_metadata(req, meta_buffer, meta,
  						meta_len, ret);
drivers/nvme/host/nvme.h +2 -1
index 9b4b3bb69e27..a63650b00d1a 100644
@@ -1071,7 +1071,8 @@ static inline void nvme_auth_free(struct nvme_ctrl *ctrl) {};
  u32 nvme_command_effects(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
  			 u8 opcode);
  u32 nvme_passthru_start(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u8 opcode);
-int nvme_execute_rq(struct request *rq, bool at_head);
+int nvme_execute_rq(struct request *rq, union nvme_result *result,
+		    bool at_head);
  void nvme_passthru_end(struct nvme_ctrl *ctrl, u32 effects,
  		       struct nvme_command *cmd, int status);
  struct nvme_ctrl *nvme_ctrl_from_file(struct file *file);
drivers/nvme/target/passthru.c +1 -2
index aae6d5bb4fd8..f5ab4d7a8c1f 100644
@@ -221,7 +221,7 @@ static void nvmet_passthru_execute_cmd_work(struct work_struct *w)
  	int status;
 
  	effects = nvme_passthru_start(ctrl, ns, req->cmd->common.opcode);
-	status = nvme_execute_rq(rq, false);
+	status = nvme_execute_rq(rq, &req->cqe->result, false);
  	if (status == NVME_SC_SUCCESS &&
  	    req->cmd->common.opcode == nvme_admin_identify) {
  		switch (req->cmd->identify.cns) {
@@ -238,7 +238,6 @@ static void nvmet_passthru_execute_cmd_work(struct work_struct *w)
  	} else if (status < 0)
  		status = NVME_SC_INTERNAL;
 
-	req->cqe->result = nvme_req(rq)->result;
  	nvmet_req_complete(req, status);
  	blk_mq_free_request(rq);
 
author maintainer
#9 lore raw

Re: [PATCH 3/5] nvme: move result handling into nvme_execute_rq()

Quoted 38 lines · Sagi Grimberg
Quoted 22 lines · Hannes Reinecke

and simplify the calling convention.

---
  drivers/nvme/host/core.c       | 16 ++++++++++------ drivers/nvme/host/ioctl.c      |  5 +++-- drivers/nvme/host/nvme.h       |  3 ++- drivers/nvme/target/passthru.c |  3 +--

  4 files changed, 16 insertions(+), 11 deletions(-)
drivers/nvme/host/core.c +2 -1
index 78da9c6cbba8..11faebe87764 100644
@@ -1004,15 +1004,21 @@ EXPORT_SYMBOL_GPL(nvme_setup_cmd);
    * >0: nvme controller's cqe status response
    * <0: kernel error in lieu of controller response
    */
-int nvme_execute_rq(struct request *rq, bool at_head)
+int nvme_execute_rq(struct request *rq, union nvme_result *result,
+            bool at_head)
   {

drivers/nvme/host/core.c EXPORT_SYMBOL_GPL(nvme_setup_cmd); · line 1017

Quoted 10 lines
drivers/nvme/host/core.c +4 -2
       blk_status_t status;
+    int ret;
       status = blk_execute_rq(rq, at_head);
       if (nvme_req(rq)->flags & NVME_REQ_CANCELLED)
           return -EINTR;
-    if (nvme_req(rq)->status)
-        return nvme_req(rq)->status;
+    ret = nvme_req(rq)->status;
+    if (ret) {
+        if (result && ret >= 0)

How can ret be < 0 here?

Quoted 2 lines

Why not always take the result, unconditionally?

Yeah, right. Will be fixing it up.

Quoted 2 lines

Is this really necessary though?

??
Yes, it is necessary to return the status (if there is one). Quite some callers expect that.
And no, it's probably not necessary to check if there is a status; we might always return a status here. But for the result I guess we should be checking the status first; I'm slightly hesitant to blindly return the result even if we have a zero status.

Cheers,

Hannes

maintainer
#10 lore raw

Re: [PATCH 3/5] nvme: move result handling into nvme_execute_rq()

Quoted 45 lines · Hannes Reinecke
Quoted 38 lines · Sagi Grimberg
Quoted 22 lines · Hannes Reinecke

and simplify the calling convention.

---
  drivers/nvme/host/core.c       | 16 ++++++++++------ drivers/nvme/host/ioctl.c      |  5 +++-- drivers/nvme/host/nvme.h       |  3 ++- drivers/nvme/target/passthru.c |  3 +--

  4 files changed, 16 insertions(+), 11 deletions(-)
drivers/nvme/host/core.c +2 -1
index 78da9c6cbba8..11faebe87764 100644
@@ -1004,15 +1004,21 @@ EXPORT_SYMBOL_GPL(nvme_setup_cmd);
    * >0: nvme controller's cqe status response
    * <0: kernel error in lieu of controller response
    */
-int nvme_execute_rq(struct request *rq, bool at_head)
+int nvme_execute_rq(struct request *rq, union nvme_result *result,
+            bool at_head)
   {

drivers/nvme/host/core.c EXPORT_SYMBOL_GPL(nvme_setup_cmd); · line 1017

Quoted 10 lines
drivers/nvme/host/core.c +4 -2
       blk_status_t status;
+    int ret;
       status = blk_execute_rq(rq, at_head);
       if (nvme_req(rq)->flags & NVME_REQ_CANCELLED)
           return -EINTR;
-    if (nvme_req(rq)->status)
-        return nvme_req(rq)->status;
+    ret = nvme_req(rq)->status;
+    if (ret) {
+        if (result && ret >= 0)

How can ret be < 0 here?

Quoted 2 lines

Why not always take the result, unconditionally?

Yeah, right. Will be fixing it up.

Quoted 2 lines

Is this really necessary though?

Quoted 7 lines

??
Yes, it is necessary to return the status (if there is one). Quite some callers expect that.
And no, it's probably not necessary to check if there is a status; we might always return a status here. But for the result I guess we should be checking the status first; I'm slightly hesitant to blindly return the result even if we have a zero status.

I meant the simplification altogether. it really forces callers to send a nvme_result (or NULL) and convert back. Didn't see that it dramatically simplifies the code.

author maintainer
#11 lore raw

PATCH 4/5 nvme: open-code __nvme_submit_sync_cmd()

In reply to Hannes Reinecke

The argument list for __nvme_submit_sync_cmd() really got overloaded trying to abstract away the various use-cases. Plus it's a really simple function now, so open-code it in the callers and drop this function.

---
 drivers/nvme/host/auth.c    | 22 ++++++++++----
 drivers/nvme/host/core.c    | 42 ++++++++++++++-------------
 drivers/nvme/host/fabrics.c | 58 +++++++++++++++++++++++--------------
 drivers/nvme/host/nvme.h    |  2 --
 4 files changed, 74 insertions(+), 50 deletions(-)
drivers/nvme/host/auth.c +16 -6
index 05d02ab229f7..ef5dcd885b0c 100644
@@ -81,13 +81,23 @@ static int nvme_auth_submit(struct nvme_ctrl *ctrl, int qid,
 	if (IS_ERR(req))
 		return PTR_ERR(req);
 
-	ret = __nvme_submit_sync_cmd(req, NULL, data, data_len, 0);
-	if (ret > 0)
-		dev_warn(ctrl->device,
-			"qid %d auth_send failed with status %d\n", qid, ret);
-	else if (ret < 0)
+	ret = blk_rq_map_kern(req->q, req, data, data_len, GFP_KERNEL);
+	if (ret) {
 		dev_err(ctrl->device,
-			"qid %d auth_send failed with error %d\n", qid, ret);
+			"qid %d auth_submit failed to map, error %d\n",
+			qid, ret);
+	} else {
+		ret = nvme_execute_rq(req, NULL, false);
+		if (ret > 0)
+			dev_warn(ctrl->device,
+				 "qid %d auth_submit failed with status %d\n",
+				 qid, ret);
+		else if (ret < 0)
+			dev_err(ctrl->device,
+				"qid %d auth_submit failed with error %d\n",
+				qid, ret);
+	}
+	blk_mq_free_request(req);
 	return ret;
 }
 
drivers/nvme/host/core.c +22 -20

81 lines not on this page · raw message

drivers/nvme/host/fabrics.c +36 -22

112 lines not on this page · raw message

drivers/nvme/host/nvme.h +0 -2
index a63650b00d1a..8f02d981644c 100644
@@ -815,8 +815,6 @@ int nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
 		void *buf, unsigned bufflen);
 struct request *nvme_alloc_request(struct request_queue *q,
 		struct nvme_command *cmd, int qid, blk_mq_req_flags_t flags);
-int __nvme_submit_sync_cmd(struct request *req, union nvme_result *result,
-		void *buffer, unsigned bufflen, int at_head);
 int nvme_set_features(struct nvme_ctrl *dev, unsigned int fid,
 		      unsigned int dword11, void *buffer, size_t buflen,
 		      u32 *result);
Signature · 1 line
2.35.3
#12 lore raw

Re: [PATCH 4/5] nvme: open-code __nvme_submit_sync_cmd()

drivers/nvme/host/auth.c static int nvme_auth_submit(struct nvme_ctrl *ctrl, int qid, · line 88

Quoted 5 lines · Hannes Reinecke
drivers/nvme/host/auth.c +3 -1
+	if (ret) {
 		dev_err(ctrl->device,
-			"qid %d auth_send failed with error %d\n", qid, ret);
+			"qid %d auth_submit failed to map, error %d\n",
+			qid, ret);

Plase do a goto out_free_request here instead of indenting the normal flow in the else path. The same comment applies in a bunch of other places.

drivers/nvme/host/core.c static int nvme_features(struct nvme_ctrl *dev, u8 op, unsigned int fid, · line 1497

Quoted 6 lines
drivers/nvme/host/core.c +5 -1
-	ret = __nvme_submit_sync_cmd(req, &res, buffer, buflen, 0);
+	ret = blk_rq_map_kern(req->q, req, buffer, buflen, GFP_KERNEL);
+	if (ret)
+		goto out;
+
+	ret = nvme_execute_rq(req, &res, false);

This could use nvmf_submit_fabrics_cmd, which has nothing to with fabrics, but just is a variant of nvme_submit_sync_cmd that returns the result. So if we have that helper anyway we might as well move it to the core and turn nvme_submit_sync_cmd into a wrapper for it.

maintainer
#13 lore raw

Re: [PATCH 4/5] nvme: open-code __nvme_submit_sync_cmd()

Quoted 11 lines

drivers/nvme/host/core.c static int nvme_features(struct nvme_ctrl *dev, u8 op, unsigned int fid, · line 1497

Quoted 7 lines
drivers/nvme/host/core.c +5 -1
-	ret = __nvme_submit_sync_cmd(req, &res, buffer, buflen, 0);
+	ret = blk_rq_map_kern(req->q, req, buffer, buflen, GFP_KERNEL);
+	if (ret)
+		goto out;
+
+	ret = nvme_execute_rq(req, &res, false);

This could use nvmf_submit_fabrics_cmd, which has nothing to with fabrics, but just is a variant of nvme_submit_sync_cmd that returns the result.

I think that the distinction is that it operates on the fabrics request queue as well.

Quoted 2 lines

So if we have that helper anyway we might as well move it to
the core and turn nvme_submit_sync_cmd into a wrapper for it.

I was thinking the other way around, nvmf_submit_fabrics_cmd wraps nvme_submit_sync_cmd with ctrl->fabrics_q, and we can add

author maintainer
#14 lore raw

PATCH 5/5 nvme: retry authentication commands if DNR status bit is not set

In reply to Hannes Reinecke

Clear the FAILFAST_DRIVER bit for authentication commands allowing them to be retried in nvme_decide_disposition() if the DNR bit is not set in the command result.

---
 drivers/nvme/host/auth.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/nvme/host/auth.c +2 -0
index ef5dcd885b0c..935f340607a7 100644
@@ -87,6 +87,8 @@ static int nvme_auth_submit(struct nvme_ctrl *ctrl, int qid,
 			"qid %d auth_submit failed to map, error %d\n",
 			qid, ret);
 	} else {
+		/* Clear failfast flag to allow for retries */
+		req->cmd_flags &= ~REQ_FAILFAST_DRIVER;
 		ret = nvme_execute_rq(req, NULL, false);
 		if (ret > 0)
 			dev_warn(ctrl->device,
Signature · 1 line
2.35.3
maintainer
#15 lore raw

Re: [PATCH 5/5] nvme: retry authentication commands if DNR status bit is not set

Quoted 3 lines

Clear the FAILFAST_DRIVER bit for authentication commands allowing them to be retried in nvme_decide_disposition() if the DNR bit is not set in the command result.

Can you please explain what is this fixing? and is there a test to reproduce this?

Quoted 11 lines
---
  drivers/nvme/host/auth.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/nvme/host/auth.c +0 -0
index ef5dcd885b0c..935f340607a7 100644

drivers/nvme/host/auth.c static int nvme_auth_submit(struct nvme_ctrl *ctrl, int qid, · line 91

Quoted 5 lines
drivers/nvme/host/auth.c +2 -0
@@ -87,6 +87,8 @@ static int nvme_auth_submit(struct nvme_ctrl *ctrl, int qid,
  			"qid %d auth_submit failed to map, error %d\n",
  			qid, ret);
  	} else {
+		/* Clear failfast flag to allow for retries */
+		req->cmd_flags &= ~REQ_FAILFAST_DRIVER;

This should come right after the allocation.
But what makes this special than any other fabrics/admin command? Why is it different than connect for example?

author maintainer
#16 lore raw

Re: [PATCH 5/5] nvme: retry authentication commands if DNR status bit is not set

Quoted 13 lines · Sagi Grimberg
Quoted 3 lines

Clear the FAILFAST_DRIVER bit for authentication commands allowing them to be retried in nvme_decide_disposition() if the DNR bit is not set in the command result.

Can you please explain what is this fixing? and is there a test to reproduce this?

Quoted 6 lines

---
  drivers/nvme/host/auth.c | 2 ++

  1 file changed, 2 insertions(+)
Quoted 15 lines

drivers/nvme/host/auth.c static int nvme_auth_submit(struct nvme_ctrl *ctrl, · line 92

Quoted 11 lines
drivers/nvme/host/auth.c +2 -0
index ef5dcd885b0c..935f340607a7 100644
@@ -87,6 +87,8 @@ static int nvme_auth_submit(struct nvme_ctrl *ctrl, 
 int qid,
               "qid %d auth_submit failed to map, error %d\n",
               qid, ret);
       } else {
+        /* Clear failfast flag to allow for retries */
+        req->cmd_flags &= ~REQ_FAILFAST_DRIVER;

This should come right after the allocation.
But what makes this special than any other fabrics/admin command? Why is it different than connect for example?

It is not different; it does, however, introduce a difference in behaviour.
And hence I didn't enable it for all commands, as previously we didn't retry, and it's questionable if we should for things like 'reg_read'/'reg_write' and friends.

But you are correct for connect, though; we really should retry that one, too, if the DNR bit is not set.

Cheers,

Hannes

maintainer
#17 lore raw

Re: [PATCH 5/5] nvme: retry authentication commands if DNR status bit is not set

Quoted 30 lines
Quoted 14 lines
Quoted 4 lines

Clear the FAILFAST_DRIVER bit for authentication commands allowing them to be retried in nvme_decide_disposition() if the DNR bit is not set in the command result.

Can you please explain what is this fixing? and is there a test to reproduce this?

Quoted 6 lines

---
  drivers/nvme/host/auth.c | 2 ++

  1 file changed, 2 insertions(+)
Quoted 15 lines

drivers/nvme/host/auth.c static int nvme_auth_submit(struct nvme_ctrl *ctrl, · line 92

Quoted 11 lines
drivers/nvme/host/auth.c +2 -0
index ef5dcd885b0c..935f340607a7 100644
@@ -87,6 +87,8 @@ static int nvme_auth_submit(struct nvme_ctrl *ctrl, 
 int qid,
               "qid %d auth_submit failed to map, error %d\n",
               qid, ret);
       } else {
+        /* Clear failfast flag to allow for retries */
+        req->cmd_flags &= ~REQ_FAILFAST_DRIVER;

This should come right after the allocation.
But what makes this special than any other fabrics/admin command? Why is it different than connect for example?

Quoted 4 lines

It is not different; it does, however, introduce a difference in behaviour.
And hence I didn't enable it for all commands, as previously we didn't retry, and it's questionable if we should for things like 'reg_read'/'reg_write' and friends.

But you are correct for connect, though; we really should retry that one, too, if the DNR bit is not set.

I'm not sure. if the transport is unavailable, we cannot set DNR, which will lead to a retry of the connect (or equivalent) command. Today the host will schedule another full controller connect within reconnect_delay, which is what we want right?

author maintainer
#18 lore raw

Re: [PATCH 5/5] nvme: retry authentication commands if DNR status bit is not set

Quoted 33 lines · Sagi Grimberg
Quoted 33 lines
Quoted 14 lines
Quoted 4 lines

Clear the FAILFAST_DRIVER bit for authentication commands allowing them to be retried in nvme_decide_disposition() if the DNR bit is not set in the command result.

Can you please explain what is this fixing? and is there a test to reproduce this?

Quoted 6 lines

---
  drivers/nvme/host/auth.c | 2 ++

  1 file changed, 2 insertions(+)
Quoted 15 lines

drivers/nvme/host/auth.c static int nvme_auth_submit(struct nvme_ctrl · line 92

Quoted 11 lines
drivers/nvme/host/auth.c +2 -0
index ef5dcd885b0c..935f340607a7 100644
@@ -87,6 +87,8 @@ static int nvme_auth_submit(struct nvme_ctrl 
 *ctrl, int qid,
               "qid %d auth_submit failed to map, error %d\n",
               qid, ret);
       } else {
+        /* Clear failfast flag to allow for retries */
+        req->cmd_flags &= ~REQ_FAILFAST_DRIVER;

This should come right after the allocation.
But what makes this special than any other fabrics/admin command? Why is it different than connect for example?

It is not different; it does, however, introduce a difference in behaviour.
And hence I didn't enable it for all commands, as previously we didn't retry, and it's questionable if we should for things like 'reg_read'/'reg_write' and friends.

Quoted 6 lines
Quoted 1 line

But you are correct for connect, though; we really should retry that one, too, if the DNR bit is not set.

I'm not sure. if the transport is unavailable, we cannot set DNR, which will lead to a retry of the connect (or equivalent) command. Today the host will schedule another full controller connect within reconnect_delay, which is what we want right?

I knew this would be coming up, which is why I left it out of the initial patchset.

Long explanation:

Thing is, connect handling is not _just_ connect handling.
With linux we only have a single (ioctl-like) entry for the userspace 'nvme connect' call.

That really does several things:
- Setting up the transport
- Create the transport association for the admin q
- Create the admin q
- send 'connect' over that queue
- Create transport associations for the i/o qs
- create i/o qs
- send 'connect' over those queues

And my point here is that the actual 'connect' commands really are straight NVMe commands. And as such should be subjected to the normal status evaluation rules for NVMe commands. The problem here is the strange 'half-breed' nature of the connect command:

_Technically_ the association and the 'connect' command are independent, and as such we would be entirely within spec to allow the 'connect' command to fail without having the association torn down. But due to
our implementation that would leave us unable to re-use the association
for further connect commands, as that would need to be triggered by
userspace (which will always create a new association).

Consequently I would advocate for having any non-retryable failure of the 'connect' command to always tear down the association, too.

That would be a deviation from our normal rules (where we always retry
transport failures), but really is something we need to do if we enable DNR evaluation for the 'connect' command.

And we would need an agreement on this, hence I didn't attempt it in this patchset.

(Actually I'm wondering if it's worth a session at LSF; this has been a long-running topic without us being able to make meaningful progress)

Cheers,

Hannes

maintainer
#19 lore raw

Re: [PATCH 5/5] nvme: retry authentication commands if DNR status bit is not set

Quoted 65 lines
Quoted 33 lines
Quoted 33 lines
Quoted 14 lines
Quoted 4 lines

Clear the FAILFAST_DRIVER bit for authentication commands allowing them to be retried in nvme_decide_disposition() if the DNR bit is not set in the command result.

Can you please explain what is this fixing? and is there a test to reproduce this?

Quoted 6 lines

---
  drivers/nvme/host/auth.c | 2 ++

  1 file changed, 2 insertions(+)
Quoted 15 lines

drivers/nvme/host/auth.c static int nvme_auth_submit(struct nvme_ctrl · line 92

Quoted 11 lines
drivers/nvme/host/auth.c +2 -0
index ef5dcd885b0c..935f340607a7 100644
@@ -87,6 +87,8 @@ static int nvme_auth_submit(struct nvme_ctrl 
 *ctrl, int qid,
               "qid %d auth_submit failed to map, error %d\n",
               qid, ret);
       } else {
+        /* Clear failfast flag to allow for retries */
+        req->cmd_flags &= ~REQ_FAILFAST_DRIVER;

This should come right after the allocation.
But what makes this special than any other fabrics/admin command? Why is it different than connect for example?

It is not different; it does, however, introduce a difference in behaviour.
And hence I didn't enable it for all commands, as previously we didn't retry, and it's questionable if we should for things like 'reg_read'/'reg_write' and friends.

Quoted 6 lines
Quoted 1 line

But you are correct for connect, though; we really should retry that one, too, if the DNR bit is not set.

I'm not sure. if the transport is unavailable, we cannot set DNR, which will lead to a retry of the connect (or equivalent) command. Today the host will schedule another full controller connect within reconnect_delay, which is what we want right?

I knew this would be coming up, which is why I left it out of the initial patchset.

Long explanation:

Thing is, connect handling is not _just_ connect handling.
With linux we only have a single (ioctl-like) entry for the userspace 'nvme connect' call.

That really does several things:
- Setting up the transport
- Create the transport association for the admin q
- Create the admin q
- send 'connect' over that queue
- Create transport associations for the i/o qs
- create i/o qs
- send 'connect' over those queues

And my point here is that the actual 'connect' commands really are straight NVMe commands. And as such should be subjected to the normal status evaluation rules for NVMe commands. The problem here is the strange 'half-breed' nature of the connect command:

_Technically_ the association and the 'connect' command are independent, and as such we would be entirely within spec to allow the 'connect' command to fail without having the association torn down. But due to
our implementation that would leave us unable to re-use the association
for further connect commands, as that would need to be triggered by
userspace (which will always create a new association).

Quoted 4 lines

Consequently I would advocate for having any non-retryable failure of the 'connect' command to always tear down the association, too.

That would be a deviation from our normal rules (where we always retry
transport failures), but really is something we need to do if we enable DNR evaluation for the 'connect' command.

How the host handles connect or any other request failing is entirely the host choice.

In this patch, you decided to effectively to retry for transport errors, which will effectively retry nvme_max_retries times. Can you please help me understand what is the patch actually solving? I'm assuming that this is an actual completion that you see from the controller, my second question is what happens with this patch when the transport is the source of the completion?

Once we understand this, we can discuss any difference between auth and other driver generated commands.

author maintainer
#20 lore raw

Re: [PATCH 5/5] nvme: retry authentication commands if DNR status bit is not set

Quoted 73 lines · Sagi Grimberg
Quoted 65 lines
Quoted 33 lines
Quoted 33 lines
Quoted 14 lines
Quoted 4 lines

Clear the FAILFAST_DRIVER bit for authentication commands allowing them to be retried in nvme_decide_disposition() if the DNR bit is not set in the command result.

Can you please explain what is this fixing? and is there a test to reproduce this?

Quoted 6 lines

---
  drivers/nvme/host/auth.c | 2 ++

  1 file changed, 2 insertions(+)
Quoted 15 lines

drivers/nvme/host/auth.c static int nvme_auth_submit(struct nvme_ctrl · line 92

Quoted 11 lines
drivers/nvme/host/auth.c +2 -0
index ef5dcd885b0c..935f340607a7 100644
@@ -87,6 +87,8 @@ static int nvme_auth_submit(struct nvme_ctrl 
 *ctrl, int qid,
               "qid %d auth_submit failed to map, error %d\n",
               qid, ret);
       } else {
+        /* Clear failfast flag to allow for retries */
+        req->cmd_flags &= ~REQ_FAILFAST_DRIVER;

This should come right after the allocation.
But what makes this special than any other fabrics/admin command? Why is it different than connect for example?

It is not different; it does, however, introduce a difference in behaviour.
And hence I didn't enable it for all commands, as previously we didn't retry, and it's questionable if we should for things like 'reg_read'/'reg_write' and friends.

Quoted 6 lines
Quoted 1 line

But you are correct for connect, though; we really should retry that one, too, if the DNR bit is not set.

I'm not sure. if the transport is unavailable, we cannot set DNR, which will lead to a retry of the connect (or equivalent) command. Today the host will schedule another full controller connect within reconnect_delay, which is what we want right?

I knew this would be coming up, which is why I left it out of the initial patchset.

Long explanation:

Thing is, connect handling is not _just_ connect handling.
With linux we only have a single (ioctl-like) entry for the userspace 'nvme connect' call.

That really does several things:
- Setting up the transport
- Create the transport association for the admin q
- Create the admin q
- send 'connect' over that queue
- Create transport associations for the i/o qs
- create i/o qs
- send 'connect' over those queues

And my point here is that the actual 'connect' commands really are straight NVMe commands. And as such should be subjected to the normal status evaluation rules for NVMe commands. The problem here is the strange 'half-breed' nature of the connect command:

_Technically_ the association and the 'connect' command are independent, and as such we would be entirely within spec to allow the 'connect' command to fail without having the association torn down. But due to
our implementation that would leave us unable to re-use the association
for further connect commands, as that would need to be triggered by
userspace (which will always create a new association).

Quoted 4 lines

Consequently I would advocate for having any non-retryable failure of the 'connect' command to always tear down the association, too.

That would be a deviation from our normal rules (where we always retry
transport failures), but really is something we need to do if we enable DNR evaluation for the 'connect' command.

How the host handles connect or any other request failing is entirely the host choice.

Quoted 7 lines

In this patch, you decided to effectively to retry for transport errors, which will effectively retry nvme_max_retries times. Can you please help me understand what is the patch actually solving? I'm assuming that this is an actual completion that you see from the controller, my second question is what happens with this patch when the transport is the source of the completion?

Hmm. All what this patch does is to enable retries by modifying the flow in nvme_decide_disposition(). And nvme_decide_disposition() only deals with NVMe errors; if
nvme_req(req)->status would be an error number we'd be in much worse problems than just retries.

So where do you see the transport errors being retried?

And I need to retry as some controller implementations temporarily return the authentication commands with the 'DNR' bit set, presumeably to initialize the authentication subsystem.

Cheers,

Hannes

maintainer
#21 lore raw

Re: [PATCH 5/5] nvme: retry authentication commands if DNR status bit is not set

Quoted 80 lines
Quoted 73 lines
Quoted 65 lines
Quoted 33 lines
Quoted 33 lines
Quoted 14 lines
Quoted 4 lines

Clear the FAILFAST_DRIVER bit for authentication commands allowing them to be retried in nvme_decide_disposition() if the DNR bit is not set in the command result.

Can you please explain what is this fixing? and is there a test to reproduce this?

Quoted 6 lines

---
  drivers/nvme/host/auth.c | 2 ++

  1 file changed, 2 insertions(+)
Quoted 15 lines

drivers/nvme/host/auth.c static int nvme_auth_submit(struct nvme_ctrl · line 92

Quoted 11 lines
drivers/nvme/host/auth.c +2 -0
index ef5dcd885b0c..935f340607a7 100644
@@ -87,6 +87,8 @@ static int nvme_auth_submit(struct nvme_ctrl 
 *ctrl, int qid,
               "qid %d auth_submit failed to map, error %d\n",
               qid, ret);
       } else {
+        /* Clear failfast flag to allow for retries */
+        req->cmd_flags &= ~REQ_FAILFAST_DRIVER;

This should come right after the allocation.
But what makes this special than any other fabrics/admin command? Why is it different than connect for example?

It is not different; it does, however, introduce a difference in behaviour.
And hence I didn't enable it for all commands, as previously we didn't retry, and it's questionable if we should for things like 'reg_read'/'reg_write' and friends.

Quoted 6 lines
Quoted 1 line

But you are correct for connect, though; we really should retry that one, too, if the DNR bit is not set.

I'm not sure. if the transport is unavailable, we cannot set DNR, which will lead to a retry of the connect (or equivalent) command. Today the host will schedule another full controller connect within reconnect_delay, which is what we want right?

I knew this would be coming up, which is why I left it out of the initial patchset.

Long explanation:

Thing is, connect handling is not _just_ connect handling.
With linux we only have a single (ioctl-like) entry for the userspace 'nvme connect' call.

That really does several things:
- Setting up the transport
- Create the transport association for the admin q
- Create the admin q
- send 'connect' over that queue
- Create transport associations for the i/o qs
- create i/o qs
- send 'connect' over those queues

And my point here is that the actual 'connect' commands really are straight NVMe commands. And as such should be subjected to the normal status evaluation rules for NVMe commands. The problem here is the strange 'half-breed' nature of the connect command:

_Technically_ the association and the 'connect' command are independent, and as such we would be entirely within spec to allow the 'connect' command to fail without having the association torn down. But due to
our implementation that would leave us unable to re-use the association
for further connect commands, as that would need to be triggered by
userspace (which will always create a new association).

Quoted 4 lines

Consequently I would advocate for having any non-retryable failure of the 'connect' command to always tear down the association, too.

That would be a deviation from our normal rules (where we always retry
transport failures), but really is something we need to do if we enable DNR evaluation for the 'connect' command.

How the host handles connect or any other request failing is entirely the host choice.

Quoted 7 lines

In this patch, you decided to effectively to retry for transport errors, which will effectively retry nvme_max_retries times. Can you please help me understand what is the patch actually solving? I'm assuming that this is an actual completion that you see from the controller, my second question is what happens with this patch when the transport is the source of the completion?

Quoted 3 lines

Hmm. All what this patch does is to enable retries by modifying the flow in nvme_decide_disposition(). And nvme_decide_disposition() only deals with NVMe errors; if
nvme_req(req)->status would be an error number we'd be in much worse problems than just retries.

Hannes, can you please describe the flow that went wrong here and you attempted to fix?

My assumption is that the host got a non-zero nvme status with DNR cleared. Is that correct? This is not described in the commit msg, hence me asking.

Quoted 1 line

So where do you see the transport errors being retried?

Effectively, all transport errors do not set the DNR bit, and will be retried within crdt, until nvme_max_retries is reached. My question is weather this affects the reconnect flow given that we go and cancel all inflight requests (NVME_SC_HOST_ABORTED_CMD). Does this mean that if now the auth is inflight, it will retry? causing the teardown to block?

Same question applies to other driver requests that you say that should comply to the DNR bit.

Quoted 1 line

And I need to retry as some controller implementations temporarily return the authentication commands with the 'DNR' bit set, presumeably to initialize the authentication subsystem.

That is unrelated to this patch set though.