Skip to content

Commit 1e73203

Browse files
committed
PM / Sleep: Move disabling of usermode helpers to the freezer
The core suspend/hibernation code calls usermodehelper_disable() to avoid race conditions between the freezer and the starting of usermode helpers and each code path has to do that on its own. However, it is always called right before freeze_processes() and usermodehelper_enable() is always called right after thaw_processes(). For this reason, to avoid code duplication and to make the connection between usermodehelper_disable() and the freezer more visible, make freeze_processes() call it and remove the direct usermodehelper_disable() and usermodehelper_enable() calls from all suspend/hibernation code paths. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: stable@vger.kernel.org
1 parent 7b5179a commit 1e73203

4 files changed

Lines changed: 8 additions & 27 deletions

File tree

‎kernel/power/hibernate.c‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <linux/string.h>
1717
#include <linux/device.h>
1818
#include <linux/async.h>
19-
#include <linux/kmod.h>
2019
#include <linux/delay.h>
2120
#include <linux/fs.h>
2221
#include <linux/mount.h>
@@ -620,10 +619,6 @@ int hibernate(void)
620619
sys_sync();
621620
printk("done.\n");
622621

623-
error = usermodehelper_disable();
624-
if (error)
625-
goto Exit;
626-
627622
error = freeze_processes();
628623
if (error)
629624
goto Free_bitmaps;
@@ -660,7 +655,6 @@ int hibernate(void)
660655
freezer_test_done = false;
661656

662657
Free_bitmaps:
663-
usermodehelper_enable();
664658
free_basic_memory_bitmaps();
665659
Exit:
666660
pm_notifier_call_chain(PM_POST_HIBERNATION);
@@ -780,10 +774,6 @@ static int software_resume(void)
780774
if (error)
781775
goto close_finish;
782776

783-
error = usermodehelper_disable();
784-
if (error)
785-
goto close_finish;
786-
787777
pr_debug("PM: Preparing processes for restore.\n");
788778
error = freeze_processes();
789779
if (error) {
@@ -802,7 +792,6 @@ static int software_resume(void)
802792
swsusp_free();
803793
thaw_processes();
804794
Done:
805-
usermodehelper_enable();
806795
free_basic_memory_bitmaps();
807796
Finish:
808797
pm_notifier_call_chain(PM_POST_RESTORE);

‎kernel/power/process.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/freezer.h>
1717
#include <linux/delay.h>
1818
#include <linux/workqueue.h>
19+
#include <linux/kmod.h>
1920

2021
/*
2122
* Timeout for stopping processes
@@ -122,6 +123,10 @@ int freeze_processes(void)
122123
{
123124
int error;
124125

126+
error = usermodehelper_disable();
127+
if (error)
128+
return error;
129+
125130
if (!pm_freezing)
126131
atomic_inc(&system_freezing_cnt);
127132

@@ -187,6 +192,8 @@ void thaw_processes(void)
187192
} while_each_thread(g, p);
188193
read_unlock(&tasklist_lock);
189194

195+
usermodehelper_enable();
196+
190197
schedule();
191198
printk("done.\n");
192199
}

‎kernel/power/suspend.c‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <linux/delay.h>
1313
#include <linux/errno.h>
1414
#include <linux/init.h>
15-
#include <linux/kmod.h>
1615
#include <linux/console.h>
1716
#include <linux/cpu.h>
1817
#include <linux/syscalls.h>
@@ -102,17 +101,12 @@ static int suspend_prepare(void)
102101
if (error)
103102
goto Finish;
104103

105-
error = usermodehelper_disable();
106-
if (error)
107-
goto Finish;
108-
109104
error = suspend_freeze_processes();
110105
if (!error)
111106
return 0;
112107

113108
suspend_stats.failed_freeze++;
114109
dpm_save_failed_step(SUSPEND_FREEZE);
115-
usermodehelper_enable();
116110
Finish:
117111
pm_notifier_call_chain(PM_POST_SUSPEND);
118112
pm_restore_console();
@@ -259,7 +253,6 @@ int suspend_devices_and_enter(suspend_state_t state)
259253
static void suspend_finish(void)
260254
{
261255
suspend_thaw_processes();
262-
usermodehelper_enable();
263256
pm_notifier_call_chain(PM_POST_SUSPEND);
264257
pm_restore_console();
265258
}

‎kernel/power/user.c‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <linux/suspend.h>
1313
#include <linux/syscalls.h>
1414
#include <linux/reboot.h>
15-
#include <linux/kmod.h>
1615
#include <linux/string.h>
1716
#include <linux/device.h>
1817
#include <linux/miscdevice.h>
@@ -222,14 +221,8 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,
222221
sys_sync();
223222
printk("done.\n");
224223

225-
error = usermodehelper_disable();
226-
if (error)
227-
break;
228-
229224
error = freeze_processes();
230-
if (error)
231-
usermodehelper_enable();
232-
else
225+
if (!error)
233226
data->frozen = 1;
234227
break;
235228

@@ -238,7 +231,6 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,
238231
break;
239232
pm_restore_gfp_mask();
240233
thaw_processes();
241-
usermodehelper_enable();
242234
data->frozen = 0;
243235
break;
244236

0 commit comments

Comments
 (0)