From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tianyu Lan Subject: [PATCH V2 2/5] KVM: Add tlb remote flush callback in kvm_x86_ops. Date: Mon, 9 Jul 2018 09:02:41 +0000 Message-ID: <20180709090218.15342-3-Tianyu.Lan@microsoft.com> References: <20180709090218.15342-1-Tianyu.Lan@microsoft.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Cc: Tianyu Lan , KY Srinivasan , Haiyang Zhang , Stephen Hemminger , "tglx@linutronix.de" , "mingo@redhat.com" , "hpa@zytor.com" , "x86@kernel.org" , "pbonzini@redhat.com" , "rkrcmar@redhat.com" , "devel@linuxdriverproject.org" , "linux-kernel@vger.kernel.org" , "kvm@vger.kernel.org" , "Michael Kelley (EOSG)" , "vkuznets@redhat.com" To: unlisted-recipients:; (no To-header on input) Return-path: In-Reply-To: <20180709090218.15342-1-Tianyu.Lan@microsoft.com> Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org 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 --- Change since v1: Add kvm_arch_hv_flush_remote_tlb() to avoid compilation issue for non-x86 platform. --- arch/x86/include/asm/kvm_host.h | 11 +++++++++++ include/linux/kvm_host.h | 7 +++++++ virt/kvm/kvm_main.c | 11 ++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_hos= t.h index c13cd28d9d1b..d89e4204816c 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -973,6 +973,7 @@ struct kvm_x86_ops { void (*set_rflags)(struct kvm_vcpu *vcpu, unsigned long rflags); =20 void (*tlb_flush)(struct kvm_vcpu *vcpu, bool invalidate_gpa); + int (*hv_tlb_remote_flush)(struct kvm *kvm); =20 void (*run)(struct kvm_vcpu *vcpu); int (*handle_exit)(struct kvm_vcpu *vcpu); @@ -1117,6 +1118,16 @@ static inline void kvm_arch_free_vm(struct kvm *kvm) return kvm_x86_ops->vm_free(kvm); } =20 +#define __KVM_HAVE_HV_FLUSH_REMOTE_TLB +static inline int kvm_arch_hv_flush_remote_tlb(struct kvm *kvm) +{ + if (kvm_x86_ops->hv_tlb_remote_flush && + !kvm_x86_ops->hv_tlb_remote_flush(kvm)) + return 0; + else + return -EFAULT; +} + int kvm_mmu_module_init(void); void kvm_mmu_module_exit(void); =20 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 4ee7bc548a83..0c2c36cb041b 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -827,6 +827,13 @@ static inline void kvm_arch_free_vm(struct kvm *kvm) } #endif =20 +#ifndef __KVM_HAVE_HV_FLUSH_REMOTE_TLB +static inline int kvm_arch_hv_flush_remote_tlb(struct kvm *kvm) +{ + return -EFAULT; +} +#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); diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 8b47507faab5..c2b5e3273848 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -256,11 +256,20 @@ bool kvm_make_all_cpus_request(struct kvm *kvm, unsig= ned int req) #ifndef CONFIG_HAVE_KVM_ARCH_TLB_FLUSH_ALL void kvm_flush_remote_tlbs(struct kvm *kvm) { + long dirty_count; + + /* + * Call kvm_arch_hv_tlb_remote first and go back old way when + * return failure. + */ + if (!kvm_arch_hv_flush_remote_tlb(kvm)) + return; + /* * Read tlbs_dirty before setting KVM_REQ_TLB_FLUSH in * kvm_make_all_cpus_request. */ - long dirty_count =3D smp_load_acquire(&kvm->tlbs_dirty); + dirty_count =3D smp_load_acquire(&kvm->tlbs_dirty); =20 /* * We want to publish modifications to the page tables before reading --=20 2.14.3