Linux Patch 4
Subsystems (2)
PATCH 4/7 Linux Patch 4
x86/mdd/firmware calls: Save/Restore the MDD bit when using SPEC_CTRL
.. when we perform the IBRS calls for firmware calls we need to take into account the MD bit as well. This is a bit complicated in the assembler constructs as the value is no more a constant but a variable.
Signed-off-by Konrad Rzeszutek Wilk <[email protected]>
---
v3: s/md_v4/mdd/
v3.1: Add spec_ctrl_firmware to use only when going to SMI.
--- arch/x86/include/asm/nospec-branch.h | 12 ++++++++---- arch/x86/kernel/cpu/bugs.c | 3 +++ 2 files changed, 11 insertions(+), 4 deletions(-)
arch/x86/include/asm/nospec-branch.h +8 -4
@@ -226,6 +226,7 @@ enum md_mitigation {extern enum md_mitigation md_mode;extern u64 spec_ctrl_priv;extern u64 spec_ctrl_unpriv; +extern u64 spec_ctrl_firmware;static inline bool mdd_at_boot (void ) {
@@ -263,12 +264,13 @@ static inline void vmexit_fill_RSB(void) "movl $0, %%edx\n\t" \ "wrmsr", \ _feature) \ - : : [msr] "i" (_msr), [val] "i" (_val) \ + : : [msr] "i" (_msr), [val] "m" (_val) \ : "eax", "ecx", "edx", "memory") static inline void indirect_branch_prediction_barrier(void) { -alternative_msr_write (MSR_IA32_PRED_CMD ,PRED_CMD_IBPB , +u64 val =PRED_CMD_IBPB ; +alternative_msr_write (MSR_IA32_PRED_CMD , val,X86_FEATURE_USE_IBPB ); }
@@ -281,13 +283,15 @@ static inline void indirect_branch_prediction_barrier(void)#define firmware_restrict_branch_speculation_start () \ do { \ preempt_disable(); \ - alternative_msr_write(MSR_IA32_SPEC_CTRL, SPEC_CTRL_IBRS, \ + alternative_msr_write(MSR_IA32_SPEC_CTRL, \ + spec_ctrl_firmware, \ X86_FEATURE_USE_IBRS_FW); \ } while (0)#define firmware_restrict_branch_speculation_end () \ do { \ - alternative_msr_write(MSR_IA32_SPEC_CTRL, 0, \ + alternative_msr_write(MSR_IA32_SPEC_CTRL, \ + spec_ctrl_unpriv, \ X86_FEATURE_USE_IBRS_FW); \ preempt_enable(); \ } while (0)
arch/x86/kernel/cpu/bugs.c +3 -0
@@ -329,6 +329,9 @@ EXPORT_SYMBOL_GPL(spec_ctrl_priv);u64 spec_ctrl_unpriv;EXPORT_SYMBOL_GPL (spec_ctrl_unpriv); +/* When switching from higher to SMI privilege level. */ +u64 spec_ctrl_firmware =SPEC_CTRL_IBRS ; +/* The kernel command line selection */ enum md_mitigation_cmd {MD_CMD_NONE ,
Signature · 1 line
2.14.3