Return-path: Received: from mx3-rdu2.redhat.com ([66.187.233.73] helo=mx1.redhat.com) by Galois.linutronix.de with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1fIrJl-0006i4-9D for speck@linutronix.de; Wed, 16 May 2018 09:57:49 +0200 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 61E0D8082559 for ; Wed, 16 May 2018 07:57:43 +0000 (UTC) Received: from [10.36.117.154] (ovpn-117-154.ams2.redhat.com [10.36.117.154]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D44B52024CBB for ; Wed, 16 May 2018 07:57:42 +0000 (UTC) Subject: [MODERATED] Re: Settings question References: <20180514175715.GL18407@pd.tnic> <7dbfcac5-c32e-351b-7ae7-e40acf0decb9@redhat.com> From: Paolo Bonzini Message-ID: <190767cb-379b-1583-4d10-c546ac8a05f3@redhat.com> Date: Wed, 16 May 2018 09:57:41 +0200 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="3BYbpk05PmT0a60j8u5wFekKgd0MrmENS"; protected-headers="v1" To: speck@linutronix.de List-ID: This is an OpenPGP/MIME encrypted message (RFC 4880 and 3156) --3BYbpk05PmT0a60j8u5wFekKgd0MrmENS Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: quoted-printable On 15/05/2018 20:59, speck for Thomas Gleixner wrote: > On Tue, 15 May 2018, speck for Paolo Bonzini wrote: >> 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 gues= t >> access it without vmexits. > > 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: >=20 > 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. Th= is > is to avoid vmexits when the guest toggles a SPEC_CTRL bit often, > i.e. on context switch. >=20 > 2) Host restores the host state on VMEXIT if the guest toouched the > MSR_SPEC_CTRL and restores guest state on VMENTER >=20 > 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 i= n > place. >=20 > Correct? Correct, and what you listed is actually how KVM already works (commit d28b387fb74d, "KVM/VMX: Allow direct access to MSR_IA32_SPEC_CTRL", 2018-02-03). Right now the upstream code assumes that the host spec_ctrl is 0, but "x86/bugs, KVM: Support the combination of guest and host IBRS" changes it to take host SSBD into account: /* on vmentry */ - if (vmx->spec_ctrl) - wrmsrl(MSR_IA32_SPEC_CTRL, vmx->spec_ctrl); + x86_spec_ctrl_set_guest(vmx->spec_ctrl); =2E.. /* on vmexit */ - if (vmx->spec_ctrl) - wrmsrl(MSR_IA32_SPEC_CTRL, 0); + x86_spec_ctrl_restore_host(vmx->spec_ctrl); Paolo --3BYbpk05PmT0a60j8u5wFekKgd0MrmENS--