From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932151AbdKNTkm (ORCPT ); Tue, 14 Nov 2017 14:40:42 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51166 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932124AbdKNTkZ (ORCPT ); Tue, 14 Nov 2017 14:40:25 -0500 Subject: Re: [PATCH] x86,kvm: move qemu/guest FPU switching out to vcpu_run To: Rik van Riel , pbonzini@redhat.com Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, rkrcmar@redhat.com, borntraeger@de.ibm.com References: <20171114001223.441ea2ca@annuminas.surriel.com> <1510682877.30057.1.camel@redhat.com> From: David Hildenbrand Organization: Red Hat GmbH Message-ID: <6f73cff1-eddf-7dc6-a93c-31c20e8520d7@redhat.com> Date: Tue, 14 Nov 2017 20:40:22 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <1510682877.30057.1.camel@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 14 Nov 2017 19:40:24 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 14.11.2017 19:07, Rik van Riel wrote: > On Tue, 2017-11-14 at 17:57 +0100, David Hildenbrand wrote: >> >>> 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 >> >> We should also get rid of guest_fpu_loaded now, right? > > Indeed, we no longer need that member. I'll get rid of it. > >> 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?) > > Now that is a very good question! > > When called from inside the loop, it is indeed not > needed. > > My question is, can the in-kernel emulator code ever > be called from OUTSIDE the KVM_RUN ioctl loop? > > 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. > > The FPU and XSAVE ioctls all work on the saved > vcpu->arch.guest_fpu data, and never directly on the > registers. > > Looks like we can completely get rid of .get_fpu and > .put_fpu... > > Unless Paolo has any objection, I'll go do that :) I think we should check all get/put_fpu callers if they need preempt_disable(). 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. @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. -- Thanks, David / dhildenb