Commit 43789ef3 authored by Frederic Weisbecker's avatar Frederic Weisbecker Committed by Ingo Molnar
Browse files

rcu/nocb: Perform deferred wake up before last idle's need_resched() check



Entering RCU idle mode may cause a deferred wake up of an RCU NOCB_GP
kthread (rcuog) to be serviced.

Usually a local wake up happening while running the idle task is handled
in one of the need_resched() checks carefully placed within the idle
loop that can break to the scheduler.

Unfortunately the call to rcu_idle_enter() is already beyond the last
generic need_resched() check and we may halt the CPU with a resched
request unhandled, leaving the task hanging.

Fix this with splitting the rcuog wakeup handling from rcu_idle_enter()
and place it before the last generic need_resched() check in the idle
loop. It is then assumed that no call to call_rcu() will be performed
after that in the idle loop until the CPU is put in low power mode.

Fixes: 96d3fd0d (rcu: Break call_rcu() deadlock involving scheduler and perf)
Reported-by: default avatarPaul E. McKenney <paulmck@kernel.org>
Signed-off-by: default avatarFrederic Weisbecker <frederic@kernel.org>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/20210131230548.32970-3-frederic@kernel.org
parent 54b7429e
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -110,8 +110,10 @@ static inline void rcu_user_exit(void) { }

#ifdef CONFIG_RCU_NOCB_CPU
void rcu_init_nohz(void);
void rcu_nocb_flush_deferred_wakeup(void);
#else /* #ifdef CONFIG_RCU_NOCB_CPU */
static inline void rcu_init_nohz(void) { }
static inline void rcu_nocb_flush_deferred_wakeup(void) { }
#endif /* #else #ifdef CONFIG_RCU_NOCB_CPU */

/**
+0 −3
Original line number Diff line number Diff line
@@ -671,10 +671,7 @@ static noinstr void rcu_eqs_enter(bool user)
 */
void rcu_idle_enter(void)
{
	struct rcu_data *rdp = this_cpu_ptr(&rcu_data);

	lockdep_assert_irqs_disabled();
	do_nocb_deferred_wakeup(rdp);
	rcu_eqs_enter(false);
}
EXPORT_SYMBOL_GPL(rcu_idle_enter);
+5 −0
Original line number Diff line number Diff line
@@ -2187,6 +2187,11 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
		do_nocb_deferred_wakeup_common(rdp);
}

void rcu_nocb_flush_deferred_wakeup(void)
{
	do_nocb_deferred_wakeup(this_cpu_ptr(&rcu_data));
}

void __init rcu_init_nohz(void)
{
	int cpu;
+1 −0
Original line number Diff line number Diff line
@@ -285,6 +285,7 @@ static void do_idle(void)
		}

		arch_cpu_idle_enter();
		rcu_nocb_flush_deferred_wakeup();

		/*
		 * In poll mode we reenable interrupts and spin. Also if we