Commit

81e097a064b28b4a1f6ca1a8b433e659c1bd64c0

scsi: libsas: Fix SMP IO deadlock during HA resume

smp_execute_task_sg() calls pm_runtime_get_sync() on the host before
issuing an SMP command. When that command is itself issued from the HA
resume path, the get_sync() deadlocks: it waits for the ongoing resume
(the device is RPM_RESUMING), while the resume is blocked in
sas_drain_work() waiting for that same SMP IO to complete.

The deadlock needs an expander-attached SATA disk. During
sas_resume_ha() -> sas_drain_work(), DISCE_RESUME -> sas_resume_sata()
-> ata_sas_port_resume() requests ATA_EH_RESET, and the hard reset for
such a disk is done via SMP PHY CONTROL (sas_ata_hard_reset() ->
sas_phy_reset() -> sas_smp_phy_control() ->
smp_execute_task_sg()). Direct-attached SATA resets through
lldd_control_phy() and SSP devices use TMFs, so neither hits this.

Replace the get_sync()/put_sync() pair with
pm_runtime_get_noresume()/pm_runtime_put(). smp_execute_task_sg() only
needs to hold off autosuspend while the SMP is in flight, and it must
not try to resume the host: a sync resume issued from the HA resume path
itself is what deadlocks, and by the time sas_resume_ha() runs, hw_init
has already reinitialized the hardware, so the device is accessible
without one.

The usage reference is still required. Discovery work normally runs
inside an event worker's PM reference, taken at sas_notify_port_event()
notify time and held until the handler has flushed the disco
queue. sas_rediscover_ex_phy() however requeues DISCE_REVALIDATE_DOMAIN
from within the revalidation worker itself, and flush_workqueue() does
not wait for work items queued during execution, so that chained
revalidation runs with no outer PM reference - without the
get_noresume(), its SMP could race autosuspend.

For the BSG path, sas_smp_handler() is the only caller which may find
the host autosuspended: expander SMP requests do not go through any SCSI
device request queue, so nothing else in that path holds the host
awake. Resume it there with pm_runtime_resume_and_get() and check the
result.

Fixes: 3dbbbf656b850 ("scsi: libsas: Fix HA resume deadlock and hisi_sas disk-wake race")
Signed-off-by: Xingui Yang <yangxingui@huawei.com>
Reviewed-by: John Garry <john.garry@linux.dev>
Link: https://patch.msgid.link/20260928040234.992912-1-yangxingui@huawei.com
Signed-off-by: Martin K. Petersen (Oracle) <mkp@kernel.org>

Xingui Yang <yangxingui@huawei.com> · 2026-09-28 04:02 UTC · committed by Martin K. Petersen (Oracle)

Browse files
1 file changed, +12 −2
modified drivers/scsi/libsas/sas_expander.c
@@ -62,7 +62,11 @@ static int smp_execute_task_sg(struct domain_device *dev,
62 62 to_sas_internal(dev->port->ha->shost->transportt);
63 63 struct sas_ha_struct *ha = dev->port->ha;
64 64
65 - pm_runtime_get_sync(ha->dev);
65 + /*
66 + * Non-blocking: a sync resume here would deadlock against
67 + * sas_drain_work() during HA resume.
68 + */
69 + pm_runtime_get_noresume(ha->dev);
66 70 mutex_lock(&dev->ex_dev.cmd_mutex);
67 71 for (retry = 0; retry < 3; retry++) {
68 72 if (test_bit(SAS_DEV_GONE, &dev->state)) {
@@ -135,7 +139,7 @@ static int smp_execute_task_sg(struct domain_device *dev,
135 139 }
136 140 }
137 141 mutex_unlock(&dev->ex_dev.cmd_mutex);
138 - pm_runtime_put_sync(ha->dev);
142 + pm_runtime_put(ha->dev);
139 143
140 144 BUG_ON(retry == 3 && task != NULL);
141 145 sas_free_task(task);
@@ -2222,6 +2226,11 @@ void sas_smp_handler(struct bsg_job *job, struct Scsi_Host *shost,
2222 2226 goto out;
2223 2227 }
2224 2228
2229 + /* The host may have autosuspended, resume it here. */
2230 + ret = pm_runtime_resume_and_get(dev->port->ha->dev);
2231 + if (ret)
2232 + goto out;
2233 +
2225 2234 ret = smp_execute_task_sg(dev, job->request_payload.sg_list,
2226 2235 job->reply_payload.sg_list);
2227 2236 if (ret >= 0) {
@@ -2229,6 +2238,7 @@ void sas_smp_handler(struct bsg_job *job, struct Scsi_Host *shost,
2229 2238 rcvlen = job->reply_payload.payload_len - ret;
2230 2239 ret = 0;
2231 2240 }
2241 + pm_runtime_put(dev->port->ha->dev);
2232 2242
2233 2243 out:
2234 2244 bsg_job_done(job, ret, rcvlen);