Make sure that kvm_free_physmem actually frees memory
when a memory slot is not user allocated.
Signed-off-by: François Diakhaté <[EMAIL PROTECTED]>
---
arch/x86/kvm/x86.c | 2 +-
virt/kvm/kvm_main.c | 11 ++++++++++-
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 883c137..ae360dc 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -4195,7 +4195,7 @@ int kvm_arch_set_memory_region(struct kvm *kvm,
memslot->userspace_addr = userspace_addr;
spin_unlock(&kvm->mmu_lock);
} else {
- if (!old.user_alloc && old.rmap) {
+ if (!old.user_alloc && old.rmap && current->mm) {
int ret;
down_write(¤t->mm->mmap_sem);
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index a87f45e..b0d7435 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -639,8 +639,17 @@ void kvm_free_physmem(struct kvm *kvm)
{
int i;
- for (i = 0; i < kvm->nmemslots; ++i)
+ for (i = 0; i < kvm->nmemslots; ++i) {
+ struct kvm_userspace_memory_region mem = {
+ .slot = i,
+ .guest_phys_addr = kvm->memslots[i].base_gfn <<
PAGE_SHIFT,
+ .memory_size = 0,
+ .flags = 0,
+ };
+
+ kvm_set_memory_region(kvm, &mem, kvm->memslots[i].user_alloc);
kvm_free_physmem_slot(&kvm->memslots[i], NULL);
+ }
}
static void kvm_destroy_vm(struct kvm *kvm)
--
1.6.0.3
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at http://vger.kernel.org/majordomo-info.html