From patchwork Tue Sep 11 09:20:16 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Hao, Xudong" X-Patchwork-Id: 1436171 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id AB826DFAF3 for ; Tue, 11 Sep 2012 09:20:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757919Ab2IKJUX (ORCPT ); Tue, 11 Sep 2012 05:20:23 -0400 Received: from mga09.intel.com ([134.134.136.24]:35805 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757826Ab2IKJUV convert rfc822-to-8bit (ORCPT ); Tue, 11 Sep 2012 05:20:21 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 11 Sep 2012 02:20:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.80,402,1344236400"; d="scan'208";a="201390269" Received: from fmsmsx106.amr.corp.intel.com ([10.19.9.37]) by orsmga002.jf.intel.com with ESMTP; 11 Sep 2012 02:20:20 -0700 Received: from fmsmsx153.amr.corp.intel.com (10.19.17.7) by FMSMSX106.amr.corp.intel.com (10.19.9.37) with Microsoft SMTP Server (TLS) id 14.1.355.2; Tue, 11 Sep 2012 02:20:20 -0700 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by FMSMSX153.amr.corp.intel.com (10.19.17.7) with Microsoft SMTP Server (TLS) id 14.1.355.2; Tue, 11 Sep 2012 02:20:19 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.92]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.239]) with mapi id 14.01.0355.002; Tue, 11 Sep 2012 17:20:18 +0800 From: "Hao, Xudong" To: Avi Kivity CC: "kvm@vger.kernel.org" , "Zhang, Xiantao" , "Joerg.Roedel@amd.com" Subject: RE: [PATCH v2] kvm/fpu: Enable fully eager restore kvm FPU Thread-Topic: [PATCH v2] kvm/fpu: Enable fully eager restore kvm FPU Thread-Index: AQHNiwUIGcYb6+AWLE+yMSKYIyMu4Zd7NCyAgAFWn6D//+jKAIAGaHIw///eXICAAcmrcP//xRSAABH5OxA= Date: Tue, 11 Sep 2012 09:20:16 +0000 Message-ID: <403610A45A2B5242BD291EDAE8B37D300FEBF79C@SHSMSX102.ccr.corp.intel.com> References: <1346808370-28376-1-git-send-email-xudong.hao@intel.com> <50474FD7.3020301@redhat.com> <403610A45A2B5242BD291EDAE8B37D300FEBC4CF@SHSMSX102.ccr.corp.intel.com> <50485BC8.4050807@redhat.com> <403610A45A2B5242BD291EDAE8B37D300FEBECEB@SHSMSX102.ccr.corp.intel.com> <504D9FAB.7020708@redhat.com> <403610A45A2B5242BD291EDAE8B37D300FEBF5A2@SHSMSX102.ccr.corp.intel.com> <504EEE29.9040309@redhat.com> In-Reply-To: <504EEE29.9040309@redhat.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org > -----Original Message----- > From: Avi Kivity [mailto:avi@redhat.com] > Sent: Tuesday, September 11, 2012 3:54 PM > To: Hao, Xudong > Cc: kvm@vger.kernel.org; Zhang, Xiantao; Joerg.Roedel@amd.com > Subject: Re: [PATCH v2] kvm/fpu: Enable fully eager restore kvm FPU > > On 09/11/2012 09:43 AM, Hao, Xudong wrote: > >> -----Original Message----- > >> From: Avi Kivity [mailto:avi@redhat.com] > >> Sent: Monday, September 10, 2012 4:07 PM > >> To: Hao, Xudong > >> Cc: kvm@vger.kernel.org; Zhang, Xiantao; Joerg.Roedel@amd.com > >> Subject: Re: [PATCH v2] kvm/fpu: Enable fully eager restore kvm FPU > >> > >> > > >> > Avi, I'm not sure if I fully understand of you. Do you mean enter guest with > a > >> fpu_active=0 and then fpu does not restore? > >> > >> Yes. > >> > >> > If so, I will add fpu_active=1 in the no-lazy case. > >> > > >> > - kvm_make_request(KVM_REQ_DEACTIVATE_FPU, vcpu); > >> > + if (kvm_read_cr4_bits(vcpu, X86_CR4_OSXSAVE) && > >> > + (vcpu->arch.xcr0 & ~((u64)KVM_XSTATE_LAZY))) { > >> > + kvm_x86_ops->fpu_activate(vcpu); > >> > + vcpu->fpu_active=1; > >> > + } > >> > + else > >> > + kvm_make_request(KVM_REQ_DEACTIVATE_FPU, vcpu); > >> > > >> > >> It doesn't help here. > >> > >> 1 guest boot > >> 2 kvm_userspace_exit (deactivates fpu) > >> 3 XSETBV exit that sets xcr0.new_bit > >> 4 kvm_enter > >> > >> There is no call to kvm_put_guest_fpu() between 3 and 4, you need > >> something in __kvm_set_xcr() to activate the fpu. > >> > > > > Yes, it's code path when enable xsave in guest, I'll add fpu activate there and > remain v2 patch in kvm_put_guest_fpu(). > > > > @@ -554,6 +554,8 @@ int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, > u64 xcr) > > xcr0 = xcr; > > if (kvm_x86_ops->get_cpl(vcpu) != 0) > > return 1; > > + if (xcr0 & ~((u64)KVM_XSTATE_LAZY)) > > + kvm_x86_ops->fpu_activate(vcpu); > > if (!(xcr0 & XSTATE_FP)) > > return 1; > > if ((xcr0 & XSTATE_YMM) && !(xcr0 & XSTATE_SSE)) > > > >> Note you also need to consider writes to xcr0 and cr4 that happen in the > >> reverse order due to live migration. > >> > > > > I'm confused of this, doesn't setting cr4 firstly then xcr0? > > Do you mean current live migration has a reverse order, or it must be a > reverse order with my eager restore patch? > > I mean I want the code to work regardless of whether KVM_SET_SREGS or > KVM_SET_XCRS is called first. > Okay, I got it. fpu_active(vcpu) in __kvm_set_xcr () read guest cr0, so KVM_SET_XCRS depends on KVM_SET_SREGS in live migration case. Here only set fpu_active=1 in __kvm_set_xcr(), and clear TS bit in set_cr0 should solve this issue. --- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -3028,6 +3028,8 @@ static void vmx_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0) if (!vcpu->fpu_active) hw_cr0 |= X86_CR0_TS | X86_CR0_MP; + else + hw_cr0 &= ~(X86_CR0_TS | X86_CR0_MP); vmcs_writel(CR0_READ_SHADOW, cr0); vmcs_writel(GUEST_CR0, hw_cr0); diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 20f2266..183cf60 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -560,6 +560,8 @@ int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr) return 1; if (xcr0 & ~host_xcr0) return 1; + if (xcr0 & ~((u64)KVM_XSTATE_LAZY)) + vcpu->fpu_active = 1; vcpu->arch.xcr0 = xcr0; vcpu->guest_xcr0_loaded = 0; return 0;