Received: by 10.223.176.5 with SMTP id f5csp2721567wra; Mon, 29 Jan 2018 02:55:55 -0800 (PST) X-Google-Smtp-Source: AH8x227hJsjsHEZGv4Pd+36nSFjF6o8gFoc5Cx+TzLJfjYwqphE+XmGNfSEwiP3/jxnjCt6a+BKc X-Received: by 2002:a17:902:824:: with SMTP id 33-v6mr20046847plk.258.1517223355598; Mon, 29 Jan 2018 02:55:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517223355; cv=none; d=google.com; s=arc-20160816; b=rHIRC9J6hQafE6OTT8hP1vxd3eIAoKYv3j+7gV5aTdn38Ir+1avRo+ccSLCwVAQ+wH Y7AMToUhwx9pJmzAu/DknVPfEkE1YgMf1AkA93ejASLzyG4AgKKpMHJG+yZ5l9oXrKVF Pq1/P+3SHfWaYd1EV/DtXS7kr5JycQOKifKMw6v3+QpuEXv1nVe0Yb2XheU0U0hPVNj8 gUcDH3ewopOV4Qrl23MxSLuNQ8vicqCxApYPe2RsSExVTgYWIsENWdGsgyFMe6djs6xE da1oQiMcZDSJI+XUOl/WvnKadpEBhyZDerKx/jf/ocFX1LdiV73NRzqgiRkQBskVQt5s TbDg== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=ODKFidiUFOCuM7OUKYJPmNSTI6k31J4JACTm+rcauvw=; b=yfanh4OXtGTFJzdom5Uaq8JiKBGVFJw1A20Ye1JDxcXOC7fonwPwYwxydEZyqyKmP6 YUKcfuOLDmQqo/KoNNzRPGabRJrcBg39kahBjLe8t87HSus+zBfco17wV6Iein5PFi4O IvNBQjMkX5OLVFJ2zJWlbCRXGtGmyUzS1Jowf7g/paOSHcGiW7DXer7bF6KMhpeR8AaR 5usZEpc3TGTVW9sOdAnsQOleoKADmoZ4apZUAXkieJxB6ZdE5q0PoOEdiASCpHVTGSQq 77qLh9sxo/fQqh8KQOkJi7XbEKXePDXi99/BvfF+ccJnR5n21aVkHLzk8juYyvN2/n4l r3jw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bi5-v6si1160816plb.226.2018.01.29.02.55.41; Mon, 29 Jan 2018 02:55:55 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751640AbeA2KzN (ORCPT + 99 others); Mon, 29 Jan 2018 05:55:13 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35876 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750913AbeA2KzM (ORCPT ); Mon, 29 Jan 2018 05:55:12 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 17DFCC047B91; Mon, 29 Jan 2018 10:55:12 +0000 (UTC) Received: from [10.36.117.86] (ovpn-117-86.ams2.redhat.com [10.36.117.86]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BD2DD7C144; Mon, 29 Jan 2018 10:55:04 +0000 (UTC) Subject: Re: [PATCH] x86: vmx: Allow direct access to MSR_IA32_SPEC_CTRL To: David Woodhouse , KarimAllah Ahmed , Liran Alon Cc: konrad.wilk@oracle.com, 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, linux-kernel@vger.kernel.org, ak@linux.intel.com, kvm@vger.kernel.org, aarcange@redhat.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> From: Paolo Bonzini Message-ID: <23d496d7-37f0-166d-9b3a-7cf731d8244f@redhat.com> Date: Mon, 29 Jan 2018 11:55:02 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <1517222264.6624.131.camel@infradead.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 29 Jan 2018 10:55:12 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 29/01/2018 11:37, 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're >>> 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*. >> >> Okay, let me sort this out in v3 then. > > 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? That case is awfully slow anyway, it doesn't matter, but the direct-access flag would simply be always 0 if you have no MSR bitmaps. > 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 > >  /* If this vCPU has touched SPEC_CTRL then restore its value if needed */ >  if (vmx->spec_ctrl_live && vmx->spec_ctrl) >      wrmsrl(MSR_IA32_SPEC_CTRL, vmx->spec_ctrl); >  /* vmentry is serialising on affected CPUs, so the conditional branch is safe */ > > > ... and, respectively, ... > > /* If this vCPU has touched SPEC_CTRL then save its value and ensure we 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); > } > > Perhaps we can ditch the separate 'spec_ctrl_live' flag and check the > pass-through MSR bitmap directly, in the case that it exists?  Probably a cache miss, or even a TLB miss if you're unlucky, so the separate flag is okay. Paolo