Received: by 10.223.176.5 with SMTP id f5csp1844895wra; Wed, 31 Jan 2018 12:30:06 -0800 (PST) X-Google-Smtp-Source: AH8x227hLq4YDxUL5W7jr0dcePILb67El/u3EyczgZ2ME7eENBbREutJNqZnfvSl25RaPHllwe1p X-Received: by 10.98.54.71 with SMTP id d68mr34406487pfa.173.1517430606309; Wed, 31 Jan 2018 12:30:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517430606; cv=none; d=google.com; s=arc-20160816; b=ygUp2fLZ37F0oCV1BdgYSocTGZ3dpcTNfP46ffiN9uwE0CpjqjG3AfA4QNVbJnZy56 TLdi46gzccm2L6CqLa/SAlEFMt/i/fkNxYWNu2wIchYOChm5zpsBKVHft9vVHD6TzU04 Iop/asBojqecR2H8uCGkn4hkD8K42+9Id3d7BXMsNqMsT9Dg3i2kLJAsJk05y/HFPU0i xBkS4D6678Trhp1Y+tl2WGQayLZBFoh8Mlgt721gy076KKw4CEpYyCwjHOhzlYKkesAe 4rkkaR/hgPiGlwxgG6tglO3rTKhSWqgwuuKWs9EUiIWbIedmUpag3YRZ9Yj1numXShME CL1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=MfHicXP/m57YW/vJtPjyD8Cc6ljpPjJgg186s+COJt4=; b=M4OXyb0jBUJMJZzs4sKpTPXFlOkd9uEmMjZz0SjX9aJov6U7pnpE4ojMLfPQpJIuTJ de0SR2Kkb058X93FgCv3dsGp7zaMvTY1hezywNDeh+bG0Gbx43ImmWXhEnGPokaOXrwP Zxl3hElmNy3qT70XOIVkXDobLK83Ucb+ByaYgNWrgusODQfMWdp0bXtv5zcTgB/YDWLH Ytsyi1CXIW7KXgm19DU0jp6CrP51P72vpWuKhRGRyPVKphHdCMZAmeY6wC031EQyWUzY HeNpHkCMdos/wkvq7WhvcxOAjJQuivXB6QthVlnbpzP9d8SHBq1haeOUSq+lwsEkI1+r gy+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=G7YdL6FZ; 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 b3-v6si2412145pls.325.2018.01.31.12.29.49; Wed, 31 Jan 2018 12:30:06 -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=G7YdL6FZ; 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 S1751881AbeAaU3Y (ORCPT + 99 others); Wed, 31 Jan 2018 15:29:24 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:57056 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751579AbeAaU3X (ORCPT ); Wed, 31 Jan 2018 15:29:23 -0500 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 w0VKRIse039545; Wed, 31 Jan 2018 20:28:51 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2017-10-26; bh=MfHicXP/m57YW/vJtPjyD8Cc6ljpPjJgg186s+COJt4=; b=G7YdL6FZwMmOjj1aTYrkzIyqoWJHHZ0O6N4DzFy1t/VLlSS/ZkMARIrN41GvGi4JmsDw ROtcKY1MKJvuggGCUsuqhmr4ltGJ6xhKTD1lMu77MDM5fknOSJFIK50iDmPptAEPtUmh YmM9GjuYBgraMKbJfGiZDUwlRRPzZWA5zfalhn20BBjc/xXT7Hlj8g93JXos4RUGvGGr cgPA4mwF9CRyeAzW29xJ9Pprr4pu3Z17PbhMtaYywMSJ39Y0VmM+82mEuUdVBAtT8pjt ZP/iV92Z8inPZ8CSB+6quTO3hzdJV2SZGJ5bUIOCVvdJAx9ysxme+a7nrvf+q6yN3n6/ yg== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2fujpm8nrk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 31 Jan 2018 20:28:50 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w0VKSnhK008763 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 31 Jan 2018 20:28:50 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w0VKSmeg021011; Wed, 31 Jan 2018 20:28:48 GMT Received: from char.us.oracle.com (/10.137.176.158) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 31 Jan 2018 12:28:48 -0800 Received: by char.us.oracle.com (Postfix, from userid 1000) id 49B606A09F6; Wed, 31 Jan 2018 15:28:46 -0500 (EST) Date: Wed, 31 Jan 2018 15:28:46 -0500 From: Konrad Rzeszutek Wilk To: KarimAllah Ahmed Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, Ashok Raj , Asit Mallick , Dave Hansen , Arjan Van De Ven , Tim Chen , Linus Torvalds , Andrea Arcangeli , Andi Kleen , Thomas Gleixner , Dan Williams , Jun Nakajima , Andy Lutomirski , Greg KH , Paolo Bonzini , Peter Zijlstra , David Woodhouse Subject: Re: [PATCH v5 2/5] KVM: x86: Add IBPB support Message-ID: <20180131202846.GG22045@char.us.oracle.com> References: <1517427467-28567-1-git-send-email-karahmed@amazon.de> <1517427467-28567-3-git-send-email-karahmed@amazon.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1517427467-28567-3-git-send-email-karahmed@amazon.de> User-Agent: Mutt/1.8.3 (2017-05-23) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8791 signatures=668659 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-1711220000 definitions=main-1801310255 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > index d46a61b..2e4e8af 100644 > --- a/arch/x86/kvm/vmx.c > +++ b/arch/x86/kvm/vmx.c > @@ -2285,6 +2285,7 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu) > if (per_cpu(current_vmcs, cpu) != vmx->loaded_vmcs->vmcs) { > per_cpu(current_vmcs, cpu) = vmx->loaded_vmcs->vmcs; > vmcs_load(vmx->loaded_vmcs->vmcs); > + indirect_branch_prediction_barrier(); > } > > if (!already_loaded) { > @@ -3342,6 +3343,26 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) > case MSR_IA32_TSC: > kvm_write_tsc(vcpu, msr_info); > break; > + case MSR_IA32_PRED_CMD: > + if (!msr_info->host_initiated && > + !guest_cpuid_has(vcpu, X86_FEATURE_IBPB) && > + !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL)) > + return 1; > + > + if (data & ~PRED_CMD_IBPB) > + return 1; > + > + if (!data) > + break; > + > + wrmsrl(MSR_IA32_PRED_CMD, PRED_CMD_IBPB); > + > + if (is_guest_mode(vcpu)) > + break; Don't you want this the other way around? That is first do the disable_intercept and then add the 'if (is_guest_mode(vcpu))' ? Otherwise the very first MSR write from the guest is going to hit condition above and never end up executing the disabling of the intercept? > + > + vmx_disable_intercept_for_msr(vmx->vmcs01.msr_bitmap, MSR_IA32_PRED_CMD, > + MSR_TYPE_W); > + break; > case MSR_IA32_CR_PAT: > if (vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_IA32_PAT) { > if (!kvm_mtrr_valid(vcpu, MSR_IA32_CR_PAT, data))