From: David Hildenbrand <david@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Michael S . Tsirkin" <mst@redhat.com>,
David Hildenbrand <david@redhat.com>,
qemu-stable@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>,
Igor Mammedov <imammedo@redhat.com>,
David Gibson <david@gibson.dropbear.id.au>
Subject: [Qemu-devel] [PATCH-for-4.1 v2 2/3] virtio-balloon: fix memory leak on unrealize()
Date: Wed, 17 Jul 2019 12:35:49 +0200 [thread overview]
Message-ID: <20190717103550.24657-3-david@redhat.com> (raw)
In-Reply-To: <20190717103550.24657-1-david@redhat.com>
We could have tracking data for a pbp (PartiallyBalloonedPage)
allocated. Let's free it.
Fixes: ed48c59875b6 ("virtio-balloon: Safely handle BALLOON_PAGE_SIZE <
host page size")
Cc: qemu-stable@nongnu.org #v4.0.0
Cc: Stefan Hajnoczi <stefanha@redhat.com>
Cc: David Gibson <david@gibson.dropbear.id.au>
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
hw/virtio/virtio-balloon.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
index 669067d661..84d01bceb3 100644
--- a/hw/virtio/virtio-balloon.c
+++ b/hw/virtio/virtio-balloon.c
@@ -40,6 +40,12 @@ struct PartiallyBalloonedPage {
unsigned long bitmap[];
};
+static void virtio_balloon_reset_pbp(VirtIOBalloon *balloon)
+{
+ g_free(balloon->pbp);
+ balloon->pbp = NULL;
+}
+
static void balloon_inflate_page(VirtIOBalloon *balloon,
MemoryRegion *mr, hwaddr offset)
{
@@ -82,8 +88,7 @@ static void balloon_inflate_page(VirtIOBalloon *balloon,
/* We've partially ballooned part of a host page, but now
* we're trying to balloon part of a different one. Too hard,
* give up on the old partial page */
- g_free(balloon->pbp);
- balloon->pbp = NULL;
+ virtio_balloon_reset_pbp(balloon);
}
if (!balloon->pbp) {
@@ -106,8 +111,7 @@ static void balloon_inflate_page(VirtIOBalloon *balloon,
* has already reported them, and failing to discard a balloon
* page is not fatal */
- g_free(balloon->pbp);
- balloon->pbp = NULL;
+ virtio_balloon_reset_pbp(balloon);
}
}
@@ -143,8 +147,7 @@ static void balloon_deflate_page(VirtIOBalloon *balloon,
balloon->pbp->bitmap);
if (bitmap_empty(balloon->pbp->bitmap, subpages)) {
- g_free(balloon->pbp);
- balloon->pbp = NULL;
+ virtio_balloon_reset_pbp(balloon);
}
}
@@ -831,6 +834,7 @@ static void virtio_balloon_device_unrealize(DeviceState *dev, Error **errp)
virtio_balloon_free_page_stop(s);
precopy_remove_notifier(&s->free_page_report_notify);
}
+ virtio_balloon_reset_pbp(s);
balloon_stats_destroy_timer(s);
qemu_remove_balloon_handler(s);
virtio_cleanup(vdev);
--
2.21.0
next prev parent reply other threads:[~2019-07-17 10:36 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-17 10:35 [Qemu-devel] [PATCH-for-4.1 v2 0/3] virtio-balloon: fixes for PartialBalloonedPage David Hildenbrand
2019-07-17 10:35 ` [Qemu-devel] [PATCH-for-4.1 v2 1/3] virtio-balloon: fix QEMU crashes on pagesize > BALLOON_PAGE_SIZE David Hildenbrand
2019-07-18 3:50 ` David Gibson
2019-07-18 11:50 ` David Hildenbrand
2019-07-17 10:35 ` David Hildenbrand [this message]
2019-07-18 3:51 ` [Qemu-devel] [PATCH-for-4.1 v2 2/3] virtio-balloon: fix memory leak on unrealize() David Gibson
2019-07-17 10:35 ` [Qemu-devel] [PATCH-for-4.1 v2 3/3] virtio-balloon: reset pbp on device resets David Hildenbrand
2019-07-17 10:48 ` Michael S. Tsirkin
2019-07-17 11:06 ` David Hildenbrand
2019-07-17 11:29 ` Michael S. Tsirkin
2019-07-17 11:32 ` David Hildenbrand
2019-07-18 3:52 ` David Gibson
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=20190717103550.24657-3-david@redhat.com \
--to=david@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=imammedo@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@nongnu.org \
--cc=stefanha@redhat.com \
/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).