From: Paolo Bonzini <pbonzini@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Alexey Kardashevskiy <aik@ozlabs.ru>,
Yongji Xie <xyjxie@linux.vnet.ibm.com>,
QEMU Developers <qemu-devel@nongnu.org>,
Alex Williamson <alex.williamson@redhat.com>,
zhong@linux.vnet.ibm.com,
David Gibson <david@gibson.dropbear.id.au>,
Paul Mackerras <paulus@samba.org>
Subject: Re: [Qemu-devel] [PATCH] memory: make ram device read/write endian sensitive
Date: Thu, 23 Feb 2017 16:58:40 +0100 [thread overview]
Message-ID: <c76578aa-ec76-f904-b0fc-72676e4ce515@redhat.com> (raw)
In-Reply-To: <CAFEAcA_BgiXrjW9aRNFkXEEjS+kjibJ_UisJtiLgrPh=0re5qA@mail.gmail.com>
On 23/02/2017 16:29, Peter Maydell wrote:
>> No, they look entirely the same. The only difference is that they go
>> through MemoryRegionOps instead of memcpy.
> Then we have a different problem, because the thing this patch
> is claiming to fix is that the memory the device is backed by
> (from vfio) is little-endian and we're not accessing it right.
>
> RAM of the usual sort is target-endian (by which I mean "when the guest
> does a write of 32-bits 0x12345678, and you look at the memory byte
> by byte then the order of bytes is either 0x12 0x34 0x56 0x78 if
> TARGET_LITTLE_ENDIAN or 0x78 0x56 0x34 0x12 if TARGET_BIG_ENDIAN").
Okay, I think I see what you mean.
MMIO regions do not expect their datum in any endianness; they just get
a uint64_t representing an 8/16/32/64-bit value. The datum undergoes a
conversion if necessary, according to target and MemoryRegionOps
endiannesses, before the callback is invoked.
In the ramd case, the ops convert between
bunch-of-bytes-stored-into-RAM-by-host and uint64_t (to uint64_t for
read, from uint64_t for write). The conversion from/to target
endianness has been done already by the memory.c core code. The ops'
task is to ensure that this bunch of bytes has the exact order that the
guest desired. There's more than one way to do it---all that's needed
is that the order used by the ops matches the one specified by the ops'
endianness, resulting in an even number of swaps.
However, DEVICE_NATIVE_ENDIAN would have to be paired with tswap, which
the current code does not do, hence the bug. To have no swap at all,
you'd need DEVICE_HOST_ENDIAN.
> AIUI what we want for this VFIO case is "when the guest does
> a 32-bit write of 0x12345678 then the bytes are 0x12 0x34 0x56 0x78
> regardless of whether TARGET_BIG_ENDIAN or not".
No, I don't think so. This is not specific to VFIO. You can do it with
any device, albeit VFIO is currently the only one using ramd regions.
Paolo
next prev parent reply other threads:[~2017-02-23 15:58 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-21 6:46 [Qemu-devel] [PATCH] memory: make ram device read/write endian sensitive Yongji Xie
2017-02-21 16:21 ` Alex Williamson
2017-02-21 16:34 ` Paolo Bonzini
2017-02-21 18:09 ` Peter Maydell
2017-02-21 18:44 ` Alex Williamson
2017-02-22 7:54 ` Yongji Xie
2017-02-22 10:53 ` Paolo Bonzini
2017-02-21 18:53 ` Paolo Bonzini
2017-02-21 19:40 ` Peter Maydell
2017-02-23 4:20 ` Alexey Kardashevskiy
2017-02-23 8:35 ` Paolo Bonzini
2017-02-23 10:02 ` Peter Maydell
2017-02-23 10:10 ` Paolo Bonzini
2017-02-23 10:23 ` Peter Maydell
2017-02-23 10:33 ` Paolo Bonzini
2017-02-23 11:34 ` Peter Maydell
2017-02-23 11:43 ` Paolo Bonzini
2017-02-23 12:26 ` Peter Maydell
2017-02-23 12:53 ` Paolo Bonzini
2017-02-23 14:35 ` Peter Maydell
2017-02-23 15:21 ` Paolo Bonzini
2017-02-23 15:29 ` Peter Maydell
2017-02-23 15:58 ` Paolo Bonzini [this message]
2017-02-23 16:08 ` Peter Maydell
2017-02-23 16:15 ` Paolo Bonzini
2017-02-23 17:14 ` Yongji Xie
2017-02-24 3:28 ` David Gibson
2017-02-23 23:36 ` Paul Mackerras
2017-02-23 15:39 ` Alex Williamson
2017-02-23 15:47 ` Paolo Bonzini
2017-02-23 16:08 ` Alex Williamson
2017-02-24 3:26 ` David Gibson
2017-02-23 11:04 ` Alexey Kardashevskiy
2017-02-27 2:25 ` Michael Roth
2017-02-27 3:25 ` Alexey Kardashevskiy
2017-02-27 4:28 ` Yongji Xie
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=c76578aa-ec76-f904-b0fc-72676e4ce515@redhat.com \
--to=pbonzini@redhat.com \
--cc=aik@ozlabs.ru \
--cc=alex.williamson@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=paulus@samba.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=xyjxie@linux.vnet.ibm.com \
--cc=zhong@linux.vnet.ibm.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;
as well as URLs for NNTP newsgroup(s).