[PATCH v3 06/11] scsi: mpt3sas: Stop polling devices when the unresponding scan is cancelled

From: Jeff Layton

Date: Wed Nov 18 2026 - 18:12:46 EST


After a hard reset, the MPT3SAS_REMOVE_UNRESPONDING_DEVICES event polls
each blocked device with TEST UNIT READY in
_scsih_ublock_io_all_device(). It retries a device for up to
command_retry_count seconds (144 by default).

If another hard reset starts during this time, it sets shost_recovery.
Then _scsih_fw_event_cleanup_queue() waits for the event in
cancel_work_sync(). While shost_recovery is set,
_scsih_wait_for_device_to_become_ready() returns DEVICE_RETRY and does
not test the device. Thus, before the reset can continue, the event
consumes all the retries of the device that it polls. The event then
marks that device deleted and offline, although it never tested the
device.

If the event is cancelled, or if the host is being removed, the event
already returns before it polls. Do the same check during polling, and
stop polling if the check is true. The remaining devices stay blocked.
The reset queues a new MPT3SAS_REMOVE_UNRESPONDING_DEVICES event, which
polls them after recovery ends. If the host is removed, the removal
deletes them.

Fixes: 72340fecd0c8 ("scsi: mpt3sas: Add configurable command retry limit for slow-to-respond devices")
Signed-off-by: Jeff Layton <jlayton@xxxxxxxxxx>
---
drivers/scsi/mpt3sas/mpt3sas_scsih.c | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 5d494ad12c54..5657bda241f7 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -4057,6 +4057,22 @@ _scsih_internal_device_unblock(struct scsi_device *sdev,
}
}

+/**
+ * _scsih_unresponding_scan_cancelled - should polling devices stop
+ * @ioc: per adapter object
+ *
+ * While the MPT3SAS_REMOVE_UNRESPONDING_DEVICES event polls devices, a
+ * hard reset or the removal of the host waits for it to finish, and the
+ * readiness check doesn't test devices during a reset.
+ *
+ * Return: true if the event is being cancelled, false otherwise.
+ */
+static bool
+_scsih_unresponding_scan_cancelled(struct MPT3SAS_ADAPTER *ioc)
+{
+ return READ_ONCE(ioc->remove_host) || READ_ONCE(ioc->fw_events_cleanup);
+}
+
/**
* _scsih_ublock_io_all_device - unblock every device
* @ioc: per adapter object
@@ -4114,7 +4130,13 @@ _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER *ioc, u8 no_turs)
pcie_device_put(pcie_device);
} while ((rc == DEVICE_RETRY || rc == DEVICE_START_UNIT ||
rc == DEVICE_STOP_UNIT || rc == DEVICE_RETRY_UA)
- && count++ < command_retry_count);
+ && count++ < command_retry_count &&
+ !_scsih_unresponding_scan_cancelled(ioc));
+ if (_scsih_unresponding_scan_cancelled(ioc)) {
+ /* a reset queues a new scan, which polls the rest */
+ scsi_device_put(sdev);
+ return;
+ }
sas_device_priv_data->block = 0;
if (rc != DEVICE_READY)
sas_device_priv_data->deleted = 1;

--
2.56.1