Received: from eggs.gnu.org ([2001:4830:134:3::10]:55769) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5kRX-0001GN-9X for qemu-devel@nongnu.org; Wed, 25 May 2016 21:50:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b5kRS-00053Z-VD for qemu-devel@nongnu.org; Wed, 25 May 2016 21:50:34 -0400 Date: Thu, 26 May 2016 11:50:20 +1000 From: David Gibson Message-ID: <20160526015020.GV17226@voom.fritz.box> References: <1462344751-28281-1-git-send-email-aik@ozlabs.ru> <1462344751-28281-4-git-send-email-aik@ozlabs.ru> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="BlkQeOBdElZ1aiuH" Content-Disposition: inline In-Reply-To: <1462344751-28281-4-git-send-email-aik@ozlabs.ru> Subject: Re: [Qemu-devel] [PATCH qemu v16 03/19] memory: Fix IOMMU replay base address List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alexey Kardashevskiy Cc: qemu-devel@nongnu.org, qemu-ppc@nongnu.org, Alexander Graf , Alex Williamson , Paolo Bonzini --BlkQeOBdElZ1aiuH Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, May 04, 2016 at 04:52:15PM +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. >=20 > This stores the IOMMU's offset_within_address_space and adjusts > the IOVA before calling vfio_dma_map/vfio_dma_unmap. >=20 > 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). >=20 > Signed-off-by: Alexey Kardashevskiy > Reviewed-by: David Gibson Alex, this is a real fix independent of the other stuff. Can we apply it ASAP. > --- > 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(-) >=20 > 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] =3D tce; > =20 > entry.target_as =3D &address_space_memory, > - entry.iova =3D ioba & page_mask; > + entry.iova =3D (ioba - tcet->bus_offset) & page_mask; > entry.translated_addr =3D tce & page_mask; > entry.addr_mask =3D ~page_mask; > entry.perm =3D spapr_tce_iommu_access_flags(tce); > diff --git a/hw/vfio/common.c b/hw/vfio/common.c > index 0b40262..f32cc49 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 =3D container_of(n, VFIOGuestIOMMU, n); > VFIOContainer *container =3D giommu->container; > IOMMUTLBEntry *iotlb =3D data; > + hwaddr iova =3D iotlb->iova + giommu->iommu_offset; > MemoryRegion *mr; > hwaddr xlat; > hwaddr len =3D iotlb->addr_mask + 1; > void *vaddr; > int ret; > =20 > - trace_vfio_iommu_map_notify(iotlb->iova, > - iotlb->iova + iotlb->addr_mask); > + trace_vfio_iommu_map_notify(iova, iova + iotlb->addr_mask); > =20 > /* > * The IOMMU TLB entry we have just covers translation through > @@ -291,21 +291,21 @@ static void vfio_iommu_map_notify(Notifier *n, void= *data) > =20 > if ((iotlb->perm & IOMMU_RW) !=3D IOMMU_NONE) { > vaddr =3D memory_region_get_ram_ptr(mr) + xlat; > - ret =3D vfio_dma_map(container, iotlb->iova, > + ret =3D 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) =3D %d (%m)", > - container, iotlb->iova, > + container, iova, > iotlb->addr_mask + 1, vaddr, ret); > } > } else { > - ret =3D vfio_dma_unmap(container, iotlb->iova, iotlb->addr_mask = + 1); > + ret =3D vfio_dma_unmap(container, iova, iotlb->addr_mask + 1); > if (ret) { > error_report("vfio_dma_unmap(%p, 0x%"HWADDR_PRIx", " > "0x%"HWADDR_PRIx") =3D %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 =3D g_malloc0(sizeof(*giommu)); > giommu->iommu =3D section->mr; > + giommu->iommu_offset =3D section->offset_within_address_space - > + section->offset_within_region; > giommu->container =3D container; > giommu->n.notify =3D 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; --=20 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 --BlkQeOBdElZ1aiuH Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJXRlZcAAoJEGw4ysog2bOSOpIP/1XKFQdFYu2L6opiJ/pZTkDV 95BvLNmOHbk+4fjAkWQy/4pzEnvJYvILNJYtMULeYOqB4V8oWIhgWB12Oeb3IrQn XMRsRKw7QcFkvmjvFN4cLRWrxVN9vhb+6N+nycMLqSyouOL5tj+yemz0sU3Zi/WF oF0XN8dnalzPPcmR3whBN1A2qT/4cNn99k1Nha11nwH/vsr9K0PJUeOLsSVa+X3Q 8RjbNf/DaCsVaTcYAOWrbycmAlDQv+H0gYKPFcq0e5dd6iFT8Q48leDfFHoGy3GC BnRDyVJK6RvePLi9GzF3wzA2c9aEKRDdfN9DOy+u2OQIPMqOx+GAX1m7CqIN5Vc0 IfP1EAV/flmRplg215uxZcfOSU4q2PnXgjDWZG+A1dYvIdMAnsf+od/pPJzi1jl7 oeaMGO7dIXBDE0bs8T0PfsMiRBpGGQ5bc2hg2BXuQMz/waEw3kIcwgQmf6q7y6IE p1Szld8uvSg5JSMBZedNpunUju9aX2B+fmsvEWAeQpoj2+/QF7dtWqNorYlBqY0y i7ivp8eOp17EtwuUW/IcS5Vhcr1BMBFtRaRJceiT0jgZAFlSN4O08y/ctXFU79y5 nfv35k7UhuD9xI2G03N+mm/bj8LVXOEDrWUldUoTSc/QzP9QkOWAIC5ZAciTG+sS 8piGWb2YmyjFobYSrILw =bQQY -----END PGP SIGNATURE----- --BlkQeOBdElZ1aiuH--