aboutsummaryrefslogtreecommitdiff
path: root/include/hw/virtio/virtio-access.h
diff options
context:
space:
mode:
authorJason Wang <jasowang@redhat.com>2015-07-17 15:19:18 +0800
committerMichael S. Tsirkin <mst@redhat.com>2015-07-20 14:19:41 +0300
commitfeb93f361739071778ca2d23df3876db399548f7 (patch)
tree4e343f13bc3292507b1e08e6cc5f8c29def4f552 /include/hw/virtio/virtio-access.h
parentd345ed2da3279b015605823397235b8c5ca5251f (diff)
virtio-net: unbreak any layout
Commit 032a74a1c0fcdd5fd1c69e56126b4c857ee36611 ("virtio-net: byteswap virtio-net header") breaks any layout by requiring out_sg[0].iov_len >= n->guest_hdr_len. Fixing this by copying header to temporary buffer if swap is needed, and then use this buffer as part of out_sg. Fixes 032a74a1c0fcdd5fd1c69e56126b4c857ee36611 ("virtio-net: byteswap virtio-net header") Cc: qemu-stable@nongnu.org Cc: clg@fr.ibm.com Signed-off-by: Jason Wang <jasowang@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'include/hw/virtio/virtio-access.h')
-rw-r--r--include/hw/virtio/virtio-access.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/include/hw/virtio/virtio-access.h b/include/hw/virtio/virtio-access.h
index cee5dd70c9..1ec1dfdb6c 100644
--- a/include/hw/virtio/virtio-access.h
+++ b/include/hw/virtio/virtio-access.h
@@ -143,6 +143,15 @@ static inline uint64_t virtio_ldq_p(VirtIODevice *vdev, const void *ptr)
}
}
+static inline bool virtio_needs_swap(VirtIODevice *vdev)
+{
+#ifdef HOST_WORDS_BIGENDIAN
+ return virtio_access_is_big_endian(vdev) ? false : true;
+#else
+ return virtio_access_is_big_endian(vdev) ? true : false;
+#endif
+}
+
static inline uint16_t virtio_tswap16(VirtIODevice *vdev, uint16_t s)
{
#ifdef HOST_WORDS_BIGENDIAN