From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43069) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zeto7-0007n9-4L for qemu-devel@nongnu.org; Wed, 23 Sep 2015 19:50:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zeto5-0000PI-Mg for qemu-devel@nongnu.org; Wed, 23 Sep 2015 19:50:39 -0400 Date: Thu, 24 Sep 2015 09:47:36 +1000 From: David Gibson Message-ID: <20150923234736.GD15944@voom.fritz.box> References: <1442495357-26547-1-git-send-email-david@gibson.dropbear.id.au> <1442495357-26547-6-git-send-email-david@gibson.dropbear.id.au> <56028192.8060001@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="Qrgsu6vtpU/OV/zm" Content-Disposition: inline In-Reply-To: <56028192.8060001@redhat.com> Subject: Re: [Qemu-devel] [RFC PATCH 05/10] memory: Allow replay of IOMMU mapping notifications List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Thomas Huth Cc: lvivier@redhat.com, aik@ozlabs.ru, gwshan@linux.vnet.ibm.com, qemu-devel@nongnu.org, alex.williamson@redhat.com, qemu-ppc@nongnu.org, pbonzini@redhat.com --Qrgsu6vtpU/OV/zm Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Sep 23, 2015 at 12:40:18PM +0200, Thomas Huth wrote: > On 17/09/15 15:09, David Gibson wrote: > > When we have guest visible IOMMUs, we allow notifiers to be registered > > which will be informed of all changes to IOMMU mappings. This is used = by > > vfio to keep the host IOMMU mappings in sync with guest IOMMU mappings. > >=20 > > However, unlike with a memory region listener, an iommu notifier won't = be > > told about any mappings which already exist in the (guest) IOMMU at the > > time it is registered. This can cause problems if hotplugging a VFIO > > device onto a guest bus which had existing guest IOMMU mappings, but di= dn't > > previously have an VFIO devices (and hence no host IOMMU mappings). > >=20 > > This adds a memory_region_register_iommu_notifier_replay() function to > > handle this case. As well as registering the new notifier it replays > > existing mappings. Because the IOMMU memory region doesn't internally > > remember the granularity of the guest IOMMU it has a small hack where t= he > > caller must specify a granularity at which to replay mappings. > >=20 > > If there are finer mappings in the guest IOMMU these will be reported in > > the iotlb structures passed to the notifier which it must handle (proba= bly > > causing it to flag an error). This isn't new - the VFIO iommu notifier > > must already handle notifications about guest IOMMU mappings too short > > for it to represent in the host IOMMU. > >=20 > > Signed-off-by: David Gibson > > --- > > include/exec/memory.h | 16 ++++++++++++++++ > > memory.c | 18 ++++++++++++++++++ > > 2 files changed, 34 insertions(+) >=20 > > diff --git a/memory.c b/memory.c > > index 0d8b2d9..6b5a2f1 100644 > > --- a/memory.c > > +++ b/memory.c > > @@ -1403,6 +1403,24 @@ void memory_region_register_iommu_notifier(Memor= yRegion *mr, Notifier *n) > > notifier_list_add(&mr->iommu_notify, n); > > } > > =20 > > +void memory_region_register_iommu_notifier_replay(MemoryRegion *mr, No= tifier *n, > > + hwaddr granularity, = bool is_write) >=20 > granularity itself is not an address, but a size, isn't it? So using > "hwaddr" sounds wrong here. As Laurent says, hwaddr is used for sizes through memory.c - I think the rationale is that a size is a difference between two hwaddrs, so should have the same type. > > +{ > > + hwaddr addr; >=20 > dma_addr_t ? As mentioned in previus reply, I don't think so on consideration. > > + IOMMUTLBEntry iotlb; > > + > > + memory_region_register_iommu_notifier(mr, n); > > + > > + for (addr =3D 0; > > + int128_lt(int128_make64(addr), mr->size); > > + addr +=3D granularity) { > > + > > + iotlb =3D mr->iommu_ops->translate(mr, addr, is_write); > > + if (iotlb.perm !=3D IOMMU_NONE) > > + n->notify(n, &iotlb); >=20 > Missing curly braces. Thanks, fixed. >=20 > > + } > > +} > > + >=20 > Thomas >=20 --=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 --Qrgsu6vtpU/OV/zm Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJWAzoYAAoJEGw4ysog2bOSxMsQAJUQDKfKsJCfYwHPdXEBu0Bz y9NNu4r5wfCcJmdNzFwwPelolyhSDW1YZ20Z6kk7DQMHZO5pYsVkEp2vkqORNoNW LXLpe4/HeLNhJUzHCQME++9HzQSeErN3dkbqbdN3klmhiv12bguPGSJCvRZu7t+K 19/XmcRRiDXQL8EJ4+xjZ5OTnvkdmzq49e0L6f7vx0BRnNF3J/A6aUd7TvoEUHxZ Fssp5U9JUhrdbglw8HkKif5wEfLC49m7jUIeelL7cizMvMk4Tl2uFsbHQXVeJgn+ Ba9rLzw7FvCNXUSAsX++X/E4+rHvHGGv4nLi8qwnZOEGtbrKpwH8VYE5Yfa4G9nO lcoEdeivX2O3JVasRJXcTUzjc8s6j4PC2o73gWxOvIfUMdFzxZA/j8RGJWOAnOO6 LcIPfQcwWvK4GjfiPgVxBDWaHws9F/p/lI1rvwXrtHnIDlpRwK7NSY8dzf2I/xaR gx7H5PYvSP7yo8rYkPY+nm3Vgqy/id63nfhoNijGRIARpYI0g5F32tliOWnTl/vl OPpLrQv5kLknZH0u6EIaKnRJNW5NjKMOC6pHtwzEFZbp3XdWs0rGV9J9Mw9xOAw0 UxriRKSs4DWaRUOipCb2PhopgIbznfkE6DRmpqKHaRI5KVgvXn6mWoTPizeJPfzo OyTeI+RwRJOCMFUJA7QJ =X2Sq -----END PGP SIGNATURE----- --Qrgsu6vtpU/OV/zm--