From: Will Deacon <will.deacon@arm.com>
To: Marc Zyngier <Marc.Zyngier@arm.com>
Cc: "linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"kvmarm@lists.cs.columbia.edu" <kvmarm@lists.cs.columbia.edu>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
Pekka Enberg <penberg@kernel.org>
Subject: Re: [PATCH 2/7] kvmtool: virt_queue: handle guest endianness
Date: Fri, 11 Oct 2013 15:50:47 +0100 [thread overview]
Message-ID: <20131011145047.GO14732@mudshark.cambridge.arm.com> (raw)
In-Reply-To: <1381502195-8263-3-git-send-email-marc.zyngier@arm.com>
On Fri, Oct 11, 2013 at 03:36:30PM +0100, Marc Zyngier wrote:
> Wrap all accesses to virt_queue data structures shared between
> host and guest with byte swapping helpers.
>
> Should the architecture only support one endianness, these helpers
> are reduced to the identity function.
>
> Cc: Pekka Enberg <penberg@kernel.org>
> Cc: Will Deacon <will.deacon@arm.com>
> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
> ---
> tools/kvm/include/kvm/virtio.h | 189 ++++++++++++++++++++++++++++++++++++++++-
> tools/kvm/virtio/core.c | 59 +++++++------
> 2 files changed, 219 insertions(+), 29 deletions(-)
>
> diff --git a/tools/kvm/include/kvm/virtio.h b/tools/kvm/include/kvm/virtio.h
> index d6b0f47..04ec137 100644
> --- a/tools/kvm/include/kvm/virtio.h
> +++ b/tools/kvm/include/kvm/virtio.h
> @@ -1,6 +1,8 @@
> #ifndef KVM__VIRTIO_H
> #define KVM__VIRTIO_H
>
> +#include <endian.h>
> +
> #include <linux/virtio_ring.h>
> #include <linux/virtio_pci.h>
>
> @@ -29,15 +31,194 @@ struct virt_queue {
> u16 endian;
> };
>
> +/*
> + * The default policy is not to cope with the guest endianness.
> + * It also helps not breaking archs that do not care about supporting
> + * such a configuration.
> + */
Jesus Marc, are you *trying* to crash my preprocessor? Seriously though,
maybe this is better done as a block:
#if __BYTE_ORDER == __BIG_ENDIAN
#define virtio_le16toh(x) le16toh(x)
#define virtio_be16toh(x)
[...]
> +#ifndef VIRTIO_RING_ENDIAN
> +#define VIRTIO_RING_ENDIAN 0
> +#endif
> +
> +#if (VIRTIO_RING_ENDIAN & ((1UL << VIRTIO_RING_F_GUEST_LE) | (1UL << VIRTIO_RING_F_GUEST_BE)))
> +
> +#ifndef __BYTE_ORDER
> +#error "No byteorder? Giving up..."
> +#endif
> +
> +
> +static inline __u16 __virtio_guest_to_host_u16(u16 endian, __u16 val)
> +{
> +#if __BYTE_ORDER == __BIG_ENDIAN
> + if (endian == VIRTIO_ENDIAN_LE)
> + return le16toh(val);
> +#else
> + if (endian == VIRTIO_ENDIAN_BE)
> + return be16toh(val);
> +#endif
Then you can just use the endian parameter to do the right thing.
Will
next prev parent reply other threads:[~2013-10-11 14:51 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-11 14:36 [PATCH 0/7] kvmtool: handle guests of a different endianness Marc Zyngier
2013-10-11 14:36 ` [PATCH 1/7] kvmtool: virt_queue configuration based on endianness Marc Zyngier
2013-10-11 14:36 ` [PATCH 2/7] kvmtool: virt_queue: handle guest endianness Marc Zyngier
2013-10-11 14:50 ` Will Deacon [this message]
2013-10-11 16:54 ` Robin Murphy
2013-10-11 14:36 ` [PATCH 3/7] kvmtool: convert console backend to support bi-endianness Marc Zyngier
2013-10-11 14:36 ` [PATCH 4/7] kvmtool: convert 9p " Marc Zyngier
2013-10-11 14:36 ` [PATCH 5/7] kvmtool: convert blk " Marc Zyngier
2013-10-11 14:36 ` [PATCH 6/7] kvmtool: convert net " Marc Zyngier
2013-10-11 14:36 ` [PATCH 7/7] kvmtool: virtio: enable arm/arm64 support for bi-endianness Marc Zyngier
2013-10-14 13:05 ` Paolo Bonzini
2013-10-14 13:17 ` Marc Zyngier
2013-10-11 14:54 ` [PATCH 0/7] kvmtool: handle guests of a different endianness Will Deacon
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=20131011145047.GO14732@mudshark.cambridge.arm.com \
--to=will.deacon@arm.com \
--cc=Marc.Zyngier@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=penberg@kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox