From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.120 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796025262; b=oFTE9ridEfxpWs4YZ1yUq71OLsc4czkaHFJEBoTfp3KpER5xdWvrHDVlfefNZk1k6HJY ypMePaoOVN6Q8Ia7YYs4os1MNpjsYXohg3tVNU0FCoC5Cpn9dw/KxsGZLH1BnnA9HhJkR PdxGWWnN9wp/A1Hnb31BTtuV3vU4vE/l78QSIKnCcAObVQzTsEGi6HoNF1wGUMXQay9aU EXLC9sagpdLTMuC0ycyP66oisH/SCgDnjFT0W3M3WP6Fs06vp19AlX/70G7hjuYGw4jmN vDCueSYFWpi0cEWz6JJgfx7NsQspYKSL6BSCzIALg71yRR9ES8+ZbKnyOsAV6fUGaJw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796025262; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=e63YedW3Xc2vJ88ByiC4wyuaXy5AzJAOdNLQfduCVNc=; b=YurZjyVVkw6EmBxc4LUT2qhYPBmu/HsIN7+HVPWQYaNx/Yc/4NW6gA7C4LC6MbQxxrxV TpMTDen7//pop7/0rwCzXcPpqhy56yVHzyeqWkStErYKvkwNWj50bShIdwQ7NIDEwPl0C 240Z8Ml7IuTkTrcA0pzYaFnMLAZN2IPXgbCAUiTvWWalTM5fFfpqxcoMNNOWq/+UGPV9b ZEgtidlk1uN9YVy6BAbfFDkgxw2DBaSTgHrQ4WcjGKGXo+flq4SDlN7pjEMCb6nycuAs0 0eE19okWe7ym76yN4cH1sRpExzDIrdi8gQWmNb8onb0bRdTJ6HRkWuNpokIG1XGdWUQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=WWR6C8Xj; arc=none smtp.remote-ip=91.218.175.120 Received: from mta0.migadu.com (out-120.mta0.migadu.com [91.218.175.120]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E0D1606A31C for ; Mon, 30 Nov 2026 07:54:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7E0D1606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=WWR6C8Xj X-Envelope-To: linux-scsi@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=9hi2CbqvKgxkE+j3BUdxg/0x/LeWpq4qZtd9qM0UHBk=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796025259; v=1; x=1796630059; b=WWR6C8XjqfHarqzilpATwSl3YBSbktEneQHzyhLEkuxUpukiwjqOYr59MdOsXAyExXRt6jpF 34KHRnoB6cFAi1GyBsNTWXNS90XdfXlSQpJ71Oau4COXcbf4slEB+S/tBPbJ/Q9uHjMdgx14D2G F9XgMngJzXKtySJ/YE3pWUQ4= X-Envelope-To: linux-scsi@vger.kernel.org Received: by mta11.migadu.com with ESMTPS id b22b5d239a365b9a; Mon, 30 Nov 2026 07:54:19 +0000 X-Mizu-Trace-ID: b22b5d239a365b9a X-Migadu-Flow: FLOW_OUT From: John Garry To: James.Bottomley@HansenPartnership.com, mkp@kernel.org Cc: linux-scsi@vger.kernel.org, bvanassche@acm.org, stable@vger.kernel.org, John Garry Subject: [PATCH v4] scsi: core: Clear cmd->flags for terminal queuing error Date: Mon, 30 Nov 2026 07:54:02 +0000 Message-ID: <20261130075402.113855-1-john.garry@linux.dev> X-Mailer: git-send-email 2.43.0 X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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