Skip to content

Commit b08660e

Browse files
Tianyu Lanbonzini
authored andcommitted
KVM: x86: Add tlb remote flush callback in kvm_x86_ops.
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>
1 parent 60cfce4 commit b08660e

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,7 @@ struct kvm_x86_ops {
985985
void (*set_rflags)(struct kvm_vcpu *vcpu, unsigned long rflags);
986986

987987
void (*tlb_flush)(struct kvm_vcpu *vcpu, bool invalidate_gpa);
988+
int (*tlb_remote_flush)(struct kvm *kvm);
988989

989990
/*
990991
* Flush any TLB entries associated with the given GVA.
@@ -1145,6 +1146,16 @@ static inline void kvm_arch_free_vm(struct kvm *kvm)
11451146
return kvm_x86_ops->vm_free(kvm);
11461147
}
11471148

1149+
#define __KVM_HAVE_ARCH_FLUSH_REMOTE_TLB
1150+
static inline int kvm_arch_flush_remote_tlb(struct kvm *kvm)
1151+
{
1152+
if (kvm_x86_ops->tlb_remote_flush &&
1153+
!kvm_x86_ops->tlb_remote_flush(kvm))
1154+
return 0;
1155+
else
1156+
return -ENOTSUPP;
1157+
}
1158+
11481159
int kvm_mmu_module_init(void);
11491160
void kvm_mmu_module_exit(void);
11501161

include/linux/kvm_host.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,13 @@ static inline void kvm_arch_free_vm(struct kvm *kvm)
834834
}
835835
#endif
836836

837+
#ifndef __KVM_HAVE_ARCH_FLUSH_REMOTE_TLB
838+
static inline int kvm_arch_flush_remote_tlb(struct kvm *kvm)
839+
{
840+
return -ENOTSUPP;
841+
}
842+
#endif
843+
837844
#ifdef __KVM_HAVE_ARCH_NONCOHERENT_DMA
838845
void kvm_arch_register_noncoherent_dma(struct kvm *kvm);
839846
void kvm_arch_unregister_noncoherent_dma(struct kvm *kvm);

virt/kvm/kvm_main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ void kvm_flush_remote_tlbs(struct kvm *kvm)
273273
* kvm_make_all_cpus_request() reads vcpu->mode. We reuse that
274274
* barrier here.
275275
*/
276-
if (kvm_make_all_cpus_request(kvm, KVM_REQ_TLB_FLUSH))
276+
if (!kvm_arch_flush_remote_tlb(kvm)
277+
|| kvm_make_all_cpus_request(kvm, KVM_REQ_TLB_FLUSH))
277278
++kvm->stat.remote_tlb_flush;
278279
cmpxchg(&kvm->tlbs_dirty, dirty_count, 0);
279280
}

0 commit comments

Comments
 (0)