]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - arch/x86/kernel/cpu/bugs.c
x86/speculation: Prepare for conditional IBPB in switch_mm()
[mirror_ubuntu-bionic-kernel.git] / arch / x86 / kernel / cpu / bugs.c
index c5aa17a5c9ddc66f0c4a5023e2111fe18b3263d9..3a27b2e9b695a5036b6b5603f3d24c8529d7ffca 100644 (file)
@@ -55,6 +55,10 @@ u64 __ro_after_init x86_amd_ls_cfg_ssbd_mask;
 
 /* Control conditional STIPB in switch_to() */
 DEFINE_STATIC_KEY_FALSE(switch_to_cond_stibp);
+/* Control conditional IBPB in switch_mm() */
+DEFINE_STATIC_KEY_FALSE(switch_mm_cond_ibpb);
+/* Control unconditional IBPB in switch_mm() */
+DEFINE_STATIC_KEY_FALSE(switch_mm_always_ibpb);
 
 void __init check_bugs(void)
 {
@@ -330,7 +334,17 @@ spectre_v2_user_select_mitigation(enum spectre_v2_mitigation_cmd v2_cmd)
        /* Initialize Indirect Branch Prediction Barrier */
        if (boot_cpu_has(X86_FEATURE_IBPB)) {
                setup_force_cpu_cap(X86_FEATURE_USE_IBPB);
-               pr_info("Spectre v2 mitigation: Enabling Indirect Branch Prediction Barrier\n");
+
+               switch (mode) {
+               case SPECTRE_V2_USER_STRICT:
+                       static_branch_enable(&switch_mm_always_ibpb);
+                       break;
+               default:
+                       break;
+               }
+
+               pr_info("mitigation: Enabling %s Indirect Branch Prediction Barrier\n",
+                       mode == SPECTRE_V2_USER_STRICT ? "always-on" : "conditional");
        }
 
        /* If enhanced IBRS is enabled no STIPB required */
@@ -949,10 +963,15 @@ static char *stibp_state(void)
 
 static char *ibpb_state(void)
 {
-       if (boot_cpu_has(X86_FEATURE_USE_IBPB))
-               return ", IBPB";
-       else
-               return "";
+       if (boot_cpu_has(X86_FEATURE_IBPB)) {
+               switch (spectre_v2_user) {
+               case SPECTRE_V2_USER_NONE:
+                       return ", IBPB: disabled";
+               case SPECTRE_V2_USER_STRICT:
+                       return ", IBPB: always-on";
+               }
+       }
+       return "";
 }
 
 static ssize_t cpu_show_common(struct device *dev, struct device_attribute *attr,