From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from aserp2120.oracle.com ([141.146.126.78]) by Galois.linutronix.de with esmtps (TLS1.2:RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1fIn9s-0003YL-Ol for speck@linutronix.de; Wed, 16 May 2018 05:31:21 +0200 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w4G3V8XV025713 for ; Wed, 16 May 2018 03:31:13 GMT Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2120.oracle.com with ESMTP id 2hx29w2vwh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 16 May 2018 03:31:13 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w4G3VCpv007321 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 16 May 2018 03:31:12 GMT Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w4G3VCwx029971 for ; Wed, 16 May 2018 03:31:12 GMT Date: Tue, 15 May 2018 23:31:11 -0400 From: Konrad Rzeszutek Wilk Subject: [MODERATED] Re: [patch 08/15] Hidden 8 Message-ID: <20180516033111.GI18660@char.us.oracle.com> References: <20180513140048.543641807@linutronix.de> <20180513140538.883795088@linutronix.de> MIME-Version: 1.0 In-Reply-To: <20180513140538.883795088@linutronix.de> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit To: speck@linutronix.de List-ID: On Sun, May 13, 2018 at 04:00:56PM +0200, speck for Thomas Gleixner wrote: > Subject: [patch 08/15] x86/speculation: Add virtualized speculative store bypass disable support > From: Tom Lendacky > > 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. Which would imply you should be able to use this on Intel. That is an 'software' and 'virtualized' MSR should be CPU vendor agnostic. Why have it on 0x80000008_EBX instead of the virtualized CPUID leafs? Oh wait, future AMD chips will do the right thing in the microcode. And it may be that Intel will do it too? In which case see below.. > > 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 > Signed-off-by: Thomas Gleixner > --- > arch/x86/include/asm/cpufeatures.h | 1 + > arch/x86/include/asm/msr-index.h | 2 ++ > arch/x86/kernel/cpu/bugs.c | 4 +++- > arch/x86/kernel/process.c | 13 ++++++++++++- > 4 files changed, 18 insertions(+), 2 deletions(-) > > --- a/arch/x86/include/asm/cpufeatures.h > +++ b/arch/x86/include/asm/cpufeatures.h > @@ -282,6 +282,7 @@ > #define X86_FEATURE_AMD_IBPB (13*32+12) /* "" Indirect Branch Prediction Barrier */ > #define X86_FEATURE_AMD_IBRS (13*32+14) /* "" Indirect Branch Restricted Speculation */ > #define X86_FEATURE_AMD_STIBP (13*32+15) /* "" Single Thread Indirect Branch Predictors */ > +#define X86_FEATURE_VIRT_SSBD (13*32+25) /* Virtualized Speculative Store Bypass Disable */ > > /* Thermal and Power Management Leaf, CPUID level 0x00000006 (EAX), word 14 */ > #define X86_FEATURE_DTHERM (14*32+ 0) /* Digital Thermal Sensor */ > --- a/arch/x86/include/asm/msr-index.h > +++ b/arch/x86/include/asm/msr-index.h > @@ -347,6 +347,8 @@ > #define MSR_AMD64_SEV_ENABLED_BIT 0 > #define MSR_AMD64_SEV_ENABLED BIT_ULL(MSR_AMD64_SEV_ENABLED_BIT) > > +#define MSR_AMD64_VIRT_SPEC_CTRL 0xc001011f /me scratches his head. this looks off, but it is probably my editor. > + > /* Fam 17h MSRs */ > #define MSR_F17H_IRPERF 0xc00000e9 > ..snip.. > --- a/arch/x86/kernel/process.c > +++ b/arch/x86/kernel/process.c > @@ -366,6 +366,15 @@ static __always_inline void amd_set_core > } > #endif > > +static __always_inline void amd_set_ssb_virt_state(unsigned long tifn) s/amd_// ? > +{ > + /* > + * SSBD has the same definition in SPEC_CTRL and VIRT_SPEC_CTRL, > + * so ssbd_tif_to_spec_ctrl() just works. > + */ > + wrmsrl(MSR_AMD64_VIRT_SPEC_CTRL, ssbd_tif_to_spec_ctrl(tifn)); > +} > + > static __always_inline void intel_set_ssb_state(unsigned long tifn) > { > u64 msr = x86_spec_ctrl_base | ssbd_tif_to_spec_ctrl(tifn); > @@ -375,7 +384,9 @@ static __always_inline void intel_set_ss > > static __always_inline void __speculative_store_bypass_update(unsigned long tifn) > { > - if (static_cpu_has(X86_FEATURE_LS_CFG_SSBD)) > + if (static_cpu_has(X86_FEATURE_VIRT_SSBD)) > + amd_set_ssb_virt_state(tifn); and here too obviously.. > + else if (static_cpu_has(X86_FEATURE_LS_CFG_SSBD)) > amd_set_core_ssb_state(tifn); > else > intel_set_ssb_state(tifn); >