Skip to contentSkip to conversation

scsi: ufs: core: cancel RTC work in active-active suspend

PATCH Superseded Guangshuo Li 3 participants 6 messages Jul 8 – Jul 14

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: ufs: core: cancel RTC work in active-active suspend

UFS RTC support schedules ufs_rtc_update_work to periodically update the device RTC. The work can issue query commands and access the UFS host controller.

__ufshcd_wl_suspend() cancels ufs_rtc_update_work in the common suspend path before calling the vendor suspend callback. However, the active-active path, where both the device power mode and link state stay active, jumps directly to vops_suspend after flushing exception handling work. That jump bypasses the RTC work cancellation.

If the RTC work runs while the vendor suspend callback is gating or otherwise changing hardware state, it can access the controller during suspend and trigger an SError.

Cancel the RTC work in the active-active path before jumping to vops_suspend, matching the common suspend path.

Fixes 6bf999e0eb41 ("scsi: ufs: core: Add UFS RTC support")
---
 drivers/ufs/core/ufshcd.c | 1 +
 1 file changed, 1 insertion(+)
drivers/ufs/core/ufshcd.c +1 -0
index d3044a3089b5..9d5571a7aec2 100644
@@ -10269,6 +10269,7 @@ static int __ufshcd_wl_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op)
 			req_link_state == UIC_LINK_ACTIVE_STATE) {
 		ufshcd_disable_auto_bkops(hba);
 		flush_work(&hba->eeh_work);
+		cancel_delayed_work_sync(&hba->ufs_rtc_update_work);
 		goto vops_suspend;
 	}
 
Signature · 1 line
2.43.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The patch cancels ufs_rtc_update_work during the active-active suspend path but fails to…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The patch cancels ufs_rtc_update_work during the active-active suspend path but fails to re-schedule it when the device resumes, causing periodic RTC updates to permanently stop. --

--- Patch [1]: [PATCH] scsi: ufs: core: cancel RTC work in active-active suspend --- commit d6ec0bf16c0b8402d3955ca2fc9c1ec563b33c79
Author: Guangshuo Li <[email protected]>

scsi: ufs: core: cancel RTC work in active-active suspend

This commit modifies the active-active suspend path in __ufshcd_wl_suspend() to cancel the ufs_rtc_update_work before jumping to vops_suspend. This prevents the RTC work from accessing the controller while the hardware state is changing.

drivers/ufs/core/ufshcd.c static int __ufshcd_wl_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op) · line 10272

Quoted 9 lines
drivers/ufs/core/ufshcd.c +1 -0
index d3044a3089b53..9d5571a7aec23 100644
@@ -10269,6 +10269,7 @@ static int __ufshcd_wl_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op)
 			req_link_state == UIC_LINK_ACTIVE_STATE) {
 		ufshcd_disable_auto_bkops(hba);
 		flush_work(&hba->eeh_work);
+		cancel_delayed_work_sync(&hba->ufs_rtc_update_work);

[Severity: Medium]
If the work is cancelled here during active-active suspend, will it be safely rescheduled on resume?

Looking at __ufshcd_wl_resume(), the rescheduling of ufs_rtc_update_work appears to be gated by a check for whether the device is not active:

drivers/ufs/core/ufshcd.c:__ufshcd_wl_resume() {
    ...
    if (!ufshcd_is_ufs_dev_active(hba)) {
        ret = ufshcd_set_dev_pwr_mode(hba, UFS_ACTIVE_PWR_MODE);
        if (ret)
            goto set_old_link_state;
        ufshcd_set_timestamp_attr(hba);
        schedule_delayed_work(&hba->ufs_rtc_update_work,
                              msecs_to_jiffies(UFS_RTC_UPDATE_INTERVAL_MS));
    }
    ...
}

Since the active-active suspend path leaves the device in UFS_ACTIVE_PWR_MODE, it looks like ufshcd_is_ufs_dev_active(hba) will evaluate to true. Does this cause the periodic RTC work to be permanently stopped after the first active-active suspend cycle?

Quoted 3 lines
drivers/ufs/core/ufshcd.c +0 -0
 		goto vops_suspend;
 	}
 
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
Quoted 50 lines · On Wed, 2026-07-08 at 13:03 +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The patch cancels ufs_rtc_update_work during the active-active suspend path but fails to re-schedule it when the device resumes, causing periodic RTC updates to permanently stop.
--

