You've already forked linux-apfs
mirror of
https://github.com/linux-apfs/linux-apfs.git
synced 2026-05-01 15:00:59 -07:00
Merge tag 'pm-for-3.4-part-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
Pull more power management updates from Rafael Wysocki: - Patch series that hopefully fixes races between the freezer and request_firmware() and request_firmware_nowait() for good, with two cleanups from Stephen Boyd on top. - Runtime PM fix from Alan Stern preventing tasks from getting stuck indefinitely in the runtime PM wait queue. - Device PM QoS update from MyungJoo Ham introducing a new variant of pm_qos_update_request() allowing the callers to specify a timeout. * tag 'pm-for-3.4-part-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: PM / QoS: add pm_qos_update_request_timeout() API firmware_class: Move request_firmware_nowait() to workqueues firmware_class: Reorganize fw_create_instance() PM / Sleep: Mitigate race between the freezer and request_firmware() PM / Sleep: Move disabling of usermode helpers to the freezer PM / Hibernate: Disable usermode helpers right before freezing tasks firmware_class: Do not warn that system is not ready from async loads firmware_class: Split _request_firmware() into three functions, v2 firmware_class: Rework usermodehelper check PM / Runtime: don't forget to wake up waitqueue on failure
This commit is contained in:
+89
-32
@@ -322,7 +322,7 @@ static void __call_usermodehelper(struct work_struct *work)
|
||||
* land has been frozen during a system-wide hibernation or suspend operation).
|
||||
* Should always be manipulated under umhelper_sem acquired for write.
|
||||
*/
|
||||
static int usermodehelper_disabled = 1;
|
||||
static enum umh_disable_depth usermodehelper_disabled = UMH_DISABLED;
|
||||
|
||||
/* Number of helpers running */
|
||||
static atomic_t running_helpers = ATOMIC_INIT(0);
|
||||
@@ -333,33 +333,111 @@ static atomic_t running_helpers = ATOMIC_INIT(0);
|
||||
*/
|
||||
static DECLARE_WAIT_QUEUE_HEAD(running_helpers_waitq);
|
||||
|
||||
/*
|
||||
* Used by usermodehelper_read_lock_wait() to wait for usermodehelper_disabled
|
||||
* to become 'false'.
|
||||
*/
|
||||
static DECLARE_WAIT_QUEUE_HEAD(usermodehelper_disabled_waitq);
|
||||
|
||||
/*
|
||||
* Time to wait for running_helpers to become zero before the setting of
|
||||
* usermodehelper_disabled in usermodehelper_disable() fails
|
||||
*/
|
||||
#define RUNNING_HELPERS_TIMEOUT (5 * HZ)
|
||||
|
||||
void read_lock_usermodehelper(void)
|
||||
int usermodehelper_read_trylock(void)
|
||||
{
|
||||
down_read(&umhelper_sem);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(read_lock_usermodehelper);
|
||||
DEFINE_WAIT(wait);
|
||||
int ret = 0;
|
||||
|
||||
void read_unlock_usermodehelper(void)
|
||||
down_read(&umhelper_sem);
|
||||
for (;;) {
|
||||
prepare_to_wait(&usermodehelper_disabled_waitq, &wait,
|
||||
TASK_INTERRUPTIBLE);
|
||||
if (!usermodehelper_disabled)
|
||||
break;
|
||||
|
||||
if (usermodehelper_disabled == UMH_DISABLED)
|
||||
ret = -EAGAIN;
|
||||
|
||||
up_read(&umhelper_sem);
|
||||
|
||||
if (ret)
|
||||
break;
|
||||
|
||||
schedule();
|
||||
try_to_freeze();
|
||||
|
||||
down_read(&umhelper_sem);
|
||||
}
|
||||
finish_wait(&usermodehelper_disabled_waitq, &wait);
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(usermodehelper_read_trylock);
|
||||
|
||||
long usermodehelper_read_lock_wait(long timeout)
|
||||
{
|
||||
DEFINE_WAIT(wait);
|
||||
|
||||
if (timeout < 0)
|
||||
return -EINVAL;
|
||||
|
||||
down_read(&umhelper_sem);
|
||||
for (;;) {
|
||||
prepare_to_wait(&usermodehelper_disabled_waitq, &wait,
|
||||
TASK_UNINTERRUPTIBLE);
|
||||
if (!usermodehelper_disabled)
|
||||
break;
|
||||
|
||||
up_read(&umhelper_sem);
|
||||
|
||||
timeout = schedule_timeout(timeout);
|
||||
if (!timeout)
|
||||
break;
|
||||
|
||||
down_read(&umhelper_sem);
|
||||
}
|
||||
finish_wait(&usermodehelper_disabled_waitq, &wait);
|
||||
return timeout;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(usermodehelper_read_lock_wait);
|
||||
|
||||
void usermodehelper_read_unlock(void)
|
||||
{
|
||||
up_read(&umhelper_sem);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(read_unlock_usermodehelper);
|
||||
EXPORT_SYMBOL_GPL(usermodehelper_read_unlock);
|
||||
|
||||
/**
|
||||
* usermodehelper_disable - prevent new helpers from being started
|
||||
* __usermodehelper_set_disable_depth - Modify usermodehelper_disabled.
|
||||
* depth: New value to assign to usermodehelper_disabled.
|
||||
*
|
||||
* Change the value of usermodehelper_disabled (under umhelper_sem locked for
|
||||
* writing) and wakeup tasks waiting for it to change.
|
||||
*/
|
||||
int usermodehelper_disable(void)
|
||||
void __usermodehelper_set_disable_depth(enum umh_disable_depth depth)
|
||||
{
|
||||
down_write(&umhelper_sem);
|
||||
usermodehelper_disabled = depth;
|
||||
wake_up(&usermodehelper_disabled_waitq);
|
||||
up_write(&umhelper_sem);
|
||||
}
|
||||
|
||||
/**
|
||||
* __usermodehelper_disable - Prevent new helpers from being started.
|
||||
* @depth: New value to assign to usermodehelper_disabled.
|
||||
*
|
||||
* Set usermodehelper_disabled to @depth and wait for running helpers to exit.
|
||||
*/
|
||||
int __usermodehelper_disable(enum umh_disable_depth depth)
|
||||
{
|
||||
long retval;
|
||||
|
||||
if (!depth)
|
||||
return -EINVAL;
|
||||
|
||||
down_write(&umhelper_sem);
|
||||
usermodehelper_disabled = 1;
|
||||
usermodehelper_disabled = depth;
|
||||
up_write(&umhelper_sem);
|
||||
|
||||
/*
|
||||
@@ -374,31 +452,10 @@ int usermodehelper_disable(void)
|
||||
if (retval)
|
||||
return 0;
|
||||
|
||||
down_write(&umhelper_sem);
|
||||
usermodehelper_disabled = 0;
|
||||
up_write(&umhelper_sem);
|
||||
__usermodehelper_set_disable_depth(UMH_ENABLED);
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
/**
|
||||
* usermodehelper_enable - allow new helpers to be started again
|
||||
*/
|
||||
void usermodehelper_enable(void)
|
||||
{
|
||||
down_write(&umhelper_sem);
|
||||
usermodehelper_disabled = 0;
|
||||
up_write(&umhelper_sem);
|
||||
}
|
||||
|
||||
/**
|
||||
* usermodehelper_is_disabled - check if new helpers are allowed to be started
|
||||
*/
|
||||
bool usermodehelper_is_disabled(void)
|
||||
{
|
||||
return usermodehelper_disabled;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(usermodehelper_is_disabled);
|
||||
|
||||
static void helper_lock(void)
|
||||
{
|
||||
atomic_inc(&running_helpers);
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
#include <linux/string.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/async.h>
|
||||
#include <linux/kmod.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/mount.h>
|
||||
@@ -611,14 +610,10 @@ int hibernate(void)
|
||||
if (error)
|
||||
goto Exit;
|
||||
|
||||
error = usermodehelper_disable();
|
||||
if (error)
|
||||
goto Exit;
|
||||
|
||||
/* Allocate memory management structures */
|
||||
error = create_basic_memory_bitmaps();
|
||||
if (error)
|
||||
goto Enable_umh;
|
||||
goto Exit;
|
||||
|
||||
printk(KERN_INFO "PM: Syncing filesystems ... ");
|
||||
sys_sync();
|
||||
@@ -661,8 +656,6 @@ int hibernate(void)
|
||||
|
||||
Free_bitmaps:
|
||||
free_basic_memory_bitmaps();
|
||||
Enable_umh:
|
||||
usermodehelper_enable();
|
||||
Exit:
|
||||
pm_notifier_call_chain(PM_POST_HIBERNATION);
|
||||
pm_restore_console();
|
||||
@@ -777,16 +770,10 @@ static int software_resume(void)
|
||||
if (error)
|
||||
goto close_finish;
|
||||
|
||||
error = usermodehelper_disable();
|
||||
error = create_basic_memory_bitmaps();
|
||||
if (error)
|
||||
goto close_finish;
|
||||
|
||||
error = create_basic_memory_bitmaps();
|
||||
if (error) {
|
||||
usermodehelper_enable();
|
||||
goto close_finish;
|
||||
}
|
||||
|
||||
pr_debug("PM: Preparing processes for restore.\n");
|
||||
error = freeze_processes();
|
||||
if (error) {
|
||||
@@ -806,7 +793,6 @@ static int software_resume(void)
|
||||
thaw_processes();
|
||||
Done:
|
||||
free_basic_memory_bitmaps();
|
||||
usermodehelper_enable();
|
||||
Finish:
|
||||
pm_notifier_call_chain(PM_POST_RESTORE);
|
||||
pm_restore_console();
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <linux/freezer.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/workqueue.h>
|
||||
#include <linux/kmod.h>
|
||||
|
||||
/*
|
||||
* Timeout for stopping processes
|
||||
@@ -122,6 +123,10 @@ int freeze_processes(void)
|
||||
{
|
||||
int error;
|
||||
|
||||
error = __usermodehelper_disable(UMH_FREEZING);
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
if (!pm_freezing)
|
||||
atomic_inc(&system_freezing_cnt);
|
||||
|
||||
@@ -130,6 +135,7 @@ int freeze_processes(void)
|
||||
error = try_to_freeze_tasks(true);
|
||||
if (!error) {
|
||||
printk("done.");
|
||||
__usermodehelper_set_disable_depth(UMH_DISABLED);
|
||||
oom_killer_disable();
|
||||
}
|
||||
printk("\n");
|
||||
@@ -187,6 +193,8 @@ void thaw_processes(void)
|
||||
} while_each_thread(g, p);
|
||||
read_unlock(&tasklist_lock);
|
||||
|
||||
usermodehelper_enable();
|
||||
|
||||
schedule();
|
||||
printk("done.\n");
|
||||
}
|
||||
|
||||
@@ -229,6 +229,21 @@ int pm_qos_request_active(struct pm_qos_request *req)
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(pm_qos_request_active);
|
||||
|
||||
/**
|
||||
* pm_qos_work_fn - the timeout handler of pm_qos_update_request_timeout
|
||||
* @work: work struct for the delayed work (timeout)
|
||||
*
|
||||
* This cancels the timeout request by falling back to the default at timeout.
|
||||
*/
|
||||
static void pm_qos_work_fn(struct work_struct *work)
|
||||
{
|
||||
struct pm_qos_request *req = container_of(to_delayed_work(work),
|
||||
struct pm_qos_request,
|
||||
work);
|
||||
|
||||
pm_qos_update_request(req, PM_QOS_DEFAULT_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* pm_qos_add_request - inserts new qos request into the list
|
||||
* @req: pointer to a preallocated handle
|
||||
@@ -253,6 +268,7 @@ void pm_qos_add_request(struct pm_qos_request *req,
|
||||
return;
|
||||
}
|
||||
req->pm_qos_class = pm_qos_class;
|
||||
INIT_DELAYED_WORK(&req->work, pm_qos_work_fn);
|
||||
pm_qos_update_target(pm_qos_array[pm_qos_class]->constraints,
|
||||
&req->node, PM_QOS_ADD_REQ, value);
|
||||
}
|
||||
@@ -279,6 +295,9 @@ void pm_qos_update_request(struct pm_qos_request *req,
|
||||
return;
|
||||
}
|
||||
|
||||
if (delayed_work_pending(&req->work))
|
||||
cancel_delayed_work_sync(&req->work);
|
||||
|
||||
if (new_value != req->node.prio)
|
||||
pm_qos_update_target(
|
||||
pm_qos_array[req->pm_qos_class]->constraints,
|
||||
@@ -286,6 +305,34 @@ void pm_qos_update_request(struct pm_qos_request *req,
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(pm_qos_update_request);
|
||||
|
||||
/**
|
||||
* pm_qos_update_request_timeout - modifies an existing qos request temporarily.
|
||||
* @req : handle to list element holding a pm_qos request to use
|
||||
* @new_value: defines the temporal qos request
|
||||
* @timeout_us: the effective duration of this qos request in usecs.
|
||||
*
|
||||
* After timeout_us, this qos request is cancelled automatically.
|
||||
*/
|
||||
void pm_qos_update_request_timeout(struct pm_qos_request *req, s32 new_value,
|
||||
unsigned long timeout_us)
|
||||
{
|
||||
if (!req)
|
||||
return;
|
||||
if (WARN(!pm_qos_request_active(req),
|
||||
"%s called for unknown object.", __func__))
|
||||
return;
|
||||
|
||||
if (delayed_work_pending(&req->work))
|
||||
cancel_delayed_work_sync(&req->work);
|
||||
|
||||
if (new_value != req->node.prio)
|
||||
pm_qos_update_target(
|
||||
pm_qos_array[req->pm_qos_class]->constraints,
|
||||
&req->node, PM_QOS_UPDATE_REQ, new_value);
|
||||
|
||||
schedule_delayed_work(&req->work, usecs_to_jiffies(timeout_us));
|
||||
}
|
||||
|
||||
/**
|
||||
* pm_qos_remove_request - modifies an existing qos request
|
||||
* @req: handle to request list element
|
||||
@@ -305,6 +352,9 @@ void pm_qos_remove_request(struct pm_qos_request *req)
|
||||
return;
|
||||
}
|
||||
|
||||
if (delayed_work_pending(&req->work))
|
||||
cancel_delayed_work_sync(&req->work);
|
||||
|
||||
pm_qos_update_target(pm_qos_array[req->pm_qos_class]->constraints,
|
||||
&req->node, PM_QOS_REMOVE_REQ,
|
||||
PM_QOS_DEFAULT_VALUE);
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include <linux/delay.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/kmod.h>
|
||||
#include <linux/console.h>
|
||||
#include <linux/cpu.h>
|
||||
#include <linux/syscalls.h>
|
||||
@@ -102,17 +101,12 @@ static int suspend_prepare(void)
|
||||
if (error)
|
||||
goto Finish;
|
||||
|
||||
error = usermodehelper_disable();
|
||||
if (error)
|
||||
goto Finish;
|
||||
|
||||
error = suspend_freeze_processes();
|
||||
if (!error)
|
||||
return 0;
|
||||
|
||||
suspend_stats.failed_freeze++;
|
||||
dpm_save_failed_step(SUSPEND_FREEZE);
|
||||
usermodehelper_enable();
|
||||
Finish:
|
||||
pm_notifier_call_chain(PM_POST_SUSPEND);
|
||||
pm_restore_console();
|
||||
@@ -259,7 +253,6 @@ int suspend_devices_and_enter(suspend_state_t state)
|
||||
static void suspend_finish(void)
|
||||
{
|
||||
suspend_thaw_processes();
|
||||
usermodehelper_enable();
|
||||
pm_notifier_call_chain(PM_POST_SUSPEND);
|
||||
pm_restore_console();
|
||||
}
|
||||
|
||||
+1
-9
@@ -12,7 +12,6 @@
|
||||
#include <linux/suspend.h>
|
||||
#include <linux/syscalls.h>
|
||||
#include <linux/reboot.h>
|
||||
#include <linux/kmod.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/miscdevice.h>
|
||||
@@ -222,14 +221,8 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,
|
||||
sys_sync();
|
||||
printk("done.\n");
|
||||
|
||||
error = usermodehelper_disable();
|
||||
if (error)
|
||||
break;
|
||||
|
||||
error = freeze_processes();
|
||||
if (error)
|
||||
usermodehelper_enable();
|
||||
else
|
||||
if (!error)
|
||||
data->frozen = 1;
|
||||
break;
|
||||
|
||||
@@ -238,7 +231,6 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,
|
||||
break;
|
||||
pm_restore_gfp_mask();
|
||||
thaw_processes();
|
||||
usermodehelper_enable();
|
||||
data->frozen = 0;
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user