nvme: fix two issues in nvme unhotplug
cover nvme: fix two issues in nvme unhotplug
The first corrent the refcount and second fix a memory leak.
Li Qiang (2):
nvme: don't unref ctrl_mem when device unrealized
nvme: free cmbuf in nvme_exit
hw/block/nvme.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Signature · 1 line
2.11.0
PATCH 1/2 nvme: don't unref ctrl_mem when device unrealized
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.0qom/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.
--- hw/block/nvme.c | 3 --- 1 file changed, 3 deletions(-)
hw/block/nvme.c +0 -3
@@ -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); }
Signature · 1 line
2.11.0
PATCH 2/2 nvme: free cmbuf in nvme_exit
In reply to Li QiangThis avoid a memory leak in unhotplug nvme device.
--- hw/block/nvme.c | 3 +++ 1 file changed, 3 insertions(+)
hw/block/nvme.c +3 -0
@@ -1332,6 +1332,9 @@ static void nvme_exit(PCIDevice *pci_dev)g_free (n->cq);g_free (n->sq); +if (n->cmb_size_mb) { +g_free (n->cmbuf); + }msix_uninit_exclusive_bar (pci_dev); }
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH 2/2] nvme: free cmbuf in nvme_exit
Quoted 3 lines · Li Qiang
This avoid a memory leak in unhotplug nvme device.
Signed-off-by Li Qiang <[email protected]>
Quoted 19 lines
--- hw/block/nvme.c | 3 +++ 1 file changed, 3 insertions(+)hw/block/nvme.c +3
-0@@ -1332,6 +1332,9 @@ static void nvme_exit(PCIDevice *pci_dev)g_free (n->cq);g_free (n->sq); +if (n->cmb_size_mb) { +g_free (n->cmbuf); + }msix_uninit_exclusive_bar (pci_dev); }
Re: [Qemu-devel] [PATCH 1/2] nvme: don't unref ctrl_mem when device unrealized
In reply to Li QiangPing...
I think this is a serious issue, can go 3.1
Thanks,
Li Qiang
Quoted 44 lines · Li Qiang <[email protected]> 于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)]0x00007fffdb9e4fffin 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.0qom/object.c:981/home/liqiang02/qemu-upstream/qemu/memory.c:1732/home/liqiang02/qemu-upstream/qemu/memory.c:285util/qemu-thread-posix.c:504/lib/x86_64-linux-gnu/libpthread.so.0This is caused by
memory_region_unrefinnvme_exit.Remove it to make the PCIdevice refcount correct.
Signed-off-by Li Qiang <[email protected]>--- hw/block/nvme.c | 3 --- 1 file changed, 3 deletions(-)hw/block/nvme.c +0
-4@@ -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
Re: [Qemu-devel] [PATCH 1/2] nvme: don't unref ctrl_mem when device unrealized
In reply to Li QiangQuoted 17 lines · On Sun, 28 Oct 2018 23:29:40 -0700 Li Qiang <[email protected]> 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)]0x00007fffdb9e4fffin 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.0qom/object.c:981/home/liqiang02/qemu-upstream/qemu/memory.c:1732/home/liqiang02/qemu-upstream/qemu/memory.c:285util/qemu-thread-posix.c:504/lib/x86_64-linux-gnu/libpthread.so.0
Quoted 5 lines
This is caused by
memory_region_unrefinnvme_exit.Remove it to make the PCIdevice refcount correct.
Signed-off-by Li Qiang <[email protected]>
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.
Quoted 18 lines
--- hw/block/nvme.c | 3 --- 1 file changed, 3 deletions(-)hw/block/nvme.c +0
-3@@ -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); }
Kevin Wolf
AppliedAm 29.10.2018 um 07:29 hat Li Qiang geschrieben:
Quoted 1 line
The first corrent the refcount and second fix a memory leak.
Thanks, applied to the block branch.
Kevin