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 1fNwzi-0008NN-25 for speck@linutronix.de; Wed, 30 May 2018 11:02:10 +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 3470E406E966 for ; Wed, 30 May 2018 09:02:04 +0000 (UTC) Received: from [10.36.118.56] (unknown [10.36.118.56]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9EDC66B59A for ; Wed, 30 May 2018 09:02:03 +0000 (UTC) Subject: [MODERATED] Re: [PATCH 1/2] L1TF KVM 1 References: <20180529194214.2600-1-pbonzini@redhat.com> <20180529194240.7F1336110A@crypto-ml.lab.linutronix.de> From: Paolo Bonzini Message-ID: <7b13a151-7af2-7df6-8a20-f19c358498f5@redhat.com> Date: Wed, 30 May 2018 11:02:02 +0200 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="jEjZJAWCvxdHghuurZCAfSIC2CbVXZdu0"; protected-headers="v1" To: speck@linutronix.de List-ID: This is an OpenPGP/MIME encrypted message (RFC 4880 and 3156) --jEjZJAWCvxdHghuurZCAfSIC2CbVXZdu0 Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: quoted-printable On 30/05/2018 00:49, speck for Thomas Gleixner wrote: > On Tue, 29 May 2018, speck for Paolo Bonzini wrote: >> From: Paolo Bonzini >> Subject: [PATCH 1/2] kvm: x86: mitigation for L1 cache terminal fault = vulnerabilities >> >> This patch adds two mitigation modes for CVE-2018-3620, aka L1 termina= l >> fault. The two modes are "vmexit_l1d_flush=3D1" and "vmexit_l1d_flush= =3D2". >=20 > This is confusing at best. Why is this vmexit_l1d_flush? You flush on > VMENTER not on VMEXIT. Yes, that makes sense. >> Notably, L1 cache flushes are performed on EPT violations (which are >> basically KVM-level page faults), vmexits that involve the emulator, >> and on every KVM_RUN invocation (so each userspace exit). However, >> most vmexits are considered safe. I singled out the emulator because >> it may be a good target for other speculative execution-based threats,= >> and the MMU because it can bring host page tables in the L1 cache. >=20 > What about interrupts? Will fix the commit message and rework the patch to set vcpu_unconfined at vmexit time. >> + /* >> + * The next three set vcpu->arch.vcpu_unconfined themselves, so >> + * we consider them confined here. >=20 > What's the logic behind that? >=20 >> + */ >> + case EXIT_REASON_EPT_VIOLATION: >> + case EXIT_REASON_EPT_MISCONFIG: >> + case EXIT_REASON_IO_INSTRUCTION: >> + return true; EPT misconfig and I/O instruction are very frequent, and most of the time they run just a small fast path. EPT violation can be put together with the "always slow" ones. >> + case EXIT_REASON_EXTERNAL_INTERRUPT: { >> + int cpu =3D raw_smp_processor_id(); >> + int vector =3D per_cpu(last_vector, cpu); >> + return vector =3D=3D LOCAL_TIMER_VECTOR || vector =3D=3D RESCHEDULE= _VECTOR; >=20 > That wants a comment why these two are considered safe. >=20 > The timer vector is a doubtful one. It does not necessarily cause a > reschedule and it can run arbitrary softirq code on interrupt return. I= > wouldn't be that sure that it's safe. It's also the most frequent one. :( But I see your and Peter's point, I'll drop it and consider all external interrupts to be unconfined. May there could be some kind of "ran softirq" generation count. >> @@ -9457,11 +9515,13 @@ static void vmx_handle_external_intr(struct kv= m_vcpu *vcpu) >> unsigned long entry; >> gate_desc *desc; >> struct vcpu_vmx *vmx =3D to_vmx(vcpu); >> + int cpu =3D raw_smp_processor_id(); >> #ifdef CONFIG_X86_64 >> unsigned long tmp; >> #endif >> =20 >> vector =3D exit_intr_info & INTR_INFO_VECTOR_MASK; >> + per_cpu(last_vector, cpu) =3D vector; >=20 > Why aren't you doing the evaluation of the vector right here and set th= e > unconfined bit instead of having yet another indirection and probably > another cache line for that per_cpu() storage? That does not make any > sense at all. Because that's how the patches I got from Intel did it, and I kind of liked keeping all the logic in one function. But it's going to go away, it's not safe. >> desc =3D (gate_desc *)vmx->host_idt_base + vector; >> entry =3D gate_offset(desc); >=20 >> --- a/arch/x86/kvm/x86.c >> +++ b/arch/x86/kvm/x86.c >> @@ -6509,10 +6512,40 @@ static int pvclock_gtod_notify(struct notifier= _block *nb, unsigned long unused, >> }; >> #endif >> =20 >> + >> +#define L1D_CACHE_ORDER 3 >=20 > This should use the cache size information and not a hard coded value I= think.=20 Plus it seems wrong. Order 3 is 32K, not 64K, isn't it? :/ > And this whole magic should be documented. >=20 > Aside of that do we really need that manual flush thingy? Is that ucode= > update going to take forever? As Andrew said, this was also copied from Intel's patch, assuming they knew what they were doing. I'll just drop it and just use the microcode MSR. Paolo --jEjZJAWCvxdHghuurZCAfSIC2CbVXZdu0--