diff mbox series

[v5,1/4] x86/speculation: Add __update_spec_ctrl() helper

Message ID 20230710194857.2898284-2-longman@redhat.com
State New
Headers show
Series x86/speculation: Disable IBRS when idle | expand

Commit Message

Waiman Long July 10, 2023, 7:48 p.m. UTC
Add a new __update_spec_ctrl() helper which is a variant of
update_spec_ctrl() that can be used in a noinstr function.

Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Waiman Long <longman@redhat.com>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 arch/x86/include/asm/nospec-branch.h | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h
index 55388c9f7601..06ceacfd1fe2 100644
--- a/arch/x86/include/asm/nospec-branch.h
+++ b/arch/x86/include/asm/nospec-branch.h
@@ -9,7 +9,7 @@ 
 
 #include <asm/alternative.h>
 #include <asm/cpufeatures.h>
-#include <asm/msr-index.h>
+#include <asm/msr.h>
 #include <asm/unwind_hints.h>
 #include <asm/percpu.h>
 #include <asm/current.h>
@@ -488,6 +488,16 @@  DECLARE_PER_CPU(u64, x86_spec_ctrl_current);
 extern void update_spec_ctrl_cond(u64 val);
 extern u64 spec_ctrl_current(void);
 
+/*
+ * This can be used in noinstr function & should only be called in bare
+ * metal context.
+ */
+static __always_inline void __update_spec_ctrl(u64 val)
+{
+	__this_cpu_write(x86_spec_ctrl_current, val);
+	native_wrmsrl(MSR_IA32_SPEC_CTRL, val);
+}
+
 /*
  * With retpoline, we must use IBRS to restrict branch prediction
  * before calling into firmware.