Received: from eggs.gnu.org ([2001:4830:134:3::10]:39764) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bnGXr-0001dm-AE for qemu-devel@nongnu.org; Thu, 22 Sep 2016 22:49:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bnGXo-0002FP-Te for qemu-devel@nongnu.org; Thu, 22 Sep 2016 22:48:58 -0400 Received: from ozlabs.org ([103.22.144.67]:55543) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bnGXo-0002E6-6V for qemu-devel@nongnu.org; Thu, 22 Sep 2016 22:48:56 -0400 Date: Fri, 23 Sep 2016 10:36:25 +1000 From: David Gibson Message-ID: <20160923003625.GK2085@umbus.fritz.box> References: <1474433936-19617-1-git-send-email-peterx@redhat.com> <1474433936-19617-2-git-send-email-peterx@redhat.com> <20160922052048.GF2085@umbus.fritz.box> <20160922071746.GP5134@pxdev.xzpeter.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="zPXeIxDajdrcF2en" Content-Disposition: inline In-Reply-To: <20160922071746.GP5134@pxdev.xzpeter.org> Subject: Re: [Qemu-devel] [PATCH v6 1/3] memory: introduce IOMMUNotifier and its caps List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Xu Cc: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com, vkaplans@redhat.com, alex.williamson@redhat.com, wexu@redhat.com, pbonzini@redhat.com, cornelia.huck@de.ibm.com, dgibson@redhat.com --zPXeIxDajdrcF2en Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Sep 22, 2016 at 03:17:46PM +0800, Peter Xu wrote: > On Thu, Sep 22, 2016 at 03:20:48PM +1000, David Gibson wrote: > > On Wed, Sep 21, 2016 at 12:58:54PM +0800, Peter Xu wrote: > > > IOMMU Notifier list is used for notifying IO address mapping changes. > > > Currently VFIO is the only user. > > >=20 > > > However it is possible that future consumer like vhost would like to > > > only listen to part of its notifications (e.g., cache invalidations). > > >=20 > > > This patch introduced IOMMUNotifier and IOMMUNotfierFlag bits for a > > > finer grained control of it. > > >=20 > > > IOMMUNotifier contains a bitfield for the notify consumer describing > > > what kind of notification it is interested in. Currently two kinds of > > > notifications are defined: > > >=20 > > > - IOMMU_NOTIFIER_MAP: for newly mapped entries (additions) > > > - IOMMU_NOTIFIER_UNMAP: for entries to be removed (cache invalidates) > > >=20 > > > When registering the IOMMU notifier, we need to specify one or multip= le > > > types of messages to listen to. > > >=20 > > > When notifications are triggered, its type will be checked against the > > > notifier's type bits, and only notifiers with registered bits will be > > > notified. > > >=20 > > > (For any IOMMU implementation, an in-place mapping change should be > > > notified with an UNMAP followed by a MAP.) > >=20 > > Ok, I wasn't clear. I meant a big fat comment in the *code*, not just > > in the commit message. It should not be necessary to look at the > > commit history to figure out how to use an interface correctly > >=20 > > Even a comment in the code is barely adequate, compared to designing > > the interface signatures such that it's obvious. > >=20 > > Please bear in mind: > > http://ozlabs.org/~rusty/index.cgi/tech/2008-03-30.html > > and http://ozlabs.org/~rusty/index.cgi/tech/2008-04-01.html > >=20 >=20 > Thanks for the links. >=20 > Maybe a better solution is to re-design the IOTLB interface. However > that's out of the scope of this series, and another patchset can be > opened for the refactoring work IMHO if there is a strong willingness. >=20 > For now I can add this into comments: >=20 > ---------8<----------- >=20 > @@ -607,6 +628,15 @@ uint64_t memory_region_iommu_get_min_page_size(Memor= yRegion *mr); > /** > * memory_region_notify_iommu: notify a change in an IOMMU translation e= ntry. > * > + * The notification type will be decided by entry.perm bits: > + * > + * - For UNMAP (cache invalidation) notifies: set entry.perm to IOMMU_NO= NE. > + * - For MAP (newly added entry) notifies: set entry.perm to the > + * permission of the page (which is definitely !IOMMU_NONE). > + * > + * Note: for any IOMMU implementation, an in-place mapping change > + * should be notified with an UNMAP followed by a MAP. > + * > * @mr: the memory region that was changed > * @entry: the new entry in the IOMMU translation table. The entry > * replaces all old entries for the same virtual I/O address ran= ge. >=20 > --------->8----------- Thanks, that looks about as good as we can get with a comment. >=20 > [...] >=20 > > > -static void vfio_iommu_map_notify(Notifier *n, void *data) > > > +static void vfio_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *d= ata) > >=20 > > This change leaves a now pointless IOMMUTLBEntry *iotlb =3D data a few > > lines below. >=20 > Yes, will fix. >=20 > >=20 > > > { > > > VFIOGuestIOMMU *giommu =3D container_of(n, VFIOGuestIOMMU, n); > > > VFIOContainer *container =3D giommu->container; > > > @@ -454,6 +454,7 @@ static void vfio_listener_region_add(MemoryListen= er *listener, > > > section->offset_within_region; > > > giommu->container =3D container; > > > giommu->n.notify =3D vfio_iommu_map_notify; > > > + giommu->n.notifier_flags =3D IOMMU_NOTIFIER_ALL; > > > QLIST_INSERT_HEAD(&container->giommu_list, giommu, giommu_ne= xt); > > > =20 > > > memory_region_register_iommu_notifier(giommu->iommu, &giommu= ->n); > > > diff --git a/include/exec/memory.h b/include/exec/memory.h > > > index 3e4d416..a3ec7aa 100644 > > > --- a/include/exec/memory.h > > > +++ b/include/exec/memory.h > > > @@ -67,6 +67,27 @@ struct IOMMUTLBEntry { > > > IOMMUAccessFlags perm; > > > }; > > > =20 > > > +/* > > > + * Bitmap for differnet IOMMUNotifier capabilities. Each notifier can > >=20 > > s/differnet/different/ >=20 > Will fix. Thanks. >=20 > -- peterx >=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 --zPXeIxDajdrcF2en Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJX5HkJAAoJEGw4ysog2bOS3ekP/iSN7L7vHy1UVPFRugSAJh1b nHoVJHwKU+g6PcCQCUIN78cy3CSBY7qnUcU+kdDrIOsiMyd2o2H6vWfYyS7kLE6K gqjjcPROH0MPqRzbRt68eHA2NnhZAk6dasLVdi2zinbgZMLQCkaOZWcto6CMAhp6 9mLvfPPAaLZZvT7tz2mzLMOer5AqRnNUaqiaorbjqmJgIarnxpKqnsraOS1fxMO6 szqf7ZVE5/jRsCrDG77pVU22ZjCeDQvHR7SXBfVGuvTZwcOHyJMUT7r0WzsucHpv my01ntRG/TY0rD9W0pYtpFlQzIxRH1Aullzdrwy8cvtupN8v4bqy3PfiLKKbHvNd 0DSJMhZX/p2HtOLTViE2F7VbqoP0K3ouBnaN9KLOsiIO4QugzUv5mbY58vfSy+Q6 /FYkFBsBuHDtFVgCbhy6s4+TjNt5TN2qLtut9TkvYLkHeWcdDzt7aVqHRuQT7Lyi 6IoHkuuxZuEdj4Zw/PHiR2bwNaENoUqReY9FMsSo8+Kn7LjsEu2ZFnmZ0iiV/EUj o71sOTWqeTzz1j+UKSDX9o/Gi6jVy0Un5Qmu/DZuQjHuLjkiH5giiYqfuYBZPv1D rup2dmM7YMS3yzWTU6q99a00+qBOcPAlIz3fj+DMNNPBLKoQDnvR9S/XT95cZt+8 1BO9++hxT9CtC8R4raT8 =oSb0 -----END PGP SIGNATURE----- --zPXeIxDajdrcF2en--