From mboxrd@z Thu Jan 1 00:00:00 1970 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=-17.5 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,USER_AGENT_SANE_1 autolearn=ham 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 5E104C433DB for ; Tue, 22 Dec 2020 04:21:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 24C5122D02 for ; Tue, 22 Dec 2020 04:21:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725825AbgLVEV2 (ORCPT ); Mon, 21 Dec 2020 23:21:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:57446 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725820AbgLVEV2 (ORCPT ); Mon, 21 Dec 2020 23:21:28 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5363722ADC; Tue, 22 Dec 2020 04:20:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1608610847; bh=6WW6bchu/hFRXl913wHiGV8Ial4KKNDAr7VAEGblU1k=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=isn+vkb2O2t1irCOzkUOYOdSMqy+yOtuxF87CSzxlAvcWAcwNi54j0JcfGXKRt6zc a4SaC9U98fX9aQ+wLOtvw9DS2wD3Qi37ZWqvjHkGc5/fJ+bPGor6kU4LdyBv03Bdap 9cn21kZyAEAXB/F+fOhH2UJrIjp0Vaxs674CeiZLXVGFElT8naGhToaaOs0NOZMcmb NdilQ8w/aQD0WtDzuPG9qwTG6TMbT0Qm9Pjm1bu7QBgV/2suoW557rM8bR1vFFhnn+ G0JXefyQdtqGzduDWA0dHjQKhrXI6ISrXpLxqiEjb6cO8p3LGl48jcZ1mL/BfjYDYC oOcpiTzOZn/Wg== Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id 16D8C352275F; Mon, 21 Dec 2020 20:20:47 -0800 (PST) Date: Mon, 21 Dec 2020 20:20:47 -0800 From: "Paul E. McKenney" To: Frederic Weisbecker Cc: LKML , "Rafael J . Wysocki" , Peter Zijlstra , Ingo Molnar , Fabio Estevam , stable@vger.kernel.org, Thomas Gleixner , Len Brown , Pengutronix Kernel Team , NXP Linux Team , Daniel Lezcano , Shawn Guo , Sascha Hauer Subject: Re: [PATCH 1/4] sched/idle: Fix missing need_resched() check after rcu_idle_enter() Message-ID: <20201222042047.GZ2657@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org References: <20201222013712.15056-1-frederic@kernel.org> <20201222013712.15056-2-frederic@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201222013712.15056-2-frederic@kernel.org> User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org On Tue, Dec 22, 2020 at 02:37:09AM +0100, Frederic Weisbecker wrote: > 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-by: Paul E. McKenney > Fixes: 96d3fd0d315a (rcu: Break call_rcu() deadlock involving scheduler and perf) > Cc: stable@vger.kernel.org > Cc: Peter Zijlstra > Cc: Rafael J. Wysocki > Cc: Thomas Gleixner > Cc: Ingo Molnar > Signed-off-by: Frederic Weisbecker Tested-by: Paul E. McKenney > --- > 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_); > -- > 2.25.1 >