Re: [PATCH v2 2/2] scsi: ufs: core: Do not recover the link concurrently with a PM callback

From: Manish Pandey

Date: Tue Dec 01 2026 - 10:57:30 EST


Hi Stanley,

This fix is helping as far as it goes with
ufshcd_err_handler Vs __ufshcd_wl_resume

but there is a second, structurally identical bypass that the commit didn't touch, in ufshcd_eh_host_reset_handler()
(the SCSI .eh_host_reset_handler callback),

static int ufshcd_eh_host_reset_handler(struct scsi_cmnd *cmd)
{
...
if (hba->pm_op_in_progress) {
if (ufshcd_link_recovery(hba))
err = FAILED;
return err;
}
...
}

This has exactly the same shape:
it calls ufshcd_link_recovery(hba) directly, without taking
hba->host_sem and without going through ufshcd_err_handling_prepare() / ufshcd_rpm_get_sync().

Also i would like to know what is the plan for Stable kernels Like
kernel 6.18 ? As same issue is observed there also.

Thanks
Manish

On 16-11-2026 18:23, Peter Wang wrote:
On Fri, 2026-11-13 at 19:12 +0800, Stanley Jhu wrote:
From: Brian Kao <powenkao@xxxxxxxxxx>

ufshcd_set_dev_pwr_mode() now recovers the link after a START STOP
UNIT timeout. ufshcd_err_handler() must not recover the link while a
PM callback runs. Its pm_op_in_progress branch still does so when a
fatal UIC error arrives during that recovery.


Hi Stanley,

Could we just add a check to prevent the concurrency issue
in ufshcd_link_recovery?

--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -1,10 +1,16 @@
int ufshcd_link_recovery(struct ufs_hba *hba)
{
int ret;
unsigned long flags;
spin_lock_irqsave(hba->host->host_lock, flags);
+ if (ufshcd_eh_in_progress(hba)) {
+ spin_unlock_irqrestore(hba->host->host_lock, flags);
+ dev_info(hba->dev, "%s: link recovery already in
progress, skipping\n",
+ __func__);
+ return -EBUSY;
+ }
hba->ufshcd_state = UFSHCD_STATE_RESET;
ufshcd_set_eh_in_progress(hba);
spin_unlock_irqrestore(hba->host->host_lock, flags);



@@ -7074,23 +7074,6 @@ static void ufshcd_err_handler(struct
work_struct *work)
  hba->saved_uic_err, hba->force_reset,
  ufshcd_is_link_broken(hba) ? "; link is broken" :
"");
- if (hba->ufs_device_wlun) {
- /*
- * Use ufshcd_rpm_get_noresume() here to safely
perform link
- * recovery even if an error occurs during runtime
suspend or
- * runtime resume. This avoids potential deadlocks
that could
- * happen if we tried to resume the device while a
PM operation
- * is already in progress.
- */
- ufshcd_rpm_get_noresume(hba);
- if (hba->pm_op_in_progress) {
- ufshcd_link_recovery(hba);
- ufshcd_rpm_put(hba);
- return;
- }
- ufshcd_rpm_put(hba);
- }
-


This section of code is used when a UIC error occurs
before SSU is sent.

Because the error handler uses link recovery, it will
recover from the error quickly rather than waiting for
the 10s SSU timeout. The end user will feel lag because
the I/O cannot resume for 10s.

Thanks
Peter