Re: [PATCH v2 2/2] KVM: Fetch guest cr3 from hardware on demand

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <avi@xxxxxxxxxx>
> ---
>  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.

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux