Skip to content

Commit eed4d47

Browse files
committed
ACPI / sleep: Ignore spurious SCI wakeups from suspend-to-idle
The ACPI SCI (System Control Interrupt) is set up as a wakeup IRQ during suspend-to-idle transitions and, consequently, any events signaled through it wake up the system from that state. However, on some systems some of the events signaled via the ACPI SCI while suspended to idle should not cause the system to wake up. In fact, quite often they should just be discarded. Arguably, systems should not resume entirely on such events, but in order to decide which events really should cause the system to resume and which are spurious, it is necessary to resume up to the point when ACPI SCIs are actually handled and processed, which is after executing dpm_resume_noirq() in the system resume path. For this reasons, add a loop around freeze_enter() in which the platforms can process events signaled via multiplexed IRQ lines like the ACPI SCI and add suspend-to-idle hooks that can be used for this purpose to struct platform_freeze_ops. In the ACPI case, the ->wake hook is used for checking if the SCI has triggered while suspended and deferring the interrupt-induced system wakeup until the events signaled through it are actually processed sufficiently to decide whether or not the system should resume. In turn, the ->sync hook allows all of the relevant event queues to be flushed so as to prevent events from being missed due to race conditions. In addition to that, some ACPI code processing wakeup events needs to be modified to use the "hard" version of wakeup triggers, so that it will cause a system resume to happen on device-induced wakeup events even if the "soft" mechanism to prevent the system from suspending is not enabled (that also helps to catch device-induced wakeup events occurring during suspend transitions in progress). Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 8a537ec commit eed4d47

9 files changed

Lines changed: 77 additions & 22 deletions

File tree

‎drivers/acpi/battery.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ static int acpi_battery_update(struct acpi_battery *battery, bool resume)
776776
if ((battery->state & ACPI_BATTERY_STATE_CRITICAL) ||
777777
(test_bit(ACPI_BATTERY_ALARM_PRESENT, &battery->flags) &&
778778
(battery->capacity_now <= battery->alarm)))
779-
pm_wakeup_event(&battery->device->dev, 0);
779+
pm_wakeup_hard_event(&battery->device->dev);
780780

781781
return result;
782782
}

‎drivers/acpi/button.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ static int acpi_lid_notify_state(struct acpi_device *device, int state)
216216
}
217217

218218
if (state)
219-
pm_wakeup_event(&device->dev, 0);
219+
pm_wakeup_hard_event(&device->dev);
220220

221221
ret = blocking_notifier_call_chain(&acpi_lid_notifier, state, device);
222222
if (ret == NOTIFY_DONE)
@@ -398,7 +398,7 @@ static void acpi_button_notify(struct acpi_device *device, u32 event)
398398
} else {
399399
int keycode;
400400

401-
pm_wakeup_event(&device->dev, 0);
401+
pm_wakeup_hard_event(&device->dev);
402402
if (button->suspended)
403403
break;
404404

@@ -530,6 +530,7 @@ static int acpi_button_add(struct acpi_device *device)
530530
lid_device = device;
531531
}
532532

533+
device_init_wakeup(&device->dev, true);
533534
printk(KERN_INFO PREFIX "%s [%s]\n", name, acpi_device_bid(device));
534535
return 0;
535536

‎drivers/acpi/device_pm.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/pm_qos.h>
2525
#include <linux/pm_domain.h>
2626
#include <linux/pm_runtime.h>
27+
#include <linux/suspend.h>
2728

2829
#include "internal.h"
2930

@@ -399,7 +400,7 @@ static void acpi_pm_notify_handler(acpi_handle handle, u32 val, void *not_used)
399400
mutex_lock(&acpi_pm_notifier_lock);
400401

401402
if (adev->wakeup.flags.notifier_present) {
402-
__pm_wakeup_event(adev->wakeup.ws, 0);
403+
pm_wakeup_ws_event(adev->wakeup.ws, 0, true);
403404
if (adev->wakeup.context.work.func)
404405
queue_pm_work(&adev->wakeup.context.work);
405406
}

