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=-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 9DB3DC43381 for ; Mon, 4 Jan 2021 15:22:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6CE0F22286 for ; Mon, 4 Jan 2021 15:22:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727457AbhADPV5 (ORCPT ); Mon, 4 Jan 2021 10:21:57 -0500 Received: from mail.kernel.org ([198.145.29.99]:54950 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727403AbhADPV4 (ORCPT ); Mon, 4 Jan 2021 10:21:56 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id AC8AB221F9; Mon, 4 Jan 2021 15:21:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1609773675; bh=VCMU4IFAUFEcsXLNAK+wusaU1FE1pK3Cow2d/CCs2Pc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y1DBGqdJPwEMESop9TyoVJi4sZI1w7iQ95zH1XsAmcPCO2n961j7nWMLoD7Km7WkZ eOxhHnQJMB+sPFvrRGRE9BXFp3X8Dl7460avbTeia4suLLziBdRyxkSIGUorgmH8iH xXEA3hYTicz43uGap+Wj1ivpONeQ2YXkfL4yVhwFCIVwxoWEANeWyI4GRpnHHug8pM p7K1KM2PyBuY4Dwqef7pVZ0w/GQu4rBpPtbGG4EG8sg05GlQWFoJEQrg/SGTh9Ql/p pOcXbuGXsuKX2v01CfYtgExVgwS8RDJIvIvi94GAxQqbKJ6WcTM9aqSuzKj3CqG24h v3Ys9tJDRExfQ== 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 3/4] ARM: imx6q: Fix missing need_resched() check after rcu_idle_enter() Date: Mon, 4 Jan 2021 16:20:57 +0100 Message-Id: <20210104152058.36642-4-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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 imx6q_enter_wait() is beyond the last generic need_resched() check and it performs a wfi right away after the call to rcu_idle_enter(). 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 Reviewed-by: Rafael J. Wysocki Fixes: 1a67b9263e06 (ARM: imx6q: Fixup RCU usage for cpuidle) Cc: stable@vger.kernel.org Cc: Shawn Guo Cc: Sascha Hauer Cc: Pengutronix Kernel Team Cc: Fabio Estevam Cc: NXP Linux Team Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Ingo Molnar Signed-off-by: Frederic Weisbecker --- arch/arm/mach-imx/cpuidle-imx6q.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/arm/mach-imx/cpuidle-imx6q.c b/arch/arm/mach-imx/cpuidle-imx6q.c index 094337dc1bc7..1115f4dc6d1d 100644 --- a/arch/arm/mach-imx/cpuidle-imx6q.c +++ b/arch/arm/mach-imx/cpuidle-imx6q.c @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -25,7 +26,12 @@ static int imx6q_enter_wait(struct cpuidle_device *dev, raw_spin_unlock(&cpuidle_lock); rcu_idle_enter(); - cpu_do_idle(); + /* + * Last need_resched() check must come after rcu_idle_enter() + * which may wake up RCU internal tasks. + */ + if (!tif_need_resched()) + cpu_do_idle(); rcu_idle_exit(); raw_spin_lock(&cpuidle_lock); -- 2.25.1