Skip to contentSkip to conversation

nvme: Return BLK_STS_TARGET if the DNR bit is set

PATCH Mike Snitzer 2 participants 6 messages Apr 15, 2021 – Apr 16, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

BZ: 1948690
Upstream Status: RHEL-only

rhel-8.git commit ef4ab90c12db5e0e50800ec323736b95be7a6ff5

Author: Mike Snitzer <[email protected]>
Date:   Tue Aug 25 21:52:45 2020 -0400

[nvme] nvme: Return BLK_STS_TARGET if the DNR bit is set

Message-id: <[email protected]>
Patchwork-id: 325178
Patchwork-instance: patchwork
O-Subject: [RHEL8.3 PATCH 07/10] nvme: Return BLK_STS_TARGET if the DNR bit is set
Bugzilla: 1843515

BZ: 1843515
Upstream Status: RHEL-only

If the DNR bit is set we should not retry the command, even if the standard status evaluation indicates so.

SUSE is carrying this patch in their kernel:
https://lwn.net/Articles/800370/

Based on patch posted for upstream inclusion but rejected:
v1: https://lore.kernel.org/linux-nvme/[email protected]/
v2: https://lore.kernel.org/linux-nvme/[email protected]/
v2-keith: https://lore.kernel.org/linux-nvme/[email protected]/
v3: https://lore.kernel.org/linux-nvme/[email protected]/
v3-keith: https://lore.kernel.org/linux-nvme/[email protected]/

This commit's change is basically "v3-keith".

---
 drivers/nvme/host/core.c |    3 +++
 1 file changed, 3 insertions(+)
