From db748dc72be6322b4f9b0be6accb3cb863e43ee3 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Sat, 4 Feb 2012 11:04:24 +0200 Subject: [PATCH] kvm tools, x86: Fix munmap() size in kvm__arch_delete_ram() Sasha noticed during code review that commit e106906 ("kvm tool: Change kvm->ram_size to real mapped size.") changed kvm->ram_size accounting to include 32-bit memory hole but forgot to update munmap in kvm__arch_delete_ram(). Reported-by: Sasha Levin Signed-off-by: Pekka Enberg --- tools/kvm/x86/kvm.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tools/kvm/x86/kvm.c b/tools/kvm/x86/kvm.c index d6afa02101dd..10a1212431bd 100644 --- a/tools/kvm/x86/kvm.c +++ b/tools/kvm/x86/kvm.c @@ -156,11 +156,11 @@ void kvm__arch_init(struct kvm *kvm, const char *hugetlbfs_path, u64 ram_size) die_perror("KVM_CREATE_PIT2 ioctl"); if (ram_size < KVM_32BIT_GAP_START) { - kvm->ram_size = ram_size; + kvm->ram_size = ram_size; kvm->ram_start = mmap_anon_or_hugetlbfs(hugetlbfs_path, ram_size); } else { kvm->ram_start = mmap_anon_or_hugetlbfs(hugetlbfs_path, ram_size + KVM_32BIT_GAP_SIZE); - kvm->ram_size = ram_size + KVM_32BIT_GAP_SIZE; + kvm->ram_size = ram_size + KVM_32BIT_GAP_SIZE; if (kvm->ram_start != MAP_FAILED) /* * We mprotect the gap (see kvm__init_ram() for details) PROT_NONE so that @@ -180,10 +180,7 @@ void kvm__arch_init(struct kvm *kvm, const char *hugetlbfs_path, u64 ram_size) void kvm__arch_delete_ram(struct kvm *kvm) { - if (kvm->ram_size < KVM_32BIT_GAP_START) - munmap(kvm->ram_start, kvm->ram_size); - else - munmap(kvm->ram_start, kvm->ram_size + KVM_32BIT_GAP_SIZE); + munmap(kvm->ram_start, kvm->ram_size); } void kvm__irq_line(struct kvm *kvm, int irq, int level) -- 2.39.5