public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Scott Wood <scottwood@freescale.com>
To: Alexander Graf <agraf@suse.de>
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Christoffer Dall <christoffer.dall@linaro.org>,
	kvm-devel <kvm@vger.kernel.org>,
	kvm-ppc <kvm-ppc@vger.kernel.org>,
	"kvmarm@lists.cs.columbia.edu" <kvmarm@lists.cs.columbia.edu>,
	Patch Tracking <patches@linaro.org>,
	"Marc Zyngier" <marc.zyngier@arm.com>
Subject: Re: [PATCH v2] KVM: Specify byte order for KVM_EXIT_MMIO
Date: Mon, 27 Jan 2014 19:59:41 -0600	[thread overview]
Message-ID: <1390874381.24905.799.camel@snotra.buserror.net> (raw)
In-Reply-To: <86A0FDA4-97AB-43EA-8306-17A1D0A94D14@suse.de>

On Sat, 2014-01-25 at 03:15 +0100, Alexander Graf wrote:
> Ok, let's go through the combinations for a 32-bit write of 0x01020304 on PPC and what data[] looks like
> 
> your proposal:
> 
>   BE guest, BE host: { 0x01, 0x02, 0x03, 0x04 }
>   LE guest, BE host: { 0x04, 0x03, 0x02, 0x01 }
>   BE guest, LE host:  { 0x01, 0x02, 0x03, 0x04 }
>   LE guest, LE host:  { 0x04, 0x03, 0x02, 0x01 }
> 
> -> ldw_p() will give us the correct value to work with

Do you mean ldl_p(), which just does a memcpy()?  How is that different
from *(uint32_t*)data, other than complying with C99 aliasing rules?

What you get from doing ldl_p() is the value as interpreted by the host
endianness.  If the memory region endianness is different from the host
endianness, you need to swap.  adjust_endianness() sort of does this,
but it's using TARGET_WORDS_BIGENDIAN instead of the host endianness
which will break if they are not the same.  It works for TCG because it
passes the MMIO value in target endianness rather than host --
effectively the TARGET_WORDS_BIGENDIAN usages in memory.c and
include/exec/softmmu_template.h cancel each other.

> current proposal:
> 
>   BE guest, BE host: { 0x01, 0x02, 0x03, 0x04 }
>   LE guest, BE host: { 0x04, 0x03, 0x02, 0x01 }
>   BE guest, LE host:  { 0x04, 0x03, 0x02, 0x01 }
>   LE guest, LE host:  { 0x01, 0x02, 0x03, 0x04 }
> 
> -> *(uint32_t*)data will give us the correct value to work with

*(uint32_t*)data in the "LE guest, LE host" case will get you 0x04030201
-- how is that the correct value to work with?  Did you make this table
with the assumption that big-endian interpretation is inherently "the
correct value" on PPC?

> There are pros and cons for both approaches.
> 
> Pro approach 1 is that it fits the way data[] is read today, so no QEMU
> changes are required. However, it means that user space needs to have
> awareness of the "default endianness".

Normally the endianness is well specified by the particular device/bus
(PCI is little-endian, e500 CCSR is big-endian, etc).

I suppose you could define one endianness as "natural" for a particular
platform, and the other as swapped, but I don't think that's a useful
way to look at it except for things like virtio that are defined as
being native-endian (and I don't think KVM_EXIT_MMIO is the right layer
to try to sort that problem out, as it just introduces confusion for
non-virtio MMIO).

Unfortunately, that appears to currently be how QEMU works, so either
QEMU needs to be fixed in a way that is compatible with currently
working scenarios (e.g. by changing adjust_endianness() to use host
endianness and changing the TCG path to match), or it needs to be
explicitly defined in the API what assumptions are being made regarding
the default endianness on each architecture.  I believe these
assumptions are present but implicit in the current proposal (if Alex's
intepretation of it matches what was intended).

> With approach 2 you don't care about endianness at all anymore - you
> just get a payload that the host process can read in.

You always need to care about endianness -- something has to result in
PCI registers appearing swapped compared to e500 CCSR registers.

-Scott

  parent reply	other threads:[~2014-01-28  1:59 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-24 23:39 [PATCH v2] KVM: Specify byte order for KVM_EXIT_MMIO Christoffer Dall
2014-01-24 23:51 ` Scott Wood
2014-01-25  0:05   ` Victor Kamensky
2014-01-25  0:24   ` Peter Maydell
2014-01-25  1:56     ` Christoffer Dall
2014-01-25  2:04       ` Scott Wood
2014-01-25  2:16         ` Alexander Graf
2014-01-25  1:58     ` Scott Wood
2014-01-25  2:15       ` Alexander Graf
2014-01-25  2:34         ` Christoffer Dall
2014-01-25  9:13           ` Alexander Graf
2014-01-25  2:37         ` Victor Kamensky
2014-01-25  9:20           ` Alexander Graf
2014-01-25 15:36             ` Victor Kamensky
2014-01-25 16:12               ` Alexander Graf
2014-01-25 16:23         ` Peter Maydell
2014-01-25 18:31           ` Christoffer Dall
2014-01-26  3:46             ` Victor Kamensky
2014-01-26  5:43               ` Victor Kamensky
2014-01-27  7:52                 ` Alexander Graf
2014-01-27  9:42                   ` Peter Maydell
2014-01-27  7:41               ` Alexander Graf
2014-01-28  1:59         ` Scott Wood [this message]
2014-01-28  8:55           ` Peter Maydell

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=1390874381.24905.799.camel@snotra.buserror.net \
    --to=scottwood@freescale.com \
    --cc=agraf@suse.de \
    --cc=christoffer.dall@linaro.org \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=marc.zyngier@arm.com \
    --cc=patches@linaro.org \
    --cc=peter.maydell@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