All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andre Przywara <andre.przywara@arm.com>
To: will.deacon@arm.com, marc.zyngier@arm.com
Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu,
	linux-arm-kernel@lists.infradead.org, eric.auger@linaro.org,
	Pavel Fedin <p.fedin@samsung.com>
Subject: [PATCH 03/14] virtio: fix endianness check for vhost support
Date: Mon, 20 Jul 2015 14:02:05 +0100	[thread overview]
Message-ID: <1437397336-21385-4-git-send-email-andre.przywara@arm.com> (raw)
In-Reply-To: <1437397336-21385-1-git-send-email-andre.przywara@arm.com>

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.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
 include/kvm/virtio.h | 9 +++++++--
 virtio/net.c         | 2 +-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/include/kvm/virtio.h b/include/kvm/virtio.h
index 768ee96..66530fd 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 9784520..aa61103 100644
--- a/virtio/net.c
+++ b/virtio/net.c
@@ -521,7 +521,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);
-- 
2.3.5


WARNING: multiple messages have this Message-ID (diff)
From: andre.przywara@arm.com (Andre Przywara)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 03/14] virtio: fix endianness check for vhost support
Date: Mon, 20 Jul 2015 14:02:05 +0100	[thread overview]
Message-ID: <1437397336-21385-4-git-send-email-andre.przywara@arm.com> (raw)
In-Reply-To: <1437397336-21385-1-git-send-email-andre.przywara@arm.com>

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.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
 include/kvm/virtio.h | 9 +++++++--
 virtio/net.c         | 2 +-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/include/kvm/virtio.h b/include/kvm/virtio.h
index 768ee96..66530fd 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 9784520..aa61103 100644
--- a/virtio/net.c
+++ b/virtio/net.c
@@ -521,7 +521,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);
-- 
2.3.5

  parent reply	other threads:[~2015-07-20 13:02 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-20 13:02 [PATCH 00/14] kvmtool: add ITS emulation and GSI routing for ARM Andre Przywara
2015-07-20 13:02 ` Andre Przywara
2015-07-20 13:02 ` [PATCH 01/14] irq: move IRQ routing into irq.c Andre Przywara
2015-07-20 13:02   ` Andre Przywara
2015-07-20 13:02 ` [PATCH 02/14] MSI-X: update GSI routing after changed MSI-X configuration Andre Przywara
2015-07-20 13:02   ` Andre Przywara
2015-07-20 13:02 ` Andre Przywara [this message]
2015-07-20 13:02   ` [PATCH 03/14] virtio: fix endianness check for vhost support Andre Przywara
2015-07-20 13:02 ` [PATCH 04/14] FDT: introduce global phandle allocation Andre Przywara
2015-07-20 13:02   ` Andre Przywara
2015-07-20 13:02 ` [PATCH 05/14] arm: use new phandle allocation functions Andre Przywara
2015-07-20 13:02   ` Andre Przywara
2015-07-20 13:02 ` [PATCH 06/14] TEMPORARY: arm: update public headers for GICv3 ITS emulation Andre Przywara
2015-07-20 13:02   ` Andre Przywara
2015-07-20 13:02 ` [PATCH 07/14] arm: allow creation of an MSI register frame region Andre Przywara
2015-07-20 13:02   ` Andre Przywara
2015-07-20 13:02 ` [PATCH 08/14] arm: FDT: create MSI controller DT node Andre Przywara
2015-07-20 13:02   ` Andre Przywara
2015-07-20 13:02 ` [PATCH 09/14] add kvm__check_vm_capability Andre Przywara
2015-07-20 13:02   ` Andre Przywara
2015-07-20 13:02 ` [PATCH 10/14] PCI: inject PCI device ID on MSI injection Andre Przywara
2015-07-20 13:02   ` Andre Przywara
2015-07-20 13:02 ` [PATCH 11/14] arm64: enable GICv3-ITS emulation Andre Przywara
2015-07-20 13:02   ` Andre Przywara
2015-07-20 13:02 ` [PATCH 12/14] arm: setup SPI IRQ routing tables Andre Przywara
2015-07-20 13:02   ` Andre Przywara
2015-07-20 13:02 ` [PATCH 13/14] TEMPORARY: update public headers for kvm_irq_routing_msi extension Andre Przywara
2015-07-20 13:02   ` Andre Przywara
2015-07-20 13:02 ` [PATCH 14/14] extend GSI IRQ routing to take a device ID Andre Przywara
2015-07-20 13:02   ` Andre Przywara

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=1437397336-21385-4-git-send-email-andre.przywara@arm.com \
    --to=andre.przywara@arm.com \
    --cc=eric.auger@linaro.org \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=marc.zyngier@arm.com \
    --cc=p.fedin@samsung.com \
    --cc=will.deacon@arm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.