From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PULL 09/20] libqos: add qvirtqueue_cleanup()
Date: Mon, 20 Jun 2016 15:05:20 +0100 [thread overview]
Message-ID: <1466431531-17806-10-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1466431531-17806-1-git-send-email-stefanha@redhat.com>
qvirtqueue_setup() allocates the vring and virtqueue state. So far
there has been no function to free it. Callers have been using
guest_free() for the vring but forgot to free the QVirtQueue state.
This patch solves the memory leak by introducing qvirtqueue_cleanup().
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
tests/libqos/virtio-mmio.c | 8 ++++++++
tests/libqos/virtio-pci.c | 10 ++++++++++
tests/libqos/virtio.c | 6 ++++++
tests/libqos/virtio.h | 5 +++++
tests/virtio-blk-test.c | 10 +++++-----
tests/virtio-net-test.c | 2 +-
tests/virtio-scsi-test.c | 2 +-
7 files changed, 36 insertions(+), 7 deletions(-)
diff --git a/tests/libqos/virtio-mmio.c b/tests/libqos/virtio-mmio.c
index ccb92d9..0cab38f 100644
--- a/tests/libqos/virtio-mmio.c
+++ b/tests/libqos/virtio-mmio.c
@@ -154,6 +154,13 @@ static QVirtQueue *qvirtio_mmio_virtqueue_setup(QVirtioDevice *d,
return vq;
}
+static void qvirtio_mmio_virtqueue_cleanup(QVirtQueue *vq,
+ QGuestAllocator *alloc)
+{
+ guest_free(alloc, vq->desc);
+ g_free(vq);
+}
+
static void qvirtio_mmio_virtqueue_kick(QVirtioDevice *d, QVirtQueue *vq)
{
QVirtioMMIODevice *dev = (QVirtioMMIODevice *)d;
@@ -176,6 +183,7 @@ const QVirtioBus qvirtio_mmio = {
.get_queue_size = qvirtio_mmio_get_queue_size,
.set_queue_address = qvirtio_mmio_set_queue_address,
.virtqueue_setup = qvirtio_mmio_virtqueue_setup,
+ .virtqueue_cleanup = qvirtio_mmio_virtqueue_cleanup,
.virtqueue_kick = qvirtio_mmio_virtqueue_kick,
};
diff --git a/tests/libqos/virtio-pci.c b/tests/libqos/virtio-pci.c
index 3b2b59b..18b92b9 100644
--- a/tests/libqos/virtio-pci.c
+++ b/tests/libqos/virtio-pci.c
@@ -235,6 +235,15 @@ static QVirtQueue *qvirtio_pci_virtqueue_setup(QVirtioDevice *d,
return &vqpci->vq;
}
+static void qvirtio_pci_virtqueue_cleanup(QVirtQueue *vq,
+ QGuestAllocator *alloc)
+{
+ QVirtQueuePCI *vqpci = container_of(vq, QVirtQueuePCI, vq);
+
+ guest_free(alloc, vq->desc);
+ g_free(vqpci);
+}
+
static void qvirtio_pci_virtqueue_kick(QVirtioDevice *d, QVirtQueue *vq)
{
QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
@@ -257,6 +266,7 @@ const QVirtioBus qvirtio_pci = {
.get_queue_size = qvirtio_pci_get_queue_size,
.set_queue_address = qvirtio_pci_set_queue_address,
.virtqueue_setup = qvirtio_pci_virtqueue_setup,
+ .virtqueue_cleanup = qvirtio_pci_virtqueue_cleanup,
.virtqueue_kick = qvirtio_pci_virtqueue_kick,
};
diff --git a/tests/libqos/virtio.c b/tests/libqos/virtio.c
index f79d2d1..d8c2970 100644
--- a/tests/libqos/virtio.c
+++ b/tests/libqos/virtio.c
@@ -54,6 +54,12 @@ QVirtQueue *qvirtqueue_setup(const QVirtioBus *bus, QVirtioDevice *d,
return bus->virtqueue_setup(d, alloc, index);
}
+void qvirtqueue_cleanup(const QVirtioBus *bus, QVirtQueue *vq,
+ QGuestAllocator *alloc)
+{
+ return bus->virtqueue_cleanup(vq, alloc);
+}
+
void qvirtio_reset(const QVirtioBus *bus, QVirtioDevice *d)
{
bus->set_status(d, 0);
diff --git a/tests/libqos/virtio.h b/tests/libqos/virtio.h
index c73fd8c..0250842 100644
--- a/tests/libqos/virtio.h
+++ b/tests/libqos/virtio.h
@@ -79,6 +79,9 @@ typedef struct QVirtioBus {
QVirtQueue *(*virtqueue_setup)(QVirtioDevice *d, QGuestAllocator *alloc,
uint16_t index);
+ /* Free virtqueue resources */
+ void (*virtqueue_cleanup)(QVirtQueue *vq, QGuestAllocator *alloc);
+
/* Notify changes in virtqueue */
void (*virtqueue_kick)(QVirtioDevice *d, QVirtQueue *vq);
} QVirtioBus;
@@ -118,6 +121,8 @@ void qvirtio_wait_config_isr(const QVirtioBus *bus, QVirtioDevice *d,
gint64 timeout_us);
QVirtQueue *qvirtqueue_setup(const QVirtioBus *bus, QVirtioDevice *d,
QGuestAllocator *alloc, uint16_t index);
+void qvirtqueue_cleanup(const QVirtioBus *bus, QVirtQueue *vq,
+ QGuestAllocator *alloc);
void qvring_init(const QGuestAllocator *alloc, QVirtQueue *vq, uint64_t addr);
QVRingIndirectDesc *qvring_indirect_desc_setup(QVirtioDevice *d,
diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c
index 9d27be5..4ab14d5 100644
--- a/tests/virtio-blk-test.c
+++ b/tests/virtio-blk-test.c
@@ -298,7 +298,7 @@ static void pci_basic(void)
(uint64_t)(uintptr_t)addr);
/* End test */
- guest_free(alloc, vqpci->vq.desc);
+ qvirtqueue_cleanup(&qvirtio_pci, &vqpci->vq, alloc);
pc_alloc_uninit(alloc);
qvirtio_pci_device_disable(dev);
g_free(dev);
@@ -401,7 +401,7 @@ static void pci_indirect(void)
guest_free(alloc, req_addr);
/* End test */
- guest_free(alloc, vqpci->vq.desc);
+ qvirtqueue_cleanup(&qvirtio_pci, &vqpci->vq, alloc);
pc_alloc_uninit(alloc);
qvirtio_pci_device_disable(dev);
g_free(dev);
@@ -552,7 +552,7 @@ static void pci_msix(void)
guest_free(alloc, req_addr);
/* End test */
- guest_free(alloc, vqpci->vq.desc);
+ qvirtqueue_cleanup(&qvirtio_pci, &vqpci->vq, alloc);
pc_alloc_uninit(alloc);
qpci_msix_disable(dev->pdev);
qvirtio_pci_device_disable(dev);
@@ -679,7 +679,7 @@ static void pci_idx(void)
guest_free(alloc, req_addr);
/* End test */
- guest_free(alloc, vqpci->vq.desc);
+ qvirtqueue_cleanup(&qvirtio_pci, &vqpci->vq, alloc);
pc_alloc_uninit(alloc);
qpci_msix_disable(dev->pdev);
qvirtio_pci_device_disable(dev);
@@ -745,7 +745,7 @@ static void mmio_basic(void)
g_assert_cmpint(capacity, ==, n_size / 512);
/* End test */
- guest_free(alloc, vq->desc);
+ qvirtqueue_cleanup(&qvirtio_mmio, vq, alloc);
generic_alloc_uninit(alloc);
g_free(dev);
test_end();
diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c
index 1712450..0d2c63f 100644
--- a/tests/virtio-net-test.c
+++ b/tests/virtio-net-test.c
@@ -229,7 +229,7 @@ static void pci_basic(gconstpointer data)
/* End test */
close(sv[0]);
- guest_free(alloc, tx->vq.desc);
+ qvirtqueue_cleanup(&qvirtio_pci, &tx->vq, alloc);
pc_alloc_uninit(alloc);
qvirtio_pci_device_disable(dev);
g_free(dev);
diff --git a/tests/virtio-scsi-test.c b/tests/virtio-scsi-test.c
index 3938163..cbe5dcc 100644
--- a/tests/virtio-scsi-test.c
+++ b/tests/virtio-scsi-test.c
@@ -58,7 +58,7 @@ static void qvirtio_scsi_pci_free(QVirtIOSCSI *vs)
int i;
for (i = 0; i < vs->num_queues + 2; i++) {
- guest_free(vs->alloc, vs->vq[i]->desc);
+ qvirtqueue_cleanup(&qvirtio_pci, vs->vq[i], vs->alloc);
}
pc_alloc_uninit(vs->alloc);
qvirtio_pci_device_disable(container_of(vs->dev, QVirtioPCIDevice, vdev));
--
2.5.5
next prev parent reply other threads:[~2016-06-20 14:06 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-20 14:05 [Qemu-devel] [PULL 00/20] Block patches Stefan Hajnoczi
2016-06-20 14:05 ` [Qemu-devel] [PULL 01/20] libqos: use virtio_ids.h for device ID definitions Stefan Hajnoczi
2016-06-20 14:05 ` [Qemu-devel] [PULL 02/20] libqos: drop duplicated PCI vendor ID definition Stefan Hajnoczi
2016-06-20 14:05 ` [Qemu-devel] [PULL 03/20] libqos: drop duplicated virtio_config.h definitions Stefan Hajnoczi
2016-06-20 14:05 ` [Qemu-devel] [PULL 04/20] libqos: drop duplicated virtio_ring.h bit definitions Stefan Hajnoczi
2016-06-20 14:05 ` [Qemu-devel] [PULL 05/20] libqos: drop duplicated virtio_vring.h structs Stefan Hajnoczi
2016-06-20 14:05 ` [Qemu-devel] [PULL 06/20] libqos: drop duplicated virtio_blk.h definitions Stefan Hajnoczi
2016-06-20 14:05 ` [Qemu-devel] [PULL 07/20] libqos: drop duplicated virtio_scsi.h definitions Stefan Hajnoczi
2016-06-20 14:05 ` [Qemu-devel] [PULL 08/20] libqos: drop duplicated virtio_pci.h definitions Stefan Hajnoczi
2016-06-20 14:05 ` Stefan Hajnoczi [this message]
2016-06-20 14:05 ` [Qemu-devel] [PULL 10/20] block: fixed BdrvTrackedRequest filling in bdrv_co_discard Stefan Hajnoczi
2016-06-20 14:05 ` [Qemu-devel] [PULL 11/20] block: fix race in bdrv_co_discard with drive-mirror Stefan Hajnoczi
2016-06-20 14:05 ` [Qemu-devel] [PULL 12/20] block: process before_write_notifiers in bdrv_co_discard Stefan Hajnoczi
2016-06-20 14:05 ` [Qemu-devel] [PULL 13/20] blockjob: move iostatus reset out of block_job_enter() Stefan Hajnoczi
2016-06-20 14:05 ` [Qemu-devel] [PULL 14/20] blockjob: rename block_job_is_paused() Stefan Hajnoczi
2016-06-20 14:05 ` [Qemu-devel] [PULL 15/20] blockjob: add pause points Stefan Hajnoczi
2016-06-20 14:05 ` [Qemu-devel] [PULL 16/20] blockjob: add block_job_get_aio_context() Stefan Hajnoczi
2016-06-20 14:05 ` [Qemu-devel] [PULL 17/20] block: use safe iteration over AioContext notifiers Stefan Hajnoczi
2016-06-20 14:05 ` [Qemu-devel] [PULL 18/20] blockjob: add AioContext attached callback Stefan Hajnoczi
2016-06-20 14:05 ` [Qemu-devel] [PULL 19/20] mirror: follow AioContext change gracefully Stefan Hajnoczi
2016-06-20 14:05 ` [Qemu-devel] [PULL 20/20] backup: " Stefan Hajnoczi
2016-06-20 17:08 ` [Qemu-devel] [PULL 00/20] Block patches Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1466431531-17806-10-git-send-email-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).