aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndre Przywara <andre.przywara@arm.com>2017-04-25 15:39:22 +0100
committerWill Deacon <will.deacon@arm.com>2017-06-09 11:16:47 +0100
commitb960f243c593dfcfcc9359f30558a8ae6a6ff535 (patch)
tree32260404573bdf48446980c2e0a0b266cc96b1fb
parent6518065aeb6c88e4710eb5c1bf0d8a4c2d268d1e (diff)
downloadkvmtool-b960f243c593dfcfcc9359f30558a8ae6a6ff535.tar.gz
virtio: fix endianness check for vhost support
Currently we deny any VHOST_* functionality if the architecture supports guests with different endianness than the host. Most of the time even on those architectures the endianness of guest and host are the same, though, so we are denying the glory of VHOST needlessly. Switch from compile time determination to a run time scheme, which takes the actual endianness of the guest into account. For this we change the semantics of VIRTIO_ENDIAN_HOST to return the actual endianness of the host (the endianness of kvmtool at compile time, really). The actual check in vhost_net now compares this against the guest endianness. This enables vhost support on ARM and ARM64. Acked-by: Marc Zyngier <marc.zyngier@arm.com> Signed-off-by: Andre Przywara <andre.przywara@arm.com> Signed-off-by: Will Deacon <will.deacon@arm.com>
-rw-r--r--include/kvm/virtio.h9
-rw-r--r--virtio/net.c2
2 files changed, 8 insertions, 3 deletions
diff --git a/include/kvm/virtio.h b/include/kvm/virtio.h
index 8324ba7d..00a791ac 100644
--- a/include/kvm/virtio.h
+++ b/include/kvm/virtio.h
@@ -17,10 +17,15 @@
#define VIRTIO_PCI_O_CONFIG 0
#define VIRTIO_PCI_O_MSIX 1
-#define VIRTIO_ENDIAN_HOST 0
#define VIRTIO_ENDIAN_LE (1 << 0)
#define VIRTIO_ENDIAN_BE (1 << 1)
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+#define VIRTIO_ENDIAN_HOST VIRTIO_ENDIAN_LE
+#else
+#define VIRTIO_ENDIAN_HOST VIRTIO_ENDIAN_BE
+#endif
+
struct virt_queue {
struct vring vring;
u32 pfn;
@@ -40,7 +45,7 @@ struct virt_queue {
#define VIRTIO_RING_ENDIAN VIRTIO_ENDIAN_HOST
#endif
-#if (VIRTIO_RING_ENDIAN & (VIRTIO_ENDIAN_LE | VIRTIO_ENDIAN_BE))
+#if VIRTIO_RING_ENDIAN != VIRTIO_ENDIAN_HOST
static inline __u16 __virtio_g2h_u16(u16 endian, __u16 val)
{
diff --git a/virtio/net.c b/virtio/net.c
index ffa83ab3..9fb9f1ee 100644
--- a/virtio/net.c
+++ b/virtio/net.c
@@ -530,7 +530,7 @@ static int init_vq(struct kvm *kvm, void *dev, u32 vq, u32 page_size, u32 align,
}
if (queue->endian != VIRTIO_ENDIAN_HOST)
- die_perror("VHOST requires VIRTIO_ENDIAN_HOST");
+ die_perror("VHOST requires the same endianness in guest and host");
state.num = queue->vring.num;
r = ioctl(ndev->vhost_fd, VHOST_SET_VRING_NUM, &state);