ACPI: PM: s2idle: Harden the premature EC wakeups handling
Subsystems (2)
cover ACPI: PM: s2idle: Harden the premature EC wakeups handling
Hi All,
It turns out that the checks added by commit fdde0ff8590b ("ACPI: PM: s2idle:
Prevent spurious SCIs from waking up the system") were not precise enough and there are cases in which it actually doesn't prevent the system from resuming due to a spurious wakeup event coming from the EC.
To fix that issue, allow acpi_any_gpe_status_set() to skip one GPE from the check carried out by it (patch [1/2]) and use that for skipping the EC GPE from that check in the suspend-to-idle loop, which then allows the wakeup events coming from the EC to be checked more precisely (patch [2/2]).
Thanks!
PATCH 1/2 ACPICA: Allow acpi_any_gpe_status_set() to skip one GPE
From: "Rafael J. Wysocki" <[email protected]>
The check carried out by acpi_any_gpe_status_set() is not precise enough for the suspend-to-idle implementation in Linux and in some cases it is necessary make it skip one GPE (specifically, the EC GPE) from the check to prevent a race condition leading to a premature system resume from occurring.
For this reason, redefine acpi_any_gpe_status_set() to take the number of a GPE to skip as an argument.
--- drivers/acpi/acpica/achware.h | 2 +- drivers/acpi/acpica/evxfgpe.c | 17 +++++++++++----- drivers/acpi/acpica/hwgpe.c | 47 ++++++++++++++++++++++++++++++++++--------- drivers/acpi/sleep.c | 2 +- include/acpi/acpixf.h | 2 +- 5 files changed, 53 insertions(+), 17 deletions(-)
drivers/acpi/acpica/achware.h +1 -1
@@ -101,7 +101,7 @@ acpi_status acpi_hw_enable_all_runtime_gpes(void);acpi_status acpi_hw_enable_all_wakeup_gpes (void ); -u8 acpi_hw_check_all_gpes (void ); +u8 acpi_hw_check_all_gpes (acpi_handle gpe_skip_device,u32 gpe_skip_number); acpi_status acpi_hw_enable_runtime_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
drivers/acpi/acpica/evxfgpe.c +12 -5
@@ -799,17 +799,19 @@ ACPI_EXPORT_SYMBOL(acpi_enable_all_wakeup_gpes)* * FUNCTION: acpi_any_gpe_status_set * -* PARAMETERS: None +* PARAMETERS: gpe_skip_number - Number of the GPE to skip * * RETURN: Whether or not the status bit is set for any GPE * -* DESCRIPTION: Check the status bits of all enabled GPEs and return TRUE if any -* of them is set or FALSE otherwise. +* DESCRIPTION: Check the status bits of all enabled GPEs, except for the one +* represented by the "skip" argument, and return TRUE if any of +* them is set or FALSE otherwise. * ******************************************************************************/ -u32 acpi_any_gpe_status_set (void ) +u32 acpi_any_gpe_status_set (u32 gpe_skip_number) {acpi_status status; +acpi_handle gpe_device;u8 ret;ACPI_FUNCTION_TRACE (acpi_any_gpe_status_set);
@@ -819,7 +821,12 @@ u32 acpi_any_gpe_status_set(void)return (FALSE); } - ret =acpi_hw_check_all_gpes (); + status =acpi_get_gpe_device (gpe_skip_number, &gpe_device); +if (ACPI_FAILURE (status)) { + gpe_device =NULL ; + } + + ret =acpi_hw_check_all_gpes (gpe_device, gpe_skip_number); (void )acpi_ut_release_mutex (ACPI_MTX_EVENTS );return (ret);
drivers/acpi/acpica/hwgpe.c +38 -9
93 lines not on this page · raw message
drivers/acpi/sleep.c +1 -1
@@ -1022,7 +1022,7 @@ static bool acpi_s2idle_wake(void)* status bit from unset to set between the checks with the * status bits of all the other GPEs unset. */ -if (acpi_any_gpe_status_set () && !acpi_ec_dispatch_gpe ()) +if (acpi_any_gpe_status_set (U32_MAX ) && !acpi_ec_dispatch_gpe ())return true;/*
include/acpi/acpixf.h +1 -1
@@ -752,7 +752,7 @@ ACPI_HW_DEPENDENT_RETURN_UINT32(u32 acpi_dispatch_gpe(acpi_handle gpe_device, u3 ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status acpi_disable_all_gpes(void)) ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status acpi_enable_all_runtime_gpes(void)) ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status acpi_enable_all_wakeup_gpes(void)) -ACPI_HW_DEPENDENT_RETURN_UINT32(u32 acpi_any_gpe_status_set(void)) +ACPI_HW_DEPENDENT_RETURN_UINT32(u32 acpi_any_gpe_status_set(u32 gpe_skip_number)) ACPI_HW_DEPENDENT_RETURN_UINT32(u32 acpi_any_fixed_event_status_set(void)) ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status
Signature · 1 line
2.16.4
PATCH 2/2 ACPI: PM: s2idle: Refine active GPEs check
In reply to Rafael J. WysockiFrom: "Rafael J. Wysocki" <[email protected]>
The check for any active GPEs added by commit fdde0ff8590b ("ACPI:
PM: s2idle: Prevent spurious SCIs from waking up the system") turns out to be insufficiently precise to prevent some systems from resuming prematurely due to a spurious EC wakeup, so refine it by first checking if any GPEs other than the EC GPE are active and skipping all of the SCIs coming from the EC that do not produce any genuine wakeup events after processing.
--- drivers/acpi/ec.c | 5 +++++ drivers/acpi/internal.h | 1 + drivers/acpi/sleep.c | 19 ++++++++++--------- 3 files changed, 16 insertions(+), 9 deletions(-)
drivers/acpi/ec.c +5 -0
@@ -2037,6 +2037,11 @@ void acpi_ec_set_gpe_wake_mask(u8 action)acpi_set_gpe_wake_mask (NULL , first_ec->gpe, action); } +bool acpi_ec_other_gpes_active (void ) +{ +return acpi_any_gpe_status_set (first_ec ? first_ec->gpe :U32_MAX ); +} +bool acpi_ec_dispatch_gpe (void ) {u32 ret;
drivers/acpi/internal.h +1 -0
@@ -202,6 +202,7 @@ void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit);#ifdef CONFIG_PM_SLEEP void acpi_ec_flush_work (void ); +bool acpi_ec_other_gpes_active (void );bool acpi_ec_dispatch_gpe (void );#endif
drivers/acpi/sleep.c +10 -9
@@ -1013,18 +1013,19 @@ static bool acpi_s2idle_wake(void)return true;/* -* If there are no EC events to process and at least one of the -* other enabled GPEs is active, the wakeup is regarded as a -* genuine one. -* -* Note that the checks below must be carried out in this order -* to avoid returning prematurely due to a change of the EC GPE -* status bit from unset to set between the checks with the -* status bits of all the other GPEs unset. +* If the status bit is set for any enabled GPE other than the +* EC one, the wakeup is regarded as a genuine one. */ -if (acpi_any_gpe_status_set (U32_MAX ) && !acpi_ec_dispatch_gpe ()) +if (acpi_ec_other_gpes_active ())return true; +/* +* If the EC GPE status bit has not been set, the wakeup is +* regarded as a spurious one. +*/ +if (!acpi_ec_dispatch_gpe ()) +return false; +/* * Cancel the wakeup and process all pending events in case * there are any wakeup ones in there.
Signature · 1 line
2.16.4