From: William Roche Date: Sat, 16 Feb 2019 01:06:17 +0000 (-0500) Subject: x86/speculation: Dynamic enable and disable of RSB stuffing with IBRS&!SMEP X-Git-Tag: v4.1.12-124.31.3~89 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=01526ef58652f1dc731c619e7c58e9fc3854edf2;p=users%2Fjedix%2Flinux-maple.git x86/speculation: Dynamic enable and disable of RSB stuffing with IBRS&!SMEP As IBRS is a dynamic feature, RSB overwrite needs to also be dynamically activated and disabled with IBRS (if SMEP is not available). Signed-off-by: William Roche Co-developed-by: Alexandre Chartre Signed-off-by: Alexandre Chartre Reviewed-by: Darren Kenny Reviewed-by: Boris Ostrovsky Reviewed-by: Alejandro Jimenez (cherry picked from commit fe61cd8181780903b2e092e2079ee09a6eb733d9) Orabug: 29660924 Signed-off-by: William Roche Reviewed-by: Darren Kenny Acked-by: Boris Ostrovsky Signed-off-by: Brian Maly Conflicts: arch/x86/kernel/cpu/bugs.c arch/x86/kernel/cpu/spec_ctrl.c bugs.c vs bugs_64.c in UEK4 spec_ctrl.c code still in bugs_64.c on UEK4 Signed-off-by: Brian Maly --- diff --git a/arch/x86/kernel/cpu/bugs_64.c b/arch/x86/kernel/cpu/bugs_64.c index 5c27c37ee36b..688b3a8f2d59 100644 --- a/arch/x86/kernel/cpu/bugs_64.c +++ b/arch/x86/kernel/cpu/bugs_64.c @@ -573,9 +573,14 @@ void change_spectre_v2_mitigation(enum spectre_v2_mitigation_action action) if (eibrs_supported) spec_ctrl_flush_all_cpus(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_priv); + if (!boot_cpu_has(X86_FEATURE_SMEP)) { + /* IBRS without SMEP needs RSB overwrite */ + rsb_overwrite_enable(); + } } else { set_ibrs_disabled(); if (use_ibrs & SPEC_CTRL_IBRS_SUPPORTED) { + rsb_overwrite_disable(); spec_ctrl_flush_all_cpus(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base); } @@ -735,10 +740,13 @@ static void __init select_ibrs_variant(enum spectre_v2_mitigation *mode) static void disable_ibrs_and_friends(bool disable_ibpb) { set_ibrs_disabled(); - if (use_ibrs & SPEC_CTRL_IBRS_SUPPORTED) - /* Disable IBRS an all cpus */ + if (use_ibrs & SPEC_CTRL_IBRS_SUPPORTED) { + rsb_overwrite_disable(); + /* Disable IBRS on all cpus */ spec_ctrl_flush_all_cpus(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base & ~SPEC_CTRL_FEATURE_ENABLE_IBRS); + } + /* * We need to use IBPB with retpoline if it is available. * Also IBRS for firmware paths.