]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
KVM: Directly return result from kvm_arch_check_processor_compat()
authorSean Christopherson <sean.j.christopherson@intel.com>
Sat, 20 Apr 2019 05:18:17 +0000 (22:18 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 4 Jun 2019 17:27:32 +0000 (19:27 +0200)
Add a wrapper to invoke kvm_arch_check_processor_compat() so that the
boilerplate ugliness of checking virtualization support on all CPUs is
hidden from the arch specific code.  x86's implementation in particular
is quite heinous, as it unnecessarily propagates the out-param pattern
into kvm_x86_ops.

While the x86 specific issue could be resolved solely by changing
kvm_x86_ops, make the change for all architectures as returning a value
directly is prettier and technically more robust, e.g. s390 doesn't set
the out param, which could lead to subtle breakage in the (highly
unlikely) scenario where the out-param was not pre-initialized by the
caller.

Opportunistically annotate svm_check_processor_compat() with __init.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/mips/kvm/mips.c
arch/powerpc/kvm/powerpc.c
arch/s390/include/asm/kvm_host.h
arch/s390/kvm/kvm-s390.c
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/svm.c
arch/x86/kvm/vmx/vmx.c
arch/x86/kvm/x86.c
include/linux/kvm_host.h
virt/kvm/arm/arm.c
virt/kvm/kvm_main.c

index 0369f26ab96d6aeb934d7f6e084e9789419fd03e..2cfe839f0b3a776898595c480d66807d161910f4 100644 (file)
@@ -123,9 +123,9 @@ int kvm_arch_hardware_setup(void)
        return 0;
 }
 
-void kvm_arch_check_processor_compat(void *rtn)
+int kvm_arch_check_processor_compat(void)
 {
-       *(int *)rtn = 0;
+       return 0;
 }
 
 int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
index aa3a678711beecfa99b544d182cb6af021141c8e..628d3c791ad727bfb9e0cd597a70a3539a21f73a 100644 (file)
@@ -425,9 +425,9 @@ int kvm_arch_hardware_setup(void)
        return 0;
 }
 
-void kvm_arch_check_processor_compat(void *rtn)
+int kvm_arch_check_processor_compat(void)
 {
-       *(int *)rtn = kvmppc_core_check_processor_compat();
+       return kvmppc_core_check_processor_compat();
 }
 
 int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
index 2b00a3ebee08627f89653ec8073cc1f2c7854b84..da5825a3c16bf420392af97b8ec9478722a516ad 100644 (file)
@@ -905,7 +905,6 @@ 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_check_processor_compat(void *rtn) {}
 static inline void kvm_arch_sync_events(struct kvm *kvm) {}
 static inline void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu) {}
 static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {}
index 28ebd647784c93b784bf625dc5063f02c5df3c30..7936af0a971f4ab93300be17e82127f5c7326841 100644 (file)
@@ -227,6 +227,11 @@ int kvm_arch_hardware_enable(void)
        return 0;
 }
 
+int kvm_arch_check_processor_compat(void)
+{
+       return 0;
+}
+
 static void kvm_gmap_notifier(struct gmap *gmap, unsigned long start,
                              unsigned long end);
 
index 450d69a1e6fac02579a16df5f091b87807118ae2..d5457c7bb2430b38819c7b022a4f79e100c30458 100644 (file)
@@ -999,7 +999,7 @@ struct kvm_x86_ops {
        int (*disabled_by_bios)(void);             /* __init */
        int (*hardware_enable)(void);
        void (*hardware_disable)(void);
-       void (*check_processor_compatibility)(void *rtn);
+       int (*check_processor_compatibility)(void);/* __init */
        int (*hardware_setup)(void);               /* __init */
        void (*hardware_unsetup)(void);            /* __exit */
        bool (*cpu_has_accelerated_tpr)(void);
index c56f40d430e54c80253bc79b5758f2a74b601a71..302cb409d452fe542b9411fb786360626a88d118 100644 (file)
@@ -5871,9 +5871,9 @@ svm_patch_hypercall(struct kvm_vcpu *vcpu, unsigned char *hypercall)
        hypercall[2] = 0xd9;
 }
 
-static void svm_check_processor_compat(void *rtn)
+static int __init svm_check_processor_compat(void)
 {
-       *(int *)rtn = 0;
+       return 0;
 }
 
 static bool svm_cpu_has_accelerated_tpr(void)
index b35b3800a3c0a4f7fb9c553ddbd4e462f3e6422f..0861c71a4379d985c341ee1340e0ce233ed5f656 100644 (file)
@@ -6733,22 +6733,22 @@ static int vmx_vm_init(struct kvm *kvm)
        return 0;
 }
 
-static void __init vmx_check_processor_compat(void *rtn)
+static int __init vmx_check_processor_compat(void)
 {
        struct vmcs_config vmcs_conf;
        struct vmx_capability vmx_cap;
 
-       *(int *)rtn = 0;
        if (setup_vmcs_config(&vmcs_conf, &vmx_cap) < 0)
-               *(int *)rtn = -EIO;
+               return -EIO;
        if (nested)
                nested_vmx_setup_ctls_msrs(&vmcs_conf.nested, vmx_cap.ept,
                                           enable_apicv);
        if (memcmp(&vmcs_config, &vmcs_conf, sizeof(struct vmcs_config)) != 0) {
                printk(KERN_ERR "kvm: CPU %d feature inconsistency!\n",
                                smp_processor_id());
-               *(int *)rtn = -EIO;
+               return -EIO;
        }
+       return 0;
 }
 
 static u64 vmx_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio)
index 2a713a74ca2e9d4838e8742c003a047c8e1533c5..5cb9ac9b61abb420d36b9e4a9d6d6bb8cefb6e00 100644 (file)
@@ -9082,9 +9082,9 @@ void kvm_arch_hardware_unsetup(void)
        kvm_x86_ops->hardware_unsetup();
 }
 
-void kvm_arch_check_processor_compat(void *rtn)
+int kvm_arch_check_processor_compat(void)
 {
-       kvm_x86_ops->check_processor_compatibility(rtn);
+       return kvm_x86_ops->check_processor_compatibility();
 }
 
 bool kvm_vcpu_is_reset_bsp(struct kvm_vcpu *vcpu)
index 79fa4426509c4e68b8c519b5196328abbe2370b9..5e9fd7ad80183b35f5fcde534a96ee1a6b9f6c31 100644 (file)
@@ -870,7 +870,7 @@ int kvm_arch_hardware_enable(void);
 void kvm_arch_hardware_disable(void);
 int kvm_arch_hardware_setup(void);
 void kvm_arch_hardware_unsetup(void);
-void kvm_arch_check_processor_compat(void *rtn);
+int kvm_arch_check_processor_compat(void);
 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);
index 7eeebe5e9da2b123f6b26e07e2e52ac404c15eb6..d2389033e9d67b2f6b6b399a165eb771e4b4349c 100644 (file)
@@ -105,9 +105,9 @@ int kvm_arch_hardware_setup(void)
        return 0;
 }
 
-void kvm_arch_check_processor_compat(void *rtn)
+int kvm_arch_check_processor_compat(void)
 {
-       *(int *)rtn = 0;
+       return 0;
 }
 
 
index ca54b09adf5b7876dd1b102262d562e6d5c3f2dd..b2579841263feaaf2235c967b5a30d731942b0b9 100644 (file)
@@ -4224,6 +4224,11 @@ static void kvm_sched_out(struct preempt_notifier *pn,
        kvm_arch_vcpu_put(vcpu);
 }
 
+static void check_processor_compat(void *rtn)
+{
+       *(int *)rtn = kvm_arch_check_processor_compat();
+}
+
 int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
                  struct module *module)
 {
@@ -4255,9 +4260,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
                goto out_free_0a;
 
        for_each_online_cpu(cpu) {
-               smp_call_function_single(cpu,
-                               kvm_arch_check_processor_compat,
-                               &r, 1);
+               smp_call_function_single(cpu, check_processor_compat, &r, 1);
                if (r < 0)
                        goto out_free_1;
        }