‎drivers/acpi/sleep.c‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,14 +662,40 @@ static int acpi_freeze_prepare(void)
662662
acpi_os_wait_events_complete();
663663
if (acpi_sci_irq_valid())
664664
enable_irq_wake(acpi_sci_irq);
665+
665666
return 0;
666667
}
667668

669+
static void acpi_freeze_wake(void)
670+
{
671+
/*
672+
* If IRQD_WAKEUP_ARMED is not set for the SCI at this point, it means
673+
* that the SCI has triggered while suspended, so cancel the wakeup in
674+
* case it has not been a wakeup event (the GPEs will be checked later).
675+
*/
676+
if (acpi_sci_irq_valid() &&
677+
!irqd_is_wakeup_armed(irq_get_irq_data(acpi_sci_irq)))
678+
pm_system_cancel_wakeup();
679+
}
680+
681+
static void acpi_freeze_sync(void)
682+
{
683+
/*
684+
* Process all pending events in case there are any wakeup ones.
685+
*
686+
* The EC driver uses the system workqueue, so that one needs to be
687+
* flushed too.
688+
*/
689+
acpi_os_wait_events_complete();
690+
flush_scheduled_work();
691+
}
692+
668693
static void acpi_freeze_restore(void)
669694
{
670695
acpi_disable_wakeup_devices(ACPI_STATE_S0);
671696
if (acpi_sci_irq_valid())
672697
disable_irq_wake(acpi_sci_irq);
698+
673699
acpi_enable_all_runtime_gpes();
674700
}
675701

@@ -681,6 +707,8 @@ static void acpi_freeze_end(void)
681707
static const struct platform_freeze_ops acpi_freeze_ops = {
682708
.begin = acpi_freeze_begin,
683709
.prepare = acpi_freeze_prepare,
710+
.wake = acpi_freeze_wake,
711+
.sync = acpi_freeze_sync,
684712
.restore = acpi_freeze_restore,
685713
.end = acpi_freeze_end,
686714
};

