[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20201222042047.GZ2657@paulmck-ThinkPad-P72>
Date: Mon, 21 Dec 2020 20:20:47 -0800
From: "Paul E. McKenney" <paulmck@...nel.org>
To: Frederic Weisbecker <frederic@...nel.org>
Cc: LKML <linux-kernel@...r.kernel.org>,
"Rafael J . Wysocki" <rafael.j.wysocki@...el.com>,
Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...nel.org>,
Fabio Estevam <festevam@...il.com>, stable@...r.kernel.org,
Thomas Gleixner <tglx@...utronix.de>,
Len Brown <lenb@...nel.org>,
Pengutronix Kernel Team <kernel@...gutronix.de>,
NXP Linux Team <linux-imx@....com>,
Daniel Lezcano <daniel.lezcano@...aro.org>,
Shawn Guo <shawnguo@...nel.org>,
Sascha Hauer <s.hauer@...gutronix.de>
Subject: Re: [PATCH 1/4] sched/idle: Fix missing need_resched() check after
rcu_idle_enter()
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 <paulmck@...nel.org>
> Fixes: 96d3fd0d315a (rcu: Break call_rcu() deadlock involving scheduler and perf)
> Cc: stable@...r.kernel.org
> Cc: Peter Zijlstra <peterz@...radead.org>
> Cc: Rafael J. Wysocki <rafael.j.wysocki@...el.com>
> Cc: Thomas Gleixner <tglx@...utronix.de>
> Cc: Ingo Molnar<mingo@...nel.org>
> Signed-off-by: Frederic Weisbecker <frederic@...nel.org>
Tested-by: Paul E. McKenney <paulmck@...nel.org>
> ---
> 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
>
Powered by blists - more mailing lists