qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

vhost-vsock: delete vqs in vhost_vsock_unrealize to avoid memleaks

Receive/transmit/event vqs forgot to cleanup in vhost_vsock_unrealize. This
patch save receive/transmit vq pointer in realize() and cleanup vqs
through those vq pointers in unrealize(). The leak stack is as follow:

Direct leak of 21504 byte(s) in 3 object(s) allocated from:
#0 0x7f86a1356970 (/lib64/libasan.so.5+0xef970) ??:?
#1 0x7f86a09aa49d (/lib64/libglib-2.0.so.0+0x5249d) ??:?
#2 0x5604852f85ca (./x86_64-softmmu/qemu-system-x86_64+0x2c3e5ca) /mnt/sdb/qemu/hw/virtio/virtio.c:2333
#3 0x560485356208 (./x86_64-softmmu/qemu-system-x86_64+0x2c9c208) /mnt/sdb/qemu/hw/virtio/vhost-vsock.c:339
#4 0x560485305a17 (./x86_64-softmmu/qemu-system-x86_64+0x2c4ba17) /mnt/sdb/qemu/hw/virtio/virtio.c:3531
#5 0x5604858e6b65 (./x86_64-softmmu/qemu-system-x86_64+0x322cb65) /mnt/sdb/qemu/hw/core/qdev.c:865
#6 0x5604861e6c41 (./x86_64-softmmu/qemu-system-x86_64+0x3b2cc41) /mnt/sdb/qemu/qom/object.c:2102

Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
Message-Id: <20200115062535.50644-1-pannengyuan@huawei.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

authored by

Pan Nengyuan and committed by
Michael S. Tsirkin
e1932cf9 2feff67c

+12 -2
+10 -2
hw/virtio/vhost-vsock.c
··· 335 335 sizeof(struct virtio_vsock_config)); 336 336 337 337 /* Receive and transmit queues belong to vhost */ 338 - virtio_add_queue(vdev, VHOST_VSOCK_QUEUE_SIZE, vhost_vsock_handle_output); 339 - virtio_add_queue(vdev, VHOST_VSOCK_QUEUE_SIZE, vhost_vsock_handle_output); 338 + vsock->recv_vq = virtio_add_queue(vdev, VHOST_VSOCK_QUEUE_SIZE, 339 + vhost_vsock_handle_output); 340 + vsock->trans_vq = virtio_add_queue(vdev, VHOST_VSOCK_QUEUE_SIZE, 341 + vhost_vsock_handle_output); 340 342 341 343 /* The event queue belongs to QEMU */ 342 344 vsock->event_vq = virtio_add_queue(vdev, VHOST_VSOCK_QUEUE_SIZE, ··· 363 365 err_vhost_dev: 364 366 vhost_dev_cleanup(&vsock->vhost_dev); 365 367 err_virtio: 368 + virtio_delete_queue(vsock->recv_vq); 369 + virtio_delete_queue(vsock->trans_vq); 370 + virtio_delete_queue(vsock->event_vq); 366 371 virtio_cleanup(vdev); 367 372 close(vhostfd); 368 373 return; ··· 379 384 vhost_vsock_set_status(vdev, 0); 380 385 381 386 vhost_dev_cleanup(&vsock->vhost_dev); 387 + virtio_delete_queue(vsock->recv_vq); 388 + virtio_delete_queue(vsock->trans_vq); 389 + virtio_delete_queue(vsock->event_vq); 382 390 virtio_cleanup(vdev); 383 391 } 384 392
+2
include/hw/virtio/vhost-vsock.h
··· 33 33 struct vhost_virtqueue vhost_vqs[2]; 34 34 struct vhost_dev vhost_dev; 35 35 VirtQueue *event_vq; 36 + VirtQueue *recv_vq; 37 + VirtQueue *trans_vq; 36 38 QEMUTimer *post_load_timer; 37 39 38 40 /*< public >*/