Skip to content

Commit 11fb068

Browse files
tlendackyKAGA-KOKO
authored andcommitted
x86/speculation: Add virtualized speculative store bypass disable support
Some AMD processors only support a non-architectural means of enabling speculative store bypass disable (SSBD). To allow a simplified view of this to a guest, an architectural definition has been created through a new CPUID bit, 0x80000008_EBX[25], and a new MSR, 0xc001011f. With this, a hypervisor can virtualize the existence of this definition and provide an architectural method for using SSBD to a guest. Add the new CPUID feature, the new MSR and update the existing SSBD support to use this MSR when present. Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Borislav Petkov <bp@suse.de>
1 parent ccbcd26 commit 11fb068

4 files changed

Lines changed: 18 additions & 2 deletions

File tree

‎arch/x86/include/asm/cpufeatures.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@
282282
#define X86_FEATURE_AMD_IBPB (13*32+12) /* "" Indirect Branch Prediction Barrier */
283283
#define X86_FEATURE_AMD_IBRS (13*32+14) /* "" Indirect Branch Restricted Speculation */
284284
#define X86_FEATURE_AMD_STIBP (13*32+15) /* "" Single Thread Indirect Branch Predictors */
285+
#define X86_FEATURE_VIRT_SSBD (13*32+25) /* Virtualized Speculative Store Bypass Disable */
285286

286287
/* Thermal and Power Management Leaf, CPUID level 0x00000006 (EAX), word 14 */
287288
#define X86_FEATURE_DTHERM (14*32+ 0) /* Digital Thermal Sensor */

‎arch/x86/include/asm/msr-index.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,8 @@
347347
#define MSR_AMD64_SEV_ENABLED_BIT 0
348348
#define MSR_AMD64_SEV_ENABLED BIT_ULL(MSR_AMD64_SEV_ENABLED_BIT)
349349

350+
#define MSR_AMD64_VIRT_SPEC_CTRL 0xc001011f
351+
350352
/* Fam 17h MSRs */
351353
#define MSR_F17H_IRPERF 0xc00000e9
352354

‎arch/x86/kernel/cpu/bugs.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,9 @@ static void x86_amd_ssb_disable(void)
205205
{
206206
u64 msrval = x86_amd_ls_cfg_base | x86_amd_ls_cfg_ssbd_mask;
207207

208-
if (boot_cpu_has(X86_FEATURE_LS_CFG_SSBD))
208+
if (boot_cpu_has(X86_FEATURE_VIRT_SSBD))
209+
wrmsrl(MSR_AMD64_VIRT_SPEC_CTRL, SPEC_CTRL_SSBD);
210+
else if (boot_cpu_has(X86_FEATURE_LS_CFG_SSBD))
209211
wrmsrl(MSR_AMD64_LS_CFG, msrval);
210212
}
211213

‎arch/x86/kernel/process.c‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,15 @@ static __always_inline void amd_set_core_ssb_state(unsigned long tifn)
388388
}
389389
#endif
390390

391+
static __always_inline void amd_set_ssb_virt_state(unsigned long tifn)
392+
{
393+
/*
394+
* SSBD has the same definition in SPEC_CTRL and VIRT_SPEC_CTRL,
395+
* so ssbd_tif_to_spec_ctrl() just works.
396+
*/
397+
wrmsrl(MSR_AMD64_VIRT_SPEC_CTRL, ssbd_tif_to_spec_ctrl(tifn));
398+
}
399+
391400
static __always_inline void intel_set_ssb_state(unsigned long tifn)
392401
{
393402
u64 msr = x86_spec_ctrl_base | ssbd_tif_to_spec_ctrl(tifn);
@@ -397,7 +406,9 @@ static __always_inline void intel_set_ssb_state(unsigned long tifn)
397406

398407
static __always_inline void __speculative_store_bypass_update(unsigned long tifn)
399408
{
400-
if (static_cpu_has(X86_FEATURE_LS_CFG_SSBD))
409+
if (static_cpu_has(X86_FEATURE_VIRT_SSBD))
410+
amd_set_ssb_virt_state(tifn);
411+
else if (static_cpu_has(X86_FEATURE_LS_CFG_SSBD))
401412
amd_set_core_ssb_state(tifn);
402413
else
403414
intel_set_ssb_state(tifn);

0 commit comments

Comments
 (0)