From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796044908; b=x2r2fnou5VW3mwepDPBzFHk3TfJRjt6xTfQ6dsZxOuqC3GUVQkV+VB/i1gmN2+HY28a/ s1ggY07Tgody+0nqeIa4YyIH8XxvYoy4hSXrntZy5Zhb33NjPt92zJ4ATh3qvBs2Wym0x uS8qX141MGyulZ4V4wya1tI2yB1nBrJvqa4/T9PjXdWGK+fh1xpFs0jB+v2G5C/rzgqTi XnHOxD4se5idMKTvcYv6v2zHh7YSdbTnTPi4VQdxkiNKnx1zaquta1YrZoITzMLUZDtgX avhfe8fd2h+mzDCJIf0u1/833BqWQ5QCPCJpV6pHejz2nrw02jS2q6aqvdZXFzJmDQA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796044908; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=K3Rr+3dFPCxHh4rgKDGaYT0GlnNMLhMwDiVoSo9kJbk=; b=QJEqz+rnHAsWIfF/VYPvk0ElVYi3oBHwv2BhujgsUVb8QrL/ZqcGtOnacalxWjraoY9e m36HFRMPUGv+X62oFZt3cZQmsoEwOo2DpYq3XLRW0rWDhOWBGtomaznG+MU5CpVUjr8Fi 3gbaYIgT4SnE2+0IM9jYw5EelUuQCHyAycHMDGOeAwXYM9XJ78JrfrD0ptsMaPzpDfEha DcHX1BRHbQHXI+6SoRiOmQy0ZCU0x3FKLqxhaG9xSxco2eB2v3fH4kPkB17ShdEnRlniS tqQBo+5zd0ZL7KxfEvOpRBjgaZFwVnWKx/AP83RbtWSwuHtCez2LRLR5dVRL917T3Xg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=YUw9CWn3; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5CBE160A262D; Mon, 30 Nov 2026 13:21:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=YUw9CWn3 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D37221F00A15; Mon, 30 Nov 2026 13:21:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796044907; bh=K3Rr+3dFPCxHh4rgKDGaYT0GlnNMLhMwDiVoSo9kJbk=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=YUw9CWn3VODj8/aoEzKQf1aGuMOH2sUJHLfpt7BGcIFYwraJSfx1uV/2wfwYCp5vG 5ReupxvfkoUgNNLMa1IqbR70/Qymb9jcaYmXXuzGsmFj9f6K5kNpvGGhs02DaDN4Ke HwLVJCA1zjFaYhYl0523p4kCKe2rEdUU9FhQ4bH1lMaKa38IXieP9tTEtFUHU+lBHn TBX9eKs9F2qTSRFcbUlWY4jOixWnLi7rF9xP651MFYt4KB3Ehua9eoY/2fIdrNpGLS XX2SC6SWPGtlUPkoV4YKfIgL46rfoLtESfsbVpWJK3xzkbfBiHgh6TJ7CxGlfpU8PC Guv/DxEEiSG3Q== From: Jeff Layton Date: Mon, 30 Nov 2026 08:21:09 -0500 Subject: [PATCH v5 07/12] scsi: mpt3sas: Stop polling devices when the unresponding scan is cancelled X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261130-sas-abba-v5-7-487c39d1114f@kernel.org> References: <20261130-sas-abba-v5-0-487c39d1114f@kernel.org> In-Reply-To: <20261130-sas-abba-v5-0-487c39d1114f@kernel.org> To: Sathya Prakash , Sreekanth Reddy , Suganath Prabu Subramani , Ranjan Kumar , "James E.J. Bottomley" , "Martin K. Petersen" , Nagalakshmi Nandigama , James Bottomley Cc: Keith Busch , Sreekanth Reddy , MPT-FusionLinux.pdl@broadcom.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4456; i=jlayton@kernel.org; h=from:subject:message-id; bh=SNB+YrH9V4mHSVIM8diX+YePSo0W8U3KsmSn6b/Ur7k=; b=owEBbQKS/ZANAwAKAQAOaEEZVoIVAcsmYgBrDXhc6moFhTTvuHlBv8opj2zSP8fEXnqhIDHO5 cisPpRpfAeJAjMEAAEKAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCaw14XAAKCRAADmhBGVaC FYkrD/9oD8VC0VNP1Wwf44D9KBr7zAdHqt4i/DdRnXQi6NhsGDFiBkQBoOiZHtP1B2zvZYafw2b 2DySSG1R11TmwhUT15iRjR97Zvg+ReaTWyDMV6JLWAuLmcFYjtJ2OTc7TWxRF8IXKfB5lii/CIA vHmXBZ96V72xKsjP83YHgKhYAAKqgaqc9yoy4Wwnl2drzdRaxthupdPjdKAoaGx4dLwYhAyOY4Z nAYEI24dyzXIgOd3VMob43LabFPClQHgFISHz+Kmgc0kcbNXh1cCx8NkV6lrpBUNW7e9cJLSTmX 4Ng55haF69Og6XXznR5WZGh+a/WmrMiVGhdGuAX5sNY7iW4KUhloR+KBE8Uspd8A+ft4si4je2g HLmjCGPa8RldD2+hb1+lgI0lzkOKTiptkrCWek3Cp55ZEIlGSBvUa/CW6Y7oS/3Y5y2tcp6yfqM TaOVjs4+MR7atN7+ry/rycZPz1wHWdcKw+61XAlMU4MbmeaHuN5DQuJJJ53rrQA1OIYJqXMncsl aUWffPhJiaWTFCwJ2/k2/eulVGiF+7jPfXjpOW1/y1TcVE58kr013CuPvlYbIFVKR3+nMC6zB8Y lMpKcfjTEbY18IZ2ukraMy2FWWOZjpaXj3jkXsE/jWijmos8WrdHXmIpqFSfFwP59kNttNyzWXD 3CkNG//MsP4XwgQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 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 --- 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