Merge tag 'sched-core-2022-05-23' of git://git.kernel.org/pub/scm/linux/kernel/git...
authorLinus Torvalds <torvalds@linux-foundation.org>
Tue, 24 May 2022 18:11:13 +0000 (11:11 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 24 May 2022 18:11:13 +0000 (11:11 -0700)
Pull scheduler updates from Ingo Molnar:

 - Updates to scheduler metrics:
     - PELT fixes & enhancements
     - PSI fixes & enhancements
     - Refactor cpu_util_without()

 - Updates to instrumentation/debugging:
     - Remove sched_trace_*() helper functions - can be done via debug
       info
     - Fix double update_rq_clock() warnings

 - Introduce & use "preemption model accessors" to simplify some of the
   Kconfig complexity.

 - Make softirq handling RT-safe.

 - Misc smaller fixes & cleanups.

* tag 'sched-core-2022-05-23' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  topology: Remove unused cpu_cluster_mask()
  sched: Reverse sched_class layout
  sched/deadline: Remove superfluous rq clock update in push_dl_task()
  sched/core: Avoid obvious double update_rq_clock warning
  smp: Make softirq handling RT safe in flush_smp_call_function_queue()
  smp: Rename flush_smp_call_function_from_idle()
  sched: Fix missing prototype warnings
  sched/fair: Remove cfs_rq_tg_path()
  sched/fair: Remove sched_trace_*() helper functions
  sched/fair: Refactor cpu_util_without()
  sched/fair: Revise comment about lb decision matrix
  sched/psi: report zeroes for CPU full at the system level
  sched/fair: Delete useless condition in tg_unthrottle_up()
  sched/fair: Fix cfs_rq_clock_pelt() for throttled cfs_rq
  sched/fair: Move calculate of avg_load to a better location
  mailmap: Update my email address to @redhat.com
  MAINTAINERS: Add myself as scheduler topology reviewer
  psi: Fix trigger being fired unexpectedly at initial
  ftrace: Use preemption model accessors for trace header printout
  kcsan: Use preemption model accessors

1  2 
.mailmap
MAINTAINERS
include/linux/interrupt.h
include/linux/sched.h
kernel/sched/core.c
kernel/sched/idle.c
kernel/smp.c
kernel/stop_machine.c

diff --combined .mailmap
+++ b/.mailmap
@@@ -45,7 -45,6 +45,7 @@@ Andrey Konovalov <andreyknvl@gmail.com
  Andrey Ryabinin <ryabinin.a.a@gmail.com> <a.ryabinin@samsung.com>
  Andrey Ryabinin <ryabinin.a.a@gmail.com> <aryabinin@virtuozzo.com>
  Andrzej Hajda <andrzej.hajda@intel.com> <a.hajda@samsung.com>
 +André Almeida <andrealmeid@igalia.com> <andrealmeid@collabora.com>
  Andy Adamson <andros@citi.umich.edu>
  Antoine Tenart <atenart@kernel.org> <antoine.tenart@bootlin.com>
  Antoine Tenart <atenart@kernel.org> <antoine.tenart@free-electrons.com>
@@@ -205,7 -204,6 +205,7 @@@ Juha Yrjola <at solidboot.com
  Juha Yrjola <juha.yrjola@nokia.com>
  Juha Yrjola <juha.yrjola@solidboot.com>
  Julien Thierry <julien.thierry.kdev@gmail.com> <julien.thierry@arm.com>
 +Kalle Valo <kvalo@kernel.org> <kvalo@codeaurora.org>
  Kalyan Thota <quic_kalyant@quicinc.com> <kalyan_t@codeaurora.org>
  Kay Sievers <kay.sievers@vrfy.org>
  Kees Cook <keescook@chromium.org> <kees.cook@canonical.com>
@@@ -251,7 -249,6 +251,7 @@@ Mark Yao <markyao0591@gmail.com> <mark.
  Martin Kepplinger <martink@posteo.de> <martin.kepplinger@ginzinger.com>
  Martin Kepplinger <martink@posteo.de> <martin.kepplinger@puri.sm>
  Martin Kepplinger <martink@posteo.de> <martin.kepplinger@theobroma-systems.com>
 +Martyna Szapar-Mudlaw <martyna.szapar-mudlaw@linux.intel.com> <martyna.szapar-mudlaw@intel.com>
  Mathieu Othacehe <m.othacehe@gmail.com>
  Matthew Wilcox <willy@infradead.org> <matthew.r.wilcox@intel.com>
  Matthew Wilcox <willy@infradead.org> <matthew@wil.cx>
@@@ -398,6 -395,7 +398,7 @@@ Vasily Averin <vasily.averin@linux.dev
  Vasily Averin <vasily.averin@linux.dev> <vvs@openvz.org>
  Vasily Averin <vasily.averin@linux.dev> <vvs@parallels.com>
  Vasily Averin <vasily.averin@linux.dev> <vvs@sw.ru>
+ Valentin Schneider <vschneid@redhat.com> <valentin.schneider@arm.com>
  Vinod Koul <vkoul@kernel.org> <vinod.koul@intel.com>
  Vinod Koul <vkoul@kernel.org> <vinod.koul@linux.intel.com>
  Vinod Koul <vkoul@kernel.org> <vkoul@infradead.org>
diff --combined MAINTAINERS
@@@ -3571,9 -3571,8 +3571,9 @@@ M:      Andy Gospodarek <andy@greyhouse.net
  L:    netdev@vger.kernel.org
  S:    Supported
  W:    http://sourceforge.net/projects/bonding/
 +F:    Documentation/networking/bonding.rst
  F:    drivers/net/bonding/
 -F:    include/net/bonding.h
 +F:    include/net/bond*
  F:    include/uapi/linux/if_bonding.h
  
  BOSCH SENSORTEC BMA400 ACCELEROMETER IIO DRIVER
@@@ -5440,7 -5439,6 +5440,7 @@@ F:      net/ax25/sysctl_net_ax25.
  
  DATA ACCESS MONITOR
  M:    SeongJae Park <sj@kernel.org>
 +L:    damon@lists.linux.dev
  L:    linux-mm@kvack.org
  S:    Maintained
  F:    Documentation/ABI/testing/sysfs-kernel-mm-damon
@@@ -5919,7 -5917,7 +5919,7 @@@ R:      Benjamin Gaignard <benjamin.gaignard
  R:    Liam Mark <lmark@codeaurora.org>
  R:    Laura Abbott <labbott@redhat.com>
  R:    Brian Starkey <Brian.Starkey@arm.com>
 -R:    John Stultz <john.stultz@linaro.org>
 +R:    John Stultz <jstultz@google.com>
  L:    linux-media@vger.kernel.org
  L:    dri-devel@lists.freedesktop.org
  L:    linaro-mm-sig@lists.linaro.org (moderated for non-subscribers)
@@@ -6589,7 -6587,7 +6589,7 @@@ F:      drivers/gpu/drm/gma500
  DRM DRIVERS FOR HISILICON
  M:    Xinliang Liu <xinliang.liu@linaro.org>
  M:    Tian Tao  <tiantao6@hisilicon.com>
 -R:    John Stultz <john.stultz@linaro.org>
 +R:    John Stultz <jstultz@google.com>
  R:    Xinwei Kong <kong.kongxinwei@hisilicon.com>
  R:    Chen Feng <puck.chen@hisilicon.com>
  L:    dri-devel@lists.freedesktop.org
@@@ -7385,6 -7383,7 +7385,6 @@@ L:      linux-mm@kvack.or
  S:    Supported
  T:    git git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/execve
  F:    arch/alpha/kernel/binfmt_loader.c
 -F:    arch/x86/ia32/ia32_aout.c
  F:    fs/*binfmt_*.c
  F:    fs/exec.c
  F:    include/linux/binfmts.h
@@@ -7500,7 -7499,7 +7500,7 @@@ F:      Documentation/hwmon/f71805f.rs
  F:    drivers/hwmon/f71805f.c
  
  FADDR2LINE
 -M:    Josh Poimboeuf <jpoimboe@redhat.com>
 +M:    Josh Poimboeuf <jpoimboe@kernel.org>
  S:    Maintained
  F:    scripts/faddr2line
  
@@@ -8113,7 -8112,7 +8113,7 @@@ M:      Ingo Molnar <mingo@redhat.com
  R:    Peter Zijlstra <peterz@infradead.org>
  R:    Darren Hart <dvhart@infradead.org>
  R:    Davidlohr Bueso <dave@stgolabs.net>
 -R:    André Almeida <andrealmeid@collabora.com>
 +R:    André Almeida <andrealmeid@igalia.com>
  L:    linux-kernel@vger.kernel.org
  S:    Maintained
  T:    git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git locking/core
@@@ -8386,7 -8385,7 +8386,7 @@@ M:      Linus Walleij <linus.walleij@linaro.
  M:    Bartosz Golaszewski <brgl@bgdev.pl>
  L:    linux-gpio@vger.kernel.org
  S:    Maintained
 -T:    git git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio.git
 +T:    git git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux.git
  F:    Documentation/ABI/obsolete/sysfs-gpio
  F:    Documentation/ABI/testing/gpio-cdev
  F:    Documentation/admin-guide/gpio/
@@@ -8849,7 -8848,7 +8849,7 @@@ F:      Documentation/devicetree/bindings/ne
  F:    drivers/net/ethernet/hisilicon/
  
  HIKEY960 ONBOARD USB GPIO HUB DRIVER
 -M:    John Stultz <john.stultz@linaro.org>
 +M:    John Stultz <jstultz@google.com>
  L:    linux-kernel@vger.kernel.org
  S:    Maintained
  F:    drivers/misc/hisi_hikey_usb.c
@@@ -9863,14 -9862,6 +9863,14 @@@ B:    https://bugzilla.kernel.or
  T:    git git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux.git
  F:    drivers/idle/intel_idle.c
  
 +INTEL IN FIELD SCAN (IFS) DEVICE
 +M:    Jithu Joseph <jithu.joseph@intel.com>
 +R:    Ashok Raj <ashok.raj@intel.com>
 +R:    Tony Luck <tony.luck@intel.com>
 +S:    Maintained
 +F:    drivers/platform/x86/intel/ifs
 +F:    include/trace/events/intel_ifs.h
 +
  INTEL INTEGRATED SENSOR HUB DRIVER
  M:    Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
  M:    Jiri Kosina <jikos@kernel.org>
@@@ -10140,7 -10131,7 +10140,7 @@@ S:   Supporte
  F:    drivers/net/wireless/intel/iwlegacy/
  
  INTEL WIRELESS WIFI LINK (iwlwifi)
 -M:    Luca Coelho <luciano.coelho@intel.com>
 +M:    Gregory Greenman <gregory.greenman@intel.com>
  L:    linux-wireless@vger.kernel.org
  S:    Supported
  W:    https://wireless.wiki.kernel.org/en/users/drivers/iwlwifi
@@@ -11357,7 -11348,7 +11357,7 @@@ F:   drivers/mmc/host/litex_mmc.
  N:    litex
  
  LIVE PATCHING
 -M:    Josh Poimboeuf <jpoimboe@redhat.com>
 +M:    Josh Poimboeuf <jpoimboe@kernel.org>
  M:    Jiri Kosina <jikos@kernel.org>
  M:    Miroslav Benes <mbenes@suse.cz>
  M:    Petr Mladek <pmladek@suse.com>
@@@ -14233,7 -14224,7 +14233,7 @@@ F:   lib/objagg.
  F:    lib/test_objagg.c
  
  OBJTOOL
 -M:    Josh Poimboeuf <jpoimboe@redhat.com>
 +M:    Josh Poimboeuf <jpoimboe@kernel.org>
  M:    Peter Zijlstra <peterz@infradead.org>
  S:    Supported
  F:    tools/objtool/
@@@ -14381,6 -14372,7 +14381,6 @@@ F:   arch/arm/*omap*/*pm
  F:    drivers/cpufreq/omap-cpufreq.c
  
  OMAP POWERDOMAIN SOC ADAPTATION LAYER SUPPORT
 -M:    Rajendra Nayak <rnayak@codeaurora.org>
  M:    Paul Walmsley <paul@pwsan.com>
  L:    linux-omap@vger.kernel.org
  S:    Maintained
@@@ -15483,8 -15475,7 +15483,8 @@@ F:   tools/perf
  PERFORMANCE EVENTS TOOLING ARM64
  R:    John Garry <john.garry@huawei.com>
  R:    Will Deacon <will@kernel.org>
 -R:    Mathieu Poirier <mathieu.poirier@linaro.org>
 +R:    James Clark <james.clark@arm.com>
 +R:    Mike Leach <mike.leach@linaro.org>
  R:    Leo Yan <leo.yan@linaro.org>
  L:    linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
  S:    Supported
@@@ -17524,6 -17515,7 +17524,7 @@@ R:   Steven Rostedt <rostedt@goodmis.org
  R:    Ben Segall <bsegall@google.com> (CONFIG_CFS_BANDWIDTH)
  R:    Mel Gorman <mgorman@suse.de> (CONFIG_NUMA_BALANCING)
  R:    Daniel Bristot de Oliveira <bristot@redhat.com> (SCHED_DEADLINE)
+ R:    Valentin Schneider <vschneid@redhat.com> (TOPOLOGY)
  L:    linux-kernel@vger.kernel.org
  S:    Maintained
  T:    git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git sched/core
@@@ -18801,7 -18793,7 +18802,7 @@@ F:   include/dt-bindings/reset/starfive-j
  
  STATIC BRANCH/CALL
  M:    Peter Zijlstra <peterz@infradead.org>
 -M:    Josh Poimboeuf <jpoimboe@redhat.com>
 +M:    Josh Poimboeuf <jpoimboe@kernel.org>
  M:    Jason Baron <jbaron@akamai.com>
  R:    Steven Rostedt <rostedt@goodmis.org>
  R:    Ard Biesheuvel <ardb@kernel.org>
@@@ -19802,7 -19794,7 +19803,7 @@@ F:   drivers/net/wireless/ti
  F:    include/linux/wl12xx.h
  
  TIMEKEEPING, CLOCKSOURCE CORE, NTP, ALARMTIMER
 -M:    John Stultz <john.stultz@linaro.org>
 +M:    John Stultz <jstultz@google.com>
  M:    Thomas Gleixner <tglx@linutronix.de>
  R:    Stephen Boyd <sboyd@kernel.org>
  L:    linux-kernel@vger.kernel.org
@@@ -21453,7 -21445,7 +21454,7 @@@ F:   arch/x86/kernel/apic/x2apic_uv_x.
  F:    arch/x86/platform/uv/
  
  X86 STACK UNWINDING
 -M:    Josh Poimboeuf <jpoimboe@redhat.com>
 +M:    Josh Poimboeuf <jpoimboe@kernel.org>
  M:    Peter Zijlstra <peterz@infradead.org>
  S:    Supported
  F:    arch/x86/include/asm/unwind*.h
@@@ -222,6 -222,24 +222,6 @@@ devm_request_any_context_irq(struct dev
  
  extern void devm_free_irq(struct device *dev, unsigned int irq, void *dev_id);
  
 -/*
 - * On lockdep we dont want to enable hardirqs in hardirq
 - * context. Use local_irq_enable_in_hardirq() to annotate
 - * kernel code that has to do this nevertheless (pretty much
 - * the only valid case is for old/broken hardware that is
 - * insanely slow).
 - *
 - * NOTE: in theory this might break fragile code that relies
 - * on hardirq delivery - in practice we dont seem to have such
 - * places left. So the only effect should be slightly increased
 - * irqs-off latencies.
 - */
 -#ifdef CONFIG_LOCKDEP
 -# define local_irq_enable_in_hardirq()        do { } while (0)
 -#else
 -# define local_irq_enable_in_hardirq()        local_irq_enable()
 -#endif
 -
  bool irq_has_action(unsigned int irq);
  extern void disable_irq_nosync(unsigned int irq);
  extern bool disable_hardirq(unsigned int irq);
@@@ -589,6 -607,15 +589,15 @@@ struct softirq_actio
  asmlinkage void do_softirq(void);
  asmlinkage void __do_softirq(void);
  
+ #ifdef CONFIG_PREEMPT_RT
+ extern void do_softirq_post_smp_call_flush(unsigned int was_pending);
+ #else
+ static inline void do_softirq_post_smp_call_flush(unsigned int unused)
+ {
+       do_softirq();
+ }
+ #endif
  extern void open_softirq(int nr, void (*action)(struct softirq_action *));
  extern void softirq_init(void);
  extern void __raise_softirq_irqoff(unsigned int nr);
diff --combined include/linux/sched.h
@@@ -941,9 -941,6 +941,9 @@@ struct task_struct 
  #ifdef CONFIG_IOMMU_SVA
        unsigned                        pasid_activated:1;
  #endif
 +#ifdef        CONFIG_CPU_SUP_INTEL
 +      unsigned                        reported_split_lock:1;
 +#endif
  
        unsigned long                   atomic_flags; /* Flags requiring atomic access. */
  
@@@ -2382,20 -2379,6 +2382,6 @@@ static inline void rseq_syscall(struct 
  
  #endif
  
- const struct sched_avg *sched_trace_cfs_rq_avg(struct cfs_rq *cfs_rq);
- char *sched_trace_cfs_rq_path(struct cfs_rq *cfs_rq, char *str, int len);
- int sched_trace_cfs_rq_cpu(struct cfs_rq *cfs_rq);
- const struct sched_avg *sched_trace_rq_avg_rt(struct rq *rq);
- const struct sched_avg *sched_trace_rq_avg_dl(struct rq *rq);
- const struct sched_avg *sched_trace_rq_avg_irq(struct rq *rq);
- int sched_trace_rq_cpu(struct rq *rq);
- int sched_trace_rq_cpu_capacity(struct rq *rq);
- int sched_trace_rq_nr_running(struct rq *rq);
- const struct cpumask *sched_trace_rd_span(struct root_domain *rd);
  #ifdef CONFIG_SCHED_CORE
  extern void sched_core_free(struct task_struct *tsk);
  extern void sched_core_fork(struct task_struct *p);
@@@ -2406,4 -2389,6 +2392,6 @@@ static inline void sched_core_free(stru
  static inline void sched_core_fork(struct task_struct *p) { }
  #endif
  
+ extern void sched_set_stop_task(int cpu, struct task_struct *stop);
  #endif
diff --combined kernel/sched/core.c
  #include <linux/topology.h>
  #include <linux/sched/clock.h>
  #include <linux/sched/cond_resched.h>
+ #include <linux/sched/cputime.h>
  #include <linux/sched/debug.h>
+ #include <linux/sched/hotplug.h>
+ #include <linux/sched/init.h>
  #include <linux/sched/isolation.h>
  #include <linux/sched/loadavg.h>
  #include <linux/sched/mm.h>
@@@ -610,10 -613,10 +613,10 @@@ void double_rq_lock(struct rq *rq1, str
                swap(rq1, rq2);
  
        raw_spin_rq_lock(rq1);
-       if (__rq_lockp(rq1) == __rq_lockp(rq2))
-               return;
+       if (__rq_lockp(rq1) != __rq_lockp(rq2))
+               raw_spin_rq_lock_nested(rq2, SINGLE_DEPTH_NESTING);
  
-       raw_spin_rq_lock_nested(rq2, SINGLE_DEPTH_NESTING);
+       double_rq_clock_clear_update(rq1, rq2);
  }
  #endif
  
@@@ -2190,7 -2193,7 +2193,7 @@@ void check_preempt_curr(struct rq *rq, 
  {
        if (p->sched_class == rq->curr->sched_class)
                rq->curr->sched_class->check_preempt_curr(rq, p, flags);
-       else if (p->sched_class > rq->curr->sched_class)
+       else if (sched_class_above(p->sched_class, rq->curr->sched_class))
                resched_curr(rq);
  
        /*
@@@ -2408,7 -2411,7 +2411,7 @@@ static int migration_cpu_stop(void *dat
         * __migrate_task() such that we will not miss enforcing cpus_ptr
         * during wakeups, see set_cpus_allowed_ptr()'s TASK_WAKING test.
         */
-       flush_smp_call_function_from_idle();
+       flush_smp_call_function_queue();
  
        raw_spin_lock(&p->pi_lock);
        rq_lock(rq, &rf);
@@@ -5689,7 -5692,7 +5692,7 @@@ __pick_next_task(struct rq *rq, struct 
         * higher scheduling class, because otherwise those lose the
         * opportunity to pull in more work from other CPUs.
         */
-       if (likely(prev->sched_class <= &fair_sched_class &&
+       if (likely(!sched_class_above(prev->sched_class, &fair_sched_class) &&
                   rq->nr_running == rq->cfs.h_nr_running)) {
  
                p = pick_next_task_fair(rq, prev, rf);
@@@ -6382,7 -6385,7 +6385,7 @@@ static void __sched notrace __schedule(
                migrate_disable_switch(rq, prev);
                psi_sched_switch(prev, next, !task_on_rq_queued(prev));
  
 -              trace_sched_switch(sched_mode & SM_MASK_PREEMPT, prev_state, prev, next);
 +              trace_sched_switch(sched_mode & SM_MASK_PREEMPT, prev, next, prev_state);
  
                /* Also unlocks the rq: */
                rq = context_switch(rq, prev, next, &rf);
@@@ -9469,11 -9472,11 +9472,11 @@@ void __init sched_init(void
        int i;
  
        /* Make sure the linker didn't screw up */
-       BUG_ON(&idle_sched_class + 1 != &fair_sched_class ||
-              &fair_sched_class + 1 != &rt_sched_class ||
-              &rt_sched_class + 1   != &dl_sched_class);
+       BUG_ON(&idle_sched_class != &fair_sched_class + 1 ||
+              &fair_sched_class != &rt_sched_class + 1 ||
+              &rt_sched_class   != &dl_sched_class + 1);
  #ifdef CONFIG_SMP
-       BUG_ON(&dl_sched_class + 1 != &stop_sched_class);
+       BUG_ON(&dl_sched_class != &stop_sched_class + 1);
  #endif
  
        wait_bit_init();
diff --combined kernel/sched/idle.c
@@@ -102,7 -102,7 +102,7 @@@ void __cpuidle default_idle_call(void
                 * last -- this is very similar to the entry code.
                 */
                trace_hardirqs_on_prepare();
 -              lockdep_hardirqs_on_prepare(_THIS_IP_);
 +              lockdep_hardirqs_on_prepare();
                rcu_idle_enter();
                lockdep_hardirqs_on(_THIS_IP_);
  
@@@ -327,7 -327,7 +327,7 @@@ static void do_idle(void
         * RCU relies on this call to be done outside of an RCU read-side
         * critical section.
         */
-       flush_smp_call_function_from_idle();
+       flush_smp_call_function_queue();
        schedule_idle();
  
        if (unlikely(klp_patch_pending(current)))
diff --combined kernel/smp.c
@@@ -96,7 -96,7 +96,7 @@@ static DEFINE_PER_CPU_ALIGNED(struct ca
  
  static DEFINE_PER_CPU_SHARED_ALIGNED(struct llist_head, call_single_queue);
  
- static void flush_smp_call_function_queue(bool warn_cpu_offline);
+ static void __flush_smp_call_function_queue(bool warn_cpu_offline);
  
  int smpcfd_prepare_cpu(unsigned int cpu)
  {
@@@ -141,7 -141,7 +141,7 @@@ int smpcfd_dying_cpu(unsigned int cpu
         * ensure that the outgoing CPU doesn't go offline with work
         * still pending.
         */
-       flush_smp_call_function_queue(false);
+       __flush_smp_call_function_queue(false);
        irq_work_run();
        return 0;
  }
@@@ -183,9 -183,7 +183,9 @@@ static DEFINE_PER_CPU(smp_call_func_t, 
  static DEFINE_PER_CPU(void *, cur_csd_info);
  static DEFINE_PER_CPU(struct cfd_seq_local, cfd_seq_local);
  
 -#define CSD_LOCK_TIMEOUT (5ULL * NSEC_PER_SEC)
 +static ulong csd_lock_timeout = 5000;  /* CSD lock timeout in milliseconds. */
 +module_param(csd_lock_timeout, ulong, 0444);
 +
  static atomic_t csd_bug_count = ATOMIC_INIT(0);
  static u64 cfd_seq;
  
@@@ -331,7 -329,6 +331,7 @@@ static bool csd_lock_wait_toolong(struc
        u64 ts2, ts_delta;
        call_single_data_t *cpu_cur_csd;
        unsigned int flags = READ_ONCE(csd->node.u_flags);
 +      unsigned long long csd_lock_timeout_ns = csd_lock_timeout * NSEC_PER_MSEC;
  
        if (!(flags & CSD_FLAG_LOCK)) {
                if (!unlikely(*bug_id))
  
        ts2 = sched_clock();
        ts_delta = ts2 - *ts1;
 -      if (likely(ts_delta <= CSD_LOCK_TIMEOUT))
 +      if (likely(ts_delta <= csd_lock_timeout_ns || csd_lock_timeout_ns == 0))
                return false;
  
        firsttime = !*bug_id;
@@@ -544,11 -541,11 +544,11 @@@ void generic_smp_call_function_single_i
  {
        cfd_seq_store(this_cpu_ptr(&cfd_seq_local)->gotipi, CFD_SEQ_NOCPU,
                      smp_processor_id(), CFD_SEQ_GOTIPI);
-       flush_smp_call_function_queue(true);
+       __flush_smp_call_function_queue(true);
  }
  
  /**
-  * flush_smp_call_function_queue - Flush pending smp-call-function callbacks
+  * __flush_smp_call_function_queue - Flush pending smp-call-function callbacks
   *
   * @warn_cpu_offline: If set to 'true', warn if callbacks were queued on an
   *                  offline CPU. Skip this check if set to 'false'.
   * Loop through the call_single_queue and run all the queued callbacks.
   * Must be called with interrupts disabled.
   */
- static void flush_smp_call_function_queue(bool warn_cpu_offline)
+ static void __flush_smp_call_function_queue(bool warn_cpu_offline)
  {
        call_single_data_t *csd, *csd_next;
        struct llist_node *entry, *prev;
                      smp_processor_id(), CFD_SEQ_HDLEND);
  }
  
- void flush_smp_call_function_from_idle(void)
+ /**
+  * flush_smp_call_function_queue - Flush pending smp-call-function callbacks
+  *                               from task context (idle, migration thread)
+  *
+  * When TIF_POLLING_NRFLAG is supported and a CPU is in idle and has it
+  * set, then remote CPUs can avoid sending IPIs and wake the idle CPU by
+  * setting TIF_NEED_RESCHED. The idle task on the woken up CPU has to
+  * handle queued SMP function calls before scheduling.
+  *
+  * The migration thread has to ensure that an eventually pending wakeup has
+  * been handled before it migrates a task.
+  */
+ void flush_smp_call_function_queue(void)
  {
+       unsigned int was_pending;
        unsigned long flags;
  
        if (llist_empty(this_cpu_ptr(&call_single_queue)))
        cfd_seq_store(this_cpu_ptr(&cfd_seq_local)->idle, CFD_SEQ_NOCPU,
                      smp_processor_id(), CFD_SEQ_IDLE);
        local_irq_save(flags);
-       flush_smp_call_function_queue(true);
+       /* Get the already pending soft interrupts for RT enabled kernels */
+       was_pending = local_softirq_pending();
+       __flush_smp_call_function_queue(true);
        if (local_softirq_pending())
-               do_softirq();
+               do_softirq_post_smp_call_flush(was_pending);
  
        local_irq_restore(flags);
  }
diff --combined kernel/stop_machine.c
@@@ -535,8 -535,6 +535,6 @@@ void stop_machine_park(int cpu
        kthread_park(stopper->thread);
  }
  
- extern void sched_set_stop_task(int cpu, struct task_struct *stop);
  static void cpu_stop_create(unsigned int cpu)
  {
        sched_set_stop_task(cpu, per_cpu(cpu_stopper.thread, cpu));
@@@ -633,27 -631,6 +631,27 @@@ int stop_machine(cpu_stop_fn_t fn, voi
  }
  EXPORT_SYMBOL_GPL(stop_machine);
  
 +#ifdef CONFIG_SCHED_SMT
 +int stop_core_cpuslocked(unsigned int cpu, cpu_stop_fn_t fn, void *data)
 +{
 +      const struct cpumask *smt_mask = cpu_smt_mask(cpu);
 +
 +      struct multi_stop_data msdata = {
 +              .fn = fn,
 +              .data = data,
 +              .num_threads = cpumask_weight(smt_mask),
 +              .active_cpus = smt_mask,
 +      };
 +
 +      lockdep_assert_cpus_held();
 +
 +      /* Set the initial state and stop all online cpus. */
 +      set_state(&msdata, MULTI_STOP_PREPARE);
 +      return stop_cpus(smt_mask, multi_cpu_stop, &msdata);
 +}
 +EXPORT_SYMBOL_GPL(stop_core_cpuslocked);
 +#endif
 +
  /**
   * stop_machine_from_inactive_cpu - stop_machine() from inactive CPU
   * @fn: the function to run