avoid double request completion and IO error
Subsystems (3)
v3 cover avoid double request completion and IO error
Add blk_mq_set_request_complete and nvme_complete_failed_req for two bug fixs.
First avoid double request completion for nvmf_fail_nonready_command. Second avoid IO error for nvme native multipath.
V3:
- complete the request just for HBA driver path related error.
V2:
- use "switch" instead "if" to check return status.
Chao Leng (5):
blk-mq: introduce blk_mq_set_request_complete
nvme-core: introduce complete failed request
nvme-fabrics: avoid double request completion for
nvmf_fail_nonready_command
nvme-rdma: avoid IO error for nvme native multipath
nvme-fc: avoid IO error for nvme native multipath
drivers/nvme/host/fabrics.c | 4 +--- drivers/nvme/host/fc.c | 7 ++++++- drivers/nvme/host/nvme.h | 8 ++++++++ drivers/nvme/host/rdma.c | 9 ++++++++- include/linux/blk-mq.h | 5 +++++ 5 files changed, 28 insertions(+), 5 deletions(-)
Signature · 7 lines
2.16.4 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH v3 1/5 blk-mq: introduce blk_mq_set_request_complete
nvme drivers need to set the state of request to MQ_RQ_COMPLETE when directly complete request in queue_rq.
So add blk_mq_set_request_complete.
--- include/linux/blk-mq.h | 5 +++++ 1 file changed, 5 insertions(+)
include/linux/blk-mq.h +5 -0
@@ -494,6 +494,11 @@ static inline int blk_mq_request_completed(struct request *rq)return blk_mq_rq_state (rq) ==MQ_RQ_COMPLETE ; } +static inline void blk_mq_set_request_complete (struct request *rq) +{ +WRITE_ONCE (rq->state,MQ_RQ_COMPLETE ); +} +void blk_mq_start_request (struct request *rq);void blk_mq_end_request (struct request *rq,blk_status_t error);void __blk_mq_end_request (struct request *rq,blk_status_t error);
Signature · 7 lines
2.16.4 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerRe: [PATCH v3 1/5] blk-mq: introduce blk_mq_set_request_complete
Quoted 3 lines · Chao Leng
nvme drivers need to set the state of request to
MQ_RQ_COMPLETEwhen directly complete request inqueue_rq.
So addblk_mq_set_request_complete.
So I'm not happy with this helper. It should at least:
a) be named and documented to only apply for the ->queue_rq faіlure case
b) check that the request is in MQ_RQ_IDLE state
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH v3 1/5] blk-mq: introduce blk_mq_set_request_complete
Quoted 8 lines · Christoph Hellwig
Quoted 3 lines · Chao Leng
nvme drivers need to set the state of request to
MQ_RQ_COMPLETEwhen directly complete request inqueue_rq.
So addblk_mq_set_request_complete.So I'm not happy with this helper. It should at least:
a) be named and documented to only apply for the ->queue_rq faіlure case
Although blk_mq_complete_request_remote can set the markup directly, blk_mq_complete_request_remote can also use this helper. This helper do not need special processing for ->queue_rq failure.
Quoted 1 line
b) check that the request is in
MQ_RQ_IDLEstate
No, the request may also be in MQ_RQ_IN_FLIGHT state. Do not need to care whether the original state is MQ_RQ_IDLE or MQ_RQ_IN_FLIGHT.
Quoted 2 lines
.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH v3 2/5 nvme-core: introduce complete failed request
In reply to Chao LengWork with nvme native multipath, if a path related error occurs when queue_rq call HBA drive to send request, queue_rq need complete the request with NVME_SC_HOST_PATH_ERROR, the request will fail over to retry if needed.
So introduce nvme_complete_failed_req for queue_rq and nvmf_fail_nonready_command.
--- drivers/nvme/host/nvme.h | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/nvme/host/nvme.h +8 -0
@@ -575,6 +575,14 @@ static inline bool nvme_is_aen_req(u16 qid, __u16 command_id) }void nvme_complete_rq (struct request *req); + +static inline void nvme_complete_failed_req (struct request *req) +{ +nvme_req (req)->status =NVME_SC_HOST_PATH_ERROR ; +blk_mq_set_request_complete (req); +nvme_complete_rq (req); +} +bool nvme_cancel_request (struct request *req,void *data,bool reserved);bool nvme_change_ctrl_state (struct nvme_ctrl *ctrl,enum nvme_ctrl_state new_state);
Signature · 7 lines
2.16.4 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerRe: [PATCH v3 2/5] nvme-core: introduce complete failed request
Quoted 1 line
+static inline void
nvme_complete_failed_req(struct request *req)
I think the name is too generic, and the function also needs a little comment, especially as it forces a specific error code.
drivers/nvme/host/nvme.h static inline bool nvme_is_aen_req(u16 qid, __u16 command_id) · line 584
Quoted 5 lines
drivers/nvme/host/nvme.h +5
-0+{ +nvme_req (req)->status =NVME_SC_HOST_PATH_ERROR ; +blk_mq_set_request_complete (req); +nvme_complete_rq (req); +}
Also no need to mark this as an inline function.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH v3 2/5] nvme-core: introduce complete failed request
Quoted 4 lines · Christoph Hellwig
Quoted 1 line
+static inline void
nvme_complete_failed_req(struct request *req)I think the name is too generic, and the function also needs a little comment, especially as it forces a specific error code.
Ok, thank you for your suggestion. Use error status as a parameter may be a better choice.
Quoted 8 lines
drivers/nvme/host/nvme.h static inline bool nvme_is_aen_req(u16 qid, __u16 command_id) · line 584
Quoted 6 lines
drivers/nvme/host/nvme.h +5
-0+{ +nvme_req (req)->status =NVME_SC_HOST_PATH_ERROR ; +blk_mq_set_request_complete (req); +nvme_complete_rq (req); +}Also no need to mark this as an inline function.
Yes, export the function is ok.
Quoted 2 lines
.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH v3 3/5 nvme-fabrics: avoid double request completion for nvmf_fail_nonready_command
In reply to Chao LengWhen reconnect, the request may be completed with NVME_SC_HOST_PATH_ERROR in nvmf_fail_nonready_command. The state of request will be changed to MQ_RQ_IN_FLIGHT before call nvme_complete_rq. If free the request asynchronously such as in nvme_submit_user_cmd, in extreme scenario the request may be completed again in tear down process. nvmf_fail_nonready_command do not need calling blk_mq_start_request before complete the request. nvmf_fail_nonready_command should set the state of request to MQ_RQ_COMPLETE before complete the request.
--- drivers/nvme/host/fabrics.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/nvme/host/fabrics.c +1 -3
@@ -553,9 +553,7 @@ blk_status_t nvmf_fail_nonready_command(struct nvme_ctrl *ctrl, !blk_noretry_request(rq) && !(rq->cmd_flags & REQ_NVME_MPATH))return BLK_STS_RESOURCE ; -nvme_req (rq)->status =NVME_SC_HOST_PATH_ERROR ; -blk_mq_start_request (rq); -nvme_complete_rq (rq); +nvme_complete_failed_req (rq);return BLK_STS_OK ; }EXPORT_SYMBOL_GPL (nvmf_fail_nonready_command);
Signature · 7 lines
2.16.4 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH v3 3/5] nvme-fabrics: avoid double request completion for nvmf_fail_nonready_command
Quoted 9 lines · Chao Leng
When reconnect, the request may be completed with
NVME_SC_HOST_PATH_ERRORinnvmf_fail_nonready_command. The state of request will be changed toMQ_RQ_IN_FLIGHTbefore callnvme_complete_rq. If free the request asynchronously such as innvme_submit_user_cmd, in extreme scenario the request may be completed again in tear down process.nvmf_fail_nonready_commanddo not need callingblk_mq_start_requestbefore complete the request.nvmf_fail_nonready_commandshould set the state of request toMQ_RQ_COMPLETEbefore complete the request.
So what you are saying is that there is a race condition between blk_mq_start_request()
andnvme_complete_request()
Quoted 20 lines
Signed-off-by Chao Leng <[email protected]>--- drivers/nvme/host/fabrics.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)drivers/nvme/host/fabrics.c +1
-3@@ -553,9 +553,7 @@ blk_status_t nvmf_fail_nonready_command(struct nvme_ctrl *ctrl, !blk_noretry_request(rq) && !(rq->cmd_flags & REQ_NVME_MPATH))return BLK_STS_RESOURCE ; -nvme_req (rq)->status =NVME_SC_HOST_PATH_ERROR ; -blk_mq_start_request (rq); -nvme_complete_rq (rq); +nvme_complete_failed_req (rq);return BLK_STS_OK ; }EXPORT_SYMBOL_GPL (nvmf_fail_nonready_command);
Quoted 1 line
I'd rather have '
nvme_complete_failed_req()' accept the status as
argument, like
nvme_complete_failed_request(rq, NVME_SC_HOST_PATH_ERROR)
that way it's obvious what is happening, and the status isn't hidden in the function.
Cheers,
Hannes
Signature · 9 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerRe: [PATCH v3 3/5] nvme-fabrics: avoid double request completion for nvmf_fail_nonready_command
Quoted 11 lines · Hannes Reinecke
Quoted 9 lines · Chao Leng
When reconnect, the request may be completed with
NVME_SC_HOST_PATH_ERRORinnvmf_fail_nonready_command. The state of request will be changed toMQ_RQ_IN_FLIGHTbefore callnvme_complete_rq. If free the request asynchronously such as innvme_submit_user_cmd, in extreme scenario the request may be completed again in tear down process.nvmf_fail_nonready_commanddo not need callingblk_mq_start_requestbefore complete the request.nvmf_fail_nonready_commandshould set the state of request toMQ_RQ_COMPLETEbefore complete the request.
Quoted 4 lines
So what you are saying is that there is a race condition between
blk_mq_start_request()
andnvme_complete_request()
Between those to a teardwon that cancels all requests can come in.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH v3 3/5] nvme-fabrics: avoid double request completion for nvmf_fail_nonready_command
Quoted 12 lines · Christoph Hellwig
Quoted 11 lines · Hannes Reinecke
Quoted 9 lines · Chao Leng
When reconnect, the request may be completed with
NVME_SC_HOST_PATH_ERRORinnvmf_fail_nonready_command. The state of request will be changed toMQ_RQ_IN_FLIGHTbefore callnvme_complete_rq. If free the request asynchronously such as innvme_submit_user_cmd, in extreme scenario the request may be completed again in tear down process.nvmf_fail_nonready_commanddo not need callingblk_mq_start_requestbefore complete the request.nvmf_fail_nonready_commandshould set the state of request toMQ_RQ_COMPLETEbefore complete the request.
Quoted 7 lines
Quoted 4 lines
So what you are saying is that there is a race condition between
blk_mq_start_request()
andnvme_complete_request()Between those to a teardown that cancels all requests can come in.
Doesn't nvme_complete_request() insulate against a double completion? I seem to remember we've gone through great lengths ensuring that.
And if this is just about setting the correct error code on completion I'd really prefer to stick with the current code. Moving that into a helper is fine, but I'd rather not introduce our own code modifying request state.
If there really is a race condition this feels like a more generic problem; calling blk_mq_start_request() followed by blk_mq_end_request() is a quite common pattern, and from my impression the recommended way. So if there is an issue it would need to be addressed for all drivers, not just some nvme-specific way.
Plus I'd like to have Jens' opinion here.
Cheers,
Hannes
Signature · 9 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH v3 3/5] nvme-fabrics: avoid double request completion for nvmf_fail_nonready_command
Quoted 13 lines · Hannes Reinecke
Quoted 12 lines · Christoph Hellwig
Quoted 11 lines · Hannes Reinecke
Quoted 9 lines · Chao Leng
When reconnect, the request may be completed with
NVME_SC_HOST_PATH_ERRORinnvmf_fail_nonready_command. The state of request will be changed toMQ_RQ_IN_FLIGHTbefore callnvme_complete_rq. If free the request asynchronously such as innvme_submit_user_cmd, in extreme scenario the request may be completed again in tear down process.nvmf_fail_nonready_commanddo not need callingblk_mq_start_requestbefore complete the request.nvmf_fail_nonready_commandshould set the state of request toMQ_RQ_COMPLETEbefore complete the request.
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
So what you are saying is that there is a race condition between
blk_mq_start_request()
andnvme_complete_request()Between those to a teardown that cancels all requests can come in.
Doesn't
nvme_complete_request()insulate against a double completion?
nvme_complete_request can not insulate against double completion. Setting the state of request to MQ_RQ_COMPLETE avoid double completion. tear down(nvme_cancel_request) check the state of the request, if the state is MQ_RQ_COMPLETE, it will skip completion.
Quoted 6 lines
I seem to remember we've gone through great lengths ensuring that.
And if this is just about setting the correct error code on completion I'd really prefer to stick with the current code. Moving that into a helper is fine, but I'd rather not introduce our own code modifying request state.
If there really is a race condition this feels like a more generic problem; calling
blk_mq_start_request()followed byblk_mq_end_request()is a quite common pattern, and from my impression the recommended way. So if there is an issue it would need to be addressed for all drivers, not just some nvme-specific way.
Currently, it is not safe for nvme. The probability is very low. I am not sure whether similar occurs in other scenarios.
Quoted 5 lines
Plus I'd like to have Jens' opinion here.
Cheers,
Hannes
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH v3 3/5] nvme-fabrics: avoid double request completion for nvmf_fail_nonready_command
In reply to Hannes ReineckeQuoted 11 lines · Hannes Reinecke
Quoted 9 lines · Chao Leng
When reconnect, the request may be completed with
NVME_SC_HOST_PATH_ERRORinnvmf_fail_nonready_command. The state of request will be changed toMQ_RQ_IN_FLIGHTbefore callnvme_complete_rq. If free the request asynchronously such as innvme_submit_user_cmd, in extreme scenario the request may be completed again in tear down process.nvmf_fail_nonready_commanddo not need callingblk_mq_start_requestbefore complete the request.nvmf_fail_nonready_commandshould set the state of request toMQ_RQ_COMPLETEbefore complete the request.
Quoted 4 lines
So what you are saying is that there is a race condition between
blk_mq_start_request()
andnvme_complete_request()
Yes. The race is:
process1:error recovery->tear down->quiesce queue(wait dispatch done) process2:dispatch->queue_rq->nvmf_fail_nonready_command->
nvme_complete_rq(if the request is freed asynchronously, wake
nvme_submit_user_cmd( for example) but have no chance to run).
process1:continue ->cancle suspend request, check the state is not
MQ_RQ_IDLE and MQ_RQ_COMPLETE, complete(free) the request.
process3: nvme_submit_user_cmd now has chance to run, and the free the
request again.
Test Injection Method: inject a msleep before call blk_mq_free_request in nvme_submit_user_cmd.
Quoted 23 lines
Quoted 20 lines
Signed-off-by Chao Leng <[email protected]>---
drivers/nvme/host/fabrics.c| 4 +---1 file changed, 1 insertion(+), 3 deletions(-)drivers/nvme/host/fabrics.c +1
-3@@ -553,9 +553,7 @@ blk_status_t nvmf_fail_nonready_command(struct nvme_ctrl *ctrl, !blk_noretry_request(rq) && !(rq->cmd_flags & REQ_NVME_MPATH)) return BLK_STS_RESOURCE; - nvme_req(rq)->status = NVME_SC_HOST_PATH_ERROR; - blk_mq_start_request(rq); - nvme_complete_rq(rq); + nvme_complete_failed_req(rq); return BLK_STS_OK; } EXPORT_SYMBOL_GPL(nvmf_fail_nonready_command);Quoted 1 line
I'd rather have '
nvme_complete_failed_req()' accept the status asargument, like
Quoted 3 lines
nvme_complete_failed_request(rq, NVME_SC_HOST_PATH_ERROR)that way it's obvious what is happening, and the status isn't hidden in the function.
Ok, good idea. Thank you for your suggestion.
Quoted 4 lines
Cheers,
Hannes
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH v3 4/5 nvme-rdma: avoid IO error for nvme native multipath
In reply to Chao LengWork with nvme native multipath, if a path related error occurs when queue_rq call HBA drive to send request, queue_rq will return BLK_STS_IOERR to blk-mq. The request is completed with BLK_STS_IOERR instead of fail over to retry.queue_rq need call nvme_complete_rq to complete the request with NVME_SC_HOST_PATH_ERROR, the request will fail over to retry if needed.
--- drivers/nvme/host/rdma.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/nvme/host/rdma.c +8 -1
@@ -2030,6 +2030,7 @@ static blk_status_t nvme_rdma_queue_rq(struct blk_mq_hw_ctx *hctx,bool queue_ready =test_bit (NVME_RDMA_Q_LIVE , &queue->flags);blk_status_t ret;int err; +bool driver_error = false;WARN_ON_ONCE (rq->tag <0 );
@@ -2077,8 +2078,10 @@ static blk_status_t nvme_rdma_queue_rq(struct blk_mq_hw_ctx *hctx, err =nvme_rdma_post_send (queue, sqe, req->sge, req->num_sge, req->mr ? &req->reg_wr.wr :NULL ); -if (unlikely (err)) +if (unlikely (err)) { + driver_error = true; goto err_unmap; + }return BLK_STS_OK ;
@@ -2093,6 +2096,10 @@ static blk_status_t nvme_rdma_queue_rq(struct blk_mq_hw_ctx *hctx, unmap_qe:ib_dma_unmap_single (dev, req->sqe.dma,sizeof (struct nvme_command ),DMA_TO_DEVICE ); +if (driver_error && ret ==BLK_STS_IOERR ) { +nvme_complete_failed_req (rq); + ret =BLK_STS_OK ; + }return ret; }
Signature · 7 lines
2.16.4 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH v3 5/5 nvme-fc: avoid IO error for nvme native multipath
In reply to Chao LengWork with nvme native multipath, if a path related error occurs when queue_rq call HBA drive to send request, queue_rq will return BLK_STS_IOERR to blk-mq. The request is completed with BLK_STS_IOERR instead of fail over to retry.queue_rq need call nvme_complete_rq to complete the request with NVME_SC_HOST_PATH_ERROR, the request will fail over to retry if needed.
--- drivers/nvme/host/fc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/nvme/host/fc.c +6 -1
@@ -2791,7 +2791,12 @@ nvme_fc_queue_rq(struct blk_mq_hw_ctx *hctx, } -return nvme_fc_start_fcp_op (ctrl, queue, op, data_len, io_dir); + ret =nvme_fc_start_fcp_op (ctrl, queue, op, data_len, io_dir); +if (ret ==BLK_STS_IOERR ) { +nvme_complete_failed_req (rq); + ret =BLK_STS_OK ; + } +return ret; } static void
Signature · 7 lines
2.16.4 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme