From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39066) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XqOXO-0003Tt-Ea for qemu-devel@nongnu.org; Mon, 17 Nov 2014 10:48:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XqOXF-0001Xe-CH for qemu-devel@nongnu.org; Mon, 17 Nov 2014 10:48:22 -0500 Received: from mail-wg0-x233.google.com ([2a00:1450:400c:c00::233]:35799) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XqOXF-0001XU-1O for qemu-devel@nongnu.org; Mon, 17 Nov 2014 10:48:13 -0500 Received: by mail-wg0-f51.google.com with SMTP id k14so5909278wgh.38 for ; Mon, 17 Nov 2014 07:48:12 -0800 (PST) Date: Mon, 17 Nov 2014 15:48:09 +0000 From: Stefan Hajnoczi Message-ID: <20141117154809.GI16192@stefanha-thinkpad.redhat.com> References: <1414861350-13099-1-git-send-email-marc.mari.barcelo@gmail.com> <1414861350-13099-6-git-send-email-marc.mari.barcelo@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="Op27XXJsWz80g3oF" Content-Disposition: inline In-Reply-To: <1414861350-13099-6-git-send-email-marc.mari.barcelo@gmail.com> Subject: Re: [Qemu-devel] [PATCH v2 5/5] libqos: Add virtio MMIO support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Marc =?iso-8859-1?Q?Mar=ED?= Cc: qemu-devel@nongnu.org, Stefan Hajnoczi , Andreas =?iso-8859-1?Q?F=E4rber?= --Op27XXJsWz80g3oF Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Nov 01, 2014 at 06:02:30PM +0100, Marc Mar=ED wrote: > Add virtio MMIO support. > Add virtio-blk-test MMIO test case. >=20 > Signed-off-by: Marc Mar=ED > --- > tests/Makefile | 4 +- > tests/libqos/virtio-mmio.c | 190 ++++++++++++++++++++++++++++++++++++++= ++++++ > tests/libqos/virtio-mmio.h | 46 +++++++++++ > tests/virtio-blk-test.c | 143 +++++++++++++++++++++++++++++++-- > 4 files changed, 375 insertions(+), 8 deletions(-) > create mode 100644 tests/libqos/virtio-mmio.c > create mode 100644 tests/libqos/virtio-mmio.h >=20 > diff --git a/tests/Makefile b/tests/Makefile > index 4ae0ca4..f193b03 100644 > --- a/tests/Makefile > +++ b/tests/Makefile > @@ -183,6 +183,8 @@ gcov-files-sparc-y +=3D hw/timer/m48t59.c > gcov-files-sparc64-y +=3D hw/timer/m48t59.c > check-qtest-arm-y =3D tests/tmp105-test$(EXESUF) > gcov-files-arm-y +=3D hw/misc/tmp105.c > +check-qtest-arm-y +=3D tests/virtio-blk-test$(EXESUF) > +gcov-files-arm-y +=3D arm-softmmu/hw/block/virtio-blk.c > check-qtest-ppc-y +=3D tests/boot-order-test$(EXESUF) > check-qtest-ppc64-y +=3D tests/boot-order-test$(EXESUF) > check-qtest-ppc64-y +=3D tests/spapr-phb-test$(EXESUF) > @@ -300,8 +302,8 @@ libqos-obj-y +=3D tests/libqos/i2c.o > libqos-pc-obj-y =3D $(libqos-obj-y) tests/libqos/pci-pc.o > libqos-pc-obj-y +=3D tests/libqos/malloc-pc.o > libqos-omap-obj-y =3D $(libqos-obj-y) tests/libqos/i2c-omap.o > -libqos-virtio-obj-y =3D $(libqos-obj-y) $(libqos-pc-obj-y) tests/libqos/= virtio.o tests/libqos/virtio-pci.o > libqos-usb-obj-y =3D $(libqos-pc-obj-y) tests/libqos/usb.o > +libqos-virtio-obj-y =3D $(libqos-pc-obj-y) tests/libqos/virtio.o tests/l= ibqos/virtio-pci.o tests/libqos/virtio-mmio.o tests/libqos/malloc-generic.o > =20 > tests/rtc-test$(EXESUF): tests/rtc-test.o > tests/m48t59-test$(EXESUF): tests/m48t59-test.o > diff --git a/tests/libqos/virtio-mmio.c b/tests/libqos/virtio-mmio.c > new file mode 100644 > index 0000000..6896f7b > --- /dev/null > +++ b/tests/libqos/virtio-mmio.c > @@ -0,0 +1,190 @@ > +/* > + * libqos virtio MMIO driver > + * > + * Copyright (c) 2014 Marc Mar=ED > + * > + * This work is licensed under the terms of the GNU GPL, version 2 or la= ter. > + * See the COPYING file in the top-level directory. > + */ > + > +#include > +#include "libqtest.h" > +#include "libqos/virtio.h" > +#include "libqos/virtio-mmio.h" > +#include "libqos/malloc.h" > +#include "libqos/malloc-generic.h" > +#include Please include system headers before user headers. > +QVirtioMMIODevice *qvirtio_mmio_init_device(uint64_t addr, uint32_t page= _size) > +{ > + QVirtioMMIODevice *dev; > + uint32_t magic; > + dev =3D g_malloc0(sizeof(*dev)); > + > + magic =3D readl(addr + QVIRTIO_MMIO_MAGIC_VALUE); > + g_assert(magic =3D=3D ('v' | 'i' << 8 | 'r' << 16 | 't' << 24)); The magic value is little-endian according to the virtio 1.0 specification and the Linux kernel's virtio_mmio implementation. QEMU's virtio-mmio is native endian (i.e. host endian) and I think this is a bug. qtest's readl() is host-endian so it matches what QEMU does. I suppose you can leave this for now but it may need to be changed in the future. > +static void mmio_basic(void) > +{ > + QVirtioMMIODevice *dev; > + QVirtQueue *vq; > + QGuestAllocator *alloc; > + QVirtioBlkReq req; > + int n_size =3D TEST_IMAGE_SIZE / 2; > + uint64_t req_addr; > + uint64_t capacity; > + uint32_t features; > + uint32_t free_head; > + uint8_t status; > + char *data; > + > + arm_test_start(); > + > + dev =3D qvirtio_mmio_init_device(MMIO_DEV_BASE_ADDR, MMIO_PAGE_SIZE); > + g_assert(dev !=3D NULL); > + g_assert_cmphex(dev->vdev.device_type, =3D=3D, QVIRTIO_BLK_DEVICE_ID= ); > + > + qvirtio_reset(&qvirtio_mmio, &dev->vdev); > + qvirtio_set_acknowledge(&qvirtio_mmio, &dev->vdev); > + qvirtio_set_driver(&qvirtio_mmio, &dev->vdev); > + > + capacity =3D qvirtio_config_readq(&qvirtio_mmio, &dev->vdev, > + QVIRTIO_MMIO_DEVICE_SPEC= IFIC); > + g_assert_cmpint(capacity, =3D=3D, TEST_IMAGE_SIZE / 512); > + > + features =3D qvirtio_get_features(&qvirtio_mmio, &dev->vdev); > + features =3D features & ~(QVIRTIO_F_RING_INDIRECT_DESC | > + QVIRTIO_F_RING_EVENT_IDX | QVIRTIO_BLK_F= _SCSI); > + qvirtio_set_features(&qvirtio_mmio, &dev->vdev, features); > + > + alloc =3D generic_alloc_init(MMIO_RAM_ADDR, MMIO_RAM_SIZE, MMIO_PAGE= _SIZE); > + vq =3D qvirtqueue_setup(&qvirtio_mmio, &dev->vdev, alloc, 0); > + > + qvirtio_set_driver_ok(&qvirtio_mmio, &dev->vdev); > + > + qmp("{ 'execute': 'block_resize', 'arguments': { 'device': 'drive0',= " > + " 'size': %d } }", n= _size); > + > + qvirtio_wait_queue_isr(&qvirtio_mmio, &dev->vdev, vq, > + QVIRTIO_BLK_TIMEOUT_US); > + > + capacity =3D qvirtio_config_readq(&qvirtio_mmio, &dev->vdev, > + QVIRTIO_MMIO_DEVICE_SPEC= IFIC); > + g_assert_cmpint(capacity, =3D=3D, n_size / 512); > + > + /* Write request */ > + req.type =3D QVIRTIO_BLK_T_OUT; > + req.ioprio =3D 1; > + req.sector =3D 0; > + req.data =3D g_malloc0(512); > + strcpy(req.data, "TEST"); > + > + req_addr =3D virtio_blk_request(alloc, &req, 512); > + > + g_free(req.data); > + > + free_head =3D qvirtqueue_add(vq, req_addr, 528, false, true); > + qvirtqueue_add(vq, req_addr + 528, 1, true, false); > + qvirtqueue_kick(&qvirtio_mmio, &dev->vdev, vq, free_head); > + > + qvirtio_wait_queue_isr(&qvirtio_mmio, &dev->vdev, vq, > + QVIRTIO_BLK_TIMEOUT_US); > + status =3D readb(req_addr + 528); > + g_assert_cmpint(status, =3D=3D, 0); > + > + guest_free(alloc, req_addr); > + > + /* Read request */ > + req.type =3D QVIRTIO_BLK_T_IN; > + req.ioprio =3D 1; > + req.sector =3D 0; > + req.data =3D g_malloc0(512); > + > + req_addr =3D virtio_blk_request(alloc, &req, 512); > + > + g_free(req.data); > + > + free_head =3D qvirtqueue_add(vq, req_addr, 16, false, true); > + qvirtqueue_add(vq, req_addr + 16, 513, true, false); > + > + qvirtqueue_kick(&qvirtio_mmio, &dev->vdev, vq, free_head); > + > + qvirtio_wait_queue_isr(&qvirtio_mmio, &dev->vdev, vq, > + QVIRTIO_BLK_TIMEOUT_US); > + status =3D readb(req_addr + 528); > + g_assert_cmpint(status, =3D=3D, 0); > + > + data =3D g_malloc0(512); > + memread(req_addr + 16, data, 512); > + g_assert_cmpstr(data, =3D=3D, "TEST"); > + g_free(data); There is a lot of code duplication here. Can the test logic but shared between PCI and MMIO? --Op27XXJsWz80g3oF Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJUahi5AAoJEJykq7OBq3PIT0QIAIX+QzXXLc4DkSQhn2ks+8n0 SqNo91ZVQfUqPucfUQLamj6m3EJa9cjylvsHeQ8XHc1gAslJEGHnqdo8pz+p67ow DgsRitndKI/a3xmAy1iipt6pdhLzJY2XFg6/qfkYDEWxDwpeX6Je6eu2vsVAVgBI ZnSXTUFgz2SXWXMEQIpNskPAB3oDjW4ZddtB1ZcNbrsQudBqCJ5ZdddSuRr/wHqm ln0tIFjieTYCPX0T95wzWJX39WxtO4J+pB+uXiV/7C2/AkskwofHVqXh2RPsHhLu 9ogbQZ2CvqPFYctvJyUpLrXwFoLBCEnLE6ka7KYfpcc2HK0QYwgVAvX8oQXCeY8= =3he9 -----END PGP SIGNATURE----- --Op27XXJsWz80g3oF--