forked from luck/tmp_suning_uos_patched
notifier: Fix broken error handling pattern
The current notifiers have the following error handling pattern all over the place: int err, nr; err = __foo_notifier_call_chain(&chain, val_up, v, -1, &nr); if (err & NOTIFIER_STOP_MASK) __foo_notifier_call_chain(&chain, val_down, v, nr-1, NULL) And aside from the endless repetition thereof, it is broken. Consider blocking notifiers; both calls take and drop the rwsem, this means that the notifier list can change in between the two calls, making @nr meaningless. Fix this by replacing all the __foo_notifier_call_chain() functions with foo_notifier_call_chain_robust() that embeds the above pattern, but ensures it is inside a single lock region. Note: I switched atomic_notifier_call_chain_robust() to use the spinlock, since RCU cannot provide the guarantee required for the recovery. Note: software_resume() error handling was broken afaict. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Link: https://lore.kernel.org/r/20200818135804.325626653@infradead.org
This commit is contained in:
parent
f75aef392f
commit
70d9329857
|
@ -161,20 +161,19 @@ extern int srcu_notifier_chain_unregister(struct srcu_notifier_head *nh,
|
||||||
|
|
||||||
extern int atomic_notifier_call_chain(struct atomic_notifier_head *nh,
|
extern int atomic_notifier_call_chain(struct atomic_notifier_head *nh,
|
||||||
unsigned long val, void *v);
|
unsigned long val, void *v);
|
||||||
extern int __atomic_notifier_call_chain(struct atomic_notifier_head *nh,
|
|
||||||
unsigned long val, void *v, int nr_to_call, int *nr_calls);
|
|
||||||
extern int blocking_notifier_call_chain(struct blocking_notifier_head *nh,
|
extern int blocking_notifier_call_chain(struct blocking_notifier_head *nh,
|
||||||
unsigned long val, void *v);
|
unsigned long val, void *v);
|
||||||
extern int __blocking_notifier_call_chain(struct blocking_notifier_head *nh,
|
|
||||||
unsigned long val, void *v, int nr_to_call, int *nr_calls);
|
|
||||||
extern int raw_notifier_call_chain(struct raw_notifier_head *nh,
|
extern int raw_notifier_call_chain(struct raw_notifier_head *nh,
|
||||||
unsigned long val, void *v);
|
unsigned long val, void *v);
|
||||||
extern int __raw_notifier_call_chain(struct raw_notifier_head *nh,
|
|
||||||
unsigned long val, void *v, int nr_to_call, int *nr_calls);
|
|
||||||
extern int srcu_notifier_call_chain(struct srcu_notifier_head *nh,
|
extern int srcu_notifier_call_chain(struct srcu_notifier_head *nh,
|
||||||
unsigned long val, void *v);
|
unsigned long val, void *v);
|
||||||
extern int __srcu_notifier_call_chain(struct srcu_notifier_head *nh,
|
|
||||||
unsigned long val, void *v, int nr_to_call, int *nr_calls);
|
extern int atomic_notifier_call_chain_robust(struct atomic_notifier_head *nh,
|
||||||
|
unsigned long val_up, unsigned long val_down, void *v);
|
||||||
|
extern int blocking_notifier_call_chain_robust(struct blocking_notifier_head *nh,
|
||||||
|
unsigned long val_up, unsigned long val_down, void *v);
|
||||||
|
extern int raw_notifier_call_chain_robust(struct raw_notifier_head *nh,
|
||||||
|
unsigned long val_up, unsigned long val_down, void *v);
|
||||||
|
|
||||||
#define NOTIFY_DONE 0x0000 /* Don't care */
|
#define NOTIFY_DONE 0x0000 /* Don't care */
|
||||||
#define NOTIFY_OK 0x0001 /* Suits me */
|
#define NOTIFY_OK 0x0001 /* Suits me */
|
||||||
|
|
|
@ -15,18 +15,28 @@
|
||||||
|
|
||||||
static ATOMIC_NOTIFIER_HEAD(cpu_pm_notifier_chain);
|
static ATOMIC_NOTIFIER_HEAD(cpu_pm_notifier_chain);
|
||||||
|
|
||||||
static int cpu_pm_notify(enum cpu_pm_event event, int nr_to_call, int *nr_calls)
|
static int cpu_pm_notify(enum cpu_pm_event event)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* __atomic_notifier_call_chain has a RCU read critical section, which
|
* atomic_notifier_call_chain has a RCU read critical section, which
|
||||||
* could be disfunctional in cpu idle. Copy RCU_NONIDLE code to let
|
* could be disfunctional in cpu idle. Copy RCU_NONIDLE code to let
|
||||||
* RCU know this.
|
* RCU know this.
|
||||||
*/
|
*/
|
||||||
rcu_irq_enter_irqson();
|
rcu_irq_enter_irqson();
|
||||||
ret = __atomic_notifier_call_chain(&cpu_pm_notifier_chain, event, NULL,
|
ret = atomic_notifier_call_chain(&cpu_pm_notifier_chain, event, NULL);
|
||||||
nr_to_call, nr_calls);
|
rcu_irq_exit_irqson();
|
||||||
|
|
||||||
|
return notifier_to_errno(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cpu_pm_notify_robust(enum cpu_pm_event event_up, enum cpu_pm_event event_down)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
rcu_irq_enter_irqson();
|
||||||
|
ret = atomic_notifier_call_chain_robust(&cpu_pm_notifier_chain, event_up, event_down, NULL);
|
||||||
rcu_irq_exit_irqson();
|
rcu_irq_exit_irqson();
|
||||||
|
|
||||||
return notifier_to_errno(ret);
|
return notifier_to_errno(ret);
|
||||||
|
@ -80,18 +90,7 @@ EXPORT_SYMBOL_GPL(cpu_pm_unregister_notifier);
|
||||||
*/
|
*/
|
||||||
int cpu_pm_enter(void)
|
int cpu_pm_enter(void)
|
||||||
{
|
{
|
||||||
int nr_calls = 0;
|
return cpu_pm_notify_robust(CPU_PM_ENTER, CPU_PM_ENTER_FAILED);
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
ret = cpu_pm_notify(CPU_PM_ENTER, -1, &nr_calls);
|
|
||||||
if (ret)
|
|
||||||
/*
|
|
||||||
* Inform listeners (nr_calls - 1) about failure of CPU PM
|
|
||||||
* PM entry who are notified earlier to prepare for it.
|
|
||||||
*/
|
|
||||||
cpu_pm_notify(CPU_PM_ENTER_FAILED, nr_calls - 1, NULL);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(cpu_pm_enter);
|
EXPORT_SYMBOL_GPL(cpu_pm_enter);
|
||||||
|
|
||||||
|
@ -109,7 +108,7 @@ EXPORT_SYMBOL_GPL(cpu_pm_enter);
|
||||||
*/
|
*/
|
||||||
int cpu_pm_exit(void)
|
int cpu_pm_exit(void)
|
||||||
{
|
{
|
||||||
return cpu_pm_notify(CPU_PM_EXIT, -1, NULL);
|
return cpu_pm_notify(CPU_PM_EXIT);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(cpu_pm_exit);
|
EXPORT_SYMBOL_GPL(cpu_pm_exit);
|
||||||
|
|
||||||
|
@ -131,18 +130,7 @@ EXPORT_SYMBOL_GPL(cpu_pm_exit);
|
||||||
*/
|
*/
|
||||||
int cpu_cluster_pm_enter(void)
|
int cpu_cluster_pm_enter(void)
|
||||||
{
|
{
|
||||||
int nr_calls = 0;
|
return cpu_pm_notify_robust(CPU_CLUSTER_PM_ENTER, CPU_CLUSTER_PM_ENTER_FAILED);
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
ret = cpu_pm_notify(CPU_CLUSTER_PM_ENTER, -1, &nr_calls);
|
|
||||||
if (ret)
|
|
||||||
/*
|
|
||||||
* Inform listeners (nr_calls - 1) about failure of CPU cluster
|
|
||||||
* PM entry who are notified earlier to prepare for it.
|
|
||||||
*/
|
|
||||||
cpu_pm_notify(CPU_CLUSTER_PM_ENTER_FAILED, nr_calls - 1, NULL);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(cpu_cluster_pm_enter);
|
EXPORT_SYMBOL_GPL(cpu_cluster_pm_enter);
|
||||||
|
|
||||||
|
@ -163,7 +151,7 @@ EXPORT_SYMBOL_GPL(cpu_cluster_pm_enter);
|
||||||
*/
|
*/
|
||||||
int cpu_cluster_pm_exit(void)
|
int cpu_cluster_pm_exit(void)
|
||||||
{
|
{
|
||||||
return cpu_pm_notify(CPU_CLUSTER_PM_EXIT, -1, NULL);
|
return cpu_pm_notify(CPU_CLUSTER_PM_EXIT);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(cpu_cluster_pm_exit);
|
EXPORT_SYMBOL_GPL(cpu_cluster_pm_exit);
|
||||||
|
|
||||||
|
|
|
@ -94,6 +94,34 @@ static int notifier_call_chain(struct notifier_block **nl,
|
||||||
}
|
}
|
||||||
NOKPROBE_SYMBOL(notifier_call_chain);
|
NOKPROBE_SYMBOL(notifier_call_chain);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* notifier_call_chain_robust - Inform the registered notifiers about an event
|
||||||
|
* and rollback on error.
|
||||||
|
* @nl: Pointer to head of the blocking notifier chain
|
||||||
|
* @val_up: Value passed unmodified to the notifier function
|
||||||
|
* @val_down: Value passed unmodified to the notifier function when recovering
|
||||||
|
* from an error on @val_up
|
||||||
|
* @v Pointer passed unmodified to the notifier function
|
||||||
|
*
|
||||||
|
* NOTE: It is important the @nl chain doesn't change between the two
|
||||||
|
* invocations of notifier_call_chain() such that we visit the
|
||||||
|
* exact same notifier callbacks; this rules out any RCU usage.
|
||||||
|
*
|
||||||
|
* Returns: the return value of the @val_up call.
|
||||||
|
*/
|
||||||
|
static int notifier_call_chain_robust(struct notifier_block **nl,
|
||||||
|
unsigned long val_up, unsigned long val_down,
|
||||||
|
void *v)
|
||||||
|
{
|
||||||
|
int ret, nr = 0;
|
||||||
|
|
||||||
|
ret = notifier_call_chain(nl, val_up, v, -1, &nr);
|
||||||
|
if (ret & NOTIFY_STOP_MASK)
|
||||||
|
notifier_call_chain(nl, val_down, v, nr-1, NULL);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Atomic notifier chain routines. Registration and unregistration
|
* Atomic notifier chain routines. Registration and unregistration
|
||||||
* use a spinlock, and call_chain is synchronized by RCU (no locks).
|
* use a spinlock, and call_chain is synchronized by RCU (no locks).
|
||||||
|
@ -144,13 +172,30 @@ int atomic_notifier_chain_unregister(struct atomic_notifier_head *nh,
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(atomic_notifier_chain_unregister);
|
EXPORT_SYMBOL_GPL(atomic_notifier_chain_unregister);
|
||||||
|
|
||||||
|
int atomic_notifier_call_chain_robust(struct atomic_notifier_head *nh,
|
||||||
|
unsigned long val_up, unsigned long val_down, void *v)
|
||||||
|
{
|
||||||
|
unsigned long flags;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Musn't use RCU; because then the notifier list can
|
||||||
|
* change between the up and down traversal.
|
||||||
|
*/
|
||||||
|
spin_lock_irqsave(&nh->lock, flags);
|
||||||
|
ret = notifier_call_chain_robust(&nh->head, val_up, val_down, v);
|
||||||
|
spin_unlock_irqrestore(&nh->lock, flags);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(atomic_notifier_call_chain_robust);
|
||||||
|
NOKPROBE_SYMBOL(atomic_notifier_call_chain_robust);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* __atomic_notifier_call_chain - Call functions in an atomic notifier chain
|
* atomic_notifier_call_chain - Call functions in an atomic notifier chain
|
||||||
* @nh: Pointer to head of the atomic notifier chain
|
* @nh: Pointer to head of the atomic notifier chain
|
||||||
* @val: Value passed unmodified to notifier function
|
* @val: Value passed unmodified to notifier function
|
||||||
* @v: Pointer passed unmodified to notifier function
|
* @v: Pointer passed unmodified to notifier function
|
||||||
* @nr_to_call: See the comment for notifier_call_chain.
|
|
||||||
* @nr_calls: See the comment for notifier_call_chain.
|
|
||||||
*
|
*
|
||||||
* Calls each function in a notifier chain in turn. The functions
|
* Calls each function in a notifier chain in turn. The functions
|
||||||
* run in an atomic context, so they must not block.
|
* run in an atomic context, so they must not block.
|
||||||
|
@ -163,24 +208,16 @@ EXPORT_SYMBOL_GPL(atomic_notifier_chain_unregister);
|
||||||
* Otherwise the return value is the return value
|
* Otherwise the return value is the return value
|
||||||
* of the last notifier function called.
|
* of the last notifier function called.
|
||||||
*/
|
*/
|
||||||
int __atomic_notifier_call_chain(struct atomic_notifier_head *nh,
|
int atomic_notifier_call_chain(struct atomic_notifier_head *nh,
|
||||||
unsigned long val, void *v,
|
unsigned long val, void *v)
|
||||||
int nr_to_call, int *nr_calls)
|
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
rcu_read_lock();
|
rcu_read_lock();
|
||||||
ret = notifier_call_chain(&nh->head, val, v, nr_to_call, nr_calls);
|
ret = notifier_call_chain(&nh->head, val, v, -1, NULL);
|
||||||
rcu_read_unlock();
|
rcu_read_unlock();
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
EXPORT_SYMBOL_GPL(__atomic_notifier_call_chain);
|
|
||||||
NOKPROBE_SYMBOL(__atomic_notifier_call_chain);
|
|
||||||
|
|
||||||
int atomic_notifier_call_chain(struct atomic_notifier_head *nh,
|
return ret;
|
||||||
unsigned long val, void *v)
|
|
||||||
{
|
|
||||||
return __atomic_notifier_call_chain(nh, val, v, -1, NULL);
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(atomic_notifier_call_chain);
|
EXPORT_SYMBOL_GPL(atomic_notifier_call_chain);
|
||||||
NOKPROBE_SYMBOL(atomic_notifier_call_chain);
|
NOKPROBE_SYMBOL(atomic_notifier_call_chain);
|
||||||
|
@ -250,13 +287,30 @@ int blocking_notifier_chain_unregister(struct blocking_notifier_head *nh,
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(blocking_notifier_chain_unregister);
|
EXPORT_SYMBOL_GPL(blocking_notifier_chain_unregister);
|
||||||
|
|
||||||
|
int blocking_notifier_call_chain_robust(struct blocking_notifier_head *nh,
|
||||||
|
unsigned long val_up, unsigned long val_down, void *v)
|
||||||
|
{
|
||||||
|
int ret = NOTIFY_DONE;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We check the head outside the lock, but if this access is
|
||||||
|
* racy then it does not matter what the result of the test
|
||||||
|
* is, we re-check the list after having taken the lock anyway:
|
||||||
|
*/
|
||||||
|
if (rcu_access_pointer(nh->head)) {
|
||||||
|
down_read(&nh->rwsem);
|
||||||
|
ret = notifier_call_chain_robust(&nh->head, val_up, val_down, v);
|
||||||
|
up_read(&nh->rwsem);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(blocking_notifier_call_chain_robust);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* __blocking_notifier_call_chain - Call functions in a blocking notifier chain
|
* blocking_notifier_call_chain - Call functions in a blocking notifier chain
|
||||||
* @nh: Pointer to head of the blocking notifier chain
|
* @nh: Pointer to head of the blocking notifier chain
|
||||||
* @val: Value passed unmodified to notifier function
|
* @val: Value passed unmodified to notifier function
|
||||||
* @v: Pointer passed unmodified to notifier function
|
* @v: Pointer passed unmodified to notifier function
|
||||||
* @nr_to_call: See comment for notifier_call_chain.
|
|
||||||
* @nr_calls: See comment for notifier_call_chain.
|
|
||||||
*
|
*
|
||||||
* Calls each function in a notifier chain in turn. The functions
|
* Calls each function in a notifier chain in turn. The functions
|
||||||
* run in a process context, so they are allowed to block.
|
* run in a process context, so they are allowed to block.
|
||||||
|
@ -268,9 +322,8 @@ EXPORT_SYMBOL_GPL(blocking_notifier_chain_unregister);
|
||||||
* Otherwise the return value is the return value
|
* Otherwise the return value is the return value
|
||||||
* of the last notifier function called.
|
* of the last notifier function called.
|
||||||
*/
|
*/
|
||||||
int __blocking_notifier_call_chain(struct blocking_notifier_head *nh,
|
int blocking_notifier_call_chain(struct blocking_notifier_head *nh,
|
||||||
unsigned long val, void *v,
|
unsigned long val, void *v)
|
||||||
int nr_to_call, int *nr_calls)
|
|
||||||
{
|
{
|
||||||
int ret = NOTIFY_DONE;
|
int ret = NOTIFY_DONE;
|
||||||
|
|
||||||
|
@ -281,19 +334,11 @@ int __blocking_notifier_call_chain(struct blocking_notifier_head *nh,
|
||||||
*/
|
*/
|
||||||
if (rcu_access_pointer(nh->head)) {
|
if (rcu_access_pointer(nh->head)) {
|
||||||
down_read(&nh->rwsem);
|
down_read(&nh->rwsem);
|
||||||
ret = notifier_call_chain(&nh->head, val, v, nr_to_call,
|
ret = notifier_call_chain(&nh->head, val, v, -1, NULL);
|
||||||
nr_calls);
|
|
||||||
up_read(&nh->rwsem);
|
up_read(&nh->rwsem);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(__blocking_notifier_call_chain);
|
|
||||||
|
|
||||||
int blocking_notifier_call_chain(struct blocking_notifier_head *nh,
|
|
||||||
unsigned long val, void *v)
|
|
||||||
{
|
|
||||||
return __blocking_notifier_call_chain(nh, val, v, -1, NULL);
|
|
||||||
}
|
|
||||||
EXPORT_SYMBOL_GPL(blocking_notifier_call_chain);
|
EXPORT_SYMBOL_GPL(blocking_notifier_call_chain);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -335,13 +380,18 @@ int raw_notifier_chain_unregister(struct raw_notifier_head *nh,
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(raw_notifier_chain_unregister);
|
EXPORT_SYMBOL_GPL(raw_notifier_chain_unregister);
|
||||||
|
|
||||||
|
int raw_notifier_call_chain_robust(struct raw_notifier_head *nh,
|
||||||
|
unsigned long val_up, unsigned long val_down, void *v)
|
||||||
|
{
|
||||||
|
return notifier_call_chain_robust(&nh->head, val_up, val_down, v);
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(raw_notifier_call_chain_robust);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* __raw_notifier_call_chain - Call functions in a raw notifier chain
|
* raw_notifier_call_chain - Call functions in a raw notifier chain
|
||||||
* @nh: Pointer to head of the raw notifier chain
|
* @nh: Pointer to head of the raw notifier chain
|
||||||
* @val: Value passed unmodified to notifier function
|
* @val: Value passed unmodified to notifier function
|
||||||
* @v: Pointer passed unmodified to notifier function
|
* @v: Pointer passed unmodified to notifier function
|
||||||
* @nr_to_call: See comment for notifier_call_chain.
|
|
||||||
* @nr_calls: See comment for notifier_call_chain
|
|
||||||
*
|
*
|
||||||
* Calls each function in a notifier chain in turn. The functions
|
* Calls each function in a notifier chain in turn. The functions
|
||||||
* run in an undefined context.
|
* run in an undefined context.
|
||||||
|
@ -354,18 +404,10 @@ EXPORT_SYMBOL_GPL(raw_notifier_chain_unregister);
|
||||||
* Otherwise the return value is the return value
|
* Otherwise the return value is the return value
|
||||||
* of the last notifier function called.
|
* of the last notifier function called.
|
||||||
*/
|
*/
|
||||||
int __raw_notifier_call_chain(struct raw_notifier_head *nh,
|
|
||||||
unsigned long val, void *v,
|
|
||||||
int nr_to_call, int *nr_calls)
|
|
||||||
{
|
|
||||||
return notifier_call_chain(&nh->head, val, v, nr_to_call, nr_calls);
|
|
||||||
}
|
|
||||||
EXPORT_SYMBOL_GPL(__raw_notifier_call_chain);
|
|
||||||
|
|
||||||
int raw_notifier_call_chain(struct raw_notifier_head *nh,
|
int raw_notifier_call_chain(struct raw_notifier_head *nh,
|
||||||
unsigned long val, void *v)
|
unsigned long val, void *v)
|
||||||
{
|
{
|
||||||
return __raw_notifier_call_chain(nh, val, v, -1, NULL);
|
return notifier_call_chain(&nh->head, val, v, -1, NULL);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(raw_notifier_call_chain);
|
EXPORT_SYMBOL_GPL(raw_notifier_call_chain);
|
||||||
|
|
||||||
|
@ -437,12 +479,10 @@ int srcu_notifier_chain_unregister(struct srcu_notifier_head *nh,
|
||||||
EXPORT_SYMBOL_GPL(srcu_notifier_chain_unregister);
|
EXPORT_SYMBOL_GPL(srcu_notifier_chain_unregister);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* __srcu_notifier_call_chain - Call functions in an SRCU notifier chain
|
* srcu_notifier_call_chain - Call functions in an SRCU notifier chain
|
||||||
* @nh: Pointer to head of the SRCU notifier chain
|
* @nh: Pointer to head of the SRCU notifier chain
|
||||||
* @val: Value passed unmodified to notifier function
|
* @val: Value passed unmodified to notifier function
|
||||||
* @v: Pointer passed unmodified to notifier function
|
* @v: Pointer passed unmodified to notifier function
|
||||||
* @nr_to_call: See comment for notifier_call_chain.
|
|
||||||
* @nr_calls: See comment for notifier_call_chain
|
|
||||||
*
|
*
|
||||||
* Calls each function in a notifier chain in turn. The functions
|
* Calls each function in a notifier chain in turn. The functions
|
||||||
* run in a process context, so they are allowed to block.
|
* run in a process context, so they are allowed to block.
|
||||||
|
@ -454,25 +494,17 @@ EXPORT_SYMBOL_GPL(srcu_notifier_chain_unregister);
|
||||||
* Otherwise the return value is the return value
|
* Otherwise the return value is the return value
|
||||||
* of the last notifier function called.
|
* of the last notifier function called.
|
||||||
*/
|
*/
|
||||||
int __srcu_notifier_call_chain(struct srcu_notifier_head *nh,
|
int srcu_notifier_call_chain(struct srcu_notifier_head *nh,
|
||||||
unsigned long val, void *v,
|
unsigned long val, void *v)
|
||||||
int nr_to_call, int *nr_calls)
|
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
int idx;
|
int idx;
|
||||||
|
|
||||||
idx = srcu_read_lock(&nh->srcu);
|
idx = srcu_read_lock(&nh->srcu);
|
||||||
ret = notifier_call_chain(&nh->head, val, v, nr_to_call, nr_calls);
|
ret = notifier_call_chain(&nh->head, val, v, -1, NULL);
|
||||||
srcu_read_unlock(&nh->srcu, idx);
|
srcu_read_unlock(&nh->srcu, idx);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(__srcu_notifier_call_chain);
|
|
||||||
|
|
||||||
int srcu_notifier_call_chain(struct srcu_notifier_head *nh,
|
|
||||||
unsigned long val, void *v)
|
|
||||||
{
|
|
||||||
return __srcu_notifier_call_chain(nh, val, v, -1, NULL);
|
|
||||||
}
|
|
||||||
EXPORT_SYMBOL_GPL(srcu_notifier_call_chain);
|
EXPORT_SYMBOL_GPL(srcu_notifier_call_chain);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -706,8 +706,8 @@ static int load_image_and_restore(void)
|
||||||
*/
|
*/
|
||||||
int hibernate(void)
|
int hibernate(void)
|
||||||
{
|
{
|
||||||
int error, nr_calls = 0;
|
|
||||||
bool snapshot_test = false;
|
bool snapshot_test = false;
|
||||||
|
int error;
|
||||||
|
|
||||||
if (!hibernation_available()) {
|
if (!hibernation_available()) {
|
||||||
pm_pr_dbg("Hibernation not available.\n");
|
pm_pr_dbg("Hibernation not available.\n");
|
||||||
|
@ -723,11 +723,9 @@ int hibernate(void)
|
||||||
|
|
||||||
pr_info("hibernation entry\n");
|
pr_info("hibernation entry\n");
|
||||||
pm_prepare_console();
|
pm_prepare_console();
|
||||||
error = __pm_notifier_call_chain(PM_HIBERNATION_PREPARE, -1, &nr_calls);
|
error = pm_notifier_call_chain_robust(PM_HIBERNATION_PREPARE, PM_POST_HIBERNATION);
|
||||||
if (error) {
|
if (error)
|
||||||
nr_calls--;
|
goto Restore;
|
||||||
goto Exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
ksys_sync_helper();
|
ksys_sync_helper();
|
||||||
|
|
||||||
|
@ -785,7 +783,8 @@ int hibernate(void)
|
||||||
/* Don't bother checking whether freezer_test_done is true */
|
/* Don't bother checking whether freezer_test_done is true */
|
||||||
freezer_test_done = false;
|
freezer_test_done = false;
|
||||||
Exit:
|
Exit:
|
||||||
__pm_notifier_call_chain(PM_POST_HIBERNATION, nr_calls, NULL);
|
pm_notifier_call_chain(PM_POST_HIBERNATION);
|
||||||
|
Restore:
|
||||||
pm_restore_console();
|
pm_restore_console();
|
||||||
hibernate_release();
|
hibernate_release();
|
||||||
Unlock:
|
Unlock:
|
||||||
|
@ -804,7 +803,7 @@ int hibernate(void)
|
||||||
*/
|
*/
|
||||||
int hibernate_quiet_exec(int (*func)(void *data), void *data)
|
int hibernate_quiet_exec(int (*func)(void *data), void *data)
|
||||||
{
|
{
|
||||||
int error, nr_calls = 0;
|
int error;
|
||||||
|
|
||||||
lock_system_sleep();
|
lock_system_sleep();
|
||||||
|
|
||||||
|
@ -815,11 +814,9 @@ int hibernate_quiet_exec(int (*func)(void *data), void *data)
|
||||||
|
|
||||||
pm_prepare_console();
|
pm_prepare_console();
|
||||||
|
|
||||||
error = __pm_notifier_call_chain(PM_HIBERNATION_PREPARE, -1, &nr_calls);
|
error = pm_notifier_call_chain_robust(PM_HIBERNATION_PREPARE, PM_POST_HIBERNATION);
|
||||||
if (error) {
|
if (error)
|
||||||
nr_calls--;
|
goto restore;
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
error = freeze_processes();
|
error = freeze_processes();
|
||||||
if (error)
|
if (error)
|
||||||
|
@ -880,8 +877,9 @@ int hibernate_quiet_exec(int (*func)(void *data), void *data)
|
||||||
thaw_processes();
|
thaw_processes();
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
__pm_notifier_call_chain(PM_POST_HIBERNATION, nr_calls, NULL);
|
pm_notifier_call_chain(PM_POST_HIBERNATION);
|
||||||
|
|
||||||
|
restore:
|
||||||
pm_restore_console();
|
pm_restore_console();
|
||||||
|
|
||||||
hibernate_release();
|
hibernate_release();
|
||||||
|
@ -910,7 +908,7 @@ EXPORT_SYMBOL_GPL(hibernate_quiet_exec);
|
||||||
*/
|
*/
|
||||||
static int software_resume(void)
|
static int software_resume(void)
|
||||||
{
|
{
|
||||||
int error, nr_calls = 0;
|
int error;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the user said "noresume".. bail out early.
|
* If the user said "noresume".. bail out early.
|
||||||
|
@ -997,11 +995,9 @@ static int software_resume(void)
|
||||||
|
|
||||||
pr_info("resume from hibernation\n");
|
pr_info("resume from hibernation\n");
|
||||||
pm_prepare_console();
|
pm_prepare_console();
|
||||||
error = __pm_notifier_call_chain(PM_RESTORE_PREPARE, -1, &nr_calls);
|
error = pm_notifier_call_chain_robust(PM_RESTORE_PREPARE, PM_POST_RESTORE);
|
||||||
if (error) {
|
if (error)
|
||||||
nr_calls--;
|
goto Restore;
|
||||||
goto Close_Finish;
|
|
||||||
}
|
|
||||||
|
|
||||||
pm_pr_dbg("Preparing processes for hibernation restore.\n");
|
pm_pr_dbg("Preparing processes for hibernation restore.\n");
|
||||||
error = freeze_processes();
|
error = freeze_processes();
|
||||||
|
@ -1017,7 +1013,8 @@ static int software_resume(void)
|
||||||
error = load_image_and_restore();
|
error = load_image_and_restore();
|
||||||
thaw_processes();
|
thaw_processes();
|
||||||
Finish:
|
Finish:
|
||||||
__pm_notifier_call_chain(PM_POST_RESTORE, nr_calls, NULL);
|
pm_notifier_call_chain(PM_POST_RESTORE);
|
||||||
|
Restore:
|
||||||
pm_restore_console();
|
pm_restore_console();
|
||||||
pr_info("resume failed (%d)\n", error);
|
pr_info("resume failed (%d)\n", error);
|
||||||
hibernate_release();
|
hibernate_release();
|
||||||
|
|
|
@ -80,18 +80,18 @@ int unregister_pm_notifier(struct notifier_block *nb)
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(unregister_pm_notifier);
|
EXPORT_SYMBOL_GPL(unregister_pm_notifier);
|
||||||
|
|
||||||
int __pm_notifier_call_chain(unsigned long val, int nr_to_call, int *nr_calls)
|
int pm_notifier_call_chain_robust(unsigned long val_up, unsigned long val_down)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = __blocking_notifier_call_chain(&pm_chain_head, val, NULL,
|
ret = blocking_notifier_call_chain_robust(&pm_chain_head, val_up, val_down, NULL);
|
||||||
nr_to_call, nr_calls);
|
|
||||||
|
|
||||||
return notifier_to_errno(ret);
|
return notifier_to_errno(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
int pm_notifier_call_chain(unsigned long val)
|
int pm_notifier_call_chain(unsigned long val)
|
||||||
{
|
{
|
||||||
return __pm_notifier_call_chain(val, -1, NULL);
|
return blocking_notifier_call_chain(&pm_chain_head, val, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If set, devices may be suspended and resumed asynchronously. */
|
/* If set, devices may be suspended and resumed asynchronously. */
|
||||||
|
|
|
@ -210,8 +210,7 @@ static inline void suspend_test_finish(const char *label) {}
|
||||||
|
|
||||||
#ifdef CONFIG_PM_SLEEP
|
#ifdef CONFIG_PM_SLEEP
|
||||||
/* kernel/power/main.c */
|
/* kernel/power/main.c */
|
||||||
extern int __pm_notifier_call_chain(unsigned long val, int nr_to_call,
|
extern int pm_notifier_call_chain_robust(unsigned long val_up, unsigned long val_down);
|
||||||
int *nr_calls);
|
|
||||||
extern int pm_notifier_call_chain(unsigned long val);
|
extern int pm_notifier_call_chain(unsigned long val);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -342,18 +342,16 @@ static int suspend_test(int level)
|
||||||
*/
|
*/
|
||||||
static int suspend_prepare(suspend_state_t state)
|
static int suspend_prepare(suspend_state_t state)
|
||||||
{
|
{
|
||||||
int error, nr_calls = 0;
|
int error;
|
||||||
|
|
||||||
if (!sleep_state_supported(state))
|
if (!sleep_state_supported(state))
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
|
|
||||||
pm_prepare_console();
|
pm_prepare_console();
|
||||||
|
|
||||||
error = __pm_notifier_call_chain(PM_SUSPEND_PREPARE, -1, &nr_calls);
|
error = pm_notifier_call_chain_robust(PM_SUSPEND_PREPARE, PM_POST_SUSPEND);
|
||||||
if (error) {
|
if (error)
|
||||||
nr_calls--;
|
goto Restore;
|
||||||
goto Finish;
|
|
||||||
}
|
|
||||||
|
|
||||||
trace_suspend_resume(TPS("freeze_processes"), 0, true);
|
trace_suspend_resume(TPS("freeze_processes"), 0, true);
|
||||||
error = suspend_freeze_processes();
|
error = suspend_freeze_processes();
|
||||||
|
@ -363,8 +361,8 @@ static int suspend_prepare(suspend_state_t state)
|
||||||
|
|
||||||
suspend_stats.failed_freeze++;
|
suspend_stats.failed_freeze++;
|
||||||
dpm_save_failed_step(SUSPEND_FREEZE);
|
dpm_save_failed_step(SUSPEND_FREEZE);
|
||||||
Finish:
|
pm_notifier_call_chain(PM_POST_SUSPEND);
|
||||||
__pm_notifier_call_chain(PM_POST_SUSPEND, nr_calls, NULL);
|
Restore:
|
||||||
pm_restore_console();
|
pm_restore_console();
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ int is_hibernate_resume_dev(const struct inode *bd_inode)
|
||||||
static int snapshot_open(struct inode *inode, struct file *filp)
|
static int snapshot_open(struct inode *inode, struct file *filp)
|
||||||
{
|
{
|
||||||
struct snapshot_data *data;
|
struct snapshot_data *data;
|
||||||
int error, nr_calls = 0;
|
int error;
|
||||||
|
|
||||||
if (!hibernation_available())
|
if (!hibernation_available())
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
|
@ -73,9 +73,7 @@ static int snapshot_open(struct inode *inode, struct file *filp)
|
||||||
swap_type_of(swsusp_resume_device, 0, NULL) : -1;
|
swap_type_of(swsusp_resume_device, 0, NULL) : -1;
|
||||||
data->mode = O_RDONLY;
|
data->mode = O_RDONLY;
|
||||||
data->free_bitmaps = false;
|
data->free_bitmaps = false;
|
||||||
error = __pm_notifier_call_chain(PM_HIBERNATION_PREPARE, -1, &nr_calls);
|
error = pm_notifier_call_chain_robust(PM_HIBERNATION_PREPARE, PM_POST_HIBERNATION);
|
||||||
if (error)
|
|
||||||
__pm_notifier_call_chain(PM_POST_HIBERNATION, --nr_calls, NULL);
|
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
* Resuming. We may need to wait for the image device to
|
* Resuming. We may need to wait for the image device to
|
||||||
|
@ -85,15 +83,11 @@ static int snapshot_open(struct inode *inode, struct file *filp)
|
||||||
|
|
||||||
data->swap = -1;
|
data->swap = -1;
|
||||||
data->mode = O_WRONLY;
|
data->mode = O_WRONLY;
|
||||||
error = __pm_notifier_call_chain(PM_RESTORE_PREPARE, -1, &nr_calls);
|
error = pm_notifier_call_chain_robust(PM_RESTORE_PREPARE, PM_POST_RESTORE);
|
||||||
if (!error) {
|
if (!error) {
|
||||||
error = create_basic_memory_bitmaps();
|
error = create_basic_memory_bitmaps();
|
||||||
data->free_bitmaps = !error;
|
data->free_bitmaps = !error;
|
||||||
} else
|
}
|
||||||
nr_calls--;
|
|
||||||
|
|
||||||
if (error)
|
|
||||||
__pm_notifier_call_chain(PM_POST_RESTORE, nr_calls, NULL);
|
|
||||||
}
|
}
|
||||||
if (error)
|
if (error)
|
||||||
hibernate_release();
|
hibernate_release();
|
||||||
|
|
|
@ -171,7 +171,7 @@ class SystemValues:
|
||||||
tracefuncs = {
|
tracefuncs = {
|
||||||
'sys_sync': {},
|
'sys_sync': {},
|
||||||
'ksys_sync': {},
|
'ksys_sync': {},
|
||||||
'__pm_notifier_call_chain': {},
|
'pm_notifier_call_chain_robust': {},
|
||||||
'pm_prepare_console': {},
|
'pm_prepare_console': {},
|
||||||
'pm_notifier_call_chain': {},
|
'pm_notifier_call_chain': {},
|
||||||
'freeze_processes': {},
|
'freeze_processes': {},
|
||||||
|
|
Loading…
Reference in New Issue
Block a user