From: David Hildenbrand Date: Wed, 5 Feb 2020 16:34:00 +0000 (+0100) Subject: virtio-balloon: Fix memory leak when unloading while hinting is in progress X-Git-Tag: v5.6-rc1~37^2~1 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=6c22dc61c76b7e7d355f1697ba0ecf26d1334ba6;p=users%2Fjedix%2Flinux-maple.git virtio-balloon: Fix memory leak when unloading while hinting is in progress When unloading the driver while hinting is in progress, we will not release the free page blocks back to MM, resulting in a memory leak. Fixes: 86a559787e6f ("virtio-balloon: VIRTIO_BALLOON_F_FREE_PAGE_HINT") Cc: "Michael S. Tsirkin" Cc: Jason Wang Cc: Wei Wang Cc: Liang Li Signed-off-by: David Hildenbrand Link: https://lore.kernel.org/r/20200205163402.42627-2-david@redhat.com Signed-off-by: Michael S. Tsirkin --- diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index 2457c54b6185..6d063eeaa08a 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -970,6 +970,10 @@ static void remove_common(struct virtio_balloon *vb) leak_balloon(vb, vb->num_pages); update_balloon_size(vb); + /* There might be free pages that are being reported: release them. */ + if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_FREE_PAGE_HINT)) + return_free_pages_to_mm(vb, ULONG_MAX); + /* Now we reset the device so we can clean up the queues. */ vb->vdev->config->reset(vb->vdev);