From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37499) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c7K2l-0005sn-N4 for qemu-devel@nongnu.org; Thu, 17 Nov 2016 05:35:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c7K2k-0004vu-TV for qemu-devel@nongnu.org; Thu, 17 Nov 2016 05:35:47 -0500 Date: Thu, 17 Nov 2016 10:35:37 +0000 From: Stefan Hajnoczi Message-ID: <20161117103537.GD24138@stefanha-x1.localdomain> References: <20161115224732.1334-1-mreitz@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="8nsIa27JVQLqB7/C" Content-Disposition: inline In-Reply-To: <20161115224732.1334-1-mreitz@redhat.com> Subject: Re: [Qemu-devel] [Qemu-block] [PATCH for-2.8 v2] hbitmap: Fix shifts of constants by granularity List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Max Reitz Cc: qemu-block@nongnu.org, Fam Zheng , qemu-devel@nongnu.org, Stefan Hajnoczi --8nsIa27JVQLqB7/C Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Nov 15, 2016 at 11:47:32PM +0100, Max Reitz wrote: > An hbitmap's granularity may be anything from 0 to 63, so when shifting > constants by its value, they should not be plain ints. >=20 > Even having changed the types, hbitmap_serialization_granularity() still > tries to shift 64 to the right by the granularity. This operation is > undefined if the granularity is greater than 57. Adding an assertion is > fine for now, because serializing is done only in tests so far, but this > means that only bitmaps with a granularity below 58 can be serialized > and we should thus add a hbitmap_is_serializable() function later. >=20 > One of the two places touched in this patch uses > QEMU_ALIGN_UP(x, 1 << y). We can use ROUND_UP() there, since the second > parameter is obviously a power of two. >=20 > Signed-off-by: Max Reitz > --- > v2: > - Fix the same issue in hbitmap_truncate() [Stefan] > - Use ROUND_UP() instead of QEMU_ALIGN_UP() there (because we can) > - Add an assertion to hbitmap_serialization_granularity() guaranteeing > that the shift doesn't overflow; we can guarantee this so far because > the only place where serialization functions are used in is the > hbitmap test > (I'll send a follow-up patch to allow users to check whether a certain > bitmap can be (de-)serialized) > --- > util/hbitmap.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) Reviewed-by: Stefan Hajnoczi --8nsIa27JVQLqB7/C Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEcBAEBAgAGBQJYLYf5AAoJEJykq7OBq3PIT1wH/3YFxhULTiH+dVm79ny++RM/ QI3E6jdh7RQwaow9WkaP+MxBGPQxRoG2BPS6G4xW7ENcWNZ4cp61SSyKuuEw1hFG QjrD5na5waxyIQw74M/7aQW3JCKAc06Wi9n8MZhAVBUtPNqinRo1bgbQyY+6PyWi fLe8K53io09MPPgtg/UzjfDWEkmANDsFEwPQlFkqM1tgVPQH+4RBFeugTJHyqg9T DVvToB9mrEOSaHN8eskKT7iwu1lVGW3jcsDGC0f6KohohD1w1xDpjA6qh+QCtns0 zmany5pSDr90sbFZVGl1qDdLm8VP3r94mK2RpnHQup2x2Th+hKt+oAOyasUguIo= =lXh7 -----END PGP SIGNATURE----- --8nsIa27JVQLqB7/C--