Return-path: Received: from userp2130.oracle.com ([156.151.31.86]) by Galois.linutronix.de with esmtps (TLS1.2:RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1fImAc-0002sP-1y for speck@linutronix.de; Wed, 16 May 2018 04:28:02 +0200 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 w4G2PkfE096153 for ; Wed, 16 May 2018 02:27:55 GMT Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2130.oracle.com with ESMTP id 2hx29wash2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 16 May 2018 02:27:54 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w4G2Rs7l009205 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 16 May 2018 02:27:54 GMT Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w4G2RsWw029092 for ; Wed, 16 May 2018 02:27:54 GMT Date: Tue, 15 May 2018 22:27:53 -0400 From: Konrad Rzeszutek Wilk Subject: [MODERATED] Re: Settings question Message-ID: <20180516022752.GA18660@char.us.oracle.com> References: <20180514175715.GL18407@pd.tnic> <7dbfcac5-c32e-351b-7ae7-e40acf0decb9@redhat.com> MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit To: speck@linutronix.de List-ID: On Tue, May 15, 2018 at 08:59:13PM +0200, speck for Thomas Gleixner wrote: > On Tue, 15 May 2018, speck for Paolo Bonzini wrote: > > On 14/05/2018 19:57, speck for Borislav Petkov wrote: > > > Hi folks, > > > > > > so we just had this question: > > > > > > Imagine you boot the *host* with > > > > > > spec_store_bypass_disable=3Don > > > > > > which means, you enable the mitigation system-wide. Now someone boots > > > a guest with > > > > > > spec_store_bypass_disable=3Doff > > > > > > because someone wants performance in the guest and doesn't care about > > > leaking sensitive info through the side channel. > > > > > > Right now the guest can't override the setting because the host has > > > disabled it system-wide. > > > > > > And both use cases have their merits - host-enforced mitigation on vs > > > guests are allowed to disable the mitigation so as not to pay the perf > > > penalty. > > > > > > What do we allow? > > > > We pretty much have to allow only the case where guests can disable > > SSBD. Having rdmsr/wrmsr vmexits on every context switch would be too > > expensive, and therefore KVM special cases SPEC_CTRL and lets the guest > > access it without vmexits. > > > > (Some gory and unrelated details, in case you look at the code: > > rdmsr/wrmsr is also expensive to have on every vmentry, so this is > > actually enabled lazily. As soon as the VM accesses SPEC_CTRL, it will > > have to pay the price forever. However, if it doesn't access SPEC_CTRL, > > there is no penalty. The idea is that once a VM that accesses SPEC_CTRL > > it is unlikely to stop doing so, especially since we don't have to deal > > with nasty firmware writers...). > > So while you did not answer Borislav question and rather described the > status quo of the SPEC_CTRL MSR, I think what you want to have is: > > 1) Guest is allowed to write ANY (valid) value into MSR_SPEC_CTRL. The > first access traps and after that the host hands the MSR through. This > is to avoid vmexits when the guest toggles a SPEC_CTRL bit often, > i.e. on context switch. > > 2) Host restores the host state on VMEXIT if the guest toouched the > MSR_SPEC_CTRL and restores guest state on VMENTER It has a slight optimization in that if the SPEC_CTRL MSR value is the same as the host on VMENTER/VMEXIT it won't frob it. > > This happens under the assumption that even clearing a SPEC_CTRL bit, > i.e. disabling a mitigation, does not make the host vulnerable as long as > the VMEXIT restores SPEC_CTRL and has the other necessary protections in > place. > > Correct? Yes. > > Thanks, > > tglx >