[PATCH v6 0/3] scsi: ufs: core: Avoid redundant link recovery from the error handler during PM

From: HOYOUNG SEO

Date: Thu Nov 05 2026 - 21:20:53 EST


If a LINERESET is reported and the hibern8 exit fails during system
resume, both ufshcd_err_handler() and __ufshcd_wl_resume() call
ufshcd_link_recovery(), and the two recoveries are not serialized.

Patch 1 makes ufshcd_link_recovery() clear the saved errors like
ufshcd_reset_and_restore() does, so the error handler does not act on
errors that have already been recovered.

Patch 2 restricts the early link recovery in ufshcd_err_handler(), which
does not hold host_sem, to runtime PM. For system PM the error handler
now waits for host_sem, and for shutdown and poweroff it stops.

Patch 3 sets hba->shutting_down in ufshcd_wl_poweroff() like
ufshcd_wl_shutdown() does, so that the error handler stops during
poweroff.

The early link recovery is kept for runtime suspend and runtime resume.
During runtime resume it can still run concurrently with
__ufshcd_wl_resume(). Removing it there needs a closer look at the
deadlock that it avoids.

Changes in v6:
- Go back to a single flag for runtime PM, hba->runtime_pm_in_progress,
instead of the system PM flag of v5, and set it in
ufshcd_wl_runtime_suspend() and ufshcd_wl_runtime_resume(). The error
handler no longer reads two variables that are not updated atomically
(Sashiko review of v5).
- Add patch 2. With patch 3, poweroff no longer takes the early path,
and ufshcd_wl_poweroff() holds neither host_sem nor sets
hba->shutting_down (Sashiko review of v4).

Changes in v5:
- Patch 2: track system PM (hba->system_pm_in_progress) instead of
runtime PM, so that the early link recovery is only skipped where
host_sem is held.

Changes in v4 (as suggested by Bart Van Assche):
- Replace the is_sys_suspended check of v3 patch 2 with a flag set in
__ufshcd_wl_suspend() and __ufshcd_wl_resume(), which also covers a
system suspend failure.
- Add Fixes: tags.
- Do not serialize ufshcd_link_recovery() with a mutex: it calls
ufshcd_probe_hba(), and a device command timing out inside it ends up
in ufshcd_eh_timed_out(), which calls ufshcd_link_recovery() again.

Changes in v3:
- Patch 2: reword the commit message only, no code change. The error
handler does not always run a full recovery after a failed system
resume; it stops according to ufshcd_err_handling_should_stop() (e.g.
in UFSHCD_STATE_ERROR). Describe this behavior and refer to the commit
that added the early link recovery (Sashiko review).
- Patch 1: no change.

Changes in v2:
- Add patch 1. As pointed out by the Sashiko review, saved_err and
saved_uic_err are still set after the resume path recovered the link,
so with v1 alone ufshcd_err_handler() would run a redundant recovery
once host_sem is released.
- Patch 2: describe the race and the system/runtime PM difference in
the commit message, and add a comment.

v5: https://lore.kernel.org/linux-scsi/cover.1793865172.git.hy50.seo@xxxxxxxxxxx/
v4: https://lore.kernel.org/linux-scsi/cover.1793851432.git.hy50.seo@xxxxxxxxxxx/
v3: https://lore.kernel.org/linux-scsi/cover.1792989286.git.hy50.seo@xxxxxxxxxxx/
v2: https://lore.kernel.org/linux-scsi/cover.1792755091.git.hy50.seo@xxxxxxxxxxx/

HOYOUNG SEO (3):
scsi: ufs: core: Clear saved errors in ufshcd_link_recovery()
scsi: ufs: core: Limit early link recovery in the error handler to
runtime PM
scsi: ufs: core: Set shutting_down in ufshcd_wl_poweroff()

drivers/ufs/core/ufshcd.c | 30 ++++++++++++++++++++++++++++--
include/ufs/ufshcd.h | 2 ++
2 files changed, 30 insertions(+), 2 deletions(-)

--
2.34.1