@@ -530,40 +530,44 @@ static void __init spectre_v2_select_mitigation(void)
530
530
arch_smt_update ();
531
531
}
532
532
533
- static bool stibp_needed (void )
533
+ static void update_stibp_msr (void * __unused )
534
534
{
535
- /* Enhanced IBRS makes using STIBP unnecessary. */
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 ;
535
+ wrmsrl (MSR_IA32_SPEC_CTRL , x86_spec_ctrl_base );
541
536
}
542
537
543
- static void update_stibp_msr (void * info )
538
+ /* Update x86_spec_ctrl_base in case SMT state changed. */
539
+ static 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
548
555
void arch_smt_update (void )
549
556
{
550
- u64 mask ;
551
-
552
- if (!stibp_needed ())
557
+ /* Enhanced IBRS implies STIBP. No update required. */
558
+ if (spectre_v2_enabled == SPECTRE_V2_IBRS_ENHANCED )
553
559
return ;
554
560
555
561
mutex_lock (& spec_ctrl_mutex );
556
562
557
- mask = x86_spec_ctrl_base & ~SPEC_CTRL_STIBP ;
558
- if (sched_smt_active ())
559
- mask |= SPEC_CTRL_STIBP ;
560
-
561
- if (mask != x86_spec_ctrl_base ) {
562
- pr_info ("Spectre v2 cross-process SMT mitigation: %s STIBP\n" ,
563
- mask & SPEC_CTRL_STIBP ? "Enabling" : "Disabling" );
564
- x86_spec_ctrl_base = mask ;
565
- on_each_cpu (update_stibp_msr , NULL , 1 );
563
+ switch (spectre_v2_user ) {
564
+ case SPECTRE_V2_USER_NONE :
565
+ break ;
566
+ case SPECTRE_V2_USER_STRICT :
567
+ update_stibp_strict ();
568
+ break ;
566
569
}
570
+
567
571
mutex_unlock (& spec_ctrl_mutex );
568
572
}
569
573
0 commit comments