Skip to contentSkip to conversation

KVM: fix memoryleak in kvm_init()

PATCH Applied Miaohe Lin 3 participants 5 messages Aug 23, 2022 – Sep 1, 2022 KVM

lore
Share & tools
lore

Miaohe Lin

author
#0 lore raw

PATCH 1/1 KVM: fix memoryleak in kvm_init()

When alloc_cpumask_var_node() fails for a certain cpu, there might be some allocated cpumasks for percpu cpu_kick_mask. We should free these cpumasks or memoryleak will occur.

Fixes baff59ccdc65 ("KVM: Pre-allocate cpumasks for kvm_make_all_cpus_request_except()")
---
 virt/kvm/kvm_main.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
virt/kvm/kvm_main.c +2 -3
index 584a5bab3af3..dcf47da44844 100644
@@ -5881,7 +5881,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
 
 	r = kvm_async_pf_init();
 	if (r)
-		goto out_free_5;
+		goto out_free_4;
 
 	kvm_chardev_ops.owner = module;
 
@@ -5905,10 +5905,9 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
 
 out_unreg:
 	kvm_async_pf_deinit();
-out_free_5:
+out_free_4:
 	for_each_possible_cpu(cpu)
 		free_cpumask_var(per_cpu(cpu_kick_mask, cpu));
-out_free_4:
 	kmem_cache_destroy(kvm_vcpu_cache);
 out_free_3:
 	unregister_reboot_notifier(&kvm_reboot_notifier);
Signature · 1 line
2.23.0
reviewer Applied
#2 lore raw
In reply to Miaohe Lin
Quoted 7 lines · Miaohe Lin

When alloc_cpumask_var_node() fails for a certain cpu, there might be some allocated cpumasks for percpu cpu_kick_mask. We should free these cpumasks or memoryleak will occur.

Fixes baff59ccdc65 ("KVM: Pre-allocate cpumasks for kvm_make_all_cpus_request_except()")

---

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.

maintainer
#3 lore raw
Quoted 9 lines · Sean Christopherson
Quoted 7 lines · Miaohe Lin

When alloc_cpumask_var_node() fails for a certain cpu, there might be some allocated cpumasks for percpu cpu_kick_mask. We should free these cpumasks or memoryleak will occur.

Fixes baff59ccdc65 ("KVM: Pre-allocate cpumasks for kvm_make_all_cpus_request_except()")

---

Quoted 7 lines

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.

Hmm, I was going to merge these memory leak fixes for 6.0, but no big deal since they're mostly theoretical anyway.

Paolo

#4 lore raw
Quoted 12 lines · Paolo Bonzini
Quoted 11 lines · Sean Christopherson
Quoted 7 lines · Miaohe Lin

When alloc_cpumask_var_node() fails for a certain cpu, there might be some allocated cpumasks for percpu cpu_kick_mask. We should free these cpumasks or memoryleak will occur.

Fixes baff59ccdc65 ("KVM: Pre-allocate cpumasks for kvm_make_all_cpus_request_except()")

---

Pushed to branch for_paolo/6.1 at:

Quoted 8 lines
Quoted 5 lines

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.

Hmm, I was going to merge these memory leak fixes for 6.0, but no big deal since they're mostly theoretical anyway.

Take them, I wasn't sure and was anticipating possibly dropping them anyways. I can easily adjust, and was deliberately a little greedy for these technically-a-bug memory leaks so that we would't miss them by thinking the other would grab 'em.