From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932586AbdKOPVD (ORCPT ); Wed, 15 Nov 2017 10:21:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42234 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932525AbdKOPUo (ORCPT ); Wed, 15 Nov 2017 10:20:44 -0500 Subject: Re: [PATCH] x86,kvm: move qemu/guest FPU switching out to vcpu_run To: Rik van Riel , Paolo Bonzini 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> <6f73cff1-eddf-7dc6-a93c-31c20e8520d7@redhat.com> <1510757432.21121.294.camel@redhat.com> From: David Hildenbrand Organization: Red Hat GmbH Message-ID: <645ea07b-b5fe-e058-dc19-c1844781cfac@redhat.com> Date: Wed, 15 Nov 2017 16:20:37 +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: <1510757432.21121.294.camel@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 15 Nov 2017 15:20:43 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 15.11.2017 15:50, Rik van Riel wrote: > On Wed, 2017-11-15 at 09:34 +0100, Paolo Bonzini wrote: >> On 14/11/2017 20:40, David Hildenbrand wrote: >>> 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. >> >> Rik may correct me, but I believe that you don't need >> preempt_disable/enable because preempt notifiers do this for you. > > We no longer even need the preempt notifiers to save and > restore the guest FPU state. > > The context switch code itself will save the FPU state > from the registers, into current->thread.fpu.state, when > the VCPU thread gets scheduled out. > > When the VCPU thread gets scheduled in, the scheduler > will restore the guest FPU state from current->thread.fpu.state. > > At this point, vcpu->arch.guest_fpu may be OUT OF DATE. > > However, this is just fine, because we will save the guest > FPU state into vcpu->arch.guest_fpu in kvm_put_guest_fpu, > before we leave the KVM_RUN ioctl, and before we release > the vcpu->mutex. > > In other words, by the time anybody else can examine the > VCPU FPU state (after they obtain the vcpu->mutex), the > vcpu->arch.guest_fpu area will contain the correct FPU > state. > Okay, that answers my question, thanks! -- Thanks, David / dhildenb