kvm: x86: Do proper cleanup if kvm_x86_ops->vm_init() fails
PATCH v2 1/1 kvm: x86: Do proper cleanup if kvm_x86_ops->vm_init() fails
If vm_init() fails [which can happen, for instance, if a memory allocation fails during avic_vm_init()], we need to cleanup some state in order to avoid resource leaks.
Signed-off-by Junaid Shahid <[email protected]>
---
v2:
- Moved the vm_init() call earlier in kvm_arch_init_vm()
arch/x86/kvm/x86.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
arch/x86/kvm/x86.c +7 -1
@@ -12029,6 +12029,10 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)if (ret) goto out_page_track; + ret =static_call (kvm_x86_vm_init)(kvm); +if (ret) + goto out_uninit_mmu; +INIT_HLIST_HEAD (&kvm->arch.mask_notifier_list);INIT_LIST_HEAD (&kvm->arch.assigned_dev_head);atomic_set (&kvm->arch.noncoherent_dma_count,0 );
@@ -12064,8 +12068,10 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)kvm_hv_init_vm (kvm);kvm_xen_init_vm (kvm); -return static_call (kvm_x86_vm_init)(kvm); +return 0 ; +out_uninit_mmu: +kvm_mmu_uninit_vm (kvm); out_page_track:kvm_page_track_cleanup (kvm); out:
base-commit: a4850b5590d01bf3fb19fda3fc5d433f7382a974
Signature · 1 line
2.37.1.455.g008518b4e5-goog
Quoted 6 lines · Junaid Shahid
If
vm_init()fails [which can happen, for instance, if a memory allocation fails duringavic_vm_init()], we need to cleanup some state in order to avoid resource leaks.Signed-off-by Junaid Shahid <[email protected]>---
Pushed to branch for_paolo/6.1 at:
https://github.com/sean-jc/linux.git
Unless you hear otherwise, it will make its way to kvm/queue "soon".
Note, the commit IDs are not guaranteed to be stable.