Skip to contentSkip to conversation

PM / suspend: Abort suspend if somebody holds wakelock

PATCH In review Mukesh Ojha 2 participants 2 messages Oct 6, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PM / suspend: Abort suspend if somebody holds wakelock

There could be a scenario, where request_firmware() call results in user land process trying to load firmwares into memory and parallely one miscellaneous process is trying to invoke manual suspend and due to which user mode helper gets disabled during freezing of processes and that aborts loading of firmware even though request_firmware() thread has taken wakelock.

Although, we are checking for any wakeup event inside try_to_freeze_tasks() but that could be too late for the above scenario.

Let's add a check before freezing/disable user land process in suspend path.

---
 kernel/power/process.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/power/process.c +3 -0
index 37401c9..3e0d3d6 100644
@@ -124,6 +124,9 @@ int freeze_processes(void)
 {
 	int error;
 
+	if (pm_wakeup_pending())
+		return -EBUSY;
+
 	error = __usermodehelper_disable(UMH_FREEZING);
 	if (error)
 		return error;
Signature · 2 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center,
Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
#1 lore raw
Quoted 8 lines · Mukesh Ojha

There could be a scenario, where request_firmware() call results in user land process trying to load firmwares into memory and parallely one miscellaneous process is trying to invoke manual suspend and due to which user mode helper gets disabled during freezing of processes and that aborts loading of firmware even though request_firmware() thread has taken wakelock.

Quoted 6 lines

Although, we are checking for any wakeup event inside try_to_freeze_tasks() but that could be too late for the above scenario.

Let's add a check before freezing/disable user land process in suspend path.

If a laptop lid is closed and the system is expected to suspend, it must suspend.

This takes precedence over the loading of firmware. Sorry.

Quoted 23 lines
---
 kernel/power/process.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/power/process.c +3 -1
index 37401c9..3e0d3d6 100644
@@ -124,6 +124,9 @@ int freeze_processes(void)
 {
        int error;
 
+       if (pm_wakeup_pending())
+               return -EBUSY;
+
        error = __usermodehelper_disable(UMH_FREEZING);
        if (error)
                return error;
--

Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project