Intel and AMD use different cpuid bits for MSR_PRED_CMD IBPB
authorjsg <jsg@openbsd.org>
Mon, 12 Feb 2024 02:57:14 +0000 (02:57 +0000)
committerjsg <jsg@openbsd.org>
Mon, 12 Feb 2024 02:57:14 +0000 (02:57 +0000)
ok guenther@

sys/arch/amd64/amd64/cpu.c
sys/arch/amd64/amd64/vmm_machdep.c

index c89099a..37da9dc 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: cpu.c,v 1.179 2024/02/12 01:18:17 guenther Exp $      */
+/*     $OpenBSD: cpu.c,v 1.180 2024/02/12 02:57:14 jsg Exp $   */
 /* $NetBSD: cpu.c,v 1.1 2003/04/26 18:39:26 fvdl Exp $ */
 
 /*-
@@ -188,7 +188,7 @@ replacemeltdown(void)
 {
        static int replacedone = 0;
        struct cpu_info *ci = &cpu_info_primary;
-       int swapgs_vuln = 0, ibrs = 0, s;
+       int swapgs_vuln = 0, ibrs = 0, s, ibpb = 0;
 
        if (strcmp(cpu_vendor, "GenuineIntel") == 0) {
                int family = ci->ci_family;
@@ -211,6 +211,8 @@ replacemeltdown(void)
                } else if (ci->ci_feature_sefflags_edx & SEFF0EDX_IBRS) {
                        ibrs = 1;
                }
+               if (ci->ci_feature_sefflags_edx & SEFF0EDX_IBRS)
+                       ibpb = 1;
         } else if (strcmp(cpu_vendor, "AuthenticAMD") == 0 &&
             ci->ci_pnfeatset >= 0x80000008) {
                if (ci->ci_feature_amdspec_ebx & CPUIDEBX_IBRS_ALWAYSON) {
@@ -219,6 +221,8 @@ replacemeltdown(void)
                    (ci->ci_feature_amdspec_ebx & CPUIDEBX_IBRS_PREF)) {
                        ibrs = 1;
                }
+               if (ci->ci_feature_amdspec_ebx & CPUIDEBX_IBPB)
+                       ibpb = 1;
        }
 
        /* Enhanced IBRS: turn it on once on each CPU and don't touch again */
@@ -232,7 +236,7 @@ replacemeltdown(void)
        s = splhigh();
 
        /* If we don't have IBRS/IBPB, then don't use IBPB */
-       if ((ci->ci_feature_sefflags_edx & SEFF0EDX_IBRS) == 0)
+       if (ibpb == 0)
                codepatch_nop(CPTAG_IBPB_NOP);
 
        if (ibrs == 2 || (ci->ci_feature_sefflags_edx & SEFF0EDX_IBT)) {
index ccc3c80..7cc3759 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: vmm_machdep.c,v 1.17 2024/02/12 01:18:17 guenther Exp $ */
+/* $OpenBSD: vmm_machdep.c,v 1.18 2024/02/12 02:57:14 jsg Exp $ */
 /*
  * Copyright (c) 2014 Mike Larkin <mlarkin@openbsd.org>
  *
@@ -6513,7 +6513,7 @@ vcpu_run_svm(struct vcpu *vcpu, struct vm_run_params *vrp)
                 * then use it to prevent cross-VM branch-target injection.
                 */
                if (ci->ci_guest_vcpu != vcpu &&
-                   (ci->ci_feature_sefflags_edx & SEFF0EDX_IBRS)) {
+                   (ci->ci_feature_amdspec_ebx & CPUIDEBX_IBPB)) {
                        wrmsr(MSR_PRED_CMD, PRED_CMD_IBPB);
                        ci->ci_guest_vcpu = vcpu;
                }