[PATCH v2] nvme-core: initialize status to NVME_SC_HOST_PATH_ERROR

Yuanyuan Zhong yzhong at purestorage.com
Wed Apr 14 18:08:33 BST 2021


Block layer blk_end_sync_rq() silently drops blk_status_t error.
When ->queue_rq returns error, nvme driver should set nvme status
explicitly. Otherwise the passthrough command may take the stale
status as result. A typical value zero will be interpreted as
NVME_SC_SUCCESS, despite the dispatching error from ->queue_rq.

Instead of trying to fix it for every error return, this change
initialize the status to NVME_SC_HOST_PATH_ERROR during
nvme_clear_nvme_request().

Fixes: 27fa9bc54541 ("nvme: split nvme status from block req->errors")
Signed-off-by: Yuanyuan Zhong <yzhong at purestorage.com>
Signed-off-by: Casey Chen <cachen at purestorage.com>
---
 drivers/nvme/host/core.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 0896e21642be..df7d9a515297 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -580,6 +580,14 @@ static inline void nvme_clear_nvme_request(struct request *req)
 		nvme_req(req)->flags = 0;
 		req->rq_flags |= RQF_DONTPREP;
 	}
+
+	/*
+	 * We need to set nvme_req(req)->status whenever ->queue_rq()
+	 * fails the command submission. Ideally an appropriate status
+	 * should be set for each ->queue_rq() error case.
+	 * This is a blanket failsafe to avoid omission.
+	 */
+	nvme_req(req)->status = NVME_SC_HOST_PATH_ERROR;
 }
 
 static inline unsigned int nvme_req_op(struct nvme_command *cmd)
-- 
2.31.1




More information about the Linux-nvme mailing list