From: Bart Van Assche <bvanassche@acm.org>
To: John Garry <john.garry@linux.dev>,
James.Bottomley@HansenPartnership.com, mkp@kernel.org
Cc: linux-scsi@vger.kernel.org, hare@suse.de
Subject: Re: [PATCH RFC] scsi: core: Clear cmd->flags for terminal queuing error
Date: Wed, 9 Sep 2026 09:32:24 -0700 [thread overview]
Message-ID: <c46f6c74-2aa0-4aad-a234-7ff4ba367bdb@acm.org> (raw)
In-Reply-To: <20260908120841.185742-1-john.garry@linux.dev>
On 9/8/26 5:08 AM, John Garry wrote:
> If a request can't be queued in scsi_queue_rq(), then we error out with
> a blk_status_t code. Such a scenario may be the scsi_device has its
> transport offline.
>
> For BLK_STS_RESOURCE or BLK_STS_AGAIN, the request will be requeued in the
> block layer. For other errors, the block layer ends the request and so
> we won't see it again (until recycled).
>
> Normally when a request completes scmd->flags is cleared in
> scsi_end_request().
>
> However for the error scenario mentioned above, scsi_end_request() is
> not called and so scmd->flags is not cleared. As such, when the request
> is recycled we see the old value in scmd->flags.
>
> Fix this issue by clearing scmd->flags in the error scenario mentioned.
>
> Signed-off-by: John Garry <john.garry@linux.dev>
> ---
> Setting as an RFC as I am not 100% sure that this is correct as there are
> lots of paths involved. Sashiko pointed out a related issue in
> https://lore.kernel.org/linux-scsi/20260729161243.C918D1F00A3A@smtp.kernel.org/,
> but blk_mq_cleanup_rq() -> scsi_cleanup_rq() -> cmd->flags = 0 is only
> called for by DM code.
>
> diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
> index af27fd3df8d4..295f8b4afaa7 100644
> --- a/drivers/scsi/scsi_lib.c
> +++ b/drivers/scsi/scsi_lib.c
> @@ -1967,6 +1967,7 @@ static blk_status_t scsi_queue_rq(struct blk_mq_hw_ctx *hctx,
> */
> if (req->rq_flags & RQF_DONTPREP)
> scsi_mq_uninit_cmd(cmd);
> + cmd->flags = 0;
> scsi_run_queue_async(sdev);
> break;
> }
Is there agreement that all block drivers are affected that define a
.cleanup_rq() callback? Would this be a valid alternative (untested)?
diff --git a/block/blk-mq.c b/block/blk-mq.c
index a26a11c73ee3..0be933e26d67 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2126,6 +2126,12 @@ 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:
+ /*
+ * Make sure to release all allocated resources when
+ * we hit an error, as we will never see this command
+ * again.
+ */
+ 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 48aab0df30b7..636854bffd1e 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -1960,13 +1960,6 @@ 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);
scsi_run_queue_async(sdev);
break;
}
Thanks,
Bart.
next prev parent reply other threads:[~2026-09-09 16:32 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-08 12:08 [PATCH RFC] scsi: core: Clear cmd->flags for terminal queuing error John Garry
2026-09-09 16:32 ` Bart Van Assche [this message]
2026-09-09 16:49 ` John Garry
2026-09-09 17:55 ` Bart Van Assche
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c46f6c74-2aa0-4aad-a234-7ff4ba367bdb@acm.org \
--to=bvanassche@acm.org \
--cc=James.Bottomley@HansenPartnership.com \
--cc=hare@suse.de \
--cc=john.garry@linux.dev \
--cc=linux-scsi@vger.kernel.org \
--cc=mkp@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox