Return-Path: Received: from mail.linutronix.de (146.0.238.70:993) by crypto-ml.lab.linutronix.de with IMAP4-SSL for ; 17 Jul 2018 11:20:37 -0000 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 1ffO1z-00062d-Ka for speck@linutronix.de; Tue, 17 Jul 2018 13:20:36 +0200 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E39C2407574B for ; Tue, 17 Jul 2018 11:20:28 +0000 (UTC) Received: from [10.36.116.189] (ovpn-116-189.ams2.redhat.com [10.36.116.189]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4097E7C54 for ; Tue, 17 Jul 2018 11:20:28 +0000 (UTC) Subject: [MODERATED] Re: [PATCH] L1TF KVM ARCH_CAPABILITIES #1 References: <20180715135716.1874-1-pbonzini@redhat.com> <20180715135716.1874-2-pbonzini@redhat.com> From: Paolo Bonzini Message-ID: <066257c8-1cd8-8600-7bcc-2bc5db5a2580@redhat.com> Date: Tue, 17 Jul 2018 13:20:26 +0200 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="exq0C4d9fRCLj6TwUY0QTQgSzVQeNWhRl"; protected-headers="v1" To: speck@linutronix.de List-ID: This is an OpenPGP/MIME encrypted message (RFC 4880 and 3156) --exq0C4d9fRCLj6TwUY0QTQgSzVQeNWhRl Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: quoted-printable I'll send more patches today or tomorrow, in the meanwhile a couple clarifications. On 16/07/2018 22:02, speck for Thomas Gleixner wrote: > On Sun, 15 Jul 2018, speck for Paolo Bonzini wrote: >> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c >> index c5c0118b126d..bf0801399cb4 100644 >> --- a/arch/x86/kvm/vmx.c >> +++ b/arch/x86/kvm/vmx.c >> @@ -208,14 +208,17 @@ >> #define L1D_CACHE_ORDER 4 >> static void *vmx_l1d_flush_pages; >> =20 >> -static int vmx_setup_l1d_flush(enum vmx_l1d_flush_state l1tf) >> +static bool vmx_l1tf_vulnerable(void) >> +{ >> + return l1tf_vmx_mitigation !=3D VMENTER_L1D_FLUSH_NOT_VULNERABLE && >> + l1tf_vmx_mitigation !=3D VMENTER_L1D_FLUSH_EPT_DISABLED; >=20 > That's really a bad choice. >=20 > Not vulnerable is when the CPU does not have X86_BUG_L1TF. It is a bit more complicated, if SMT is disabled and L1D flush on entry is not required, then effectively _as far as VMX is concerned_ the processor is not vulnerable. I'm not sure if we want this to affect disable_smt. > If EPT=3Dn then > the CPU is vulnerable, but EPT disabled mitigates the issue. >=20 >> +} >> + >> +static int vmx_update_l1d_flush(enum vmx_l1d_flush_state l1tf) >> { >> struct page *page; >> =20 >> - if (!enable_ept) { >> - l1tf_vmx_mitigation =3D VMENTER_L1D_FLUSH_EPT_DISABLED; >> - return 0; >> - } >> + WARN_ON(!vmx_l1tf_vulnerable()); >> =20 >> /* If set to auto use the default l1tf mitigation method */ >> if (l1tf =3D=3D VMENTER_L1D_FLUSH_AUTO) { >> @@ -276,7 +289,7 @@ static int vmentry_l1d_flush_set(const char *s, co= nst struct kernel_param *kp) >> { >> int l1tf, ret; >> =20 >> - if (!boot_cpu_has(X86_BUG_L1TF)) >> + if (!vmx_l1tf_vulnerable()) >> return 0; >=20 > So you check for !vulnerable here and return. If vulnerable you call > vmx_update_l1d_flush() which has another check with a warnon. That's > convoluted, really. There are other calls to vmx_update_l1d_flush, the WARN_ON checks a precondition that should be true for all such calls. The precondition can be true because the caller checks it, because of where the call is, e= tc. I don't see what's convoluted about it, but actually there's a race between two calls to vmentry_l1d_flush_set that could trigger the WARN_ON, so this will have to be changed as well. >> l1tf =3D vmentry_l1d_flush_parse(s); >> @@ -295,7 +308,7 @@ static int vmentry_l1d_flush_set(const char *s, co= nst struct kernel_param *kp) >> } >> =20 >> mutex_lock(&vmx_l1d_flush_mutex); >> - ret =3D vmx_setup_l1d_flush(l1tf); >> + ret =3D vmx_update_l1d_flush(l1tf); >> mutex_unlock(&vmx_l1d_flush_mutex); >> return ret; >> } >> @@ -10592,7 +10605,7 @@ static int vmx_vm_init(struct kvm *kvm) >> if (!ple_gap) >> kvm->arch.pause_in_guest =3D true; >> =20 >> - if (boot_cpu_has(X86_BUG_L1TF) && enable_ept) { >> + if (vmx_l1tf_vulnerable()) { >=20 > This should be a check for vmx_l1tf_flush_required() which checks for >=20 > BUG_L1TF, enable_ept and then for that magic MSR bit. Ok. >> switch (l1tf_mitigation) { >> case L1TF_MITIGATION_OFF: >> case L1TF_MITIGATION_FLUSH_NOWARN: >> @@ -13383,8 +13396,8 @@ static int __init vmx_init(void) >> * contain 'auto' which will be turned into the default 'cond' >> * mitigation mode. >> */ >> - if (boot_cpu_has(X86_BUG_L1TF)) { >> - r =3D vmx_setup_l1d_flush(vmentry_l1d_flush_param); >> + if (l1tf_vmx_mitigation !=3D VMENTER_L1D_FLUSH_NOT_VULNERABLE) { >> + r =3D vmx_setup_l1d_flush(); >> if (r) { >> vmx_exit(); >> return r; >=20 > So this code should check for the magic MSR and act accordingly. >=20 > Thanks, >=20 > tglx >=20 --exq0C4d9fRCLj6TwUY0QTQgSzVQeNWhRl--