During early boot, spectre_v2_check_boottime_disable() sets the
RETPOLINE_AMD feature for AMD hardware (before init_amd() is called).
Since the RETPOLINE_AMD feature uses LFENCE to perform speculation
control, it can only be used if LFENCE is serializing.  Clear the
RETPOLINE_AMD feature if the MSR write to make LFENCE serializing
is not successful.

Signed-off-by: Tom Lendacky <[email protected]>
---
 arch/x86/kernel/cpu/amd.c |    4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
index ea831c8..8a0076b 100644
--- a/arch/x86/kernel/cpu/amd.c
+++ b/arch/x86/kernel/cpu/amd.c
@@ -13,6 +13,7 @@
 #include <asm/smp.h>
 #include <asm/pci-direct.h>
 #include <asm/delay.h>
+#include <asm/nospec-branch.h>
 
 #ifdef CONFIG_X86_64
 # include <asm/mmconfig.h>
@@ -854,6 +855,9 @@ static void init_amd(struct cpuinfo_x86 *c)
                } else {
                        /* MFENCE stops RDTSC speculation */
                        set_cpu_cap(c, X86_FEATURE_MFENCE_RDTSC);
+
+                       /* Don't use the LFENCE-based retpoline support */
+                       retpoline_amd_disable();
                }
        }
 

Reply via email to