From: Tianyu Lan Subject: [RFC Patch 2/3] KVM: Add tlb remote flush callback in kvm_x86_ops. Date: Mon, 4 Jun 2018 09:08:28 +0000 Message-ID: <20180604090749.489-3-Tianyu.Lan@microsoft.com> References: <20180604090749.489-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 , "pbonzini@redhat.com" , "rkrcmar@redhat.com" , "tglx@linutronix.de" , "mingo@redhat.com" , "hpa@zytor.com" , "x86@kernel.org" , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" , KY Srinivasan , "vkuznets@redhat.com" To: unlisted-recipients:; (no To-header on input) Return-path: In-Reply-To: <20180604090749.489-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 tlb remote flush callback and this helps to optimize operation of tlb flush among vcpus for nested virtualization case. Signed-off-by: Lan Tianyu --- arch/x86/include/asm/kvm_host.h | 1 + virt/kvm/kvm_main.c | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_hos= t.h index 0ebe659f2802..aaad43916f9d 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 (*tlb_remote_flush)(struct kvm *kvm); =20 void (*run)(struct kvm_vcpu *vcpu); int (*handle_exit)(struct kvm_vcpu *vcpu); diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index c5f6a552e486..31e2b54c6049 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -251,11 +251,21 @@ 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 tlb_remote_flush first and go back old way when + * return failure. + */ + if (kvm_x86_ops->tlb_remote_flush && + !kvm_x86_ops->tlb_remote_flush(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