qemu/tests/qtest/libqos
Daniel Henrique Barboza 3283843a8e libqos/virtio.c: fix 'avail_event' offset in qvring_init()
In qvring_init() we're writing vq->used->avail_event at "vq->used + 2 +
array_size".  The struct pointed by vq->used is, from virtio_ring.h
Linux header):

 *	// A ring of used descriptor heads with free-running index.
 *	__virtio16 used_flags;
 *	__virtio16 used_idx;
 *	struct vring_used_elem used[num];
 *	__virtio16 avail_event_idx;

So 'flags' is the word right at vq->used. 'idx' is vq->used + 2. We need
to skip 'used_idx' by adding + 2 bytes, and then sum the vector size, to
reach avail_event_idx. An example on how to properly access this field
can be found in qvirtqueue_kick():

avail_event = qvirtio_readw(d, qts, vq->used + 4 +
                            sizeof(struct vring_used_elem) * vq->size);

This error was detected when enabling the RISC-V 'virt' libqos machine.
The 'idx' test from vhost-user-blk-test.c errors out with a timeout in
qvirtio_wait_used_elem(). The timeout happens because when processing
the first element, 'avail_event' is read in qvirtqueue_kick() as non-zero
because we didn't initialize it properly (and the memory at that point
happened to be non-zero). 'idx' is 0.

All of this makes this condition fail because "idx - avail_event" will
overflow and be non-zero:

/* < 1 because we add elements to avail queue one by one */
if ((flags & VRING_USED_F_NO_NOTIFY) == 0 &&
                        (!vq->event || (uint16_t)(idx-avail_event) < 1)) {
    d->bus->virtqueue_kick(d, vq);
}

As a result the virtqueue is never kicked and we'll timeout waiting for it.

Fixes: 1053587c3f ("libqos: Added EVENT_IDX support")
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Message-ID: <20240217192607.32565-3-dbarboza@ventanamicro.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
2024-03-01 08:27:33 +01:00
..
aarch64-xlnx-zcu102-machine.c tests/qtest: libqos: Rename malloc.h to libqos-malloc.h 2022-08-29 15:28:51 +02:00
ahci.c hw/ide/ahci: PxCI should not get cleared when ERR_STAT is set 2023-09-06 22:48:04 -04:00
ahci.h hw/ide/ahci: PxCI should not get cleared when ERR_STAT is set 2023-09-06 22:48:04 -04:00
arm-imx25-pdk-machine.c tests/qtest: libqos: Rename malloc.h to libqos-malloc.h 2022-08-29 15:28:51 +02:00
arm-n800-machine.c tests/qtest: libqos: Rename malloc.h to libqos-malloc.h 2022-08-29 15:28:51 +02:00
arm-raspi2-machine.c tests/qtest: libqos: Rename malloc.h to libqos-malloc.h 2022-08-29 15:28:51 +02:00
arm-sabrelite-machine.c tests/qtest: libqos: Rename malloc.h to libqos-malloc.h 2022-08-29 15:28:51 +02:00
arm-smdkc210-machine.c tests/qtest: libqos: Rename malloc.h to libqos-malloc.h 2022-08-29 15:28:51 +02:00
arm-virt-machine.c tests/qtest: libqos: Rename malloc.h to libqos-malloc.h 2022-08-29 15:28:51 +02:00
arm-xilinx-zynq-a9-machine.c tests/qtest: libqos: Rename malloc.h to libqos-malloc.h 2022-08-29 15:28:51 +02:00
e1000e.c tests/qtest/libqos/e1000e: Export macreg functions 2023-03-10 17:26:47 +08:00
e1000e.h tests/qtest/libqos/e1000e: Export macreg functions 2023-03-10 17:26:47 +08:00
fw_cfg.c tests: move libqtest.h back under qtest/ 2022-05-03 15:16:51 +04:00
fw_cfg.h tests: move libqtest.h back under qtest/ 2022-05-03 15:16:51 +04:00
generic-pcihost.c tests/qtest/libqos: Add generic pci host bridge in arm-virt machine 2022-05-12 12:07:06 +02:00
generic-pcihost.h tests/qtest: libqos: Rename malloc.h to libqos-malloc.h 2022-08-29 15:28:51 +02:00
i2c-imx.c tests: move libqtest.h back under qtest/ 2022-05-03 15:16:51 +04:00
i2c-omap.c tests: move libqtest.h back under qtest/ 2022-05-03 15:16:51 +04:00
i2c.c tests: move libqtest.h back under qtest/ 2022-05-03 15:16:51 +04:00
i2c.h tests: move libqtest.h back under qtest/ 2022-05-03 15:16:51 +04:00
igb.c igb: RX payload guest writting refactoring 2023-09-18 14:36:13 +08:00
libqos-malloc.c tests/qtest: libqos: Rename malloc.h to libqos-malloc.h 2022-08-29 15:28:51 +02:00
libqos-malloc.h tests/qtest: libqos: Rename malloc.h to libqos-malloc.h 2022-08-29 15:28:51 +02:00
libqos-pc.c meson: convert tests/qtest to meson 2020-08-21 06:30:20 -04:00
libqos-pc.h tests: add G_GNUC_PRINTF for various functions 2023-01-11 10:44:34 +01:00
libqos-spapr.c meson: convert tests/qtest to meson 2020-08-21 06:30:20 -04:00
libqos-spapr.h tests: add G_GNUC_PRINTF for various functions 2023-01-11 10:44:34 +01:00
libqos.c tests/qtest: Move mkimg() and have_qemu_img() from libqos to libqtest 2023-07-10 15:34:57 +02:00
libqos.h tests/qtest: Move mkimg() and have_qemu_img() from libqos to libqtest 2023-07-10 15:34:57 +02:00
malloc-pc.c Remove qemu-common.h include from most units 2022-04-06 14:31:55 +02:00
malloc-pc.h tests/qtest: libqos: Rename malloc.h to libqos-malloc.h 2022-08-29 15:28:51 +02:00
malloc-spapr.c Remove qemu-common.h include from most units 2022-04-06 14:31:55 +02:00
malloc-spapr.h tests/qtest: libqos: Rename malloc.h to libqos-malloc.h 2022-08-29 15:28:51 +02:00
meson.build tests/qtest: enable tests for virtio-scmi 2023-07-10 16:17:08 -04:00
pci-pc.c tests/x86: add helper qtest_qmp_device_del_send() 2022-10-11 14:06:48 +02:00
pci-pc.h tests/qtest: libqos: Rename malloc.h to libqos-malloc.h 2022-08-29 15:28:51 +02:00
pci-spapr.c tests/qtest/libqos/pci: Introduce pio_limit 2022-05-12 12:07:06 +02:00
pci-spapr.h tests/qtest: libqos: Rename malloc.h to libqos-malloc.h 2022-08-29 15:28:51 +02:00
pci.c tests/qtest/libqos/pci: Introduce pio_limit 2022-05-12 12:07:06 +02:00
pci.h tests/qtest/libqos: Skip hotplug tests if pci root bus is not hotpluggable 2022-05-12 12:07:06 +02:00
ppc64_pseries-machine.c tests: move libqtest.h back under qtest/ 2022-05-03 15:16:51 +04:00
qgraph_internal.h tests/: spelling fixes 2023-09-08 13:08:52 +03:00
qgraph.c tests/: spelling fixes 2023-09-08 13:08:52 +03:00
qgraph.h Fix several typos in documentation (found by codespell) 2022-11-11 09:39:25 +01:00
qos_external.c tests/qtest: libqos: Rename malloc.h to libqos-malloc.h 2022-08-29 15:28:51 +02:00
qos_external.h tests/qtest: libqos: Rename malloc.h to libqos-malloc.h 2022-08-29 15:28:51 +02:00
rtas.c tests: move libqtest.h back under qtest/ 2022-05-03 15:16:51 +04:00
rtas.h tests/qtest: libqos: Rename malloc.h to libqos-malloc.h 2022-08-29 15:28:51 +02:00
sdhci-cmd.c tests: move libqtest.h back under qtest/ 2022-05-03 15:16:51 +04:00
sdhci-cmd.h tests: move libqtest.h back under qtest/ 2022-05-03 15:16:51 +04:00
sdhci.c tests: move libqtest.h back under qtest/ 2022-05-03 15:16:51 +04:00
sdhci.h meson: convert tests/qtest to meson 2020-08-21 06:30:20 -04:00
tpci200.c tests: move libqtest.h back under qtest/ 2022-05-03 15:16:51 +04:00
usb.c tests: move libqtest.h back under qtest/ 2022-05-03 15:16:51 +04:00
usb.h meson: convert tests/qtest to meson 2020-08-21 06:30:20 -04:00
vhost-user-blk.c tests: move libqtest.h back under qtest/ 2022-05-03 15:16:51 +04:00
vhost-user-blk.h test: new qTest case to test the vhost-user-blk-server 2021-05-18 12:57:38 +02:00
virtio-9p-client.c tests/9p: fix potential leak in v9fs_rreaddir() 2023-05-16 16:21:54 +02:00
virtio-9p-client.h tests/9p: merge v9fs_tunlinkat() and do_unlinkat() 2022-10-24 12:24:32 +02:00
virtio-9p.c tests: add G_GNUC_PRINTF for various functions 2023-01-11 10:44:34 +01:00
virtio-9p.h tests/9pfs: make create/remove test dir public 2020-11-01 19:44:29 +01:00
virtio-balloon.c tests: move libqtest.h back under qtest/ 2022-05-03 15:16:51 +04:00
virtio-balloon.h meson: convert tests/qtest to meson 2020-08-21 06:30:20 -04:00
virtio-blk.c tests: move libqtest.h back under qtest/ 2022-05-03 15:16:51 +04:00
virtio-blk.h meson: convert tests/qtest to meson 2020-08-21 06:30:20 -04:00
virtio-gpio.c tests/: spelling fixes 2023-09-08 13:08:52 +03:00
virtio-gpio.h tests/qtest: enable tests for virtio-gpio 2022-10-07 09:41:51 -04:00
virtio-iommu.c tests: move libqtest.h back under qtest/ 2022-05-03 15:16:51 +04:00
virtio-iommu.h tests: qtest: Add virtio-iommu test 2021-12-15 08:08:59 +01:00
virtio-mmio.c tests/qtest: libqos: Rename malloc.h to libqos-malloc.h 2022-08-29 15:28:51 +02:00
virtio-mmio.h meson: convert tests/qtest to meson 2020-08-21 06:30:20 -04:00
virtio-net.c tests: move libqtest.h back under qtest/ 2022-05-03 15:16:51 +04:00
virtio-net.h meson: convert tests/qtest to meson 2020-08-21 06:30:20 -04:00
virtio-pci-modern.c tests/libqos: Move the libqos files under tests/qtest/ 2020-01-12 11:42:41 +01:00
virtio-pci-modern.h tests/libqos: Move the libqos files under tests/qtest/ 2020-01-12 11:42:41 +01:00
virtio-pci.c tests/qtest: libqos: Rename malloc.h to libqos-malloc.h 2022-08-29 15:28:51 +02:00
virtio-pci.h meson: convert tests/qtest to meson 2020-08-21 06:30:20 -04:00
virtio-rng.c tests: move libqtest.h back under qtest/ 2022-05-03 15:16:51 +04:00
virtio-rng.h meson: convert tests/qtest to meson 2020-08-21 06:30:20 -04:00
virtio-scmi.c tests/qtest: enable tests for virtio-scmi 2023-07-10 16:17:08 -04:00
virtio-scmi.h tests/qtest: enable tests for virtio-scmi 2023-07-10 16:17:08 -04:00
virtio-scsi.c tests: move libqtest.h back under qtest/ 2022-05-03 15:16:51 +04:00
virtio-scsi.h meson: convert tests/qtest to meson 2020-08-21 06:30:20 -04:00
virtio-serial.c tests: move libqtest.h back under qtest/ 2022-05-03 15:16:51 +04:00
virtio-serial.h meson: convert tests/qtest to meson 2020-08-21 06:30:20 -04:00
virtio.c libqos/virtio.c: fix 'avail_event' offset in qvring_init() 2024-03-01 08:27:33 +01:00
virtio.h tests/qtest: libqos: Rename malloc.h to libqos-malloc.h 2022-08-29 15:28:51 +02:00
x86_64_pc-machine.c tests: move libqtest.h back under qtest/ 2022-05-03 15:16:51 +04:00