qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paul Brook <paul@codesourcery.com>
To: Anthony Liguori <anthony@codemonkey.ws>
Cc: Joerg Roedel <joro@8bytes.org>,
	Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>,
	qemu-devel@nongnu.org, kvm@vger.kernel.org, avi@redhat.com
Subject: Re: [Qemu-devel] Re: [RFC PATCH 4/7] ide: IOMMU support
Date: Thu, 15 Jul 2010 15:02:43 +0100	[thread overview]
Message-ID: <201007151502.43767.paul@codesourcery.com> (raw)
In-Reply-To: <4C3F0242.90005@codemonkey.ws>

> >>> Depending how the we decide to handle IOMMU invalidation, it may also
> >>> be necessary to augment the memory_map API to allow the system to
> >>> request a mapping be revoked.  However this issue is not specific to
> >>> the IOMMU implementation. Such bugs are already present on any system
> >>> that allows dynamic reconfiguration of the address space, e.g. by
> >>> changing PCI BARs.
> >> 
> >> That's why the memory_map API today does not allow mappings to persist
> >> after trips back to the main loop.
> > 
> > Sure it does.  If you can't combine zero-copy memory access with
> > asynchronous IO then IMO it's fairly useless. See e.g. dma-helpers.c
> 
> DMA's a very special case.  

Special compared to what?  The whole purpose of this API is to provide DMA.

> DMA is performed asynchronously to the
> execution of the CPU so you generally can't make any guarantees about
> what state the transaction is in until it's completed.  That gives us a
> fair bit of wiggle room when dealing with a DMA operation to a region of
> physical memory where the physical memory mapping is altered in some way
> during the transaction.

You do have ordering constraints though. While it may not be possible to 
directly determine whether the DMA completed before or after the remapping, 
and you might not be able to make any assumptions about the atomicity of the 
transaction as a whole, it is reasonable to assume that any writes to the old 
mapping will occur before the remapping operation completes.

While things like store buffers potentially allows reordering and deferral of 
accesses, there are generally fairly tight constraints on this. For example a 
PCI hast bridge may buffer CPU writes. However it will guarantee that those 
writes have been flushed out before a subsequent read operation completes.

Consider the case where the hypervisor allows passthough of a device, using 
the IOMMU to support DMA from that device into virtual machine RAM. When that 
virtual machine is destroyed the IOMMU mapping for that device will be 
invalidated. Once the invalidation has completed that RAM can be reused by the 
hypervisor for other purposes. This may happen before the device is reset.  We 
probably don't really care what happens to the device in this case, but we do 
need to prevent the device stomping on ram it no longer owns.

There are two ways this can be handled:

If your address translation mechanism allows updates to be deferred 
indefinitely then we can stall until all relevant DMA transactions have 
completed.  This is probably sufficient for well behaved guests, but 
potentially opens up a significant window for DoS attacks. 

If you need the remapping to occur in a finite timeframe (in the PCI BAR case 
this is probably before the next CPU access to that bus) then you need some 
mechanism for revoking the host mapping provided by cpu_physical_memory_map.

Note that a QEMU DMA transaction typically encompasses a whole block of data. 
The transaction is started when the AIO request is issued, and remains live 
until the transfer completes. This includes the time taken to fetch the data 
from external media/devices.

On real hardware a DMA transaction typically only covers a single burst memory 
write (maybe 16 bytes). This will generally not start until the device has 
buffered sufficient data to satisfy the burst (or has sufficient buffer space 
to receive the whole burst).

Paul

  reply	other threads:[~2010-07-15 14:02 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-14  5:45 [Qemu-devel] [RFC PATCH 0/7] AMD IOMMU emulation patchset Eduard - Gabriel Munteanu
2010-07-14  5:45 ` [Qemu-devel] [RFC PATCH 1/7] Generic IOMMU layer Eduard - Gabriel Munteanu
2010-07-14  6:07   ` malc
2010-07-14 22:47     ` Eduard - Gabriel Munteanu
2010-07-14  5:45 ` [Qemu-devel] [RFC PATCH 2/7] AMD IOMMU emulation Eduard - Gabriel Munteanu
2010-07-14 20:16   ` Paul Brook
2010-07-14  5:45 ` [Qemu-devel] [RFC PATCH 3/7] pci: call IOMMU hooks Eduard - Gabriel Munteanu
2010-07-14  7:37   ` Isaku Yamahata
2010-07-14 22:50     ` Eduard - Gabriel Munteanu
2010-07-14  5:45 ` [Qemu-devel] [RFC PATCH 4/7] ide: IOMMU support Eduard - Gabriel Munteanu
2010-07-14 13:53   ` [Qemu-devel] " Paul Brook
2010-07-14 18:33     ` Joerg Roedel
2010-07-14 20:13       ` Paul Brook
2010-07-14 21:29         ` Anthony Liguori
2010-07-14 22:24           ` Chris Wright
2010-07-15 10:28             ` Paul Brook
2010-07-15 16:52               ` Chris Wright
2010-07-15 17:02                 ` Avi Kivity
2010-07-15 17:17                   ` Chris Wright
2010-07-15 17:22                     ` Avi Kivity
2010-07-15 17:25                       ` Chris Wright
2010-07-15 17:27                     ` Eduard - Gabriel Munteanu
2010-07-15 17:22                   ` Joerg Roedel
2010-07-15 17:14                 ` Chris Wright
2010-07-15  9:10           ` Joerg Roedel
2010-07-15 12:45             ` Anthony Liguori
2010-07-15 14:45               ` Joerg Roedel
2010-07-15 16:45               ` Eduard - Gabriel Munteanu
2010-07-15 17:42                 ` Anthony Liguori
2010-07-15 10:33           ` Paul Brook
2010-07-15 12:42             ` Anthony Liguori
2010-07-15 14:02               ` Paul Brook [this message]
2010-07-14 23:39         ` Eduard - Gabriel Munteanu
2010-07-15  9:22         ` Joerg Roedel
2010-07-15 10:49           ` Paul Brook
2010-07-15 14:59             ` Joerg Roedel
2010-07-14 23:11     ` Eduard - Gabriel Munteanu
2010-07-15 10:58       ` Paul Brook
2010-07-14  5:45 ` [Qemu-devel] [RFC PATCH 5/7] rtl8139: " Eduard - Gabriel Munteanu
2010-07-14  5:45 ` [Qemu-devel] [RFC PATCH 6/7] eepro100: " Eduard - Gabriel Munteanu
2010-07-14  5:45 ` [Qemu-devel] [RFC PATCH 7/7] ac97: " Eduard - Gabriel Munteanu
2010-07-14  6:09   ` malc

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=201007151502.43767.paul@codesourcery.com \
    --to=paul@codesourcery.com \
    --cc=anthony@codemonkey.ws \
    --cc=avi@redhat.com \
    --cc=eduard.munteanu@linux360.ro \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --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).