Received: from eggs.gnu.org ([2001:4830:134:3::10]:50895) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cBOVi-0004Vn-8c for qemu-devel@nongnu.org; Mon, 28 Nov 2016 11:10:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cBOVc-0006MI-Fm for qemu-devel@nongnu.org; Mon, 28 Nov 2016 11:10:30 -0500 References: <1476395910-8697-1-git-send-email-jsnow@redhat.com> <1476395910-8697-8-git-send-email-jsnow@redhat.com> <87vavba9mi.fsf@dusky.pond.sub.org> From: John Snow Message-ID: <7054940b-beee-d92d-3245-b5037ba8d42f@redhat.com> Date: Mon, 28 Nov 2016 11:10:12 -0500 MIME-Version: 1.0 In-Reply-To: <87vavba9mi.fsf@dusky.pond.sub.org> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v10 07/10] hbitmap: serialization List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: qemu-block@nongnu.org, vsementsov@virtuozzo.com, famz@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com On 11/25/2016 09:59 AM, Markus Armbruster wrote: > John Snow writes: > >> From: Vladimir Sementsov-Ogievskiy >> >> Functions to serialize / deserialize(restore) HBitmap. HBitmap should be >> saved to linear sequence of bits independently of endianness and bitmap >> array element (unsigned long) size. Therefore Little Endian is chosen. >> >> These functions are appropriate for dirty bitmap migration, restoring >> the bitmap in several steps is available. To save performance, every >> step writes only the last level of the bitmap. All other levels are >> restored by hbitmap_deserialize_finish() as a last step of restoring. >> So, HBitmap is inconsistent while restoring. >> >> Signed-off-by: Vladimir Sementsov-Ogievskiy >> [Fix left shift operand to 1UL; add "finish" parameter. - Fam] >> Signed-off-by: Fam Zheng >> >> Signed-off-by: John Snow > [...] >> diff --git a/util/hbitmap.c b/util/hbitmap.c >> index f303975..5d1a21c 100644 >> --- a/util/hbitmap.c >> +++ b/util/hbitmap.c >> @@ -397,6 +397,143 @@ bool hbitmap_get(const HBitmap *hb, uint64_t item) >> return (hb->levels[HBITMAP_LEVELS - 1][pos >> BITS_PER_LEVEL] & bit) != 0; >> } >> >> +uint64_t hbitmap_serialization_granularity(const HBitmap *hb) >> +{ >> + /* Require at least 64 bit granularity to be safe on both 64 bit and 32 bit >> + * hosts. */ >> + return 64 << hb->granularity; >> +} > > Coverity reports: > > *** CID 1365378: Integer handling issues (OVERFLOW_BEFORE_WIDEN) > /util/hbitmap.c: 404 in hbitmap_serialization_granularity() > 398 } > 399 > 400 uint64_t hbitmap_serialization_granularity(const HBitmap *hb) > 401 { > 402 /* Require at least 64 bit granularity to be safe on both 64 bit and 32 bit > 403 * hosts. */ > >>> CID 1365378: Integer handling issues (OVERFLOW_BEFORE_WIDEN) > >>> Potentially overflowing expression "0x40 << hb->granularity" with type "int" (32 bits, signed) is evaluated using 32-bit arithmetic, and then used in a context that expects an expression of type "uint64_t" (64 bits, unsigned). > 404 return 64 << hb->granularity; > 405 } > 406 > 407 /* Start should be aligned to serialization granularity, chunk size should be > 408 * aligned to serialization granularity too, except for last chunk. > 409 */ > > Use (uint64_t)64 << hb->granularity for an unsigned 64 bit shift. > > [...] > If I am not mistaken, Max already sent a patch for this. I might need to send a PR for that one for 2.8. Let me work off the tryptophan haze. --js