Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp694266imm; Fri, 1 Jun 2018 08:02:16 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIMrZHWQ7rCngrxInXYyX5Bq+njyMwCaPT2Mz/Q9XqiAX9BFpfEECca62dMyfMVUEUJ9B+y X-Received: by 2002:a17:902:8308:: with SMTP id bd8-v6mr11565858plb.195.1527865336909; Fri, 01 Jun 2018 08:02:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527865336; cv=none; d=google.com; s=arc-20160816; b=lUzjlhIcg+e6kGmdOG0bGYlNjRKcAY3vD8zgBuv7nP8kUHzpB7mJpWcITAnZXKlzO1 bDg0CO9LHynoy9c8f3GISVYdUGpSWr+LmFKX1vA4xgCxsEhjTN+gJeVfu9kVlUjduuj4 BKccHby+h68Nf6nzpvecv8SgPze9qV9j31/7w/gVUsxHlQKBGsWIlO1SxlJVXwNcQaeu zXzF+mnqdxxrkv1SbFckGcDtYwCI47tdJAsll0YFAoegZgy2qO50jkTVfpwa0BrxQJ6k FPeeP/uPM1Sez/dclBAMmcyNlsfz0Dbkms1CflnQ1Hfc+/wy1b4W2BqMGTr0TUSPBu+C mSGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=mJ9BtTR+NsOlkCY31jQZIYbrTamYGRlXS9ku5OD5iX8=; b=rJ/yZIwiIjriqDj73MkSVhdH+h0vI20hzmp0SNHOo1IeLoR2pUo6SP2yJZrWUWOYFt sNW6V87d+tqqlpwnze9fTMfk6rwiz7wDM3HnjukL7Og+4b4PFbl9ogd7WA0zBUABbu7z B/PLWLJexIP865ONWwYwGIbo9aC+5fdKD5Hwva//Bs09O8uDPNRpQ6wWCuIDcnAwQj9c 6TzCza3K+w55s4tt9Q7bPfhQNoz8T9LdivC1jY33YIyiZpnpsyYho4wgsnToZrIed6Qh gtZY29KW2hB4BNtQofTJHBCO8DFHLBXdloG1URtSV35t5ATwp85CDykxzF6o78mtBqqb azmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=G2YO732E; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3-v6si39008933plx.591.2018.06.01.08.01.54; Fri, 01 Jun 2018 08:02:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=G2YO732E; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752687AbeFAPAG (ORCPT + 99 others); Fri, 1 Jun 2018 11:00:06 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:54506 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752468AbeFAPAC (ORCPT ); Fri, 1 Jun 2018 11:00:02 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w51EvVN9070112; Fri, 1 Jun 2018 14:59:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2017-10-26; bh=mJ9BtTR+NsOlkCY31jQZIYbrTamYGRlXS9ku5OD5iX8=; b=G2YO732Eii/KQFVEYizMWpX5m5gh83TzzbjZWV2NWCvvM+4d5WxHbejfAwvH4X6Qlpuh jeRErYSLr8WN+JIDVKN8BQJeg47EWUARtL15TwnyKkanWEXJg9cLf6Y0x9xTbhcbYajt buv1ebRWsOJBpUjwP6sdnV10Khmh+aXNSh7ryK+YQBc23yfvP3eTjZA7yMr7UUXlFOtE UpmiOyTmdRfHHnG1IN7i7FM8FQs8zi2w1gcN9plITgLi1sDMn74pgaeLysS/NRrTcMpg etDCHcQRuHHLyrEu7ShCwHF17Rd1qaHd/pJNhL0nXPpVjlBAXOkCCNyQF1zIqgXuRQCK TA== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2janje589b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 01 Jun 2018 14:59:25 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w51ExOU0026193 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 1 Jun 2018 14:59:24 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w51ExOor017138; Fri, 1 Jun 2018 14:59:24 GMT Received: from char.us.oracle.com (/10.137.176.158) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 01 Jun 2018 07:59:23 -0700 Received: by char.us.oracle.com (Postfix, from userid 1000) id 490986A00E3; Fri, 1 Jun 2018 10:59:22 -0400 (EDT) From: Konrad Rzeszutek Wilk To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, x86@kernel.org, tglx@linutronix.de, andrew.cooper3@citrix.com Cc: Konrad Rzeszutek Wilk , Ingo Molnar , "H. Peter Anvin" , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Joerg Roedel , Borislav Petkov , David Woodhouse , Tom Lendacky , Janakarajan Natarajan , Kees Cook , KarimAllah Ahmed , Andy Lutomirski Subject: [PATCH v1 2/3] x86/bugs: Add AMD's SPEC_CTRL MSR usage Date: Fri, 1 Jun 2018 10:59:20 -0400 Message-Id: <20180601145921.9500-3-konrad.wilk@oracle.com> X-Mailer: git-send-email 2.13.4 In-Reply-To: <20180601145921.9500-1-konrad.wilk@oracle.com> References: <20180601145921.9500-1-konrad.wilk@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8911 signatures=668702 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1805220000 definitions=main-1806010174 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The AMD document outlining the SSBD handling 124441_AMD64_SpeculativeStoreBypassDisable_Whitepaper_final.pdf mentions that if CPUID 8000_0008.EBX[24] is set we should be using the SPEC_CTRL MSR (0x48) over the VIRT SPEC_CTRL MSR (0xC001_011f) for speculative store bypass disable. This in effect means we should clear the X86_FEATURE_VIRT_SSBD flag so that we would prefer the SPEC_CTRL MSR. See the document titled: 124441_AMD64_SpeculativeStoreBypassDisable_Whitepaper_final.pdf A copy of this document is available at https://bugzilla.kernel.org/show_bug.cgi?id=3D199889 Signed-off-by: Konrad Rzeszutek Wilk --- Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Paolo Bonzini Cc: "Radim Kr=C4=8Dm=C3=A1=C5=99" Cc: Joerg Roedel Cc: Borislav Petkov Cc: Konrad Rzeszutek Wilk Cc: David Woodhouse Cc: Tom Lendacky Cc: Janakarajan Natarajan Cc: Kees Cook Cc: KarimAllah Ahmed Cc: Andy Lutomirski --- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/kernel/cpu/bugs.c | 12 +++++++----- arch/x86/kernel/cpu/common.c | 6 ++++++ arch/x86/kvm/cpuid.c | 10 ++++++++-- arch/x86/kvm/svm.c | 8 +++++--- 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cp= ufeatures.h index b6d7ce32927a..5701f5cecd31 100644 --- 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 Predictio= n Barrier */ #define X86_FEATURE_AMD_IBRS (13*32+14) /* "" Indirect Branch Restricte= d Speculation */ #define X86_FEATURE_AMD_STIBP (13*32+15) /* "" Single Thread Indirect B= ranch Predictors */ +#define X86_FEATURE_AMD_SSBD (13*32+24) /* "" Speculative Store Bypass = Disable */ #define X86_FEATURE_VIRT_SSBD (13*32+25) /* Virtualized Speculative Sto= re Bypass Disable */ #define X86_FEATURE_AMD_SSB_NO (13*32+26) /* "" Speculative Store Bypas= s is fixed in hardware. */ =20 diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index 7416fc206b4a..6bea81855cdd 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -529,18 +529,20 @@ static enum ssb_mitigation __init __ssb_select_miti= gation(void) if (mode =3D=3D SPEC_STORE_BYPASS_DISABLE) { setup_force_cpu_cap(X86_FEATURE_SPEC_STORE_BYPASS_DISABLE); /* - * Intel uses the SPEC CTRL MSR Bit(2) for this, while AMD uses - * a completely different MSR and bit dependent on family. + * Intel uses the SPEC CTRL MSR Bit(2) for this, while AMD may + * use a completely different MSR and bit dependent on family. */ switch (boot_cpu_data.x86_vendor) { case X86_VENDOR_INTEL: + case X86_VENDOR_AMD: + if (!static_cpu_has(X86_FEATURE_MSR_SPEC_CTRL)) { + x86_amd_ssb_disable(); + break; + } x86_spec_ctrl_base |=3D SPEC_CTRL_SSBD; x86_spec_ctrl_mask |=3D SPEC_CTRL_SSBD; wrmsrl(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base); break; - case X86_VENDOR_AMD: - x86_amd_ssb_disable(); - break; } } =20 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 494735cf63f5..d08a29bd0385 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -783,6 +783,12 @@ static void init_speculation_control(struct cpuinfo_= x86 *c) set_cpu_cap(c, X86_FEATURE_STIBP); set_cpu_cap(c, X86_FEATURE_MSR_SPEC_CTRL); } + + if (cpu_has(c, X86_FEATURE_AMD_SSBD)) { + set_cpu_cap(c, X86_FEATURE_SSBD); + set_cpu_cap(c, X86_FEATURE_MSR_SPEC_CTRL); + clear_cpu_cap(c, X86_FEATURE_VIRT_SSBD); + } } =20 void get_cpu_cap(struct cpuinfo_x86 *c) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 132f8a58692e..f4f30d0c25c4 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -379,7 +379,8 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_ent= ry2 *entry, u32 function, =20 /* cpuid 0x80000008.ebx */ const u32 kvm_cpuid_8000_0008_ebx_x86_features =3D - F(AMD_IBPB) | F(AMD_IBRS) | F(VIRT_SSBD) | F(AMD_SSB_NO); + F(AMD_IBPB) | F(AMD_IBRS) | F(AMD_SSBD) | F(VIRT_SSBD) | + F(AMD_SSB_NO); =20 /* cpuid 0xC0000001.edx */ const u32 kvm_cpuid_C000_0001_edx_x86_features =3D @@ -664,7 +665,12 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_en= try2 *entry, u32 function, entry->ebx |=3D F(VIRT_SSBD); entry->ebx &=3D kvm_cpuid_8000_0008_ebx_x86_features; cpuid_mask(&entry->ebx, CPUID_8000_0008_EBX); - if (boot_cpu_has(X86_FEATURE_LS_CFG_SSBD)) + /* + * The preference is to use SPEC CTRL MSR instead of the + * VIRT_SPEC MSR. + */ + if (boot_cpu_has(X86_FEATURE_LS_CFG_SSBD) && + !boot_cpu_has(X86_FEATURE_AMD_SSBD)) entry->ebx |=3D F(VIRT_SSBD); break; } diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 26110c202b19..950ec50f77c3 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -4115,7 +4115,8 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, struc= t msr_data *msr_info) break; case MSR_IA32_SPEC_CTRL: if (!msr_info->host_initiated && - !guest_cpuid_has(vcpu, X86_FEATURE_AMD_IBRS)) + !guest_cpuid_has(vcpu, X86_FEATURE_AMD_IBRS) && + !guest_cpuid_has(vcpu, X86_FEATURE_AMD_SSBD)) return 1; =20 msr_info->data =3D svm->spec_ctrl; @@ -4217,11 +4218,12 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, str= uct msr_data *msr) break; case MSR_IA32_SPEC_CTRL: if (!msr->host_initiated && - !guest_cpuid_has(vcpu, X86_FEATURE_AMD_IBRS)) + !guest_cpuid_has(vcpu, X86_FEATURE_AMD_IBRS) && + !guest_cpuid_has(vcpu, X86_FEATURE_AMD_SSBD)) return 1; =20 /* The STIBP bit doesn't fault even if it's not advertised */ - if (data & ~(SPEC_CTRL_IBRS | SPEC_CTRL_STIBP)) + if (data & ~(SPEC_CTRL_IBRS | SPEC_CTRL_STIBP | SPEC_CTRL_SSBD)) return 1; =20 svm->spec_ctrl =3D data; --=20 2.13.4