[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH qemu v15 01/17] memory: Fix IOMMU replay base ad
From: |
David Gibson |
Subject: |
Re: [Qemu-devel] [PATCH qemu v15 01/17] memory: Fix IOMMU replay base address |
Date: |
Tue, 5 Apr 2016 11:34:36 +1000 |
User-agent: |
Mutt/1.5.24 (2015-08-30) |
On Mon, Apr 04, 2016 at 07:33:30PM +1000, Alexey Kardashevskiy wrote:
> 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 <address@hidden>
Reviewed-by: David Gibson <address@hidden>
> ---
> Changes:
> v15:
> * accounted section->offset_within_region
> * s/giommu->offset_within_address_space/giommu->iommu_offset/
> ---
> 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 fb588d8..27753d8 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->iommu_offset;
> 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->iommu_offset = section->offset_within_address_space -
> + section->offset_within_region;
> 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 eb0e1b0..c9b6622 100644
> --- a/include/hw/vfio/vfio-common.h
> +++ b/include/hw/vfio/vfio-common.h
> @@ -90,6 +90,7 @@ typedef struct VFIOContainer {
> typedef struct VFIOGuestIOMMU {
> VFIOContainer *container;
> MemoryRegion *iommu;
> + hwaddr iommu_offset;
> Notifier n;
> QLIST_ENTRY(VFIOGuestIOMMU) giommu_next;
> } VFIOGuestIOMMU;
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
signature.asc
Description: PGP signature
- [Qemu-devel] [PATCH qemu v15 00/17] spapr: vfio: Enable Dynamic DMA windows (DDW), Alexey Kardashevskiy, 2016/04/04
- [Qemu-devel] [PATCH qemu v15 01/17] memory: Fix IOMMU replay base address, Alexey Kardashevskiy, 2016/04/04
- Re: [Qemu-devel] [PATCH qemu v15 01/17] memory: Fix IOMMU replay base address,
David Gibson <=
- [Qemu-devel] [PATCH qemu v15 03/17] vfio: Check that IOMMU MR translates to system address space, Alexey Kardashevskiy, 2016/04/04
- [Qemu-devel] [PATCH qemu v15 02/17] vmstate: Define VARRAY with VMS_ALLOC, Alexey Kardashevskiy, 2016/04/04
- [Qemu-devel] [PATCH qemu v15 11/17] vfio: spapr: Add SPAPR IOMMU v2 support (DMA memory preregistering), Alexey Kardashevskiy, 2016/04/04
- [Qemu-devel] [PATCH qemu v15 09/17] spapr_pci: Reset DMA config on PHB reset, Alexey Kardashevskiy, 2016/04/04
- [Qemu-devel] [PATCH qemu v15 12/17] spapr_pci: Add and export DMA resetting helper, Alexey Kardashevskiy, 2016/04/04
- [Qemu-devel] [PATCH qemu v15 15/17] spapr_pci: Get rid of dma_loibn, Alexey Kardashevskiy, 2016/04/04