All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Garry <john.garry@linux.dev>
To: James.Bottomley@HansenPartnership.com, mkp@kernel.org
Cc: linux-scsi@vger.kernel.org, bvanassche@acm.org,
	stable@vger.kernel.org, John Garry <john.garry@linux.dev>
Subject: [PATCH v4] scsi: core: Clear cmd->flags for terminal queuing error
Date: Mon, 30 Nov 2026 07:54:02 +0000	[thread overview]
Message-ID: <20261130075402.113855-1-john.garry@linux.dev> (raw)

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 <john.garry@linux.dev>
---
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


             reply	other threads:[~2026-11-30  7:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  7:54 John Garry [this message]
2026-11-30 18:50 ` [PATCH v4] scsi: core: Clear cmd->flags for terminal queuing error 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=20261130075402.113855-1-john.garry@linux.dev \
    --to=john.garry@linux.dev \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=bvanassche@acm.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=mkp@kernel.org \
    --cc=stable@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.