KVM: Opt out of generic hardware enabling on s390 and PPC
authorSean Christopherson <seanjc@google.com>
Wed, 30 Nov 2022 23:09:33 +0000 (23:09 +0000)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 29 Dec 2022 20:48:37 +0000 (15:48 -0500)
Allow architectures to opt out of the generic hardware enabling logic,
and opt out on both s390 and PPC, which don't need to manually enable
virtualization as it's always on (when available).

In addition to letting s390 and PPC drop a bit of dead code, this will
hopefully also allow ARM to clean up its related code, e.g. ARM has its
own per-CPU flag to track which CPUs have enable hardware due to the
need to keep hardware enabled indefinitely when pKVM is enabled.

Signed-off-by: Sean Christopherson <seanjc@google.com>
Acked-by: Anup Patel <anup@brainfault.org>
Message-Id: <20221130230934.1014142-50-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/arm64/kvm/Kconfig
arch/mips/kvm/Kconfig
arch/powerpc/include/asm/kvm_host.h
arch/powerpc/kvm/powerpc.c
arch/riscv/kvm/Kconfig
arch/s390/include/asm/kvm_host.h
arch/s390/kvm/kvm-s390.c
arch/x86/kvm/Kconfig
include/linux/kvm_host.h
virt/kvm/Kconfig
virt/kvm/kvm_main.c

index 05da3c8f7e88f6a640ef744d8c401e695e490553..ca6eadeb7d1a1142c4212dd51495099fae8db2cf 100644 (file)
@@ -21,6 +21,7 @@ if VIRTUALIZATION
 menuconfig KVM
        bool "Kernel-based Virtual Machine (KVM) support"
        depends on HAVE_KVM
+       select KVM_GENERIC_HARDWARE_ENABLING
        select MMU_NOTIFIER
        select PREEMPT_NOTIFIERS
        select HAVE_KVM_CPU_RELAX_INTERCEPT
index 91d197bee9c0a551672dd8b7992cfff1f1ea4633..29e51649203bb5aa8f377f4b4d4b33da6bd62bd9 100644 (file)
@@ -28,6 +28,7 @@ config KVM
        select MMU_NOTIFIER
        select SRCU
        select INTERVAL_TREE
+       select KVM_GENERIC_HARDWARE_ENABLING
        help
          Support for hosting Guest kernels.
 
index 0a80e80c7b9e7735ade6df3dcbbe7f322ba008c7..959f566a455ca28d3777fecb2f2d07eaf8dc774f 100644 (file)
@@ -876,7 +876,6 @@ struct kvm_vcpu_arch {
 #define __KVM_HAVE_ARCH_WQP
 #define __KVM_HAVE_CREATE_DEVICE
 
-static inline void kvm_arch_hardware_disable(void) {}
 static inline void kvm_arch_sync_events(struct kvm *kvm) {}
 static inline void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen) {}
 static inline void kvm_arch_flush_shadow_all(struct kvm *kvm) {}
index f5b4ff6bfc895135dc30bdf328a34a1994048ac6..4c5405fc55387028e33e26f83fac20c99a2e5316 100644 (file)
@@ -435,11 +435,6 @@ int kvmppc_ld(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr,
 }
 EXPORT_SYMBOL_GPL(kvmppc_ld);
 
-int kvm_arch_hardware_enable(void)
-{
-       return 0;
-}
-
 int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
 {
        struct kvmppc_ops *kvm_ops = NULL;
index f36a737d5f96d253d42075fdcb9082d500e3d08b..d5a658a047a7f738fc91df06709ee0e867ac2347 100644 (file)
@@ -20,6 +20,7 @@ if VIRTUALIZATION
 config KVM
        tristate "Kernel-based Virtual Machine (KVM) support (EXPERIMENTAL)"
        depends on RISCV_SBI && MMU
+       select KVM_GENERIC_HARDWARE_ENABLING
        select MMU_NOTIFIER
        select PREEMPT_NOTIFIERS
        select KVM_MMIO
index d67ce719d16a994e8bbfc36ea53d5ffb69e4a50b..2bbc3d54959dd39020445220c36e2ee4e2a83214 100644 (file)
@@ -1031,7 +1031,6 @@ extern char sie_exit;
 extern int kvm_s390_gisc_register(struct kvm *kvm, u32 gisc);
 extern int kvm_s390_gisc_unregister(struct kvm *kvm, u32 gisc);
 
-static inline void kvm_arch_hardware_disable(void) {}
 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_free_memslot(struct kvm *kvm,
index 7ad8252e92c2eed469aa79e95c763e6e666bcf1f..bd25076aa19b4cb90b728d72432b1962396785b5 100644 (file)
@@ -256,12 +256,6 @@ debug_info_t *kvm_s390_dbf;
 debug_info_t *kvm_s390_dbf_uv;
 
 /* Section: not file related */
-int kvm_arch_hardware_enable(void)
-{
-       /* every s390 is virtualization enabled ;-) */
-       return 0;
-}
-
 /* forward declarations */
 static void kvm_gmap_notifier(struct gmap *gmap, unsigned long start,
                              unsigned long end);
index fbeaa9ddef5985f193afccc58a0dc36c1eeb0103..8e578311ca9d4d1e24302d471eab0bdb4d40535f 100644 (file)
@@ -49,6 +49,7 @@ config KVM
        select SRCU
        select INTERVAL_TREE
        select HAVE_KVM_PM_NOTIFIER if PM
+       select KVM_GENERIC_HARDWARE_ENABLING
        help
          Support hosting fully virtualized guest machines using hardware
          virtualization extensions.  You will need a fairly recent
index 20e207e4c6c1fcc14c94187b47a43627aa8d6da4..109b18e2789c4afc88d6104941e38e4097e90dcc 100644 (file)
@@ -1441,8 +1441,10 @@ void kvm_arch_create_vcpu_debugfs(struct kvm_vcpu *vcpu, struct dentry *debugfs_
 static inline void kvm_create_vcpu_debugfs(struct kvm_vcpu *vcpu) {}
 #endif
 
+#ifdef CONFIG_KVM_GENERIC_HARDWARE_ENABLING
 int kvm_arch_hardware_enable(void);
 void kvm_arch_hardware_disable(void);
+#endif
 int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu);
 bool kvm_arch_vcpu_in_kernel(struct kvm_vcpu *vcpu);
 int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu);
@@ -2074,7 +2076,9 @@ static inline bool kvm_check_request(int req, struct kvm_vcpu *vcpu)
        }
 }
 