--- Patch [1]: [PATCH] scsi: ufs: core: cancel RTC work in active-active suspend ---
commit d6ec0bf16c0b8402d3955ca2fc9c1ec563b33c79
Author: Guangshuo Li <[email protected]>

scsi: ufs: core: cancel RTC work in active-active suspend

This commit modifies the active-active suspend path in __ufshcd_wl_suspend() to cancel the ufs_rtc_update_work before jumping to vops_suspend. This prevents the RTC work from accessing the controller while the hardware state is changing.

drivers/ufs/core/ufshcd.c static int __ufshcd_wl_suspend(struct ufs_hba *hba, · line 10273

Quoted 10 lines
drivers/ufs/core/ufshcd.c +1 -0
index d3044a3089b53..9d5571a7aec23 100644
@@ -10269,6 +10269,7 @@ static int __ufshcd_wl_suspend(struct ufs_hba *hba,
 enum ufs_pm_op pm_op)
                         req_link_state == UIC_LINK_ACTIVE_STATE) {
                 ufshcd_disable_auto_bkops(hba);
                 flush_work(&hba->eeh_work);
+               cancel_delayed_work_sync(&hba->ufs_rtc_update_work);

[Severity: Medium]
If the work is cancelled here during active-active suspend, will it be safely rescheduled on resume?

Looking at __ufshcd_wl_resume(), the rescheduling of ufs_rtc_update_work appears to be gated by a check for whether the device is not active:

drivers/ufs/core/ufshcd.c:__ufshcd_wl_resume() {
    ...
    if (!ufshcd_is_ufs_dev_active(hba)) {
        ret = ufshcd_set_dev_pwr_mode(hba, UFS_ACTIVE_PWR_MODE); if (ret)
            goto set_old_link_state; ufshcd_set_timestamp_attr(hba); schedule_delayed_work(&hba->ufs_rtc_update_work, msecs_to_jiffies(UFS_RTC_UPDATE_INTERVAL_MS)); }
    ...
}

Quoted 4 lines

Since the active-active suspend path leaves the device in UFS_ACTIVE_PWR_MODE, it looks like ufshcd_is_ufs_dev_active(hba) will evaluate to true. Does this cause the periodic RTC work to be permanently stopped after the first active-active suspend cycle?

good catch, about this change:

drivers/ufs/core/ufshcd.c +0 -0
index 376a314189e4..06f253b08b65 100644
@@ -10339,6 +10339,7 @@ static int __ufshcd_wl_suspend(struct ufs_hba *hba, enum

ufs_pm_op pm_op)

                        req_link_state == UIC_LINK_ACTIVE_STATE) {
                ufshcd_disable_auto_bkops(hba);
                flush_work(&hba->eeh_work);
+               cancel_delayed_work_sync(&hba->ufs_rtc_update_work);
                goto vops_suspend;
        }

@@ -10548,10 +10549,11 @@ static int __ufshcd_wl_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op)

                if (ret)
                        goto set_old_link_state;
                ufshcd_set_timestamp_attr(hba);
-               schedule_delayed_work(&hba->ufs_rtc_update_work,
-                                    
msecs_to_jiffies(UFS_RTC_UPDATE_INTERVAL_MS));
        }

+ schedule_delayed_work(&hba->ufs_rtc_update_work,
+ msecs_to_jiffies(UFS_RTC_UPDATE_INTERVAL_MS));
+

        if (ufshcd_keep_autobkops_enabled_except_suspend(hba))
                ufshcd_enable_auto_bkops(hba);
        else
Quoted 5 lines
Quoted 4 lines
drivers/ufs/core/ufshcd.c +0 -0
                 goto vops_suspend;
         }
#3 lore raw
In reply to Guangshuo Li
Quoted 10 lines · Guangshuo Li

