diff mbox series

[1/2] nvme: don't unref ctrl_mem when device unrealized

Message ID 1540794581-33578-2-git-send-email-liq3ea@gmail.com (mailing list archive)
State New, archived
Headers show
Series nvme: fix two issues in nvme unhotplug | expand

Commit Message

Li Qiang Oct. 29, 2018, 6:29 a.m. UTC
Currently, when hotplug/unhotplug nvme device, it will cause an
assert in object.c. Following is the backtrack:

ERROR:qom/object.c:981:object_unref: assertion failed: (obj->ref > 0)

Thread 2 "qemu-system-x86" received signal SIGABRT, Aborted.
[Switching to Thread 0x7fffcbd32700 (LWP 18844)]
0x00007fffdb9e4fff in raise () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) bt
/lib/x86_64-linux-gnu/libglib-2.0.so.0
/lib/x86_64-linux-gnu/libglib-2.0.so.0
qom/object.c:981
/home/liqiang02/qemu-upstream/qemu/memory.c:1732
/home/liqiang02/qemu-upstream/qemu/memory.c:285
util/qemu-thread-posix.c:504
/lib/x86_64-linux-gnu/libpthread.so.0

This is caused by memory_region_unref in nvme_exit.

Remove it to make the PCIdevice refcount correct.

Signed-off-by: Li Qiang <liq3ea@gmail.com>
---
 hw/block/nvme.c | 3 ---
 1 file changed, 3 deletions(-)

Comments

Li Qiang Nov. 5, 2018, 2:57 p.m. UTC | #1
Ping...

I think this is a serious issue, can go 3.1

Thanks,
Li Qiang

Li Qiang <liq3ea@gmail.com> 于2018年10月29日周一 下午2:29写道:

> Currently, when hotplug/unhotplug nvme device, it will cause an
> assert in object.c. Following is the backtrack:
>
> ERROR:qom/object.c:981:object_unref: assertion failed: (obj->ref > 0)
>
> Thread 2 "qemu-system-x86" received signal SIGABRT, Aborted.
> [Switching to Thread 0x7fffcbd32700 (LWP 18844)]
> 0x00007fffdb9e4fff in raise () from /lib/x86_64-linux-gnu/libc.so.6
> (gdb) bt
> /lib/x86_64-linux-gnu/libglib-2.0.so.0
> /lib/x86_64-linux-gnu/libglib-2.0.so.0
> qom/object.c:981
> /home/liqiang02/qemu-upstream/qemu/memory.c:1732
> /home/liqiang02/qemu-upstream/qemu/memory.c:285
> util/qemu-thread-posix.c:504
> /lib/x86_64-linux-gnu/libpthread.so.0
>
> This is caused by memory_region_unref in nvme_exit.
>
> Remove it to make the PCIdevice refcount correct.
>
> Signed-off-by: Li Qiang <liq3ea@gmail.com>
> ---
>  hw/block/nvme.c | 3 ---
>  1 file changed, 3 deletions(-)
>
> diff --git a/hw/block/nvme.c b/hw/block/nvme.c
> index fc7dacb816..359a06d0ad 100644
> --- a/hw/block/nvme.c
> +++ b/hw/block/nvme.c
> @@ -1331,9 +1331,6 @@ static void nvme_exit(PCIDevice *pci_dev)
>      g_free(n->namespaces);
>      g_free(n->cq);
>      g_free(n->sq);
> -    if (n->cmbsz) {
> -        memory_region_unref(&n->ctrl_mem);
> -    }
>
>      msix_uninit_exclusive_bar(pci_dev);
>  }
> --
> 2.11.0
>
>
Igor Mammedov Nov. 6, 2018, 3:58 p.m. UTC | #2
On Sun, 28 Oct 2018 23:29:40 -0700
Li Qiang <liq3ea@gmail.com> wrote:

> Currently, when hotplug/unhotplug nvme device, it will cause an
> assert in object.c. Following is the backtrack:
> 
> ERROR:qom/object.c:981:object_unref: assertion failed: (obj->ref > 0)
> 
> Thread 2 "qemu-system-x86" received signal SIGABRT, Aborted.
> [Switching to Thread 0x7fffcbd32700 (LWP 18844)]
> 0x00007fffdb9e4fff in raise () from /lib/x86_64-linux-gnu/libc.so.6
> (gdb) bt
> /lib/x86_64-linux-gnu/libglib-2.0.so.0
> /lib/x86_64-linux-gnu/libglib-2.0.so.0
> qom/object.c:981
> /home/liqiang02/qemu-upstream/qemu/memory.c:1732
> /home/liqiang02/qemu-upstream/qemu/memory.c:285
> util/qemu-thread-posix.c:504
> /lib/x86_64-linux-gnu/libpthread.so.0
> 
> This is caused by memory_region_unref in nvme_exit.
> 
> Remove it to make the PCIdevice refcount correct.
> 
> Signed-off-by: Li Qiang <liq3ea@gmail.com>
nvme device holds a reference to ctrl_mem MemoryRegion as a parent
so MemoryRegion will be destroyed later during destruction of
nvme object when its cildren are un-parented.

Reviewed-by: Igor Mammedov <imammedo@redhat.com>

> ---
>  hw/block/nvme.c | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/hw/block/nvme.c b/hw/block/nvme.c
> index fc7dacb816..359a06d0ad 100644
> --- a/hw/block/nvme.c
> +++ b/hw/block/nvme.c
> @@ -1331,9 +1331,6 @@ static void nvme_exit(PCIDevice *pci_dev)
>      g_free(n->namespaces);
>      g_free(n->cq);
>      g_free(n->sq);
> -    if (n->cmbsz) {
> -        memory_region_unref(&n->ctrl_mem);
> -    }
>  
>      msix_uninit_exclusive_bar(pci_dev);
>  }
diff mbox series

Patch

diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index fc7dacb816..359a06d0ad 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -1331,9 +1331,6 @@  static void nvme_exit(PCIDevice *pci_dev)
     g_free(n->namespaces);
     g_free(n->cq);
     g_free(n->sq);
-    if (n->cmbsz) {
-        memory_region_unref(&n->ctrl_mem);
-    }
 
     msix_uninit_exclusive_bar(pci_dev);
 }