Message ID | 20250220170604.2279312-12-pbonzini@redhat.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | TDX initialization + vCPU/VM creation | expand |
> +static void __exit vt_exit(void) > +{ > + kvm_exit(); > + vmx_exit(); > +} > +module_exit(vt_exit); > + > +static int __init vt_init(void) > +{ > + int r; > + > + r = vmx_init(); > + if (r) > + return r; > + > + /* > + * Common KVM initialization _must_ come last, after this, /dev/kvm is > + * exposed to userspace! > + */ > + r = kvm_init(sizeof(struct vcpu_vmx), __alignof__(struct vcpu_vmx), > + THIS_MODULE); > + if (r) > + goto err_kvm_init; > + > + return 0; > + > +err_kvm_init: > + vmx_exit(); > + return r; > +} > +module_init(vt_init); > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > index 6c56d5235f0f..8d3cfef0cf3b 100644 > --- a/arch/x86/kvm/vmx/vmx.c > +++ b/arch/x86/kvm/vmx/vmx.c > @@ -8588,7 +8588,7 @@ __init int vmx_hardware_setup(void) > return r; > } > > -static void vmx_cleanup_l1d_flush(void) > +static void __exit vmx_cleanup_l1d_flush(void) > { > if (vmx_l1d_flush_pages) { > free_pages((unsigned long)vmx_l1d_flush_pages, L1D_CACHE_ORDER); > @@ -8598,23 +8598,16 @@ static void vmx_cleanup_l1d_flush(void) > l1tf_vmx_mitigation = VMENTER_L1D_FLUSH_AUTO; > } > > -static void __vmx_exit(void) > +void __exit vmx_exit(void) > { > allow_smaller_maxphyaddr = false; > > vmx_cleanup_l1d_flush(); > -} > > -static void __exit vmx_exit(void) > -{ > - kvm_exit(); > - __vmx_exit(); > kvm_x86_vendor_exit(); > - > } > -module_exit(vmx_exit); > Hi Paolo, I think you will still meet the "section mismatch in reference: vt_init ..." warning reported by LKP, for which I posted a diff to address: https://lore.kernel.org/kvm/BL1PR11MB59780AA56D67068C906A40BAF7E02@BL1PR11MB5978.namprd11.prod.outlook.com/T/#m825784c4d3f5e2651455295d8f1bd9a4ac8ecdd8
diff --git a/arch/x86/kvm/vmx/main.c b/arch/x86/kvm/vmx/main.c index 43ee9ed11291..54cf95cb8d42 100644 --- a/arch/x86/kvm/vmx/main.c +++ b/arch/x86/kvm/vmx/main.c @@ -168,3 +168,35 @@ struct kvm_x86_init_ops vt_init_ops __initdata = { .runtime_ops = &vt_x86_ops, .pmu_ops = &intel_pmu_ops, }; + +static void __exit vt_exit(void) +{ + kvm_exit(); + vmx_exit(); +} +module_exit(vt_exit); + +static int __init vt_init(void) +{ + int r; + + r = vmx_init(); + if (r) + return r; + + /* + * Common KVM initialization _must_ come last, after this, /dev/kvm is + * exposed to userspace! + */ + r = kvm_init(sizeof(struct vcpu_vmx), __alignof__(struct vcpu_vmx), + THIS_MODULE); + if (r) + goto err_kvm_init; + + return 0; + +err_kvm_init: + vmx_exit(); + return r; +} +module_init(vt_init); diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 6c56d5235f0f..8d3cfef0cf3b 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -8588,7 +8588,7 @@ __init int vmx_hardware_setup(void) return r; } -static void vmx_cleanup_l1d_flush(void) +static void __exit vmx_cleanup_l1d_flush(void) { if (vmx_l1d_flush_pages) { free_pages((unsigned long)vmx_l1d_flush_pages, L1D_CACHE_ORDER); @@ -8598,23 +8598,16 @@ static void vmx_cleanup_l1d_flush(void) l1tf_vmx_mitigation = VMENTER_L1D_FLUSH_AUTO; } -static void __vmx_exit(void) +void __exit vmx_exit(void) { allow_smaller_maxphyaddr = false; vmx_cleanup_l1d_flush(); -} -static void __exit vmx_exit(void) -{ - kvm_exit(); - __vmx_exit(); kvm_x86_vendor_exit(); - } -module_exit(vmx_exit); -static int __init vmx_init(void) +int __init vmx_init(void) { int r, cpu; @@ -8658,21 +8651,9 @@ static int __init vmx_init(void) if (!enable_ept) allow_smaller_maxphyaddr = true; - /* - * Common KVM initialization _must_ come last, after this, /dev/kvm is - * exposed to userspace! - */ - r = kvm_init(sizeof(struct vcpu_vmx), __alignof__(struct vcpu_vmx), - THIS_MODULE); - if (r) - goto err_kvm_init; - return 0; -err_kvm_init: - __vmx_exit(); err_l1d_flush: kvm_x86_vendor_exit(); return r; } -module_init(vmx_init); diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h index 8b111ce1087c..299fa1edf534 100644 --- a/arch/x86/kvm/vmx/vmx.h +++ b/arch/x86/kvm/vmx/vmx.h @@ -760,4 +760,7 @@ static inline void vmx_segment_cache_clear(struct vcpu_vmx *vmx) vmx->segment_cache.bitmask = 0; } +int vmx_init(void); +void vmx_exit(void); + #endif /* __KVM_X86_VMX_H */