qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Avi Kivity <avi@cloudius-systems.com>
To: Peter Maydell <peter.maydell@linaro.org>,
	Victor Kamensky <victor.kamensky@linaro.org>
Cc: Thomas Falcon <tlfalcon@linux.vnet.ibm.com>,
	kvm-devel <kvm@vger.kernel.org>,
	QEMU Developers <qemu-devel@nongnu.org>,
	"qemu-ppc@nongnu.org" <qemu-ppc@nongnu.org>,
	"kvmarm@lists.cs.columbia.edu" <kvmarm@lists.cs.columbia.edu>,
	Christoffer Dall <christoffer.dall@linaro.org>
Subject: Re: [Qemu-devel] KVM and variable-endianness guest CPUs
Date: Tue, 28 Jan 2014 11:04:54 +0200	[thread overview]
Message-ID: <52E772B6.1090202@cloudius-systems.com> (raw)
In-Reply-To: <CAFEAcA-Mn=Q_KpRYZpFoVAXAnMu8OR_c6rXRCMwjda0kDk7gvg@mail.gmail.com>

On 01/22/2014 12:22 PM, Peter Maydell wrote:
> On 22 January 2014 05:39, Victor Kamensky <victor.kamensky@linaro.org> wrote:
>> Hi Guys,
>>
>> Christoffer and I had a bit heated chat :) on this
>> subject last night. Christoffer, really appreciate
>> your time! We did not really reach agreement
>> during the chat and Christoffer asked me to follow
>> up on this thread.
>> Here it goes. Sorry, it is very long email.
>>
>> I don't believe we can assign any endianity to
>> mmio.data[] byte array. I believe mmio.data[] and
>> mmio.len acts just memcpy and that is all. As
>> memcpy does not imply any endianity of underlying
>> data mmio.data[] should not either.
> This email is about five times too long to be actually
> useful, but the major issue here is that the data being
> transferred is not just a bag of bytes. The data[]
> array plus the size field are being (mis)used to indicate
> that the memory transaction is one of:
>   * an 8 bit access
>   * a 16 bit access of some uint16_t value
>   * a 32 bit access of some uint32_t value
>   * a 64 bit access of some uint64_t value
>
> exactly as a CPU hardware bus would do. It's
> because the API is defined in this awkward way with
> a uint8_t[] array that we need to specify how both
> sides should go from the actual properties of the
> memory transaction (value and size) to filling in the
> array.

That is not how x86 hardware works.  Back when there was a bus, there 
were no address lines A0-A2; instead we had 8 byte enables BE0-BE7.  A 
memory transaction placed the qword address on the address lines and 
asserted the byte enables for the appropriate byte, word, dword, or 
qword, shifted for the low order bits of the address.

If you generated an unaligned access, the transaction was split into 
two, so an 8-byte write might appear as a 5-byte write followed by a 
3-byte write.  In fact, the two halves of the transaction might go to 
different devices, or one might go to a device and another to memory.

PCI works the same way.



>
> Furthermore, device endianness is entirely irrelevant
> for deciding the properties of mmio.data[], because the
> thing we're modelling here is essentially the CPU->bus
> interface. In real hardware, the properties of individual
> devices on the bus are irrelevant to how the CPU's
> interface to the bus behaves, and similarly here the
> properties of emulated devices don't affect how KVM's
> interface to QEMU userspace needs to work.
>
> MemoryRegion's 'endianness' field, incidentally, is
> a dreadful mess that we should get rid of. It is attempting
> to model the property that some buses/bridges have of
> doing byte-lane-swaps on data that passes through as
> a property of the device itself. It would be better if we
> modelled it properly, with container regions having possible
> byte-swapping and devices just being devices.
>

No, that is not what it is modelling.

Suppose a little endian cpu writes a dword 0x12345678 to address 0 of a 
device, and read back a byte from address 0.  What value do you read back?

Some (most) devices will return 0x78, others will return 0x12. Other 
devices don't support mixed sizes at all, but many do.  PCI 
configuration space is an example; it is common to read both Device ID 
and Vendor ID with a single 32-bit transaction, but you can also read 
them separately with two 16-bit transaction.  Because PCI is 
little-endian, the Vendor ID at address 0 will be returned as the low 
word of the 32-bit read of a little-endian processor.