drivers/nvme/host/core.c +3 -0
Index: linux-rhel9/drivers/nvme/host/core.c
===================================================================
@@ -237,6 +237,9 @@ static void nvme_delete_ctrl_sync(struct
 
 static blk_status_t nvme_error_status(u16 status)
 {
+	if (unlikely(status & NVME_SC_DNR))
+		return BLK_STS_TARGET;
+
 	switch (status & 0x7ff) {
 	case NVME_SC_SUCCESS:
 		return BLK_STS_OK;
#1 lore raw

nvme: update failover handling to work with REQ_FAILFAST_TRANSPORT

BZ: 1948690
Upstream Status: RHEL-only

rhel-8.git commit f8fb6ea1226e2abc525c88da13b346118d548eea

Author: Mike Snitzer <[email protected]>
Date:   Tue Aug 25 21:52:46 2020 -0400

[nvme] nvme: update failover handling to work with REQ_FAILFAST_TRANSPORT

Message-id: <[email protected]>
Patchwork-id: 325177
Patchwork-instance: patchwork
O-Subject: [RHEL8.3 PATCH 08/10] nvme: update failover handling to work with REQ_FAILFAST_TRANSPORT
Bugzilla: 1843515

BZ: 1843515
Upstream Status: RHEL-only

If REQ_FAILFAST_TRANSPORT is set it means the driver should not retry IO that completed with transport errors. REQ_FAILFAST_TRANSPORT is set by multipathing software (e.g. dm-multipath) before it issues IO. Update NVMe to prepare for failover of requests marked with either REQ_NVME_MPATH or REQ_FAILFAST_TRANSPORT. This allows such requests to be given a disposition of FAILOVER.

Introduce nvme_end_req_with_failover() for use in nvme_complete_rq() if REQ_NVME_MPATH isn't set. nvme_end_req_with_failover() ensures request is completed with a retryable IO error when appropriate. __nvme_end_req() was factored out for use by both nvme_end_req() and nvme_end_req_with_failover().

---
 drivers/nvme/host/core.c |   33 ++++++++++++++++++++++++++++-----
 1 file changed, 28 insertions(+), 5 deletions(-)
drivers/nvme/host/core.c +28 -5
Index: linux-rhel9/drivers/nvme/host/core.c
===================================================================
@@ -311,7 +311,7 @@ static inline enum nvme_disposition nvme
 	    nvme_req(req)->retries >= nvme_max_retries)
 		return COMPLETE;
 
-	if (req->cmd_flags & REQ_NVME_MPATH) {
+	if (req->cmd_flags & (REQ_NVME_MPATH | REQ_FAILFAST_TRANSPORT)) {
 		if (nvme_is_path_error(nvme_req(req)->status) ||
 		    blk_queue_dying(req->q))
 			return FAILOVER;
@@ -323,10 +323,8 @@ static inline enum nvme_disposition nvme
 	return RETRY;
 }
 
-static inline void nvme_end_req(struct request *req)
+static inline void __nvme_end_req(struct request *req, blk_status_t status)
 {
-	blk_status_t status = nvme_error_status(nvme_req(req)->status);
-
 	if (IS_ENABLED(CONFIG_BLK_DEV_ZONED) &&
 	    req_op(req) == REQ_OP_ZONE_APPEND)
 		req->__sector = nvme_lba_to_sect(req->q->queuedata,
@@ -336,6 +334,28 @@ static inline void nvme_end_req(struct r
 	blk_mq_end_request(req, status);
 }
 
+static inline void nvme_end_req(struct request *req)
+{
+	__nvme_end_req(req, nvme_error_status(nvme_req(req)->status));
+}
+
+static inline void nvme_end_req_with_failover(struct request *req)
+{
+	u16 nvme_status = nvme_req(req)->status;
+	blk_status_t status = nvme_error_status(nvme_status);
+
+	if (unlikely(nvme_status & NVME_SC_DNR))
+		goto out;
+
+	if (!blk_path_error(status)) {
+		pr_debug("Request meant for failover but blk_status_t (errno=%d) was not retryable.\n",
+			 blk_status_to_errno(status));
+		status = BLK_STS_IOERR;
+	}
+out:
+	__nvme_end_req(req, status);
+}
+
 void nvme_complete_rq(struct request *req)
 {
 	trace_nvme_complete_rq(req);
@@ -352,7 +372,10 @@ void nvme_complete_rq(struct request *re
 		nvme_retry_req(req);
 		return;
 	case FAILOVER:
-		nvme_failover_req(req);
+		if (req->cmd_flags & REQ_NVME_MPATH)
+			nvme_failover_req(req);
+		else
+			nvme_end_req_with_failover(req);
 		return;
 	}
 }
#2 lore raw

nvme: decouple basic ANA log page re-read support from native multipathing

In reply to Mike Snitzer

BZ: 1948690
Upstream Status: RHEL-only

rhel-8.git commit b904f4b8e0f90613bf1b2b9d9ccad3c015741daf

Author: Mike Snitzer <[email protected]>
Date:   Tue Aug 25 21:52:47 2020 -0400

[nvme] nvme: decouple basic ANA log page re-read support from native multipathing

Message-id: <[email protected]>
Patchwork-id: 325179
Patchwork-instance: patchwork
O-Subject: [RHEL8.3 PATCH 09/10] nvme: decouple basic ANA log page re-read support from native multipathing
Bugzilla: 1843515

BZ: 1843515
Upstream Status: RHEL-only

Whether or not ANA is present is a choice of the target implementation; the host (and whether it supports multipathing) has _zero_ influence on this. If the target declares a path as 'inaccessible' the path _is_ inaccessible to the host. As such, ANA support should be functional even if native multipathing is not.

Introduce ability to always re-read ANA log page as required due to ANA error and make current ANA state available via sysfs -- even if native multipathing is disabled on the host (e.g. nvme_core.multipath=N).

This affords userspace access to the current ANA state independent of which layer might be doing multipathing. It also allows multipath-tools to rely on the NVMe driver for ANA support while dm-multipath takes care of multipathing.

And as always, if embedded NVMe users do not want any performance overhead associated with ANA or native NVMe multipathing they can disable CONFIG_NVME_MULTIPATH.

---
 drivers/nvme/host/core.c      |    2 ++
 drivers/nvme/host/multipath.c |   23 ++++++++++++++++++-----
 drivers/nvme/host/nvme.h      |    4 ++++
 3 files changed, 24 insertions(+), 5 deletions(-)
drivers/nvme/host/core.c +2 -0
Index: linux-rhel9/drivers/nvme/host/core.c
===================================================================
@@ -347,6 +347,8 @@ static inline void nvme_end_req_with_fai
 	if (unlikely(nvme_status & NVME_SC_DNR))
 		goto out;
 
+	nvme_update_ana(req);
+
 	if (!blk_path_error(status)) {
 		pr_debug("Request meant for failover but blk_status_t (errno=%d) was not retryable.\n",
 			 blk_status_to_errno(status));
drivers/nvme/host/multipath.c +18 -5
Index: linux-rhel9/drivers/nvme/host/multipath.c
===================================================================
@@ -65,10 +65,25 @@ void nvme_set_disk_name(char *disk_name,
 	}
 }
 
+static inline void __nvme_update_ana(struct nvme_ns *ns)
+{
+	if (!ns->ctrl->ana_log_buf)
+		return;
+
+	set_bit(NVME_NS_ANA_PENDING, &ns->flags);
+	queue_work(nvme_wq, &ns->ctrl->ana_work);
+}
+
+
+void nvme_update_ana(struct request *req)
+{
+	if (nvme_is_ana_error(nvme_req(req)->status))
+		__nvme_update_ana(req->q->queuedata);
+}
+
 void nvme_failover_req(struct request *req)
 {
 	struct nvme_ns *ns = req->q->queuedata;
-	u16 status = nvme_req(req)->status & 0x7ff;
 	unsigned long flags;
 
 	nvme_mpath_clear_current_path(ns);
@@ -78,10 +93,8 @@ void nvme_failover_req(struct request *r
 	 * ready to serve this namespace.  Kick of a re-read of the ANA
 	 * information page, and just try any other available path for now.
 	 */
-	if (nvme_is_ana_error(status) && ns->ctrl->ana_log_buf) {
-		set_bit(NVME_NS_ANA_PENDING, &ns->flags);
-		queue_work(nvme_wq, &ns->ctrl->ana_work);
-	}
+	if (nvme_is_ana_error(nvme_req(req)->status))
+		__nvme_update_ana(ns);
 
 	spin_lock_irqsave(&ns->head->requeue_lock, flags);
 	blk_steal_bios(&ns->head->requeue_list, req);
drivers/nvme/host/nvme.h +4 -0
Index: linux-rhel9/drivers/nvme/host/nvme.h
===================================================================
@@ -664,6 +664,7 @@ void nvme_mpath_start_freeze(struct nvme
 void nvme_set_disk_name(char *disk_name, struct nvme_ns *ns,
 			struct nvme_ctrl *ctrl, int *flags);
 void nvme_failover_req(struct request *req);
+void nvme_update_ana(struct request *req);
 void nvme_kick_requeue_lists(struct nvme_ctrl *ctrl);
 int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl,struct nvme_ns_head *head);
 void nvme_mpath_add_disk(struct nvme_ns *ns, struct nvme_id_ns *id);
@@ -714,6 +715,9 @@ static inline void nvme_set_disk_name(ch
 static inline void nvme_failover_req(struct request *req)
 {
 }
+static inline void nvme_update_ana(struct request *req)
+{
+}
 static inline void nvme_kick_requeue_lists(struct nvme_ctrl *ctrl)
 {
 }
#3 lore raw

nvme: allow retry for requests with REQ_FAILFAST_TRANSPORT set

In reply to Mike Snitzer

BZ: 1948690
Upstream Status: RHEL-only

rhel-8.git commit 7dadadb072515f243868e6fe2f7e9c97fd3516c9

Author: Mike Snitzer <[email protected]>
Date:   Tue Aug 25 21:52:48 2020 -0400

[nvme] nvme: allow retry for requests with REQ_FAILFAST_TRANSPORT set

Message-id: <[email protected]>
Patchwork-id: 325180
Patchwork-instance: patchwork
O-Subject: [RHEL8.3 PATCH 10/10] nvme: allow retry for requests with REQ_FAILFAST_TRANSPORT set
Bugzilla: 1843515

BZ: 1843515
Upstream Status: RHEL-only

Based on patch that was proposed upstream but ultimately rejected, see:
https://www.spinics.net/lists/linux-block/msg57490.html

I'd have made this change even if this wasn't already posted obviously, but I figured I'd give proper attribution due to their public post with the same code change.

Author: Chao Leng <[email protected]>
Date: Wed Aug 12 16:18:55 2020 +0800

nvme: allow retry for requests with REQ_FAILFAST_TRANSPORT set

REQ_FAILFAST_TRANSPORT may be designed for SCSI, because SCSI protocol does not define the local retry mechanism. SCSI implements a fuzzy local retry mechanism, so REQ_FAILFAST_TRANSPORT is needed to allow higher-level multipathing software to perform failover/retry.

NVMe is different with SCSI about this. It defines a local retry mechanism and path error codes, so NVMe should retry local for non path error. If path related error, whether to retry and how to retry is still determined by higher-level multipathing's failover.

Unlike SCSI, NVMe shouldn't prevent retry if REQ_FAILFAST_TRANSPORT because NVMe's local retry is needed -- as is NVMe specific logic to categorize whether an error is path related.

In this way, the mechanism of NVMe multipath or other multipath are now equivalent. The mechanism is: non path related error will be retry local, path related error is handled by multipath.

[snitzer: edited header for grammar and to make clearer]
---
 drivers/nvme/host/core.c |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/nvme/host/core.c +8 -1
Index: linux-rhel9/drivers/nvme/host/core.c
===================================================================
@@ -306,7 +306,14 @@ static inline enum nvme_disposition nvme
 	if (likely(nvme_req(req)->status == 0))
 		return COMPLETE;
 
-	if (blk_noretry_request(req) ||
+	/*
+	 * REQ_FAILFAST_TRANSPORT is set by upper layer software that
+	 * handles multipathing. Unlike SCSI, NVMe's error handling was
+	 * specifically designed to handle local retry for non-path errors.
+	 * As such, allow NVMe's local retry mechanism to be used for
+	 * requests marked with REQ_FAILFAST_TRANSPORT.
+	 */
+	if ((req->cmd_flags & (REQ_FAILFAST_DEV | REQ_FAILFAST_DRIVER)) ||
 	    (nvme_req(req)->status & NVME_SC_DNR) ||
 	    nvme_req(req)->retries >= nvme_max_retries)
 		return COMPLETE;
#4 lore raw
In reply to Mike Snitzer

Sorry, emailed from wrong terminal... have since emailed correct v2

Quoted 59 lines · Mike Snitzer

BZ: 1948690
Upstream Status: RHEL-only

rhel-8.git commit ef4ab90c12db5e0e50800ec323736b95be7a6ff5

Author: Mike Snitzer <[email protected]>
Date:   Tue Aug 25 21:52:45 2020 -0400

[nvme] nvme: Return BLK_STS_TARGET if the DNR bit is set

Message-id: <[email protected]>
Patchwork-id: 325178
Patchwork-instance: patchwork
O-Subject: [RHEL8.3 PATCH 07/10] nvme: Return BLK_STS_TARGET if the DNR bit is set
Bugzilla: 1843515

BZ: 1843515
Upstream Status: RHEL-only

If the DNR bit is set we should not retry the command, even if the standard status evaluation indicates so.

SUSE is carrying this patch in their kernel:
https://lwn.net/Articles/800370/

Based on patch posted for upstream inclusion but rejected:
v1: https://lore.kernel.org/linux-nvme/[email protected]/
v2: https://lore.kernel.org/linux-nvme/[email protected]/
v2-keith: https://lore.kernel.org/linux-nvme/[email protected]/
v3: https://lore.kernel.org/linux-nvme/[email protected]/
v3-keith: https://lore.kernel.org/linux-nvme/[email protected]/

This commit's change is basically "v3-keith".

---
 drivers/nvme/host/core.c |    3 +++
 1 file changed, 3 insertions(+)

Index: linux-rhel9/drivers/nvme/host/core.c
===================================================================

drivers/nvme/host/core.c +3 -0
@@ -237,6 +237,9 @@ static void nvme_delete_ctrl_sync(struct
 
 static blk_status_t nvme_error_status(u16 status)
 {
+	if (unlikely(status & NVME_SC_DNR))
+		return BLK_STS_TARGET;
+
 	switch (status & 0x7ff) {
 	case NVME_SC_SUCCESS:
 		return BLK_STS_OK;
#5 lore raw
In reply to Mike Snitzer
Quoted 51 lines · Mike Snitzer

BZ: 1948690
Upstream Status: RHEL-only

rhel-8.git commit ef4ab90c12db5e0e50800ec323736b95be7a6ff5

Author: Mike Snitzer <[email protected]>
Date:   Tue Aug 25 21:52:45 2020 -0400

[nvme] nvme: Return BLK_STS_TARGET if the DNR bit is set

Message-id: <[email protected]>
Patchwork-id: 325178
Patchwork-instance: patchwork
O-Subject: [RHEL8.3 PATCH 07/10] nvme: Return BLK_STS_TARGET if the DNR bit is set
Bugzilla: 1843515

BZ: 1843515
Upstream Status: RHEL-only

If the DNR bit is set we should not retry the command, even if the standard status evaluation indicates so.

SUSE is carrying this patch in their kernel:
https://lwn.net/Articles/800370/

Based on patch posted for upstream inclusion but rejected:
v1: https://lore.kernel.org/linux-nvme/[email protected]/
v2: https://lore.kernel.org/linux-nvme/[email protected]/
v2-keith: https://lore.kernel.org/linux-nvme/[email protected]/
v3: https://lore.kernel.org/linux-nvme/[email protected]/
v3-keith: https://lore.kernel.org/linux-nvme/[email protected]/

This commit's change is basically "v3-keith".

---
 drivers/nvme/host/core.c |    3 +++
 1 file changed, 3 insertions(+)

Index: linux-rhel9/drivers/nvme/host/core.c
===================================================================

drivers/nvme/host/core.c static void nvme_delete_ctrl_sync(struct · line 245

Quoted 9 lines
drivers/nvme/host/core.c +3 -0
@@ -237,6 +237,9 @@ static void nvme_delete_ctrl_sync(struct
 
 static blk_status_t nvme_error_status(u16 status)
 {
+	if (unlikely(status & NVME_SC_DNR))
+		return BLK_STS_TARGET;
+
 	switch (status & 0x7ff) {
 	case NVME_SC_SUCCESS:
 		return BLK_STS_OK;

No; this is most likely wrong for quite some machines.
At this time we don't have a fixed mapping for the DNR bit; some BLK_STS_XX codes can be retried, some might, others should not; we never went so far as to formally code that.

But mapping it to BLK_STS_TARGET is not the correct way here.

Cheers,

Hannes

Signature · 5 lines
Dr. Hannes Reinecke		   Teamlead Storage & Networking
[email protected]			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)