From: David Gibson <david@gibson.dropbear.id.au>
To: David Hildenbrand <david@redhat.com>
Cc: Igor Mammedov <imammedo@redhat.com>,
qemu-stable@nongnu.org, qemu-devel@nongnu.org,
Stefan Hajnoczi <stefanha@redhat.com>,
"Michael S . Tsirkin" <mst@redhat.com>
Subject: Re: [Qemu-devel] [PATCH-for-4.1 v2 2/3] virtio-balloon: fix memory leak on unrealize()
Date: Thu, 18 Jul 2019 13:51:32 +1000 [thread overview]
Message-ID: <20190718035132.GD8468@umbus.fritz.box> (raw)
In-Reply-To: <20190717103550.24657-3-david@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 2966 bytes --]
On Wed, Jul 17, 2019 at 12:35:49PM +0200, David Hildenbrand wrote:
> 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>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
> ---
> 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);
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2019-07-18 6:01 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 ` [Qemu-devel] [PATCH-for-4.1 v2 2/3] virtio-balloon: fix memory leak on unrealize() David Hildenbrand
2019-07-18 3:51 ` David Gibson [this message]
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=20190718035132.GD8468@umbus.fritz.box \
--to=david@gibson.dropbear.id.au \
--cc=david@redhat.com \
--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).