[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20251025160905.3857885-214-sashal@kernel.org>
Date: Sat, 25 Oct 2025 11:57:25 -0400
From: Sasha Levin <sashal@...nel.org>
To: patches@...ts.linux.dev,
stable@...r.kernel.org
Cc: Peter Wang <peter.wang@...iatek.com>,
Bart Van Assche <bvanassche@....org>,
"Martin K. Petersen" <martin.petersen@...cle.com>,
Sasha Levin <sashal@...nel.org>,
matthias.bgg@...il.com,
angelogioacchino.delregno@...labora.com,
avri.altman@...disk.com,
beanhuo@...ron.com,
alexandre.f.demers@...il.com,
adrian.hunter@...el.com,
quic_cang@...cinc.com,
ebiggers@...nel.org,
quic_nitirawa@...cinc.com,
neil.armstrong@...aro.org,
linux-scsi@...r.kernel.org,
linux-mediatek@...ts.infradead.org,
linux-kernel@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org
Subject: [PATCH AUTOSEL 6.17-6.6] scsi: ufs: host: mediatek: Enhance recovery on hibernation exit failure
From: Peter Wang <peter.wang@...iatek.com>
[ Upstream commit faac32d4ece30609f1a0930ca0ae951cf6dc1786 ]
Improve the recovery process for hibernation exit failures. Trigger the
error handler and break the suspend operation to ensure effective
recovery from hibernation errors. Activate the error handling mechanism
by ufshcd_force_error_recovery and scheduling the error handler work.
Signed-off-by: Peter Wang <peter.wang@...iatek.com>
Reviewed-by: Bart Van Assche <bvanassche@....org>
Signed-off-by: Martin K. Petersen <martin.petersen@...cle.com>
Signed-off-by: Sasha Levin <sashal@...nel.org>
---
LLM Generated explanations, may be completely bogus:
YES
- Fixes a real bug that affects users: previously, a failure to exit
hibernation (H8) during suspend was only warned about and suspend
continued, risking a stuck/broken UFS link and subsequent I/O hangs.
The patch turns this into a recoverable path by triggering the error
handler and aborting suspend.
- Small, contained change with clear intent:
- Makes the core helper available to host drivers by de-static’ing and
exporting `ufshcd_force_error_recovery()` and declaring it in the
UFS header:
- `drivers/ufs/core/ufshcd.c:6471` acquires `host_lock`, sets
`hba->force_reset = true`, invokes `ufshcd_schedule_eh_work()`,
and is exported via
`EXPORT_SYMBOL_GPL(ufshcd_force_error_recovery)`.
- `include/ufs/ufshcd.h:1489` adds `void
ufshcd_force_error_recovery(struct ufs_hba *hba);`
- Uses that helper in the MediaTek host driver to recover from H8 exit
failures and to abort suspend:
- `drivers/ufs/host/ufs-mediatek.c:1436` changes
`ufs_mtk_auto_hibern8_disable()` to return `int` and to return an
error on failure.
- `drivers/ufs/host/ufs-mediatek.c:1454` calls
`ufshcd_force_error_recovery(hba)` when
`ufs_mtk_wait_link_state(..., VS_LINK_UP, ...)` fails, then sets
`ret = -EBUSY` to break suspend.
- `drivers/ufs/host/ufs-mediatek.c:1750` propagates the PRE_CHANGE
failure by `return ufs_mtk_auto_hibern8_disable(hba);` in
`ufs_mtk_suspend()`.
- Correct integration with the core suspend flow: the UFS core checks
vendor PRE_CHANGE return and aborts on error:
- `drivers/ufs/core/ufshcd.c:9899` calls `ufshcd_vops_suspend(hba,
pm_op, PRE_CHANGE)` and if `ret` is non-zero it aborts the suspend
path, re-enables scaling, and unwinds cleanly.
- Error handling sequencing is robust:
- `drivers/ufs/core/ufshcd.c:6456` `ufshcd_schedule_eh_work()` sets
`ufshcd_state` to `UFSHCD_STATE_EH_SCHEDULED_FATAL` if `force_reset`
or fatal conditions are detected and queues `eh_work`, ensuring the
error handler runs promptly.
- Scope and risk:
- No architectural changes; it’s a targeted behavioral fix in the
MediaTek UFS suspend path plus a symbol export in the UFS core for
in-tree drivers.
- Only triggers additional actions on an existing error path (H8 exit
failure). Normal suspend paths are unchanged.
- Storage reliability fix in a critical subsystem, but contained to
UFS/Mediatek host and UFS core error handling.
- Stable tree criteria alignment:
- Fixes an important reliability bug (avoids continuing suspend with a
broken link and prevents I/O hang).
- Minimal, surgical changes, no new features.
- No broad side effects; the exported helper is internal API used by
in-tree code.
- No major refactoring or dependency churn.
Given the above, this is a strong candidate for stable backporting.
drivers/ufs/core/ufshcd.c | 3 ++-
drivers/ufs/host/ufs-mediatek.c | 14 +++++++++++---
include/ufs/ufshcd.h | 1 +
3 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 465e66dbe08e8..78d3f0ee16d84 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -6462,13 +6462,14 @@ void ufshcd_schedule_eh_work(struct ufs_hba *hba)
}
}
-static void ufshcd_force_error_recovery(struct ufs_hba *hba)
+void ufshcd_force_error_recovery(struct ufs_hba *hba)
{
spin_lock_irq(hba->host->host_lock);
hba->force_reset = true;
ufshcd_schedule_eh_work(hba);
spin_unlock_irq(hba->host->host_lock);
}
+EXPORT_SYMBOL_GPL(ufshcd_force_error_recovery);
static void ufshcd_clk_scaling_allow(struct ufs_hba *hba, bool allow)
{
diff --git a/drivers/ufs/host/ufs-mediatek.c b/drivers/ufs/host/ufs-mediatek.c
index 055b24758ca3d..6bdbbee1f0708 100644
--- a/drivers/ufs/host/ufs-mediatek.c
+++ b/drivers/ufs/host/ufs-mediatek.c
@@ -1646,7 +1646,7 @@ static void ufs_mtk_dev_vreg_set_lpm(struct ufs_hba *hba, bool lpm)
}
}
-static void ufs_mtk_auto_hibern8_disable(struct ufs_hba *hba)
+static int ufs_mtk_auto_hibern8_disable(struct ufs_hba *hba)
{
int ret;
@@ -1657,8 +1657,16 @@ static void ufs_mtk_auto_hibern8_disable(struct ufs_hba *hba)
ufs_mtk_wait_idle_state(hba, 5);
ret = ufs_mtk_wait_link_state(hba, VS_LINK_UP, 100);
- if (ret)
+ if (ret) {
dev_warn(hba->dev, "exit h8 state fail, ret=%d\n", ret);
+
+ ufshcd_force_error_recovery(hba);
+
+ /* trigger error handler and break suspend */
+ ret = -EBUSY;
+ }
+
+ return ret;
}
static int ufs_mtk_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op,
@@ -1669,7 +1677,7 @@ static int ufs_mtk_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op,
if (status == PRE_CHANGE) {
if (ufshcd_is_auto_hibern8_supported(hba))
- ufs_mtk_auto_hibern8_disable(hba);
+ return ufs_mtk_auto_hibern8_disable(hba);
return 0;
}
diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h
index a3fa98540d184..a4eb5bde46e88 100644
--- a/include/ufs/ufshcd.h
+++ b/include/ufs/ufshcd.h
@@ -1511,5 +1511,6 @@ int __ufshcd_write_ee_control(struct ufs_hba *hba, u32 ee_ctrl_mask);
int ufshcd_write_ee_control(struct ufs_hba *hba);
int ufshcd_update_ee_control(struct ufs_hba *hba, u16 *mask,
const u16 *other_mask, u16 set, u16 clr);
+void ufshcd_force_error_recovery(struct ufs_hba *hba);
#endif /* End of Header */
--
2.51.0
Powered by blists - more mailing lists