Return-Path: Received: from mail.linutronix.de (146.0.238.70:993) by crypto-ml.lab.linutronix.de with IMAP4-SSL for ; 29 Jun 2018 14:18:56 -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 1fYsYa-0007GJ-Ka for speck@linutronix.de; Fri, 29 Jun 2018 14:31:21 +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 B14907DAC6 for ; Fri, 29 Jun 2018 12:31:13 +0000 (UTC) Received: from [10.36.116.92] (ovpn-116-92.ams2.redhat.com [10.36.116.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2C6092026D68 for ; Fri, 29 Jun 2018 12:31:13 +0000 (UTC) Subject: [MODERATED] Re: [PATCH v4 2/8] [PATCH v4 2/8] Linux Patch #2 References: <20180623135445.576988756@localhost.localdomain> <20180627155448.GF24227@zn.tnic> From: Paolo Bonzini Message-ID: <3270ad99-2008-ccea-8e0a-d3fbf7fc4e50@redhat.com> Date: Fri, 29 Jun 2018 14:31:11 +0200 MIME-Version: 1.0 In-Reply-To: <20180627155448.GF24227@zn.tnic> Content-Type: multipart/mixed; boundary="KHIfZxhuaekuRy1lyPZYQsVvm7FToHBMS"; protected-headers="v1" To: speck@linutronix.de List-ID: This is an OpenPGP/MIME encrypted message (RFC 4880 and 3156) --KHIfZxhuaekuRy1lyPZYQsVvm7FToHBMS Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable On 27/06/2018 17:54, speck for Borislav Petkov wrote: >> + * If vmentry_l1d_flush is 1, each vmexit handler is responsible fo= r >> + * setting vcpu->arch.vcpu_unconfined. Currently this happens in t= he >> + * following cases: >> + * - vmlaunch/vmresume: we do not want the cache to be cleared by a= >> + * nested hypervisor *and* by KVM on bare metal, so we just do it= >> + * on every nested entry. Nested hypervisors do not bother clear= ing >> + * the cache. >> + * - anything that runs the emulator (the slow paths for EPT miscon= fig >> + * or I/O instruction) >> + * - anything that can cause get_user_pages (EPT violation, and aga= in >> + * the slow paths for EPT misconfig or I/O instruction) >> + * - anything that can run code outside KVM (external interrupt, >> + * which can run interrupt handlers or irqs; or the sched_in >> + * preempt notifier) >> + */ >=20 > I sure hope we won't miss a case in the future... :-\ We're already missing one; we cannot detect external interrupts that happen between the vmexit and vmentry. We can do two things about it: 1) run most vmexit handlers (the list would be basically the same as above) with interrupts disabled, and change vmentry_l1d_flush=3D1 to whitelist those vmexit handlers. The interrupts would be acknowledged after vmentry, adding about 2000 clock cycles latency to interrupts delivered during vmexit handling. 2) handle at least the common case of softirqs by adding some kind of "# of times softirqs were run" percpu variable. Or (I should probably feel dirty for suggesting it) use rdtsc to find vmexits that take suspiciously long (>2500 clock cycles?) and flush the cache unconditionally. Paolo --KHIfZxhuaekuRy1lyPZYQsVvm7FToHBMS--