From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH v4] KVM: VMX: Enable XSAVE/XRSTORE for guest Date: Mon, 24 May 2010 16:40:51 +0300 Message-ID: <4BFA81E3.1020205@redhat.com> References: <1274695425-14185-1-git-send-email-sheng@linux.intel.com> <4BFA80CC.9070800@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Cc: Marcelo Tosatti , kvm@vger.kernel.org, Dexuan Cui To: Sheng Yang Return-path: Received: from mx1.redhat.com ([209.132.183.28]:60714 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753126Ab0EXNlC (ORCPT ); Mon, 24 May 2010 09:41:02 -0400 In-Reply-To: <4BFA80CC.9070800@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On 05/24/2010 04:36 PM, Avi Kivity wrote: > > may be simplified if we move xcr0 reload back to guest entry (... :) > but make it lazy: > > save_host_state: nothing > set cr4.osxsave: nothing > clear cr4.osxsave: nothing > guest entry: if (gcr4.osxsave && !guest_xcr0_loaded) { > guest_xcr0_loaded = true, load gxcr0 } > load_host_state: if (guest_xcr0_loaded) { guest_xcr0_loaded = false; > load host xcr0 } > fpu switching: if (guest_xcr0_loaded) { guest_xcr0_loaded = false; > load host xcr0 }, do fpu stuff > > So we delay xcr0 reload as late as possible for both entry and exit. > btw, this is similar to how we switch the fpu itself: if-needed-and-not-already-loaded on guest entry, if-loaded on vcpu_put. -- Do not meddle in the internals of kernels, for they are subtle and quick to panic.