From patchwork Mon Feb 10 12:33:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 231789 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2A06C352A3 for ; Mon, 10 Feb 2020 13:13:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7064B20714 for ; Mon, 10 Feb 2020 13:13:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581340387; bh=woBNc1etvzbOqdR0JwFBLJUqICi0lJEjoZkrPEyPtC8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=XuIdRzKXTaKn1R4V20ti54GIqymtd/A14CgytngGRe3NWC0C+r1f/ewqbOrBjnI+z 9ejrKhWQq50iYjLJ7s9OUC67RBYJkYxbJHsfe+sZOYxL68nW6QbTq5ZLK5vjnTjvGO 2PnPA8Dg79xyokNYcvcy1wnbJvRc3QxgrnbKF8P8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729269AbgBJNNG (ORCPT ); Mon, 10 Feb 2020 08:13:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:34822 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727836AbgBJMin (ORCPT ); Mon, 10 Feb 2020 07:38:43 -0500 Received: from localhost (unknown [209.37.97.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0A27620842; Mon, 10 Feb 2020 12:38:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581338323; bh=woBNc1etvzbOqdR0JwFBLJUqICi0lJEjoZkrPEyPtC8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G3hv8ir6Y1iosLB+s4CYHNcUlxstrxg5r2Dq/bWhCxG+N7qUS6f0G5ZX4fu7uCaCw lIuXh+XOrDQQjLK2tWNdqbB4Cb38Hkti9pLZG9pQbZ9qKOJYoPa+cGAkTf3zBsmnWt uA1qW/yLi+nqzcbcTRpjxXhpCPIbs3KC4SIYc0Cc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Wei Wang , Liang Li , David Hildenbrand Subject: [PATCH 5.4 256/309] virtio-balloon: Fix memory leak when unloading while hinting is in progress Date: Mon, 10 Feb 2020 04:33:32 -0800 Message-Id: <20200210122431.167308054@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200210122406.106356946@linuxfoundation.org> References: <20200210122406.106356946@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: David Hildenbrand commit 6c22dc61c76b7e7d355f1697ba0ecf26d1334ba6 upstream. 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 Signed-off-by: Greg Kroah-Hartman --- drivers/virtio/virtio_balloon.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -967,6 +967,10 @@ static void remove_common(struct virtio_ 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);