KVM: coalesced_mmio: fix kvm_coalesced_mmio_init()'s error handling
authorTakuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Mon, 15 Mar 2010 13:13:30 +0000 (22:13 +0900)
committerAvi Kivity <avi@redhat.com>
Mon, 17 May 2010 09:15:53 +0000 (12:15 +0300)
kvm_coalesced_mmio_init() keeps to hold the addresses of a coalesced
mmio ring page and dev even after it has freed them.

Also, if this function fails, though it might be rare, it seems to be
suggesting the system's serious state: so we'd better stop the works
following the kvm_creat_vm().

This patch clears these problems.

  We move the coalesced mmio's initialization out of kvm_create_vm().
  This seems to be natural because it includes a registration which
  can be done only when vm is successfully created.

Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
virt/kvm/coalesced_mmio.c
virt/kvm/kvm_main.c

index b66001f..5385017 100644 (file)
@@ -120,8 +120,10 @@ int kvm_coalesced_mmio_init(struct kvm *kvm)
        return ret;
 
 out_free_dev:
+       kvm->coalesced_mmio_dev = NULL;
        kfree(dev);
 out_free_page:
+       kvm->coalesced_mmio_ring = NULL;
        __free_page(page);
 out_err:
        return ret;
index 0db6dfc..55a5d48 100644 (file)
@@ -422,9 +422,6 @@ static struct kvm *kvm_create_vm(void)
        spin_lock(&kvm_lock);
        list_add(&kvm->vm_list, &vm_list);
        spin_unlock(&kvm_lock);
-#ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
-       kvm_coalesced_mmio_init(kvm);
-#endif
 out:
        return kvm;
 
@@ -1753,12 +1750,19 @@ static struct file_operations kvm_vm_fops = {
 
 static int kvm_dev_ioctl_create_vm(void)
 {
-       int fd;
+       int fd, r;
        struct kvm *kvm;
 
        kvm = kvm_create_vm();
        if (IS_ERR(kvm))
                return PTR_ERR(kvm);
+#ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
+       r = kvm_coalesced_mmio_init(kvm);
+       if (r < 0) {
+               kvm_put_kvm(kvm);
+               return r;
+       }
+#endif
        fd = anon_inode_getfd("kvm-vm", &kvm_vm_fops, kvm, O_RDWR);
        if (fd < 0)
                kvm_put_kvm(kvm);