]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
sched/smt: Update sched_smt_present at runtime
authorPeter Zijlstra <peterz@infradead.org>
Tue, 29 May 2018 14:43:46 +0000 (16:43 +0200)
committerStefan Bader <stefan.bader@canonical.com>
Wed, 8 Aug 2018 12:08:07 +0000 (14:08 +0200)
The static key sched_smt_present is only updated at boot time when SMT
siblings have been detected. Booting with maxcpus=1 and bringing the
siblings online after boot rebuilds the scheduling domains correctly but
does not update the static key, so the SMT code is not enabled.

Let the key be updated in the scheduler CPU hotplug code to fix this.

Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Acked-by: Ingo Molnar <mingo@kernel.org>
CVE-2018-3620
CVE-2018-3646

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
kernel/sched/core.c
kernel/sched/fair.c

index b4f7f890c1b9a22e9e19f088f8902e3bef8a45a8..3768fc2fcb5a89111e1b9ebc2611831588ce21f1 100644 (file)
@@ -5648,6 +5648,18 @@ int sched_cpu_activate(unsigned int cpu)
        struct rq *rq = cpu_rq(cpu);
        struct rq_flags rf;
 
+#ifdef CONFIG_SCHED_SMT
+       /*
+        * The sched_smt_present static key needs to be evaluated on every
+        * hotplug event because at boot time SMT might be disabled when
+        * the number of booted CPUs is limited.
+        *
+        * If then later a sibling gets hotplugged, then the key would stay
+        * off and SMT scheduling would never be functional.
+        */
+       if (cpumask_weight(cpu_smt_mask(cpu)) > 1)
+               static_branch_enable_cpuslocked(&sched_smt_present);
+#endif
        set_cpu_active(cpu, true);
 
        if (sched_smp_initialized) {
@@ -5743,22 +5755,6 @@ int sched_cpu_dying(unsigned int cpu)
 }
 #endif
 
-#ifdef CONFIG_SCHED_SMT
-DEFINE_STATIC_KEY_FALSE(sched_smt_present);
-
-static void sched_init_smt(void)
-{
-       /*
-        * We've enumerated all CPUs and will assume that if any CPU
-        * has SMT siblings, CPU0 will too.
-        */
-       if (cpumask_weight(cpu_smt_mask(0)) > 1)
-               static_branch_enable(&sched_smt_present);
-}
-#else
-static inline void sched_init_smt(void) { }
-#endif
-
 void __init sched_init_smp(void)
 {
        sched_init_numa();
@@ -5780,8 +5776,6 @@ void __init sched_init_smp(void)
        init_sched_rt_class();
        init_sched_dl_class();
 
-       sched_init_smt();
-
        sched_smp_initialized = true;
 }
 
index 26a71ebcd3c2ed94941673a07408a8656ea766c3..61365fcbe148518297bdf3cd189c415bc006b437 100644 (file)
@@ -6008,6 +6008,7 @@ static inline int find_idlest_cpu(struct sched_domain *sd, struct task_struct *p
 }
 
 #ifdef CONFIG_SCHED_SMT
+DEFINE_STATIC_KEY_FALSE(sched_smt_present);
 
 static inline void set_idle_cores(int cpu, int val)
 {