Skip to content

Commit f52ea6c

Browse files
pa1guptasuryasaimadhu
authored andcommitted
x86/speculation: Add a common function for MD_CLEAR mitigation update
Processor MMIO Stale Data mitigation uses similar mitigation as MDS and TAA. In preparation for adding its mitigation, add a common function to update all mitigations that depend on MD_CLEAR. [ bp: Add a newline in md_clear_update_mitigation() to separate statements better. ] Signed-off-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com> Signed-off-by: Borislav Petkov <bp@suse.de>
1 parent 5180218 commit f52ea6c

1 file changed

Lines changed: 33 additions & 26 deletions

File tree

arch/x86/kernel/cpu/bugs.c

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static void __init spectre_v2_select_mitigation(void);
4141
static void __init ssb_select_mitigation(void);
4242
static void __init l1tf_select_mitigation(void);
4343
static void __init mds_select_mitigation(void);
44-
static void __init mds_print_mitigation(void);
44+
static void __init md_clear_update_mitigation(void);
4545
static void __init taa_select_mitigation(void);
4646
static void __init srbds_select_mitigation(void);
4747
static void __init l1d_flush_select_mitigation(void);
@@ -123,10 +123,10 @@ void __init check_bugs(void)
123123
l1d_flush_select_mitigation();
124124

125125
/*
126-
* As MDS and TAA mitigations are inter-related, print MDS
127-
* mitigation until after TAA mitigation selection is done.
126+
* As MDS and TAA mitigations are inter-related, update and print their
127+
* mitigation after TAA mitigation selection is done.
128128
*/
129-
mds_print_mitigation();
129+
md_clear_update_mitigation();
130130

131131
arch_smt_update();
132132

@@ -267,14 +267,6 @@ static void __init mds_select_mitigation(void)
267267
}
268268
}
269269

270-
static void __init mds_print_mitigation(void)
271-
{
272-
if (!boot_cpu_has_bug(X86_BUG_MDS) || cpu_mitigations_off())
273-
return;
274-
275-
pr_info("%s\n", mds_strings[mds_mitigation]);
276-
}
277-
278270
static int __init mds_cmdline(char *str)
279271
{
280272
if (!boot_cpu_has_bug(X86_BUG_MDS))
@@ -329,7 +321,7 @@ static void __init taa_select_mitigation(void)
329321
/* TSX previously disabled by tsx=off */
330322
if (!boot_cpu_has(X86_FEATURE_RTM)) {
331323
taa_mitigation = TAA_MITIGATION_TSX_DISABLED;
332-
goto out;
324+
return;
333325
}
334326

335327
if (cpu_mitigations_off()) {
@@ -343,7 +335,7 @@ static void __init taa_select_mitigation(void)
343335
*/
344336
if (taa_mitigation == TAA_MITIGATION_OFF &&
345337
mds_mitigation == MDS_MITIGATION_OFF)
346-
goto out;
338+
return;
347339

348340
if (boot_cpu_has(X86_FEATURE_MD_CLEAR))
349341
taa_mitigation = TAA_MITIGATION_VERW;
@@ -375,18 +367,6 @@ static void __init taa_select_mitigation(void)
375367

376368
if (taa_nosmt || cpu_mitigations_auto_nosmt())
377369
cpu_smt_disable(false);
378-
379-
/*
380-
* Update MDS mitigation, if necessary, as the mds_user_clear is
381-
* now enabled for TAA mitigation.
382-
*/
383-
if (mds_mitigation == MDS_MITIGATION_OFF &&
384-
boot_cpu_has_bug(X86_BUG_MDS)) {
385-
mds_mitigation = MDS_MITIGATION_FULL;
386-
mds_select_mitigation();
387-
}
388-
out:
389-
pr_info("%s\n", taa_strings[taa_mitigation]);
390370
}
391371

392372
static int __init tsx_async_abort_parse_cmdline(char *str)
@@ -410,6 +390,33 @@ static int __init tsx_async_abort_parse_cmdline(char *str)
410390
}
411391
early_param("tsx_async_abort", tsx_async_abort_parse_cmdline);
412392

393+
#undef pr_fmt
394+
#define pr_fmt(fmt) "" fmt
395+
396+
static void __init md_clear_update_mitigation(void)
397+
{
398+
if (cpu_mitigations_off())
399+
return;
400+
401+
if (!static_key_enabled(&mds_user_clear))
402+
goto out;
403+
404+
/*
405+
* mds_user_clear is now enabled. Update MDS mitigation, if
406+
* necessary.
407+
*/
408+
if (mds_mitigation == MDS_MITIGATION_OFF &&
409+
boot_cpu_has_bug(X86_BUG_MDS)) {
410+
mds_mitigation = MDS_MITIGATION_FULL;
411+
mds_select_mitigation();
412+
}
413+
out:
414+
if (boot_cpu_has_bug(X86_BUG_MDS))
415+
pr_info("MDS: %s\n", mds_strings[mds_mitigation]);
416+
if (boot_cpu_has_bug(X86_BUG_TAA))
417+
pr_info("TAA: %s\n", taa_strings[taa_mitigation]);
418+
}
419+
413420
#undef pr_fmt
414421
#define pr_fmt(fmt) "SRBDS: " fmt
415422

0 commit comments

Comments
 (0)