@@ -113,6 +113,10 @@ DEFINE_STATIC_KEY_FALSE(switch_mm_cond_ibpb);
113113/* Control unconditional IBPB in switch_mm() */
114114DEFINE_STATIC_KEY_FALSE (switch_mm_always_ibpb );
115115
116+ /* Control IBPB on vCPU load */
117+ DEFINE_STATIC_KEY_FALSE (switch_vcpu_ibpb );
118+ EXPORT_SYMBOL_GPL (switch_vcpu_ibpb );
119+
116120/* Control MDS CPU buffer clear before idling (halt, mwait) */
117121DEFINE_STATIC_KEY_FALSE (mds_idle_clear );
118122EXPORT_SYMBOL_GPL (mds_idle_clear );
@@ -234,7 +238,7 @@ static void x86_amd_ssb_disable(void)
234238
235239/* Default mitigation for MDS-affected CPUs */
236240static enum mds_mitigations mds_mitigation __ro_after_init =
237- IS_ENABLED (CONFIG_MITIGATION_MDS ) ? MDS_MITIGATION_FULL : MDS_MITIGATION_OFF ;
241+ IS_ENABLED (CONFIG_MITIGATION_MDS ) ? MDS_MITIGATION_AUTO : MDS_MITIGATION_OFF ;
238242static bool mds_nosmt __ro_after_init = false;
239243
240244static const char * const mds_strings [] = {
@@ -243,13 +247,50 @@ static const char * const mds_strings[] = {
243247 [MDS_MITIGATION_VMWERV ] = "Vulnerable: Clear CPU buffers attempted, no microcode" ,
244248};
245249
250+ enum taa_mitigations {
251+ TAA_MITIGATION_OFF ,
252+ TAA_MITIGATION_AUTO ,
253+ TAA_MITIGATION_UCODE_NEEDED ,
254+ TAA_MITIGATION_VERW ,
255+ TAA_MITIGATION_TSX_DISABLED ,
256+ };
257+
258+ /* Default mitigation for TAA-affected CPUs */
259+ static enum taa_mitigations taa_mitigation __ro_after_init =
260+ IS_ENABLED (CONFIG_MITIGATION_TAA ) ? TAA_MITIGATION_AUTO : TAA_MITIGATION_OFF ;
261+
262+ enum mmio_mitigations {
263+ MMIO_MITIGATION_OFF ,
264+ MMIO_MITIGATION_AUTO ,
265+ MMIO_MITIGATION_UCODE_NEEDED ,
266+ MMIO_MITIGATION_VERW ,
267+ };
268+
269+ /* Default mitigation for Processor MMIO Stale Data vulnerabilities */
270+ static enum mmio_mitigations mmio_mitigation __ro_after_init =
271+ IS_ENABLED (CONFIG_MITIGATION_MMIO_STALE_DATA ) ? MMIO_MITIGATION_AUTO : MMIO_MITIGATION_OFF ;
272+
273+ enum rfds_mitigations {
274+ RFDS_MITIGATION_OFF ,
275+ RFDS_MITIGATION_AUTO ,
276+ RFDS_MITIGATION_VERW ,
277+ RFDS_MITIGATION_UCODE_NEEDED ,
278+ };
279+
280+ /* Default mitigation for Register File Data Sampling */
281+ static enum rfds_mitigations rfds_mitigation __ro_after_init =
282+ IS_ENABLED (CONFIG_MITIGATION_RFDS ) ? RFDS_MITIGATION_AUTO : RFDS_MITIGATION_OFF ;
283+
246284static void __init mds_select_mitigation (void )
247285{
248286 if (!boot_cpu_has_bug (X86_BUG_MDS ) || cpu_mitigations_off ()) {
249287 mds_mitigation = MDS_MITIGATION_OFF ;
250288 return ;
251289 }
252290
291+ if (mds_mitigation == MDS_MITIGATION_AUTO )
292+ mds_mitigation = MDS_MITIGATION_FULL ;
293+
253294 if (mds_mitigation == MDS_MITIGATION_FULL ) {
254295 if (!boot_cpu_has (X86_FEATURE_MD_CLEAR ))
255296 mds_mitigation = MDS_MITIGATION_VMWERV ;
@@ -286,16 +327,6 @@ early_param("mds", mds_cmdline);
286327#undef pr_fmt
287328#define pr_fmt (fmt ) "TAA: " fmt
288329
289- enum taa_mitigations {
290- TAA_MITIGATION_OFF ,
291- TAA_MITIGATION_UCODE_NEEDED ,
292- TAA_MITIGATION_VERW ,
293- TAA_MITIGATION_TSX_DISABLED ,
294- };
295-
296- /* Default mitigation for TAA-affected CPUs */
297- static enum taa_mitigations taa_mitigation __ro_after_init =
298- IS_ENABLED (CONFIG_MITIGATION_TAA ) ? TAA_MITIGATION_VERW : TAA_MITIGATION_OFF ;
299330static bool taa_nosmt __ro_after_init ;
300331
301332static const char * const taa_strings [] = {
@@ -386,15 +417,6 @@ early_param("tsx_async_abort", tsx_async_abort_parse_cmdline);
386417#undef pr_fmt
387418#define pr_fmt (fmt ) "MMIO Stale Data: " fmt
388419
389- enum mmio_mitigations {
390- MMIO_MITIGATION_OFF ,
391- MMIO_MITIGATION_UCODE_NEEDED ,
392- MMIO_MITIGATION_VERW ,
393- };
394-
395- /* Default mitigation for Processor MMIO Stale Data vulnerabilities */
396- static enum mmio_mitigations mmio_mitigation __ro_after_init =
397- IS_ENABLED (CONFIG_MITIGATION_MMIO_STALE_DATA ) ? MMIO_MITIGATION_VERW : MMIO_MITIGATION_OFF ;
398420static bool mmio_nosmt __ro_after_init = false;
399421
400422static const char * const mmio_strings [] = {
@@ -483,16 +505,6 @@ early_param("mmio_stale_data", mmio_stale_data_parse_cmdline);
483505#undef pr_fmt
484506#define pr_fmt (fmt ) "Register File Data Sampling: " fmt
485507
486- enum rfds_mitigations {
487- RFDS_MITIGATION_OFF ,
488- RFDS_MITIGATION_VERW ,
489- RFDS_MITIGATION_UCODE_NEEDED ,
490- };
491-
492- /* Default mitigation for Register File Data Sampling */
493- static enum rfds_mitigations rfds_mitigation __ro_after_init =
494- IS_ENABLED (CONFIG_MITIGATION_RFDS ) ? RFDS_MITIGATION_VERW : RFDS_MITIGATION_OFF ;
495-
496508static const char * const rfds_strings [] = {
497509 [RFDS_MITIGATION_OFF ] = "Vulnerable" ,
498510 [RFDS_MITIGATION_VERW ] = "Mitigation: Clear Register File" ,
@@ -508,6 +520,9 @@ static void __init rfds_select_mitigation(void)
508520 if (rfds_mitigation == RFDS_MITIGATION_OFF )
509521 return ;
510522
523+ if (rfds_mitigation == RFDS_MITIGATION_AUTO )
524+ rfds_mitigation = RFDS_MITIGATION_VERW ;
525+
511526 if (x86_arch_cap_msr & ARCH_CAP_RFDS_CLEAR )
512527 setup_force_cpu_cap (X86_FEATURE_CLEAR_CPU_BUF );
513528 else
@@ -1293,9 +1308,13 @@ static __ro_after_init enum spectre_v2_mitigation_cmd spectre_v2_cmd;
12931308static enum spectre_v2_user_cmd __init
12941309spectre_v2_parse_user_cmdline (void )
12951310{
1311+ enum spectre_v2_user_cmd mode ;
12961312 char arg [20 ];
12971313 int ret , i ;
12981314
1315+ mode = IS_ENABLED (CONFIG_MITIGATION_SPECTRE_V2 ) ?
1316+ SPECTRE_V2_USER_CMD_AUTO : SPECTRE_V2_USER_CMD_NONE ;
1317+
12991318 switch (spectre_v2_cmd ) {
13001319 case SPECTRE_V2_CMD_NONE :
13011320 return SPECTRE_V2_USER_CMD_NONE ;
@@ -1308,7 +1327,7 @@ spectre_v2_parse_user_cmdline(void)
13081327 ret = cmdline_find_option (boot_command_line , "spectre_v2_user" ,
13091328 arg , sizeof (arg ));
13101329 if (ret < 0 )
1311- return SPECTRE_V2_USER_CMD_AUTO ;
1330+ return mode ;
13121331
13131332 for (i = 0 ; i < ARRAY_SIZE (v2_user_options ); i ++ ) {
13141333 if (match_option (arg , ret , v2_user_options [i ].option )) {
@@ -1318,8 +1337,8 @@ spectre_v2_parse_user_cmdline(void)
13181337 }
13191338 }
13201339
1321- pr_err ("Unknown user space protection option (%s). Switching to AUTO select \n" , arg );
1322- return SPECTRE_V2_USER_CMD_AUTO ;
1340+ pr_err ("Unknown user space protection option (%s). Switching to default \n" , arg );
1341+ return mode ;
13231342}
13241343
13251344static inline bool spectre_v2_in_ibrs_mode (enum spectre_v2_mitigation mode )
@@ -1331,16 +1350,11 @@ static void __init
13311350spectre_v2_user_select_mitigation (void )
13321351{
13331352 enum spectre_v2_user_mitigation mode = SPECTRE_V2_USER_NONE ;
1334- bool smt_possible = IS_ENABLED (CONFIG_SMP );
13351353 enum spectre_v2_user_cmd cmd ;
13361354
13371355 if (!boot_cpu_has (X86_FEATURE_IBPB ) && !boot_cpu_has (X86_FEATURE_STIBP ))
13381356 return ;
13391357
1340- if (cpu_smt_control == CPU_SMT_FORCE_DISABLED ||
1341- cpu_smt_control == CPU_SMT_NOT_SUPPORTED )
1342- smt_possible = false;
1343-
13441358 cmd = spectre_v2_parse_user_cmdline ();
13451359 switch (cmd ) {
13461360 case SPECTRE_V2_USER_CMD_NONE :
@@ -1364,7 +1378,7 @@ spectre_v2_user_select_mitigation(void)
13641378
13651379 /* Initialize Indirect Branch Prediction Barrier */
13661380 if (boot_cpu_has (X86_FEATURE_IBPB )) {
1367- setup_force_cpu_cap ( X86_FEATURE_USE_IBPB );
1381+ static_branch_enable ( & switch_vcpu_ibpb );
13681382
13691383 spectre_v2_user_ibpb = mode ;
13701384 switch (cmd ) {
@@ -1401,7 +1415,7 @@ spectre_v2_user_select_mitigation(void)
14011415 * so allow for STIBP to be selected in those cases.
14021416 */
14031417 if (!boot_cpu_has (X86_FEATURE_STIBP ) ||
1404- !smt_possible ||
1418+ !cpu_smt_possible () ||
14051419 (spectre_v2_in_eibrs_mode (spectre_v2_enabled ) &&
14061420 !boot_cpu_has (X86_FEATURE_AUTOIBRS )))
14071421 return ;
@@ -1973,6 +1987,7 @@ void cpu_bugs_smt_update(void)
19731987
19741988 switch (mds_mitigation ) {
19751989 case MDS_MITIGATION_FULL :
1990+ case MDS_MITIGATION_AUTO :
19761991 case MDS_MITIGATION_VMWERV :
19771992 if (sched_smt_active () && !boot_cpu_has (X86_BUG_MSBDS_ONLY ))
19781993 pr_warn_once (MDS_MSG_SMT );
@@ -1984,6 +1999,7 @@ void cpu_bugs_smt_update(void)
19841999
19852000 switch (taa_mitigation ) {
19862001 case TAA_MITIGATION_VERW :
2002+ case TAA_MITIGATION_AUTO :
19872003 case TAA_MITIGATION_UCODE_NEEDED :
19882004 if (sched_smt_active ())
19892005 pr_warn_once (TAA_MSG_SMT );
@@ -1995,6 +2011,7 @@ void cpu_bugs_smt_update(void)
19952011
19962012 switch (mmio_mitigation ) {
19972013 case MMIO_MITIGATION_VERW :
2014+ case MMIO_MITIGATION_AUTO :
19982015 case MMIO_MITIGATION_UCODE_NEEDED :
19992016 if (sched_smt_active ())
20002017 pr_warn_once (MMIO_MSG_SMT );
@@ -2522,6 +2539,7 @@ enum srso_mitigation {
25222539 SRSO_MITIGATION_SAFE_RET ,
25232540 SRSO_MITIGATION_IBPB ,
25242541 SRSO_MITIGATION_IBPB_ON_VMEXIT ,
2542+ SRSO_MITIGATION_BP_SPEC_REDUCE ,
25252543};
25262544
25272545enum srso_mitigation_cmd {
@@ -2539,7 +2557,8 @@ static const char * const srso_strings[] = {
25392557 [SRSO_MITIGATION_MICROCODE ] = "Vulnerable: Microcode, no safe RET" ,
25402558 [SRSO_MITIGATION_SAFE_RET ] = "Mitigation: Safe RET" ,
25412559 [SRSO_MITIGATION_IBPB ] = "Mitigation: IBPB" ,
2542- [SRSO_MITIGATION_IBPB_ON_VMEXIT ] = "Mitigation: IBPB on VMEXIT only"
2560+ [SRSO_MITIGATION_IBPB_ON_VMEXIT ] = "Mitigation: IBPB on VMEXIT only" ,
2561+ [SRSO_MITIGATION_BP_SPEC_REDUCE ] = "Mitigation: Reduced Speculation"
25432562};
25442563
25452564static enum srso_mitigation srso_mitigation __ro_after_init = SRSO_MITIGATION_NONE ;
@@ -2578,7 +2597,7 @@ static void __init srso_select_mitigation(void)
25782597 srso_cmd == SRSO_CMD_OFF ) {
25792598 if (boot_cpu_has (X86_FEATURE_SBPB ))
25802599 x86_pred_cmd = PRED_CMD_SBPB ;
2581- return ;
2600+ goto out ;
25822601 }
25832602
25842603 if (has_microcode ) {
@@ -2590,7 +2609,7 @@ static void __init srso_select_mitigation(void)
25902609 */
25912610 if (boot_cpu_data .x86 < 0x19 && !cpu_smt_possible ()) {
25922611 setup_force_cpu_cap (X86_FEATURE_SRSO_NO );
2593- return ;
2612+ goto out ;
25942613 }
25952614
25962615 if (retbleed_mitigation == RETBLEED_MITIGATION_IBPB ) {
@@ -2670,6 +2689,12 @@ static void __init srso_select_mitigation(void)
26702689
26712690ibpb_on_vmexit :
26722691 case SRSO_CMD_IBPB_ON_VMEXIT :
2692+ if (boot_cpu_has (X86_FEATURE_SRSO_BP_SPEC_REDUCE )) {
2693+ pr_notice ("Reducing speculation to address VM/HV SRSO attack vector.\n" );
2694+ srso_mitigation = SRSO_MITIGATION_BP_SPEC_REDUCE ;
2695+ break ;
2696+ }
2697+
26732698 if (IS_ENABLED (CONFIG_MITIGATION_IBPB_ENTRY )) {
26742699 if (has_microcode ) {
26752700 setup_force_cpu_cap (X86_FEATURE_IBPB_ON_VMEXIT );
@@ -2691,7 +2716,15 @@ static void __init srso_select_mitigation(void)
26912716 }
26922717
26932718out :
2694- pr_info ("%s\n" , srso_strings [srso_mitigation ]);
2719+ /*
2720+ * Clear the feature flag if this mitigation is not selected as that
2721+ * feature flag controls the BpSpecReduce MSR bit toggling in KVM.
2722+ */
2723+ if (srso_mitigation != SRSO_MITIGATION_BP_SPEC_REDUCE )
2724+ setup_clear_cpu_cap (X86_FEATURE_SRSO_BP_SPEC_REDUCE );
2725+
2726+ if (srso_mitigation != SRSO_MITIGATION_NONE )
2727+ pr_info ("%s\n" , srso_strings [srso_mitigation ]);
26952728}
26962729
26972730#undef pr_fmt
0 commit comments