lkml.org 
[lkml]   [2022]   [Feb]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH v2 20/39] x86/bugs: Disable Retpoline when IBT
Retpoline and IBT are mutually exclusive. IBT relies on indirect
branches (JMP/CALL *%reg) while retpoline avoids them by design.

Demote to LFENCE on IBT enabled hardware.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
arch/x86/kernel/cpu/bugs.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)

--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -937,6 +937,11 @@ static void __init spectre_v2_select_mit
boot_cpu_data.x86_vendor == X86_VENDOR_HYGON) {
retpoline_amd:
if (!boot_cpu_has(X86_FEATURE_LFENCE_RDTSC)) {
+ if (HAS_KERNEL_IBT &&
+ boot_cpu_has(X86_FEATURE_IBT)) {
+ pr_err("Spectre mitigation: LFENCE not serializing, generic retpoline not available due to IBT, switching to none\n");
+ return;
+ }
pr_err("Spectre mitigation: LFENCE not serializing, switching to generic retpoline\n");
goto retpoline_generic;
}
@@ -945,6 +950,26 @@ static void __init spectre_v2_select_mit
setup_force_cpu_cap(X86_FEATURE_RETPOLINE);
} else {
retpoline_generic:
+ /*
+ * Full retpoline is incompatible with IBT, demote to LFENCE.
+ */
+ if (HAS_KERNEL_IBT &&
+ boot_cpu_has(X86_FEATURE_IBT)) {
+ switch (cmd) {
+ case SPECTRE_V2_CMD_FORCE:
+ case SPECTRE_V2_CMD_AUTO:
+ case SPECTRE_V2_CMD_RETPOLINE:
+ /* silent for auto select */
+ break;
+
+ default:
+ /* warn when 'demoting' an explicit selection */
+ pr_warn("Spectre mitigation: Switching to LFENCE due to IBT\n");
+ break;
+ }
+
+ goto retpoline_amd;
+ }
mode = SPECTRE_V2_RETPOLINE_GENERIC;
setup_force_cpu_cap(X86_FEATURE_RETPOLINE);
}

\
 
 \ /
  Last update: 2022-02-24 16:22    [W:0.957 / U:0.332 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site