ufs: core: Fix runtime suspend error deadlock
Subsystems (3)
PATCH 1/1 ufs: core: Fix runtime suspend error deadlock
From: Peter Wang <[email protected]>
Resolve the deadlock issue during runtime suspend when an error triggers the error handler. Prevent the deadlock by checking pm_op_in_progress and performing a quick recovery. This approach ensures that the error handler does not wait indefinitely for runtime PM to resume, allowing runtime suspend to proceed smoothly.
--- drivers/ufs/core/ufshcd.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/ufs/core/ufshcd.c +5 -0
@@ -6681,6 +6681,11 @@ static void ufshcd_err_handler(struct work_struct *work) }spin_unlock_irqrestore (hba->host->host_lock, flags); +if (hba->pm_op_in_progress) { +ufshcd_link_recovery (hba); +return ; + } +ufshcd_err_handling_prepare (hba);spin_lock_irqsave (hba->host->host_lock, flags);
Signature · 1 line
2.45.2
Bart Van Assche
reviewerQuoted 22 lines · On 9/23/25 1:20 AM, [email protected] wrote:
From: Peter Wang <[email protected]>
Resolve the deadlock issue during runtime suspend when an error triggers the error handler. Prevent the deadlock by checking
pm_op_in_progressand performing a quick recovery. This approach ensures that the error handler does not wait indefinitely for runtime PM to resume, allowing runtime suspend to proceed smoothly.Signed-off-by Peter Wang <[email protected]>Suggested-by Bart Van Assche <[email protected]>Tested-by Bart Van Assche <[email protected]>--- drivers/ufs/core/ufshcd.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/ufs/core/ufshcd.c +0
-0@@ -6681,6 +6681,11 @@ static void ufshcd_err_handler(struct work_struct *work) }
drivers/ufs/core/ufshcd.c static void ufshcd_err_handler(struct work_struct *work) · line 6691
Quoted 10 lines
drivers/ufs/core/ufshcd.c +5
-0spin_unlock_irqrestore (hba->host->host_lock, flags); +if (hba->pm_op_in_progress) { +ufshcd_link_recovery (hba); +return ; + } +ufshcd_err_handling_prepare (hba);spin_lock_irqsave (hba->host->host_lock, flags);
Does this patch introduce a race condition? Can a power management operation start after hba->pm_op_in_progress has been tested and before ufshcd_err_handling_prepare() is called? Should the added code perhaps be surrounded with ufshcd_rpm_get_noresume() and ufshcd_rpm_put()?
Thanks,
Bart.
Quoted 9 lines · Bart Van Assche
Does this patch introduce a race condition? Can a power management operation start after
hba->pm_op_in_progresshas been tested and beforeufshcd_err_handling_prepare()is called? Should the added code perhaps
be surrounded withufshcd_rpm_get_noresume()andufshcd_rpm_put()?
Quoted 3 lines
Thanks,
Bart.
Hi Bart,
Are you saying that after the runtime suspend timer expires, the error handler might be triggered just before runtime suspend? I don't think this can happen, since there shouldn't be anything triggering the error handler when the bus has been idle for a long time.
Thanks
Peter
Bart Van Assche
reviewerQuoted 5 lines · Peter Wang (王信友)
Are you saying that after the runtime suspend timer expires, the error handler might be triggered just before runtime suspend? I don't think this can happen, since there shouldn't be anything triggering the error handler when the bus has been idle for a long time.
Hi Peter,
The UFS error handler is not only triggered by bus errors. It can also be activated via debugfs. Do you agree that activation via debugfs can happen concurrently with runtime suspend?
Thanks,
Bart.
Quoted 9 lines · Bart Van Assche
Hi Peter,
The UFS error handler is not only triggered by bus errors. It can also
be activated via debugfs. Do you agree that activation via debugfs can
happen concurrently with runtime suspend?
Quoted 3 lines
Thanks,
Bart.
Hi Bart,
Do you mean that debugfs could schedule EH work just before suspend? If so, there is indeed a chance that this patch might not work as intended. Even if we surround it with ufshcd_rpm_get_noresume() and ufshcd_rpm_put(), there is still a possibility that runtime PM is ongoing and the suspend callback hasn't been called yet, so the result would be the same, just with a lower chance of occurrence.
Because this patch mainly targets errors that occur during the suspend process. If the error happens before suspend, it’s outside the scope of what this patch is intended to fix. But I will add ufshcd_rpm_get_noresume() and ufshcd_rpm_put() next version.
Thanks.
Peter