From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756844AbdKNVLg (ORCPT ); Tue, 14 Nov 2017 16:11:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52068 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753871AbdKNVL2 (ORCPT ); Tue, 14 Nov 2017 16:11:28 -0500 Message-ID: <1510693882.1080.3.camel@redhat.com> Subject: Re: [PATCH] x86,kvm: move qemu/guest FPU switching out to vcpu_run From: Rik van Riel To: David Hildenbrand , pbonzini@redhat.com Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, rkrcmar@redhat.com, borntraeger@de.ibm.com Date: Tue, 14 Nov 2017 16:11:22 -0500 In-Reply-To: <6f73cff1-eddf-7dc6-a93c-31c20e8520d7@redhat.com> References: <20171114001223.441ea2ca@annuminas.surriel.com> <1510682877.30057.1.camel@redhat.com> <6f73cff1-eddf-7dc6-a93c-31c20e8520d7@redhat.com> Content-Type: multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"; boundary="=-Zc+y/qiT1S8hlBuiiQYJ" Mime-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 14 Nov 2017 21:11:28 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=-Zc+y/qiT1S8hlBuiiQYJ Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, 2017-11-14 at 20:40 +0100, David Hildenbrand wrote: > On 14.11.2017 19:07, Rik van Riel wrote: > > On Tue, 2017-11-14 at 17:57 +0100, David Hildenbrand wrote: > > >=20 > > > > diff --git a/arch/x86/include/asm/kvm_host.h > > > > b/arch/x86/include/asm/kvm_host.h > > > > index c73e493adf07..92e66685249e 100644 > > > > --- a/arch/x86/include/asm/kvm_host.h > > > > +++ b/arch/x86/include/asm/kvm_host.h > > >=20 > > > We should also get rid of guest_fpu_loaded now, right? > >=20 > > Indeed, we no longer need that member. I'll get rid of it. > >=20 > > > emulator_get_fpu() does a kvm_load_guest_fpu(). Doesn't that mean > > > that > > > this is now not needed anymore? (at least when emulator code is > > > called > > > from inside the loop?) > >=20 > > Now that is a very good question! > >=20 > > When called from inside the loop, it is indeed not > > needed. > >=20 > > My question is, can the in-kernel emulator code ever > > be called from OUTSIDE the KVM_RUN ioctl loop? > >=20 > > If so, we need to restore the user FPU context before > > returning from the emulator code. Given that the current > > emulator code does not do that, I suspect this is not > > the case. I also see no path from the kvm ioctl into > > the emulator code, other than via KVM_RUN. > >=20 > > The FPU and XSAVE ioctls all work on the saved > > vcpu->arch.guest_fpu data, and never directly on the > > registers. > >=20 > > Looks like we can completely get rid of .get_fpu and > > .put_fpu... > >=20 > > Unless Paolo has any objection, I'll go do that :) >=20 >=20 > I think we should check all get/put_fpu callers if they need > preempt_disable(). >=20 > E.g. em_fxrstor() needs disabled preemption as we temporarily > save + restore some host register (via fxsave + fxrstor) under some > circumstances that are not saved/restored when switching to/back from > another process. We should double check. >=20 > @Paolo what about complete_userspace_io? It can end up calling > emulate_instruction(). So maybe we have to move load/put fpu further > out > or add special handling. It looks like all complete_userspace_io causes is for the vcpu_run loop to exit, and return to userspace from the KVM_RUN ioctl code. In other words, the userspace qemu FPU context should be restored before we return to userspace, even with my patch (v2 on the way). --=20 All rights reversed --=-Zc+y/qiT1S8hlBuiiQYJ Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAABCAAGBQJaC1v6AAoJEM553pKExN6DaKwH+wXCcuALdEQPmLe8/sefAzcw ng2OU6P+s2TXay+iRCgBI8XNmaaDA/k5oZJqBth0KGQsLv+w4C1zYOs4enELevC+ KvTLan+JXJtnDmPz6je2dQojcyA3wMpSH9mtb/Jmj2LLlVdQwgtR5zFnrEoRO7FJ dlauRrLc8OibA5K/UfK7xvL/XA7vzg3un5DaRIu3PAnbK7AFYashLrooYUZoVl49 O8tTx73q0o+VvAciayt6d3jW9ZO2SwXW42vbn07VBNWF1MOofDIlwY/CdrLTJv4o lgWrnZD/d9CxK+m4mp1T+fX4pu99ljjrymvMb05kXeJ90MFAV0IjXJZ+8OMEvBo= =t4fZ -----END PGP SIGNATURE----- --=-Zc+y/qiT1S8hlBuiiQYJ--