Skip to content

Commit 6449f5b

Browse files
pa1guptahansendc
authored andcommitted
x86/bugs: Move cpu_bugs_smt_update() down
cpu_bugs_smt_update() uses global variables from different mitigations. For SMT updates it can't currently use vmscape_mitigation that is defined after it. Since cpu_bugs_smt_update() depends on many other mitigations, move it after all mitigations are defined. With that, it can use vmscape_mitigation in a moment. No functional change. Signed-off-by: Pawan Gupta <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Reviewed-by: Dave Hansen <[email protected]>
1 parent 556c1ad commit 6449f5b

File tree

1 file changed

+83
-82
lines changed

1 file changed

+83
-82
lines changed

arch/x86/kernel/cpu/bugs.c

Lines changed: 83 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -2551,88 +2551,6 @@ static void update_mds_branch_idle(void)
25512551
}
25522552
}
25532553

2554-
#define MDS_MSG_SMT "MDS CPU bug present and SMT on, data leak possible. See https://www.kernel.org/doc/html/latest/admin-guide/hw-vuln/mds.html for more details.\n"
2555-
#define TAA_MSG_SMT "TAA CPU bug present and SMT on, data leak possible. See https://www.kernel.org/doc/html/latest/admin-guide/hw-vuln/tsx_async_abort.html for more details.\n"
2556-
#define MMIO_MSG_SMT "MMIO Stale Data CPU bug present and SMT on, data leak possible. See https://www.kernel.org/doc/html/latest/admin-guide/hw-vuln/processor_mmio_stale_data.html for more details.\n"
2557-
2558-
void cpu_bugs_smt_update(void)
2559-
{
2560-
mutex_lock(&spec_ctrl_mutex);
2561-
2562-
if (sched_smt_active() && unprivileged_ebpf_enabled() &&
2563-
spectre_v2_enabled == SPECTRE_V2_EIBRS_LFENCE)
2564-
pr_warn_once(SPECTRE_V2_EIBRS_LFENCE_EBPF_SMT_MSG);
2565-
2566-
switch (spectre_v2_user_stibp) {
2567-
case SPECTRE_V2_USER_NONE:
2568-
break;
2569-
case SPECTRE_V2_USER_STRICT:
2570-
case SPECTRE_V2_USER_STRICT_PREFERRED:
2571-
update_stibp_strict();
2572-
break;
2573-
case SPECTRE_V2_USER_PRCTL:
2574-
case SPECTRE_V2_USER_SECCOMP:
2575-
update_indir_branch_cond();
2576-
break;
2577-
}
2578-
2579-
switch (mds_mitigation) {
2580-
case MDS_MITIGATION_FULL:
2581-
case MDS_MITIGATION_AUTO:
2582-
case MDS_MITIGATION_VMWERV:
2583-
if (sched_smt_active() && !boot_cpu_has(X86_BUG_MSBDS_ONLY))
2584-
pr_warn_once(MDS_MSG_SMT);
2585-
update_mds_branch_idle();
2586-
break;
2587-
case MDS_MITIGATION_OFF:
2588-
break;
2589-
}
2590-
2591-
switch (taa_mitigation) {
2592-
case TAA_MITIGATION_VERW:
2593-
case TAA_MITIGATION_AUTO:
2594-
case TAA_MITIGATION_UCODE_NEEDED:
2595-
if (sched_smt_active())
2596-
pr_warn_once(TAA_MSG_SMT);
2597-
break;
2598-
case TAA_MITIGATION_TSX_DISABLED:
2599-
case TAA_MITIGATION_OFF:
2600-
break;
2601-
}
2602-
2603-
switch (mmio_mitigation) {
2604-
case MMIO_MITIGATION_VERW:
2605-
case MMIO_MITIGATION_AUTO:
2606-
case MMIO_MITIGATION_UCODE_NEEDED:
2607-
if (sched_smt_active())
2608-
pr_warn_once(MMIO_MSG_SMT);
2609-
break;
2610-
case MMIO_MITIGATION_OFF:
2611-
break;
2612-
}
2613-
2614-
switch (tsa_mitigation) {
2615-
case TSA_MITIGATION_USER_KERNEL:
2616-
case TSA_MITIGATION_VM:
2617-
case TSA_MITIGATION_AUTO:
2618-
case TSA_MITIGATION_FULL:
2619-
/*
2620-
* TSA-SQ can potentially lead to info leakage between
2621-
* SMT threads.
2622-
*/
2623-
if (sched_smt_active())
2624-
static_branch_enable(&cpu_buf_idle_clear);
2625-
else
2626-
static_branch_disable(&cpu_buf_idle_clear);
2627-
break;
2628-
case TSA_MITIGATION_NONE:
2629-
case TSA_MITIGATION_UCODE_NEEDED:
2630-
break;
2631-
}
2632-
2633-
mutex_unlock(&spec_ctrl_mutex);
2634-
}
2635-
26362554
#undef pr_fmt
26372555
#define pr_fmt(fmt) "Speculative Store Bypass: " fmt
26382556

