Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+18 -8
+2
arch/x86/include/asm/kvm-x86-ops.h
··· 55 55 KVM_X86_OP(get_if_flag) 56 56 KVM_X86_OP(flush_tlb_all) 57 57 KVM_X86_OP(flush_tlb_current) 58 + #if IS_ENABLED(CONFIG_HYPERV) 58 59 KVM_X86_OP_OPTIONAL(flush_remote_tlbs) 59 60 KVM_X86_OP_OPTIONAL(flush_remote_tlbs_range) 61 + #endif 60 62 KVM_X86_OP(flush_tlb_gva) 61 63 KVM_X86_OP(flush_tlb_guest) 62 64 KVM_X86_OP(vcpu_pre_run)
+12
arch/x86/include/asm/kvm_host.h
··· 1614 1614 1615 1615 void (*flush_tlb_all)(struct kvm_vcpu *vcpu); 1616 1616 void (*flush_tlb_current)(struct kvm_vcpu *vcpu); 1617 + #if IS_ENABLED(CONFIG_HYPERV) 1617 1618 int (*flush_remote_tlbs)(struct kvm *kvm); 1618 1619 int (*flush_remote_tlbs_range)(struct kvm *kvm, gfn_t gfn, 1619 1620 gfn_t nr_pages); 1621 + #endif 1620 1622 1621 1623 /* 1622 1624 * Flush any TLB entries associated with the given GVA. ··· 1827 1825 #define __KVM_HAVE_ARCH_VM_FREE 1828 1826 void kvm_arch_free_vm(struct kvm *kvm); 1829 1827 1828 + #if IS_ENABLED(CONFIG_HYPERV) 1830 1829 #define __KVM_HAVE_ARCH_FLUSH_REMOTE_TLBS 1831 1830 static inline int kvm_arch_flush_remote_tlbs(struct kvm *kvm) 1832 1831 { ··· 1839 1836 } 1840 1837 1841 1838 #define __KVM_HAVE_ARCH_FLUSH_REMOTE_TLBS_RANGE 1839 + static inline int kvm_arch_flush_remote_tlbs_range(struct kvm *kvm, gfn_t gfn, 1840 + u64 nr_pages) 1841 + { 1842 + if (!kvm_x86_ops.flush_remote_tlbs_range) 1843 + return -EOPNOTSUPP; 1844 + 1845 + return static_call(kvm_x86_flush_remote_tlbs_range)(kvm, gfn, nr_pages); 1846 + } 1847 + #endif /* CONFIG_HYPERV */ 1842 1848 1843 1849 #define kvm_arch_pmi_in_guest(vcpu) \ 1844 1850 ((vcpu) && (vcpu)->arch.handling_intr_from_guest)
+4 -8
arch/x86/kvm/mmu/mmu.c
··· 271 271 272 272 static inline bool kvm_available_flush_remote_tlbs_range(void) 273 273 { 274 + #if IS_ENABLED(CONFIG_HYPERV) 274 275 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 283 279 } 284 280 285 281 static gfn_t kvm_mmu_page_get_gfn(struct kvm_mmu_page *sp, int index);