From: sashiko-bot@kernel.org
To: "Xingui Yang" <yangxingui@huawei.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH] scsi: libsas: Fix SMP IO deadlock during HA resume
Date: Wed, 26 Aug 2026 03:40:29 +0000 [thread overview]
Message-ID: <20260826034029.B2CEB1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260826032845.1632348-1-yangxingui@huawei.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [High] Bypassing PM reference counting via a global state flag creates a race condition where concurrent independent threads can submit SMP I/Os without holding a PM reference, risking premature hardware suspend.
Pre-existing issues:
- [High] The return value of pm_runtime_get_sync() is ignored, which can lead to accessing powered-off hardware on failure.
--
commit ecfcb25c960bd684b2b9ddb5e30db0c49c3a78b4
Author: Xingui Yang <yangxingui@huawei.com>
scsi: libsas: Fix SMP IO deadlock during HA resume
This commit attempts to fix a deadlock during sas_resume_ha() by
skipping pm_runtime_get_sync() and pm_runtime_put_sync() when the
SAS_HA_RESUMING flag is set. It targets expander-attached ATA devices
triggered by ATA EH via sas_phy_reset().
> diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c
> index 811c9eb4fef11..77ae2ae7b2c45 100644
> --- a/drivers/scsi/libsas/sas_expander.c
> +++ b/drivers/scsi/libsas/sas_expander.c
> @@ -61,8 +61,17 @@ static int smp_execute_task_sg(struct domain_device *dev,
> struct sas_internal *i =
> to_sas_internal(dev->port->ha->shost->transportt);
> struct sas_ha_struct *ha = dev->port->ha;
> -
> - pm_runtime_get_sync(ha->dev);
> + bool skip_pm = test_bit(SAS_HA_RESUMING, &ha->state);
[Severity: High]
Does bypassing PM reference counting via a global state flag create a race
condition here in smp_execute_task_sg() in drivers/scsi/libsas/sas_expander.c?
Concurrent independent threads could submit SMP I/Os without holding a PM
reference, risking premature hardware suspend.
For example, if a concurrent userspace SMP request via bsg executes during
sas_resume_ha(), smp_execute_task_sg() could evaluate test_bit for
SAS_HA_RESUMING to true and skip pm_runtime_get_sync(). Meanwhile,
sas_resume_ha() might unblock SCSI requests via scsi_unblock_requests() and
eventually clear SAS_HA_RESUMING, dropping the resume thread's PM reference.
Could this allow the device to autosuspend while the BSG thread is still
waiting for the SMP IO to complete, potentially causing a system crash, bus
fault, or IO timeout?
> +
> + /*
> + * Skip PM get/put during HA resume to avoid deadlock: the host is
> + * RPM_RESUMING and the drain waits for this SMP IO to finish, but
> + * pm_runtime_get_sync() would block on RPM_RESUMING. Safe because
> + * hardware is already initialized by the LLDD before call
> + * sas_resume_ha().
> + */
> + if (!skip_pm)
> + pm_runtime_get_sync(ha->dev);
[Severity: High]
This isn't a bug introduced by this patch, but the return value of
pm_runtime_get_sync() is ignored here in smp_execute_task_sg().
If pm_runtime_get_sync() fails to resume the device due to a hardware fault
or disabled runtime PM, the function will blindly proceed to allocate and
issue SMP tasks to the LLDD. Accessing suspended or unclocked hardware
registers can cause unrecoverable bus faults or system lockups.
Should the negative error code be checked before proceeding to access
hardware?
> mutex_lock(&dev->ex_dev.cmd_mutex);
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260826032845.1632348-1-yangxingui@huawei.com?part=1
next prev parent reply other threads:[~2026-08-26 3:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-26 3:28 [PATCH] scsi: libsas: Fix SMP IO deadlock during HA resume Xingui Yang
2026-08-26 3:40 ` sashiko-bot [this message]
2026-09-11 1:00 ` yangxingui
2026-09-16 13:58 ` John Garry
2026-09-17 9:36 ` yangxingui
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=20260826034029.B2CEB1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=yangxingui@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.