From: Asdlerto Korry <korryasdlerto@gmail.com>
To: "Martin K . Petersen" <mkp@kernel.org>,
"James E . J . Bottomley" <James.Bottomley@HansenPartnership.com>
Cc: Bart Van Assche <bvanassche@acm.org>,
Alim Akhtar <alim.akhtar@samsung.com>,
Bean Huo <beanhuo@micron.com>,
Peter Wang <peter.wang@mediatek.com>,
Can Guo <can.guo@oss.qualcomm.com>,
linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
Asdlerto Korry <korryasdlerto@gmail.com>
Subject: [RFC PATCH] scsi: ufs: core: Allow error recovery before the device W-LUN exists
Date: Mon, 2 Nov 2026 02:36:07 +0200 [thread overview]
Message-ID: <20261102003607.341651-1-korryasdlerto@gmail.com> (raw)
ufshcd_err_handling_should_stop() returns true while hba->ufs_device_wlun
is NULL, i.e. until the first probe has added the device W-LUN. If the
link fails during that first probe (for example NOP OUT failing after
link startup), the error handler therefore never resets the host or the
link: it only marks the state operational and returns, and the probe
keeps failing until it gives up.
On a Samsung Galaxy M52 5G (SM7325) the first link startup regularly
ends in PA errors (LINERESET). With the W-LUN check removed, the error
handler performs a real host reset and restore and the device comes up;
without it, it never does.
Removing the check exposes three places that dereference
hba->ufs_device_wlun unconditionally on this path:
ufshcd_rpm_get_sync()/ufshcd_rpm_put(), ufshcd_err_handling_prepare()
and ufshcd_recover_pm_error(). Skip the W-LUN runtime PM handling there
when the W-LUN does not exist yet; there is nothing to resume and no
regular SCSI I/O before it is added.
Note: the error handler then calls ufshcd_verify_dev_init() through
ufshcd_reset_and_restore() while the tag set is quiesced. This needs the
pseudo SCSI device queue to be unquiesced in ufshcd_err_handling_prepare()
(as done upstream), otherwise blk_execute_rq() waits forever.
Signed-off-by: Asdlerto Korry <korryasdlerto@gmail.com>
---
drivers/ufs/core/ufshcd-priv.h | 4 ++++
drivers/ufs/core/ufshcd.c | 13 +++++++++----
2 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/drivers/ufs/core/ufshcd-priv.h b/drivers/ufs/core/ufshcd-priv.h
index e55c2a02c1f5..2cb0d542d114 100644
--- a/drivers/ufs/core/ufshcd-priv.h
+++ b/drivers/ufs/core/ufshcd-priv.h
@@ -385,6 +385,8 @@ static inline int ufshcd_update_ee_usr_mask(struct ufs_hba *hba,
static inline int ufshcd_rpm_get_sync(struct ufs_hba *hba)
{
+ if (!hba->ufs_device_wlun)
+ return 0;
return pm_runtime_get_sync(&hba->ufs_device_wlun->sdev_gendev);
}
@@ -410,6 +412,8 @@ static inline int ufshcd_rpm_resume(struct ufs_hba *hba)
static inline void ufshcd_rpm_put(struct ufs_hba *hba)
{
+ if (!hba->ufs_device_wlun)
+ return;
pm_runtime_put(&hba->ufs_device_wlun->sdev_gendev);
}
diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index fd52deb72d21..9767fbc7b870 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -6876,8 +6876,9 @@ static void ufshcd_err_handling_prepare(struct ufs_hba *hba)
*/
pm_runtime_get_sync(hba->dev);
ufshcd_rpm_get_sync(hba);
- if (pm_runtime_status_suspended(&hba->ufs_device_wlun->sdev_gendev) ||
- hba->is_sys_suspended) {
+ if (hba->ufs_device_wlun &&
+ (pm_runtime_status_suspended(&hba->ufs_device_wlun->sdev_gendev) ||
+ hba->is_sys_suspended)) {
enum ufs_pm_op pm_op;
/*
@@ -6926,7 +6927,6 @@ static void ufshcd_err_handling_unprepare(struct ufs_hba *hba)
static inline bool ufshcd_err_handling_should_stop(struct ufs_hba *hba)
{
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))));
@@ -6935,12 +6935,17 @@ static inline bool ufshcd_err_handling_should_stop(struct ufs_hba *hba)
#ifdef CONFIG_PM
static void ufshcd_recover_pm_error(struct ufs_hba *hba)
{
- struct scsi_target *starget = hba->ufs_device_wlun->sdev_target;
+ struct scsi_target *starget;
struct Scsi_Host *shost = hba->host;
struct scsi_device *sdev;
struct request_queue *q;
bool resume_sdev_queues = false;
+ /* Nothing to recover before the device W-LUN has been added */
+ if (!hba->ufs_device_wlun)
+ return;
+ starget = hba->ufs_device_wlun->sdev_target;
+
hba->is_sys_suspended = false;
/*
--
2.25.1
next reply other threads:[~2026-11-02 0:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 0:36 Asdlerto Korry [this message]
2026-11-02 8:45 ` Peter Wang
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=20261102003607.341651-1-korryasdlerto@gmail.com \
--to=korryasdlerto@gmail.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=alim.akhtar@samsung.com \
--cc=beanhuo@micron.com \
--cc=bvanassche@acm.org \
--cc=can.guo@oss.qualcomm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=mkp@kernel.org \
--cc=peter.wang@mediatek.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®