On 30/4/25 09:33, Thomas Huth wrote:
From: Thomas Huth <th...@redhat.com>
The logic in the qvirtio_read/write function is rather a headache,
involving byte-swapping when the target is big endian, just to
maybe involve another byte-swapping in the qtest_read/write
function immediately afterwards (on the QEMU side). Let's do it in
a more obvious way here: For virtio 1.0, we know that the values have
to be little endian, so let's read/write the bytes in that well known
order here.
Thanks for looking at this!
Signed-off-by: Thomas Huth <th...@redhat.com>
---
This also decreases our usage of qtest_big_endian() which might (or
might not) get helpful for the universal binary one day...
tests/qtest/libqos/virtio.c | 61 ++++++++++++++++++++++++++-----------
1 file changed, 44 insertions(+), 17 deletions(-)
diff --git a/tests/qtest/libqos/virtio.c b/tests/qtest/libqos/virtio.c
index 2e7979652fd..078adf3c8dc 100644
--- a/tests/qtest/libqos/virtio.c
+++ b/tests/qtest/libqos/virtio.c
@@ -25,49 +25,76 @@
*/
static uint16_t qvirtio_readw(QVirtioDevice *d, QTestState *qts, uint64_t
addr)
{
- uint16_t val = qtest_readw(qts, addr);
+ uint8_t buf[2];
- if (d->features & (1ull << VIRTIO_F_VERSION_1) && qtest_big_endian(qts)) {
- val = bswap16(val);
+ if (d->features & (1ull << VIRTIO_F_VERSION_1)) {
+ qtest_memread(qts, addr, buf, sizeof(buf));
+ return (buf[1] << 8) | buf[0];
+ } else {
+ return qtest_readw(qts, addr);
}
- return val;
}
What about using cpu_to_le() API?
-- >8 --
static uint16_t qvirtio_readw(QVirtioDevice *d, QTestState *qts,
uint64_t addr)
{
- uint16_t val = qtest_readw(qts, addr);
+ uint16_t val;
- if (d->features & (1ull << VIRTIO_F_VERSION_1) &&
qtest_big_endian(qts)) {
- val = bswap16(val);
+ if (d->features & (1ull << VIRTIO_F_VERSION_1)) {
+ qtest_memread(qts, addr, &val, sizeof(val));
+ cpu_to_le16s(&val);
+ } else {
+ val = qtest_readw(qts, addr);
}
+
return val;
}
---