qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
	qemu-devel@nongnu.org, Alexander Graf <agraf@suse.de>,
	Blue Swirl <blauwirbel@gmail.com>,
	Alex Williamson <alex.williamson@redhat.com>,
	Anthony Liguori <anthony@codemonkey.ws>
Subject: Re: [Qemu-devel] [PATCH v2 3/7] memory: iommu support
Date: Thu, 01 Nov 2012 15:44:19 +0200	[thread overview]
Message-ID: <50927CB3.6020804@redhat.com> (raw)
In-Reply-To: <1351709961.12271.206.camel@pasglop>

On 10/31/2012 08:59 PM, Benjamin Herrenschmidt wrote:
> On Wed, 2012-10-31 at 12:32 +0200, Avi Kivity wrote:
>> This has nothing to do with device endianness; we're translating from a
>> byte buffer (address_space_rw()) to a uint64_t
>> (MemoryRegionOps::read/write()) so we need to take host endianess into
>> account.
>> 
>> This code cleverly makes use of memory core endian support to do the
>> conversion for us.  But it's probably too clever and should be replaced
>> by an explicit call to a helper.
> 
> Well, the whole idea of providing sized-type accessors (u8/u16/...) is
> very fishy for DMA. I understand it comes from the MemoryRegion ops, and
> It made somewhat sense in CPU to device (though even then endianness had
> always gotten wrong) but for DMA it's going to be a can of worms.

Endianness here has no effect on the result.  An address_space_rw()
causes a lookup of a memory region, which happens to be an iommu memory
region.  Because of the way MemoryRegionOps are done, it is converted to
a 1/2/4/8 accessor, and then converted immediately back to a byte array.
 As long as we're consistent there's no change to the data path.

However we do have a problem with non-1/2/4/8 byte writes.  Right now
any mismatched access ends up as an 8 byte write, we need an extra
accessor for arbitrary writes, or rather better use of the .impl members
of MemoryRegionOps.

> 
> Taking "host endianness" into account means nothing if you don't define
> what endianness those are expected to use to write to memory. If you add
> yet another case of "guest endianness" in the mix, then you make yet
> another mistake akin to the virtio trainwreck since things like powerpc
> or ARM can operate in different endianness.
> 
> The best thing to do is to forbid use of those functions :-) And
> basically mandate the use of endian explicit accessor that specifically
> indicate what endianness the value should have once written in target
> memory. The most sensible expectation when using the "raw" Memory ops is
> to have the value go "as is" ie in host endianness.
-- 
error compiling committee.c: too many arguments to function

  reply	other threads:[~2012-11-01 13:44 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-30 11:47 [Qemu-devel] [PATCH v2 0/7] IOMMU support Avi Kivity
2012-10-30 11:47 ` [Qemu-devel] [PATCH v2 1/7] memory: fix address space initialization/destruction Avi Kivity
2012-10-30 11:47 ` [Qemu-devel] [PATCH v2 2/7] memory: limit sections in the radix tree to the actual address space size Avi Kivity
2012-10-30 11:47 ` [Qemu-devel] [PATCH v2 3/7] memory: iommu support Avi Kivity
2012-10-30 19:11   ` Blue Swirl
2012-10-30 20:03     ` Benjamin Herrenschmidt
2012-10-30 21:13       ` Blue Swirl
2012-10-31 10:32     ` Avi Kivity
2012-10-31 18:59       ` Benjamin Herrenschmidt
2012-11-01 13:44         ` Avi Kivity [this message]
2012-11-01 13:45           ` Avi Kivity
2012-10-30 11:47 ` [Qemu-devel] [PATCH v2 4/7] memory: provide a MemoryRegion for IOMMUs to log faults Avi Kivity
2012-10-30 19:14   ` Blue Swirl
2012-10-31 10:33     ` Avi Kivity
2012-10-30 11:47 ` [Qemu-devel] [PATCH v2 5/7] pci: use memory core for iommu support Avi Kivity
2012-10-30 11:47 ` [Qemu-devel] [PATCH v2 6/7] vfio: abort if an emulated iommu is used Avi Kivity
2012-10-30 11:47 ` [Qemu-devel] [PATCH v2 7/7] i440fx: add an iommu Avi Kivity
2012-10-30 19:18   ` Blue Swirl
2012-10-31 10:34     ` Avi Kivity

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=50927CB3.6020804@redhat.com \
    --to=avi@redhat.com \
    --cc=agraf@suse.de \
    --cc=alex.williamson@redhat.com \
    --cc=anthony@codemonkey.ws \
    --cc=benh@kernel.crashing.org \
    --cc=blauwirbel@gmail.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.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).