Received: by 10.223.176.5 with SMTP id f5csp3148786wra; Mon, 29 Jan 2018 09:29:35 -0800 (PST) X-Google-Smtp-Source: AH8x224Y02TaXG5Cft8Ob2RnZqEli2uCWUQJiGb1hWbvD6ZZ4BbAqaHYUgCa4Mx5bqNWZVNlfH2t X-Received: by 10.99.131.74 with SMTP id h71mr21628469pge.373.1517246975011; Mon, 29 Jan 2018 09:29:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517246974; cv=none; d=google.com; s=arc-20160816; b=gs2QVj7EWTGXXFVyehLZfYp4RHj82pCRt3CEYXoU6bA+W/wP/Dw9eOA6OK8sGq7V2X lur9FJO25YfVJUlmx9aQOheCpNGq0gT/4Fnz8bQYUCvU4A68nVDEpUsL1OGLJoeZUCrX e69JsyJkHgsFYo6KY2o3xKl1Ufw/AOQlnDSGPa06hu16d4xhTCjy4NZnV3TnsC4puswb 9NLkNatiYevatef4qkUrA1paPwChLAH3NcWYeWRT4q6Y58oOBjyLICWxG8Tv2G/4KJDV mJENI0AD6M9kit26TrifL178r155oX0d695fqGEnxmfy3QbmJFN28oqac7YaBoIdAcin 3UlA== 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:user-agent :in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:dkim-signature:arc-authentication-results; bh=H5R8ejy1qOhTyY8PIWVHAyrwfdmPrUk0Ko9+XIFe15g=; b=XDZ2U7JWexAlbPtE432FFKSl9bM8ytelmWvhOlr7IZHn/Wl8VlPNlBKDtAop+uCSWw ajvhFusjmbk9mY6FMWZRlPh+kD3W3ud7+giI79yx6JM4PF8ers7cXccXx3GY+aekhKzD iFWmrXw7gDH/NyJ/rdfUckzh+Uk5Zep7w8Xl+83jwja6rBbhzU59dckpUCj5CoSEzvHI VkgEBwJPN/hj/Lg41ikeiZ7zo+6XpdLl9L7vawC0d/3Fo9fROHPM3VXqbf+yojkl3VGp qxVs5C73vFRj9OTbDzWwQvXIjXovWmv6KxVuIjB534ToXQyICA8NsdtRdnLZ/3wNelia BTEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=AJIjR72x; 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 v65si7755687pgb.238.2018.01.29.09.29.20; Mon, 29 Jan 2018 09:29:34 -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=AJIjR72x; 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 S1751478AbeA2R2U (ORCPT + 99 others); Mon, 29 Jan 2018 12:28:20 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:51450 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751264AbeA2R2T (ORCPT ); Mon, 29 Jan 2018 12:28:19 -0500 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 w0THRKLx164272; Mon, 29 Jan 2018 17:27:45 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 : content-transfer-encoding; s=corp-2017-10-26; bh=H5R8ejy1qOhTyY8PIWVHAyrwfdmPrUk0Ko9+XIFe15g=; b=AJIjR72xW11E2aJiyf/0gyhCE8MbRyUVFbVTak6dZ87AJQMdWXFX6vjsUkKpy5JN3Iyi t5qzKUjPiICfDx+1q/PURXbwTXY6nKZtzs6JaDw/qG+EhSYJVRuaMo/v85OCP2nebiCa g2nnKMjvKhF++Hka8+fhp0hT/YeXWuK/k66W33gURGU5gMa3xOqKirh7TWwVEeC0qgsk 0C0FsgMozGebuDNSod96p3Ipf0hB9CedNUlKSJJhyLjfYGH9GaEd2L9nxNauExuw5XwA ir1YvgRPZsd+BkETrj5KOgQUsh11FKGY4UWI5X8ZM8g2U1sbjsOyglwH+hhGfaTZj9w8 bg== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2120.oracle.com with ESMTP id 2ft7ft0bu9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Jan 2018 17:27:44 +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 w0THRiAi024498 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 29 Jan 2018 17:27:44 GMT Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w0THRil6028863; Mon, 29 Jan 2018 17:27:44 GMT Received: from char.us.oracle.com (/10.137.176.158) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 29 Jan 2018 09:27:43 -0800 Received: by char.us.oracle.com (Postfix, from userid 1000) id E9B886A0A22; Mon, 29 Jan 2018 12:27:41 -0500 (EST) Date: Mon, 29 Jan 2018 12:27:41 -0500 From: Konrad Rzeszutek Wilk To: David Woodhouse , daniel.kiper@oracle.com, Mihai Carabas Cc: KarimAllah Ahmed , Liran Alon , luto@kernel.org, tglx@linutronix.de, torvalds@linux-foundation.org, gregkh@linuxfoundation.org, asit.k.mallick@intel.com, dave.hansen@intel.com, karahmed@amazon.de, jun.nakajima@intel.com, dan.j.williams@intel.com, ashok.raj@intel.com, daniel.kiper@oracle.com, arjan.van.de.ven@intel.com, tim.c.chen@linux.intel.com, pbonzini@redhat.com, linux-kernel@vger.kernel.org, ak@linux.intel.com, kvm@vger.kernel.org, aarcange@redhat.com Subject: Re: [PATCH] x86: vmx: Allow direct access to MSR_IA32_SPEC_CTRL Message-ID: <20180129172741.GN22045@char.us.oracle.com> References: <6b9a1ec2-5ebd-4624-a825-3f31db5cefb5@default> <1517215563.6624.118.camel@infradead.org> <8bed4a5a-afc6-1569-d9bf-a3e1103e92f8@amazon.com> <1517222264.6624.131.camel@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1517222264.6624.131.camel@infradead.org> User-Agent: Mutt/1.8.3 (2017-05-23) Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8789 signatures=668655 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=844 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1801290226 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 29, 2018 at 10:37:44AM +0000, David Woodhouse wrote: > On Mon, 2018-01-29 at 10:43 +0100, KarimAllah Ahmed wrote: > > On 01/29/2018 09:46 AM, David Woodhouse wrote: > > > Reading the code and comparing with the SDM, I can't see where we'r= e > > > ever setting VM_EXIT_MSR_STORE_{ADDR,COUNT} except in the nested > > > case... > > Hmmm ... you are probably right! I think all users of this interface > > always trap + update save area and never passthrough the MSR. That is > > why only LOAD is needed *so far*. > >=20 > > Okay, let me sort this out in v3 then. >=20 > I'm starting to think a variant of Ashok's patch might actually be the > simpler approach, and not "premature optimisation". Especially if we > need to support the !cpu_has_vmx_msr_bitmaps() case? >=20 > Start with vmx->spec_ctrl set to zero. When first touched, make it > passthrough (but not atomically switched) and set a flag (e.g. > "spec_ctrl_live") which triggers the 'restore_branch_speculation' and > 'save_and_restrict_branch_speculation' behaviours. Except don't use > those macros. Those can look something like >=20 > =A0/* If this vCPU has touched SPEC_CTRL then restore its value if need= ed */ > =A0if (vmx->spec_ctrl_live && vmx->spec_ctrl) > =A0 =A0 =A0wrmsrl(MSR_IA32_SPEC_CTRL, vmx->spec_ctrl); > =A0/* vmentry is serialising on affected CPUs, so the conditional branc= h is safe */ >=20 >=20 > ... and, respectively, ... >=20 > /* If this vCPU has touched SPEC_CTRL then save its value and ensure w= e have zero */ > if (vmx->spec_ctrl_live) { > rdmsrl(MSR_IA32_SPEC_CTRL, vmx->spec_ctrl); > if (vmx->spec_ctrl) > wrmsrl(MSR_IA32_SPEC_CTRL, 0); > } >=20 >=20 > Perhaps we can ditch the separate 'spec_ctrl_live' flag and check the > pass-through MSR bitmap directly, in the case that it exists?=A0 Or the cpuid_flag as that would determine whether the MSR bitmap intercep= t is set or not.