From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35886) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZfLoO-0005IT-Ku for qemu-devel@nongnu.org; Fri, 25 Sep 2015 01:44:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZfLoL-0003qT-EU for qemu-devel@nongnu.org; Fri, 25 Sep 2015 01:44:48 -0400 Date: Fri, 25 Sep 2015 15:24:34 +1000 From: David Gibson Message-ID: <20150925052434.GD11620@voom.redhat.com> References: <1443069231-14856-1-git-send-email-david@gibson.dropbear.id.au> <1443069231-14856-6-git-send-email-david@gibson.dropbear.id.au> <1443115949.23936.569.camel@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="mJm6k4Vb/yFcL9ZU" Content-Disposition: inline In-Reply-To: <1443115949.23936.569.camel@redhat.com> Subject: Re: [Qemu-devel] [PATCH 5/7] memory: Allow replay of IOMMU mapping notifications List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alex Williamson Cc: lvivier@redhat.com, thuth@redhat.com, abologna@redhat.com, qemu-devel@nongnu.org, qemu-ppc@nongnu.org, pbonzini@redhat.com --mJm6k4Vb/yFcL9ZU Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Sep 24, 2015 at 11:32:29AM -0600, Alex Williamson wrote: > On Thu, 2015-09-24 at 14:33 +1000, 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 [snip] > > +void memory_region_register_iommu_notifier_replay(MemoryRegion *mr, No= tifier *n, > > + hwaddr granularity, > > + bool is_write) > > +{ > > + hwaddr addr; > > + IOMMUTLBEntry iotlb; > > + > > + memory_region_register_iommu_notifier(mr, n); > > + > > + for (addr =3D 0; addr < memory_region_size(mr); addr +=3D granular= ity) { > > + > > + iotlb =3D mr->iommu_ops->translate(mr, addr, is_write); > > + if (iotlb.perm !=3D IOMMU_NONE) { > > + n->notify(n, &iotlb); > > + } > > + } > > +} > > + >=20 >=20 > When memory_listener_register() replays mappings, it does so on an rcu > copy of the flatview for each AddressSpace. Here we don't seem to have > anything protecting against concurrency... do we need to worry about > that? I was assuming that the IOMMU mappings are protected by the BQL. I _think_ that's the case (for every IOMMU we have so far), but I'm not really sure how to be sure. >=20 > > void memory_region_unregister_iommu_notifier(Notifier *n) > > { > > notifier_remove(n); >=20 >=20 >=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 --mJm6k4Vb/yFcL9ZU Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJWBNqSAAoJEGw4ysog2bOS3egP/1W/AD4LsSslkeWx4jaOn0/e E3TYHXb57xfbY1C2Z50H1vaTIiwMfgr/MSdeuac4UP4ouHtcwBnUqoFKGKUqY8Ee zzapN0RZ3WaXJsAb5aqeIaTz0R3mbvJ5IqmDOrawPbNxS5rlQgHTl4x2fOmB96J1 ney3VkjvLk5876g7peVC/f31QmgdqSt2NuLBTmKNQBeB4sV73r2LO3aSHejTA4MH owWF/rgh+RpCFlcmPH5iRtI6TC1D+62jq3MRRVzi8fE4llCJUZqEt8+WbeBq9Bbi FRPzGHfdfewljEmGGu7fY5SK3+UaB7y7Dn4TgWhvWFL8g5DT8Dl+o0UWSItpeszU Cw+eX99LqAkiy7/Vzv6kycQgj+EL1mxJdBcqpPjC1v8OkYdHVrZG7pzMuTc9lEre xcuTSm7cuMkDR1iTMZJEaIMvfbIos41hStADhSnubiaa0MjQ++K94Vo15+WPtcOK 2gl2qBucZX5D619rixmNMSgwhCLslhZZ2JcaEN5ZIm9oN5XOqc8zzhJ63f6HJ/Ls wZ049ESVp0LY4sQXG6QLUe1EhZwCqI6mDLP+5W1MaEYqff8HFCMML6bLH5naWcOw CMZ9ri3cAUGFVt2jZ94GWY6wMRrTRIFmI1wh1OhbeTTu2BXQkFM1hAq65JC0pUu+ CtKYHAtABYWmGA6ihLH/ =8P8j -----END PGP SIGNATURE----- --mJm6k4Vb/yFcL9ZU--