From: Alexey Kardashevskiy <aik@ozlabs.ru>
To: qemu-devel@nongnu.org
Cc: Alexey Kardashevskiy <aik@ozlabs.ru>,
Alex Williamson <alex.williamson@redhat.com>,
qemu-ppc@nongnu.org
Subject: [Qemu-devel] [PATCH qemu v13 01/16] memory: Fix IOMMU replay base address
Date: Tue, 1 Mar 2016 20:10:26 +1100 [thread overview]
Message-ID: <1456823441-46757-2-git-send-email-aik@ozlabs.ru> (raw)
In-Reply-To: <1456823441-46757-1-git-send-email-aik@ozlabs.ru>
Since a788f227 "memory: Allow replay of IOMMU mapping notifications"
when new VFIO listener is added, all existing IOMMU mappings are
replayed. However there is a problem that the base address of
an IOMMU memory region (IOMMU MR) is ignored which is not a problem
for the existing user (which is pseries) with its default 32bit DMA
window starting at 0 but it is if there is another DMA window.
This stores the IOMMU's offset_within_address_space and adjusts
the IOVA before calling vfio_dma_map/vfio_dma_unmap.
As the IOMMU notifier expects IOVA offset rather than the absolute
address, this also adjusts IOVA in sPAPR H_PUT_TCE handler before
calling notifier(s).
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---
hw/ppc/spapr_iommu.c | 2 +-
hw/vfio/common.c | 14 ++++++++------
include/hw/vfio/vfio-common.h | 1 +
3 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c
index 7dd4588..277f289 100644
--- a/hw/ppc/spapr_iommu.c
+++ b/hw/ppc/spapr_iommu.c
@@ -277,7 +277,7 @@ static target_ulong put_tce_emu(sPAPRTCETable *tcet, target_ulong ioba,
tcet->table[index] = tce;
entry.target_as = &address_space_memory,
- entry.iova = ioba & page_mask;
+ entry.iova = (ioba - tcet->bus_offset) & page_mask;
entry.translated_addr = tce & page_mask;
entry.addr_mask = ~page_mask;
entry.perm = spapr_tce_iommu_access_flags(tce);
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 55e87d3..9bf4c3b 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -257,14 +257,14 @@ static void vfio_iommu_map_notify(Notifier *n, void *data)
VFIOGuestIOMMU *giommu = container_of(n, VFIOGuestIOMMU, n);
VFIOContainer *container = giommu->container;
IOMMUTLBEntry *iotlb = data;
+ hwaddr iova = iotlb->iova + giommu->offset_within_address_space;
MemoryRegion *mr;
hwaddr xlat;
hwaddr len = iotlb->addr_mask + 1;
void *vaddr;
int ret;
- trace_vfio_iommu_map_notify(iotlb->iova,
- iotlb->iova + iotlb->addr_mask);
+ trace_vfio_iommu_map_notify(iova, iova + iotlb->addr_mask);
/*
* The IOMMU TLB entry we have just covers translation through
@@ -291,21 +291,21 @@ static void vfio_iommu_map_notify(Notifier *n, void *data)
if ((iotlb->perm & IOMMU_RW) != IOMMU_NONE) {
vaddr = memory_region_get_ram_ptr(mr) + xlat;
- ret = vfio_dma_map(container, iotlb->iova,
+ ret = vfio_dma_map(container, iova,
iotlb->addr_mask + 1, vaddr,
!(iotlb->perm & IOMMU_WO) || mr->readonly);
if (ret) {
error_report("vfio_dma_map(%p, 0x%"HWADDR_PRIx", "
"0x%"HWADDR_PRIx", %p) = %d (%m)",
- container, iotlb->iova,
+ container, iova,
iotlb->addr_mask + 1, vaddr, ret);
}
} else {
- ret = vfio_dma_unmap(container, iotlb->iova, iotlb->addr_mask + 1);
+ ret = vfio_dma_unmap(container, iova, iotlb->addr_mask + 1);
if (ret) {
error_report("vfio_dma_unmap(%p, 0x%"HWADDR_PRIx", "
"0x%"HWADDR_PRIx") = %d (%m)",
- container, iotlb->iova,
+ container, iova,
iotlb->addr_mask + 1, ret);
}
}
@@ -377,6 +377,8 @@ static void vfio_listener_region_add(MemoryListener *listener,
*/
giommu = g_malloc0(sizeof(*giommu));
giommu->iommu = section->mr;
+ giommu->offset_within_address_space =
+ section->offset_within_address_space;
giommu->container = container;
giommu->n.notify = vfio_iommu_map_notify;
QLIST_INSERT_HEAD(&container->giommu_list, giommu, giommu_next);
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index f037f3c..9ffa681 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -80,6 +80,7 @@ typedef struct VFIOContainer {
typedef struct VFIOGuestIOMMU {
VFIOContainer *container;
MemoryRegion *iommu;
+ hwaddr offset_within_address_space;
Notifier n;
QLIST_ENTRY(VFIOGuestIOMMU) giommu_next;
} VFIOGuestIOMMU;
--
2.5.0.rc3
next prev parent reply other threads:[~2016-03-01 9:12 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-01 9:10 [Qemu-devel] [PATCH qemu v13 00/16] spapr: vfio: Enable Dynamic DMA windows (DDW) Alexey Kardashevskiy
2016-03-01 9:10 ` Alexey Kardashevskiy [this message]
2016-03-03 1:34 ` [Qemu-devel] [Qemu-ppc] [PATCH qemu v13 01/16] memory: Fix IOMMU replay base address David Gibson
2016-03-01 9:10 ` [Qemu-devel] [PATCH qemu v13 02/16] spapr_pci: Move DMA window enablement to a helper Alexey Kardashevskiy
2016-03-03 1:40 ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-03-10 5:47 ` Alexey Kardashevskiy
2016-03-15 5:30 ` David Gibson
2016-03-01 9:10 ` [Qemu-devel] [PATCH qemu v13 03/16] spapr_iommu: Move table allocation to helpers Alexey Kardashevskiy
2016-03-01 9:10 ` [Qemu-devel] [PATCH qemu v13 04/16] spapr_iommu: Introduce "enabled" state for TCE table Alexey Kardashevskiy
2016-03-03 3:00 ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-03-10 7:39 ` Alexey Kardashevskiy
2016-03-15 5:32 ` David Gibson
2016-03-01 9:10 ` [Qemu-devel] [PATCH qemu v13 05/16] spapr_iommu: Add root memory region Alexey Kardashevskiy
2016-03-04 4:08 ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-03-01 9:10 ` [Qemu-devel] [PATCH qemu v13 06/16] spapr_pci: Reset DMA config on PHB reset Alexey Kardashevskiy
2016-03-03 3:02 ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-03-01 9:10 ` [Qemu-devel] [PATCH qemu v13 07/16] vfio, memory: Notify IOMMU about starting/stopping being used by VFIO Alexey Kardashevskiy
2016-03-03 5:28 ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-03-03 6:01 ` Alexey Kardashevskiy
2016-03-04 4:01 ` David Gibson
2016-03-01 9:10 ` [Qemu-devel] [PATCH qemu v13 08/16] memory: Add reporting of supported page sizes Alexey Kardashevskiy
2016-03-03 5:33 ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-03-01 9:10 ` [Qemu-devel] [PATCH qemu v13 09/16] vfio: Generalize IOMMU memory listener Alexey Kardashevskiy
2016-03-03 5:36 ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-03-03 6:07 ` Alexey Kardashevskiy
2016-03-04 3:44 ` David Gibson
2016-03-01 9:10 ` [Qemu-devel] [PATCH qemu v13 10/16] vfio: Use different page size for different IOMMU types Alexey Kardashevskiy
2016-03-03 6:08 ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-03-01 9:10 ` [Qemu-devel] [PATCH qemu v13 11/16] vfio: spapr: Add SPAPR IOMMU v2 support (DMA memory preregistering) Alexey Kardashevskiy
2016-03-03 6:30 ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-03-15 2:53 ` Alexey Kardashevskiy
2016-03-15 5:42 ` David Gibson
2016-03-17 5:04 ` Alexey Kardashevskiy
2016-03-17 6:10 ` David Gibson
2016-03-17 9:23 ` Alexey Kardashevskiy
2016-03-21 4:53 ` David Gibson
2016-03-21 6:08 ` Alexey Kardashevskiy
2016-03-01 9:10 ` [Qemu-devel] [PATCH qemu v13 12/16] vmstate: Define VARRAY with VMS_ALLOC Alexey Kardashevskiy
2016-03-03 6:31 ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-03-01 9:10 ` [Qemu-devel] [PATCH qemu v13 13/16] spapr_iommu: Remove need_vfio flag from sPAPRTCETable Alexey Kardashevskiy
2016-03-03 6:38 ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-03-01 9:10 ` [Qemu-devel] [PATCH qemu v13 14/16] spapr_pci: Add and export DMA resetting helper Alexey Kardashevskiy
2016-03-03 6:39 ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-03-01 9:10 ` [Qemu-devel] [PATCH qemu v13 15/16] vfio: Move iova_pgsizes from container to guest IOMMU Alexey Kardashevskiy
2016-03-03 11:22 ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-03-04 0:02 ` Alexey Kardashevskiy
2016-03-01 9:10 ` [Qemu-devel] [PATCH qemu v13 16/16] spapr_pci/spapr_pci_vfio: Support Dynamic DMA Windows (DDW) Alexey Kardashevskiy
2016-03-04 4:51 ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-03-11 9:03 ` Alexey Kardashevskiy
2016-03-15 5:53 ` David Gibson
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=1456823441-46757-2-git-send-email-aik@ozlabs.ru \
--to=aik@ozlabs.ru \
--cc=alex.williamson@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@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).