aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/x86/kernel/cpu/bugs.c46
1 files changed, 25 insertions, 21 deletions
diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index 29f40a92f5a8..9cab538e10f1 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -530,40 +530,44 @@ specv2_set_mode:
530 arch_smt_update(); 530 arch_smt_update();
531} 531}
532 532
533static bool stibp_needed(void) 533static void update_stibp_msr(void * __unused)
534{ 534{
535 /* Enhanced IBRS makes using STIBP unnecessary. */ 535 wrmsrl(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base);
536 if (spectre_v2_enabled == SPECTRE_V2_IBRS_ENHANCED)
537 return false;
538
539 /* Check for strict user mitigation mode */
540 return spectre_v2_user == SPECTRE_V2_USER_STRICT;
541} 536}
542 537
543static void update_stibp_msr(void *info) 538/* Update x86_spec_ctrl_base in case SMT state changed. */
539static void update_stibp_strict(void)
544{ 540{
545 wrmsrl(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base); 541 u64 mask = x86_spec_ctrl_base & ~SPEC_CTRL_STIBP;
542
543 if (sched_smt_active())
544 mask |= SPEC_CTRL_STIBP;
545
546 if (mask == x86_spec_ctrl_base)
547 return;
548
549 pr_info("Update user space SMT mitigation: STIBP %s\n",
550 mask & SPEC_CTRL_STIBP ? "always-on" : "off");
551 x86_spec_ctrl_base = mask;
552 on_each_cpu(update_stibp_msr, NULL, 1);
546} 553}
547 554
548void arch_smt_update(void) 555void arch_smt_update(void)
549{ 556{
550 u64 mask; 557 /* Enhanced IBRS implies STIBP. No update required. */
551 558 if (spectre_v2_enabled == SPECTRE_V2_IBRS_ENHANCED)
552 if (!stibp_needed())
553 return; 559 return;
554 560
555 mutex_lock(&spec_ctrl_mutex); 561 mutex_lock(&spec_ctrl_mutex);
556 562
557 mask = x86_spec_ctrl_base & ~SPEC_CTRL_STIBP; 563 switch (spectre_v2_user) {
558 if (sched_smt_active()) 564 case SPECTRE_V2_USER_NONE:
559 mask |= SPEC_CTRL_STIBP; 565 break;
560 566 case SPECTRE_V2_USER_STRICT:
561 if (mask != x86_spec_ctrl_base) { 567 update_stibp_strict();
562 pr_info("Spectre v2 cross-process SMT mitigation: %s STIBP\n", 568 break;
563 mask & SPEC_CTRL_STIBP ? "Enabling" : "Disabling");
564 x86_spec_ctrl_base = mask;
565 on_each_cpu(update_stibp_msr, NULL, 1);
566 } 569 }
570
567 mutex_unlock(&spec_ctrl_mutex); 571 mutex_unlock(&spec_ctrl_mutex);
568} 572}
569 573