[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210104152058.36642-2-frederic@kernel.org>
Date: Mon, 4 Jan 2021 16:20:55 +0100
From: Frederic Weisbecker <frederic@...nel.org>
To: Peter Zijlstra <peterz@...radead.org>
Cc: LKML <linux-kernel@...r.kernel.org>,
Frederic Weisbecker <frederic@...nel.org>,
"Rafael J . Wysocki" <rafael.j.wysocki@...el.com>,
Ingo Molnar <mingo@...nel.org>,
Fabio Estevam <festevam@...il.com>, stable@...r.kernel.org,
Thomas Gleixner <tglx@...utronix.de>,
"Paul E . McKenney" <paulmck@...nel.org>,
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: [PATCH 1/4] sched/idle: Fix missing need_resched() check after rcu_idle_enter()
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 <paulmck@...nel.org>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@...el.com>
Fixes: 96d3fd0d315a (rcu: Break call_rcu() deadlock involving scheduler and perf)
Cc: stable@...r.kernel.org
Cc: Peter Zijlstra <peterz@...radead.org>
Cc: Thomas Gleixner <tglx@...utronix.de>
Cc: Ingo Molnar<mingo@...nel.org>
Signed-off-by: Frederic Weisbecker <frederic@...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