+#ifdef CONFIG_KVM_GENERIC_HARDWARE_ENABLING
 extern bool kvm_rebooting;
+#endif
 
 extern unsigned int halt_poll_ns;
 extern unsigned int halt_poll_ns_grow;
index 9fb1ff6f19e5f76112aebd01c9221ff91d96b94d..b74916de5183a5060c13381c6c442f041092de59 100644 (file)
@@ -92,3 +92,6 @@ config KVM_XFER_TO_GUEST_WORK
 
 config HAVE_KVM_PM_NOTIFIER
        bool
+
+config KVM_GENERIC_HARDWARE_ENABLING
+       bool
index 6c0bd9a8e27e242505f29c7468c22dfc182ae6e0..3d0678579c5ea0d1c5910fd1790f4be0cd0376b6 100644 (file)
@@ -102,9 +102,6 @@ EXPORT_SYMBOL_GPL(halt_poll_ns_shrink);
 DEFINE_MUTEX(kvm_lock);
 LIST_HEAD(vm_list);
 
-static DEFINE_PER_CPU(bool, hardware_enabled);
-static int kvm_usage_count;
-
 static struct kmem_cache *kvm_vcpu_cache;
 
 static __read_mostly struct preempt_ops kvm_preempt_ops;
@@ -146,9 +143,6 @@ static void hardware_disable_all(void);
 
 static void kvm_io_bus_destroy(struct kvm_io_bus *bus);
 
-__visible bool kvm_rebooting;
-EXPORT_SYMBOL_GPL(kvm_rebooting);
-
 #define KVM_EVENT_CREATE_VM 0
 #define KVM_EVENT_DESTROY_VM 1
 static void kvm_uevent_notify_change(unsigned int type, struct kvm *kvm);
@@ -5093,6 +5087,13 @@ static struct miscdevice kvm_dev = {
        &kvm_chardev_ops,
 };
 
+#ifdef CONFIG_KVM_GENERIC_HARDWARE_ENABLING
+__visible bool kvm_rebooting;
+EXPORT_SYMBOL_GPL(kvm_rebooting);
+
+static DEFINE_PER_CPU(bool, hardware_enabled);
+static int kvm_usage_count;
+
 static int __hardware_enable_nolock(void)
 {
        if (__this_cpu_read(hardware_enabled))
@@ -5254,6 +5255,17 @@ static struct syscore_ops kvm_syscore_ops = {
        .suspend = kvm_suspend,
        .resume = kvm_resume,
 };
+#else /* CONFIG_KVM_GENERIC_HARDWARE_ENABLING */
+static int hardware_enable_all(void)
+{
+       return 0;
+}
+
+static void hardware_disable_all(void)
+{
+
+}
+#endif /* CONFIG_KVM_GENERIC_HARDWARE_ENABLING */
 
 static void kvm_io_bus_destroy(struct kvm_io_bus *bus)
 {
@@ -5942,6 +5954,7 @@ int kvm_init(unsigned vcpu_size, unsigned vcpu_align, struct module *module)
        int r;
        int cpu;
 
+#ifdef CONFIG_KVM_GENERIC_HARDWARE_ENABLING
        r = cpuhp_setup_state_nocalls(CPUHP_AP_KVM_ONLINE, "kvm/cpu:online",
                                      kvm_online_cpu, kvm_offline_cpu);
        if (r)
@@ -5949,6 +5962,7 @@ int kvm_init(unsigned vcpu_size, unsigned vcpu_align, struct module *module)
 
        register_reboot_notifier(&kvm_reboot_notifier);
        register_syscore_ops(&kvm_syscore_ops);
+#endif
 
        /* A kmem cache lets us meet the alignment requirements of fx_save. */
        if (!vcpu_align)
@@ -6016,9 +6030,11 @@ out_free_4:
                free_cpumask_var(per_cpu(cpu_kick_mask, cpu));
        kmem_cache_destroy(kvm_vcpu_cache);
 out_free_3:
+#ifdef CONFIG_KVM_GENERIC_HARDWARE_ENABLING
        unregister_syscore_ops(&kvm_syscore_ops);
        unregister_reboot_notifier(&kvm_reboot_notifier);
        cpuhp_remove_state_nocalls(CPUHP_AP_KVM_ONLINE);
+#endif
        return r;
 }
 EXPORT_SYMBOL_GPL(kvm_init);
@@ -6040,9 +6056,11 @@ void kvm_exit(void)
        kmem_cache_destroy(kvm_vcpu_cache);
        kvm_vfio_ops_exit();
        kvm_async_pf_deinit();
+#ifdef CONFIG_KVM_GENERIC_HARDWARE_ENABLING
        unregister_syscore_ops(&kvm_syscore_ops);
        unregister_reboot_notifier(&kvm_reboot_notifier);
        cpuhp_remove_state_nocalls(CPUHP_AP_KVM_ONLINE);
+#endif
        kvm_irqfd_exit();
 }
 EXPORT_SYMBOL_GPL(kvm_exit);