diff options
author | Waiman Long <longman@redhat.com> | 2023-07-27 21:45:57 +0300 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2023-10-07 12:33:28 +0300 |
commit | e3e3bab1844d448a239cd57ebf618839e26b4157 (patch) | |
tree | 802bf900819d458b15494cdd680b1627f227b576 /arch/x86/include/asm/spec-ctrl.h | |
parent | ea41bb514fe286bf50498b3c6d7f7a5dc2b6c5e0 (diff) | |
download | linux-e3e3bab1844d448a239cd57ebf618839e26b4157.tar.xz |
x86/speculation: Add __update_spec_ctrl() helper
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>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20230727184600.26768-2-longman@redhat.com
Diffstat (limited to 'arch/x86/include/asm/spec-ctrl.h')
-rw-r--r-- | arch/x86/include/asm/spec-ctrl.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/arch/x86/include/asm/spec-ctrl.h b/arch/x86/include/asm/spec-ctrl.h index cb0386fc4dc3..c648502e4535 100644 --- a/arch/x86/include/asm/spec-ctrl.h +++ b/arch/x86/include/asm/spec-ctrl.h @@ -4,6 +4,7 @@ #include <linux/thread_info.h> #include <asm/nospec-branch.h> +#include <asm/msr.h> /* * On VMENTER we must preserve whatever view of the SPEC_CTRL MSR @@ -76,6 +77,16 @@ static inline u64 ssbd_tif_to_amd_ls_cfg(u64 tifn) return (tifn & _TIF_SSBD) ? x86_amd_ls_cfg_ssbd_mask : 0ULL; } +/* + * This can be used in noinstr functions & 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); +} + #ifdef CONFIG_SMP extern void speculative_store_bypass_ht_init(void); #else |