public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kvm: x86: mmu: fix memoryleak in kvm_mmu_vendor_module_init()
@ 2022-08-23  6:32 Miaohe Lin
  2022-08-24 15:44 ` Sean Christopherson
  2022-08-30 21:40 ` Sean Christopherson
  0 siblings, 2 replies; 9+ messages in thread
From: Miaohe Lin @ 2022-08-23  6:32 UTC (permalink / raw)
  To: seanjc, pbonzini, tglx, mingo, bp, dave.hansen
  Cc: x86, hpa, kvm, linux-kernel, linmiaohe

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")
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 arch/x86/kvm/mmu/mmu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index e418ef3ecfcb..d25d55b1f0b5 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -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;
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-08-31  1:58 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-23  6:32 [PATCH] kvm: x86: mmu: fix memoryleak in kvm_mmu_vendor_module_init() Miaohe Lin
2022-08-24 15:44 ` Sean Christopherson
2022-08-25  1:43   ` Miaohe Lin
2022-08-30 21:40 ` Sean Christopherson
2022-08-30 22:42   ` Huang, Kai
2022-08-30 22:52     ` Sean Christopherson
2022-08-31  1:07       ` Huang, Kai
2022-08-31  1:58         ` Miaohe Lin
2022-08-31  1:53     ` Miaohe Lin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox