From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51862) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpmfK-0000Vo-4D for qemu-devel@nongnu.org; Thu, 29 Sep 2016 21:31:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bpmfF-0002Qo-W2 for qemu-devel@nongnu.org; Thu, 29 Sep 2016 21:31:06 -0400 Date: Fri, 30 Sep 2016 11:29:46 +1000 From: David Gibson Message-ID: <20160930012946.GR30519@umbus.fritz.box> References: <1475169307-1510-1-git-send-email-lvivier@redhat.com> <1475169307-1510-3-git-send-email-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="zj18g9eElA7rRQh+" Content-Disposition: inline In-Reply-To: <1475169307-1510-3-git-send-email-lvivier@redhat.com> Subject: Re: [Qemu-devel] [Qemu-ppc] [PATCH 2/3] qtest: evaluate endianness of the target in qtest_init() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Laurent Vivier Cc: qemu-devel@nongnu.org, dgibson@redhat.com, thuth@redhat.com, qemu-ppc@nongnu.org, Greg Kurz --zj18g9eElA7rRQh+ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Sep 29, 2016 at 07:15:06PM +0200, Laurent Vivier wrote: > This allows to store it and not have to rescan the list > each time we need it. >=20 > Signed-off-by: Laurent Vivier > Reviewed-by: Greg Kurz Reviewed-by: David Gibson In that it looks technically correct. The whole notion of guest endianness is kind of bogus, doubly so when we're essentially replacing the cpu with the qtest proxy. It'd be better to make all the io operations have explicit endianness. Still, it looks reasonable in the short term. > --- > tests/libqos/virtio-pci.c | 2 +- > tests/libqtest.c | 96 +++++++++++++++++++++++++----------------= ------ > tests/libqtest.h | 16 ++++++-- > tests/virtio-blk-test.c | 2 +- > 4 files changed, 66 insertions(+), 50 deletions(-) >=20 > diff --git a/tests/libqos/virtio-pci.c b/tests/libqos/virtio-pci.c > index 18b92b9..6e005c1 100644 > --- a/tests/libqos/virtio-pci.c > +++ b/tests/libqos/virtio-pci.c > @@ -86,7 +86,7 @@ static uint64_t qvirtio_pci_config_readq(QVirtioDevice = *d, uint64_t addr) > int i; > uint64_t u64 =3D 0; > =20 > - if (qtest_big_endian()) { > + if (target_big_endian()) { > for (i =3D 0; i < 8; ++i) { > u64 |=3D (uint64_t)qpci_io_readb(dev->pdev, > (void *)(uintptr_t)addr + i) << (7 - i) = * 8; > diff --git a/tests/libqtest.c b/tests/libqtest.c > index 6f6bdf1..aa4bc9e 100644 > --- a/tests/libqtest.c > +++ b/tests/libqtest.c > @@ -37,6 +37,7 @@ struct QTestState > bool irq_level[MAX_IRQ]; > GString *rx; > pid_t qemu_pid; /* our child QEMU process */ > + bool big_endian; > }; > =20 > static GHookList abrt_hooks; > @@ -146,6 +147,52 @@ void qtest_add_abrt_handler(GHookFunc fn, const void= *data) > g_hook_prepend(&abrt_hooks, hook); > } > =20 > +static bool arch_is_big_endian(const char *arch) > +{ > + int i; > + static const struct { > + const char *arch; > + bool big_endian; > + } endianness[] =3D { > + { "aarch64", false }, > + { "alpha", false }, > + { "arm", false }, > + { "cris", false }, > + { "i386", false }, > + { "lm32", true }, > + { "m68k", true }, > + { "microblaze", true }, > + { "microblazeel", false }, > + { "mips", true }, > + { "mips64", true }, > + { "mips64el", false }, > + { "mipsel", false }, > + { "moxie", true }, > + { "or32", true }, > + { "ppc", true }, > + { "ppc64", true }, > + { "ppcemb", true }, > + { "s390x", true }, > + { "sh4", false }, > + { "sh4eb", true }, > + { "sparc", true }, > + { "sparc64", true }, > + { "unicore32", false }, > + { "x86_64", false }, > + { "xtensa", false }, > + { "xtensaeb", true }, > + { "tricore", false }, > + {}, > + }; > + > + for (i =3D 0; endianness[i].arch; i++) { > + if (strcmp(endianness[i].arch, arch) =3D=3D 0) { > + return endianness[i].big_endian; > + } > + } > + g_assert_not_reached(); > +} > + > QTestState *qtest_init(const char *extra_args) > { > QTestState *s; > @@ -209,6 +256,8 @@ QTestState *qtest_init(const char *extra_args) > kill(s->qemu_pid, SIGSTOP); > } > =20 > + s->big_endian =3D arch_is_big_endian(qtest_get_arch()); > + > return s; > } > =20 > @@ -886,50 +935,7 @@ char *hmp(const char *fmt, ...) > return ret; > } > =20 > -bool qtest_big_endian(void) > +bool qtest_big_endian(QTestState *s) > { > - const char *arch =3D qtest_get_arch(); > - int i; > - > - static const struct { > - const char *arch; > - bool big_endian; > - } endianness[] =3D { > - { "aarch64", false }, > - { "alpha", false }, > - { "arm", false }, > - { "cris", false }, > - { "i386", false }, > - { "lm32", true }, > - { "m68k", true }, > - { "microblaze", true }, > - { "microblazeel", false }, > - { "mips", true }, > - { "mips64", true }, > - { "mips64el", false }, > - { "mipsel", false }, > - { "moxie", true }, > - { "or32", true }, > - { "ppc", true }, > - { "ppc64", true }, > - { "ppcemb", true }, > - { "s390x", true }, > - { "sh4", false }, > - { "sh4eb", true }, > - { "sparc", true }, > - { "sparc64", true }, > - { "unicore32", false }, > - { "x86_64", false }, > - { "xtensa", false }, > - { "xtensaeb", true }, > - {}, > - }; > - > - for (i =3D 0; endianness[i].arch; i++) { > - if (strcmp(endianness[i].arch, arch) =3D=3D 0) { > - return endianness[i].big_endian; > - } > - } > - > - return false; > + return s->big_endian; > } > diff --git a/tests/libqtest.h b/tests/libqtest.h > index f7402e0..4be1f77 100644 > --- a/tests/libqtest.h > +++ b/tests/libqtest.h > @@ -410,6 +410,14 @@ int64_t qtest_clock_step(QTestState *s, int64_t step= ); > int64_t qtest_clock_set(QTestState *s, int64_t val); > =20 > /** > + * qtest_big_endian: > + * @s: QTestState instance to operate on. > + * > + * Returns: True if the architecture under test has a big endian configu= ration. > + */ > +bool qtest_big_endian(QTestState *s); > + > +/** > * qtest_get_arch: > * > * Returns: The architecture for the QEMU executable under test. > @@ -874,12 +882,14 @@ static inline int64_t clock_set(int64_t val) > } > =20 > /** > - * qtest_big_endian: > + * target_big_endian: > * > * Returns: True if the architecture under test has a big endian configu= ration. > */ > -bool qtest_big_endian(void); > - > +static inline bool target_big_endian(void) > +{ > + return qtest_big_endian(global_qtest); > +} > =20 > QDict *qmp_fd_receive(int fd); > void qmp_fd_sendv(int fd, const char *fmt, va_list ap); > diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c > index 8cf62f6..a4de3e4 100644 > --- a/tests/virtio-blk-test.c > +++ b/tests/virtio-blk-test.c > @@ -120,7 +120,7 @@ static inline void virtio_blk_fix_request(QVirtioBlkR= eq *req) > bool host_endian =3D false; > #endif > =20 > - if (qtest_big_endian() !=3D host_endian) { > + if (target_big_endian() !=3D host_endian) { > req->type =3D bswap32(req->type); > req->ioprio =3D bswap32(req->ioprio); > req->sector =3D bswap64(req->sector); --=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 --zj18g9eElA7rRQh+ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJX7cAKAAoJEGw4ysog2bOSv80QAJQW9EZXot4G9CttFvpYPctv xeMQusYSHpP0GzAt0dxxTxXhtpB0azDsqCkAzRC9raYx0lJnzUPLbaUR3XX6vBjY r73xVmqtRp/q5F3YYRyqsV+Iretapf57vsKbCEieq1i1IeiYaHd9XiPpcdx3EmTZ piWQAbIgmcbO1sy5oxh6AguHVoqw4kAPNiXEDMzfgfiMmUA/iObzMl1ot+5OgRIW ndi1b+uKstdPoFuaOzEki4Qr8CigLbJJhS/4tE0KKO1CTkSWUQyZ4/yM5yr5ehh5 9TxXfucu2izxNluTdgGb+P+Hr9ls0gVFIJTs0Bm3gjOzU7LU6BWPiCfFkz3PUWRr KwJJT+oRI7PP0jcDeIxzjGpeKinIw3IPoF3wvn96dYDJ1M/xJdGPeIKN9HkOla83 3T+IKXnlFmpPGyoLS3BVHBwWTB4xo9Ww6FH83fGydV5QjbdwcvRFhMvP/XCNEvh+ GO8MzsPp+o6Tff05VofjrtJgTrxX1vDamoDZPQZgrI4Hu7Ks0l+MfxT9r5x4UaIu JLhONoVGDD7+8izm2+NP2kocwm+JgpM0uT41Yr5x6PNBdtR6oX6UtoFC3j/jcMOH 4x8+gMqbr4uEto+3rH0tBre6qge3Gf0nZhkv0P/0lYNwBIn5rU8e1EYReP4MgCvp +lQFJiWRSHI8rwDqK8Y8 =bruT -----END PGP SIGNATURE----- --zj18g9eElA7rRQh+--