Commit 1bfcf130 authored by Rafael J. Wysocki's avatar Rafael J. Wysocki Committed by Linus Torvalds

pm: rework disabling of user mode helpers during suspend/hibernation

We currently use a PM notifier to disable user mode helpers before suspend
and hibernation and to re-enable them during resume.  However, this is not
an ideal solution, because if any drivers want to upload firmware into
memory before suspend, they have to use a PM notifier for this purpose and
there is no guarantee that the ordering of PM notifiers will be as
expected (ie.  the notifier that disables user mode helpers has to be run
after the driver's notifier used for uploading the firmware).

For this reason, it seems better to move the disabling and enabling of
user mode helpers to separate functions that will be called by the PM core
as necessary.

[akpm@linux-foundation.org: remove unneeded ifdefs]
Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
Cc: Alan Stern <stern@rowland.harvard.edu>
Acked-by: default avatarPavel Machek <pavel@suse.cz>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 574f34ce
...@@ -99,4 +99,7 @@ struct file; ...@@ -99,4 +99,7 @@ struct file;
extern int call_usermodehelper_pipe(char *path, char *argv[], char *envp[], extern int call_usermodehelper_pipe(char *path, char *argv[], char *envp[],
struct file **filp); struct file **filp);
extern int usermodehelper_disable(void);
extern void usermodehelper_enable(void);
#endif /* __LINUX_KMOD_H__ */ #endif /* __LINUX_KMOD_H__ */
...@@ -265,7 +265,7 @@ static void __call_usermodehelper(struct work_struct *work) ...@@ -265,7 +265,7 @@ static void __call_usermodehelper(struct work_struct *work)
} }
} }
#ifdef CONFIG_PM #ifdef CONFIG_PM_SLEEP
/* /*
* If set, call_usermodehelper_exec() will exit immediately returning -EBUSY * If set, call_usermodehelper_exec() will exit immediately returning -EBUSY
* (used for preventing user land processes from being created after the user * (used for preventing user land processes from being created after the user
...@@ -288,15 +288,13 @@ static DECLARE_WAIT_QUEUE_HEAD(running_helpers_waitq); ...@@ -288,15 +288,13 @@ static DECLARE_WAIT_QUEUE_HEAD(running_helpers_waitq);
*/ */
#define RUNNING_HELPERS_TIMEOUT (5 * HZ) #define RUNNING_HELPERS_TIMEOUT (5 * HZ)
static int usermodehelper_pm_callback(struct notifier_block *nfb, /**
unsigned long action, * usermodehelper_disable - prevent new helpers from being started
void *ignored) */
int usermodehelper_disable(void)
{ {
long retval; long retval;
switch (action) {
case PM_HIBERNATION_PREPARE:
case PM_SUSPEND_PREPARE:
usermodehelper_disabled = 1; usermodehelper_disabled = 1;
smp_mb(); smp_mb();
/* /*
...@@ -308,19 +306,19 @@ static int usermodehelper_pm_callback(struct notifier_block *nfb, ...@@ -308,19 +306,19 @@ static int usermodehelper_pm_callback(struct notifier_block *nfb,
retval = wait_event_timeout(running_helpers_waitq, retval = wait_event_timeout(running_helpers_waitq,
atomic_read(&running_helpers) == 0, atomic_read(&running_helpers) == 0,
RUNNING_HELPERS_TIMEOUT); RUNNING_HELPERS_TIMEOUT);
if (retval) { if (retval)
return NOTIFY_OK; return 0;
} else {
usermodehelper_disabled = 0;
return NOTIFY_BAD;
}
case PM_POST_HIBERNATION:
case PM_POST_SUSPEND:
usermodehelper_disabled = 0; usermodehelper_disabled = 0;
return NOTIFY_OK; return -EAGAIN;
} }
return NOTIFY_DONE; /**
* usermodehelper_enable - allow new helpers to be started again
*/
void usermodehelper_enable(void)
{
usermodehelper_disabled = 0;
} }
static void helper_lock(void) static void helper_lock(void)
...@@ -334,18 +332,12 @@ static void helper_unlock(void) ...@@ -334,18 +332,12 @@ static void helper_unlock(void)
if (atomic_dec_and_test(&running_helpers)) if (atomic_dec_and_test(&running_helpers))
wake_up(&running_helpers_waitq); wake_up(&running_helpers_waitq);
} }
#else /* CONFIG_PM_SLEEP */
static void register_pm_notifier_callback(void)
{
pm_notifier(usermodehelper_pm_callback, 0);
}
#else /* CONFIG_PM */
#define usermodehelper_disabled 0 #define usermodehelper_disabled 0
static inline void helper_lock(void) {} static inline void helper_lock(void) {}
static inline void helper_unlock(void) {} static inline void helper_unlock(void) {}
static inline void register_pm_notifier_callback(void) {} #endif /* CONFIG_PM_SLEEP */
#endif /* CONFIG_PM */
/** /**
* call_usermodehelper_setup - prepare to call a usermode helper * call_usermodehelper_setup - prepare to call a usermode helper
...@@ -515,5 +507,4 @@ void __init usermodehelper_init(void) ...@@ -515,5 +507,4 @@ void __init usermodehelper_init(void)
{ {
khelper_wq = create_singlethread_workqueue("khelper"); khelper_wq = create_singlethread_workqueue("khelper");
BUG_ON(!khelper_wq); BUG_ON(!khelper_wq);
register_pm_notifier_callback();
} }
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <linux/reboot.h> #include <linux/reboot.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/kmod.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/mount.h> #include <linux/mount.h>
...@@ -520,6 +521,10 @@ int hibernate(void) ...@@ -520,6 +521,10 @@ int hibernate(void)
if (error) if (error)
goto Exit; goto Exit;
error = usermodehelper_disable();
if (error)
goto Exit;
/* Allocate memory management structures */ /* Allocate memory management structures */
error = create_basic_memory_bitmaps(); error = create_basic_memory_bitmaps();
if (error) if (error)
...@@ -558,6 +563,7 @@ int hibernate(void) ...@@ -558,6 +563,7 @@ int hibernate(void)
thaw_processes(); thaw_processes();
Finish: Finish:
free_basic_memory_bitmaps(); free_basic_memory_bitmaps();
usermodehelper_enable();
Exit: Exit:
pm_notifier_call_chain(PM_POST_HIBERNATION); pm_notifier_call_chain(PM_POST_HIBERNATION);
pm_restore_console(); pm_restore_console();
...@@ -634,6 +640,10 @@ static int software_resume(void) ...@@ -634,6 +640,10 @@ static int software_resume(void)
if (error) if (error)
goto Finish; goto Finish;
error = usermodehelper_disable();
if (error)
goto Finish;
error = create_basic_memory_bitmaps(); error = create_basic_memory_bitmaps();
if (error) if (error)
goto Finish; goto Finish;
...@@ -656,6 +666,7 @@ static int software_resume(void) ...@@ -656,6 +666,7 @@ static int software_resume(void)
thaw_processes(); thaw_processes();
Done: Done:
free_basic_memory_bitmaps(); free_basic_memory_bitmaps();
usermodehelper_enable();
Finish: Finish:
pm_notifier_call_chain(PM_POST_RESTORE); pm_notifier_call_chain(PM_POST_RESTORE);
pm_restore_console(); pm_restore_console();
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <linux/string.h> #include <linux/string.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/kmod.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/console.h> #include <linux/console.h>
#include <linux/cpu.h> #include <linux/cpu.h>
...@@ -237,6 +238,10 @@ static int suspend_prepare(void) ...@@ -237,6 +238,10 @@ static int suspend_prepare(void)
if (error) if (error)
goto Finish; goto Finish;
error = usermodehelper_disable();
if (error)
goto Finish;
if (suspend_freeze_processes()) { if (suspend_freeze_processes()) {
error = -EAGAIN; error = -EAGAIN;
goto Thaw; goto Thaw;
...@@ -256,6 +261,7 @@ static int suspend_prepare(void) ...@@ -256,6 +261,7 @@ static int suspend_prepare(void)
Thaw: Thaw:
suspend_thaw_processes(); suspend_thaw_processes();
usermodehelper_enable();
Finish: Finish:
pm_notifier_call_chain(PM_POST_SUSPEND); pm_notifier_call_chain(PM_POST_SUSPEND);
pm_restore_console(); pm_restore_console();
...@@ -376,6 +382,7 @@ int suspend_devices_and_enter(suspend_state_t state) ...@@ -376,6 +382,7 @@ int suspend_devices_and_enter(suspend_state_t state)
static void suspend_finish(void) static void suspend_finish(void)
{ {
suspend_thaw_processes(); suspend_thaw_processes();
usermodehelper_enable();
pm_notifier_call_chain(PM_POST_SUSPEND); pm_notifier_call_chain(PM_POST_SUSPEND);
pm_restore_console(); pm_restore_console();
} }
......
...@@ -212,13 +212,20 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd, ...@@ -212,13 +212,20 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,
case SNAPSHOT_FREEZE: case SNAPSHOT_FREEZE:
if (data->frozen) if (data->frozen)
break; break;
printk("Syncing filesystems ... "); printk("Syncing filesystems ... ");
sys_sync(); sys_sync();
printk("done.\n"); printk("done.\n");
error = freeze_processes(); error = usermodehelper_disable();
if (error) if (error)
break;
error = freeze_processes();
if (error) {
thaw_processes(); thaw_processes();
usermodehelper_enable();
}
if (!error) if (!error)
data->frozen = 1; data->frozen = 1;
break; break;
...@@ -227,6 +234,7 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd, ...@@ -227,6 +234,7 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,
if (!data->frozen || data->ready) if (!data->frozen || data->ready)
break; break;
thaw_processes(); thaw_processes();
usermodehelper_enable();
data->frozen = 0; data->frozen = 0;
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment