ACPI: EC: Fix flushing of pending work
diff mbox series

Message ID 2209952.LFAxc7Zn43@kreacher
State Superseded
Commit 4903c0540b0d0e094db3b32f5bcbc80f8c8a4ae1
Headers show
Series
  • ACPI: EC: Fix flushing of pending work
Related show

Commit Message

Rafael J. Wysocki Feb. 6, 2020, 10:32 a.m. UTC
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Commit 016b87ca5c8c ("ACPI: EC: Rework flushing of pending work")
introduced a subtle bug into the flushing of pending EC work while
suspended to idle, which may cause the EC driver to fail to
re-enable the EC GPE after handling a non-wakeup event (like a
battery status change event, for example).

The problem is that one of the work items flushed by the
flush_scheduled_work() in __acpi_ec_flush_work() may disable the EC
GPE and schedule another work item expected to re-enable it, but that
new work item is not flushed, so __acpi_ec_flush_work() returns with
the EC GPE disabled and the CPU running it goes into an idle state
subsequently.  If all of the other CPUs are in idle states at that
point, the EC GPE won't be re-enabled until at least one CPU is woken
up by another interrupt source, so system wakeup events that would
normally come from the EC then don't work.

This is reproducible on a Dell XPS13 9360 in my office which
sometimes stops reacting to power button and lid events (triggered
by the EC on that machine) after switching from AC power to battery
power or vice versa while suspended to idle (each of those switches
causes the EC GPE to trigger for several times in a row, but they
are not system wakeup events).

To avoid this problem, change __acpi_ec_flush_work() to call
drain_workqueue() on system_wq instead of flush_scheduled_work(),
which is sufficient to make it go away on the machine mentioned
above.

Fixes: 016b87ca5c8c ("ACPI: EC: Rework flushing of pending work")
Cc: 5.4+ <stable@vger.kernel.org> # 5.4+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/acpi/ec.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Patch
diff mbox series

Index: linux-pm/drivers/acpi/ec.c
===================================================================
--- linux-pm.orig/drivers/acpi/ec.c
+++ linux-pm/drivers/acpi/ec.c
@@ -535,7 +535,7 @@  static void acpi_ec_enable_event(struct
 #ifdef CONFIG_PM_SLEEP
 static void __acpi_ec_flush_work(void)
 {
-	flush_scheduled_work(); /* flush ec->work */
+	drain_workqueue(system_wq); /* flush ec->work */
 	flush_workqueue(ec_query_wq); /* flush queries */
 }