From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36431) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XNRtf-0007dL-L1 for qemu-devel@nongnu.org; Fri, 29 Aug 2014 15:31:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XNRtW-0001MA-K5 for qemu-devel@nongnu.org; Fri, 29 Aug 2014 15:31:43 -0400 Received: from mail-wg0-x231.google.com ([2a00:1450:400c:c00::231]:61170) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XNRtW-0001M3-DF for qemu-devel@nongnu.org; Fri, 29 Aug 2014 15:31:34 -0400 Received: by mail-wg0-f49.google.com with SMTP id y10so2628913wgg.32 for ; Fri, 29 Aug 2014 12:31:33 -0700 (PDT) Date: Fri, 29 Aug 2014 21:31:28 +0200 From: Marc =?UTF-8?B?TWFyw60=?= Message-ID: <20140829213128.17814c69@crunchbang> In-Reply-To: <20140829154936.GA19824@stefanha-thinkpad.redhat.com> References: <1409308848-5245-1-git-send-email-marc.mari.barcelo@gmail.com> <1409308848-5245-3-git-send-email-marc.mari.barcelo@gmail.com> <20140829154936.GA19824@stefanha-thinkpad.redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v7 2/7] tests: Add virtio device initialization List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: Paolo Bonzini , qemu-devel@nongnu.org, Stefan Hajnoczi El Fri, 29 Aug 2014 16:49:36 +0100 Stefan Hajnoczi escribi=C3=B3: > On Fri, Aug 29, 2014 at 12:40:43PM +0200, Marc Mar=C3=AD wrote: > > +static uint64_t qvirtio_pci_config_readq(QVirtioDevice *d, void > > *addr) +{ > > + QVirtioPCIDevice *dev =3D (QVirtioPCIDevice *)d; > > + int i; > > + union { > > + uint8_t bytes[8]; > > + uint64_t u64; > > + } quad; > > + > > + if (qtest_big_endian()) { > > + for (i =3D 0; i < 8; ++i) { > > + quad.bytes[7-i] =3D qpci_io_readb(dev->pdev, addr + i); > > + } > > + } else { > > + for (i =3D 0; i < 8; ++i) { > > + quad.bytes[i] =3D qpci_io_readb(dev->pdev, addr + i); > > + } > > + } > > + > > + return quad.u64; > > +} >=20 > This assumes that the host is little-endian. The host could be > big-endian! >=20 > qvirtio_pci_config_readq() needs to return a 64-bit value in host CPU > endianness. So the logic should be: >=20 > for (i =3D 0; i < 8; ++i) { > quad.bytes[i] =3D qpci_io_readb(dev->pdev, addr + i); > } > if (qtest_big_endian() !=3D qtest_host_endian()) { > quad.u64 =3D bswap64(quad.u64); > } > return quard.u64; >=20 > Stefan Sorry, I messed up. These are the things that one is not used to think about, as this is usally taken for granted because the OS handles it. Marc