KVM: x86: Fix probable memory leak of vcpu->arch.mce_banks
PATCH 1/2 KVM: x86: Fix probable memory leak of vcpu->arch.mce_banks
vcpu->arch.mce_banks is malloc in kvm_arch_vcpu_init(), but never free in any place, this may cause memory leak. So this patch fixed to free it in kvm_arch_vcpu_uninit().
--- arch/x86/kvm/x86.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
arch/x86/kvm/x86.c +1 -0
@@ -5089,6 +5089,7 @@ fail:void kvm_arch_vcpu_uninit (struct kvm_vcpu *vcpu) { +kfree (vcpu->arch.mce_banks);kvm_free_lapic (vcpu);down_read (&vcpu->kvm->slots_lock);kvm_mmu_destroy (vcpu);
Signature · 1 line
1.6.2.2
PATCH 2/2 KVM: x86: Fix leak of free lapic date in kvm_arch_vcpu_init()
In function kvm_arch_vcpu_init(), if the memory malloc for vcpu->arch.mce_banks is fail, it does not free the memory of lapic date. This patch fixed it.
--- arch/x86/kvm/x86.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
arch/x86/kvm/x86.c +3 -2
@@ -5072,12 +5072,13 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu) GFP_KERNEL);if (!vcpu->arch.mce_banks) { r = -ENOMEM ; - goto fail_mmu_destroy; + goto fail_free_lapic; } vcpu->arch.mcg_cap =KVM_MAX_MCE_BANKS ;return 0 ; - +fail_free_lapic: +kvm_free_lapic (vcpu); fail_mmu_destroy:kvm_mmu_destroy (vcpu); fail_free_pio_data:
Signature · 1 line
1.6.2.2
PATCH v2 1/2 KVM: x86: Fix probable memory leak of vcpu->arch.mce_banks
In reply to Wei Yongjunvcpu->arch.mce_banks is malloc in kvm_arch_vcpu_init(), but never free in any place, this may cause memory leak. So this patch fixed to free it in kvm_arch_vcpu_uninit().
--- arch/x86/kvm/x86.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
arch/x86/kvm/x86.c +1 -0
@@ -5470,6 +5470,7 @@ void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu) {int idx; +kfree (vcpu->arch.mce_banks);kvm_free_lapic (vcpu); idx =srcu_read_lock (&vcpu->kvm->srcu);kvm_mmu_destroy (vcpu);
PATCH 1/1 KVM: MMU: Remove some useless code from alloc_mmu_pages()
In reply to Wei YongjunIf we fail to alloc page for vcpu->arch.mmu.pae_root, call to free_mmu_pages() is unnecessary, which just do free the page malloc for vcpu->arch.mmu.pae_root.
--- arch/x86/kvm/mmu.c | 7 ++----- 1 files changed, 2 insertions(+), 5 deletions(-)
arch/x86/kvm/mmu.c +2 -5
@@ -2849,16 +2849,13 @@ static int alloc_mmu_pages(struct kvm_vcpu *vcpu)*/ page =alloc_page (GFP_KERNEL | __GFP_DMA32);if (!page) - goto error_1; +return -ENOMEM ; + vcpu->arch.mmu.pae_root =page_address (page);for (i =0 ; i <4 ; ++i) vcpu->arch.mmu.pae_root[i] =INVALID_PAGE ;return 0 ; - -error_1: -free_mmu_pages (vcpu); -return -ENOMEM ; }int kvm_mmu_create (struct kvm_vcpu *vcpu)
Signature · 1 line
1.6.2.2
Marcelo Tosatti
AppliedRe: [PATCH] KVM: MMU: Remove some useless code from alloc_mmu_pages()
Quoted 5 lines · Wei Yongjun
If we fail to alloc page for
vcpu->arch.mmu.pae_root, call tofree_mmu_pages()is unnecessary, which just do free the page malloc forvcpu->arch.mmu.pae_root.Signed-off-by Wei Yongjun <[email protected]>
Applied all 3, thanks.