]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
rcu/nocb: Perform deferred wake up before last idle's need_resched() check
authorFrederic Weisbecker <frederic@kernel.org>
Sun, 31 Jan 2021 23:05:45 +0000 (00:05 +0100)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Wed, 14 Apr 2021 16:31:39 +0000 (18:31 +0200)
BugLink: https://bugs.launchpad.net/bugs/1918974
commit 43789ef3f7d61aa7bed0cb2764e588fc990c30ef upstream.

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: 96d3fd0d315a (rcu: Break call_rcu() deadlock involving scheduler and perf)
Reported-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/20210131230548.32970-3-frederic@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kelsey Skunberg <kelsey.skunberg@canonical.com>
include/linux/rcupdate.h
kernel/rcu/tree.c
kernel/rcu/tree_plugin.h
kernel/sched/idle.c

index 75a2eded7aa2ce6973622ecfd5a2a00772f07270..09e6ac4b669b2b2ce67823229a90e0bafa0c3b47 100644 (file)
@@ -96,8 +96,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 */
 
 /**
index 3dc02ee17957eff6f7473e43ce5d5e90a243099f..4dfa9dd47223ab5f559495c61bd40d3338cd219a 100644 (file)
@@ -599,10 +599,7 @@ static 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);
 }
 
index f7118842a2b883245d567057c08f05ac950bcec0..a71a4a272515de2aad0fb297bef81b16a7b34ea8 100644 (file)
@@ -2190,6 +2190,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;
index 131e7c86cf06e37ea4a272b76943f19499cd0672..3f8c7867c14c15ee863f466bcf2b09cb3c587d71 100644 (file)
@@ -249,6 +249,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