From: Rusty Russell <rusty@rustcorp.com.au>
To: "Michael S. Tsirkin" <mst@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>
Cc: "kvm\@vger.kernel.org mailing list" <kvm@vger.kernel.org>,
Pawel Moll <Pawel.Moll@arm.com>,
"kvmarm\@lists.cs.columbia.edu" <kvmarm@lists.cs.columbia.edu>,
linux-arm-kernel <linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH 0/3] virtio-mmio: handle BE guests on LE hosts
Date: Tue, 15 Oct 2013 09:53:17 +1030 [thread overview]
Message-ID: <874n8jbfoa.fsf@rustcorp.com.au> (raw)
In-Reply-To: <20131014171022.GA13807@redhat.com>
"Michael S. Tsirkin" <mst@redhat.com> writes:
> On Mon, Oct 14, 2013 at 06:50:48PM +0200, Paolo Bonzini wrote:
>> Il 14/10/2013 17:36, Marc Zyngier ha scritto:
>> >> >
>> >> > Devices are fine in QEMU, it's only the "generic" parts (rings) that are
>> >> > missing AFAICT.
>> > So if I understand correctly how it works, target endianness is set at
>> > compile time, and you have a BE specific QEMU?
>>
>> Yes. Though as Alex said, this will have to change for PPC
>> little-endian support.
>>
>> Paolo
>
> Or we'll just say that this platform requires virtio 1.0.
To come full circle, I have implemented virtio support for BE PPC in
qemu :) And we'll be supporting pre-1.0 for the moment. I'm awaiting
some ppc-specific hooks, but it could be merged without them.
It's icky: we don't really want to use the current endianness of the
CPU, since in theory a BE kernel could be running an LE process. So at
the time of virtio device reset (the first thing the Linux drivers do)
we read the endianness of the interrupt entry point, which is presumably
the OS endianness.
The result looks like this. In virtio_reset(void *opaque):
/* We assume all devices are the same endian. */
virtio_byteswap = virtio_get_byteswap();
And accessors like this are used in all virtio devices and routines:
/* Initialized by virtio_get_byteswap() at any virtio device reset. */
extern bool virtio_byteswap;
static inline uint16_t virtio_lduw_phys(hwaddr pa)
{
if (virtio_byteswap) {
return bswap16(lduw_phys(pa));
}
return lduw_phys(pa);
}
static inline uint32_t virtio_ldl_phys(hwaddr pa)
{
if (virtio_byteswap) {
return bswap32(ldl_phys(pa));
}
return ldl_phys(pa);
}
static inline uint64_t virtio_ldq_phys(hwaddr pa)
{
if (virtio_byteswap) {
return bswap64(ldq_phys(pa));
}
return ldq_phys(pa);
}
static inline void virtio_stw_phys(hwaddr pa, uint16_t value)
{
if (virtio_byteswap) {
stw_phys(pa, bswap16(value));
} else {
stw_phys(pa, value);
}
}
static inline void virtio_stl_phys(hwaddr pa, uint32_t value)
{
if (virtio_byteswap) {
stl_phys(pa, bswap32(value));
} else {
stl_phys(pa, value);
}
}
static inline void virtio_stw_p(void *ptr, uint16_t v)
{
if (virtio_byteswap) {
stw_p(ptr, bswap16(v));
} else {
stw_p(ptr, v);
}
}
static inline void virtio_stl_p(void *ptr, uint32_t v)
{
if (virtio_byteswap) {
stl_p(ptr, bswap32(v));
} else {
stl_p(ptr, v);
}
}
static inline void virtio_stq_p(void *ptr, uint64_t v)
{
if (virtio_byteswap) {
stq_p(ptr, bswap64(v));
} else {
stq_p(ptr, v);
}
}
static inline int virtio_lduw_p(const void *ptr)
{
if (virtio_byteswap) {
return bswap16(lduw_p(ptr));
} else {
return lduw_p(ptr);
}
}
static inline int virtio_ldl_p(const void *ptr)
{
if (virtio_byteswap) {
return bswap32(ldl_p(ptr));
} else {
return ldl_p(ptr);
}
}
static inline uint64_t virtio_ldq_p(const void *ptr)
{
if (virtio_byteswap) {
return bswap64(ldq_p(ptr));
} else {
return ldq_p(ptr);
}
}
static inline uint32_t virtio_tswap32(uint32_t s)
{
if (virtio_byteswap) {
return bswap32(tswap32(s));
} else {
return tswap32(s);
}
}
static inline void virtio_tswap32s(uint32_t *s)
{
tswap32s(s);
if (virtio_byteswap) {
*s = bswap32(*s);
}
}
There are obvious optimizations to this, such as making virtio_byteswap
a compile time constant on non-endian-ambivalent targets, but this is
the current approach.
Cheers,
Rusty.
next prev parent reply other threads:[~2013-10-14 23:27 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-11 14:36 [PATCH 0/3] virtio-mmio: handle BE guests on LE hosts Marc Zyngier
2013-10-11 14:36 ` [PATCH 1/3] virtio: let the guest report its endianess if advertized by the host Marc Zyngier
2013-10-11 14:36 ` [PATCH 2/3] virtio: mmio: fix signature checking for BE guests Marc Zyngier
2013-10-14 8:46 ` Pawel Moll
2013-10-14 9:11 ` Rusty Russell
2013-11-05 3:36 ` Rusty Russell
2013-11-05 10:45 ` Pawel Moll
2013-11-07 0:36 ` Rusty Russell
2013-10-11 14:36 ` [PATCH 3/3] virtio: mmio: access configuration space as little-endian Marc Zyngier
2013-10-14 8:44 ` Pawel Moll
2013-10-12 18:28 ` [PATCH 0/3] virtio-mmio: handle BE guests on LE hosts Michael S. Tsirkin
2013-10-14 8:24 ` Marc Zyngier
2013-10-14 8:59 ` Michael S. Tsirkin
2013-10-14 9:04 ` Pawel Moll
2013-10-14 10:46 ` Michael S. Tsirkin
2013-10-14 10:50 ` Pawel Moll
2013-10-14 23:02 ` Rusty Russell
2013-10-14 9:13 ` Rusty Russell
2013-10-14 8:21 ` Rusty Russell
2013-10-14 12:36 ` Marc Zyngier
2013-10-14 12:51 ` Michael S. Tsirkin
2013-10-17 0:27 ` Rusty Russell
2013-10-14 13:03 ` Paolo Bonzini
2013-10-14 13:10 ` Alexander Graf
2013-10-14 13:13 ` Paolo Bonzini
2013-10-14 13:24 ` Marc Zyngier
2013-10-14 13:29 ` Paolo Bonzini
2013-10-14 13:39 ` Alexander Graf
2013-10-14 13:49 ` Marc Zyngier
2013-10-14 14:05 ` Michael S. Tsirkin
2013-10-14 14:13 ` Marc Zyngier
2013-10-14 14:16 ` Alexander Graf
2013-10-14 14:52 ` Marc Zyngier
2013-10-14 14:56 ` Paolo Bonzini
2013-10-14 15:12 ` Marc Zyngier
2013-10-14 15:22 ` Paolo Bonzini
2013-10-14 15:36 ` Marc Zyngier
2013-10-14 16:50 ` Paolo Bonzini
2013-10-14 17:10 ` Michael S. Tsirkin
2013-10-14 23:23 ` Rusty Russell [this message]
2013-10-15 6:38 ` Michael S. Tsirkin
2013-10-15 9:19 ` Marc Zyngier
2013-10-14 15:45 ` Anup Patel
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=874n8jbfoa.fsf@rustcorp.com.au \
--to=rusty@rustcorp.com.au \
--cc=Pawel.Moll@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox