Skip to content

Commit ea00f4f

Browse files
lianweirafaeljw
authored andcommitted
PM / sleep: make PM notifiers called symmetrically
This makes pm notifier PREPARE/POST symmetrical: if PREPARE fails, we will only undo what ever happened on PREPARE. It fixes the unbalanced CPU hotplug enable in CPU PM notifier. Signed-off-by: Lianwei Wang <lianwei.wang@gmail.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent ca5f2b4 commit ea00f4f

5 files changed

Lines changed: 37 additions & 20 deletions

File tree

‎kernel/power/hibernate.c‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ static void power_down(void)
647647
*/
648648
int hibernate(void)
649649
{
650-
int error;
650+
int error, nr_calls = 0;
651651

652652
if (!hibernation_available()) {
653653
pr_debug("PM: Hibernation not available.\n");
@@ -662,9 +662,11 @@ int hibernate(void)
662662
}
663663

664664
pm_prepare_console();
665-
error = pm_notifier_call_chain(PM_HIBERNATION_PREPARE);
666-
if (error)
665+
error = __pm_notifier_call_chain(PM_HIBERNATION_PREPARE, -1, &nr_calls);
666+
if (error) {
667+
nr_calls--;
667668
goto Exit;
669+
}
668670

669671
printk(KERN_INFO "PM: Syncing filesystems ... ");
670672
sys_sync();
@@ -714,7 +716,7 @@ int hibernate(void)
714716
/* Don't bother checking whether freezer_test_done is true */
715717
freezer_test_done = false;
716718
Exit:
717-
pm_notifier_call_chain(PM_POST_HIBERNATION);
719+
__pm_notifier_call_chain(PM_POST_HIBERNATION, nr_calls, NULL);
718720
pm_restore_console();
719721
atomic_inc(&snapshot_device_available);
720722
Unlock:
@@ -740,7 +742,7 @@ int hibernate(void)
740742
*/
741743
static int software_resume(void)
742744
{
743-
int error;
745+
int error, nr_calls = 0;
744746
unsigned int flags;
745747

746748
/*
@@ -827,9 +829,11 @@ static int software_resume(void)
827829
}
828830

829831
pm_prepare_console();
830-
error = pm_notifier_call_chain(PM_RESTORE_PREPARE);
831-
if (error)
832+
error = __pm_notifier_call_chain(PM_RESTORE_PREPARE, -1, &nr_calls);
833+
if (error) {
834+
nr_calls--;
832835
goto Close_Finish;
836+
}
833837

834838
pr_debug("PM: Preparing processes for restore.\n");
835839
error = freeze_processes();
@@ -855,7 +859,7 @@ static int software_resume(void)
855859
unlock_device_hotplug();
856860
thaw_processes();
857861
Finish:
858-
pm_notifier_call_chain(PM_POST_RESTORE);
862+
__pm_notifier_call_chain(PM_POST_RESTORE, nr_calls, NULL);
859863
pm_restore_console();
860864
atomic_inc(&snapshot_device_available);
861865
/* For success case, the suspend path will release the lock */

‎kernel/power/main.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,19 @@ int unregister_pm_notifier(struct notifier_block *nb)
3838
}
3939
EXPORT_SYMBOL_GPL(unregister_pm_notifier);
4040

41-
int pm_notifier_call_chain(unsigned long val)
41+
int __pm_notifier_call_chain(unsigned long val, int nr_to_call, int *nr_calls)
4242
{
43-
int ret = blocking_notifier_call_chain(&pm_chain_head, val, NULL);
43+
int ret;
44+
45+
ret = __blocking_notifier_call_chain(&pm_chain_head, val, NULL,
46+
nr_to_call, nr_calls);
4447

4548
return notifier_to_errno(ret);
4649
}
50+
int pm_notifier_call_chain(unsigned long val)
51+
{
52+
return __pm_notifier_call_chain(val, -1, NULL);
53+
}
4754

4855
/* If set, devices may be suspended and resumed asynchronously. */
4956
int pm_async_enabled = 1;

‎kernel/power/power.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ static inline void suspend_test_finish(const char *label) {}
200200

201201
#ifdef CONFIG_PM_SLEEP
202202
/* kernel/power/main.c */
203+
extern int __pm_notifier_call_chain(unsigned long val, int nr_to_call,
204+
int *nr_calls);
203205
extern int pm_notifier_call_chain(unsigned long val);
204206
#endif
205207

‎kernel/power/suspend.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,16 +266,18 @@ static int suspend_test(int level)
266266
*/
267267
static int suspend_prepare(suspend_state_t state)
268268
{
269-
int error;
269+
int error, nr_calls = 0;
270270

271271
if (!sleep_state_supported(state))
272272
return -EPERM;
273273

274274
pm_prepare_console();
275275

276-
error = pm_notifier_call_chain(PM_SUSPEND_PREPARE);
277-
if (error)
276+
error = __pm_notifier_call_chain(PM_SUSPEND_PREPARE, -1, &nr_calls);
277+
if (error) {
278+
nr_calls--;
278279
goto Finish;
280+
}
279281

280282
trace_suspend_resume(TPS("freeze_processes"), 0, true);
281283
error = suspend_freeze_processes();
@@ -286,7 +288,7 @@ static int suspend_prepare(suspend_state_t state)
286288
suspend_stats.failed_freeze++;
287289
dpm_save_failed_step(SUSPEND_FREEZE);
288290
Finish:
289-
pm_notifier_call_chain(PM_POST_SUSPEND);
291+
__pm_notifier_call_chain(PM_POST_SUSPEND, nr_calls, NULL);
290292
pm_restore_console();
291293
return error;
292294
}

‎kernel/power/user.c‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ atomic_t snapshot_device_available = ATOMIC_INIT(1);
4747
static int snapshot_open(struct inode *inode, struct file *filp)
4848
{
4949
struct snapshot_data *data;
50-
int error;
50+
int error, nr_calls = 0;
5151

5252
if (!hibernation_available())
5353
return -EPERM;
@@ -74,9 +74,9 @@ static int snapshot_open(struct inode *inode, struct file *filp)
7474
swap_type_of(swsusp_resume_device, 0, NULL) : -1;
7575
data->mode = O_RDONLY;
7676
data->free_bitmaps = false;
77-
error = pm_notifier_call_chain(PM_HIBERNATION_PREPARE);
77+
error = __pm_notifier_call_chain(PM_HIBERNATION_PREPARE, -1, &nr_calls);
7878
if (error)
79-
pm_notifier_call_chain(PM_POST_HIBERNATION);
79+
__pm_notifier_call_chain(PM_POST_HIBERNATION, --nr_calls, NULL);
8080
} else {
8181
/*
8282
* Resuming. We may need to wait for the image device to
@@ -86,13 +86,15 @@ static int snapshot_open(struct inode *inode, struct file *filp)
8686

8787
data->swap = -1;
8888
data->mode = O_WRONLY;
89-
error = pm_notifier_call_chain(PM_RESTORE_PREPARE);
89+
error = __pm_notifier_call_chain(PM_RESTORE_PREPARE, -1, &nr_calls);
9090
if (!error) {
9191
error = create_basic_memory_bitmaps();
9292
data->free_bitmaps = !error;
93-
}
93+
} else
94+
nr_calls--;
95+
9496
if (error)
95-
pm_notifier_call_chain(PM_POST_RESTORE);
97+
__pm_notifier_call_chain(PM_POST_RESTORE, nr_calls, NULL);
9698
}
9799
if (error)
98100
atomic_inc(&snapshot_device_available);

0 commit comments

Comments
 (0)