| Date | Thu, 24 Feb 2022 15:51:58 +0100 | From | Peter Zijlstra <> | 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); }
|