All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] two refcount and leak fixes for kvm on s390
@ 2008-11-26 13:49 Christian Borntraeger
  2008-11-26 13:50 ` [PATCH 1/2] kvm-s390: Fix refcounting and allow module unload Christian Borntraeger
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Christian Borntraeger @ 2008-11-26 13:49 UTC (permalink / raw)
  To: Avi Kivity
  Cc: kvm, Carsten Otte, Heiko Carstens, Martin Schwidefsky,
	Olaf Schnapper

Hello Avi,

here are two fixes for kvm on s390.

[PATCH 1/2] kvm-s390: Fix refcounting and allow module unload
[PATCH 2/2] kvm-s390: Fix memory leak of vcpu->run

None of the fixed problems is severe. So I guess this should be scheduled for 
the next merge window. Thanks

Christian



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

* [PATCH 1/2] kvm-s390: Fix refcounting and allow module unload
  2008-11-26 13:49 [PATCH 0/2] two refcount and leak fixes for kvm on s390 Christian Borntraeger
@ 2008-11-26 13:50 ` Christian Borntraeger
  2008-11-26 13:51 ` [PATCH 2/2] kvm-s390: Fix memory leak of vcpu->run Christian Borntraeger
  2008-11-27 12:40 ` [PATCH 0/2] two refcount and leak fixes for kvm on s390 Avi Kivity
  2 siblings, 0 replies; 4+ messages in thread
From: Christian Borntraeger @ 2008-11-26 13:50 UTC (permalink / raw)
  To: Avi Kivity
  Cc: kvm, Carsten Otte, Heiko Carstens, Martin Schwidefsky,
	Olaf Schnapper

From: Christian Borntraeger <borntraeger@de.ibm.com>

Currently it is impossible to unload the kvm module on s390.
This patch fixes kvm_arch_destroy_vm to release all cpus.
This make it possible to unload the module.

In addition we stop messing with the module refcount in arch code.

Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Acked-by: Carsten Otte <cotte@de.ibm.com>
---
 arch/s390/kvm/kvm-s390.c |   35 +++++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 14 deletions(-)

Index: kvm/arch/s390/kvm/kvm-s390.c
===================================================================
--- kvm.orig/arch/s390/kvm/kvm-s390.c
+++ kvm/arch/s390/kvm/kvm-s390.c
@@ -185,8 +185,6 @@ struct kvm *kvm_arch_create_vm(void)
 	debug_register_view(kvm->arch.dbf, &debug_sprintf_view);
 	VM_EVENT(kvm, 3, "%s", "vm created");
 
-	try_module_get(THIS_MODULE);
-
 	return kvm;
 out_nodbf:
 	free_page((unsigned long)(kvm->arch.sca));
@@ -196,13 +194,32 @@ out_nokvm:
 	return ERR_PTR(rc);
 }
 
+void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
+{
+	VCPU_EVENT(vcpu, 3, "%s", "free cpu");
+	free_page((unsigned long)(vcpu->arch.sie_block));
+	kfree(vcpu);
+}
+
+static void kvm_free_vcpus(struct kvm *kvm)
+{
+	unsigned int i;
+
+	for (i = 0; i < KVM_MAX_VCPUS; ++i) {
+		if (kvm->vcpus[i]) {
+			kvm_arch_vcpu_destroy(kvm->vcpus[i]);
+			kvm->vcpus[i] = NULL;
+		}
+	}
+}
+
 void kvm_arch_destroy_vm(struct kvm *kvm)
 {
-	debug_unregister(kvm->arch.dbf);
+	kvm_free_vcpus(kvm);
 	kvm_free_physmem(kvm);
 	free_page((unsigned long)(kvm->arch.sca));
+	debug_unregister(kvm->arch.dbf);
 	kfree(kvm);
-	module_put(THIS_MODULE);
 }
 
 /* Section: vcpu related */
@@ -308,8 +325,6 @@ struct kvm_vcpu *kvm_arch_vcpu_create(st
 	VM_EVENT(kvm, 3, "create cpu %d at %p, sie block at %p", id, vcpu,
 		 vcpu->arch.sie_block);
 
-	try_module_get(THIS_MODULE);
-
 	return vcpu;
 out_free_cpu:
 	kfree(vcpu);
@@ -317,14 +332,6 @@ out_nomem:
 	return ERR_PTR(rc);
 }
 
