From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>, <qemu-block@nongnu.org>,
Hanna Reitz <hreitz@redhat.com>,
Laurent Vivier <lvivier@redhat.com>, Fam Zheng <fam@euphon.net>,
Fabiano Rosas <farosas@suse.de>,
Paolo Bonzini <pbonzini@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Stefano Garzarella <sgarzare@redhat.com>
Subject: [PATCH 4/5] tests/libqos: extract qvirtqueue_set_avail_idx()
Date: Mon, 22 Sep 2025 18:01:48 -0400 [thread overview]
Message-ID: <20250922220149.498967-5-stefanha@redhat.com> (raw)
In-Reply-To: <20250922220149.498967-1-stefanha@redhat.com>
Setting the vring's avail.idx can be useful for low-level VIRTIO tests,
especially for testing error scenarios with invalid vrings. Extract it
into a new function so that the next commit can add a test that uses
this new test API.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
tests/qtest/libqos/virtio.h | 2 ++
tests/qtest/libqos/virtio.c | 16 ++++++++++++----
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/tests/qtest/libqos/virtio.h b/tests/qtest/libqos/virtio.h
index 7adc7cbd10..e238f1726f 100644
--- a/tests/qtest/libqos/virtio.h
+++ b/tests/qtest/libqos/virtio.h
@@ -143,6 +143,8 @@ uint32_t qvirtqueue_add(QTestState *qts, QVirtQueue *vq, uint64_t data,
uint32_t len, bool write, bool next);
uint32_t qvirtqueue_add_indirect(QTestState *qts, QVirtQueue *vq,
QVRingIndirectDesc *indirect);
+void qvirtqueue_set_avail_idx(QTestState *qts, QVirtioDevice *d,
+ QVirtQueue *vq, uint16_t idx);
void qvirtqueue_kick(QTestState *qts, QVirtioDevice *d, QVirtQueue *vq,
uint32_t free_head);
bool qvirtqueue_get_buf(QTestState *qts, QVirtQueue *vq, uint32_t *desc_idx,
diff --git a/tests/qtest/libqos/virtio.c b/tests/qtest/libqos/virtio.c
index 5a709d0bc5..010ff40834 100644
--- a/tests/qtest/libqos/virtio.c
+++ b/tests/qtest/libqos/virtio.c
@@ -265,8 +265,9 @@ void qvring_init(QTestState *qts, const QGuestAllocator *alloc, QVirtQueue *vq,
/* vq->avail->flags */
qvirtio_writew(vq->vdev, qts, vq->avail, 0);
- /* vq->avail->idx */
- qvirtio_writew(vq->vdev, qts, vq->avail + 2, 0);
+
+ qvirtqueue_set_avail_idx(qts, vq->vdev, vq, 0);
+
/* vq->avail->used_event */
qvirtio_writew(vq->vdev, qts, vq->avail + 4 + (2 * vq->size), 0);
@@ -388,6 +389,13 @@ uint32_t qvirtqueue_add_indirect(QTestState *qts, QVirtQueue *vq,
return vq->free_head++; /* Return and increase, in this order */
}
+void qvirtqueue_set_avail_idx(QTestState *qts, QVirtioDevice *d,
+ QVirtQueue *vq, uint16_t idx)
+{
+ /* vq->avail->idx */
+ qvirtio_writew(d, qts, vq->avail + 2, idx);
+}
+
void qvirtqueue_kick(QTestState *qts, QVirtioDevice *d, QVirtQueue *vq,
uint32_t free_head)
{
@@ -400,8 +408,8 @@ void qvirtqueue_kick(QTestState *qts, QVirtioDevice *d, QVirtQueue *vq,
/* vq->avail->ring[idx % vq->size] */
qvirtio_writew(d, qts, vq->avail + 4 + (2 * (idx % vq->size)), free_head);
- /* vq->avail->idx */
- qvirtio_writew(d, qts, vq->avail + 2, idx + 1);
+
+ qvirtqueue_set_avail_idx(qts, d, vq, idx + 1);
/* Must read after idx is updated */
flags = qvirtio_readw(d, qts, vq->used);
--
2.51.0
next prev parent reply other threads:[~2025-09-22 22:04 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-22 22:01 [PATCH 0/5] virtio: allow virtio_error() in IOThreads Stefan Hajnoczi
2025-09-22 22:01 ` [PATCH 1/5] vhost: use virtio_config_get_guest_notifier() Stefan Hajnoczi
2025-09-23 8:33 ` Philippe Mathieu-Daudé
2025-09-22 22:01 ` [PATCH 2/5] virtio: unify virtio_notify_irqfd() and virtio_notify() Stefan Hajnoczi
2025-09-23 8:41 ` Philippe Mathieu-Daudé
2025-09-22 22:01 ` [PATCH 3/5] virtio: support irqfd in virtio_notify_config() Stefan Hajnoczi
2025-09-22 22:01 ` Stefan Hajnoczi [this message]
2025-09-23 8:45 ` [PATCH 4/5] tests/libqos: extract qvirtqueue_set_avail_idx() Philippe Mathieu-Daudé
2025-09-23 13:07 ` Fabiano Rosas
2025-09-22 22:01 ` [PATCH 5/5] tests/virtio-scsi: add a virtio_error() IOThread test Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250922220149.498967-5-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=fam@euphon.net \
--cc=farosas@suse.de \
--cc=hreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=lvivier@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=sgarzare@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).