]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
scsi: libsas: Fix HA resume deadlock and hisi_sas disk-wake race
authorXingui Yang <yangxingui@huawei.com>
Thu, 16 Jul 2026 08:11:45 +0000 (16:11 +0800)
committerMartin K. Petersen <martin.petersen@oracle.com>
Sun, 26 Jul 2026 19:34:03 +0000 (15:34 -0400)
Commit fbefe22811c3 ("scsi: libsas: Don't always drain event workqueue
for HA resume") introduced sas_resume_ha_no_sync() to avoid a deadlock:
the PHYE_RESUME_TIMEOUT handler, running on the HA event workqueue,
calls sas_deform_port() -> sas_destruct_devices(), which removes SCSI
devices and waits for the host to become runtime-active. But the host
cannot resume until sas_resume_ha() -> sas_drain_work() returns, and the
drain is blocked on that very handler.

However skipping the drain reintroduces a race: hisi_sas returns from
resume before all PHY UP work and libsas discovery work finish. The
controller may then autosuspend while disks are still waking up. The
disks issue IO to a suspended controller, the IO fails, and the disks
get disabled.

Fix the deadlock at its source by moving the PHYE_RESUME_TIMEOUT
notification to after sas_drain_work(). By then the host resume is about
to complete, so device removal through device_link no longer blocks on
the resume and the cycle is broken.

With the deadlock gone, restore sas_resume_ha() (the draining variant)
in hisi_sas and remove sas_resume_ha_no_sync().

The reorder is safe for the other libsas consumers (isci, pm8001,
aic94xx, mvsas). During suspend, sas_suspend_devices() calls
sas_notify_lldd_dev_gone() for each device, which sets dev->lldd_dev to
NULL. When scsi_unblock_requests re-enables I/O in resume, any I/O to a
timed-out phy's disk is immediately rejected by the LLDD before reaching
hardware: isci returns SAS_DEVICE_UNKNOWN (mapped to DID_BAD_TARGET),
and pm8001 returns SAS_PHY_DOWN (mapped to DID_NO_CONNECT). Both
complete directly via scsi_done() without entering SCSI EH. This is
identical in both the old and new ordering since lldd_dev_gone runs
during suspend, before resume. The reorder only affects when the
PHYE_RESUME_TIMEOUT handler runs (synchronized by sas_drain_work()
vs. asynchronous after resume returns), not whether I/O can reach the
device. aic94xx and mvsas do not register any PM ops and never reach
this code path.

Fixes: fbefe22811c3 ("scsi: libsas: Don't always drain event workqueue for HA resume")
Signed-off-by: Xingui Yang <yangxingui@huawei.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Link: https://patch.msgid.link/20260716081145.3950172-1-yangxingui@huawei.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
drivers/scsi/libsas/sas_init.c
include/scsi/libsas.h

index 213d5b5dea94faf23d5689acea703541f909e5a0..8a2500993e19d58dd9b6eb00afe4be730242824d 100644 (file)
@@ -5261,15 +5261,7 @@ static int _resume_v3_hw(struct device *device)
                return rc;
        }
        phys_init_v3_hw(hisi_hba);
-
-       /*
-        * If a directly-attached disk is removed during suspend, a deadlock
-        * may occur, as the PHYE_RESUME_TIMEOUT processing will require the
-        * hisi_hba->device to be active, which can only happen when resume
-        * completes. So don't wait for the HA event workqueue to drain upon
-        * resume.
-        */
-       sas_resume_ha_no_sync(sha);
+       sas_resume_ha(sha);
        clear_bit(HISI_SAS_RESETTING_BIT, &hisi_hba->flags);
 
        dev_warn(dev, "end of resuming controller\n");
index 0bec236f0fb5950cca8de4fafa32ecf6a44dca93..c3f3d05b46deaca8896178818047c88e2dead444 100644 (file)
@@ -410,7 +410,7 @@ static void sas_resume_insert_broadcast_ha(struct sas_ha_struct *ha)
        }
 }
 
-static void _sas_resume_ha(struct sas_ha_struct *ha, bool drain)
+void sas_resume_ha(struct sas_ha_struct *ha)
 {
        const unsigned long tmo = msecs_to_jiffies(25000);
        int i;
@@ -426,6 +426,23 @@ static void _sas_resume_ha(struct sas_ha_struct *ha, bool drain)
                dev_info(ha->dev, "waiting up to 25 seconds for %d phy%s to resume\n",
                         i, i > 1 ? "s" : "");
        wait_event_timeout(ha->eh_wait_q, phys_suspended(ha) == 0, tmo);
+
+       /*
+        * All phys are back up or timed out. Turn on I/O and drain
+        * pending work.
+        */
+       scsi_unblock_requests(ha->shost);
+       sas_drain_work(ha);
+
+       /*
+        * Send PHYE_RESUME_TIMEOUT after sas_drain_work(). The handler
+        * calls sas_deform_port() -> sas_destruct_devices(), which removes
+        * SCSI devices and, for LLDDs using device_link() PM sync, waits
+        * for the host to be runtime-active. Sending it before the drain
+        * would deadlock: the drain waits for the handler, the handler
+        * waits for host resume, and host resume waits for the drain to
+        * finish.
+        */
        for (i = 0; i < ha->num_phys; i++) {
                struct asd_sas_phy *phy = ha->sas_phy[i];
 
@@ -436,12 +453,6 @@ static void _sas_resume_ha(struct sas_ha_struct *ha, bool drain)
                }
        }
 
-       /* all phys are back up or timed out, turn on i/o so we can
-        * flush out disks that did not return
-        */
-       scsi_unblock_requests(ha->shost);
-       if (drain)
-               sas_drain_work(ha);
        clear_bit(SAS_HA_RESUMING, &ha->state);
 
        sas_queue_deferred_work(ha);
@@ -450,20 +461,8 @@ static void _sas_resume_ha(struct sas_ha_struct *ha, bool drain)
         */
        sas_resume_insert_broadcast_ha(ha);
 }
-
-void sas_resume_ha(struct sas_ha_struct *ha)
-{
-       _sas_resume_ha(ha, true);
-}
 EXPORT_SYMBOL(sas_resume_ha);
 
-/* A no-sync variant, which does not call sas_drain_ha(). */
-void sas_resume_ha_no_sync(struct sas_ha_struct *ha)
-{
-       _sas_resume_ha(ha, false);
-}
-EXPORT_SYMBOL(sas_resume_ha_no_sync);
-
 void sas_suspend_ha(struct sas_ha_struct *ha)
 {
        int i;
index 163f23c92b4119bec2d226abeba79bc5ba863e74..36d4cb567837c676c0eb4c146aff3e2a8c085a5a 100644 (file)
@@ -680,7 +680,6 @@ extern int sas_register_ha(struct sas_ha_struct *);
 extern int sas_unregister_ha(struct sas_ha_struct *);
 extern void sas_prep_resume_ha(struct sas_ha_struct *sas_ha);
 extern void sas_resume_ha(struct sas_ha_struct *sas_ha);
-extern void sas_resume_ha_no_sync(struct sas_ha_struct *sas_ha);
 extern void sas_suspend_ha(struct sas_ha_struct *sas_ha);
 
 int sas_phy_reset(struct sas_phy *phy, int hard_reset);