82b6c5a0d61e057d271e9131536494709402d0d5
[linux-2.6-block.git] / arch / x86 / include / asm / spec-ctrl.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_SPECCTRL_H_
3 #define _ASM_X86_SPECCTRL_H_
4
5 #include <linux/thread_info.h>
6 #include <asm/nospec-branch.h>
7
8 /*
9  * On VMENTER we must preserve whatever view of the SPEC_CTRL MSR
10  * the guest has, while on VMEXIT we restore the host view. This
11  * would be easier if SPEC_CTRL were architecturally maskable or
12  * shadowable for guests but this is not (currently) the case.
13  * Takes the guest view of SPEC_CTRL MSR as a parameter and also
14  * the guest's version of VIRT_SPEC_CTRL, if emulated.
15  */
16 extern void x86_spec_ctrl_set_guest(u64 guest_spec_ctrl,
17                                     u64 guest_virt_spec_ctrl);
18 extern void x86_spec_ctrl_restore_host(u64 guest_spec_ctrl,
19                                        u64 guest_virt_spec_ctrl);
20
21 /* AMD specific Speculative Store Bypass MSR data */
22 extern u64 x86_amd_ls_cfg_base;
23 extern u64 x86_amd_ls_cfg_ssbd_mask;
24
25 /* The Intel SPEC CTRL MSR base value cache */
26 extern u64 x86_spec_ctrl_base;
27
28 static inline u64 ssbd_tif_to_spec_ctrl(u64 tifn)
29 {
30         BUILD_BUG_ON(TIF_SSBD < SPEC_CTRL_SSBD_SHIFT);
31         return (tifn & _TIF_SSBD) >> (TIF_SSBD - SPEC_CTRL_SSBD_SHIFT);
32 }
33
34 static inline u64 ssbd_tif_to_amd_ls_cfg(u64 tifn)
35 {
36         return (tifn & _TIF_SSBD) ? x86_amd_ls_cfg_ssbd_mask : 0ULL;
37 }
38
39 #ifdef CONFIG_SMP
40 extern void speculative_store_bypass_ht_init(void);
41 #else
42 static inline void speculative_store_bypass_ht_init(void) { }
43 #endif
44
45 extern void speculative_store_bypass_update(unsigned long tif);
46
47 static inline void speculative_store_bypass_update_current(void)
48 {
49         speculative_store_bypass_update(current_thread_info()->flags);
50 }
51
52 #endif