Skip to content

Commit f55e301

Browse files
KAGA-KOKOgregkh
authored andcommitted
x86/speculation: Rework SMT state change
commit a74cfff upstream 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 <[email protected]> Reviewed-by: Ingo Molnar <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Jiri Kosina <[email protected]> Cc: Tom Lendacky <[email protected]> Cc: Josh Poimboeuf <[email protected]> Cc: Andrea Arcangeli <[email protected]> Cc: David Woodhouse <[email protected]> Cc: Tim Chen <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Casey Schaufler <[email protected]> Cc: Asit Mallick <[email protected]> Cc: Arjan van de Ven <[email protected]> Cc: Jon Masters <[email protected]> Cc: Waiman Long <[email protected]> Cc: Greg KH <[email protected]> Cc: Dave Stewart <[email protected]> Cc: Kees Cook <[email protected]> Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 340693e commit f55e301

3 files changed

Lines changed: 16 additions & 12 deletions

File tree

‎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>
@@ -343,16 +344,14 @@ void arch_smt_update(void)
343344
return;
344345

345346
mutex_lock(&spec_ctrl_mutex);
346-
mask = x86_spec_ctrl_base;
347-
if (cpu_smt_control == CPU_SMT_ENABLED)
347+
348+
mask = x86_spec_ctrl_base & ~SPEC_CTRL_STIBP;
349+
if (sched_smt_active())
348350
mask |= SPEC_CTRL_STIBP;
349-
else
350-
mask &= ~SPEC_CTRL_STIBP;
351351

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

‎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>
@@ -346,6 +347,12 @@ void cpu_hotplug_enable(void)
346347
EXPORT_SYMBOL_GPL(cpu_hotplug_enable);
347348
#endif /* CONFIG_HOTPLUG_CPU */
348349

350+
/*
351+
* Architectures that need SMT-specific errata handling during SMT hotplug
352+
* should override this.
353+
*/
354+
void __weak arch_smt_update(void) { }
355+
349356
#ifdef CONFIG_HOTPLUG_SMT
350357
enum cpuhp_smt_control cpu_smt_control __read_mostly = CPU_SMT_ENABLED;
351358
EXPORT_SYMBOL_GPL(cpu_smt_control);
@@ -982,6 +989,7 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen,
982989
* concurrent CPU hotplug via cpu_add_remove_lock.
983990
*/
984991
lockup_detector_cleanup();
992+
arch_smt_update();
985993
return ret;
986994
}
987995

@@ -1110,6 +1118,7 @@ static int _cpu_up(unsigned int cpu, int tasks_frozen, enum cpuhp_state target)
11101118
ret = cpuhp_up_callbacks(cpu, st, target);
11111119
out:
11121120
cpus_write_unlock();
1121+
arch_smt_update();
11131122
return ret;
11141123
}
11151124

@@ -2026,12 +2035,6 @@ static void cpuhp_online_cpu_device(unsigned int cpu)
20262035
kobject_uevent(&dev->kobj, KOBJ_ONLINE);
20272036
}
20282037

2029-
/*
2030-
* Architectures that need SMT-specific errata handling during SMT hotplug
2031-
* should override this.
2032-
*/
2033-
void __weak arch_smt_update(void) { };
2034-
20352038
static int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval)
20362039
{
20372040
int cpu, ret = 0;

0 commit comments

Comments
 (0)