From nobody Sun Feb 8 18:49:08 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1570829180; cv=none; d=zoho.com; s=zohoarc; b=jRvrsRaJLG5lZlpSaDqYJ5fQZLNaNMK0b3MLccViUvI/CgsmbXHHrr3X8M3JedC8bdxgNxYh9pwr8d4RkfhGpfX0NsJHtuVHA6hgASgThDQ9+3zMNespWMq8g8SQL2cdn6vQQBNWSNqfCzzOiepAgn5hnY+0M/n/30LSaZbAL0I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570829180; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mmgL7tyrmi1Zg/YFp6DWfNPhcC6AlxcQ9gw9VIiq0eI=; b=W0/KujgvkOQ7nB85N0mazFStX3YJy5MT8byhF+eMFZR79Uaj3rcFDnLqoDxysv50+/3CCpmD7moMlkltXZhY/gbjNNA3WKQKscNcRa6jMar/z5rCM8kivSclq1pmnVWDFxQAIXhV5xJGylMZz0qmjxus08C7Udun240XjrQqR3s= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1570829180516171.56549570869402; Fri, 11 Oct 2019 14:26:20 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 45AE5305FD51; Fri, 11 Oct 2019 21:26:18 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1A5DD60623; Fri, 11 Oct 2019 21:26:18 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id C0DDB4EE6D; Fri, 11 Oct 2019 21:26:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9BLQ14a006446 for ; Fri, 11 Oct 2019 17:26:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id AF09E4536; Fri, 11 Oct 2019 21:26:01 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-173.bos.redhat.com [10.18.17.173]) by smtp.corp.redhat.com (Postfix) with ESMTP id 541561EC; Fri, 11 Oct 2019 21:26:00 +0000 (UTC) From: John Snow To: Peter Maydell , qemu-devel@nongnu.org Date: Fri, 11 Oct 2019 17:25:32 -0400 Message-Id: <20191011212550.27269-2-jsnow@redhat.com> In-Reply-To: <20191011212550.27269-1-jsnow@redhat.com> References: <20191011212550.27269-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Juan Quintela , libvir-list@redhat.com, John Snow , "Dr. David Alan Gilbert" , Max Reitz , Stefan Hajnoczi Subject: [libvirt] [PULL 01/19] util/hbitmap: strict hbitmap_reset X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Fri, 11 Oct 2019 21:26:19 +0000 (UTC) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy hbitmap_reset has an unobvious property: it rounds requested region up. It may provoke bugs, like in recently fixed write-blocking mode of mirror: user calls reset on unaligned region, not keeping in mind that there are possible unrelated dirty bytes, covered by rounded-up region and information of this unrelated "dirtiness" will be lost. Make hbitmap_reset strict: assert that arguments are aligned, allowing only one exception when @start + @count =3D=3D hb->orig_size. It's needed to comfort users of hbitmap_next_dirty_area, which cares about hb->orig_size. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz Message-Id: <20190806152611.280389-1-vsementsov@virtuozzo.com> [Maintainer edit: Max's suggestions from on-list. --js] Signed-off-by: John Snow --- include/qemu/hbitmap.h | 5 +++++ tests/test-hbitmap.c | 2 +- util/hbitmap.c | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h index 4afbe6292e3..1bf944ca3d1 100644 --- a/include/qemu/hbitmap.h +++ b/include/qemu/hbitmap.h @@ -132,6 +132,11 @@ void hbitmap_set(HBitmap *hb, uint64_t start, uint64_t= count); * @count: Number of bits to reset. * * Reset a consecutive range of bits in an HBitmap. + * @start and @count must be aligned to bitmap granularity. The only excep= tion + * is resetting the tail of the bitmap: @count may be equal to hb->orig_si= ze - + * @start, in this case @count may be not aligned. The sum of @start + @co= unt is + * allowed to be greater than hb->orig_size, but only if @start < hb->orig= _size + * and @start + @count =3D ALIGN_UP(hb->orig_size, granularity). */ void hbitmap_reset(HBitmap *hb, uint64_t start, uint64_t count); =20 diff --git a/tests/test-hbitmap.c b/tests/test-hbitmap.c index eed5d288cbc..e1f867085f4 100644 --- a/tests/test-hbitmap.c +++ b/tests/test-hbitmap.c @@ -423,7 +423,7 @@ static void test_hbitmap_granularity(TestHBitmapData *d= ata, hbitmap_test_check(data, 0); hbitmap_test_set(data, 0, 3); g_assert_cmpint(hbitmap_count(data->hb), =3D=3D, 4); - hbitmap_test_reset(data, 0, 1); + hbitmap_test_reset(data, 0, 2); g_assert_cmpint(hbitmap_count(data->hb), =3D=3D, 2); } =20 diff --git a/util/hbitmap.c b/util/hbitmap.c index fd44c897ab0..757d39e360a 100644 --- a/util/hbitmap.c +++ b/util/hbitmap.c @@ -476,6 +476,10 @@ void hbitmap_reset(HBitmap *hb, uint64_t start, uint64= _t count) /* Compute range in the last layer. */ uint64_t first; uint64_t last =3D start + count - 1; + uint64_t gran =3D 1ULL << hb->granularity; + + assert(!(start & (gran - 1))); + assert(!(count & (gran - 1)) || (start + count =3D=3D hb->orig_size)); =20 trace_hbitmap_reset(hb, start, count, start >> hb->granularity, last >> hb->granularity); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list