Commit f128cf8c authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

KVM: Convert KVM_ARCH_WANT_MMU_NOTIFIER to CONFIG_KVM_GENERIC_MMU_NOTIFIER

Convert KVM_ARCH_WANT_MMU_NOTIFIER into a Kconfig and select it where
appropriate to effectively maintain existing behavior.  Using a proper
Kconfig will simplify building more functionality on top of KVM's
mmu_notifier infrastructure.

Add a forward declaration of kvm_gfn_range to kvm_types.h so that
including arch/powerpc/include/asm/kvm_ppc.h's with CONFIG_KVM=n doesn't
generate warnings due to kvm_gfn_range being undeclared.  PPC defines
hooks for PR vs. HV without guarding them via #ifdeffery, e.g.

  bool (*unmap_gfn_range)(struct kvm *kvm, struct kvm_gfn_range *range);
  bool (*age_gfn)(struct kvm *kvm, struct kvm_gfn_range *range);
  bool (*test_age_gfn)(struct kvm *kvm, struct kvm_gfn_range *range);
  bool (*set_spte_gfn)(struct kvm *kvm, struct kvm_gfn_range *range);

Alternatively, PPC could forward declare kvm_gfn_range, but there's no
good reason not to define it in common KVM.
Acked-by: default avatarAnup Patel <anup@brainfault.org>
Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Reviewed-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
Reviewed-by: default avatarFuad Tabba <tabba@google.com>
Tested-by: default avatarFuad Tabba <tabba@google.com>
Message-Id: <20231027182217.3615211-8-seanjc@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 4a2e993f
...@@ -954,8 +954,6 @@ int __kvm_arm_vcpu_get_events(struct kvm_vcpu *vcpu, ...@@ -954,8 +954,6 @@ int __kvm_arm_vcpu_get_events(struct kvm_vcpu *vcpu,
int __kvm_arm_vcpu_set_events(struct kvm_vcpu *vcpu, int __kvm_arm_vcpu_set_events(struct kvm_vcpu *vcpu,
struct kvm_vcpu_events *events); struct kvm_vcpu_events *events);
#define KVM_ARCH_WANT_MMU_NOTIFIER
void kvm_arm_halt_guest(struct kvm *kvm); void kvm_arm_halt_guest(struct kvm *kvm);
void kvm_arm_resume_guest(struct kvm *kvm); void kvm_arm_resume_guest(struct kvm *kvm);
......
...@@ -22,7 +22,7 @@ menuconfig KVM ...@@ -22,7 +22,7 @@ menuconfig KVM
bool "Kernel-based Virtual Machine (KVM) support" bool "Kernel-based Virtual Machine (KVM) support"
depends on HAVE_KVM depends on HAVE_KVM
select KVM_GENERIC_HARDWARE_ENABLING select KVM_GENERIC_HARDWARE_ENABLING
select MMU_NOTIFIER select KVM_GENERIC_MMU_NOTIFIER
select PREEMPT_NOTIFIERS select PREEMPT_NOTIFIERS
select HAVE_KVM_CPU_RELAX_INTERCEPT select HAVE_KVM_CPU_RELAX_INTERCEPT
select KVM_MMIO select KVM_MMIO
......
...@@ -183,7 +183,6 @@ void kvm_flush_tlb_all(void); ...@@ -183,7 +183,6 @@ void kvm_flush_tlb_all(void);
void kvm_flush_tlb_gpa(struct kvm_vcpu *vcpu, unsigned long gpa); void kvm_flush_tlb_gpa(struct kvm_vcpu *vcpu, unsigned long gpa);
int kvm_handle_mm_fault(struct kvm_vcpu *vcpu, unsigned long badv, bool write); int kvm_handle_mm_fault(struct kvm_vcpu *vcpu, unsigned long badv, bool write);
#define KVM_ARCH_WANT_MMU_NOTIFIER
void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte); void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte);
int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end, bool blockable); int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end, bool blockable);
int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end); int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end);
......
...@@ -26,9 +26,9 @@ config KVM ...@@ -26,9 +26,9 @@ config KVM
select HAVE_KVM_VCPU_ASYNC_IOCTL select HAVE_KVM_VCPU_ASYNC_IOCTL
select KVM_GENERIC_DIRTYLOG_READ_PROTECT select KVM_GENERIC_DIRTYLOG_READ_PROTECT
select KVM_GENERIC_HARDWARE_ENABLING select KVM_GENERIC_HARDWARE_ENABLING
select KVM_GENERIC_MMU_NOTIFIER
select KVM_MMIO select KVM_MMIO
select KVM_XFER_TO_GUEST_WORK select KVM_XFER_TO_GUEST_WORK
select MMU_NOTIFIER
select PREEMPT_NOTIFIERS select PREEMPT_NOTIFIERS
help help
Support hosting virtualized guest machines using Support hosting virtualized guest machines using
......
...@@ -810,8 +810,6 @@ int kvm_mips_mkclean_gpa_pt(struct kvm *kvm, gfn_t start_gfn, gfn_t end_gfn); ...@@ -810,8 +810,6 @@ int kvm_mips_mkclean_gpa_pt(struct kvm *kvm, gfn_t start_gfn, gfn_t end_gfn);
pgd_t *kvm_pgd_alloc(void); pgd_t *kvm_pgd_alloc(void);
void kvm_mmu_free_memory_caches(struct kvm_vcpu *vcpu); void kvm_mmu_free_memory_caches(struct kvm_vcpu *vcpu);
#define KVM_ARCH_WANT_MMU_NOTIFIER
/* Emulation */ /* Emulation */
enum emulation_result update_pc(struct kvm_vcpu *vcpu, u32 cause); enum emulation_result update_pc(struct kvm_vcpu *vcpu, u32 cause);
int kvm_get_badinstr(u32 *opc, struct kvm_vcpu *vcpu, u32 *out); int kvm_get_badinstr(u32 *opc, struct kvm_vcpu *vcpu, u32 *out);
......
...@@ -25,7 +25,7 @@ config KVM ...@@ -25,7 +25,7 @@ config KVM
select HAVE_KVM_EVENTFD select HAVE_KVM_EVENTFD
select HAVE_KVM_VCPU_ASYNC_IOCTL select HAVE_KVM_VCPU_ASYNC_IOCTL
select KVM_MMIO select KVM_MMIO
select MMU_NOTIFIER select KVM_GENERIC_MMU_NOTIFIER
select INTERVAL_TREE select INTERVAL_TREE
select KVM_GENERIC_HARDWARE_ENABLING select KVM_GENERIC_HARDWARE_ENABLING
help help
......
...@@ -62,8 +62,6 @@ ...@@ -62,8 +62,6 @@
#include <linux/mmu_notifier.h> #include <linux/mmu_notifier.h>
#define KVM_ARCH_WANT_MMU_NOTIFIER
#define HPTEG_CACHE_NUM (1 << 15) #define HPTEG_CACHE_NUM (1 << 15)
#define HPTEG_HASH_BITS_PTE 13 #define HPTEG_HASH_BITS_PTE 13
#define HPTEG_HASH_BITS_PTE_LONG 12 #define HPTEG_HASH_BITS_PTE_LONG 12
......
...@@ -42,7 +42,7 @@ config KVM_BOOK3S_64_HANDLER ...@@ -42,7 +42,7 @@ config KVM_BOOK3S_64_HANDLER
config KVM_BOOK3S_PR_POSSIBLE config KVM_BOOK3S_PR_POSSIBLE
bool bool
select KVM_MMIO select KVM_MMIO
select MMU_NOTIFIER select KVM_GENERIC_MMU_NOTIFIER
config KVM_BOOK3S_HV_POSSIBLE config KVM_BOOK3S_HV_POSSIBLE
bool bool
...@@ -85,7 +85,7 @@ config KVM_BOOK3S_64_HV ...@@ -85,7 +85,7 @@ config KVM_BOOK3S_64_HV
tristate "KVM for POWER7 and later using hypervisor mode in host" tristate "KVM for POWER7 and later using hypervisor mode in host"
depends on KVM_BOOK3S_64 && PPC_POWERNV depends on KVM_BOOK3S_64 && PPC_POWERNV
select KVM_BOOK3S_HV_POSSIBLE select KVM_BOOK3S_HV_POSSIBLE
select MMU_NOTIFIER select KVM_GENERIC_MMU_NOTIFIER
select CMA select CMA
help help
Support running unmodified book3s_64 guest kernels in Support running unmodified book3s_64 guest kernels in
...@@ -194,7 +194,7 @@ config KVM_E500V2 ...@@ -194,7 +194,7 @@ config KVM_E500V2
depends on !CONTEXT_TRACKING_USER depends on !CONTEXT_TRACKING_USER
select KVM select KVM
select KVM_MMIO select KVM_MMIO
select MMU_NOTIFIER select KVM_GENERIC_MMU_NOTIFIER
help help
Support running unmodified E500 guest kernels in virtual machines on Support running unmodified E500 guest kernels in virtual machines on
E500v2 host processors. E500v2 host processors.
...@@ -211,7 +211,7 @@ config KVM_E500MC ...@@ -211,7 +211,7 @@ config KVM_E500MC
select KVM select KVM
select KVM_MMIO select KVM_MMIO
select KVM_BOOKE_HV select KVM_BOOKE_HV
select MMU_NOTIFIER select KVM_GENERIC_MMU_NOTIFIER
help help
Support running unmodified E500MC/E5500/E6500 guest kernels in Support running unmodified E500MC/E5500/E6500 guest kernels in
virtual machines on E500MC/E5500/E6500 host processors. virtual machines on E500MC/E5500/E6500 host processors.
......
...@@ -632,9 +632,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) ...@@ -632,9 +632,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
break; break;
#endif #endif
case KVM_CAP_SYNC_MMU: case KVM_CAP_SYNC_MMU:
#if !defined(CONFIG_MMU_NOTIFIER) || !defined(KVM_ARCH_WANT_MMU_NOTIFIER) BUILD_BUG_ON(!IS_ENABLED(CONFIG_KVM_GENERIC_MMU_NOTIFIER));
BUILD_BUG();
#endif
r = 1; r = 1;
break; break;
#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
......
...@@ -267,8 +267,6 @@ struct kvm_vcpu_arch { ...@@ -267,8 +267,6 @@ struct kvm_vcpu_arch {
static inline void kvm_arch_sync_events(struct kvm *kvm) {} static inline void kvm_arch_sync_events(struct kvm *kvm) {}
static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {} static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {}
#define KVM_ARCH_WANT_MMU_NOTIFIER
#define KVM_RISCV_GSTAGE_TLB_MIN_ORDER 12 #define KVM_RISCV_GSTAGE_TLB_MIN_ORDER 12
void kvm_riscv_local_hfence_gvma_vmid_gpa(unsigned long vmid, void kvm_riscv_local_hfence_gvma_vmid_gpa(unsigned long vmid,
......
...@@ -30,7 +30,7 @@ config KVM ...@@ -30,7 +30,7 @@ config KVM
select KVM_GENERIC_HARDWARE_ENABLING select KVM_GENERIC_HARDWARE_ENABLING
select KVM_MMIO select KVM_MMIO
select KVM_XFER_TO_GUEST_WORK select KVM_XFER_TO_GUEST_WORK
select MMU_NOTIFIER select KVM_GENERIC_MMU_NOTIFIER
select PREEMPT_NOTIFIERS select PREEMPT_NOTIFIERS
help help
Support hosting virtualized guest machines. Support hosting virtualized guest machines.
......
...@@ -2141,8 +2141,6 @@ enum { ...@@ -2141,8 +2141,6 @@ enum {
# define kvm_memslots_for_spte_role(kvm, role) __kvm_memslots(kvm, 0) # define kvm_memslots_for_spte_role(kvm, role) __kvm_memslots(kvm, 0)
#endif #endif
#define KVM_ARCH_WANT_MMU_NOTIFIER
int kvm_cpu_has_injectable_intr(struct kvm_vcpu *v); int kvm_cpu_has_injectable_intr(struct kvm_vcpu *v);
int kvm_cpu_has_interrupt(struct kvm_vcpu *vcpu); int kvm_cpu_has_interrupt(struct kvm_vcpu *vcpu);
int kvm_cpu_has_extint(struct kvm_vcpu *v); int kvm_cpu_has_extint(struct kvm_vcpu *v);
......
...@@ -24,7 +24,7 @@ config KVM ...@@ -24,7 +24,7 @@ config KVM
depends on HIGH_RES_TIMERS depends on HIGH_RES_TIMERS
depends on X86_LOCAL_APIC depends on X86_LOCAL_APIC
select PREEMPT_NOTIFIERS select PREEMPT_NOTIFIERS
select MMU_NOTIFIER select KVM_GENERIC_MMU_NOTIFIER
select HAVE_KVM_IRQCHIP select HAVE_KVM_IRQCHIP
select HAVE_KVM_PFNCACHE select HAVE_KVM_PFNCACHE
select HAVE_KVM_IRQFD select HAVE_KVM_IRQFD
......
...@@ -253,7 +253,7 @@ bool kvm_setup_async_pf(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, ...@@ -253,7 +253,7 @@ bool kvm_setup_async_pf(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
int kvm_async_pf_wakeup_all(struct kvm_vcpu *vcpu); int kvm_async_pf_wakeup_all(struct kvm_vcpu *vcpu);
#endif #endif
#ifdef KVM_ARCH_WANT_MMU_NOTIFIER #ifdef CONFIG_KVM_GENERIC_MMU_NOTIFIER
union kvm_mmu_notifier_arg { union kvm_mmu_notifier_arg {
pte_t pte; pte_t pte;
}; };
...@@ -783,7 +783,7 @@ struct kvm { ...@@ -783,7 +783,7 @@ struct kvm {
struct hlist_head irq_ack_notifier_list; struct hlist_head irq_ack_notifier_list;
#endif #endif
#if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER) #ifdef CONFIG_KVM_GENERIC_MMU_NOTIFIER
struct mmu_notifier mmu_notifier; struct mmu_notifier mmu_notifier;
unsigned long mmu_invalidate_seq; unsigned long mmu_invalidate_seq;
long mmu_invalidate_in_progress; long mmu_invalidate_in_progress;
...@@ -1946,7 +1946,7 @@ extern const struct _kvm_stats_desc kvm_vm_stats_desc[]; ...@@ -1946,7 +1946,7 @@ extern const struct _kvm_stats_desc kvm_vm_stats_desc[];
extern const struct kvm_stats_header kvm_vcpu_stats_header; extern const struct kvm_stats_header kvm_vcpu_stats_header;
extern const struct _kvm_stats_desc kvm_vcpu_stats_desc[]; extern const struct _kvm_stats_desc kvm_vcpu_stats_desc[];
#if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER) #ifdef CONFIG_KVM_GENERIC_MMU_NOTIFIER
static inline int mmu_invalidate_retry(struct kvm *kvm, unsigned long mmu_seq) static inline int mmu_invalidate_retry(struct kvm *kvm, unsigned long mmu_seq)
{ {
if (unlikely(kvm->mmu_invalidate_in_progress)) if (unlikely(kvm->mmu_invalidate_in_progress))
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
struct kvm; struct kvm;
struct kvm_async_pf; struct kvm_async_pf;
struct kvm_device_ops; struct kvm_device_ops;
struct kvm_gfn_range;
struct kvm_interrupt; struct kvm_interrupt;
struct kvm_irq_routing_table; struct kvm_irq_routing_table;
struct kvm_memory_slot; struct kvm_memory_slot;
......
...@@ -92,3 +92,7 @@ config HAVE_KVM_PM_NOTIFIER ...@@ -92,3 +92,7 @@ config HAVE_KVM_PM_NOTIFIER
config KVM_GENERIC_HARDWARE_ENABLING config KVM_GENERIC_HARDWARE_ENABLING
bool bool
config KVM_GENERIC_MMU_NOTIFIER
select MMU_NOTIFIER
bool
...@@ -535,7 +535,7 @@ void kvm_destroy_vcpus(struct kvm *kvm) ...@@ -535,7 +535,7 @@ void kvm_destroy_vcpus(struct kvm *kvm)
} }
EXPORT_SYMBOL_GPL(kvm_destroy_vcpus); EXPORT_SYMBOL_GPL(kvm_destroy_vcpus);
#if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER) #ifdef CONFIG_KVM_GENERIC_MMU_NOTIFIER
static inline struct kvm *mmu_notifier_to_kvm(struct mmu_notifier *mn) static inline struct kvm *mmu_notifier_to_kvm(struct mmu_notifier *mn)
{ {
return container_of(mn, struct kvm, mmu_notifier); return container_of(mn, struct kvm, mmu_notifier);
...@@ -962,14 +962,14 @@ static int kvm_init_mmu_notifier(struct kvm *kvm) ...@@ -962,14 +962,14 @@ static int kvm_init_mmu_notifier(struct kvm *kvm)
return mmu_notifier_register(&kvm->mmu_notifier, current->mm); return mmu_notifier_register(&kvm->mmu_notifier, current->mm);
} }
#else /* !(CONFIG_MMU_NOTIFIER && KVM_ARCH_WANT_MMU_NOTIFIER) */ #else /* !CONFIG_KVM_GENERIC_MMU_NOTIFIER */
static int kvm_init_mmu_notifier(struct kvm *kvm) static int kvm_init_mmu_notifier(struct kvm *kvm)
{ {
return 0; return 0;
} }
#endif /* CONFIG_MMU_NOTIFIER && KVM_ARCH_WANT_MMU_NOTIFIER */ #endif /* CONFIG_KVM_GENERIC_MMU_NOTIFIER */
#ifdef CONFIG_HAVE_KVM_PM_NOTIFIER #ifdef CONFIG_HAVE_KVM_PM_NOTIFIER
static int kvm_pm_notifier_call(struct notifier_block *bl, static int kvm_pm_notifier_call(struct notifier_block *bl,
...@@ -1289,7 +1289,7 @@ static struct kvm *kvm_create_vm(unsigned long type, const char *fdname) ...@@ -1289,7 +1289,7 @@ static struct kvm *kvm_create_vm(unsigned long type, const char *fdname)
out_err_no_debugfs: out_err_no_debugfs:
kvm_coalesced_mmio_free(kvm); kvm_coalesced_mmio_free(kvm);
out_no_coalesced_mmio: out_no_coalesced_mmio:
#if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER) #ifdef CONFIG_KVM_GENERIC_MMU_NOTIFIER
if (kvm->mmu_notifier.ops) if (kvm->mmu_notifier.ops)
mmu_notifier_unregister(&kvm->mmu_notifier, current->mm); mmu_notifier_unregister(&kvm->mmu_notifier, current->mm);
#endif #endif
...@@ -1349,7 +1349,7 @@ static void kvm_destroy_vm(struct kvm *kvm) ...@@ -1349,7 +1349,7 @@ static void kvm_destroy_vm(struct kvm *kvm)
kvm->buses[i] = NULL; kvm->buses[i] = NULL;
} }
kvm_coalesced_mmio_free(kvm); kvm_coalesced_mmio_free(kvm);
#if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER) #ifdef CONFIG_KVM_GENERIC_MMU_NOTIFIER
mmu_notifier_unregister(&kvm->mmu_notifier, kvm->mm); mmu_notifier_unregister(&kvm->mmu_notifier, kvm->mm);
/* /*
* At this point, pending calls to invalidate_range_start() * At this point, pending calls to invalidate_range_start()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment