mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@kernel.org>
To: Sathya Prakash <sathya.prakash@broadcom.com>,
	 Sreekanth Reddy <sreekanth.reddy@broadcom.com>,
	 Suganath Prabu Subramani <suganath-prabu.subramani@broadcom.com>,
	 Ranjan Kumar <ranjan.kumar@broadcom.com>,
	 "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
	 "Martin K. Petersen" <mkp@kernel.org>,
	 Nagalakshmi Nandigama <Nagalakshmi.Nandigama@lsi.com>,
	 James Bottomley <JBottomley@Parallels.com>
Cc: Keith Busch <kbusch@kernel.org>,
	 Sreekanth Reddy <Sreekanth.Reddy@lsi.com>,
	MPT-FusionLinux.pdl@broadcom.com,  linux-scsi@vger.kernel.org,
	linux-kernel@vger.kernel.org,  Jeff Layton <jlayton@kernel.org>
Subject: [PATCH v5 07/12] scsi: mpt3sas: Stop polling devices when the unresponding scan is cancelled
Date: Mon, 30 Nov 2026 08:21:09 -0500	[thread overview]
Message-ID: <20261130-sas-abba-v5-7-487c39d1114f@kernel.org> (raw)
In-Reply-To: <20261130-sas-abba-v5-0-487c39d1114f@kernel.org>

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.
While shost_recovery is set, _scsih_wait_for_device_to_become_ready()
returns DEVICE_RETRY and does not test the device, but each of these
checks still counts as a retry. The reset can spend a minute or more
in mpt3sas_wait_for_commands_to_complete() and
mpt3sas_base_make_ioc_ready() before it calls
_scsih_fw_event_cleanup_queue(), and that function then waits for the
event in cancel_work_sync(). Thus the event can consume all the retries
of the device that it polls. The event then marks that device deleted
and offline, although it never tested the device.

Don't count a check while shost_recovery is set. If the reset fails
before it cancels the event, polling continues after the reset.

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.

Also skip the rest of the event in that case. The reset that waits for
the event holds reset_in_progress_mutex, and the IOC is not yet
operational. Each config request in
_scsih_scan_for_devices_after_reset() would then stall the reset for
its timeout. While the driver is loading, mpt3sas_wait_for_ioc()
returns -ETIME immediately, and _config_request() calls
mpt3sas_base_hard_reset_handler(), which deadlocks on
reset_in_progress_mutex.

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

diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 2e2e66ff0196..7d8411d1eb28 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -4075,6 +4075,21 @@ _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.
+ *
+ * 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
@@ -4131,8 +4146,16 @@ _scsih_ublock_io_all_device(struct MPT3SAS_ADAPTER *ioc, u8 no_turs)
 			if (pcie_device)
 				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);
+		    rc == DEVICE_STOP_UNIT || rc == DEVICE_RETRY_UA) &&
+			/* a reset skips the check, so it doesn't count */
+			(READ_ONCE(ioc->shost_recovery) ||
+			 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;
@@ -12124,6 +12147,14 @@ _mpt3sas_fw_work(struct MPT3SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
 			ssleep(1);
 		}
 		_scsih_remove_unresponding_devices(ioc);
+		/*
+		 * The reset waiting for this event holds the IOC out of the
+		 * operational state, so the config requests below would stall
+		 * it, or try to reset the IOC again.  The reset queues a new
+		 * scan, and a removal deletes the devices.
+		 */
+		if (_scsih_unresponding_scan_cancelled(ioc))
+			goto out;
 		_scsih_del_dirty_vphy(ioc);
 		_scsih_del_dirty_port_entries(ioc);
 		if (ioc->is_gen35_ioc)

-- 
2.56.1


  parent reply	other threads:[~2026-11-30 13:21 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 13:21 [PATCH v5 00/12] scsi: mpt3sas: Fix delayed not-responding block deadlock and related bugs Jeff Layton
2026-11-30 13:21 ` [PATCH v5 01/12] scsi: mpt3sas: Don't leave requeued firmware events pending at teardown Jeff Layton
2026-11-30 13:21 ` [PATCH v5 02/12] scsi: mpt3sas: Disarm a requeued event's timer when it leaves the event list Jeff Layton
2026-11-30 13:21 ` [PATCH v5 03/12] scsi: mpt3sas: Hold event references while cleaning up the event queue Jeff Layton
2026-11-30 13:21 ` [PATCH v5 04/12] scsi: mpt3sas: Requeue topology events only for busy devices Jeff Layton
2026-11-30 13:21 ` [PATCH v5 05/12] scsi: mpt3sas: Fix pcie_device leak in _scsih_ublock_io_device_wait() Jeff Layton
2026-11-30 13:21 ` [PATCH v5 06/12] scsi: mpt3sas: Restore unblock retry " Jeff Layton
2026-11-30 13:21 ` Jeff Layton [this message]
2026-11-30 13:21 ` [PATCH v5 08/12] scsi: mpt3sas: Reset the TUR retry count for each device Jeff Layton
2026-11-30 13:21 ` [PATCH v5 09/12] scsi: mpt3sas: Cache the missing delays the IOC actually uses Jeff Layton
2026-11-30 13:21 ` [PATCH v5 10/12] scsi: mpt3sas: Serialize interrupt-time sdev block with hostdata teardown Jeff Layton
2026-11-30 13:21 ` [PATCH v5 11/12] scsi: mpt3sas: Don't use freed hostdata while polling devices Jeff Layton
2026-11-30 13:21 ` [PATCH v5 12/12] scsi: mpt3sas: Time out delayed not-responding device blocks Jeff Layton

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=20261130-sas-abba-v5-7-487c39d1114f@kernel.org \
    --to=jlayton@kernel.org \
    --cc=JBottomley@Parallels.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=MPT-FusionLinux.pdl@broadcom.com \
    --cc=Nagalakshmi.Nandigama@lsi.com \
    --cc=Sreekanth.Reddy@lsi.com \
    --cc=kbusch@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=mkp@kernel.org \
    --cc=ranjan.kumar@broadcom.com \
    --cc=sathya.prakash@broadcom.com \
    --cc=sreekanth.reddy@broadcom.com \
    --cc=suganath-prabu.subramani@broadcom.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

all inboxes | Powered by JetHome®