Re: [PATCH v2 2/2] scsi: ufs: core: Do not recover the link concurrently with a PM callback
From: Peter Wang
Date: Mon Nov 16 2026 - 07:53:16 EST
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