-void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
-{
-	VCPU_EVENT(vcpu, 3, "%s", "destroy cpu");
-	free_page((unsigned long)(vcpu->arch.sie_block));
-	kfree(vcpu);
-	module_put(THIS_MODULE);
-}
-
 int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu)
 {
 	/* kvm common code refers to this, but never calls it */

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

* [PATCH 2/2] kvm-s390: Fix memory leak of vcpu->run
  2008-11-26 13:49 [PATCH 0/2] two refcount and leak fixes for kvm on s390 Christian Borntraeger
  2008-11-26 13:50 ` [PATCH 1/2] kvm-s390: Fix refcounting and allow module unload Christian Borntraeger
@ 2008-11-26 13:51 ` Christian Borntraeger
  2008-11-27 12:40 ` [PATCH 0/2] two refcount and leak fixes for kvm on s390 Avi Kivity
  2 siblings, 0 replies; 4+ messages in thread
From: Christian Borntraeger @ 2008-11-26 13:51 UTC (permalink / raw)
  To: Avi Kivity
  Cc: kvm, Carsten Otte, Heiko Carstens, Martin Schwidefsky,
	Olaf Schnapper

From: Christian Borntraeger <borntraeger@de.ibm.com>

The s390 backend of kvm never calls kvm_vcpu_uninit. This causes
a memory leak of vcpu->run pages.
Lets call kvm_vcpu_uninit in kvm_arch_vcpu_destroy to free
the vcpu->run. 

Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Acked-by: Carsten Otte <cotte@de.ibm.com>
---
 arch/s390/kvm/kvm-s390.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Index: kvm/arch/s390/kvm/kvm-s390.c
===================================================================
--- kvm.orig/arch/s390/kvm/kvm-s390.c
+++ kvm/arch/s390/kvm/kvm-s390.c
@@ -198,6 +198,7 @@ void kvm_arch_vcpu_destroy(struct kvm_vc
 {
 	VCPU_EVENT(vcpu, 3, "%s", "free cpu");
 	free_page((unsigned long)(vcpu->arch.sie_block));
+	kvm_vcpu_uninit(vcpu);
 	kfree(vcpu);
 }
 
@@ -230,8 +231,7 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *
 
 void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu)
 {
-	/* kvm common code refers to this, but does'nt call it */
-	BUG();
+	/* Nothing todo */
 }
 
 void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)

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

* Re: [PATCH 0/2] two refcount and leak fixes for kvm on s390
  2008-11-26 13:49 [PATCH 0/2] two refcount and leak fixes for kvm on s390 Christian Borntraeger
  2008-11-26 13:50 ` [PATCH 1/2] kvm-s390: Fix refcounting and allow module unload Christian Borntraeger
  2008-11-26 13:51 ` [PATCH 2/2] kvm-s390: Fix memory leak of vcpu->run Christian Borntraeger
@ 2008-11-27 12:40 ` Avi Kivity
  2 siblings, 0 replies; 4+ messages in thread
From: Avi Kivity @ 2008-11-27 12:40 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: kvm, Carsten Otte, Heiko Carstens, Martin Schwidefsky,
	Olaf Schnapper

Christian Borntraeger wrote:
> Hello Avi,
>
> here are two fixes for kvm on s390.
>
> [PATCH 1/2] kvm-s390: Fix refcounting and allow module unload
> [PATCH 2/2] kvm-s390: Fix memory leak of vcpu->run
>
> None of the fixed problems is severe. So I guess this should be scheduled for 
> the next merge window. Thanks
>   

Applied, thanks.

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


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

end of thread, other threads:[~2008-11-27 12:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-26 13:49 [PATCH 0/2] two refcount and leak fixes for kvm on s390 Christian Borntraeger
2008-11-26 13:50 ` [PATCH 1/2] kvm-s390: Fix refcounting and allow module unload Christian Borntraeger
2008-11-26 13:51 ` [PATCH 2/2] kvm-s390: Fix memory leak of vcpu->run Christian Borntraeger
2008-11-27 12:40 ` [PATCH 0/2] two refcount and leak fixes for kvm on s390 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.