* [PATCH] blk-mq: cleanup terminal request when it could not be queued
@ 2026-09-11 7:54 John Garry
2026-09-11 15:55 ` Bart Van Assche
0 siblings, 1 reply; 2+ messages in thread
From: John Garry @ 2026-09-11 7:54 UTC (permalink / raw)
To: axboe, James.Bottomley, mkp, hch, tom.leiming, bvanassche
Cc: linux-block, linux-scsi, John Garry
Sashiko points out that the SCSI midlayer error handling misses some
cleanup for when a request could not be queued and won't be requeued [0].
Specifically, clearing the SCSI cmd flags member is missing. Normally that
would be cleared in the non-error path in scsi_end_request() (which also
calls __blk_mq_end_request()).
Callchain blk_mq_cleanup_rq() -> scsi_cleanup_rq() does all the necessary
cleanup, so call that in blk_mq_dispatch_rq_list() for when there was an
error in the dispatch and the rq will be ended.
Note that dm-rq code calls blk_mq_cleanup_rq() for a cloned rq (or SCSI rq)
for when the clone could not be queued and will be retried, but that path
does not use the sched code (and blk_mq_dispatch_rq_list()).
[0] https://lore.kernel.org/linux-scsi/20260729161243.C918D1F00A3A@smtp.kernel.org/
Suggesested-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: John Garry <john.garry@linux.dev>
---
Maybe SCSI should be doing this cleanup directly, as we now create some
confusion on who should do the cleanup - blk-mq or the driver.
diff --git a/block/blk-mq.c b/block/blk-mq.c
index a26a11c73ee3..eb3a481211d0 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2126,6 +2126,7 @@ bool blk_mq_dispatch_rq_list(struct blk_mq_hw_ctx *hctx, struct list_head *list,
blk_mq_handle_dev_resource(rq, list);
goto out;
default:
+ blk_mq_cleanup_rq(rq);
blk_mq_end_request(rq, ret);
}
} while (!list_empty(list));
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index af27fd3df8d4..1ea65b5eb25c 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -1960,13 +1960,7 @@ static blk_status_t scsi_queue_rq(struct blk_mq_hw_ctx *hctx,
cmd->result = DID_NO_CONNECT << 16;
else
cmd->result = DID_ERROR << 16;
- /*
- * Make sure to release all allocated resources when
- * we hit an error, as we will never see this command
- * again.
- */
- if (req->rq_flags & RQF_DONTPREP)
- scsi_mq_uninit_cmd(cmd);
+ /* blk-mq will cleanup our resources as the rq will end */
scsi_run_queue_async(sdev);
break;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] blk-mq: cleanup terminal request when it could not be queued
2026-09-11 7:54 [PATCH] blk-mq: cleanup terminal request when it could not be queued John Garry
@ 2026-09-11 15:55 ` Bart Van Assche
0 siblings, 0 replies; 2+ messages in thread
From: Bart Van Assche @ 2026-09-11 15:55 UTC (permalink / raw)
To: John Garry, axboe, James.Bottomley, mkp, hch, tom.leiming
Cc: linux-block, linux-scsi
On 9/11/26 12:54 AM, John Garry wrote:
> Sashiko points out that the SCSI midlayer error handling misses some
> cleanup for when a request could not be queued and won't be requeued [0].
> Specifically, clearing the SCSI cmd flags member is missing. Normally that
> would be cleared in the non-error path in scsi_end_request() (which also
> calls __blk_mq_end_request()).
>
> Callchain blk_mq_cleanup_rq() -> scsi_cleanup_rq() does all the necessary
> cleanup, so call that in blk_mq_dispatch_rq_list() for when there was an
> error in the dispatch and the rq will be ended.
>
> Note that dm-rq code calls blk_mq_cleanup_rq() for a cloned rq (or SCSI rq)
> for when the clone could not be queued and will be retried, but that path
> does not use the sched code (and blk_mq_dispatch_rq_list()).
>
> [0] https://lore.kernel.org/linux-scsi/20260729161243.C918D1F00A3A@smtp.kernel.org/
>
> Suggesested-by: Bart Van Assche <bvanassche@acm.org>
> Signed-off-by: John Garry <john.garry@linux.dev>
Does this patch need a Fixes: tag? Anyway:
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-11 15:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-11 7:54 [PATCH] blk-mq: cleanup terminal request when it could not be queued John Garry
2026-09-11 15:55 ` Bart Van Assche
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox