From: Andi Kleen <a...@linux.intel.com>

On Skylake we want additional protections against spectre_v2
over the normal RETPOLINE against underflowing return buffers.

On return buffer underflow the CPU could fall back to
the poisoned indirect branch predictor.

This patch adds a feature bit, only enabled on Skylake,
to enable additional return buffer underflow protections

This will be used in the next patches

Signed-off-by: Andi Kleen <a...@linux.intel.com>
---
 arch/x86/include/asm/cpufeatures.h | 1 +
 arch/x86/kernel/cpu/bugs.c         | 5 +++++
 2 files changed, 6 insertions(+)

diff --git a/arch/x86/include/asm/cpufeatures.h 
b/arch/x86/include/asm/cpufeatures.h
index 25b9375c1484..85108eb1876b 100644
--- a/arch/x86/include/asm/cpufeatures.h
+++ b/arch/x86/include/asm/cpufeatures.h
@@ -211,6 +211,7 @@
 
 #define X86_FEATURE_MBA                        ( 7*32+18) /* Memory Bandwidth 
Allocation */
 #define X86_FEATURE_RSB_CTXSW          ( 7*32+19) /* Fill RSB on context 
switches */
+#define X86_FEATURE_RSB_UNDERFLOW      ( 7*32+20) /* Avoid return stack 
underflows */
 
 /* Virtualization flags: Linux defined, word 8 */
 #define X86_FEATURE_TPR_SHADOW         ( 8*32+ 0) /* Intel TPR Shadow */
diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index 390b3dc3d438..68d449d51673 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -249,6 +249,11 @@ static void __init spectre_v2_select_mitigation(void)
                setup_force_cpu_cap(X86_FEATURE_RSB_CTXSW);
                pr_info("Filling RSB on context switch\n");
        }
+
+       if (is_skylake_era()) {
+               setup_force_cpu_cap(X86_FEATURE_RSB_UNDERFLOW);
+               pr_info("Enabling return buffer underflow protections");
+       }
 }
 
 #undef pr_fmt
-- 
2.14.3

Reply via email to