public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Don't destroy vcpu in case vcpu_setup fails
@ 2008-09-18  2:16 Glauber Costa
  2008-09-23  9:21 ` Avi Kivity
  0 siblings, 1 reply; 2+ messages in thread
From: Glauber Costa @ 2008-09-18  2:16 UTC (permalink / raw)
  To: kvm; +Cc: avi, aliguori

One of vcpu_setup responsibilities is to do mmu initialization.
However, in case we fail in kvm_arch_vcpu_reset, before we get the
chance to init mmu. OTOH, vcpu_destroy will attempt to destroy mmu,
triggering a bug. Keeping track of whether or not mmu is initialized
would unnecessarily complicate things. Rather, we just make return,
making sure any needed uninitialization is done before we return, in
case we fail.

Signed-off-by: Glauber Costa <glommer@redhat.com>
---
 virt/kvm/kvm_main.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index f42d5c2..644567f 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1089,12 +1089,11 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, int n)
 
 	r = kvm_arch_vcpu_setup(vcpu);
 	if (r)
-		goto vcpu_destroy;
+		return r;
 
 	mutex_lock(&kvm->lock);
 	if (kvm->vcpus[n]) {
 		r = -EEXIST;
-		mutex_unlock(&kvm->lock);
 		goto vcpu_destroy;
 	}
 	kvm->vcpus[n] = vcpu;
@@ -1110,8 +1109,8 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, int n)
 unlink:
 	mutex_lock(&kvm->lock);
 	kvm->vcpus[n] = NULL;
-	mutex_unlock(&kvm->lock);
 vcpu_destroy:
+	mutex_unlock(&kvm->lock);
 	kvm_arch_vcpu_destroy(vcpu);
 	return r;
 }
-- 
1.5.5.1


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

* Re: [PATCH] Don't destroy vcpu in case vcpu_setup fails
  2008-09-18  2:16 [PATCH] Don't destroy vcpu in case vcpu_setup fails Glauber Costa
@ 2008-09-23  9:21 ` Avi Kivity
  0 siblings, 0 replies; 2+ messages in thread
From: Avi Kivity @ 2008-09-23  9:21 UTC (permalink / raw)
  To: Glauber Costa; +Cc: kvm, aliguori

Glauber Costa wrote:
> One of vcpu_setup responsibilities is to do mmu initialization.
> However, in case we fail in kvm_arch_vcpu_reset, before we get the
> chance to init mmu. OTOH, vcpu_destroy will attempt to destroy mmu,
> triggering a bug. Keeping track of whether or not mmu is initialized
> would unnecessarily complicate things. Rather, we just make return,
> making sure any needed uninitialization is done before we return, in
> case we fail.
>   

Applied, thanks.

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


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

end of thread, other threads:[~2008-09-23  9:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-18  2:16 [PATCH] Don't destroy vcpu in case vcpu_setup fails Glauber Costa
2008-09-23  9:21 ` Avi Kivity

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox