KVM: VMX: call invvpid only when EPT is disabled
PATCH 1/1 KVM: VMX: call invvpid only when EPT is disabled
From: Davidlohr Bueso <[email protected]>
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.
--- arch/x86/kvm/vmx.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
arch/x86/kvm/vmx.c +2 -1
@@ -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)
Signature · 1 line
1.7.4.1
Quoted 20 lines · Davidlohr Bueso
From: Davidlohr Bueso <[email protected]>
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 <[email protected]>--- arch/x86/kvm/vmx.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)arch/x86/kvm/vmx.c +0
-1@@ -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));
arch/x86/kvm/vmx.c static void exit_lmode(struct kvm_vcpu *vcpu) · line 2873
Quoted 10 lines
arch/x86/kvm/vmx.c +2
-0if (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?
Signature · 1 line
error compiling committee.c: too many arguments to function