Skip to content

Commit cb1f65c

Browse files
committed
PM: s2idle: ACPI: Fix wakeup interrupts handling
After commit e3728b5 ("ACPI: PM: s2idle: Avoid possible race related to the EC GPE") wakeup interrupts occurring immediately after the one discarded by acpi_s2idle_wake() may be missed. Moreover, if the SCI triggers again immediately after the rearming in acpi_s2idle_wake(), that wakeup may be missed too. The problem is that pm_system_irq_wakeup() only calls pm_system_wakeup() when pm_wakeup_irq is 0, but that's not the case any more after the interrupt causing acpi_s2idle_wake() to run until pm_wakeup_irq is cleared by the pm_wakeup_clear() call in s2idle_loop(). However, there may be wakeup interrupts occurring in that time frame and if that happens, they will be missed. To address that issue first move the clearing of pm_wakeup_irq to the point at which it is known that the interrupt causing acpi_s2idle_wake() to tun will be discarded, before rearming the SCI for wakeup. Moreover, because that only reduces the size of the time window in which the issue may manifest itself, allow pm_system_irq_wakeup() to register two second wakeup interrupts in a row and, when discarding the first one, replace it with the second one. [Of course, this assumes that only one wakeup interrupt can be discarded in one go, but currently that is the case and I am not aware of any plans to change that.] Fixes: e3728b5 ("ACPI: PM: s2idle: Avoid possible race related to the EC GPE") Cc: 5.4+ <stable@vger.kernel.org> # 5.4+ Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent dc0075b commit cb1f65c

File tree

6 files changed

+42
-13
lines changed

6 files changed

+42
-13
lines changed

drivers/acpi/sleep.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,7 @@ bool acpi_s2idle_wake(void)
758758
return true;
759759
}
760760

761+
pm_wakeup_clear(acpi_sci_irq);
761762
rearm_wake_irq(acpi_sci_irq);
762763
}
763764

drivers/base/power/wakeup.c

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ suspend_state_t pm_suspend_target_state;
3434
bool events_check_enabled __read_mostly;
3535

3636
/* First wakeup IRQ seen by the kernel in the last cycle. */
37-
unsigned int pm_wakeup_irq __read_mostly;
37+
static unsigned int wakeup_irq[2] __read_mostly;
38+
static DEFINE_RAW_SPINLOCK(wakeup_irq_lock);
3839

3940
/* If greater than 0 and the system is suspending, terminate the suspend. */
4041
static atomic_t pm_abort_suspend __read_mostly;
@@ -942,19 +943,45 @@ void pm_system_cancel_wakeup(void)
942943
atomic_dec_if_positive(&pm_abort_suspend);
943944
}
944945

945-
void pm_wakeup_clear(bool reset)
946+
void pm_wakeup_clear(unsigned int irq_number)
946947
{
947-
pm_wakeup_irq = 0;
948-
if (reset)
948+
raw_spin_lock_irq(&wakeup_irq_lock);
949+
950+
if (irq_number && wakeup_irq[0] == irq_number)
951+
wakeup_irq[0] = wakeup_irq[1];
952+
else
953+
wakeup_irq[0] = 0;
954+
955+
wakeup_irq[1] = 0;
956+
957+
raw_spin_unlock_irq(&wakeup_irq_lock);
958+
959+
if (!irq_number)
949960
atomic_set(&pm_abort_suspend, 0);
950961
}
951962

952963
void pm_system_irq_wakeup(unsigned int irq_number)
953964
{
954-
if (pm_wakeup_irq == 0) {
955-
pm_wakeup_irq = irq_number;
965+
unsigned long flags;
966+
967+
raw_spin_lock_irqsave(&wakeup_irq_lock, flags);
968+
969+
if (wakeup_irq[0] == 0)
970+
wakeup_irq[0] = irq_number;
971+
else if (wakeup_irq[1] == 0)
972+
wakeup_irq[1] = irq_number;
973+
else
974+
irq_number = 0;
975+
976+
raw_spin_unlock_irqrestore(&wakeup_irq_lock, flags);
977+
978+
if (irq_number)
956979
pm_system_wakeup();
957-
}
980+
}
981+
982+
unsigned int pm_wakeup_irq(void)
983+
{
984+
return wakeup_irq[0];
958985
}
959986

960987
/**

include/linux/suspend.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,14 +497,14 @@ extern void ksys_sync_helper(void);
497497

498498
/* drivers/base/power/wakeup.c */
499499
extern bool events_check_enabled;
500-
extern unsigned int pm_wakeup_irq;
501500
extern suspend_state_t pm_suspend_target_state;
502501

503502
extern bool pm_wakeup_pending(void);
504503
extern void pm_system_wakeup(void);
505504
extern void pm_system_cancel_wakeup(void);
506-
extern void pm_wakeup_clear(bool reset);
505+
extern void pm_wakeup_clear(unsigned int irq_number);
507506
extern void pm_system_irq_wakeup(unsigned int irq_number);
507+
extern unsigned int pm_wakeup_irq(void);
508508
extern bool pm_get_wakeup_count(unsigned int *count, bool block);
509509
extern bool pm_save_wakeup_count(unsigned int count);
510510
extern void pm_wakep_autosleep_enabled(bool set);

kernel/power/main.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,10 @@ static ssize_t pm_wakeup_irq_show(struct kobject *kobj,
504504
struct kobj_attribute *attr,
505505
char *buf)
506506
{
507-
return pm_wakeup_irq ? sprintf(buf, "%u\n", pm_wakeup_irq) : -ENODATA;
507+
if (!pm_wakeup_irq())
508+
return -ENODATA;
509+
510+
return sprintf(buf, "%u\n", pm_wakeup_irq());
508511
}
509512

510513
power_attr_ro(pm_wakeup_irq);

kernel/power/process.c

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

137-
pm_wakeup_clear(true);
137+
pm_wakeup_clear(0);
138138
pr_info("Freezing user space processes ... ");
139139
pm_freezing = true;
140140
error = try_to_freeze_tasks(true);

kernel/power/suspend.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,6 @@ static void s2idle_loop(void)
136136
break;
137137
}
138138

139-
pm_wakeup_clear(false);
140-
141139
s2idle_enter();
142140
}
143141

0 commit comments

Comments
 (0)