qemu/tests
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
..
avocado tests/avocado/boot_linux_console.py: Add Rpi4b boot tests 2024-02-27 13:01:43 +00:00
bench meson: remove unused variable 2023-12-31 09:11:27 +01:00
data tests/qtest/bios-tables-tests: Update virt golden reference 2024-02-15 11:31:52 +00:00
decode tests/: spelling fixes 2023-09-08 13:08:52 +03:00
docker .gitlab-ci.d: Drop cross-win32-system job 2024-02-23 08:13:52 +01:00
fp tests/fp: Bump fp-test-mulAdd test timeout to 3 minutes 2024-01-12 13:23:48 +00:00
guest-debug tests/tcg: Factor out gdbstub test functions 2024-01-29 20:48:49 +10:00
image-fuzzer
include
keys
lcitool .gitlab-ci.d: Drop cross-win32-system job 2024-02-23 08:13:52 +01:00
migration tests/qtest: option to suspend during migration 2024-01-04 09:52:42 +08:00
multiboot
perf/block/qcow2
plugin tests/tcg: expand insn test case to exercise register API 2024-02-28 09:11:42 +00:00
qapi-schema qapi: Divorce QAPIDoc from QAPIParseError 2024-02-26 10:43:56 +01:00
qemu-iotests iotests: Make 144 deterministic again 2024-02-15 16:40:06 +00:00
qtest libqos/virtio.c: fix 'avail_event' offset in qvring_init() 2024-03-01 08:27:33 +01:00
rocker
tcg tests/tcg: bump TCG test timeout to 120s 2024-02-28 09:09:11 +00:00
tsan block: remove AioContext locking 2023-12-21 22:49:27 +01:00
uefi-test-tools tests/: spelling fixes 2023-09-08 13:08:52 +03:00
unit Character device backend patches for 2024-02-12 2024-02-14 13:00:19 +00:00
vm tests/vm: update openbsd image to 7.4 2024-02-28 09:09:16 +00:00
vmstate-static-checker-data
dbus-vmstate-daemon.sh
Makefile.include tests: respect --enable/--disable-download for Avocado 2023-11-24 12:07:47 +01:00
meson.build configure, meson: rename targetos to host_os 2023-12-31 09:11:29 +01:00
test-qht-par.c
vhost-user-bridge.c