From nobody Sun May 5 18:26:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538017989333577.9166199654115; Wed, 26 Sep 2018 20:13:09 -0700 (PDT) Received: from localhost ([::1]:33550 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5Mjb-0006us-8e for importer@patchew.org; Wed, 26 Sep 2018 23:12:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34745) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5MiX-0005QM-D6 for qemu-devel@nongnu.org; Wed, 26 Sep 2018 23:11:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g5MiW-0001QV-GH for qemu-devel@nongnu.org; Wed, 26 Sep 2018 23:11:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50672) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g5MiS-0001Og-DW; Wed, 26 Sep 2018 23:11:48 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 81A871E308; Thu, 27 Sep 2018 03:11:47 +0000 (UTC) Received: from red.redhat.com (ovpn-126-36.rdu2.redhat.com [10.10.126.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id A2B065D76E; Thu, 27 Sep 2018 03:11:39 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 26 Sep 2018 22:11:31 -0500 Message-Id: <20180927031131.102494-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 27 Sep 2018 03:11:47 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] bitmap: Update count after a merge X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , vsementsov@virtuozzo.com, jsnow@redhat.com, qemu-stable@nongnu.org, "open list:Dirty Bitmaps" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We need an accurate count of the number of bits set in a bitmap after a merge. In particular, since the merge operation short-circuits a merge from an empty source, if you have bitmaps A, B, and C where B started empty, then merge C into B, and B into A, an inaccurate count meant that A did not get the contents of C. Fixes: be58721db CC: qemu-stable@nongnu.org Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- Probably worth some testsuite coverage, but for a late-night one-liner, this is as much as I can do today. util/hbitmap.c | 1 + 1 file changed, 1 insertion(+) diff --git a/util/hbitmap.c b/util/hbitmap.c index bcd304041aa..52e12da4b48 100644 --- a/util/hbitmap.c +++ b/util/hbitmap.c @@ -753,3 +753,4 @@ bool hbitmap_merge(HBitmap *a, const HBitmap *b) a->levels[i][j] |=3D b->levels[i][j]; } } + a->count =3D hb_count_between(a, 0, a->size - 1); return true; } --=20 2.17.1