@@ -3402,6 +3320,89 @@ static void __init vmscape_apply_mitigation(void)
34023320
#undef pr_fmt
34033321
#define pr_fmt(fmt) fmt
34043322

3323+
#define MDS_MSG_SMT "MDS CPU bug present and SMT on, data leak possible. See https://www.kernel.org/doc/html/latest/admin-guide/hw-vuln/mds.html for more details.\n"
3324+
#define TAA_MSG_SMT "TAA CPU bug present and SMT on, data leak possible. See https://www.kernel.org/doc/html/latest/admin-guide/hw-vuln/tsx_async_abort.html for more details.\n"
3325+
#define MMIO_MSG_SMT "MMIO Stale Data CPU bug present and SMT on, data leak possible. See https://www.kernel.org/doc/html/latest/admin-guide/hw-vuln/processor_mmio_stale_data.html for more details.\n"
3326+
#define VMSCAPE_MSG_SMT "VMSCAPE: SMT on, STIBP is required for full protection. See https://www.kernel.org/doc/html/latest/admin-guide/hw-vuln/vmscape.html for more details.\n"
3327+
3328+
void cpu_bugs_smt_update(void)
3329+
{
3330+
mutex_lock(&spec_ctrl_mutex);
3331+
3332+
if (sched_smt_active() && unprivileged_ebpf_enabled() &&
3333+
spectre_v2_enabled == SPECTRE_V2_EIBRS_LFENCE)
3334+
pr_warn_once(SPECTRE_V2_EIBRS_LFENCE_EBPF_SMT_MSG);
3335+
3336+
switch (spectre_v2_user_stibp) {
3337+
case SPECTRE_V2_USER_NONE:
3338+
break;
3339+
case SPECTRE_V2_USER_STRICT:
3340+
case SPECTRE_V2_USER_STRICT_PREFERRED:
3341+
update_stibp_strict();
3342+
break;
3343+
case SPECTRE_V2_USER_PRCTL:
3344+
case SPECTRE_V2_USER_SECCOMP:
3345+
update_indir_branch_cond();
3346+
break;
3347+
}
3348+
3349+
switch (mds_mitigation) {
3350+
case MDS_MITIGATION_FULL:
3351+
case MDS_MITIGATION_AUTO:
3352+
case MDS_MITIGATION_VMWERV:
3353+
if (sched_smt_active() && !boot_cpu_has(X86_BUG_MSBDS_ONLY))
3354+
pr_warn_once(MDS_MSG_SMT);
3355+
update_mds_branch_idle();
3356+
break;
3357+
case MDS_MITIGATION_OFF:
3358+
break;
3359+
}
3360+
3361+
switch (taa_mitigation) {
3362+
case TAA_MITIGATION_VERW:
3363+
case TAA_MITIGATION_AUTO:
3364+
case TAA_MITIGATION_UCODE_NEEDED:
3365+
if (sched_smt_active())
3366+
pr_warn_once(TAA_MSG_SMT);
3367+
break;
3368+
case TAA_MITIGATION_TSX_DISABLED:
3369+
case TAA_MITIGATION_OFF:
3370+
break;
3371+
}
3372+
3373+
switch (mmio_mitigation) {
3374+
case MMIO_MITIGATION_VERW:
3375+
case MMIO_MITIGATION_AUTO:
3376+
case MMIO_MITIGATION_UCODE_NEEDED:
3377+
if (sched_smt_active())
3378+
pr_warn_once(MMIO_MSG_SMT);
3379+
break;
3380+
case MMIO_MITIGATION_OFF:
3381+
break;
3382+
}
3383+
3384+
switch (tsa_mitigation) {
3385+
case TSA_MITIGATION_USER_KERNEL:
3386+
case TSA_MITIGATION_VM:
3387+
case TSA_MITIGATION_AUTO:
3388+
case TSA_MITIGATION_FULL:
3389+
/*
3390+
* TSA-SQ can potentially lead to info leakage between
3391+
* SMT threads.
3392+
*/
3393+
if (sched_smt_active())
3394+
static_branch_enable(&cpu_buf_idle_clear);
3395+
else
3396+
static_branch_disable(&cpu_buf_idle_clear);
3397+
break;
3398+
case TSA_MITIGATION_NONE:
3399+
case TSA_MITIGATION_UCODE_NEEDED:
3400+
break;
3401+
}
3402+
3403+
mutex_unlock(&spec_ctrl_mutex);
3404+
}
3405+
34053406
#ifdef CONFIG_SYSFS
34063407

34073408
#define L1TF_DEFAULT_MSG "Mitigation: PTE Inversion"

0 commit comments

Comments
 (0)