nvme-core: initialize status to NVME_SC_HOST_PATH_ERROR
Subsystems (2)
PATCH 1/1 nvme-core: initialize status to NVME_SC_HOST_PATH_ERROR
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_alloc_request().
--- drivers/nvme/host/core.c | 1 + 1 file changed, 1 insertion(+)
drivers/nvme/host/core.c +1 -0
@@ -580,6 +580,7 @@ static inline void nvme_clear_nvme_request(struct request *req)nvme_req (req)->flags =0 ; req->rq_flags |=RQF_DONTPREP ; } +nvme_req (req)->status =NVME_SC_HOST_PATH_ERROR ; }static inline unsigned int nvme_req_op (struct nvme_command *cmd)
Signature · 7 lines
2.31.1 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
drivers/nvme/host/core.c static inline void nvme_clear_nvme_request(struct request *req) · line 585
Quoted 11 lines · Yuanyuan Zhong
drivers/nvme/host/core.c +1
-0@@ -580,6 +580,7 @@ static inline void nvme_clear_nvme_request(struct request *req)nvme_req (req)->flags =0 ; req->rq_flags |=RQF_DONTPREP ; } +nvme_req (req)->status =NVME_SC_HOST_PATH_ERROR ; }
Since setting the status to the error value in not common when clearing the request this needs a good comment why we are doing it in nvme_clear_nvme_request().
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH v2 1/1 nvme-core: initialize status to NVME_SC_HOST_PATH_ERROR
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().
--- drivers/nvme/host/core.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/nvme/host/core.c +8 -0
@@ -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)
Signature · 7 lines
2.31.1 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Keith Busch
maintainerQuoted 9 lines · Yuanyuan Zhong
Block layer
blk_end_sync_rq()silently dropsblk_status_terror. 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 asNVME_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_ERRORduringnvme_clear_nvme_request().
It doesn't look like these types of errors are unique to nvme. Could we not just have blk_execute_rq() return an error instead?
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Keith Busch
maintainerQuoted 7 lines · Keith Busch
Quoted 6 lines · Yuanyuan Zhong
Block layer
blk_end_sync_rq()silently dropsblk_status_terror. 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 asNVME_SC_SUCCESS, despite the dispatching error from ->queue_rq.
Quoted 6 lines
Quoted 3 lines
Instead of trying to fix it for every error return, this change initialize the status to
NVME_SC_HOST_PATH_ERRORduringnvme_clear_nvme_request().It doesn't look like these types of errors are unique to nvme. Could we not just have
blk_execute_rq()return an error instead?
The following enables all callers to know if queue_rq() failed:
---
block/blk-exec.c +3 -2
@@ -21,7 +21,7 @@ static void blk_end_sync_rq(struct request *rq, blk_status_t error) {struct completion *waiting = rq->end_io_data; - rq->end_io_data =NULL ; + rq->end_io_data =ERR_PTR (blk_status_to_errno (error));/* * complete last, if this is a stack request the process (and thus
@@ -73,7 +73,7 @@ EXPORT_SYMBOL_GPL(blk_execute_rq_nowait);* Insert a fully prepared request at the back of the I/O scheduler queue * for execution and wait for completion. */ -void blk_execute_rq (struct gendisk *bd_disk,struct request *rq,int at_head) +int blk_execute_rq (struct gendisk *bd_disk,struct request *rq,int at_head) {DECLARE_COMPLETION_ONSTACK (wait);unsigned long hang_check;
@@ -87,5 +87,6 @@ void blk_execute_rq(struct gendisk *bd_disk, struct request *rq, int at_head)while (!wait_for_completion_io_timeout (&wait, hang_check * (HZ /2 ))); else wait_for_completion_io(&wait); +return PTR_ERR_OR_ZERO (rq->end_io_data); }EXPORT_SYMBOL (blk_execute_rq);
include/linux/blkdev.h +1 -1
@@ -933,7 +933,7 @@ extern int blk_rq_map_kern(struct request_queue *, struct request *, void *, unsextern int blk_rq_map_user_iov (struct request_queue *,struct request *,struct rq_map_data *,const struct iov_iter *,gfp_t ); -extern void blk_execute_rq (struct gendisk *,struct request *,int ); +extern int blk_execute_rq (struct gendisk *,struct request *,int );extern void blk_execute_rq_nowait (struct gendisk *,struct request *,int ,rq_end_io_fn *);
--
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Quoted 2 lines
Quoted 2 lines
It doesn't look like these types of errors are unique to nvme. Could we not just have
blk_execute_rq()return an error instead?
Looking at history of commit b7819b925918 ("block: remove the blk_execute_rq return value") and commit be549d491154 ("scsi: core: set result when the command cannot be dispatched"), it seems scsi code no longer have issue.
include/linux/blkdev.h extern int blk_rq_map_kern(struct request_queue *, struct request *, void *, uns · line 936
Quoted 2 lines
include/linux/blkdev.h +1
-1-extern void blk_execute_rq (struct gendisk *,struct request *,int ); +extern int blk_execute_rq (struct gendisk *,struct request *,int );
Changing blk_execute_rq() prototype needs tree-wide callers update. While it could be a fix, I'd wait for maintainers to chime in.
I don't quite like initializing the status for every nvme command. However for such a long standing bug across multiple stable releases, I think it will be an easy backport for stable-tree.
--
Regards,
Yuanyuan Zhong
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Keith Busch
maintainerQuoted 5 lines · Yuanyuan Zhong
Quoted 2 lines
Quoted 2 lines
It doesn't look like these types of errors are unique to nvme. Could we not just have
blk_execute_rq()return an error instead?Looking at history of commit
b7819b925918("block: remove theblk_execute_rqreturn value") and commitbe549d491154("scsi: core: set result when the command cannot be dispatched"), it seems scsi code no longer have issue.
Those happened when 'struct request' carried an 'errors' field that a caller could check. The struct doesn't have that anymore.
Quoted 3 lines
include/linux/blkdev.h extern int blk_rq_map_kern(struct request_queue *, struct request *, void *, uns · line 936
Quoted 2 lines
include/linux/blkdev.h +1
-1-extern void blk_execute_rq (struct gendisk *,struct request *,int ); +extern int blk_execute_rq (struct gendisk *,struct request *,int );Changing
blk_execute_rq()prototype needs tree-wide callers update.
Callers aren't relying on an error now, so I don't think this suggestion requires a tree-wide update. It might want an audit to see if existing callers are susceptible to the same bug you found with NVMe, but changing the return as suggested shouldn't introduce new issues.
Quoted 1 line
While it could be a fix, I'd wait for maintainers to chime in.
Yes, this does require concensus, but Linux is usually adaptable to changing kernal APIs when it makes sense. I *think* my suggestion makes sense, but I appreciate any feedback.
Quoted 3 lines
I don't quite like initializing the status for every nvme command. However for such a long standing bug across multiple stable releases, I think it will be an easy backport for stable-tree.
Your proposal is easier for stable, however, the mainline fix doesn't necessarily need to consider that. We can always deal with a back-port if the mainline approach does not readily apply.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme