Skip to content

Commit 923ab9f

Browse files
pa1guptagregkh
authored andcommitted
x86/bugs: Move cpu_bugs_smt_update() down
Commit 6449f5b upstream. 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 <pawan.kumar.gupta@linux.intel.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Dave Hansen <dave.hansen@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 9c23a90 commit 923ab9f

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
@@ -2369,88 +2369,6 @@ static void update_mds_branch_idle(void)
23692369
}
23702370
}
23712371

2372-
#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"
2373-
#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"
2374-
#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"
2375-
2376-
void cpu_bugs_smt_update(void)
2377-
{
2378-
mutex_lock(&spec_ctrl_mutex);
2379-
2380-
if (sched_smt_active() && unprivileged_ebpf_enabled() &&
2381-
spectre_v2_enabled == SPECTRE_V2_EIBRS_LFENCE)
2382-
pr_warn_once(SPECTRE_V2_EIBRS_LFENCE_EBPF_SMT_MSG);
2383-
2384-
switch (spectre_v2_user_stibp) {
2385-
case SPECTRE_V2_USER_NONE:
2386-
break;
2387-
case SPECTRE_V2_USER_STRICT:
2388-
case SPECTRE_V2_USER_STRICT_PREFERRED:
2389-
update_stibp_strict();
2390-
break;
2391-
case SPECTRE_V2_USER_PRCTL:
2392-
case SPECTRE_V2_USER_SECCOMP:
2393-
update_indir_branch_cond();
2394-
break;
2395-
}
2396-
2397-
switch (mds_mitigation) {
2398-
case MDS_MITIGATION_FULL:
2399-
case MDS_MITIGATION_AUTO:
2400-
case MDS_MITIGATION_VMWERV:
2401-
if (sched_smt_active() && !boot_cpu_has(X86_BUG_MSBDS_ONLY))
2402-
pr_warn_once(MDS_MSG_SMT);
2403-
update_mds_branch_idle();
2404-
break;
2405-
case MDS_MITIGATION_OFF:
2406-
break;
2407-
}
2408-
2409-
switch (taa_mitigation) {
2410-
case TAA_MITIGATION_VERW:
2411-
case TAA_MITIGATION_AUTO:
2412-
case TAA_MITIGATION_UCODE_NEEDED:
2413-
if (sched_smt_active())
2414-
pr_warn_once(TAA_MSG_SMT);
2415-
break;
2416-
case TAA_MITIGATION_TSX_DISABLED:
2417-
case TAA_MITIGATION_OFF:
2418-
break;
2419-
}
2420-
2421-
switch (mmio_mitigation) {
2422-
case MMIO_MITIGATION_VERW:
2423-
case MMIO_MITIGATION_AUTO:
2424-
case MMIO_MITIGATION_UCODE_NEEDED:
2425-
if (sched_smt_active())
2426-
pr_warn_once(MMIO_MSG_SMT);
2427-
break;
2428-
case MMIO_MITIGATION_OFF:
2429-
break;
2430-
}
2431-
2432-
switch (tsa_mitigation) {
2433-
case TSA_MITIGATION_USER_KERNEL:
2434-
case TSA_MITIGATION_VM:
2435-
case TSA_MITIGATION_AUTO:
2436-
case TSA_MITIGATION_FULL:
2437-
/*
2438-
* TSA-SQ can potentially lead to info leakage between
2439-
* SMT threads.
2440-
*/
2441-
if (sched_smt_active())
2442-
static_branch_enable(&cpu_buf_idle_clear);
2443-
else
2444-
static_branch_disable(&cpu_buf_idle_clear);
2445-
break;
2446-
case TSA_MITIGATION_NONE:
2447-
case TSA_MITIGATION_UCODE_NEEDED:
2448-
break;
2449-
}
2450-
2451-
mutex_unlock(&spec_ctrl_mutex);
2452-
}
2453-
24542372
#undef pr_fmt
24552373
#define pr_fmt(fmt) "Speculative Store Bypass: " fmt
24562374

@@ -3225,6 +3143,89 @@ static void __init vmscape_apply_mitigation(void)
32253143
#undef pr_fmt
32263144
#define pr_fmt(fmt) fmt
32273145

3146+
#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"
3147+
#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"
3148+
#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"
3149+
#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"
3150+
3151+
void cpu_bugs_smt_update(void)
3152+
{
3153+
mutex_lock(&spec_ctrl_mutex);
3154+
3155+
if (sched_smt_active() && unprivileged_ebpf_enabled() &&
3156+
spectre_v2_enabled == SPECTRE_V2_EIBRS_LFENCE)
3157+
pr_warn_once(SPECTRE_V2_EIBRS_LFENCE_EBPF_SMT_MSG);
3158+
3159+
switch (spectre_v2_user_stibp) {
3160+
case SPECTRE_V2_USER_NONE:
3161+
break;
3162+
case SPECTRE_V2_USER_STRICT:
3163+
case SPECTRE_V2_USER_STRICT_PREFERRED:
3164+
update_stibp_strict();
3165+
break;
3166+
case SPECTRE_V2_USER_PRCTL:
3167+
case SPECTRE_V2_USER_SECCOMP:
3168+
update_indir_branch_cond();
3169+
break;
3170+
}
3171+
3172+
switch (mds_mitigation) {
3173+
case MDS_MITIGATION_FULL:
3174+
case MDS_MITIGATION_AUTO:
3175+
case MDS_MITIGATION_VMWERV:
3176+
if (sched_smt_active() && !boot_cpu_has(X86_BUG_MSBDS_ONLY))
3177+
pr_warn_once(MDS_MSG_SMT);
3178+
update_mds_branch_idle();
3179+
break;
3180+
case MDS_MITIGATION_OFF:
3181+
break;
3182+
}
3183+
3184+
switch (taa_mitigation) {
3185+
case TAA_MITIGATION_VERW:
3186+
case TAA_MITIGATION_AUTO:
3187+
case TAA_MITIGATION_UCODE_NEEDED:
3188+
if (sched_smt_active())
3189+
pr_warn_once(TAA_MSG_SMT);
3190+
break;
3191+
case TAA_MITIGATION_TSX_DISABLED:
3192+
case TAA_MITIGATION_OFF:
3193+
break;
3194+
}
3195+
3196+
switch (mmio_mitigation) {
3197+
case MMIO_MITIGATION_VERW:
3198+
case MMIO_MITIGATION_AUTO:
3199+
case MMIO_MITIGATION_UCODE_NEEDED:
3200+
if (sched_smt_active())
3201+
pr_warn_once(MMIO_MSG_SMT);
3202+
break;
3203+
case MMIO_MITIGATION_OFF:
3204+
break;
3205+
}
3206+
3207+
switch (tsa_mitigation) {
3208+
case TSA_MITIGATION_USER_KERNEL:
3209+
case TSA_MITIGATION_VM:
3210+
case TSA_MITIGATION_AUTO:
3211+
case TSA_MITIGATION_FULL:
3212+
/*
3213+
* TSA-SQ can potentially lead to info leakage between
3214+
* SMT threads.
3215+
*/
3216+
if (sched_smt_active())
3217+
static_branch_enable(&cpu_buf_idle_clear);
3218+
else
3219+
static_branch_disable(&cpu_buf_idle_clear);
3220+
break;
3221+
case TSA_MITIGATION_NONE:
3222+
case TSA_MITIGATION_UCODE_NEEDED:
3223+
break;
3224+
}
3225+
3226+
mutex_unlock(&spec_ctrl_mutex);
3227+
}
3228+
32283229
#ifdef CONFIG_SYSFS
32293230

32303231
#define L1TF_DEFAULT_MSG "Mitigation: PTE Inversion"

0 commit comments

Comments
 (0)