From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51294) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZCjCE-0002uJ-TQ for qemu-devel@nongnu.org; Wed, 08 Jul 2015 02:51:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZCjCA-0005Zc-N7 for qemu-devel@nongnu.org; Wed, 08 Jul 2015 02:51:06 -0400 Date: Wed, 8 Jul 2015 16:50:17 +1000 From: David Gibson Message-ID: <20150708065017.GP17857@voom.redhat.com> References: <1436148670-6592-1-git-send-email-aik@ozlabs.ru> <1436148670-6592-14-git-send-email-aik@ozlabs.ru> <20150707092311.728e2cd7@thh440s> <559BA465.50009@ozlabs.ru> <20150707122125.0e58b09e@thh440s> <559BB25E.8000008@ozlabs.ru> <20150708043029.GL17857@voom.redhat.com> <20150708082456.15e927fa@thh440s> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="xXygN3QAmJYWdGtb" Content-Disposition: inline In-Reply-To: <20150708082456.15e927fa@thh440s> Subject: Re: [Qemu-devel] [PATCH qemu v10 13/14] vfio: spapr: Add SPAPR IOMMU v2 support (DMA memory preregistering) List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Thomas Huth Cc: Michael Roth , Alexey Kardashevskiy , qemu-devel@nongnu.org, Gavin Shan , Alex Williamson , qemu-ppc@nongnu.org --xXygN3QAmJYWdGtb Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jul 08, 2015 at 08:24:56AM +0200, Thomas Huth wrote: > On Wed, 8 Jul 2015 14:30:29 +1000 > David Gibson wrote: >=20 > > On Tue, Jul 07, 2015 at 09:05:02PM +1000, Alexey Kardashevskiy wrote: > > > On 07/07/2015 08:21 PM, Thomas Huth wrote: > > > >On Tue, 7 Jul 2015 20:05:25 +1000 > > > >Alexey Kardashevskiy wrote: > > > > > > > >>On 07/07/2015 05:23 PM, Thomas Huth wrote: > > > >>>On Mon, 6 Jul 2015 12:11:09 +1000 > > > >>>Alexey Kardashevskiy wrote: > ... > > > >>>>@@ -698,14 +768,18 @@ static int vfio_connect_container(VFIOGroup= *group, AddressSpace *as) > > > >>>> > > > >>>> container->iommu_data.type1.initialized =3D true; > > > >>>> > > > >>>>- } else if (ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_SPAPR_TCE_IO= MMU)) { > > > >>>>+ } else if (ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_SPAPR_TCE_IO= MMU) || > > > >>>>+ ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_SPAPR_TCE_v2= _IOMMU)) { > > > >>>>+ bool v2 =3D !!ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_SPAPR= _TCE_v2_IOMMU); > > > >>> > > > >>>That "!!" sounds somewhat wrong here. I think you either want to c= heck > > > >>>for "ioctl() =3D=3D 1" (because only in this case you can be sure = that v2 > > > >>>is supported), or you can simply omit the "!!" because you're 100%= sure > > > >>>that the ioctl only returns 0 or 1 (and never a negative error cod= e). > > > >> > > > >> > > > >>The host kernel does not return an error on these ioctls, it return= s 0 or > > > >>1. And "!!" is shorter than "(bool)". VFIO_CHECK_EXTENSION for Type= 1 does > > > >>exactly the same already. > > > > > > > >Simply using nothing instead is even shorter than using "!!". The > > > >compiler is smart enough to convert from 0 and 1 to bool. > > > >"!!" is IMHO quite ugly and should only be used when it is really > > > >necessary. > > >=20 > > >=20 > > > imho it is not but either way I'd rather follow the existing style, > > > especially if I do literally the same thing (checking IOMMU version).= Unless > > > the original author tells me to convert all the existing occurences o= f "!!" > > > to "!=3D0" (or something like this) before I post new ones. > > >=20 > > > Alex, should I get rid of "!!"s in the patch? > >=20 > > I think !! is the lesser evil here. The trouble is that in C "bool" > > is not a first-class datatype, but just a typedef for some integer > > type. Which means that, confusingly, (bool)2 !=3D (bool)1. So using > > the !! trick to force a value to be either 0 or 1 when assigning it to > > a bool variable is probably a good idea. >=20 > That was maybe the case > 15 years ago, but since C99, there is a > proper bool type in C, as far as I know. But I am also not an expert > here... However, I tried the following small test program: >=20 > #include > #include >=20 > int main() > { > bool a =3D 1; > bool b =3D 2; > printf("a=3D%i b=3D%i\n", a, b); > return 0; > } >=20 > ... and indeed, it prints out "a=3D1 b=3D1" here, so the "2" got properly > changed to "true" :-) Huh. I had thought that C99 merely required that there be the stdbool.h header declaring the bool type, rather than defining it as a true first class type. I'm very glad to be wrong. > Anyway, that was already too much bike-shed painting now, if you want to > keep the "!!", then keep it, that's fine for me, too. But bike-shedding is a qemu tradition! ;-/ --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --xXygN3QAmJYWdGtb Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJVnMgpAAoJEGw4ysog2bOSdkMP/3HcCF+Lr3zkwXTo2qzhvOY7 onInGn79poQAXulujbDcqgmK0cgXJXUq7H6DSkR5NLbDY0D2QvVl8eDKFiI1gLcZ sFqZ8agTapArMZ2T+08iFZGIlobVwkrzOPfuyUt2370l+rdBIdsGmRF9G/yGOlXb Dbau4PQyNksc32tgKtoS9hslIcjwwc7OwALq0XOwIPsHawGt8mdnZaTAacgSDSwj Y+y4qzEbsDU7hUg7A2AulZnrNju7wH8q5UdAEML5lFrKyXeL8bDTvRUtxOKqZALu 1JDOGkNR3KkfTW5SFfvxdRP9wAokoj3i07EW5ASEjo6YE1ZzJSbh7md5YCTK0HgP Ha4cVm45n/hsvPIgnzZrf2FD9t2FuG4vZWj24QhI2uHyQWe1K9bn8oQQ64WlxbgZ na9VkSfEggLHwk4J6kPxKaN5SwJ2WFVd7fJgZrAtSx1ciGJqppj7EFokq6fu01c1 QfTUq+1PiTtDQnNVtOMFbMqwXsrixJiDAr3/1HzcpNpHdDU8ApMB/Vm22tXw3pz3 vOE+ADKfYZRdkHLrBBhAgELyz+e2GU+h+2phpQCjSAQMySqluPavQFOvEcaRBYlO fYv06AuhmmkhZOW8+/JladED3M7abbwn6rypqPR4a/aPDL7aGeFAlL8OCGaq1PGk UXjdOXddtjAoTaIKrQYy =ch3i -----END PGP SIGNATURE----- --xXygN3QAmJYWdGtb--