Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1350627ybv; Thu, 6 Feb 2020 02:33:22 -0800 (PST) X-Google-Smtp-Source: APXvYqwFVc9wsHSYEmRSod36eMLz+nIuT4jrecmUDnd2I9nR88D7Q0GGiEmuXDtbnBLHaGsAzvzM X-Received: by 2002:a9d:730e:: with SMTP id e14mr28332652otk.62.1580985202768; Thu, 06 Feb 2020 02:33:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580985202; cv=none; d=google.com; s=arc-20160816; b=JWroz+XaO3dQX3qIzLjKTFmd+GmyHvqwSfcgojTZCR6DeRsqWzWWqOFOK2ngCV2OOI T9A77vmP2WxbWBV+JgZccUhSlejwgQRrnNWYAnjDp98sq1PTjRbsPYkVMYvjk8DY6P0k 2HiZNC/3bxutlqyx6o1pYjASH1rQ2bN97u0xsi4HGz8D2cT+nhUuF8IV6XF32GxbDVEs Y7dLJE94V7mZfFdfe4AnieN4fUbAJhv+axslICc3KAG0uVfz/UiSpHibGfFU4kfKgoTn qV0ksHDKLbKHROIly2+qtYzER1RHJbfbPVGh/KROjNjCsuD0FRG8bfPPjTQ2lDg+5ybn inGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=rlWW1kyYkp/9GBbWwdp4z0hJdqOgz1xTXn3rtcDAMg0=; b=a5K/okgP05sD1hfRa96FPYb6d5Fohk2niln2sCIuxq4Ek2KTrpvpckgT+25AH6x8J0 SK11CWtoN+zqg5ljfI6QBjtyPiueHKoIcsp9PT4ifAIkjdJDwRjLjSkM4RC89Ixfgkd5 W5+3LgHZE2Q9LxZ0d4YBwXywQpaB2ONPSBq4ES/xyYlTueXYXvZi9kGtjUeDGCpRQSn+ ned2mdNO1htex0Tuh68oeYFRy4aiFKvRmtHgKOiJvM+fY9qZtJaUpEFk/SvOocdSmgjI UH9KGYbf/Tfvuv92vaj38GiiGs6dUQrXkMZb5dqGvGcWmB20N84BhoflPJh3qBlxVR8Q X6dw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t3si1721908oth.247.2020.02.06.02.33.11; Thu, 06 Feb 2020 02:33:22 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728506AbgBFKcU (ORCPT + 99 others); Thu, 6 Feb 2020 05:32:20 -0500 Received: from cloudserver094114.home.pl ([79.96.170.134]:44890 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728304AbgBFKcT (ORCPT ); Thu, 6 Feb 2020 05:32:19 -0500 Received: from 79.184.253.222.ipv4.supernova.orange.pl (79.184.253.222) (HELO kreacher.localnet) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83.341) id 40d7a63af6c90ca3; Thu, 6 Feb 2020 11:32:17 +0100 From: "Rafael J. Wysocki" To: Linux ACPI Cc: Linux PM , LKML , Zhang Rui , Chen Yu , David Box Subject: [PATCH] ACPI: EC: Fix flushing of pending work Date: Thu, 06 Feb 2020 11:32:16 +0100 Message-ID: <2209952.LFAxc7Zn43@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rafael J. Wysocki 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+ # 5.4+ Signed-off-by: Rafael J. Wysocki --- drivers/acpi/ec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 */ }