Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp13897048pxu; Mon, 4 Jan 2021 07:24:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJxtVbOoDBX+BYmF8NkhjsZFqejAnAH9zxgpXhc1D+AYHv5IVcUAN/AxhIwo3Pt95nZJt+Ev X-Received: by 2002:a17:906:1f07:: with SMTP id w7mr44646700ejj.519.1609773871809; Mon, 04 Jan 2021 07:24:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609773871; cv=none; d=google.com; s=arc-20160816; b=Jq2F7asvAXOytbK07vdXsvBXUqeOj0YV6zNCQnJ8qyRrue0UzRNl+DyumSgVOMQ7M+ UBcrvavK/mgQChuV73Kd2gmOYCPKZYgcJGFx4jcwU7kOQaeISX51tpyxHSdFTHuVpzso uPqcbDoPYYZ5w8QHLqomhtRzJ+NSzeXO4rx4RIchjEdfSb765uu4WQe8OVMotFIrFkhV x953ZplYK3bLd0bkPU43mq6GLJMoEDnl69Y8ZGGj+IqhxGThoquaiEGfXLvynaF3+UWG i/2o9Z0fz7Tjh5e3dCU8Ry7AZjLd6R4QL4P9wvgKt2ItuAFQJJFryR7KRV59Ms9hXjTO YDJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0qD3M8JQQWD6LwKD5JnJeGy6MkALfFHzxBHthAJfecg=; b=0hQpAEeWdPIFeXXBXQkJfBUMf8MGUoT0b91UenCp4+pCd4ccM5LfICcxzHBUJJrG/S shO9B7/38UoOENm3kVBVrx5qu7to7+6ZVKPy9JCWaGKxkqJd6RPLjlPuVKa1jPSzpf0P +DPfmClAwvQoCqLfHWqZ0WRoCn3hZ536P5i6I3RWNiNUdCsqf2vnHU7pVBn5g002gGDE /RVrINPE1TgydQILk3MxRiIX00Wdlg+7ZUpvmuCdPzvrjl/vKSlHoAuKMUVUFLq7JcDd 3vNKF2zm1mNDply9pEPtkz6FKFzMDXh1NOHV6g/kOTFEvotofmPosdnGUuEdlP1KtcSA nBcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Y1DBGqdJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m8si32550459edp.82.2021.01.04.07.24.08; Mon, 04 Jan 2021 07:24:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Y1DBGqdJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727441AbhADPV5 (ORCPT + 99 others); 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