In SDB mode, a timed-out command whose completion interrupt has not been handled yet can be released twice: 1. The command times out and scsi_timeout() schedules ufshcd_abort(). 2. The command finishes in hardware. Its doorbell bit is clear, but the completion interrupt has not been handled, so BIT(tag) is still set in hba->outstanding_reqs. 3. ufshcd_abort() sees the doorbell bit clear and calls __ufshcd_transfer_req_compl(). That releases the command but leaves BIT(tag) set in hba->outstanding_reqs. ufshcd_abort() returns FAILED. 4. The next ufshcd_poll() call, or the logical unit reset that follows the FAILED, sees BIT(tag) set in hba->outstanding_reqs and releases the same command again. Claim BIT(tag) in hba->outstanding_reqs with ufshcd_clear_outstanding_reqs() and release the command only if ufshcd_abort() claimed it and it is a SCSI command. Fixes: 169f5eb28869 ("scsi: ufs: Optimize SCSI command processing") Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/2e042211ca0ebc974ad5ec4c0de9f3f93b3c75c0.camel@iokpp.de Suggested-by: Bean Huo Signed-off-by: Stanley Jhu --- drivers/ufs/core/ufshcd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 111f5805f178..ee898f4a5bb1 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -8176,7 +8176,9 @@ static int ufshcd_abort(struct scsi_cmnd *cmd) dev_err(hba->dev, "%s: cmd was completed, but without a notifying intr, tag = %d", __func__, tag); - __ufshcd_transfer_req_compl(hba, 1UL << tag); + if (ufshcd_clear_outstanding_reqs(hba, BIT(tag)) && + ufshcd_is_scsi_cmd(cmd)) + ufshcd_release_scsi_cmd(hba, cmd); goto release; } -- 2.56.0.212.g129ede20d9-goog