Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: Elkin Cruz <elkin@google.com>
To: Xingui Yang <yangxingui@huawei.com>,
	 "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
	 "Martin K. Petersen" <mkp@kernel.org>
Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
	 llvm@lists.linux.dev, irogers@google.com,
	Elkin Cruz <elkin@google.com>,
	 stable@vger.kernel.org
Subject: [PATCH] scsi: hisi_sas: Avoid synchronize_irq() under task_state_lock
Date: Wed, 25 Nov 2026 22:20:29 +0000	[thread overview]
Message-ID: <20261125222029.1429071-1-elkin@google.com> (raw)

In hisi_sas_abort_task(), when SAS_TASK_STATE_DONE is set, the driver
invoked hisi_sas_sync_cq() while holding task->task_state_lock with
interrupts disabled. For interrupt-driven queues, hisi_sas_sync_cq()
calls synchronize_irq(), which may sleep (while for poll queues it
spins on cq->poll_lock in hisi_sas_sync_poll_cq()).

In addition, once SAS_TASK_STATE_DONE is set and task_state_lock is
released by the completion handler, hisi_sas_slot_task_free() clears
task->lldd_task, zeroes slot->dlvry_queue, and frees the slot back to
the pool outside task_state_lock.

Release task->task_state_lock before calling hisi_sas_sync_cqs() on the
SAS_TASK_STATE_DONE path, and read task->lldd_task under
task->task_state_lock when setting SAS_TASK_STATE_ABORTED.

Fixes: 584f53fe5f52 ("scsi: hisi_sas: Fix the race between IO completion and timeout for SMP/internal IO")
Cc: stable@vger.kernel.org
Signed-off-by: Elkin Cruz <elkin@google.com>
---

I am trying out new Clang static analysis checks for kernel bug
classes, and they flagged this code as possibly buggy. The findings
were triaged/fixed and commit descriptions were drafted with help of AI,
then checked against linux-next (not runtime-tested on hardware).

Thanks,
Elkin

 drivers/scsi/hisi_sas/hisi_sas_main.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/hisi_sas_main.c
index 06455c7a9e2a..2a5a34eb1b28 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_main.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_main.c
@@ -1730,7 +1730,7 @@ static int hisi_sas_abort_task(struct sas_task *task)
 	struct hisi_sas_internal_abort_data internal_abort_data = { false };
 	struct domain_device *device = task->dev;
 	struct hisi_sas_device *sas_dev = device->lldd_dev;
-	struct hisi_sas_slot *slot = task->lldd_task;
+	struct hisi_sas_slot *slot;
 	struct hisi_hba *hisi_hba;
 	struct device *dev;
 	int rc = TMF_RESP_FUNC_FAILED;
@@ -1744,21 +1744,18 @@ static int hisi_sas_abort_task(struct sas_task *task)
 
 	spin_lock_irqsave(&task->task_state_lock, flags);
 	if (task->task_state_flags & SAS_TASK_STATE_DONE) {
-		struct hisi_sas_cq *cq;
-
-		if (slot) {
-			/*
-			 * sync irq or poll queue to avoid free'ing task
-			 * before using task in IO completion
-			 */
-			cq = &hisi_hba->cq[slot->dlvry_queue];
-			hisi_sas_sync_cq(cq);
-		}
 		spin_unlock_irqrestore(&task->task_state_lock, flags);
+		/*
+		 * Sync all CQs to avoid freeing task before IO completion
+		 * finishes using it; slot and slot->dlvry_queue may already
+		 * be cleared or reallocated once SAS_TASK_STATE_DONE is set.
+		 */
+		hisi_sas_sync_cqs(hisi_hba);
 		rc = TMF_RESP_FUNC_COMPLETE;
 		goto out;
 	}
 	task->task_state_flags |= SAS_TASK_STATE_ABORTED;
+	slot = task->lldd_task;
 	spin_unlock_irqrestore(&task->task_state_lock, flags);
 
 	if (!slot)
-- 
2.56.1.839.g22a8290db9-goog


             reply	other threads:[~2026-11-25 22:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 22:20 Elkin Cruz [this message]
2026-11-25 22:54 ` [PATCH] scsi: hisi_sas: Avoid synchronize_irq() under task_state_lock sashiko-bot

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=20261125222029.1429071-1-elkin@google.com \
    --to=elkin@google.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=irogers@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=mkp@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=yangxingui@huawei.com \
    /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