From nobody Sun Feb 8 15:08:35 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1564055986; cv=none; d=zoho.com; s=zohoarc; b=Ek1RkrEqTy4ScSfH/62wwvgPg4u39BJoFik1AIfzf6O+svZoTkVm5wP7paLztg00SFYJSEVlZ4gAPoPle57frjvX8oYkbXimGcdBtdaElMSv99cV2a/pQglXZ8gi6Sqqp9FopEF+E+hJhx36JPR0zAkAu83KEpMU20sWFYavkWI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564055986; h=Content-Type:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=pvjz9rWfCywHeHoWu5I6HCWyzyK20pVQC/bjCbcdA+A=; b=FFraPOL8NA8cSvWkkwCrygRqPxlB74HhWyMjSEp+eLPgZXS7JaBrWDtcF5BOJEPqeG7lx5BGvfBa63CB+lUF8FLXO1m7+F8FW0tgXUK4vPvtmKFPNs0wO2ld+iEn0kiJjzNeQOTYYLgHMlsF/wHQQ2ZKyuafJ+6XoS2MDLH08D4= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1564055986816276.92974790415394; Thu, 25 Jul 2019 04:59:46 -0700 (PDT) Received: from localhost ([::1]:59108 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqcPJ-00079S-DB for importer@patchew.org; Thu, 25 Jul 2019 07:59:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56764) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqcP7-0006du-5U for qemu-devel@nongnu.org; Thu, 25 Jul 2019 07:59:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hqcP6-00078Q-3n for qemu-devel@nongnu.org; Thu, 25 Jul 2019 07:59:25 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:44139) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hqcP5-00077P-Ts for qemu-devel@nongnu.org; Thu, 25 Jul 2019 07:59:23 -0400 Received: by mail-qt1-f195.google.com with SMTP id 44so17722826qtg.11 for ; Thu, 25 Jul 2019 04:59:22 -0700 (PDT) Received: from redhat.com (bzq-79-181-91-42.red.bezeqint.net. [79.181.91.42]) by smtp.gmail.com with ESMTPSA id 42sm26348304qtm.27.2019.07.25.04.59.19 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 25 Jul 2019 04:59:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=pvjz9rWfCywHeHoWu5I6HCWyzyK20pVQC/bjCbcdA+A=; b=HffysR6OT8c2n3b6XCcsRi85J9eNhG7DdNeHRAzpubFlcymQRPobidBD+j5STtex78 eR4/zc5uDyUVBayiyFOvRLCmJh7d558FPovyTsAC3HfnRWqrj1X/tQnVkgDy6M1MSKi5 23ASO/+12hkBZS3bSKKcLU5SvuJxyqNGxeA2k51C+lRN5jk+sozc35rTPUTm6MOXf74+ cwmpt0LKD2RsQCb/jlJISX247xzNWE4DNoPfK1qzzHm9/lqC7pSDMJBTDgOxgvIcdT5R tejNlJQ7PB+gbsT7zcO1ViONgBW7ihmLPJss3JB1v2ZM9prGgCLU6R2Kg59GsHyxnUdZ lYgA== X-Gm-Message-State: APjAAAVpz5TyfG+yW9Apb3Zk3vBUXgY0uaykVqII+lRp5GcfoBOEHM/M 8aMYxFNRRIWiaNB8DFquzmR/q/WUr0M1Yw== X-Google-Smtp-Source: APXvYqzEWSr8P5aX1NMm0J4ywtSNBvHuAQnFMlqGpIG/K0Xymq241HeRGxrbI1BIMH2mg0QHLCc5rw== X-Received: by 2002:ac8:2a88:: with SMTP id b8mr56029536qta.331.1564055961697; Thu, 25 Jul 2019 04:59:21 -0700 (PDT) Date: Thu, 25 Jul 2019 07:59:17 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <20190725115914.26983-1-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email 2.22.0.678.g13338e74b8 X-Mutt-Fcc: =sent X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.160.195 Subject: [Qemu-devel] [PATCH] virtio-balloon: free pbp more aggressively X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-stable@nongnu.org, David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Previous patches switched to a temporary pbp but that does not go far enough: after device uses a buffer, guest is free to reuse it, so tracking the page and freeing it later is wrong. Free and reset the pbp after we push each element. Fixes: ed48c59875b6 ("virtio-balloon: Safely handle BALLOON_PAGE_SIZE < hos= t page size") Cc: qemu-stable@nongnu.org #v4.0.0 Cc: David Hildenbrand Signed-off-by: Michael S. Tsirkin Reviewed-by: David Hildenbrand --- hw/virtio/virtio-balloon.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index fe9664e42c..460a702463 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -39,13 +39,14 @@ typedef struct PartiallyBalloonedPage { unsigned long *bitmap; } PartiallyBalloonedPage; =20 -static void virtio_balloon_pbp_free(PartiallyBalloonedPage *pbp) +static void virtio_balloon_pbp_free(PartiallyBalloonedPage **pbp) { - if (!pbp) { + if (!*pbp) { return; } - g_free(pbp->bitmap); - g_free(pbp); + g_free(*pbp->bitmap); + g_free(*pbp); + *pbp =3D NULL; } =20 static PartiallyBalloonedPage *virtio_balloon_pbp_alloc(ram_addr_t base_gp= a, @@ -108,8 +109,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 */ - virtio_balloon_pbp_free(*pbp); - *pbp =3D NULL; + virtio_balloon_pbp_free(pbp); } =20 if (!*pbp) { @@ -127,8 +127,7 @@ static void balloon_inflate_page(VirtIOBalloon *balloon, /* We ignore errors from ram_block_discard_range(), because it * has already reported them, and failing to discard a balloon * page is not fatal */ - virtio_balloon_pbp_free(*pbp); - *pbp =3D NULL; + virtio_balloon_pbp_free(pbp); } } =20 @@ -379,9 +378,8 @@ static void virtio_balloon_handle_output(VirtIODevice *= vdev, VirtQueue *vq) virtqueue_push(vq, elem, offset); virtio_notify(vdev, vq); g_free(elem); + virtio_balloon_pbp_free(&pbp); } - - virtio_balloon_pbp_free(pbp); } =20 static void virtio_balloon_receive_stats(VirtIODevice *vdev, VirtQueue *vq) --=20 MST