Skip to content

Commit b0ef8c7

Browse files
KAGA-KOKOgregkh
authored andcommitted
x86/speculation, KVM: Implement support for VIRT_SPEC_CTRL/LS_CFG
commit 47c61b3 upstream Add the necessary logic for supporting the emulated VIRT_SPEC_CTRL MSR to x86_virt_spec_ctrl(). If either X86_FEATURE_LS_CFG_SSBD or X86_FEATURE_VIRT_SPEC_CTRL is set then use the new guest_virt_spec_ctrl argument to check whether the state must be modified on the host. The update reuses speculative_store_bypass_update() so the ZEN-specific sibling coordination can be reused. Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: David Woodhouse <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 0ec827f commit b0ef8c7

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

arch/x86/include/asm/spec-ctrl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ static inline u64 ssbd_tif_to_spec_ctrl(u64 tifn)
5353
return (tifn & _TIF_SSBD) >> (TIF_SSBD - SPEC_CTRL_SSBD_SHIFT);
5454
}
5555

56+
static inline unsigned long ssbd_spec_ctrl_to_tif(u64 spec_ctrl)
57+
{
58+
BUILD_BUG_ON(TIF_SSBD < SPEC_CTRL_SSBD_SHIFT);
59+
return (spec_ctrl & SPEC_CTRL_SSBD) << (TIF_SSBD - SPEC_CTRL_SSBD_SHIFT);
60+
}
61+
5662
static inline u64 ssbd_tif_to_amd_ls_cfg(u64 tifn)
5763
{
5864
return (tifn & _TIF_SSBD) ? x86_amd_ls_cfg_ssbd_mask : 0ULL;

arch/x86/kernel/cpu/bugs.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,36 @@ x86_virt_spec_ctrl(u64 guest_spec_ctrl, u64 guest_virt_spec_ctrl, bool setguest)
161161
wrmsrl(MSR_IA32_SPEC_CTRL, msrval);
162162
}
163163
}
164+
165+
/*
166+
* If SSBD is not handled in MSR_SPEC_CTRL on AMD, update
167+
* MSR_AMD64_L2_CFG or MSR_VIRT_SPEC_CTRL if supported.
168+
*/
169+
if (!static_cpu_has(X86_FEATURE_LS_CFG_SSBD) &&
170+
!static_cpu_has(X86_FEATURE_VIRT_SSBD))
171+
return;
172+
173+
/*
174+
* If the host has SSBD mitigation enabled, force it in the host's
175+
* virtual MSR value. If its not permanently enabled, evaluate
176+
* current's TIF_SSBD thread flag.
177+
*/
178+
if (static_cpu_has(X86_FEATURE_SPEC_STORE_BYPASS_DISABLE))
179+
hostval = SPEC_CTRL_SSBD;
180+
else
181+
hostval = ssbd_tif_to_spec_ctrl(ti->flags);
182+
183+
/* Sanitize the guest value */
184+
guestval = guest_virt_spec_ctrl & SPEC_CTRL_SSBD;
185+
186+
if (hostval != guestval) {
187+
unsigned long tif;
188+
189+
tif = setguest ? ssbd_spec_ctrl_to_tif(guestval) :
190+
ssbd_spec_ctrl_to_tif(hostval);
191+
192+
speculative_store_bypass_update(tif);
193+
}
164194
}
165195
EXPORT_SYMBOL_GPL(x86_virt_spec_ctrl);
166196

0 commit comments

Comments
 (0)