Skip to content

Commit c1a957d

Browse files
KAGA-KOKOrafaeljw
authored andcommitted
PM / suspend: Prevent might sleep splats
timekeeping suspend/resume calls read_persistent_clock() which takes rtc_lock. That results in might sleep warnings because at that point we run with interrupts disabled. We cannot convert rtc_lock to a raw spinlock as that would trigger other might sleep warnings. As a workaround we disable the might sleep warnings by setting system_state to SYSTEM_SUSPEND before calling sysdev_suspend() and restoring it to SYSTEM_RUNNING afer sysdev_resume(). There is no lock contention because hibernate / suspend to RAM is single-CPU at this point. In s2idle's case the system_state is set to SYSTEM_SUSPEND before timekeeping_suspend() which is invoked by the last CPU. In the resume case it set back to SYSTEM_RUNNING after timekeeping_resume() which is invoked by the first CPU in the resume case. The other CPUs will block on tick_freeze_lock. Signed-off-by: Thomas Gleixner <[email protected]> [bigeasy: cover s2idle in tick_freeze() / tick_unfreeze()] Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 771c577 commit c1a957d

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

include/linux/kernel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ extern enum system_states {
542542
SYSTEM_HALT,
543543
SYSTEM_POWER_OFF,
544544
SYSTEM_RESTART,
545+
SYSTEM_SUSPEND,
545546
} system_state;
546547

547548
/* This cannot be an enum because some may be used in assembly source. */

kernel/power/hibernate.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ static int create_image(int platform_mode)
287287

288288
local_irq_disable();
289289

290+
system_state = SYSTEM_SUSPEND;
291+
290292
error = syscore_suspend();
291293
if (error) {
292294
pr_err("Some system devices failed to power down, aborting hibernation\n");
@@ -317,6 +319,7 @@ static int create_image(int platform_mode)
317319
syscore_resume();
318320

319321
Enable_irqs:
322+
system_state = SYSTEM_RUNNING;
320323
local_irq_enable();
321324

322325
Enable_cpus:
@@ -445,6 +448,7 @@ static int resume_target_kernel(bool platform_mode)
445448
goto Enable_cpus;
446449

447450
local_irq_disable();
451+
system_state = SYSTEM_SUSPEND;
448452

449453
error = syscore_suspend();
450454
if (error)
@@ -478,6 +482,7 @@ static int resume_target_kernel(bool platform_mode)
478482
syscore_resume();
479483

480484
Enable_irqs:
485+
system_state = SYSTEM_RUNNING;
481486
local_irq_enable();
482487

483488
Enable_cpus:
@@ -563,6 +568,7 @@ int hibernation_platform_enter(void)
563568
goto Enable_cpus;
564569

565570
local_irq_disable();
571+
system_state = SYSTEM_SUSPEND;
566572
syscore_suspend();
567573
if (pm_wakeup_pending()) {
568574
error = -EAGAIN;
@@ -575,6 +581,7 @@ int hibernation_platform_enter(void)
575581

576582
Power_up:
577583
syscore_resume();
584+
system_state = SYSTEM_RUNNING;
578585
local_irq_enable();
579586

580587
Enable_cpus:

kernel/power/suspend.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,8 @@ static int suspend_enter(suspend_state_t state, bool *wakeup)
428428
arch_suspend_disable_irqs();
429429
BUG_ON(!irqs_disabled());
430430

431+
system_state = SYSTEM_SUSPEND;
432+
431433
error = syscore_suspend();
432434
if (!error) {
433435
*wakeup = pm_wakeup_pending();
@@ -443,6 +445,8 @@ static int suspend_enter(suspend_state_t state, bool *wakeup)
443445
syscore_resume();
444446
}
445447

448+
system_state = SYSTEM_RUNNING;
449+
446450
arch_suspend_enable_irqs();
447451
BUG_ON(irqs_disabled());
448452

kernel/time/tick-common.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ void tick_freeze(void)
490490
if (tick_freeze_depth == num_online_cpus()) {
491491
trace_suspend_resume(TPS("timekeeping_freeze"),
492492
smp_processor_id(), true);
493+
system_state = SYSTEM_SUSPEND;
493494
timekeeping_suspend();
494495
} else {
495496
tick_suspend_local();
@@ -513,6 +514,7 @@ void tick_unfreeze(void)
513514

514515
if (tick_freeze_depth == num_online_cpus()) {
515516
timekeeping_resume();
517+
system_state = SYSTEM_RUNNING;
516518
trace_suspend_resume(TPS("timekeeping_freeze"),
517519
smp_processor_id(), false);
518520
} else {

0 commit comments

Comments
 (0)