‎drivers/base/power/main.c‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,11 +1091,6 @@ static int __device_suspend_noirq(struct device *dev, pm_message_t state, bool a
10911091
if (async_error)
10921092
goto Complete;
10931093

1094-
if (pm_wakeup_pending()) {
1095-
async_error = -EBUSY;
1096-
goto Complete;
1097-
}
1098-
10991094
if (dev->power.syscore || dev->power.direct_complete)
11001095
goto Complete;
11011096

‎drivers/base/power/wakeup.c‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ bool events_check_enabled __read_mostly;
2828
/* First wakeup IRQ seen by the kernel in the last cycle. */
2929
unsigned int pm_wakeup_irq __read_mostly;
3030

31-
/* If set and the system is suspending, terminate the suspend. */
32-
static bool pm_abort_suspend __read_mostly;
31+
/* If greater than 0 and the system is suspending, terminate the suspend. */
32+
static atomic_t pm_abort_suspend __read_mostly;
3333

3434
/*
3535
* Combined counters of registered wakeup events and wakeup events in progress.
@@ -856,20 +856,26 @@ bool pm_wakeup_pending(void)
856856
pm_print_active_wakeup_sources();
857857
}
858858

859-
return ret || pm_abort_suspend;
859+
return ret || atomic_read(&pm_abort_suspend) > 0;
860860
}
861861

862862
void pm_system_wakeup(void)
863863
{
864-
pm_abort_suspend = true;
864+
atomic_inc(&pm_abort_suspend);
865865
freeze_wake();
866866
}
867867
EXPORT_SYMBOL_GPL(pm_system_wakeup);
868868

869-
void pm_wakeup_clear(void)
869+
void pm_system_cancel_wakeup(void)
870+
{
871+
atomic_dec(&pm_abort_suspend);
872+
}
873+
874+
void pm_wakeup_clear(bool reset)
870875
{
871-
pm_abort_suspend = false;
872876
pm_wakeup_irq = 0;
877+
if (reset)
878+
atomic_set(&pm_abort_suspend, 0);
873879
}
874880

875881
void pm_system_irq_wakeup(unsigned int irq_number)

‎include/linux/suspend.h‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ struct platform_suspend_ops {
189189
struct platform_freeze_ops {
190190
int (*begin)(void);
191191
int (*prepare)(void);
192+
void (*wake)(void);
193+
void (*sync)(void);
192194
void (*restore)(void);
193195
void (*end)(void);
194196
};
@@ -428,7 +430,8 @@ extern unsigned int pm_wakeup_irq;
428430

429431
extern bool pm_wakeup_pending(void);
430432
extern void pm_system_wakeup(void);
431-
extern void pm_wakeup_clear(void);
433+
extern void pm_system_cancel_wakeup(void);
434+
extern void pm_wakeup_clear(bool reset);
432435
extern void pm_system_irq_wakeup(unsigned int irq_number);
433436
extern bool pm_get_wakeup_count(unsigned int *count, bool block);
434437
extern bool pm_save_wakeup_count(unsigned int count);
@@ -478,7 +481,7 @@ static inline int unregister_pm_notifier(struct notifier_block *nb)
478481

479482
static inline bool pm_wakeup_pending(void) { return false; }
480483
static inline void pm_system_wakeup(void) {}
481-
static inline void pm_wakeup_clear(void) {}
484+
static inline void pm_wakeup_clear(bool reset) {}
482485
static inline void pm_system_irq_wakeup(unsigned int irq_number) {}
483486

484487
static inline void lock_system_sleep(void) {}

‎kernel/power/process.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ int freeze_processes(void)
132132
if (!pm_freezing)
133133
atomic_inc(&system_freezing_cnt);
134134

135-
pm_wakeup_clear();
135+
pm_wakeup_clear(true);
136136
pr_info("Freezing user space processes ... ");
137137
pm_freezing = true;
138138
error = try_to_freeze_tasks(true);

‎kernel/power/suspend.c‎

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ static void freeze_begin(void)
7272

7373
static void freeze_enter(void)
7474
{
75+
trace_suspend_resume(TPS("machine_suspend"), PM_SUSPEND_FREEZE, true);
76+
7577
spin_lock_irq(&suspend_freeze_lock);
7678
if (pm_wakeup_pending())
7779
goto out;
@@ -98,6 +100,27 @@ static void freeze_enter(void)
98100
out:
99101
suspend_freeze_state = FREEZE_STATE_NONE;
100102
spin_unlock_irq(&suspend_freeze_lock);
103+
104+
trace_suspend_resume(TPS("machine_suspend"), PM_SUSPEND_FREEZE, false);
105+
}
106+
107+
static void s2idle_loop(void)
108+
{
109+
do {
110+
freeze_enter();
111+
112+
if (freeze_ops && freeze_ops->wake)
113+
freeze_ops->wake();
114+
115+
dpm_resume_noirq(PMSG_RESUME);
116+
if (freeze_ops && freeze_ops->sync)
117+
freeze_ops->sync();
118+
119+
if (pm_wakeup_pending())
120+
break;
121+
122+
pm_wakeup_clear(false);
123+
} while (!dpm_suspend_noirq(PMSG_SUSPEND));
101124
}
102125

103126
void freeze_wake(void)
@@ -371,10 +394,8 @@ static int suspend_enter(suspend_state_t state, bool *wakeup)
371394
* all the devices are suspended.
372395
*/
373396
if (state == PM_SUSPEND_FREEZE) {
374-
trace_suspend_resume(TPS("machine_suspend"), state, true);
375-
freeze_enter();
376-
trace_suspend_resume(TPS("machine_suspend"), state, false);
377-
goto Platform_wake;
397+
s2idle_loop();
398+
goto Platform_early_resume;
378399
}
379400

380401
error = disable_nonboot_cpus();

0 commit comments

Comments
 (0)