KVM: x86: Add tlb remote flush callback in kvm_x86_ops.
authorTianyu Lan <Tianyu.Lan@microsoft.com>
Thu, 19 Jul 2018 08:40:17 +0000 (08:40 +0000)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 6 Aug 2018 15:59:06 +0000 (17:59 +0200)
This patch is to provide a way for platforms to register hv tlb remote
flush callback and this helps to optimize operation of tlb flush
among vcpus for nested virtualization case.

Signed-off-by: Lan Tianyu <Tianyu.Lan@microsoft.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/include/asm/kvm_host.h
include/linux/kvm_host.h
virt/kvm/kvm_main.c

index 75ab578c3f6a60b77902653fe1bab024d2031b75..150937e64f6372d2b209f2384d391c399547ffed 100644 (file)
@@ -985,6 +985,7 @@ struct kvm_x86_ops {
        void (*set_rflags)(struct kvm_vcpu *vcpu, unsigned long rflags);
 
        void (*tlb_flush)(struct kvm_vcpu *vcpu, bool invalidate_gpa);
+       int  (*tlb_remote_flush)(struct kvm *kvm);
 
        /*
         * Flush any TLB entries associated with the given GVA.
@@ -1145,6 +1146,16 @@ static inline void kvm_arch_free_vm(struct kvm *kvm)
        return kvm_x86_ops->vm_free(kvm);
 }
 
+#define __KVM_HAVE_ARCH_FLUSH_REMOTE_TLB
+static inline int kvm_arch_flush_remote_tlb(struct kvm *kvm)
+{
+       if (kvm_x86_ops->tlb_remote_flush &&
+           !kvm_x86_ops->tlb_remote_flush(kvm))
+               return 0;
+       else
+               return -ENOTSUPP;
+}
+
 int kvm_mmu_module_init(void);
 void kvm_mmu_module_exit(void);
 
index 2840ac74a3d7291aa1b66cc5a1b06352acdb1310..7c7362dd2faa9c549500756713ea5512c973cfcf 100644 (file)
@@ -834,6 +834,13 @@ static inline void kvm_arch_free_vm(struct kvm *kvm)
 }
 #endif
 
+#ifndef __KVM_HAVE_ARCH_FLUSH_REMOTE_TLB
+static inline int kvm_arch_flush_remote_tlb(struct kvm *kvm)
+{
+       return -ENOTSUPP;
+}
+#endif
+
 #ifdef __KVM_HAVE_ARCH_NONCOHERENT_DMA
 void kvm_arch_register_noncoherent_dma(struct kvm *kvm);
 void kvm_arch_unregister_noncoherent_dma(struct kvm *kvm);
index 8f461e0ed38219a5e953c4dc9412f877dbafd5f6..74544d20bbf8b862c9c33d2d269a31207b00ad86 100644 (file)
@@ -273,7 +273,8 @@ void kvm_flush_remote_tlbs(struct kvm *kvm)
         * kvm_make_all_cpus_request() reads vcpu->mode. We reuse that
         * barrier here.
         */
-       if (kvm_make_all_cpus_request(kvm, KVM_REQ_TLB_FLUSH))
+       if (!kvm_arch_flush_remote_tlb(kvm)
+           || kvm_make_all_cpus_request(kvm, KVM_REQ_TLB_FLUSH))
                ++kvm->stat.remote_tlb_flush;
        cmpxchg(&kvm->tlbs_dirty, dirty_count, 0);
 }