* [PATCH v2 0/2] delete virtio queues in vhost-user-blk-unrealize
@ 2020-02-24 4:13 pannengyuan
2020-02-24 4:13 ` [PATCH v2 1/2] vhost-user-blk: delete virtioqueues in unrealize to fix memleaks pannengyuan
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: pannengyuan @ 2020-02-24 4:13 UTC (permalink / raw)
To: mst, kwolf, mreitz
Cc: Pan Nengyuan, qemu-devel, qemu-block, zhang.zhanghailiang
From: Pan Nengyuan <pannengyuan@huawei.com>
This series patch fix memleaks when detaching vhost-user-blk device.
1. use old virtio_del_queue to fix memleaks, it's easier for stable branches to merge.
As the discussion in https://lists.nongnu.org/archive/html/qemu-devel/2020-01/msg02903.html
2. convert virtio_del_queue to the new one(virtio_delete_queue).
v2->v1: rename vqs to vhost_vqs to avoid confusing with virtqs (suggented by Stefan Hajnoczi)
Pan Nengyuan (2):
vhost-user-blk: delete virtioqueues in unrealize to fix memleaks
vhost-use-blk: convert to new virtio_delete_queue
hw/block/vhost-user-blk.c | 23 +++++++++++++++++------
include/hw/virtio/vhost-user-blk.h | 3 ++-
2 files changed, 19 insertions(+), 7 deletions(-)
--
2.18.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/2] vhost-user-blk: delete virtioqueues in unrealize to fix memleaks
2020-02-24 4:13 [PATCH v2 0/2] delete virtio queues in vhost-user-blk-unrealize pannengyuan
@ 2020-02-24 4:13 ` pannengyuan
2020-02-24 4:13 ` [PATCH v2 2/2] vhost-use-blk: convert to new virtio_delete_queue pannengyuan
2020-02-24 11:36 ` [PATCH v2 0/2] delete virtio queues in vhost-user-blk-unrealize Stefan Hajnoczi
2 siblings, 0 replies; 4+ messages in thread
From: pannengyuan @ 2020-02-24 4:13 UTC (permalink / raw)
To: mst, kwolf, mreitz
Cc: Pan Nengyuan, qemu-devel, qemu-block, zhang.zhanghailiang
From: Pan Nengyuan <pannengyuan@huawei.com>
virtio queues forgot to delete in unrealize, and aslo error path in
realize, this patch fix these memleaks, the leak stack is as follow:
Direct leak of 114688 byte(s) in 16 object(s) allocated from:
#0 0x7f24024fdbf0 in calloc (/lib64/libasan.so.3+0xcabf0)
#1 0x7f2401642015 in g_malloc0 (/lib64/libglib-2.0.so.0+0x50015)
#2 0x55ad175a6447 in virtio_add_queue /mnt/sdb/qemu/hw/virtio/virtio.c:2327
#3 0x55ad17570cf9 in vhost_user_blk_device_realize /mnt/sdb/qemu/hw/block/vhost-user-blk.c:419
#4 0x55ad175a3707 in virtio_device_realize /mnt/sdb/qemu/hw/virtio/virtio.c:3509
#5 0x55ad176ad0d1 in device_set_realized /mnt/sdb/qemu/hw/core/qdev.c:876
#6 0x55ad1781ff9d in property_set_bool /mnt/sdb/qemu/qom/object.c:2080
#7 0x55ad178245ae in object_property_set_qobject /mnt/sdb/qemu/qom/qom-qobject.c:26
#8 0x55ad17821eb4 in object_property_set_bool /mnt/sdb/qemu/qom/object.c:1338
#9 0x55ad177aeed7 in virtio_pci_realize /mnt/sdb/qemu/hw/virtio/virtio-pci.c:1801
Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
v2->v1: There is no change in this patch(only change the patch2/2)
---
hw/block/vhost-user-blk.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c
index d8c459c575..2eba8b9db0 100644
--- a/hw/block/vhost-user-blk.c
+++ b/hw/block/vhost-user-blk.c
@@ -460,6 +460,9 @@ reconnect:
virtio_err:
g_free(s->vqs);
g_free(s->inflight);
+ for (i = 0; i < s->num_queues; i++) {
+ virtio_del_queue(vdev, i);
+ }
virtio_cleanup(vdev);
vhost_user_cleanup(&s->vhost_user);
}
@@ -468,6 +471,7 @@ static void vhost_user_blk_device_unrealize(DeviceState *dev, Error **errp)
{
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
VHostUserBlk *s = VHOST_USER_BLK(dev);
+ int i;
virtio_set_status(vdev, 0);
qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, NULL,
@@ -476,6 +480,10 @@ static void vhost_user_blk_device_unrealize(DeviceState *dev, Error **errp)
vhost_dev_free_inflight(s->inflight);
g_free(s->vqs);
g_free(s->inflight);
+
+ for (i = 0; i < s->num_queues; i++) {
+ virtio_del_queue(vdev, i);
+ }
virtio_cleanup(vdev);
vhost_user_cleanup(&s->vhost_user);
}
--
2.18.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 2/2] vhost-use-blk: convert to new virtio_delete_queue
2020-02-24 4:13 [PATCH v2 0/2] delete virtio queues in vhost-user-blk-unrealize pannengyuan
2020-02-24 4:13 ` [PATCH v2 1/2] vhost-user-blk: delete virtioqueues in unrealize to fix memleaks pannengyuan
@ 2020-02-24 4:13 ` pannengyuan
2020-02-24 11:36 ` [PATCH v2 0/2] delete virtio queues in vhost-user-blk-unrealize Stefan Hajnoczi
2 siblings, 0 replies; 4+ messages in thread
From: pannengyuan @ 2020-02-24 4:13 UTC (permalink / raw)
To: mst, kwolf, mreitz
Cc: Pan Nengyuan, qemu-devel, qemu-block, zhang.zhanghailiang
From: Pan Nengyuan <pannengyuan@huawei.com>
use the new virtio_delete_queue function to cleanup.
Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
---
V2->V1:
- rename vqs to vhost_vqs to avoid confusing with virtqs (suggented by Stefan Hajnoczi)
---
hw/block/vhost-user-blk.c | 19 +++++++++++--------
include/hw/virtio/vhost-user-blk.h | 3 ++-
2 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c
index 2eba8b9db0..12925a47ec 100644
--- a/hw/block/vhost-user-blk.c
+++ b/hw/block/vhost-user-blk.c
@@ -306,7 +306,7 @@ static int vhost_user_blk_connect(DeviceState *dev)
s->connected = true;
s->dev.nvqs = s->num_queues;
- s->dev.vqs = s->vqs;
+ s->dev.vqs = s->vhost_vqs;
s->dev.vq_index = 0;
s->dev.backend_features = 0;
@@ -420,13 +420,14 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp)
virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK,
sizeof(struct virtio_blk_config));
+ s->virtqs = g_new(VirtQueue *, s->num_queues);
for (i = 0; i < s->num_queues; i++) {
- virtio_add_queue(vdev, s->queue_size,
- vhost_user_blk_handle_output);
+ s->virtqs[i] = virtio_add_queue(vdev, s->queue_size,
+ vhost_user_blk_handle_output);
}
s->inflight = g_new0(struct vhost_inflight, 1);
- s->vqs = g_new0(struct vhost_virtqueue, s->num_queues);
+ s->vhost_vqs = g_new0(struct vhost_virtqueue, s->num_queues);
s->watch = 0;
s->connected = false;
@@ -458,11 +459,12 @@ reconnect:
return;
virtio_err:
- g_free(s->vqs);
+ g_free(s->vhost_vqs);
g_free(s->inflight);
for (i = 0; i < s->num_queues; i++) {
- virtio_del_queue(vdev, i);
+ virtio_delete_queue(s->virtqs[i]);
}
+ g_free(s->virtqs);
virtio_cleanup(vdev);
vhost_user_cleanup(&s->vhost_user);
}
@@ -478,12 +480,13 @@ static void vhost_user_blk_device_unrealize(DeviceState *dev, Error **errp)
NULL, NULL, NULL, false);
vhost_dev_cleanup(&s->dev);
vhost_dev_free_inflight(s->inflight);
- g_free(s->vqs);
+ g_free(s->vhost_vqs);
g_free(s->inflight);
for (i = 0; i < s->num_queues; i++) {
- virtio_del_queue(vdev, i);
+ virtio_delete_queue(s->virtqs[i]);
}
+ g_free(s->virtqs);
virtio_cleanup(vdev);
vhost_user_cleanup(&s->vhost_user);
}
diff --git a/include/hw/virtio/vhost-user-blk.h b/include/hw/virtio/vhost-user-blk.h
index 108bfadeeb..05ea0ad183 100644
--- a/include/hw/virtio/vhost-user-blk.h
+++ b/include/hw/virtio/vhost-user-blk.h
@@ -36,7 +36,8 @@ typedef struct VHostUserBlk {
struct vhost_dev dev;
struct vhost_inflight *inflight;
VhostUserState vhost_user;
- struct vhost_virtqueue *vqs;
+ struct vhost_virtqueue *vhost_vqs;
+ VirtQueue **virtqs;
guint watch;
bool connected;
} VHostUserBlk;
--
2.18.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2 0/2] delete virtio queues in vhost-user-blk-unrealize
2020-02-24 4:13 [PATCH v2 0/2] delete virtio queues in vhost-user-blk-unrealize pannengyuan
2020-02-24 4:13 ` [PATCH v2 1/2] vhost-user-blk: delete virtioqueues in unrealize to fix memleaks pannengyuan
2020-02-24 4:13 ` [PATCH v2 2/2] vhost-use-blk: convert to new virtio_delete_queue pannengyuan
@ 2020-02-24 11:36 ` Stefan Hajnoczi
2 siblings, 0 replies; 4+ messages in thread
From: Stefan Hajnoczi @ 2020-02-24 11:36 UTC (permalink / raw)
To: pannengyuan
Cc: kwolf, zhang.zhanghailiang, qemu-block, mst, qemu-devel, mreitz
[-- Attachment #1: Type: text/plain, Size: 964 bytes --]
On Mon, Feb 24, 2020 at 12:13:34PM +0800, pannengyuan@huawei.com wrote:
> From: Pan Nengyuan <pannengyuan@huawei.com>
>
> This series patch fix memleaks when detaching vhost-user-blk device.
> 1. use old virtio_del_queue to fix memleaks, it's easier for stable branches to merge.
> As the discussion in https://lists.nongnu.org/archive/html/qemu-devel/2020-01/msg02903.html
>
> 2. convert virtio_del_queue to the new one(virtio_delete_queue).
>
> v2->v1: rename vqs to vhost_vqs to avoid confusing with virtqs (suggented by Stefan Hajnoczi)
>
> Pan Nengyuan (2):
> vhost-user-blk: delete virtioqueues in unrealize to fix memleaks
> vhost-use-blk: convert to new virtio_delete_queue
>
> hw/block/vhost-user-blk.c | 23 +++++++++++++++++------
> include/hw/virtio/vhost-user-blk.h | 3 ++-
> 2 files changed, 19 insertions(+), 7 deletions(-)
>
> --
> 2.18.2
>
>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-02-24 11:37 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-24 4:13 [PATCH v2 0/2] delete virtio queues in vhost-user-blk-unrealize pannengyuan
2020-02-24 4:13 ` [PATCH v2 1/2] vhost-user-blk: delete virtioqueues in unrealize to fix memleaks pannengyuan
2020-02-24 4:13 ` [PATCH v2 2/2] vhost-use-blk: convert to new virtio_delete_queue pannengyuan
2020-02-24 11:36 ` [PATCH v2 0/2] delete virtio queues in vhost-user-blk-unrealize Stefan Hajnoczi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).