]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
x86/speculation: Use synthetic bits for IBRS/IBPB/STIBP
authorBorislav Petkov <bp@suse.de>
Wed, 2 May 2018 16:15:14 +0000 (18:15 +0200)
committerBen Hutchings <ben@decadent.org.uk>
Wed, 3 Oct 2018 03:09:45 +0000 (04:09 +0100)
commit e7c587da125291db39ddf1f49b18e5970adbac17 upstream.

Intel and AMD have different CPUID bits hence for those use synthetic bits
which get set on the respective vendor's in init_speculation_control(). So
that debacles like what the commit message of

  c65732e4f721 ("x86/cpu: Restore CPUID_8000_0008_EBX reload")

talks about don't happen anymore.

Signed-off-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Tested-by: Jörg Otte <jrg.otte@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Link: https://lkml.kernel.org/r/20180504161815.GG9257@pd.tnic
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[bwh: Backported to 3.16:
 - Use the next available bit numbers in CPU feature word 7
 - Adjust filename, context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
arch/x86/include/asm/cpufeature.h
arch/x86/kernel/cpu/common.c
arch/x86/kvm/cpuid.c
arch/x86/kvm/cpuid.h

index 3d76b767a0de04a6ab1952f3cf2723d3750b16ca..83367f35970cf7494fe95a1ea0fe137c27a321d4 100644 (file)
 #define X86_FEATURE_USE_IBRS_FW (7*32+13) /* "" Use IBRS during runtime firmware calls */
 #define X86_FEATURE_SPEC_STORE_BYPASS_DISABLE (7*32+14) /* "" Disable Speculative Store Bypass. */
 #define X86_FEATURE_AMD_SSBD   (7*32+15)  /* "" AMD SSBD implementation */
+#define X86_FEATURE_IBRS       (7*32+16) /* Indirect Branch Restricted Speculation */
+#define X86_FEATURE_IBPB       (7*32+17) /* Indirect Branch Prediction Barrier */
+#define X86_FEATURE_STIBP      (7*32+18) /* Single Thread Indirect Branch Predictors */
 
 #define X86_FEATURE_RETPOLINE  (7*32+29) /* "" Generic Retpoline mitigation for Spectre variant 2 */
 #define X86_FEATURE_RETPOLINE_AMD (7*32+30) /* "" AMD Retpoline mitigation for Spectre variant 2 */
 #define X86_FEATURE_SSBD               (10*32+31) /* Speculative Store Bypass Disable */
 
 /* AMD-defined CPU features, CPUID level 0x80000008 (EBX), word 11 */
-#define X86_FEATURE_IBPB               (11*32+12) /* Indirect Branch Prediction Barrier */
-#define X86_FEATURE_IBRS               (11*32+14) /* Indirect Branch Restricted Speculation */
-#define X86_FEATURE_STIBP              (11*32+15) /* Single Thread Indirect Branch Predictors */
+#define X86_FEATURE_AMD_IBPB           (11*32+12) /* Indirect Branch Prediction Barrier */
+#define X86_FEATURE_AMD_IBRS           (11*32+14) /* Indirect Branch Restricted Speculation */
+#define X86_FEATURE_AMD_STIBP          (11*32+15) /* Single Thread Indirect Branch Predictors */
 
 /*
  * BUG word(s)
index 77fd1abb21a88403914f4450ec1c19a75ef7c760..8b0738465c803d1b7386ff01cb486122a91c9de0 100644 (file)
@@ -690,17 +690,23 @@ static void init_speculation_control(struct cpuinfo_x86 *c)
         * and they also have a different bit for STIBP support. Also,
         * a hypervisor might have set the individual AMD bits even on
         * Intel CPUs, for finer-grained selection of what's available.
-        *
-        * We use the AMD bits in 0x8000_0008 EBX as the generic hardware
-        * features, which are visible in /proc/cpuinfo and used by the
-        * kernel. So set those accordingly from the Intel bits.
         */
        if (cpu_has(c, X86_FEATURE_SPEC_CTRL)) {
                set_cpu_cap(c, X86_FEATURE_IBRS);
                set_cpu_cap(c, X86_FEATURE_IBPB);
        }
+
        if (cpu_has(c, X86_FEATURE_INTEL_STIBP))
                set_cpu_cap(c, X86_FEATURE_STIBP);
+
+       if (cpu_has(c, X86_FEATURE_AMD_IBRS))
+               set_cpu_cap(c, X86_FEATURE_IBRS);
+
+       if (cpu_has(c, X86_FEATURE_AMD_IBPB))
+               set_cpu_cap(c, X86_FEATURE_IBPB);
+
+       if (cpu_has(c, X86_FEATURE_AMD_STIBP))
+               set_cpu_cap(c, X86_FEATURE_STIBP);
 }
 
 void get_cpu_cap(struct cpuinfo_x86 *c)
index 7037c70ee8447e9b1ad9b1de48ca92c1ae0a5f7c..a655fe39b6bc6c0574932fededad893c97d79db0 100644 (file)
@@ -302,7 +302,7 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
 
        /* cpuid 0x80000008.ebx */
        const u32 kvm_cpuid_8000_0008_ebx_x86_features =
-               F(IBPB) | F(IBRS);
+               F(AMD_IBPB) | F(AMD_IBRS);
 
        /* cpuid 0xC0000001.edx */
        const u32 kvm_supported_word5_x86_features =
@@ -525,10 +525,10 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
                entry->eax = g_phys_as | (virt_as << 8);
                entry->edx = 0;
                /* IBRS and IBPB aren't necessarily present in hardware cpuid */
-               if (boot_cpu_has(X86_FEATURE_IBPB))
-                       entry->ebx |= F(IBPB);
-               if (boot_cpu_has(X86_FEATURE_IBRS))
-                       entry->ebx |= F(IBRS);
+               if (boot_cpu_has(X86_FEATURE_AMD_IBPB))
+                       entry->ebx |= F(AMD_IBPB);
+               if (boot_cpu_has(X86_FEATURE_AMD_IBRS))
+                       entry->ebx |= F(AMD_IBRS);
                entry->ebx &= kvm_cpuid_8000_0008_ebx_x86_features;
                cpuid_mask(&entry->ebx, 11);
                break;
index 94deb677c90e98aca17709012a6b79571c73286f..872ecda3070d492a542378c0df066b7654681927 100644 (file)
@@ -109,7 +109,7 @@ static inline bool guest_cpuid_has_ibpb(struct kvm_vcpu *vcpu)
        struct kvm_cpuid_entry2 *best;
 
        best = kvm_find_cpuid_entry(vcpu, 0x80000008, 0);
-       if (best && (best->ebx & bit(X86_FEATURE_IBPB)))
+       if (best && (best->ebx & bit(X86_FEATURE_AMD_IBPB)))
                return true;
        best = kvm_find_cpuid_entry(vcpu, 7, 0);
        return best && (best->edx & bit(X86_FEATURE_SPEC_CTRL));
@@ -120,7 +120,7 @@ static inline bool guest_cpuid_has_spec_ctrl(struct kvm_vcpu *vcpu)
        struct kvm_cpuid_entry2 *best;
 
        best = kvm_find_cpuid_entry(vcpu, 0x80000008, 0);
-       if (best && (best->ebx & bit(X86_FEATURE_IBRS)))
+       if (best && (best->ebx & bit(X86_FEATURE_AMD_IBRS)))
                return true;
        best = kvm_find_cpuid_entry(vcpu, 7, 0);
        return best && (best->edx & (bit(X86_FEATURE_SPEC_CTRL) | bit(X86_FEATURE_SSBD)));