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_DEV_RESOURCE, the request may 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 by calling scsi_cleanup_rq(). Fixes: 54bebe46871d ("scsi: core: Clear flags for scsi_cmnd that did not complete") Cc: stable@vger.kernel.org # v6.1+ Signed-off-by: John Garry --- Differences to v3: - stable tag and fixes change Differences to v2 (https://lore.kernel.org/linux-scsi/20261108204733.557995-2-john.garry@linux.dev/) - Adding same handling for BLK_STS_AGAIN - Add fixes tag v1 was sent in https://lore.kernel.org/linux-scsi/20260911075415.634921-1-john.garry@linux.dev/ diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index ab39514cc0c6..3d9ef83d3d10 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1976,8 +1976,7 @@ static blk_status_t scsi_queue_rq(struct blk_mq_hw_ctx *hctx, break; case BLK_STS_AGAIN: cmd->result = DID_BUS_BUSY << 16; - if (req->rq_flags & RQF_DONTPREP) - scsi_mq_uninit_cmd(cmd); + scsi_cleanup_rq(req); break; default: if (unlikely(!scsi_device_online(sdev))) @@ -1989,8 +1988,8 @@ static blk_status_t scsi_queue_rq(struct blk_mq_hw_ctx *hctx, * we hit an error, as we will never see this command * again. */ - if (req->rq_flags & RQF_DONTPREP) - scsi_mq_uninit_cmd(cmd); + scsi_cleanup_rq(req); + scsi_run_queue_async(sdev); break; } -- 2.43.0