@@ -1537,20 +1537,25 @@ static enum spectre_v2_mitigation __init spectre_v2_select_retpoline(void)
1537
1537
return SPECTRE_V2_RETPOLINE ;
1538
1538
}
1539
1539
1540
+ static bool __ro_after_init rrsba_disabled ;
1541
+
1540
1542
/* Disable in-kernel use of non-RSB RET predictors */
1541
1543
static void __init spec_ctrl_disable_kernel_rrsba (void )
1542
1544
{
1543
- u64 x86_arch_cap_msr ;
1545
+ if (rrsba_disabled )
1546
+ return ;
1544
1547
1545
- if (!boot_cpu_has (X86_FEATURE_RRSBA_CTRL ))
1548
+ if (!(x86_arch_cap_msr & ARCH_CAP_RRSBA )) {
1549
+ rrsba_disabled = true;
1546
1550
return ;
1551
+ }
1547
1552
1548
- x86_arch_cap_msr = x86_read_arch_cap_msr ();
1553
+ if (!boot_cpu_has (X86_FEATURE_RRSBA_CTRL ))
1554
+ return ;
1549
1555
1550
- if (x86_arch_cap_msr & ARCH_CAP_RRSBA ) {
1551
- x86_spec_ctrl_base |= SPEC_CTRL_RRSBA_DIS_S ;
1552
- update_spec_ctrl (x86_spec_ctrl_base );
1553
- }
1556
+ x86_spec_ctrl_base |= SPEC_CTRL_RRSBA_DIS_S ;
1557
+ update_spec_ctrl (x86_spec_ctrl_base );
1558
+ rrsba_disabled = true;
1554
1559
}
1555
1560
1556
1561
static void __init spectre_v2_determine_rsb_fill_type_at_vmexit (enum spectre_v2_mitigation mode )
@@ -1651,9 +1656,11 @@ static void __init bhi_select_mitigation(void)
1651
1656
return ;
1652
1657
1653
1658
/* Retpoline mitigates against BHI unless the CPU has RRSBA behavior */
1654
- if (cpu_feature_enabled (X86_FEATURE_RETPOLINE ) &&
1655
- !(x86_read_arch_cap_msr () & ARCH_CAP_RRSBA ))
1656
- return ;
1659
+ if (cpu_feature_enabled (X86_FEATURE_RETPOLINE )) {
1660
+ spec_ctrl_disable_kernel_rrsba ();
1661
+ if (rrsba_disabled )
1662
+ return ;
1663
+ }
1657
1664
1658
1665
if (spec_ctrl_bhi_dis ())
1659
1666
return ;
@@ -2808,8 +2815,7 @@ static const char *spectre_bhi_state(void)
2808
2815
return "; BHI: BHI_DIS_S" ;
2809
2816
else if (boot_cpu_has (X86_FEATURE_CLEAR_BHB_LOOP ))
2810
2817
return "; BHI: SW loop, KVM: SW loop" ;
2811
- else if (boot_cpu_has (X86_FEATURE_RETPOLINE ) &&
2812
- !(x86_arch_cap_msr & ARCH_CAP_RRSBA ))
2818
+ else if (boot_cpu_has (X86_FEATURE_RETPOLINE ) && rrsba_disabled )
2813
2819
return "; BHI: Retpoline" ;
2814
2820
else if (boot_cpu_has (X86_FEATURE_CLEAR_BHB_LOOP_ON_VMEXIT ))
2815
2821
return "; BHI: Syscall hardening, KVM: SW loop" ;
0 commit comments