Skip to contentSkip to conversation

kvm: x86: mmu: fix memoryleak in kvm_mmu_vendor_module_init()

PATCH Applied Miaohe Lin 3 participants 9 messages Aug 23, 2022 – Aug 31, 2022

Subsystems (3)
lore
Share & tools
lore

Miaohe Lin

author
#0 lore raw

PATCH 1/1 kvm: x86: mmu: fix memoryleak in kvm_mmu_vendor_module_init()

When register_shrinker() fails, we forgot to release the percpu counter kvm_total_used_mmu_pages leading to memoryleak. Fix this issue by calling percpu_counter_destroy() when register_shrinker() fails.

Fixes ab271bd4dfd5 ("x86: kvm: propagate register_shrinker return code")
---
 arch/x86/kvm/mmu/mmu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/kvm/mmu/mmu.c +3 -1
index e418ef3ecfcb..d25d55b1f0b5 100644
@@ -6702,10 +6702,12 @@ int kvm_mmu_vendor_module_init(void)
 
 	ret = register_shrinker(&mmu_shrinker, "x86-mmu");
 	if (ret)
-		goto out;
+		goto out_shrinker;
 
 	return 0;
 
+out_shrinker:
+	percpu_counter_destroy(&kvm_total_used_mmu_pages);
 out:
 	mmu_destroy_caches();
 	return ret;
Signature · 1 line
2.23.0
maintainer Reviewed-by on v1 1/1
#1 lore raw

Nit for future patches, please use

KVM: x86/mmu:

for the scope.

Quoted 7 lines · Miaohe Lin

When register_shrinker() fails, we forgot to release the percpu counter kvm_total_used_mmu_pages leading to memoryleak. Fix this issue by calling percpu_counter_destroy() when register_shrinker() fails.

Fixes ab271bd4dfd5 ("x86: kvm: propagate register_shrinker return code")

---

author
#2 lore raw
Quoted 5 lines · Sean Christopherson

Nit for future patches, please use

KVM: x86/mmu:

for the scope.

Will take care of it.

Quoted 11 lines · Miaohe Lin
Quoted 7 lines

When register_shrinker() fails, we forgot to release the percpu counter kvm_total_used_mmu_pages leading to memoryleak. Fix this issue by calling percpu_counter_destroy() when register_shrinker() fails.

Fixes ab271bd4dfd5 ("x86: kvm: propagate register_shrinker return code")

---

Many thanks for your review.

Thanks,
Miaohe Lin

maintainer Applied
#3 lore raw
In reply to Miaohe Lin
Quoted 7 lines · Miaohe Lin

When register_shrinker() fails, we forgot to release the percpu counter kvm_total_used_mmu_pages leading to memoryleak. Fix this issue by calling percpu_counter_destroy() when register_shrinker() fails.

Fixes ab271bd4dfd5 ("x86: kvm: propagate register_shrinker return code")

---

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.

#4 lore raw
Quoted 10 lines · Sean Christopherson
Quoted 8 lines · Miaohe Lin

When register_shrinker() fails, we forgot to release the percpu counter

kvm_total_used_mmu_pages leading to memoryleak. Fix this issue by calling percpu_counter_destroy() when register_shrinker() fails.

Fixes ab271bd4dfd5 ("x86: kvm: propagate register_shrinker return code")

---

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.

Sorry for late reply.

The commit message has "we". Should we get rid of it?

Signature · 2 lines
Thanks,
-Kai
#5 lore raw
Quoted 15 lines · Kai
Quoted 14 lines · Sean Christopherson
Quoted 8 lines · Miaohe Lin

When register_shrinker() fails, we forgot to release the percpu counter

kvm_total_used_mmu_pages leading to memoryleak. Fix this issue by calling percpu_counter_destroy() when register_shrinker() fails.

Fixes ab271bd4dfd5 ("x86: kvm: propagate register_shrinker return code")

---

Pushed to branch for_paolo/6.1 at:

https://github.com/sean-jc/linux.git

Quoted 7 lines
Quoted 3 lines

Unless you hear otherwise, it will make its way to kvm/queue "soon".

Note, the commit IDs are not guaranteed to be stable.

Sorry for late reply.

The commit message has "we". Should we get rid of it?

Avoiding pronouns is obviously my preference, but sometimes even I set aside my crusade to move things along :-)

#6 lore raw
Quoted 21 lines · Kai
Quoted 20 lines · Sean Christopherson
Quoted 19 lines · Miaohe Lin
Quoted 11 lines

When register_shrinker() fails, we forgot to release the percpu counter

kvm_total_used_mmu_pages leading to memoryleak. Fix this issue by calling
percpu_counter_destroy() when register_shrinker() fails.

Fixes ab271bd4dfd5 ("x86: kvm: propagate register_shrinker return

code")

---

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".

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Note, the commit IDs are not guaranteed to be stable.

Sorry for late reply.

The commit message has "we". Should we get rid of it?

Avoiding pronouns is obviously my preference, but sometimes even I set aside my crusade to move things along :-)

Yeah sure. I was replying just in case you didn't notice it :)

author
#7 lore raw
Quoted 23 lines · Kai
Quoted 23 lines · Kai
Quoted 22 lines · Sean Christopherson
Quoted 20 lines · Miaohe Lin
Quoted 11 lines

When register_shrinker() fails, we forgot to release the percpu counter

kvm_total_used_mmu_pages leading to memoryleak. Fix this issue by calling
percpu_counter_destroy() when register_shrinker() fails.

Fixes ab271bd4dfd5 ("x86: kvm: propagate register_shrinker return

code")

---

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.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Sorry for late reply.

The commit message has "we". Should we get rid of it?

Avoiding pronouns is obviously my preference, but sometimes even I set aside my crusade to move things along :-)

Yeah sure. I was replying just in case you didn't notice it :)

Please ignore my previous question in another thread. I just saw this patch. ;)

Many thanks.

Quoted 3 lines

.

author
#8 lore raw
In reply to Huang, Kai
Quoted 15 lines · Kai
Quoted 14 lines · Sean Christopherson
Quoted 8 lines · Miaohe Lin

When register_shrinker() fails, we forgot to release the percpu counter

kvm_total_used_mmu_pages leading to memoryleak. Fix this issue by calling percpu_counter_destroy() when register_shrinker() fails.

Fixes ab271bd4dfd5 ("x86: kvm: propagate register_shrinker return code")

---

Pushed to branch for_paolo/6.1 at:

https://github.com/sean-jc/linux.git

Quoted 7 lines
Quoted 3 lines

Unless you hear otherwise, it will make its way to kvm/queue "soon".

Note, the commit IDs are not guaranteed to be stable.

Sorry for late reply.

The commit message has "we". Should we get rid of it?

Sean has kindly tweaked the commit message. Many thanks both.

BTW: Is it unsuitable to use "we" in the commit message? If so, I will try to not use it in later patches.

Thanks,
Miaohe Lin