qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] libqos: fix endianness bug in virtio-blk-test


From: Greg Kurz
Subject: [Qemu-devel] [PATCH] libqos: fix endianness bug in virtio-blk-test
Date: Tue, 02 Sep 2014 17:26:52 +0200
User-agent: StGit/0.17-dirty

The virtio block request header is in target cpu
byte order, which may be different from the host
cpu byte order.

This patch allows the virtio-blk-test to run with
a x86_64 (LE) target on a ppc64 (BE) host.

Signed-off-by: Greg Kurz <address@hidden>
---
 tests/virtio-blk-test.c |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c
index fdc6ffe..588666c 100644
--- a/tests/virtio-blk-test.c
+++ b/tests/virtio-blk-test.c
@@ -19,6 +19,7 @@
 #include "libqos/pci-pc.h"
 #include "libqos/malloc.h"
 #include "libqos/malloc-pc.h"
+#include "qemu/bswap.h"
 
 #define QVIRTIO_BLK_F_BARRIER       0x00000001
 #define QVIRTIO_BLK_F_SIZE_MAX      0x00000002
@@ -96,6 +97,21 @@ static QVirtioPCIDevice *virtio_blk_init(QPCIBus *bus)
     return dev;
 }
 
+static inline void virtio_blk_fix_request(QVirtioBlkReq *req)
+{
+#ifdef HOST_WORDS_BIGENDIAN
+    bool host_endian = true;
+#else
+    bool host_endian = false;
+#endif
+
+    if (qtest_big_endian() != host_endian) {
+        req->type = bswap32(req->type);
+        req->ioprio = bswap32(req->ioprio);
+        req->sector = bswap64(req->sector);
+    }
+}
+
 static uint64_t virtio_blk_request(QGuestAllocator *alloc, QVirtioBlkReq *req,
                                                             uint64_t data_size)
 {
@@ -105,6 +121,8 @@ static uint64_t virtio_blk_request(QGuestAllocator *alloc, 
QVirtioBlkReq *req,
     g_assert_cmpuint(data_size % 512, ==, 0);
     addr = guest_alloc(alloc, sizeof(*req) + data_size);
 
+    virtio_blk_fix_request(req);
+
     memwrite(addr, req, 16);
     memwrite(addr + 16, req->data, data_size);
     memwrite(addr + 16 + data_size, &status, sizeof(status));




reply via email to

[Prev in Thread] Current Thread [Next in Thread]