Skip to content

Commit a74cfff

Browse files
committed
x86/speculation: Rework SMT state change
arch_smt_update() is only called when the sysfs SMT control knob is changed. This means that when SMT is enabled in the sysfs control knob the system is considered to have SMT active even if all siblings are offline. To allow finegrained control of the speculation mitigations, the actual SMT state is more interesting than the fact that siblings could be enabled. Rework the code, so arch_smt_update() is invoked from each individual CPU hotplug function, and simplify the update function while at it. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Ingo Molnar <mingo@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Jiri Kosina <jkosina@suse.cz> Cc: Tom Lendacky <thomas.lendacky@amd.com> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: David Woodhouse <dwmw@amazon.co.uk> Cc: Tim Chen <tim.c.chen@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Dave Hansen <dave.hansen@intel.com> Cc: Casey Schaufler <casey.schaufler@intel.com> Cc: Asit Mallick <asit.k.mallick@intel.com> Cc: Arjan van de Ven <arjan@linux.intel.com> Cc: Jon Masters <jcm@redhat.com> Cc: Waiman Long <longman9394@gmail.com> Cc: Greg KH <gregkh@linuxfoundation.org> Cc: Dave Stewart <david.c.stewart@intel.com> Cc: Kees Cook <keescook@chromium.org> Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/20181125185004.521974984@linutronix.de
1 parent 321a874 commit a74cfff

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

arch/x86/kernel/cpu/bugs.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/module.h>
1515
#include <linux/nospec.h>
1616
#include <linux/prctl.h>
17+
#include <linux/sched/smt.h>
1718

1819
#include <asm/spec-ctrl.h>
1920
#include <asm/cmdline.h>
@@ -344,16 +345,14 @@ void arch_smt_update(void)
344345
return;
345346

346347
mutex_lock(&spec_ctrl_mutex);
347-
mask = x86_spec_ctrl_base;
348-
if (cpu_smt_control == CPU_SMT_ENABLED)
348+
349+
mask = x86_spec_ctrl_base & ~SPEC_CTRL_STIBP;
350+
if (sched_smt_active())
349351
mask |= SPEC_CTRL_STIBP;
350-
else
351-
mask &= ~SPEC_CTRL_STIBP;
352352

353353
if (mask != x86_spec_ctrl_base) {
354354
pr_info("Spectre v2 cross-process SMT mitigation: %s STIBP\n",
355-
cpu_smt_control == CPU_SMT_ENABLED ?
356-
"Enabling" : "Disabling");
355+
mask & SPEC_CTRL_STIBP ? "Enabling" : "Disabling");
357356
x86_spec_ctrl_base = mask;
358357
on_each_cpu(update_stibp_msr, NULL, 1);
359358
}

include/linux/sched/smt.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ static __always_inline bool sched_smt_active(void)
1515
static inline bool sched_smt_active(void) { return false; }
1616
#endif
1717

18+
void arch_smt_update(void);
19+
1820
#endif

kernel/cpu.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/sched/signal.h>
1111
#include <linux/sched/hotplug.h>
1212
#include <linux/sched/task.h>
13+
#include <linux/sched/smt.h>
1314
#include <linux/unistd.h>
1415
#include <linux/cpu.h>
1516
#include <linux/oom.h>
@@ -367,6 +368,12 @@ static void lockdep_release_cpus_lock(void)
367368

368369
#endif /* CONFIG_HOTPLUG_CPU */
369370

371+
/*
372+
* Architectures that need SMT-specific errata handling during SMT hotplug
373+
* should override this.
374+
*/
375+
void __weak arch_smt_update(void) { }
376+
370377
#ifdef CONFIG_HOTPLUG_SMT
371378
enum cpuhp_smt_control cpu_smt_control __read_mostly = CPU_SMT_ENABLED;
372379
EXPORT_SYMBOL_GPL(cpu_smt_control);
@@ -1011,6 +1018,7 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen,
10111018
* concurrent CPU hotplug via cpu_add_remove_lock.
10121019
*/
10131020
lockup_detector_cleanup();
1021+
arch_smt_update();
10141022
return ret;
10151023
}
10161024

@@ -1139,6 +1147,7 @@ static int _cpu_up(unsigned int cpu, int tasks_frozen, enum cpuhp_state target)
11391147
ret = cpuhp_up_callbacks(cpu, st, target);
11401148
out:
11411149
cpus_write_unlock();
1150+
arch_smt_update();
11421151
return ret;
11431152
}
11441153

@@ -2055,12 +2064,6 @@ static void cpuhp_online_cpu_device(unsigned int cpu)
20552064
kobject_uevent(&dev->kobj, KOBJ_ONLINE);
20562065
}
20572066

2058-
/*
2059-
* Architectures that need SMT-specific errata handling during SMT hotplug
2060-
* should override this.
2061-
*/
2062-
void __weak arch_smt_update(void) { };
2063-
20642067
static int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval)
20652068
{
20662069
int cpu, ret = 0;

0 commit comments

Comments
 (0)