|
@@ -217,6 +217,17 @@ enum spectre_v2_mitigation {
|
|
SPECTRE_V2_IBRS,
|
|
SPECTRE_V2_IBRS,
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+/*
|
|
|
|
+ * The Intel specification for the SPEC_CTRL MSR requires that we
|
|
|
|
+ * preserve any already set reserved bits at boot time (e.g. for
|
|
|
|
+ * future additions that this kernel is not currently aware of).
|
|
|
|
+ * We then set any additional mitigation bits that we want
|
|
|
|
+ * ourselves and always use this as the base for SPEC_CTRL.
|
|
|
|
+ * We also use this when handling guest entry/exit as below.
|
|
|
|
+ */
|
|
|
|
+extern void x86_spec_ctrl_set(u64);
|
|
|
|
+extern u64 x86_spec_ctrl_get_default(void);
|
|
|
|
+
|
|
extern char __indirect_thunk_start[];
|
|
extern char __indirect_thunk_start[];
|
|
extern char __indirect_thunk_end[];
|
|
extern char __indirect_thunk_end[];
|
|
|
|
|
|
@@ -254,8 +265,9 @@ void alternative_msr_write(unsigned int msr, u64 val, unsigned int feature)
|
|
|
|
|
|
static inline void indirect_branch_prediction_barrier(void)
|
|
static inline void indirect_branch_prediction_barrier(void)
|
|
{
|
|
{
|
|
- alternative_msr_write(MSR_IA32_PRED_CMD, PRED_CMD_IBPB,
|
|
|
|
- X86_FEATURE_USE_IBPB);
|
|
|
|
|
|
+ u64 val = PRED_CMD_IBPB;
|
|
|
|
+
|
|
|
|
+ alternative_msr_write(MSR_IA32_PRED_CMD, val, X86_FEATURE_USE_IBPB);
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -266,14 +278,18 @@ static inline void indirect_branch_prediction_barrier(void)
|
|
*/
|
|
*/
|
|
#define firmware_restrict_branch_speculation_start() \
|
|
#define firmware_restrict_branch_speculation_start() \
|
|
do { \
|
|
do { \
|
|
|
|
+ u64 val = x86_spec_ctrl_get_default() | SPEC_CTRL_IBRS; \
|
|
|
|
+ \
|
|
preempt_disable(); \
|
|
preempt_disable(); \
|
|
- alternative_msr_write(MSR_IA32_SPEC_CTRL, SPEC_CTRL_IBRS, \
|
|
|
|
|
|
+ alternative_msr_write(MSR_IA32_SPEC_CTRL, val, \
|
|
X86_FEATURE_USE_IBRS_FW); \
|
|
X86_FEATURE_USE_IBRS_FW); \
|
|
} while (0)
|
|
} while (0)
|
|
|
|
|
|
#define firmware_restrict_branch_speculation_end() \
|
|
#define firmware_restrict_branch_speculation_end() \
|
|
do { \
|
|
do { \
|
|
- alternative_msr_write(MSR_IA32_SPEC_CTRL, 0, \
|
|
|
|
|
|
+ u64 val = x86_spec_ctrl_get_default(); \
|
|
|
|
+ \
|
|
|
|
+ alternative_msr_write(MSR_IA32_SPEC_CTRL, val, \
|
|
X86_FEATURE_USE_IBRS_FW); \
|
|
X86_FEATURE_USE_IBRS_FW); \
|
|
preempt_enable(); \
|
|
preempt_enable(); \
|
|
} while (0)
|
|
} while (0)
|