Received: from eggs.gnu.org ([2001:4830:134:3::10]:57933) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bwZMU-0005cj-99 for qemu-devel@nongnu.org; Tue, 18 Oct 2016 14:43:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bwZMQ-0003M5-B5 for qemu-devel@nongnu.org; Tue, 18 Oct 2016 14:43:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46410) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1bwZMQ-0003LX-32 for qemu-devel@nongnu.org; Tue, 18 Oct 2016 14:43:38 -0400 References: <20161018145620.20658-1-bobby.prani@gmail.com> <20161018145620.20658-2-bobby.prani@gmail.com> <20161018183441.GB9586@flamenco> From: Eric Blake Message-ID: Date: Tue, 18 Oct 2016 13:43:35 -0500 MIME-Version: 1.0 In-Reply-To: <20161018183441.GB9586@flamenco> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="GrxL5DJeOaXm7wv6HiD9gmWmcI31AmHU6" Subject: Re: [Qemu-devel] [PATCH 2/2] translate-all: Use proper type List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Emilio G. Cota" , Pranith Kumar Cc: Paolo Bonzini , Richard Henderson , "open list:Overall" , Peter Crosthwaite This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --GrxL5DJeOaXm7wv6HiD9gmWmcI31AmHU6 From: Eric Blake To: "Emilio G. Cota" , Pranith Kumar Cc: Paolo Bonzini , Richard Henderson , "open list:Overall" , Peter Crosthwaite Message-ID: Subject: Re: [Qemu-devel] [PATCH 2/2] translate-all: Use proper type References: <20161018145620.20658-1-bobby.prani@gmail.com> <20161018145620.20658-2-bobby.prani@gmail.com> <20161018183441.GB9586@flamenco> In-Reply-To: <20161018183441.GB9586@flamenco> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 10/18/2016 01:34 PM, Emilio G. Cota wrote: > +++ b/translate-all.c > @@ -405,23 +405,23 @@ static void page_init(void) > static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc) > { > PageDesc *pd; > void **lp; > int i; >=20 > /* Level 1. Always allocated. */ > lp =3D l1_map + ((index >> V_L1_SHIFT) & (V_L1_SIZE - 1)); >=20 > /* Level 2..N-1. */ > for (i =3D V_L1_SHIFT / V_L2_BITS - 1; i > 0; i--) { > - void **p =3D atomic_rcu_read(lp); > + void *p =3D atomic_rcu_read(lp); >=20 > if (p =3D=3D NULL) { > if (!alloc) { > return NULL; > } > p =3D g_new0(void *, V_L2_SIZE); > atomic_rcu_set(lp, p); > } >=20 > lp =3D p + ((index >> (i * V_L2_BITS)) & (V_L2_SIZE - 1)); Pointer addition of 'void *' plus an offset is undefined (gcc, and presumably clang, have an extension that treats it the same as computing an offset to a 'char *'; but some compilers choke); this is because sizeof(void) is unknown, so you don't know what stride to make for each offset. Or put another way, 'p + offset' is the same as '&((*p)[offset])', but (*p)[offset] is ill-defined when p is the opaque type void. Pointer addition of 'void **' plus an offset is well-defined, because sizeof(void*) is well-defined and therefore the stride (4 or 8) makes sense. Or in array notation, computing '&((*p)[offset]) means we are skipping to the offset array entry where p is the start of the array of void* pointers. In that regards, changing the type of p from 'void **' (where you stride by the size of a pointer when computing lp) to 'void *' (where you stride by 1 under gcc when computing lp) is WRONG. > I prefer void **p since that matches lp's and l1_map's type. Not just prefer, but require. >=20 > It's true that since we're dealing with void * the compiler won't > complain either way. It's a shame that void* relaxes typing so much, but this is one case where we HAVE to use the right type. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --GrxL5DJeOaXm7wv6HiD9gmWmcI31AmHU6 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJYBm1XAAoJEKeha0olJ0NqexUH/102qnYyJldL50xjRHGZmxsf Weo8u5bS3YHp1uURVQTVB8sBCjtbyHWd8ieKAJtRU67GSwdJR/AcSqc6WiKOL1ze bGNDwFAgqEv5Qer8ISRyIY9x3pigA41s8CCWxukdJ2FeS/QJpTJHBKhYwPSj3a7c 4IdRrCKSeTMohKFwE/TRm5zm5fnGOj9H0Cj567MO6nTc7yMoaPAtscF/vvNz2iZY iGrLEANsFrvk0mtlfXAjTcKNg9GaJqL0qFkTNFZwlGXgHx0X1s2aHUqS/EStEpvZ yd7Wk/vXuWp+6mwTde1BLDaY4vGEavbmH3ht7G7bXXNX5jL1//jnDUvCM3/9UbI= =yxSX -----END PGP SIGNATURE----- --GrxL5DJeOaXm7wv6HiD9gmWmcI31AmHU6--