From: sashiko-bot@kernel.org
To: "Vladimir Zapolskiy" <vladimir.zapolskiy@linaro.org>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH 3/3] scsi: ufs: core: Enter hibern8 before ufshcd_suspend() gates the clocks
Date: Thu, 03 Dec 2026 00:14:17 +0000 [thread overview]
Message-ID: <sashiko-outbox-246816@kernel.org> (raw)
In-Reply-To: <20261202235113.1632498-4-vladimir.zapolskiy@linaro.org>
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] scsi: ufs: core: link state mismatch between vops suspend and
resume
- [High] scsi: ufs: core: broken link state on hibern8 failure in
ufshcd_suspend()
- [Medium] scsi: ufs: core: link state mismatch in
ufshcd_rpm_ok_for_spm()
- [Medium] scsi: ufs: core: missing hibern8 rollback in ufshcd_suspend()
error path
- [Low] scsi: ufs: core: Fixes tag cites 57d104c153d3 instead of
1ab27c9cf8b6
--
commit 6a05a39d71fec3d3537f39c83c27329442fd5d45
Author: Vladimir Zapolskiy <vladimir.zapolskiy@linaro.org>
> scsi: ufs: core: Enter hibern8 before ufshcd_suspend() gates the clocks
>
> Hosts with UFSHCD_CAP_HIBERN8_WITH_CLK_GATING may gate their clocks only
> with the link in hibern8, and if ufshcd_gate_work() complies to it,
> ufshcd_suspend() does not, because with rpm_lvl 0 or 2 it turns the
> clocks off under an active link. As a result no request then completes
> after the next resume until the host is reset, and every access after
> a runtime suspend stalls for 8 to 11 seconds.
>
> Put an active link into hibern8 first; the W-LUN resume exits it again.
> If that fails, return -EBUSY to keep the host staying active without
> a runtime PM error.
>
> Fixes: 57d104c153d3 ("ufs: add UFS power management support")
> Signed-off-by: Vladimir Zapolskiy <vladimir.zapolskiy@linaro.org>
[Severity: Low]
57d104c153d3 ("ufs: add UFS power management support") predates UFS clock
gating and UFSHCD_CAP_HIBERN8_WITH_CLK_GATING. Should the Fixes: tag cite
1ab27c9cf8b6 ("ufs: Add support for clock gating") instead?
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index eedd74d7dbddb..b96f8a5592b17 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -10809,6 +10809,13 @@ static int ufshcd_suspend(struct ufs_hba *hba)
>
> if (!hba->is_powered)
> return 0;
> +
> + if (ufshcd_can_hibern8_during_gating(hba) &&
> + ufshcd_is_link_active(hba)) {
> + if (ufshcd_uic_hibern8_enter(hba))
> + return -EBUSY;
[Severity: High]
Can a failure in ufshcd_uic_hibern8_enter() here leave the link in
UIC_LINK_BROKEN_STATE and cause the next W-LUN resume to fail?
Unlike __ufshcd_wl_suspend(), ufshcd_suspend() runs after the W-LUN has
suspended and cleared hba->pm_op_in_progress to false. When
ufshcd_uic_hibern8_enter() fails with !hba->pm_op_in_progress,
ufshcd_uic_pwr_ctrl() marks the link broken and schedules fatal error
handling:
drivers/ufs/core/ufshcd.c:ufshcd_uic_pwr_ctrl() {
...
if (ret && !hba->pm_op_in_progress) {
ufshcd_set_link_broken(hba);
ufshcd_schedule_eh_work(hba);
}
...
}
When __ufshcd_wl_resume() subsequently runs (either during system suspend
rollback while eh_work is blocked on hba->host_sem, or from
ufshcd_err_handling_prepare() -> ufshcd_rpm_get_sync() after runtime
suspend returns -EBUSY), it only checks ufshcd_is_link_hibern8() and
ufshcd_is_link_off(), skipping link recovery for UIC_LINK_BROKEN_STATE.
At PM level 2, __ufshcd_wl_resume() then calls ufshcd_set_dev_pwr_mode()
while hba->ufshcd_state is UFSHCD_STATE_EH_SCHEDULED_FATAL, and
ufshcd_queuecommand() immediately fails the START_STOP_UNIT command with
DID_BAD_TARGET.
> + ufshcd_set_link_hibern8(hba);
> + }
[Severity: High]
Does transitioning the link to Hibern8 in ufshcd_suspend() break link
state symmetry between ufshcd_vops_suspend() and ufshcd_vops_resume()?
At PM levels 0 and 2, __ufshcd_wl_suspend() runs ufshcd_vops_suspend()
while hba->uic_link_state is still UIC_LINK_ACTIVE_STATE, before
ufshcd_suspend() enters Hibern8 and sets UIC_LINK_HIBERN8_STATE. On
resume, __ufshcd_wl_resume() runs ufshcd_vops_resume() before exiting
Hibern8, so vops->resume() sees UIC_LINK_HIBERN8_STATE.
In drivers/ufs/host/ufs-exynos.c, exynos_ufs_suspend() and
exynos_ufs_resume() both gate PHY power on !ufshcd_is_link_active(hba):
drivers/ufs/host/ufs-exynos.c:exynos_ufs_suspend() {
...
if (!ufshcd_is_link_active(hba))
phy_power_off(ufs->phy);
return 0;
}
drivers/ufs/host/ufs-exynos.c:exynos_ufs_resume() {
...
if (!ufshcd_is_link_active(hba))
phy_power_on(ufs->phy);
return 0;
}
exynos_ufs_suspend() skips phy_power_off(), while exynos_ufs_resume()
calls phy_power_on(), leaking a ufs->phy->power_count reference on every
suspend/resume cycle. ufs_mtk_suspend() / ufs_mtk_resume() and
ufs_qcom_suspend() have similar checks on ufshcd_is_link_hibern8() and
ufshcd_is_link_active().
[Severity: Medium]
Does setting hba->uic_link_state to UIC_LINK_HIBERN8_STATE at rpm_lvl 0
or 2 also break ufshcd_rpm_ok_for_spm() during system suspend preparation?
drivers/ufs/core/ufshcd.c:ufshcd_rpm_ok_for_spm() {
...
link_state = ufs_get_pm_lvl_to_link_pwr_state(hba->spm_lvl);
res = pm_runtime_suspended(dev) &&
hba->curr_dev_pwr_mode == dev_pwr_mode &&
hba->uic_link_state == link_state &&
!hba->dev_info.b_rpm_dev_flush_capable;
...
}
For PM levels 0 and 2, ufs_get_pm_lvl_to_link_pwr_state() returns
UIC_LINK_ACTIVE_STATE. If spm_lvl is 0 or 2, hba->uic_link_state is now
UIC_LINK_HIBERN8_STATE, so ufshcd_rpm_ok_for_spm() returns false and
__ufshcd_suspend_prepare() forces a runtime resume just to re-suspend into
the same state. Conversely, if spm_lvl is 1 or 3, hba->uic_link_state now
matches UIC_LINK_HIBERN8_STATE and ufshcd_rpm_ok_for_spm() returns true,
skipping system suspend even though __ufshcd_wl_suspend() and
ufshcd_vops_suspend() only ran the active-link path.
> /*
> * Disable the host irq as host controller as there won't be any
> * host controller transaction expected till resume.
> */
> ufshcd_disable_irq(hba);
> ret = ufshcd_setup_clocks(hba, false);
> if (ret) {
> ufshcd_enable_irq(hba);
> goto out;
> }
[Severity: Medium]
If ufshcd_setup_clocks(hba, false) fails here, does ufshcd_suspend()
return an error while leaving the link in Hibern8 and hba->uic_link_state
set to UIC_LINK_HIBERN8_STATE? Also, returning -EBUSY directly when
ufshcd_uic_hibern8_enter() fails bypasses the out: label and skips logging
UFS_EVT_SUSPEND_ERR via ufshcd_update_evt_hist().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202235113.1632498-1-vladimir.zapolskiy@linaro.org?part=3
next prev parent reply other threads:[~2026-12-03 0:14 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 23:51 [PATCH 0/3] scsi: ufs: core: Fix hibern8 and clock gating state handling Vladimir Zapolskiy
2026-12-02 23:51 ` [PATCH 1/3] scsi: ufs: core: Set CLKS_ON when ufshcd_gate_work() keeps clocks on Vladimir Zapolskiy
2026-12-02 23:51 ` [PATCH 2/3] scsi: ufs: core: Enter hibern8 in ufshcd_gate_work() only on an active link Vladimir Zapolskiy
2026-12-02 23:51 ` [PATCH 3/3] scsi: ufs: core: Enter hibern8 before ufshcd_suspend() gates the clocks Vladimir Zapolskiy
2026-12-03 0:14 ` sashiko-bot [this message]
2026-12-03 0:56 ` Vladimir Zapolskiy
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-246816@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=vladimir.zapolskiy@linaro.org \
/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