@@ -113,6 +113,10 @@ DEFINE_STATIC_KEY_FALSE(switch_mm_cond_ibpb);
113
113
/* Control unconditional IBPB in switch_mm() */
114
114
DEFINE_STATIC_KEY_FALSE (switch_mm_always_ibpb );
115
115
116
+ /* Control IBPB on vCPU load */
117
+ DEFINE_STATIC_KEY_FALSE (switch_vcpu_ibpb );
118
+ EXPORT_SYMBOL_GPL (switch_vcpu_ibpb );
119
+
116
120
/* Control MDS CPU buffer clear before idling (halt, mwait) */
117
121
DEFINE_STATIC_KEY_FALSE (mds_idle_clear );
118
122
EXPORT_SYMBOL_GPL (mds_idle_clear );
@@ -234,7 +238,7 @@ static void x86_amd_ssb_disable(void)
234
238
235
239
/* Default mitigation for MDS-affected CPUs */
236
240
static 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 ;
238
242
static bool mds_nosmt __ro_after_init = false;
239
243
240
244
static const char * const mds_strings [] = {
@@ -243,13 +247,50 @@ static const char * const mds_strings[] = {
243
247
[MDS_MITIGATION_VMWERV ] = "Vulnerable: Clear CPU buffers attempted, no microcode" ,
244
248
};
245
249
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
+
246
284
static void __init mds_select_mitigation (void )
247
285
{
248
286
if (!boot_cpu_has_bug (X86_BUG_MDS ) || cpu_mitigations_off ()) {
249
287
mds_mitigation = MDS_MITIGATION_OFF ;
250
288
return ;
251
289
}
252
290
291
+ if (mds_mitigation == MDS_MITIGATION_AUTO )
292
+ mds_mitigation = MDS_MITIGATION_FULL ;
293
+
253
294
if (mds_mitigation == MDS_MITIGATION_FULL ) {
254
295
if (!boot_cpu_has (X86_FEATURE_MD_CLEAR ))
255
296
mds_mitigation = MDS_MITIGATION_VMWERV ;
@@ -286,16 +327,6 @@ early_param("mds", mds_cmdline);
286
327
#undef pr_fmt
287
328
#define pr_fmt (fmt ) "TAA: " fmt
288
329
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 ;
299
330
static bool taa_nosmt __ro_after_init ;
300
331
301
332
static const char * const taa_strings [] = {
@@ -386,15 +417,6 @@ early_param("tsx_async_abort", tsx_async_abort_parse_cmdline);
386
417
#undef pr_fmt
387
418
#define pr_fmt (fmt ) "MMIO Stale Data: " fmt
388
419
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 ;
398
420
static bool mmio_nosmt __ro_after_init = false;
399
421
400
422
static const char * const mmio_strings [] = {
@@ -483,16 +505,6 @@ early_param("mmio_stale_data", mmio_stale_data_parse_cmdline);
483
505
#undef pr_fmt
484
506
#define pr_fmt (fmt ) "Register File Data Sampling: " fmt
485
507
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
-
496
508
static const char * const rfds_strings [] = {
497
509
[RFDS_MITIGATION_OFF ] = "Vulnerable" ,
498
510
[RFDS_MITIGATION_VERW ] = "Mitigation: Clear Register File" ,
@@ -508,6 +520,9 @@ static void __init rfds_select_mitigation(void)
508
520
if (rfds_mitigation == RFDS_MITIGATION_OFF )
509
521
return ;
510
522
523
+ if (rfds_mitigation == RFDS_MITIGATION_AUTO )
524
+ rfds_mitigation = RFDS_MITIGATION_VERW ;
525
+
511
526
if (x86_arch_cap_msr & ARCH_CAP_RFDS_CLEAR )
512
527
setup_force_cpu_cap (X86_FEATURE_CLEAR_CPU_BUF );
513
528
else
@@ -1293,9 +1308,13 @@ static __ro_after_init enum spectre_v2_mitigation_cmd spectre_v2_cmd;
1293
1308
static enum spectre_v2_user_cmd __init
1294
1309
spectre_v2_parse_user_cmdline (void )
1295
1310
{
1311
+ enum spectre_v2_user_cmd mode ;
1296
1312
char arg [20 ];
1297
1313
int ret , i ;
1298
1314
1315
+ mode = IS_ENABLED (CONFIG_MITIGATION_SPECTRE_V2 ) ?
1316
+ SPECTRE_V2_USER_CMD_AUTO : SPECTRE_V2_USER_CMD_NONE ;
1317
+
1299
1318
switch (spectre_v2_cmd ) {
1300
1319
case SPECTRE_V2_CMD_NONE :
1301
1320
return SPECTRE_V2_USER_CMD_NONE ;
@@ -1308,7 +1327,7 @@ spectre_v2_parse_user_cmdline(void)
1308
1327
ret = cmdline_find_option (boot_command_line , "spectre_v2_user" ,
1309
1328
arg , sizeof (arg ));
1310
1329
if (ret < 0 )
1311
- return SPECTRE_V2_USER_CMD_AUTO ;
1330
+ return mode ;
1312
1331
1313
1332
for (i = 0 ; i < ARRAY_SIZE (v2_user_options ); i ++ ) {
1314
1333
if (match_option (arg , ret , v2_user_options [i ].option )) {
@@ -1318,8 +1337,8 @@ spectre_v2_parse_user_cmdline(void)
1318
1337
}
1319
1338
}
1320
1339
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 ;
1323
1342
}
1324
1343
1325
1344
static inline bool spectre_v2_in_ibrs_mode (enum spectre_v2_mitigation mode )
@@ -1331,16 +1350,11 @@ static void __init
1331
1350
spectre_v2_user_select_mitigation (void )
1332
1351
{
1333
1352
enum spectre_v2_user_mitigation mode = SPECTRE_V2_USER_NONE ;
1334
- bool smt_possible = IS_ENABLED (CONFIG_SMP );
1335
1353
enum spectre_v2_user_cmd cmd ;
1336
1354
1337
1355
if (!boot_cpu_has (X86_FEATURE_IBPB ) && !boot_cpu_has (X86_FEATURE_STIBP ))
1338
1356
return ;
1339
1357
1340
- if (cpu_smt_control == CPU_SMT_FORCE_DISABLED ||
1341
- cpu_smt_control == CPU_SMT_NOT_SUPPORTED )
1342
- smt_possible = false;
1343
-
1344
1358
cmd = spectre_v2_parse_user_cmdline ();
1345
1359
switch (cmd ) {
1346
1360
case SPECTRE_V2_USER_CMD_NONE :
@@ -1364,7 +1378,7 @@ spectre_v2_user_select_mitigation(void)
1364
1378
1365
1379
/* Initialize Indirect Branch Prediction Barrier */
1366
1380
if (boot_cpu_has (X86_FEATURE_IBPB )) {
1367
- setup_force_cpu_cap ( X86_FEATURE_USE_IBPB );
1381
+ static_branch_enable ( & switch_vcpu_ibpb );
1368
1382
1369
1383
spectre_v2_user_ibpb = mode ;
1370
1384
switch (cmd ) {
@@ -1401,7 +1415,7 @@ spectre_v2_user_select_mitigation(void)
1401
1415
* so allow for STIBP to be selected in those cases.
1402
1416
*/
1403
1417
if (!boot_cpu_has (X86_FEATURE_STIBP ) ||
1404
- !smt_possible ||
1418
+ !cpu_smt_possible () ||
1405
1419
(spectre_v2_in_eibrs_mode (spectre_v2_enabled ) &&
1406
1420
!boot_cpu_has (X86_FEATURE_AUTOIBRS )))
1407
1421
return ;
@@ -1973,6 +1987,7 @@ void cpu_bugs_smt_update(void)
1973
1987
1974
1988
switch (mds_mitigation ) {
1975
1989
case MDS_MITIGATION_FULL :
1990
+ case MDS_MITIGATION_AUTO :
1976
1991
case MDS_MITIGATION_VMWERV :
1977
1992
if (sched_smt_active () && !boot_cpu_has (X86_BUG_MSBDS_ONLY ))
1978
1993
pr_warn_once (MDS_MSG_SMT );
@@ -1984,6 +1999,7 @@ void cpu_bugs_smt_update(void)
1984
1999
1985
2000
switch (taa_mitigation ) {
1986
2001
case TAA_MITIGATION_VERW :
2002
+ case TAA_MITIGATION_AUTO :
1987
2003
case TAA_MITIGATION_UCODE_NEEDED :
1988
2004
if (sched_smt_active ())
1989
2005
pr_warn_once (TAA_MSG_SMT );
@@ -1995,6 +2011,7 @@ void cpu_bugs_smt_update(void)
1995
2011
1996
2012
switch (mmio_mitigation ) {
1997
2013
case MMIO_MITIGATION_VERW :
2014
+ case MMIO_MITIGATION_AUTO :
1998
2015
case MMIO_MITIGATION_UCODE_NEEDED :
1999
2016
if (sched_smt_active ())
2000
2017
pr_warn_once (MMIO_MSG_SMT );
@@ -2522,6 +2539,7 @@ enum srso_mitigation {
2522
2539
SRSO_MITIGATION_SAFE_RET ,
2523
2540
SRSO_MITIGATION_IBPB ,
2524
2541
SRSO_MITIGATION_IBPB_ON_VMEXIT ,
2542
+ SRSO_MITIGATION_BP_SPEC_REDUCE ,
2525
2543
};
2526
2544
2527
2545
enum srso_mitigation_cmd {
@@ -2539,7 +2557,8 @@ static const char * const srso_strings[] = {
2539
2557
[SRSO_MITIGATION_MICROCODE ] = "Vulnerable: Microcode, no safe RET" ,
2540
2558
[SRSO_MITIGATION_SAFE_RET ] = "Mitigation: Safe RET" ,
2541
2559
[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"
2543
2562
};
2544
2563
2545
2564
static enum srso_mitigation srso_mitigation __ro_after_init = SRSO_MITIGATION_NONE ;
@@ -2578,7 +2597,7 @@ static void __init srso_select_mitigation(void)
2578
2597
srso_cmd == SRSO_CMD_OFF ) {
2579
2598
if (boot_cpu_has (X86_FEATURE_SBPB ))
2580
2599
x86_pred_cmd = PRED_CMD_SBPB ;
2581
- return ;
2600
+ goto out ;
2582
2601
}
2583
2602
2584
2603
if (has_microcode ) {
@@ -2590,7 +2609,7 @@ static void __init srso_select_mitigation(void)
2590
2609
*/
2591
2610
if (boot_cpu_data .x86 < 0x19 && !cpu_smt_possible ()) {
2592
2611
setup_force_cpu_cap (X86_FEATURE_SRSO_NO );
2593
- return ;
2612
+ goto out ;
2594
2613
}
2595
2614
2596
2615
if (retbleed_mitigation == RETBLEED_MITIGATION_IBPB ) {
@@ -2670,6 +2689,12 @@ static void __init srso_select_mitigation(void)
2670
2689
2671
2690
ibpb_on_vmexit :
2672
2691
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
+
2673
2698
if (IS_ENABLED (CONFIG_MITIGATION_IBPB_ENTRY )) {
2674
2699
if (has_microcode ) {
2675
2700
setup_force_cpu_cap (X86_FEATURE_IBPB_ON_VMEXIT );
@@ -2691,7 +2716,15 @@ static void __init srso_select_mitigation(void)
2691
2716
}
2692
2717
2693
2718
out :
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 ]);
2695
2728
}
2696
2729
2697
2730
#undef pr_fmt
0 commit comments