Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "HOYOUNG SEO" <hy50.seo@samsung.com>, linux-scsi@vger.kernel.org
Subject: Re: [PATCH v2 2/2] scsi: ufs: core: add is_sys_suspended state before recovery
Date: Fri, 23 Oct 2026 12:00:01 +0000	[thread overview]
Message-ID: <sashiko-outbox-182747@kernel.org> (raw)
In-Reply-To: <4eabe38e93631579a0cacda137a98053526fe030.1792755091.git.hy50.seo@samsung.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] scsi: ufs: core: ufshcd_err_handler() skips recovery after failed resume
--

commit c53108b377c62c7e01a8b52d302e15dfdce25f17
Author: HOYOUNG SEO <hy50.seo@samsung.com>

scsi: ufs: core: add is_sys_suspended state before recovery

This commit skips the early link recovery in ufshcd_err_handler() when
hba->is_sys_suspended is set so that error recovery waits on hba->host_sem
instead of racing with __ufshcd_wl_resume() during system resume.

> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index 0e6e593c24cfd..4b4d473530b16 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -7052,9 +7052,14 @@ static void ufshcd_err_handler(struct work_struct *work)
>  		 * runtime resume. This avoids potential deadlocks that could
>  		 * happen if we tried to resume the device while a PM operation
>  		 * is already in progress.
> +		 *
> +		 * During system resume, host_sem is held from
> +		 * ufshcd_wl_suspend() until ufshcd_wl_resume() returns, so wait
> +		 * for it below instead of recovering the link concurrently with
> +		 * the resume path.
>  		 */
>  		ufshcd_rpm_get_noresume(hba);
> -		if (hba->pm_op_in_progress) {
> +		if (hba->pm_op_in_progress && !hba->is_sys_suspended) {

[Severity: High]
The commit message notes that if system resume fails, hba->is_sys_suspended
stays set and ufshcd_err_handler() performs a full recovery as usual.
However, when ufshcd_err_handler() wakes from down(&hba->host_sem) after
ufshcd_wl_resume() -> __ufshcd_wl_resume() fails, it immediately checks
ufshcd_err_handling_should_stop():

drivers/ufs/core/ufshcd.c:ufshcd_err_handler() {
	down(&hba->host_sem);
	spin_lock_irqsave(&hba->host->host_lock, flags);
	if (ufshcd_err_handling_should_stop(hba)) {
		if (hba->ufshcd_state != UFSHCD_STATE_ERROR)
			hba->ufshcd_state = UFSHCD_STATE_OPERATIONAL;
		spin_unlock_irqrestore(&hba->host->host_lock, flags);
		up(&hba->host_sem);
		return;
	}
}

where ufshcd_err_handling_should_stop() is defined as:

drivers/ufs/core/ufshcd.c:ufshcd_err_handling_should_stop() {
	return (!hba->is_powered || hba->shutting_down ||
		!hba->ufs_device_wlun ||
		hba->ufshcd_state == UFSHCD_STATE_ERROR ||
		(!(hba->saved_err || hba->saved_uic_err || hba->force_reset ||
		   ufshcd_is_link_broken(hba))));
}

If ufshcd_uic_hibern8_exit() fails in __ufshcd_wl_resume() and the subsequent
call to ufshcd_link_recovery() also fails, ufshcd_link_recovery() sets
hba->ufshcd_state = UFSHCD_STATE_ERROR even though it restores hba->saved_err
and hba->saved_uic_err:

drivers/ufs/core/ufshcd.c:ufshcd_link_recovery() {
	...
	spin_lock_irqsave(&hba->host->host_lock, flags);
	if (ret) {
		hba->ufshcd_state = UFSHCD_STATE_ERROR;
		hba->saved_err |= saved_err;
		hba->saved_uic_err |= saved_uic_err;
	}
	ufshcd_clear_eh_in_progress(hba);
	spin_unlock_irqrestore(&hba->host->host_lock, flags);
}

Alternatively, if ufshcd_link_recovery() succeeds in __ufshcd_wl_resume()
(clearing hba->saved_err, hba->saved_uic_err, and hba->force_reset) and a
later step in __ufshcd_wl_resume() such as ufshcd_set_dev_pwr_mode() fails,
the saved error flags remain zero.

In both cases, doesn't ufshcd_err_handling_should_stop() evaluate to true and
cause ufshcd_err_handler() to return immediately after acquiring
hba->host_sem, skipping full recovery and ufshcd_recover_pm_error() while
leaving the HBA in UFSHCD_STATE_ERROR or stuck with hba->is_sys_suspended
set?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1792755091.git.hy50.seo@samsung.com?part=2

  reply	other threads:[~2026-10-23 12:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20261023113905epcas2p36f5e7bf1d3954ac8c666a25a922fc031@epcas2p3.samsung.com>
2026-10-23 11:34 ` [PATCH v2 0/2] scsi: ufs: core: Avoid redundant link recovery during system resume HOYOUNG SEO
2026-10-23 11:34   ` [PATCH v2 1/2] scsi: ufs: core: Clear saved errors in ufshcd_link_recovery HOYOUNG SEO
2026-10-23 11:34   ` [PATCH v2 2/2] scsi: ufs: core: add is_sys_suspended state before recovery HOYOUNG SEO
2026-10-23 12:00     ` sashiko-bot [this message]
2026-10-26  4:17       ` hoyoung seo

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-182747@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=hy50.seo@samsung.com \
    --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