From patchwork Mon Jan 4 15:20:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 356783 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87850C433E0 for ; Mon, 4 Jan 2021 15:22:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5B5AA207BC for ; Mon, 4 Jan 2021 15:22:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727192AbhADPVt (ORCPT ); Mon, 4 Jan 2021 10:21:49 -0500 Received: from mail.kernel.org ([198.145.29.99]:54894 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726579AbhADPVt (ORCPT ); Mon, 4 Jan 2021 10:21:49 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id E366A221E5; Mon, 4 Jan 2021 15:21:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1609773668; bh=HFmeWgP/ZwiP+hsm1k1sd6flGOowieQ4iCyWAlhoJv8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g+k9HGCekSuBIIVVZ/ISjvZonqSkNugJc5J5p4J/mSDFKTkdxuIdUMGN1QalOHEdk f7aRNnS1mdr8BczwxjxfrDMXpcUc8fYcPcQ9mj6jEcsdokhd8vOuR2qRHeI8vgS+YE DBDubISmg6gxHR6JrKrwimOmjBkWpGF5/KbhrVMlutD0AU0vW6wmBmZB1feFH/zvr7 j81hw8oarxzf6ewpFfIXn/ncGwaaUFtaQQmcqJNuR2+OGvyvoTkjRuOOxYAHnor5Tw iLQZS4ZULUhxhgUXgA8F4X2S3mSlUuMAmlVyPdvrRLow64PpXZ9/0n23trV8z4xeGj bB+6i6q/TFWew== From: Frederic Weisbecker To: Peter Zijlstra Cc: LKML , Frederic Weisbecker , "Rafael J . Wysocki" , Ingo Molnar , Fabio Estevam , stable@vger.kernel.org, Thomas Gleixner , "Paul E . McKenney" , Len Brown , Pengutronix Kernel Team , NXP Linux Team , Daniel Lezcano , Shawn Guo , Sascha Hauer Subject: [PATCH 1/4] sched/idle: Fix missing need_resched() check after rcu_idle_enter() Date: Mon, 4 Jan 2021 16:20:55 +0100 Message-Id: <20210104152058.36642-2-frederic@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210104152058.36642-1-frederic@kernel.org> References: <20210104152058.36642-1-frederic@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org Entering RCU idle mode may cause a deferred wake up of an RCU NOCB_GP kthread (rcuog) to be serviced. Usually a wake up happening while running the idle task is spotted in one of the need_resched() checks carefully placed within the idle loop that can break to the scheduler. Unfortunately in default_idle_call(), the call to rcu_idle_enter() is already beyond the last need_resched() check and we may halt the CPU with a resched request unhandled, leaving the task hanging. Fix this with performing a last minute need_resched() check after calling rcu_idle_enter(). Reported-and-tested-by: Paul E. McKenney Reviewed-by: Rafael J. Wysocki Fixes: 96d3fd0d315a (rcu: Break call_rcu() deadlock involving scheduler and perf) Cc: stable@vger.kernel.org Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Ingo Molnar Signed-off-by: Frederic Weisbecker --- kernel/sched/idle.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c index 305727ea0677..1af60dc50beb 100644 --- a/kernel/sched/idle.c +++ b/kernel/sched/idle.c @@ -109,15 +109,21 @@ void __cpuidle default_idle_call(void) rcu_idle_enter(); lockdep_hardirqs_on(_THIS_IP_); - arch_cpu_idle(); + /* + * Last need_resched() check must come after rcu_idle_enter() + * which may wake up RCU internal tasks. + */ + if (!need_resched()) { + arch_cpu_idle(); + raw_local_irq_disable(); + } /* - * OK, so IRQs are enabled here, but RCU needs them disabled to - * turn itself back on.. funny thing is that disabling IRQs - * will cause tracing, which needs RCU. Jump through hoops to - * make it 'work'. + * OK, so IRQs are enabled after arch_cpu_idle(), but RCU needs + * them disabled to turn itself back on.. funny thing is that + * disabling IRQs will cause tracing, which needs RCU. Jump through + * hoops to make it 'work'. */ - raw_local_irq_disable(); lockdep_hardirqs_off(_THIS_IP_); rcu_idle_exit(); lockdep_hardirqs_on(_THIS_IP_); From patchwork Mon Jan 4 15:20:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 356782 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF892C433E9 for ; Mon, 4 Jan 2021 15:22:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B58102242A for ; Mon, 4 Jan 2021 15:22:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727458AbhADPWA (ORCPT ); Mon, 4 Jan 2021 10:22:00 -0500 Received: from mail.kernel.org ([198.145.29.99]:54976 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727403AbhADPV7 (ORCPT ); Mon, 4 Jan 2021 10:21:59 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 12A9722286; Mon, 4 Jan 2021 15:21:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1609773679; bh=KnCcCfl5Ujo0xeLkI0m9dHw2QY6hrFRxzWMXtqAvrxY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bls+adfd/7XPttxskOXdd0DZvtCeb+LUIOhIrUhnEaaQmJZthY+QbmtdxKkRyJb+I fyHgXJHGiLnaZUPKkncqdC+DMIKr/jmP8HGkD3HF2wIXB/mo5GODrv2rQYXNe5uV8U BWsoQIyWNpF+zAhdDTz/OGLrSTmEwEG0azq+cNxd8aR4nQ1bhnobwYe51Z+6dIe9bm CZsE1zUXnV7YNIq6PlYZuvRKJfHTUUtKACb8XzOh1bcOi8kIo+ldGmCAd42fEscmhq PPrlWy/RTstaGbPRHfRLI3oIp+JL2GvrEneCuzUsFGmnYzF+QpkU5KPoXydmXTHKdR KzBWkGcjahvsw== From: Frederic Weisbecker To: Peter Zijlstra Cc: LKML , Frederic Weisbecker , "Rafael J . Wysocki" , Ingo Molnar , Fabio Estevam , stable@vger.kernel.org, Thomas Gleixner , "Paul E . McKenney" , Len Brown , Pengutronix Kernel Team , NXP Linux Team , Daniel Lezcano , Shawn Guo , Sascha Hauer Subject: [PATCH 4/4] ACPI: processor: Fix missing need_resched() check after rcu_idle_enter() Date: Mon, 4 Jan 2021 16:20:58 +0100 Message-Id: <20210104152058.36642-5-frederic@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210104152058.36642-1-frederic@kernel.org> References: <20210104152058.36642-1-frederic@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org Entering RCU idle mode may cause a deferred wake up of an RCU NOCB_GP kthread (rcuog) to be serviced. Usually a wake up happening while running the idle task is spotted in one of the need_resched() checks carefully placed within the idle loop that can break to the scheduler. Unfortunately within acpi_idle_enter_bm() the call to rcu_idle_enter() is already beyond the last generic need_resched() check. The cpu idle implementation happens to be ok because it ends up calling mwait_idle_with_hints() or acpi_safe_halt() which both perform their own need_resched() checks. But the suspend to idle implementation doesn't so it may suspend the CPU with a resched request unhandled, leaving the task hanging. Fix this with performing a last minute need_resched() check after calling rcu_idle_enter(). Reported-by: Paul E. McKenney Reviewed-by: Rafael J. Wysocki Fixes: 1fecfdbb7acc (ACPI: processor: Take over RCU-idle for C3-BM idle) Cc: stable@vger.kernel.org Cc: Len Brown Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Ingo Molnar Signed-off-by: Frederic Weisbecker --- drivers/acpi/processor_idle.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index d93e400940a3..c4939c49d972 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c @@ -604,8 +604,14 @@ static int acpi_idle_enter_bm(struct cpuidle_driver *drv, } rcu_idle_enter(); - - acpi_idle_do_entry(cx); + /* + * Last need_resched() check must come after rcu_idle_enter() + * which may wake up RCU internal tasks. mwait_idle_with_hints() + * and acpi_safe_halt() have their own checks but s2idle + * implementation doesn't. + */ + if (!need_resched()) + acpi_idle_do_entry(cx); rcu_idle_exit();