From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: Re: [PATCH v2 2/2] KVM: Fetch guest cr3 from hardware on demand Date: Wed, 22 Dec 2010 11:44:16 -0200 Message-ID: <20101222134416.GA10696@amt.cnet> References: <1292852772-24247-1-git-send-email-avi@redhat.com> <1292852772-24247-3-git-send-email-avi@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: kvm@vger.kernel.org To: Avi Kivity Return-path: Received: from mx1.redhat.com ([209.132.183.28]:60950 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752865Ab0LVNoW (ORCPT ); Wed, 22 Dec 2010 08:44:22 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oBMDiLPq003001 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 22 Dec 2010 08:44:22 -0500 Content-Disposition: inline In-Reply-To: <1292852772-24247-3-git-send-email-avi@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Mon, Dec 20, 2010 at 03:46:12PM +0200, Avi Kivity wrote: > Instead of syncing the guest cr3 every exit, which is expensince on vmx > with ept enabled, sync it only on demand. > > Signed-off-by: Avi Kivity > --- > arch/x86/include/asm/kvm_host.h | 2 ++ > arch/x86/kvm/kvm_cache_regs.h | 2 ++ > arch/x86/kvm/svm.c | 5 +++++ > arch/x86/kvm/vmx.c | 23 +++++++++++++++++------ > 4 files changed, 26 insertions(+), 6 deletions(-) > > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > index 4461429..07a20f4 100644 > --- a/arch/x86/include/asm/kvm_host.h > +++ b/arch/x86/include/asm/kvm_host.h > @@ -117,6 +117,7 @@ enum kvm_reg { > > enum kvm_reg_ex { > VCPU_EXREG_PDPTR = NR_VCPU_REGS, > + VCPU_EXREG_CR3, > }; > > enum { > @@ -533,6 +534,7 @@ struct kvm_x86_ops { > struct kvm_segment *var, int seg); > void (*get_cs_db_l_bits)(struct kvm_vcpu *vcpu, int *db, int *l); > void (*decache_cr0_guest_bits)(struct kvm_vcpu *vcpu); > + void (*decache_cr3)(struct kvm_vcpu *vcpu); > void (*decache_cr4_guest_bits)(struct kvm_vcpu *vcpu); > void (*set_cr0)(struct kvm_vcpu *vcpu, unsigned long cr0); > void (*set_cr3)(struct kvm_vcpu *vcpu, unsigned long cr3); > diff --git a/arch/x86/kvm/kvm_cache_regs.h b/arch/x86/kvm/kvm_cache_regs.h > index a6bf8db..3377d53 100644 > --- a/arch/x86/kvm/kvm_cache_regs.h > +++ b/arch/x86/kvm/kvm_cache_regs.h > @@ -75,6 +75,8 @@ static inline ulong kvm_read_cr4_bits(struct kvm_vcpu *vcpu, ulong mask) > > static inline ulong kvm_read_cr3(struct kvm_vcpu *vcpu) > { > + if (!test_bit(VCPU_EXREG_CR3, (ulong *)&vcpu->arch.regs_avail)) > + kvm_x86_ops->decache_cr3(vcpu); > return vcpu->arch.cr3; > } Should mark register available on vcpu->arch.cr3 assignment (kvm_set_cr3, kvm_set_sregs, etc), so that subsequent cr3 read does not use decache value.