From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758136AbdKPEVr (ORCPT ); Wed, 15 Nov 2017 23:21:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56984 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751455AbdKPEVh (ORCPT ); Wed, 15 Nov 2017 23:21:37 -0500 Message-ID: <1510806094.21121.303.camel@redhat.com> Subject: Re: [PATCH 1/2] x86,kvm: move qemu/guest FPU switching out to vcpu_run From: Rik van Riel To: Quan Xu , "quan.xu04@gmail.com" , pbonzini@redhat.com Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, david@redhat.com, borntraeger@de.ibm.com, tglx@linutronix.de, rkrcmar@redhat.com Date: Wed, 15 Nov 2017 23:21:34 -0500 In-Reply-To: References: <20171114215424.32214-1-riel@redhat.com> <20171114215424.32214-2-riel@redhat.com> <2e83dd3f-8f03-03ac-45e0-f2fae1d17013@gmail.com> <1510756981.21121.291.camel@redhat.com> Organization: Red Hat, Inc Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 16 Nov 2017 04:21:37 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2017-11-16 at 10:50 +0800, Quan Xu wrote: > > On 2017-11-15 22:43, Rik van Riel wrote: > > Can you explain why you believe that? > > for example, a vcpu thread is running in kvm mode under cretical > condition to stop. QEMU send an IPI to cause a VM-exit to happen > immediately, and this IPI doesn't make vcpu return to QEMU. IIUC > this vcpu thread will still continue to run in kvm mode when is > waked up at targer machine. with your patch, I don't see a chance > to load guest FPU or XSTATE, until return to QEMU and run kvm mode > again. > > then the FPU or XSTATE status is inconsistent for a small window, > what's  > even > worse is that the vcpu is running. > > Did I misunderstand? At context switch time, the context switch code will save the guest FPU state to current->thread.fpu when the VCPU thread is scheduled out. When the VCPU thread is scheduled back in, the context switch code will restore current->thread.fpu to the FPU registers. The VCPU thread will never run with anything else than the guest FPU state, while inside the KVM_RUN code.