From: HOYOUNG SEO <hy50.seo@samsung.com>
To: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
bvanassche@acm.org, mkp@kernel.org, martin.petersen@oracle.com,
stanleyjhu@google.com, alim.akhtar@samsung.com,
kwangwon.min@samsung.com, kwmad.kim@samsung.com,
cpgs@samsung.com, h10.kim@samsung.com
Cc: HOYOUNG SEO <hy50.seo@samsung.com>
Subject: [PATCH v7 0/3] scsi: ufs: core: Avoid redundant link recovery from the error handler during PM
Date: Fri, 6 Nov 2026 15:11:15 +0900 [thread overview]
Message-ID: <cover.1793943246.git.hy50.seo@samsung.com> (raw)
In-Reply-To: <CGME20261106061544epcas2p4b1ebab9e2c0e041ee52ff724caf8a9e8@epcas2p4.samsung.com>
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 makes ufshcd_wl_poweroff() hold host_sem like
ufshcd_wl_suspend() does, so that the error handler waits for it, and
fixes the unbalanced release of host_sem if hibernation is aborted.
Patch 3 restricts the early link recovery in ufshcd_err_handler(), which
does not hold host_sem, to runtime PM. For system PM and poweroff the
error handler now waits for host_sem, and for shutdown it stops.
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 v7:
- Patch 1: add Reviewed-by: Bart Van Assche.
- Patch 2 (was v6 patch 3): hold host_sem in ufshcd_wl_poweroff() until
ufshcd_wl_resume() releases it, instead of setting hba->shutting_down,
as suggested by Bart Van Assche. This fixes the failure of
ufs_mtk_system_suspend() and the state left behind when hibernation is
aborted, and the unbalanced release of host_sem. Add a Fixes: tag and
move the patch before the one that depends on it, so that the series
stays bisectable.
- Patch 3 (was v6 patch 2): use READ_ONCE() and WRITE_ONCE() for
hba->runtime_pm_in_progress, and describe the behavior change during
shutdown in the commit message.
Changes in v6:
- Go back to a single flag instead of the system PM flag of v5, and set
it in the runtime PM callbacks. The error handler no longer reads two
variables that are not updated atomically (Sashiko review of v5).
- Add a patch that sets hba->shutting_down in ufshcd_wl_poweroff()
(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.
v6: https://lore.kernel.org/linux-scsi/cover.1793931113.git.hy50.seo@samsung.com/
v5: https://lore.kernel.org/linux-scsi/cover.1793865172.git.hy50.seo@samsung.com/
v4: https://lore.kernel.org/linux-scsi/cover.1793851432.git.hy50.seo@samsung.com/
v3: https://lore.kernel.org/linux-scsi/cover.1792989286.git.hy50.seo@samsung.com/
v2: https://lore.kernel.org/linux-scsi/cover.1792755091.git.hy50.seo@samsung.com/
HOYOUNG SEO (3):
scsi: ufs: core: Clear saved errors in ufshcd_link_recovery()
scsi: ufs: core: Hold host_sem in ufshcd_wl_poweroff()
scsi: ufs: core: Limit early link recovery in the error handler to
runtime PM
drivers/ufs/core/ufshcd.c | 28 ++++++++++++++++++++++++++--
include/ufs/ufshcd.h | 2 ++
2 files changed, 28 insertions(+), 2 deletions(-)
--
2.34.1
next parent reply other threads:[~2026-11-06 6:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20261106061544epcas2p4b1ebab9e2c0e041ee52ff724caf8a9e8@epcas2p4.samsung.com>
2026-11-06 6:11 ` HOYOUNG SEO [this message]
[not found] ` <CGME20261106061545epcas2p2e16985621e8852e675e5a557857dca54@epcas2p2.samsung.com>
2026-11-06 6:11 ` [PATCH v7 1/3] scsi: ufs: core: Clear saved errors in ufshcd_link_recovery() HOYOUNG SEO
[not found] ` <CGME20261106061546epcas2p3b0d54ffe9fcea407f7d0e27ed579de0d@epcas2p3.samsung.com>
2026-11-06 6:11 ` [PATCH v7 2/3] scsi: ufs: core: Hold host_sem in ufshcd_wl_poweroff() HOYOUNG SEO
2026-11-06 21:56 ` Bart Van Assche
[not found] ` <CGME20261106061547epcas2p40541421c139d758cdc3633302634d29b@epcas2p4.samsung.com>
2026-11-06 6:11 ` [PATCH v7 3/3] scsi: ufs: core: Limit early link recovery in the error handler to runtime PM HOYOUNG SEO
2026-11-06 21:57 ` Bart Van Assche
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=cover.1793943246.git.hy50.seo@samsung.com \
--to=hy50.seo@samsung.com \
--cc=alim.akhtar@samsung.com \
--cc=bvanassche@acm.org \
--cc=cpgs@samsung.com \
--cc=h10.kim@samsung.com \
--cc=kwangwon.min@samsung.com \
--cc=kwmad.kim@samsung.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=mkp@kernel.org \
--cc=stanleyjhu@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®