Skip to content

Commit 0277022

Browse files
committed
KVM: x86/mmu: Declare flush_remote_tlbs{_range}() hooks iff HYPERV!=n
Declare the kvm_x86_ops hooks used to wire up paravirt TLB flushes when running under Hyper-V if and only if CONFIG_HYPERV!=n. Wrapping yet more code with IS_ENABLED(CONFIG_HYPERV) eliminates a handful of conditional branches, and makes it super obvious why the hooks *might* be valid. Cc: Vitaly Kuznetsov <vkuznets@redhat.com> Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com> Link: https://lore.kernel.org/r/20231018192325.1893896-1-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent e9e60c8 commit 0277022

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

arch/x86/include/asm/kvm-x86-ops.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ KVM_X86_OP(set_rflags)
5555
KVM_X86_OP(get_if_flag)
5656
KVM_X86_OP(flush_tlb_all)
5757
KVM_X86_OP(flush_tlb_current)
58+
#if IS_ENABLED(CONFIG_HYPERV)
5859
KVM_X86_OP_OPTIONAL(flush_remote_tlbs)
5960
KVM_X86_OP_OPTIONAL(flush_remote_tlbs_range)
61+
#endif
6062
KVM_X86_OP(flush_tlb_gva)
6163
KVM_X86_OP(flush_tlb_guest)
6264
KVM_X86_OP(vcpu_pre_run)

arch/x86/include/asm/kvm_host.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,9 +1614,11 @@ struct kvm_x86_ops {
16141614

16151615
void (*flush_tlb_all)(struct kvm_vcpu *vcpu);
16161616
void (*flush_tlb_current)(struct kvm_vcpu *vcpu);
1617+
#if IS_ENABLED(CONFIG_HYPERV)
16171618
int (*flush_remote_tlbs)(struct kvm *kvm);
16181619
int (*flush_remote_tlbs_range)(struct kvm *kvm, gfn_t gfn,
16191620
gfn_t nr_pages);
1621+
#endif
16201622

16211623
/*
16221624
* Flush any TLB entries associated with the given GVA.
@@ -1825,6 +1827,7 @@ static inline struct kvm *kvm_arch_alloc_vm(void)
18251827
#define __KVM_HAVE_ARCH_VM_FREE
18261828
void kvm_arch_free_vm(struct kvm *kvm);
18271829

1830+
#if IS_ENABLED(CONFIG_HYPERV)
18281831
#define __KVM_HAVE_ARCH_FLUSH_REMOTE_TLBS
18291832
static inline int kvm_arch_flush_remote_tlbs(struct kvm *kvm)
18301833
{
@@ -1836,6 +1839,15 @@ static inline int kvm_arch_flush_remote_tlbs(struct kvm *kvm)
18361839
}
18371840

18381841
#define __KVM_HAVE_ARCH_FLUSH_REMOTE_TLBS_RANGE
1842+
static inline int kvm_arch_flush_remote_tlbs_range(struct kvm *kvm, gfn_t gfn,
1843+
u64 nr_pages)
1844+
{
1845+
if (!kvm_x86_ops.flush_remote_tlbs_range)
1846+
return -EOPNOTSUPP;
1847+
1848+
return static_call(kvm_x86_flush_remote_tlbs_range)(kvm, gfn, nr_pages);
1849+
}
1850+
#endif /* CONFIG_HYPERV */
18391851

18401852
#define kvm_arch_pmi_in_guest(vcpu) \
18411853
((vcpu) && (vcpu)->arch.handling_intr_from_guest)

arch/x86/kvm/mmu/mmu.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,11 @@ static inline unsigned long kvm_mmu_get_guest_pgd(struct kvm_vcpu *vcpu,
271271

272272
static inline bool kvm_available_flush_remote_tlbs_range(void)
273273
{
274+
#if IS_ENABLED(CONFIG_HYPERV)
274275
return kvm_x86_ops.flush_remote_tlbs_range;
275-
}
276-
277-
int kvm_arch_flush_remote_tlbs_range(struct kvm *kvm, gfn_t gfn, u64 nr_pages)
278-
{
279-
if (!kvm_x86_ops.flush_remote_tlbs_range)
280-
return -EOPNOTSUPP;
281-
282-
return static_call(kvm_x86_flush_remote_tlbs_range)(kvm, gfn, nr_pages);
276+
#else
277+
return false;
278+
#endif
283279
}
284280

285281
static gfn_t kvm_mmu_page_get_gfn(struct kvm_mmu_page *sp, int index);

0 commit comments

Comments
 (0)