All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/2] KVM: Fix kvm_free_physmem memory leak.
@ 2008-10-23 13:29 François Diakhate
  2008-10-26 14:54 ` Avi Kivity
  0 siblings, 1 reply; 2+ messages in thread
From: François Diakhate @ 2008-10-23 13:29 UTC (permalink / raw)
  To: kvm

Make sure that kvm_free_physmem actually frees memory
when a memory slot is not user allocated.

Signed-off-by: François Diakhaté <fdiakh@gmail.com>
---
 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(&current->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

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

* Re: [PATCH 2/2] KVM: Fix kvm_free_physmem memory leak.
  2008-10-23 13:29 [PATCH 2/2] KVM: Fix kvm_free_physmem memory leak François Diakhate
@ 2008-10-26 14:54 ` Avi Kivity
  0 siblings, 0 replies; 2+ messages in thread
From: Avi Kivity @ 2008-10-26 14:54 UTC (permalink / raw)
  To: François Diakhate; +Cc: kvm

François Diakhate wrote:
> Make sure that kvm_free_physmem actually frees memory
> when a memory slot is not user allocated.
>
> @@ -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;
>
>   

What's the purpose of this?

> 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);
> +	}
>  }
>   

Better to fix kvm_free_physmem_slot() if it doesn't handle 
!user_allocated memory properly.

-- 
error compiling committee.c: too many arguments to function


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

end of thread, other threads:[~2008-10-26 14:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-23 13:29 [PATCH 2/2] KVM: Fix kvm_free_physmem memory leak François Diakhate
2008-10-26 14:54 ` Avi Kivity

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.