From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:35367) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSLKN-0006Gt-LJ for qemu-devel@nongnu.org; Thu, 10 May 2012 00:50:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SSLKK-00021z-9p for qemu-devel@nongnu.org; Thu, 10 May 2012 00:50:11 -0400 Received: from gate.crashing.org ([63.228.1.57]:49662) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSLKK-00020q-20 for qemu-devel@nongnu.org; Thu, 10 May 2012 00:50:08 -0400 From: Benjamin Herrenschmidt Date: Thu, 10 May 2012 14:49:07 +1000 Message-Id: <1336625347-10169-14-git-send-email-benh@kernel.crashing.org> In-Reply-To: <1336625347-10169-1-git-send-email-benh@kernel.crashing.org> References: <1336625347-10169-1-git-send-email-benh@kernel.crashing.org> Subject: [Qemu-devel] [PATCH 13/13] iommu: Add a memory barrier to DMA RW function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: David Gibson From: David Gibson The emulated devices can run simultaneously with the guest, so we need to be careful with ordering of load and stores done by them to the guest system memory, which need to be observed in the right order by the guest operating system. The simplest way for now to address that is to stick a memory barrier in the main DMA read/write function of the iommu layer, this will make everything using that layer hopefully "just work". We don't emulate devices supporting the relaxed ordering PCIe feature nor do we want to look at doing more fine grained barriers for now as it could quickly become too complex and not worth the cost. Note that this will not help devices using the map/unmap APIs, those will need to use explicit barriers, similar to what virtio does. Signed-off-by: David Gibson Signed-off-by: Benjamin Herrenschmidt --- dma-helpers.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dma-helpers.c b/dma-helpers.c index 36fa963..4350cdf 100644 --- a/dma-helpers.c +++ b/dma-helpers.c @@ -312,6 +312,9 @@ int iommu_dma_memory_rw(DMAContext *dma, dma_addr_t addr, buf += plen; } + /* HACK: full memory barrier here */ + __sync_synchronize(); + return 0; } -- 1.7.9.5