All of lore.kernel.org
 help / color / mirror / Atom feed
* [MODERATED] [patch 4/8] [PATCH v1.3.1 4/7] Linux Patch 4
@ 2018-04-13  2:26 konrad.wilk
  0 siblings, 0 replies; only message in thread
From: konrad.wilk @ 2018-04-13  2:26 UTC (permalink / raw)
  To: speck

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 <konrad.wilk@oracle.com>
---
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(-)

diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h
index 7c6ed8b1b19b..c3856b3f42eb 100644
--- a/arch/x86/include/asm/nospec-branch.h
+++ b/arch/x86/include/asm/nospec-branch.h
@@ -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)
diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index 73f76d0f5181..250baf24da56 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -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,
-- 
2.14.3

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2018-04-18 14:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-13  2:26 [MODERATED] [patch 4/8] [PATCH v1.3.1 4/7] Linux Patch 4 konrad.wilk

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.