UFS RTC support schedules ufs_rtc_update_work to periodically update the device RTC. The work can issue query commands and access the UFS host controller.

__ufshcd_wl_suspend() cancels ufs_rtc_update_work in the common suspend path before calling the vendor suspend callback. However, the active-active path, where both the device power mode and link state stay active, jumps directly to vops_suspend after flushing exception handling work. That jump bypasses the RTC work cancellation.

Quoted 8 lines

If the RTC work runs while the vendor suspend callback is gating or otherwise changing hardware state, it can access the controller during suspend and trigger an SError.

Cancel the RTC work in the active-active path before jumping to vops_suspend, matching the common suspend path.

Fixes 6bf999e0eb41 ("scsi: ufs: core: Add UFS RTC support")

this fix tag is wrong, should be:

Fixes b0bd84c39289 ("scsi: ufs: core: Fix SError in ufshcd_rtc_work() during

UFS suspend")

since 6bf999e0eb41 ("scsi: ufs: core: Add UFS RTC support") placed the cancel after the vops_suspend: label (after the POST_CHANGE vops call), so the active- active goto vops_suspend path did cancel the work. then b0bd84c39289 ("scsi:
ufs: core: Fix SError in ufshcd_rtc_work() during UFS suspend", moved the cancel up above the PRE_CHANGE vops call to close a race in the common path. That move is what removed cancellation from the active-active path. So the correct tag is

Fixes b0bd84c39289, not 6bf999e0eb41.
Quoted 10 lines

---
 drivers/ufs/core/ufshcd.c | 1 +

 1 file changed, 1 insertion(+)
drivers/ufs/core/ufshcd.c +0 -0
index d3044a3089b5..9d5571a7aec2 100644

drivers/ufs/core/ufshcd.c static int __ufshcd_wl_suspend(struct ufs_hba *hba, · line 10273

Quoted 5 lines
drivers/ufs/core/ufshcd.c +1 -0
@@ -10269,6 +10269,7 @@ static int __ufshcd_wl_suspend(struct ufs_hba *hba,
 enum ufs_pm_op pm_op)
                         req_link_state == UIC_LINK_ACTIVE_STATE) {
                 ufshcd_disable_auto_bkops(hba);
                 flush_work(&hba->eeh_work);
+               cancel_delayed_work_sync(&hba->ufs_rtc_update_work);

RTC updates stop permanently after the first active-active suspend. you need to add resume:

drivers/ufs/core/ufshcd.c +0 -0
index 376a314189e4..06f253b08b65 100644
@@ -10339,6 +10339,7 @@ static int __ufshcd_wl_suspend(struct ufs_hba *hba, enum

ufs_pm_op pm_op)

                        req_link_state == UIC_LINK_ACTIVE_STATE) {
                ufshcd_disable_auto_bkops(hba);
                flush_work(&hba->eeh_work);
+               cancel_delayed_work_sync(&hba->ufs_rtc_update_work);
                goto vops_suspend;
        }

@@ -10548,10 +10549,11 @@ static int __ufshcd_wl_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op)

                if (ret)
                        goto set_old_link_state;
                ufshcd_set_timestamp_attr(hba);
-               schedule_delayed_work(&hba->ufs_rtc_update_work,
-                                    
msecs_to_jiffies(UFS_RTC_UPDATE_INTERVAL_MS));
        }

+ schedule_delayed_work(&hba->ufs_rtc_update_work,
+ msecs_to_jiffies(UFS_RTC_UPDATE_INTERVAL_MS));
+

        if (ufshcd_keep_autobkops_enabled_except_suspend(hba))
                ufshcd_enable_auto_bkops(hba);
        else

Kind regards,
Bean

Quoted 3 lines
drivers/ufs/core/ufshcd.c +0 -0
                 goto vops_suspend;
         }

#4 lore raw

Hi Guangshuo

would you like to update your patch with the consideration of RTC update resume?

Kind regard,
Bean

Quoted 99 lines · Bean Huo
Quoted 10 lines · Guangshuo Li

UFS RTC support schedules ufs_rtc_update_work to periodically update the device RTC. The work can issue query commands and access the UFS host controller.

