delete virtio queues in vhost-user-blk-unrealize
v2 cover delete virtio queues in vhost-user-blk-unrealize
From: Pan Nengyuan <[email protected]>
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(-)
Signature · 1 line
2.18.2
PATCH v2 1/2 vhost-user-blk: delete virtioqueues in unrealize to fix memleaks
From: Pan Nengyuan <[email protected]>
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---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(+)
hw/block/vhost-user-blk.c +8 -0
@@ -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); }
Signature · 1 line
2.18.2
PATCH v2 2/2 vhost-use-blk: convert to new virtio_delete_queue
In reply to [email protected]From: Pan Nengyuan <[email protected]>
use the new virtio_delete_queue function to cleanup.
---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(-)
hw/block/vhost-user-blk.c +11 -8
@@ -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); }
include/hw/virtio/vhost-user-blk.h +2 -1
@@ -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;
Signature · 1 line
2.18.2
Quoted 10 lines · On Mon, Feb 24, 2020 at 12:13:34PM +0800, [email protected] wrote:
From: Pan Nengyuan <[email protected]>
This series patch fix memleaks when detaching vhost-user-blk device.
1. use oldvirtio_del_queueto 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.html2. convert
virtio_del_queueto the newone(virtio_delete_queue).
v2->v1: rename vqs tovhost_vqsto avoid confusing with virtqs (suggented by Stefan Hajnoczi)
Quoted 12 lines
Pan Nengyuan (2):
vhost-user-blk: delete virtioqueues in unrealize to fix memleaks
vhost-use-blk: convert to newvirtio_delete_queuehw/block/vhost-user-blk.c | 23 +++++++++++++++++------ include/hw/virtio/vhost-user-blk.h | 3 ++- 2 files changed, 19 insertions(+), 7 deletions(-)Signature · 1 line
2.18.2