* [PATCH 0/4] virtio: fix some virtio-queue leaks.
@ 2020-02-25 7:55 Pan Nengyuan
2020-02-25 7:55 ` [PATCH 1/4] vhost-user-fs: do delete virtio_queues in unrealize Pan Nengyuan
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Pan Nengyuan @ 2020-02-25 7:55 UTC (permalink / raw)
To: mst; +Cc: euler.robot, Pan Nengyuan, qemu-devel, zhang.zhanghailiang
Similar to other virtio device(https://patchwork.kernel.org/patch/11399237/), we aslo found some virtio-queue leaks in unrealize().
This series do the cleanup in unrealize to fix it.
Pan Nengyuan (4):
vhost-user-fs: do delete virtio_queues in unrealize
vhost-user-fs: convert to the new virtio_delete_queue function
virtio-pmem: do delete rq_vq in virtio_pmem_unrealize
virtio-crypto: do delete ctrl_vq in virtio_crypto_device_unrealize
hw/virtio/vhost-user-fs.c | 16 ++++++++++++++--
hw/virtio/virtio-crypto.c | 3 ++-
hw/virtio/virtio-pmem.c | 1 +
include/hw/virtio/vhost-user-fs.h | 2 ++
4 files changed, 19 insertions(+), 3 deletions(-)
--
2.18.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/4] vhost-user-fs: do delete virtio_queues in unrealize
2020-02-25 7:55 [PATCH 0/4] virtio: fix some virtio-queue leaks Pan Nengyuan
@ 2020-02-25 7:55 ` Pan Nengyuan
2020-02-25 7:55 ` [PATCH 2/4] vhost-user-fs: convert to the new virtio_delete_queue function Pan Nengyuan
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Pan Nengyuan @ 2020-02-25 7:55 UTC (permalink / raw)
To: mst
Cc: zhang.zhanghailiang, Pan Nengyuan, qemu-devel,
Dr. David Alan Gilbert, Stefan Hajnoczi, euler.robot
Similar to other virtio device(https://patchwork.kernel.org/patch/11399237/), 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 57344 byte(s) in 1 object(s) allocated from:
#0 0x7f15784fb970 in __interceptor_calloc (/lib64/libasan.so.5+0xef970)
#1 0x7f157790849d in g_malloc0 (/lib64/libglib-2.0.so.0+0x5249d)
#2 0x55587a1bf859 in virtio_add_queue /mnt/sdb/qemu-new/qemu_test/qemu/hw/virtio/virtio.c:2333
#3 0x55587a2071d5 in vuf_device_realize /mnt/sdb/qemu-new/qemu_test/qemu/hw/virtio/vhost-user-fs.c:212
#4 0x55587a1ae360 in virtio_device_realize /mnt/sdb/qemu-new/qemu_test/qemu/hw/virtio/virtio.c:3531
#5 0x55587a63fb7b in device_set_realized /mnt/sdb/qemu-new/qemu_test/qemu/hw/core/qdev.c:891
#6 0x55587acf03f5 in property_set_bool /mnt/sdb/qemu-new/qemu_test/qemu/qom/object.c:2238
#7 0x55587acfce0d in object_property_set_qobject /mnt/sdb/qemu-new/qemu_test/qemu/qom/qom-qobject.c:26
#8 0x55587acf5c8c in object_property_set_bool /mnt/sdb/qemu-new/qemu_test/qemu/qom/object.c:1390
#9 0x55587a8e22a2 in pci_qdev_realize /mnt/sdb/qemu-new/qemu_test/qemu/hw/pci/pci.c:2095
#10 0x55587a63fb7b in device_set_realized /mnt/sdb/qemu-new/qemu_test/qemu/hw/core/qdev.c:891
#11 0x55587acf03f5 in property_set_bool /mnt/sdb/qemu-new/qemu_test/qemu/qom/object.c:2238
#12 0x55587acfce0d in object_property_set_qobject /mnt/sdb/qemu-new/qemu_test/qemu/qom/qom-qobject.c:26
#13 0x55587acf5c8c in object_property_set_bool /mnt/sdb/qemu-new/qemu_test/qemu/qom/object.c:1390
#14 0x55587a496d65 in qdev_device_add /mnt/sdb/qemu-new/qemu_test/qemu/qdev-monitor.c:679
Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
Cc: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
Cc: Stefan Hajnoczi <stefanha@redhat.com>
---
hw/virtio/vhost-user-fs.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c
index 33b17848c2..4554d123b7 100644
--- a/hw/virtio/vhost-user-fs.c
+++ b/hw/virtio/vhost-user-fs.c
@@ -230,6 +230,10 @@ static void vuf_device_realize(DeviceState *dev, Error **errp)
err_virtio:
vhost_user_cleanup(&fs->vhost_user);
+ virtio_del_queue(vdev, 0);
+ for (i = 0; i < fs->conf.num_request_queues; i++) {
+ virtio_del_queue(vdev, i + 1);
+ }
virtio_cleanup(vdev);
g_free(fs->vhost_dev.vqs);
return;
@@ -239,6 +243,7 @@ static void vuf_device_unrealize(DeviceState *dev, Error **errp)
{
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
VHostUserFS *fs = VHOST_USER_FS(dev);
+ int i;
/* This will stop vhost backend if appropriate. */
vuf_set_status(vdev, 0);
@@ -247,6 +252,10 @@ static void vuf_device_unrealize(DeviceState *dev, Error **errp)
vhost_user_cleanup(&fs->vhost_user);
+ virtio_del_queue(vdev, 0);
+ for (i = 0; i < fs->conf.num_request_queues; i++) {
+ virtio_del_queue(vdev, i + 1);
+ }
virtio_cleanup(vdev);
g_free(fs->vhost_dev.vqs);
fs->vhost_dev.vqs = NULL;
--
2.18.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/4] vhost-user-fs: convert to the new virtio_delete_queue function
2020-02-25 7:55 [PATCH 0/4] virtio: fix some virtio-queue leaks Pan Nengyuan
2020-02-25 7:55 ` [PATCH 1/4] vhost-user-fs: do delete virtio_queues in unrealize Pan Nengyuan
@ 2020-02-25 7:55 ` Pan Nengyuan
2020-02-25 7:55 ` [PATCH 3/4] virtio-pmem: do delete rq_vq in virtio_pmem_unrealize Pan Nengyuan
2020-02-25 7:55 ` [PATCH 4/4] virtio-crypto: do delete ctrl_vq in virtio_crypto_device_unrealize Pan Nengyuan
3 siblings, 0 replies; 6+ messages in thread
From: Pan Nengyuan @ 2020-02-25 7:55 UTC (permalink / raw)
To: mst
Cc: zhang.zhanghailiang, Pan Nengyuan, qemu-devel,
Dr. David Alan Gilbert, Stefan Hajnoczi, euler.robot
use the new virtio_delete_queue function to cleanup.
Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
Cc: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
Cc: Stefan Hajnoczi <stefanha@redhat.com>
---
hw/virtio/vhost-user-fs.c | 15 +++++++++------
include/hw/virtio/vhost-user-fs.h | 2 ++
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c
index 4554d123b7..6136768875 100644
--- a/hw/virtio/vhost-user-fs.c
+++ b/hw/virtio/vhost-user-fs.c
@@ -209,11 +209,12 @@ static void vuf_device_realize(DeviceState *dev, Error **errp)
sizeof(struct virtio_fs_config));
/* Hiprio queue */
- virtio_add_queue(vdev, fs->conf.queue_size, vuf_handle_output);
+ fs->hiprio_vq = virtio_add_queue(vdev, fs->conf.queue_size, vuf_handle_output);
/* Request queues */
+ fs->req_vqs = g_new(VirtQueue *, fs->conf.num_request_queues);
for (i = 0; i < fs->conf.num_request_queues; i++) {
- virtio_add_queue(vdev, fs->conf.queue_size, vuf_handle_output);
+ fs->req_vqs[i] = virtio_add_queue(vdev, fs->conf.queue_size, vuf_handle_output);
}
/* 1 high prio queue, plus the number configured */
@@ -230,10 +231,11 @@ static void vuf_device_realize(DeviceState *dev, Error **errp)
err_virtio:
vhost_user_cleanup(&fs->vhost_user);
- virtio_del_queue(vdev, 0);
+ virtio_delete_queue(fs->hiprio_vq);
for (i = 0; i < fs->conf.num_request_queues; i++) {
- virtio_del_queue(vdev, i + 1);
+ virtio_delete_queue(fs->req_vqs[i]);
}
+ g_free(fs->req_vqs);
virtio_cleanup(vdev);
g_free(fs->vhost_dev.vqs);
return;
@@ -252,10 +254,11 @@ static void vuf_device_unrealize(DeviceState *dev, Error **errp)
vhost_user_cleanup(&fs->vhost_user);
- virtio_del_queue(vdev, 0);
+ virtio_delete_queue(fs->hiprio_vq);
for (i = 0; i < fs->conf.num_request_queues; i++) {
- virtio_del_queue(vdev, i + 1);
+ virtio_delete_queue(fs->req_vqs[i]);
}
+ g_free(fs->req_vqs);
virtio_cleanup(vdev);
g_free(fs->vhost_dev.vqs);
fs->vhost_dev.vqs = NULL;
diff --git a/include/hw/virtio/vhost-user-fs.h b/include/hw/virtio/vhost-user-fs.h
index 9ff1bdb7cf..6f3030d288 100644
--- a/include/hw/virtio/vhost-user-fs.h
+++ b/include/hw/virtio/vhost-user-fs.h
@@ -37,6 +37,8 @@ typedef struct {
struct vhost_virtqueue *vhost_vqs;
struct vhost_dev vhost_dev;
VhostUserState vhost_user;
+ VirtQueue **req_vqs;
+ VirtQueue *hiprio_vq;
/*< public >*/
} VHostUserFS;
--
2.18.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/4] virtio-pmem: do delete rq_vq in virtio_pmem_unrealize
2020-02-25 7:55 [PATCH 0/4] virtio: fix some virtio-queue leaks Pan Nengyuan
2020-02-25 7:55 ` [PATCH 1/4] vhost-user-fs: do delete virtio_queues in unrealize Pan Nengyuan
2020-02-25 7:55 ` [PATCH 2/4] vhost-user-fs: convert to the new virtio_delete_queue function Pan Nengyuan
@ 2020-02-25 7:55 ` Pan Nengyuan
2020-02-25 9:21 ` Philippe Mathieu-Daudé
2020-02-25 7:55 ` [PATCH 4/4] virtio-crypto: do delete ctrl_vq in virtio_crypto_device_unrealize Pan Nengyuan
3 siblings, 1 reply; 6+ messages in thread
From: Pan Nengyuan @ 2020-02-25 7:55 UTC (permalink / raw)
To: mst; +Cc: euler.robot, Pan Nengyuan, qemu-devel, zhang.zhanghailiang
Similar to other virtio-deivces, rq_vq forgot to delete in virtio_pmem_unrealize, this patch fix it.
This device has aleardy maintained a vq pointer, thus we use the new virtio_delete_queue function directly to do the cleanup.
Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
---
hw/virtio/virtio-pmem.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/hw/virtio/virtio-pmem.c b/hw/virtio/virtio-pmem.c
index 97287e923b..43399522f5 100644
--- a/hw/virtio/virtio-pmem.c
+++ b/hw/virtio/virtio-pmem.c
@@ -130,6 +130,7 @@ static void virtio_pmem_unrealize(DeviceState *dev, Error **errp)
VirtIOPMEM *pmem = VIRTIO_PMEM(dev);
host_memory_backend_set_mapped(pmem->memdev, false);
+ virtio_delete_queue(pmem->rq_vq);
virtio_cleanup(vdev);
}
--
2.18.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 4/4] virtio-crypto: do delete ctrl_vq in virtio_crypto_device_unrealize
2020-02-25 7:55 [PATCH 0/4] virtio: fix some virtio-queue leaks Pan Nengyuan
` (2 preceding siblings ...)
2020-02-25 7:55 ` [PATCH 3/4] virtio-pmem: do delete rq_vq in virtio_pmem_unrealize Pan Nengyuan
@ 2020-02-25 7:55 ` Pan Nengyuan
3 siblings, 0 replies; 6+ messages in thread
From: Pan Nengyuan @ 2020-02-25 7:55 UTC (permalink / raw)
To: mst
Cc: Gonglei (Arei), euler.robot, Pan Nengyuan, qemu-devel,
zhang.zhanghailiang
Similar to other virtio-deivces, ctrl_vq forgot to delete in virtio_crypto_device_unrealize, this patch fix it.
This device has aleardy maintained vq pointers. Thus, we use the new virtio_delete_queue function directly to do the cleanup.
The leak stack:
Direct leak of 10752 byte(s) in 3 object(s) allocated from:
#0 0x7f4c024b1970 in __interceptor_calloc (/lib64/libasan.so.5+0xef970)
#1 0x7f4c018be49d in g_malloc0 (/lib64/libglib-2.0.so.0+0x5249d)
#2 0x55a2f8017279 in virtio_add_queue /mnt/sdb/qemu-new/qemu_test/qemu/hw/virtio/virtio.c:2333
#3 0x55a2f8057035 in virtio_crypto_device_realize /mnt/sdb/qemu-new/qemu_test/qemu/hw/virtio/virtio-crypto.c:814
#4 0x55a2f8005d80 in virtio_device_realize /mnt/sdb/qemu-new/qemu_test/qemu/hw/virtio/virtio.c:3531
#5 0x55a2f8497d1b in device_set_realized /mnt/sdb/qemu-new/qemu_test/qemu/hw/core/qdev.c:891
#6 0x55a2f8b48595 in property_set_bool /mnt/sdb/qemu-new/qemu_test/qemu/qom/object.c:2238
#7 0x55a2f8b54fad in object_property_set_qobject /mnt/sdb/qemu-new/qemu_test/qemu/qom/qom-qobject.c:26
#8 0x55a2f8b4de2c in object_property_set_bool /mnt/sdb/qemu-new/qemu_test/qemu/qom/object.c:1390
#9 0x55a2f80609c9 in virtio_crypto_pci_realize /mnt/sdb/qemu-new/qemu_test/qemu/hw/virtio/virtio-crypto-pci.c:58
Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
Cc: "Gonglei (Arei)" <arei.gonglei@huawei.com>
---
hw/virtio/virtio-crypto.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c
index 7351ab0a19..4c65114de5 100644
--- a/hw/virtio/virtio-crypto.c
+++ b/hw/virtio/virtio-crypto.c
@@ -831,12 +831,13 @@ static void virtio_crypto_device_unrealize(DeviceState *dev, Error **errp)
max_queues = vcrypto->multiqueue ? vcrypto->max_queues : 1;
for (i = 0; i < max_queues; i++) {
- virtio_del_queue(vdev, i);
+ virtio_delete_queue(vcrypto->vqs[i].dataq);
q = &vcrypto->vqs[i];
qemu_bh_delete(q->dataq_bh);
}
g_free(vcrypto->vqs);
+ virtio_delete_queue(vcrypto->ctrl_vq);
virtio_cleanup(vdev);
cryptodev_backend_set_used(vcrypto->cryptodev, false);
--
2.18.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 3/4] virtio-pmem: do delete rq_vq in virtio_pmem_unrealize
2020-02-25 7:55 ` [PATCH 3/4] virtio-pmem: do delete rq_vq in virtio_pmem_unrealize Pan Nengyuan
@ 2020-02-25 9:21 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-25 9:21 UTC (permalink / raw)
To: Pan Nengyuan, mst; +Cc: zhang.zhanghailiang, qemu-devel, euler.robot
On 2/25/20 8:55 AM, Pan Nengyuan wrote:
> Similar to other virtio-deivces, rq_vq forgot to delete in virtio_pmem_unrealize, this patch fix it.
"devices"
> This device has aleardy maintained a vq pointer, thus we use the new virtio_delete_queue function directly to do the cleanup.
"already"
>
> Reported-by: Euler Robot <euler.robot@huawei.com>
> Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
> hw/virtio/virtio-pmem.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/hw/virtio/virtio-pmem.c b/hw/virtio/virtio-pmem.c
> index 97287e923b..43399522f5 100644
> --- a/hw/virtio/virtio-pmem.c
> +++ b/hw/virtio/virtio-pmem.c
> @@ -130,6 +130,7 @@ static void virtio_pmem_unrealize(DeviceState *dev, Error **errp)
> VirtIOPMEM *pmem = VIRTIO_PMEM(dev);
>
> host_memory_backend_set_mapped(pmem->memdev, false);
> + virtio_delete_queue(pmem->rq_vq);
> virtio_cleanup(vdev);
> }
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-02-25 9:22 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-25 7:55 [PATCH 0/4] virtio: fix some virtio-queue leaks Pan Nengyuan
2020-02-25 7:55 ` [PATCH 1/4] vhost-user-fs: do delete virtio_queues in unrealize Pan Nengyuan
2020-02-25 7:55 ` [PATCH 2/4] vhost-user-fs: convert to the new virtio_delete_queue function Pan Nengyuan
2020-02-25 7:55 ` [PATCH 3/4] virtio-pmem: do delete rq_vq in virtio_pmem_unrealize Pan Nengyuan
2020-02-25 9:21 ` Philippe Mathieu-Daudé
2020-02-25 7:55 ` [PATCH 4/4] virtio-crypto: do delete ctrl_vq in virtio_crypto_device_unrealize Pan Nengyuan
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).