Received: by 10.223.176.46 with SMTP id f43csp1174214wra; Sat, 20 Jan 2018 12:31:52 -0800 (PST) X-Google-Smtp-Source: AH8x2252mMZ458p/gq2a7XEkrfvfQ/TGx0UMN7LPMszWXPsWy29umBtix8w0THOHA4A3tKvWUQBc X-Received: by 2002:a17:902:3084:: with SMTP id v4-v6mr672385plb.61.1516480311967; Sat, 20 Jan 2018 12:31:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516480311; cv=none; d=google.com; s=arc-20160816; b=W9E/W59JXWokYPVQVr0YKagbHAmvFPUk8NhUstTVZu9FFXn8AXJ/61J9kqnPvFTdhI bruweR5/aDq1U4ygLUGaAATIMUt2MYB/CkSJjAdcKT/ILhFbnTyaGS+OuPfSk54qNSmZ fF98uPwlCRQk94LkfLJwzSaen7b5pNfk3MrpeRUOKc+ukygdifTFIubjPbgqW1QaYhwd rYi3q15u3Q0X/7/SMpvXBWxa/1QK8I6/8isbdRQ/XCi1k8xWJRA6D3t7BCkFfTAlNxxR 8c0cg9z8Ghl3K5o6C7x8uMA9RnGn+VSZGIEftLEswlBXyfvmIqb0hGivEB3ao0rwAVB2 3wnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:subject:cc:to:from:date:message-id :mime-version:dkim-signature:arc-authentication-results; bh=eJZYPMWaeWyaT5UcMEXzPHBNMZBSSAJynSGsXIRTh8c=; b=wASDGTuM5Afb0GdqQGtNRKOzJZKheW0mNxs/RyMbzMg9KkpNyECztTLMKhvnQFu3jd VEHKcbhfgIfhOJ6xYlz3e+tBwQB5FyoN5j3uLJAxiGNupnIsZjmAKnDH7iHH6Ut7P9GY BBCmDmSI7j6vAiI7MXZdx3jg7tai9KWsyiiFNYKU39H/2OqYt2U4ex3DJqCCrbt3da5Q kYuEq7IMLmo/tNj1aH5Dlq3OlpsX2NsogrSO7Mw8gwQrT7UA6fKoNqvtH1rECTPOFJch O46CNC/vKV6BjnlxuZY4FPKOIxaZ/S5BK3RZZcu26bxuLC2ivbppvySnhwJvSueZKtPt cgQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=ZNeYRyz2; 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 a70si10878659pge.448.2018.01.20.12.31.38; Sat, 20 Jan 2018 12:31:51 -0800 (PST) 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=ZNeYRyz2; 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 S1756759AbeATUaG (ORCPT + 99 others); Sat, 20 Jan 2018 15:30:06 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:47796 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756615AbeATU36 (ORCPT ); Sat, 20 Jan 2018 15:29:58 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w0KKRU3d091347; Sat, 20 Jan 2018 20:28:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=mime-version : message-id : date : from : to : cc : subject : content-type : content-transfer-encoding; s=corp-2017-10-26; bh=eJZYPMWaeWyaT5UcMEXzPHBNMZBSSAJynSGsXIRTh8c=; b=ZNeYRyz2t3IMJTEN3e7SYmvv49RYxSMQVO2VwMdZ5tfpB3IAnB7dLNG6yfj9AUJu+XKf 6t1ehglaZI+zAq3UIzUR8LzJe1jYvpIQcGt6ooq0yukks2z2eaHC0ZDWWqMU6mQ0Qrs0 y0VkK7agxoDM5/uCob19Nc2eMcgiY+E+GQBjLTAE5TfHvAPVI9r2eSmVZ8gxIPc2NpIL sM/FfmRvTJ660YE1YSUCHOTv10xotZkNdUllfZUy++2fyRgm6k/nWi8rJSp50ZDJjrpF MIHO45COub/eFAEukMTTYdtgwyeBHOTBwlapC3674tvLGUNTZhlMiK2UKT/RmnE8bWxp yA== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2130.oracle.com with ESMTP id 2fmcqhg0ax-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 20 Jan 2018 20:28:42 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w0KKSeKu006811 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 20 Jan 2018 20:28:40 GMT Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w0KKSbjs015769; Sat, 20 Jan 2018 20:28:37 GMT MIME-Version: 1.0 Message-ID: Date: Sat, 20 Jan 2018 12:28:37 -0800 (PST) From: Liran Alon To: Cc: , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: Re: [RFC 02/10] x86/kvm: Add IBPB support X-Mailer: Zimbra on Oracle Beehive Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8780 signatures=668655 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 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-1711220000 definitions=main-1801200297 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- karahmed@amazon.de wrote: > From: Ashok Raj >=20 > Add MSR passthrough for MSR_IA32_PRED_CMD and place branch predictor > barriers on switching between VMs to avoid inter VM specte-v2 > attacks. >=20 > [peterz: rebase and changelog rewrite] > [dwmw2: fixes] > [karahmed: - vmx: expose PRED_CMD whenever it is available > =09 - svm: only pass through IBPB if it is available] >=20 > Cc: Asit Mallick > Cc: Dave Hansen > Cc: Arjan Van De Ven > Cc: Tim Chen > Cc: Linus Torvalds > Cc: Andrea Arcangeli > Cc: Andi Kleen > Cc: Thomas Gleixner > Cc: Dan Williams > Cc: Jun Nakajima > Cc: Andy Lutomirski > Cc: Greg KH > Cc: David Woodhouse > Cc: Paolo Bonzini > Signed-off-by: Ashok Raj > Signed-off-by: Peter Zijlstra (Intel) > Link: > https://urldefense.proofpoint.com/v2/url?u=3Dhttp-3A__lkml.kernel.org_r_1= 515720739-2D43819-2D6-2Dgit-2Dsend-2Demail-2Dashok.raj-40intel.com&d=3DDwIB= aQ&c=3DRoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=3DJk6Q8nNzkQ6LJ6g42qAR= kg6ryIDGQr-yKXPNGZbpTx0&m=3D0Y6G18aD_Uxu0jx8J4AbITM-rlF_AyH591Zg5HwA5L8&s= =3Duf8SxTOp8zu-Q5H9l-Ko-UoLUgvfuN5bvLdJwe6kUXc&e=3D >=20 > Signed-off-by: David Woodhouse > Signed-off-by: KarimAllah Ahmed > --- > arch/x86/kvm/svm.c | 14 ++++++++++++++ > arch/x86/kvm/vmx.c | 4 ++++ > 2 files changed, 18 insertions(+) >=20 > diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c > index 2744b973..cfdb9ab 100644 > --- a/arch/x86/kvm/svm.c > +++ b/arch/x86/kvm/svm.c > @@ -529,6 +529,7 @@ struct svm_cpu_data { > =09struct kvm_ldttss_desc *tss_desc; > =20 > =09struct page *save_area; > +=09struct vmcb *current_vmcb; > }; > =20 > static DEFINE_PER_CPU(struct svm_cpu_data *, svm_data); > @@ -918,6 +919,9 @@ static void svm_vcpu_init_msrpm(u32 *msrpm) > =20 > =09=09set_msr_interception(msrpm, direct_access_msrs[i].index, 1, 1); > =09} > + > +=09if (boot_cpu_has(X86_FEATURE_AMD_PRED_CMD)) > +=09=09set_msr_interception(msrpm, MSR_IA32_PRED_CMD, 1, 1); > } > =20 > static void add_msr_offset(u32 offset) > @@ -1706,11 +1710,17 @@ static void svm_free_vcpu(struct kvm_vcpu > *vcpu) > =09__free_pages(virt_to_page(svm->nested.msrpm), MSRPM_ALLOC_ORDER); > =09kvm_vcpu_uninit(vcpu); > =09kmem_cache_free(kvm_vcpu_cache, svm); > +=09/* > +=09 * The vmcb page can be recycled, causing a false negative in > +=09 * svm_vcpu_load(). So do a full IBPB now. > +=09 */ > +=09indirect_branch_prediction_barrier(); > } > =20 > static void svm_vcpu_load(struct kvm_vcpu *vcpu, int cpu) > { > =09struct vcpu_svm *svm =3D to_svm(vcpu); > +=09struct svm_cpu_data *sd =3D per_cpu(svm_data, cpu); > =09int i; > =20 > =09if (unlikely(cpu !=3D vcpu->cpu)) { > @@ -1739,6 +1749,10 @@ static void svm_vcpu_load(struct kvm_vcpu > *vcpu, int cpu) > =09if (static_cpu_has(X86_FEATURE_RDTSCP)) > =09=09wrmsrl(MSR_TSC_AUX, svm->tsc_aux); > =20 > +=09if (sd->current_vmcb !=3D svm->vmcb) { > +=09=09sd->current_vmcb =3D svm->vmcb; > +=09=09indirect_branch_prediction_barrier(); > +=09} > =09avic_vcpu_load(vcpu, cpu); > } > =20 > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > index d1e25db..3b64de2 100644 > --- a/arch/x86/kvm/vmx.c > +++ b/arch/x86/kvm/vmx.c > @@ -2279,6 +2279,7 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, > int cpu) > =09if (per_cpu(current_vmcs, cpu) !=3D vmx->loaded_vmcs->vmcs) { > =09=09per_cpu(current_vmcs, cpu) =3D vmx->loaded_vmcs->vmcs; > =09=09vmcs_load(vmx->loaded_vmcs->vmcs); > +=09=09indirect_branch_prediction_barrier(); > =09} > =20 > =09if (!already_loaded) { > @@ -6791,6 +6792,9 @@ static __init int hardware_setup(void) > =09=09kvm_tsc_scaling_ratio_frac_bits =3D 48; > =09} > =20 > +=09if (boot_cpu_has(X86_FEATURE_SPEC_CTRL)) > +=09=09vmx_disable_intercept_for_msr(MSR_IA32_PRED_CMD, false); > + > =09vmx_disable_intercept_for_msr(MSR_FS_BASE, false); > =09vmx_disable_intercept_for_msr(MSR_GS_BASE, false); > =09vmx_disable_intercept_for_msr(MSR_KERNEL_GS_BASE, true); > --=20 > 2.7.4 Isn't it cleaner to check for "boot_cpu_has(X86_FEATURE_IBPB)" both in svm_= vcpu_init_msrpm() and hardware_setup()? -Liran