public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: VMX: call invvpid only when EPT is disabled
@ 2012-03-15  1:44 Davidlohr Bueso
  2012-03-15  9:53 ` Avi Kivity
  0 siblings, 1 reply; 2+ messages in thread
From: Davidlohr Bueso @ 2012-03-15  1:44 UTC (permalink / raw)
  To: Avi Kivity, Marcelo Tosatti, Sheng Yang; +Cc: KVM, lkml

From: Davidlohr Bueso <dave@gnu.org>

With EPT enabled it is not required to explicitly run invvpid to invalidate tagged TLB entries, as
KVM does not force vm-exits for cr3 writes and invlpg. Run invvpid only when these instructions
are emulated and shadow pages are used.

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
---
 arch/x86/kvm/vmx.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 2c22fc7..51c7fb9 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -2861,12 +2861,13 @@ static void exit_lmode(struct kvm_vcpu *vcpu)
 
 static void vmx_flush_tlb(struct kvm_vcpu *vcpu)
 {
-	vpid_sync_context(to_vmx(vcpu));
 	if (enable_ept) {
 		if (!VALID_PAGE(vcpu->arch.mmu.root_hpa))
 			return;
 		ept_sync_context(construct_eptp(vcpu->arch.mmu.root_hpa));
 	}
+	else
+		vpid_sync_context(to_vmx(vcpu));
 }
 
 static void vmx_decache_cr0_guest_bits(struct kvm_vcpu *vcpu)
-- 
1.7.4.1




^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] KVM: VMX: call invvpid only when EPT is disabled
  2012-03-15  1:44 [PATCH] KVM: VMX: call invvpid only when EPT is disabled Davidlohr Bueso
@ 2012-03-15  9:53 ` Avi Kivity
  0 siblings, 0 replies; 2+ messages in thread
From: Avi Kivity @ 2012-03-15  9:53 UTC (permalink / raw)
  To: dave; +Cc: Marcelo Tosatti, Sheng Yang, KVM, lkml

On 03/15/2012 03:44 AM, Davidlohr Bueso wrote:
> From: Davidlohr Bueso <dave@gnu.org>
>
> With EPT enabled it is not required to explicitly run invvpid to invalidate tagged TLB entries, as
> KVM does not force vm-exits for cr3 writes and invlpg. Run invvpid only when these instructions
> are emulated and shadow pages are used.
>
> Signed-off-by: Davidlohr Bueso <dave@gnu.org>
> ---
>  arch/x86/kvm/vmx.c |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 2c22fc7..51c7fb9 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -2861,12 +2861,13 @@ static void exit_lmode(struct kvm_vcpu *vcpu)
>  
>  static void vmx_flush_tlb(struct kvm_vcpu *vcpu)
>  {
> -	vpid_sync_context(to_vmx(vcpu));
>  	if (enable_ept) {
>  		if (!VALID_PAGE(vcpu->arch.mmu.root_hpa))
>  			return;
>  		ept_sync_context(construct_eptp(vcpu->arch.mmu.root_hpa));
>  	}
> +	else
> +		vpid_sync_context(to_vmx(vcpu));
>  }
>  
>  static void vmx_decache_cr0_guest_bits(struct kvm_vcpu *vcpu)

This is wrong, cr3 can still be written from host userspace.

To perform this optimization you need to separate the concept of
flushing the guest tlb and the host tlb.  I doubt it's worthwhile
though, won't the ept invalidation flush the entire tlb anyway?

-- 
error compiling committee.c: too many arguments to function


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-03-15  9:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-15  1:44 [PATCH] KVM: VMX: call invvpid only when EPT is disabled Davidlohr Bueso
2012-03-15  9:53 ` Avi Kivity

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox