KVM: Directly return result from kvm_arch_check_processor_compat()
PATCH 1/1 KVM: Directly return result from kvm_arch_check_processor_compat()
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.
---
Tested on VMX only.
arch/mips/kvm/mips.c | 4 ++-- arch/powerpc/kvm/powerpc.c | 4 ++-- arch/s390/include/asm/kvm_host.h | 1 - arch/s390/kvm/kvm-s390.c | 5 +++++ arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/svm.c | 4 ++-- arch/x86/kvm/vmx/vmx.c | 8 ++++---- arch/x86/kvm/x86.c | 4 ++-- include/linux/kvm_host.h | 2 +- virt/kvm/arm/arm.c | 4 ++-- virt/kvm/kvm_main.c | 9 ++++++--- 11 files changed, 27 insertions(+), 20 deletions(-)
arch/mips/kvm/mips.c +2 -2
@@ -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)
arch/powerpc/kvm/powerpc.c +2 -2
@@ -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)
arch/s390/include/asm/kvm_host.h +0 -1
@@ -903,7 +903,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) {}
arch/s390/kvm/kvm-s390.c +5 -0
@@ -221,6 +221,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);
arch/x86/include/asm/kvm_host.h +1 -1
@@ -995,7 +995,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 );
arch/x86/kvm/svm.c +2 -2
@@ -5859,9 +5859,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 )
arch/x86/kvm/vmx/vmx.c +4 -4
@@ -6720,22 +6720,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)
arch/x86/kvm/x86.c +2 -2
@@ -9042,9 +9042,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)
include/linux/kvm_host.h +1 -1
@@ -842,7 +842,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);
virt/kvm/arm/arm.c +2 -2
@@ -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 ; }
virt/kvm/kvm_main.c +6 -3
@@ -4135,6 +4135,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) {
@@ -4166,9 +4171,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; }
Signature · 1 line
2.21.0
Quoted 20 lines · On Fri, 19 Apr 2019 22:18:17 -0700 Sean Christopherson…
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 intokvm_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 <[email protected]>---
Tested on VMX only.
Quoted 12 lines
arch/mips/kvm/mips.c | 4 ++-- arch/powerpc/kvm/powerpc.c | 4 ++-- arch/s390/include/asm/kvm_host.h | 1 - arch/s390/kvm/kvm-s390.c | 5 +++++ arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/svm.c | 4 ++-- arch/x86/kvm/vmx/vmx.c | 8 ++++---- arch/x86/kvm/x86.c | 4 ++-- include/linux/kvm_host.h | 2 +- virt/kvm/arm/arm.c | 4 ++-- virt/kvm/kvm_main.c | 9 ++++++--- 11 files changed, 27 insertions(+), 20 deletions(-)
Yes, this does look nicer.
Quoted 13 lines · Sean Christopherson
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 intokvm_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.
Quoted 3 lines
Opportunistically annotate
svm_check_processor_compat()with__init.Signed-off-by Sean Christopherson <[email protected]>
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Quoted 216 lines · Sean Christopherson
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 intokvm_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 <[email protected]>---
Tested on VMX only.
arch/mips/kvm/mips.c | 4 ++-- arch/powerpc/kvm/powerpc.c | 4 ++-- arch/s390/include/asm/kvm_host.h | 1 - arch/s390/kvm/kvm-s390.c | 5 +++++ arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/svm.c | 4 ++-- arch/x86/kvm/vmx/vmx.c | 8 ++++---- arch/x86/kvm/x86.c | 4 ++-- include/linux/kvm_host.h | 2 +- virt/kvm/arm/arm.c | 4 ++-- virt/kvm/kvm_main.c | 9 ++++++--- 11 files changed, 27 insertions(+), 20 deletions(-)arch/mips/kvm/mips.c +2
-2@@ -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)arch/powerpc/kvm/powerpc.c +2
-2@@ -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)arch/s390/include/asm/kvm_host.h +0
-1@@ -903,7 +903,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) {}arch/s390/kvm/kvm-s390.c +5
-0@@ -221,6 +221,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);arch/x86/include/asm/kvm_host.h +1
-1@@ -995,7 +995,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 );arch/x86/kvm/svm.c +2
-2@@ -5859,9 +5859,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 )arch/x86/kvm/vmx/vmx.c +4
-4@@ -6720,22 +6720,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)arch/x86/kvm/x86.c +2
-2@@ -9042,9 +9042,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)include/linux/kvm_host.h +1
-1@@ -842,7 +842,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);virt/kvm/arm/arm.c +2
-2@@ -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 ; }virt/kvm/kvm_main.c +5
-0@@ -4135,6 +4135,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) {
virt/kvm/kvm_main.c int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align, · line 4177
Quoted 10 lines
virt/kvm/kvm_main.c +1
-3@@ -4166,9 +4171,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; }
Queued for 5.3, thanks.
Paolo