Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jeff Layton" <jlayton@kernel.org>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v5 12/12] scsi: mpt3sas: Time out delayed not-responding device blocks
Date: Mon, 30 Nov 2026 13:55:42 +0000	[thread overview]
Message-ID: <sashiko-outbox-241328@kernel.org> (raw)
In-Reply-To: <20261130-sas-abba-v5-12-487c39d1114f@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] scsi: mpt3sas: offline sdev unblocked without TUR via
  _scsih_block_io_device()
- [Medium] scsi: mpt3sas: _scsih_block_io_device() resets block_extends
  while still blocked
--

commit 726b1a93a28bd173eab435290e62be2f6c61a515
Author: Jeff Layton <jlayton@kernel.org>

scsi: mpt3sas: Time out delayed not-responding device blocks

This commit adds a per-device deadline and delayed work to expire
DELAY_NOT_RESPONDING device blocks so that sysfs scans cannot deadlock on
sas_host->lock or shost->scan_mutex waiting for the firmware event worker.

> diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
> index faba6e90243ae..455b0d9d0fd48 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c

[ ... ]

> @@ -4350,6 +4517,8 @@ _scsih_ublock_io_device_wait(struct MPT3SAS_ADAPTER *ioc, u64 sas_address,
>  		if (sas_target->sas_address != sas_address ||
>  		    sas_target->port != port)
>  			goto next;
> +		/* polling one device can outlast another's deadline */
> +		sas_device_priv_data->block_deadline = 0;
>  		if (sdev->sdev_state == SDEV_OFFLINE) {
>  			sas_device_priv_data->block = 1;
>  			sas_device_priv_data->deleted = 0;

[Severity: Medium]
Can an SDEV_OFFLINE device end up unblocked to SDEV_RUNNING without passing
a TUR check if a DELAY_NOT_RESPONDING event arrives during
_scsih_ublock_io_device_wait()?

The first loop in _scsih_ublock_io_device_wait() moves every SDEV_OFFLINE
sdev on the target to SDEV_RUNNING and then SDEV_BLOCK with block = 1,
deleted = 0, and block_deadline = 0 before the second loop polls each LUN
with TURs outside ioc->block_lock:

drivers/scsi/mpt3sas/mpt3sas_scsih.c:_scsih_ublock_io_device_wait() {
    ...
		if (sdev->sdev_state == SDEV_OFFLINE) {
			sas_device_priv_data->block = 1;
			sas_device_priv_data->deleted = 0;
			scsi_device_set_state(sdev, SDEV_RUNNING);
			scsi_internal_device_block_nowait(sdev);
		}
    ...
}

If a DELAY_NOT_RESPONDING event arrives for the handle during that polling
window, _scsih_block_io_device() sees block == 1 and block_deadline == 0 on
the formerly offline sdev, takes the early if (sas_device_priv_data->block)
branch before reaching the SDEV_OFFLINE check, increments block_seq, and
arms block_deadline.  __scsih_claim_block() then skips polling the sdev (or
_scsih_end_poll() bails out on block_seq mismatch without restoring
SDEV_OFFLINE if the TUR check fails), and when block_deadline expires,
_scsih_dnr_unblock_sdev() sets the device to SDEV_RUNNING untested.

[ ... ]

> @@ -4558,10 +4845,39 @@ _scsih_block_io_device(struct MPT3SAS_ADAPTER *ioc, u16 handle)
>  			goto next;
>  		if (sas_device_priv_data->sas_target->handle != handle)
>  			goto next;
> -		if (sas_device_priv_data->block)
> +		deadline = (jiffies + _scsih_dnr_block_timeout(ioc,
> +		    sas_device_priv_data->sas_target)) ?: 1;
> +		if (sas_device_priv_data->block) {
> +			if (!sas_device_priv_data->block_deadline) {
> +				/*
> +				 * The firmware event worker cleared the
> +				 * deadline to poll the device.  Make this a
> +				 * new block, which the worker leaves to its
> +				 * deadline and the firmware's next event.
> +				 */
> +				sas_device_priv_data->block_seq++;
> +				sas_device_priv_data->block_extends = 0;
> +				sas_device_priv_data->block_deadline = deadline;
> +				__scsih_dnr_unblock_work_by(ioc, deadline);
> +			} else if (sas_device_priv_data->block_extends <
> +				   MPT3SAS_DNR_BLOCK_MAX_EXTENDS) {
> +				/* a repeat DNR restarts the missing delay */
> +				sas_device_priv_data->block_extends++;
> +				sas_device_priv_data->block_deadline = deadline;
> +				__scsih_dnr_unblock_work_by(ioc, deadline);
> +			}
>  			goto next;
> +		}

[Severity: Medium]
Does resetting block_extends = 0 when block_deadline is 0 allow a flapping
drive to stay in SDEV_BLOCK past MPT3SAS_DNR_BLOCK_MAX_EXTENDS?

When a flapping link briefly reconnects and triggers
_scsih_ublock_io_device_wait() (or _scsih_ublock_io_all_device()), the
worker clears block_deadline = 0 while sas_device_priv_data->block is still
1.  If the link drops again and emits DELAY_NOT_RESPONDING while the worker
is polling that sdev or an earlier LUN in the pass, this branch increments
block_seq, resets block_extends to 0, and sets a new block_deadline.
Because block_seq changed and block_deadline is non-zero, __scsih_claim_block()
and _scsih_end_poll() do not unblock the sdev, so the sdev never leaves
SDEV_BLOCK yet its extension counter is reset on each flap cycle, allowing
it to stall scans for as long as the flapping continues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130-sas-abba-v5-0-487c39d1114f@kernel.org?part=12

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

Thread overview: 16+ 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 ` [PATCH v5 07/12] scsi: mpt3sas: Stop polling devices when the unresponding scan is cancelled Jeff Layton
2026-11-30 13:51   ` sashiko-bot
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:46   ` sashiko-bot
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
2026-11-30 13:55   ` sashiko-bot [this message]

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=sashiko-outbox-241328@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=jlayton@kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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