lkml.org 
[lkml]   [2021]   [Jan]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 2/5] rcu/nocb: Perform deferred wake up before last idle's need_resched() check
    Date
    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.

    Reported-by: Paul E. McKenney <paulmck@kernel.org>
    Fixes: 96d3fd0d315a (rcu: Break call_rcu() deadlock involving scheduler and perf)
    Cc: stable@vger.kernel.org
    Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: Ingo Molnar <mingo@kernel.org>
    Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
    ---
    include/linux/rcupdate.h | 2 ++
    kernel/rcu/tree.c | 3 ---
    kernel/rcu/tree_plugin.h | 5 +++++
    kernel/sched/idle.c | 3 +++
    4 files changed, 10 insertions(+), 3 deletions(-)

    diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
    index fd02c5fa60cb..36c2119de702 100644
    --- a/include/linux/rcupdate.h
    +++ b/include/linux/rcupdate.h
    @@ -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 */

    /**
    diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
    index 63032e5620b9..82838e93b498 100644
    --- a/kernel/rcu/tree.c
    +++ b/kernel/rcu/tree.c
    @@ -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);
    diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
    index 7e291ce0a1d6..d5b38c28abd1 100644
    --- a/kernel/rcu/tree_plugin.h
    +++ b/kernel/rcu/tree_plugin.h
    @@ -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;
    diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c
    index 305727ea0677..b601a3aa2152 100644
    --- a/kernel/sched/idle.c
    +++ b/kernel/sched/idle.c
    @@ -55,6 +55,7 @@ __setup("hlt", cpu_idle_nopoll_setup);
    static noinline int __cpuidle cpu_idle_poll(void)
    {
    trace_cpu_idle(0, smp_processor_id());
    + rcu_nocb_flush_deferred_wakeup();
    stop_critical_timings();
    rcu_idle_enter();
    local_irq_enable();
    @@ -173,6 +174,8 @@ static void cpuidle_idle_call(void)
    struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
    int next_state, entered_state;

    + rcu_nocb_flush_deferred_wakeup();
    +
    /*
    * Check if the idle task must be rescheduled. If it is the
    * case, exit the function after re-enabling the local irq.
    --
    2.25.1
    \
     
     \ /
      Last update: 2021-02-01 00:07    [W:3.691 / U:0.020 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site