If you remove device endianness from memory regions, you have to pass 
the data as arrays of bytes (like the KVM interface) and let the device 
assemble words from those bytes itself, taking into consideration its 
own endianness.  What MemoryRegion's endianness does is let the device 
declare its endianness to the API and let it do all the work.

      parent reply	other threads:[~2014-01-28  9:05 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-17 17:53 [Qemu-devel] KVM and variable-endianness guest CPUs Peter Maydell
2014-01-17 18:52 ` Peter Maydell
2014-01-18  4:24   ` Christoffer Dall
2014-01-18  7:32     ` Alexander Graf
2014-01-18 10:15       ` Peter Maydell
2014-01-20 14:20         ` Alexander Graf
2014-01-20 14:31           ` Peter Maydell
2014-01-20 14:22   ` Alexander Graf
2014-01-20 19:19     ` Christoffer Dall
2014-01-22  5:39       ` Victor Kamensky
2014-01-22  6:31         ` Anup Patel
2014-01-22  6:41           ` [Qemu-devel] [Qemu-ppc] " Alexander Graf
2014-01-22  7:26             ` Victor Kamensky
2014-01-22 10:52               ` Alexander Graf
2014-01-23  4:25                 ` Victor Kamensky
2014-01-23 10:32                   ` Alexander Graf
2014-01-23 10:56                   ` Greg Kurz
2014-01-22  8:57             ` Anup Patel
2014-01-23 23:28               ` Christoffer Dall
2014-01-22 10:22         ` [Qemu-devel] " Peter Maydell
2014-01-22 17:19           ` Victor Kamensky
2014-01-22 17:29             ` Peter Maydell
2014-01-22 19:29               ` Victor Kamensky
2014-01-22 20:02                 ` Peter Maydell
2014-01-22 22:47                   ` Victor Kamensky
2014-01-22 23:18                     ` Peter Maydell
2014-01-23  0:22                       ` Victor Kamensky
2014-01-23 10:23                         ` Peter Maydell
2014-01-23 15:06                           ` Victor Kamensky
2014-01-23 15:33                             ` Peter Maydell
2014-01-23 16:25                               ` Victor Kamensky
2014-01-23 20:45                                 ` Christoffer Dall
2014-01-24  0:50                                   ` Victor Kamensky
2014-01-24  2:14                                     ` Christoffer Dall
2014-01-24  4:11                                       ` Victor Kamensky
2014-01-28  0:32                                         ` [Qemu-devel] [Qemu-ppc] " Benjamin Herrenschmidt
2014-01-28  0:40                                           ` Christoffer Dall
2014-01-28  0:15                                   ` Benjamin Herrenschmidt
2014-01-24  0:09                                 ` [Qemu-devel] " Victor Kamensky
2014-01-28  0:07                               ` [Qemu-devel] [Qemu-ppc] " Benjamin Herrenschmidt
2014-01-28  0:07                                 ` Benjamin Herrenschmidt
2014-01-27 23:34                   ` Benjamin Herrenschmidt
2014-01-27 23:49                     ` Peter Maydell
2014-01-28  0:36                       ` Benjamin Herrenschmidt
2014-01-28  0:44                         ` Christoffer Dall
2014-01-28  4:47                           ` Benjamin Herrenschmidt
2014-01-28 16:31                             ` Christoffer Dall
2014-01-27 23:31                 ` Benjamin Herrenschmidt
2014-01-27 23:27               ` Benjamin Herrenschmidt
2014-01-28  9:16                 ` Avi Kivity
2014-01-28  9:04           ` Avi Kivity [this message]

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=52E772B6.1090202@cloudius-systems.com \
    --to=avi@cloudius-systems.com \
    --cc=christoffer.dall@linaro.org \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=tlfalcon@linux.vnet.ibm.com \
    --cc=victor.kamensky@linaro.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;
as well as URLs for NNTP newsgroup(s).