__ufshcd_wl_suspend() cancels ufs_rtc_update_work in the common suspend path before calling the vendor suspend callback. However, the active-active path, where both the device power mode and link state stay active, jumps directly to vops_suspend after flushing exception handling work. That jump bypasses the RTC work cancellation.

Quoted 8 lines

If the RTC work runs while the vendor suspend callback is gating or otherwise changing hardware state, it can access the controller during suspend and trigger an SError.

Cancel the RTC work in the active-active path before jumping to vops_suspend, matching the common suspend path.

Fixes 6bf999e0eb41 ("scsi: ufs: core: Add UFS RTC support")

this fix tag is wrong, should be:

Fixes b0bd84c39289 ("scsi: ufs: core: Fix SError in ufshcd_rtc_work() during

UFS suspend")

since 6bf999e0eb41 ("scsi: ufs: core: Add UFS RTC support") placed the cancel after the vops_suspend: label (after the POST_CHANGE vops call), so the active-
active goto vops_suspend path did cancel the work. then b0bd84c39289 ("scsi:
ufs: core: Fix SError in ufshcd_rtc_work() during UFS suspend", moved the cancel
up above the PRE_CHANGE vops call to close a race in the common path. That move
is what removed cancellation from the active-active path. So the correct tag is

Fixes b0bd84c39289, not 6bf999e0eb41.
Quoted 10 lines

---
 drivers/ufs/core/ufshcd.c | 1 +

 1 file changed, 1 insertion(+)
drivers/ufs/core/ufshcd.c +0 -0
index d3044a3089b5..9d5571a7aec2 100644

drivers/ufs/core/ufshcd.c static int __ufshcd_wl_suspend(struct ufs_hba *hba, · line 10273

Quoted 5 lines
drivers/ufs/core/ufshcd.c +1 -0
@@ -10269,6 +10269,7 @@ static int __ufshcd_wl_suspend(struct ufs_hba *hba,
 enum ufs_pm_op pm_op)
                         req_link_state == UIC_LINK_ACTIVE_STATE) {
                 ufshcd_disable_auto_bkops(hba);
                 flush_work(&hba->eeh_work);
+               cancel_delayed_work_sync(&hba->ufs_rtc_update_work);

RTC updates stop permanently after the first active-active suspend. you need to
add resume:

drivers/ufs/core/ufshcd.c +0 -0
index 376a314189e4..06f253b08b65 100644
@@ -10339,6 +10339,7 @@ static int __ufshcd_wl_suspend(struct ufs_hba *hba,

enum
ufs_pm_op pm_op)
                        req_link_state == UIC_LINK_ACTIVE_STATE) { ufshcd_disable_auto_bkops(hba); flush_work(&hba->eeh_work);
+               cancel_delayed_work_sync(&hba->ufs_rtc_update_work); goto vops_suspend;
        }

drivers/ufs/core/ufshcd.c +0 -2
@@ -10548,10 +10549,11 @@ static int __ufshcd_wl_resume(struct ufs_hba *hba,
 enum ufs_pm_op pm_op)
                 if (ret)
                         goto set_old_link_state;
                 ufshcd_set_timestamp_attr(hba);
-               schedule_delayed_work(&hba->ufs_rtc_update_work,
-                                    
 msecs_to_jiffies(UFS_RTC_UPDATE_INTERVAL_MS));
         }


+       schedule_delayed_work(&hba->ufs_rtc_update_work,
+                             msecs_to_jiffies(UFS_RTC_UPDATE_INTERVAL_MS)); +
        if (ufshcd_keep_autobkops_enabled_except_suspend(hba)) ufshcd_enable_auto_bkops(hba);
        else

Kind regards,
Bean

Quoted 3 lines
drivers/ufs/core/ufshcd.c +0 -0
                 goto vops_suspend;
         }

#5 lore raw

Hi Bean,

Quoted 111 lines · Bean Huo

Hi Guangshuo

would you like to update your patch with the consideration of RTC update resume?

Kind regard,
Bean

Quoted 99 lines · Bean Huo
Quoted 10 lines · Guangshuo Li

UFS RTC support schedules ufs_rtc_update_work to periodically update the device RTC. The work can issue query commands and access the UFS host controller.

__ufshcd_wl_suspend() cancels ufs_rtc_update_work in the common suspend path before calling the vendor suspend callback. However, the active-active path, where both the device power mode and link state stay active, jumps directly to vops_suspend after flushing exception handling work. That jump bypasses the RTC work cancellation.

Quoted 8 lines

If the RTC work runs while the vendor suspend callback is gating or otherwise changing hardware state, it can access the controller during suspend and trigger an SError.

Cancel the RTC work in the active-active path before jumping to vops_suspend, matching the common suspend path.

Fixes 6bf999e0eb41 ("scsi: ufs: core: Add UFS RTC support")

this fix tag is wrong, should be:

Fixes b0bd84c39289 ("scsi: ufs: core: Fix SError in ufshcd_rtc_work() during

UFS suspend")

since 6bf999e0eb41 ("scsi: ufs: core: Add UFS RTC support") placed the cancel after the vops_suspend: label (after the POST_CHANGE vops call), so the active-
active goto vops_suspend path did cancel the work. then b0bd84c39289 ("scsi:
ufs: core: Fix SError in ufshcd_rtc_work() during UFS suspend", moved the cancel
up above the PRE_CHANGE vops call to close a race in the common path. That move
is what removed cancellation from the active-active path. So the correct tag is

Fixes b0bd84c39289, not 6bf999e0eb41.
Quoted 10 lines
---
 drivers/ufs/core/ufshcd.c | 1 +
 1 file changed, 1 insertion(+)
drivers/ufs/core/ufshcd.c +0 -0
index d3044a3089b5..9d5571a7aec2 100644

drivers/ufs/core/ufshcd.c static int __ufshcd_wl_suspend(struct ufs_hba *hba, · line 10273

Quoted 5 lines
drivers/ufs/core/ufshcd.c +1 -0
@@ -10269,6 +10269,7 @@ static int __ufshcd_wl_suspend(struct ufs_hba *hba,
 enum ufs_pm_op pm_op)
                        req_link_state == UIC_LINK_ACTIVE_STATE) {
                ufshcd_disable_auto_bkops(hba);
                flush_work(&hba->eeh_work);
+               cancel_delayed_work_sync(&hba->ufs_rtc_update_work);

RTC updates stop permanently after the first active-active suspend. you need to
add resume:

drivers/ufs/core/ufshcd.c +0 -0
index 376a314189e4..06f253b08b65 100644
@@ -10339,6 +10339,7 @@ static int __ufshcd_wl_suspend(struct ufs_hba *hba,

enum
ufs_pm_op pm_op)

                        req_link_state == UIC_LINK_ACTIVE_STATE) {
                ufshcd_disable_auto_bkops(hba);
                flush_work(&hba->eeh_work);
drivers/ufs/core/ufshcd.c +4 -2
+               cancel_delayed_work_sync(&hba->ufs_rtc_update_work);
                goto vops_suspend;
        }
@@ -10548,10 +10549,11 @@ static int __ufshcd_wl_resume(struct ufs_hba *hba,
 enum ufs_pm_op pm_op)
                if (ret)
                        goto set_old_link_state;
                ufshcd_set_timestamp_attr(hba);
-               schedule_delayed_work(&hba->ufs_rtc_update_work,
-
 msecs_to_jiffies(UFS_RTC_UPDATE_INTERVAL_MS));
        }
 
+       schedule_delayed_work(&hba->ufs_rtc_update_work,
+                             msecs_to_jiffies(UFS_RTC_UPDATE_INTERVAL_MS));
+
        if (ufshcd_keep_autobkops_enabled_except_suspend(hba))
                ufshcd_enable_auto_bkops(hba);
        else

Kind regards,
Bean

Quoted 3 lines
drivers/ufs/core/ufshcd.c +0 -0
                goto vops_suspend;
        }

Yes, I will update the patch to fix the Fixes tag and add the RTC work rescheduling in the resume path.

Thanks for your review and suggestion.

Kind regards,
Guangshuo