Received: from eggs.gnu.org ([2001:4830:134:3::10]:50928) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhVxl-0005zX-Gc for qemu-devel@nongnu.org; Wed, 07 Sep 2016 02:03:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bhVxj-00016B-0m for qemu-devel@nongnu.org; Wed, 07 Sep 2016 02:03:56 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:59283) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhVxh-00015Y-K5 for qemu-devel@nongnu.org; Wed, 07 Sep 2016 02:03:54 -0400 Date: Wed, 7 Sep 2016 16:05:50 +1000 From: David Gibson Message-ID: <20160907060550.GQ2780@voom.fritz.box> References: <1473226344-28520-1-git-send-email-peterx@redhat.com> <1473226344-28520-3-git-send-email-peterx@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="3wfpuDtTLg8/Vq6g" Content-Disposition: inline In-Reply-To: <1473226344-28520-3-git-send-email-peterx@redhat.com> Subject: Re: [Qemu-devel] [PATCH v3 2/3] memory: generalize iommu_ops.notify_started to notifier_add 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 --3wfpuDtTLg8/Vq6g Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Sep 07, 2016 at 01:32:23PM +0800, Peter Xu wrote: > Considering that we may have multiple IOMMU notifier consumers in the > future, converting iommu_ops.notify_{started|stopped} into some more > general form. Now we can trap all notifier registerations and > deregistrations, rather than only the first ones. >=20 > Power was leveraging the notifier_{started|stopped}, adding iommu_user > field for counting on Power guests to achieve the same goal. Requiring each vIOMMU frontend to reference count or whatever seems like a pain. The semantics of notify_started() were designed to avoid that. Instead I'd suggest a callback which gets tripped any time the logical OR of the requested notifications for all current notifiers changes. > Suggested-by: Paolo Bonzini > Signed-off-by: Peter Xu > --- > hw/i386/intel_iommu.c | 4 ++-- > hw/ppc/spapr_iommu.c | 18 ++++++++++++------ > include/exec/memory.h | 8 ++++---- > include/hw/ppc/spapr.h | 1 + > memory.c | 10 ++++------ > 5 files changed, 23 insertions(+), 18 deletions(-) >=20 > diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c > index 28c31a2..c6bd8f6 100644 > --- a/hw/i386/intel_iommu.c > +++ b/hw/i386/intel_iommu.c > @@ -1974,7 +1974,7 @@ static IOMMUTLBEntry vtd_iommu_translate(MemoryRegi= on *iommu, hwaddr addr, > return ret; > } > =20 > -static void vtd_iommu_notify_started(MemoryRegion *iommu) > +static void vtd_iommu_notifier_add(MemoryRegion *iommu, IOMMUNotifier *n) > { > VTDAddressSpace *vtd_as =3D container_of(iommu, VTDAddressSpace, iom= mu); > =20 > @@ -2348,7 +2348,7 @@ static void vtd_init(IntelIOMMUState *s) > memset(s->womask, 0, DMAR_REG_SIZE); > =20 > s->iommu_ops.translate =3D vtd_iommu_translate; > - s->iommu_ops.notify_started =3D vtd_iommu_notify_started; > + s->iommu_ops.notifier_add =3D vtd_iommu_notifier_add; > s->root =3D 0; > s->root_extended =3D false; > s->dmar_enabled =3D false; > diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c > index 6bc4d4d..99c83a4 100644 > --- a/hw/ppc/spapr_iommu.c > +++ b/hw/ppc/spapr_iommu.c > @@ -156,14 +156,20 @@ static uint64_t spapr_tce_get_min_page_size(MemoryR= egion *iommu) > return 1ULL << tcet->page_shift; > } > =20 > -static void spapr_tce_notify_started(MemoryRegion *iommu) > +static void spapr_tce_notifier_add(MemoryRegion *iommu, IOMMUNotifier *n) > { > - spapr_tce_set_need_vfio(container_of(iommu, sPAPRTCETable, iommu), t= rue); > + sPAPRTCETable *tcet =3D container_of(iommu, sPAPRTCETable, iommu); > + if (tcet->iommu_users++ =3D=3D 0) { > + spapr_tce_set_need_vfio(tcet, true); > + } > } > =20 > -static void spapr_tce_notify_stopped(MemoryRegion *iommu) > +static void spapr_tce_notifier_del(MemoryRegion *iommu, IOMMUNotifier *n) > { > - spapr_tce_set_need_vfio(container_of(iommu, sPAPRTCETable, iommu), f= alse); > + sPAPRTCETable *tcet =3D container_of(iommu, sPAPRTCETable, iommu); > + if (--tcet->iommu_users =3D=3D 0) { > + spapr_tce_set_need_vfio(tcet, false); > + } > } > =20 > static int spapr_tce_table_post_load(void *opaque, int version_id) > @@ -246,8 +252,8 @@ static const VMStateDescription vmstate_spapr_tce_tab= le =3D { > static MemoryRegionIOMMUOps spapr_iommu_ops =3D { > .translate =3D spapr_tce_translate_iommu, > .get_min_page_size =3D spapr_tce_get_min_page_size, > - .notify_started =3D spapr_tce_notify_started, > - .notify_stopped =3D spapr_tce_notify_stopped, > + .notifier_add =3D spapr_tce_notifier_add, > + .notifier_del =3D spapr_tce_notifier_del, > }; > =20 > static int spapr_tce_table_realize(DeviceState *dev) > diff --git a/include/exec/memory.h b/include/exec/memory.h > index 92f14db..9efcf1b 100644 > --- a/include/exec/memory.h > +++ b/include/exec/memory.h > @@ -175,10 +175,10 @@ struct MemoryRegionIOMMUOps { > IOMMUTLBEntry (*translate)(MemoryRegion *iommu, hwaddr addr, bool is= _write); > /* Returns minimum supported page size */ > uint64_t (*get_min_page_size)(MemoryRegion *iommu); > - /* Called when the first notifier is set */ > - void (*notify_started)(MemoryRegion *iommu); > - /* Called when the last notifier is removed */ > - void (*notify_stopped)(MemoryRegion *iommu); > + /* Called when someone registers to the notify list */ > + void (*notifier_add)(MemoryRegion *iommu, IOMMUNotifier *n); > + /* Called when someone unregisters from the notify list */ > + void (*notifier_del)(MemoryRegion *iommu, IOMMUNotifier *n); > }; > =20 > typedef struct CoalescedMemoryRange CoalescedMemoryRange; > diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h > index caf7be9..08627ec 100644 > --- a/include/hw/ppc/spapr.h > +++ b/include/hw/ppc/spapr.h > @@ -564,6 +564,7 @@ struct sPAPRTCETable { > MemoryRegion root, iommu; > struct VIOsPAPRDevice *vdev; /* for @bypass migration compatibility = only */ > QLIST_ENTRY(sPAPRTCETable) list; > + int iommu_users; > }; > =20 > sPAPRTCETable *spapr_tce_find_by_liobn(target_ulong liobn); > diff --git a/memory.c b/memory.c > index 45a3902..d913043 100644 > --- a/memory.c > +++ b/memory.c > @@ -1518,9 +1518,8 @@ void memory_region_register_iommu_notifier(MemoryRe= gion *mr, > { > /* We need to register for at least one bitfield */ > assert(n->notifier_caps !=3D IOMMU_NOTIFIER_NONE); > - if (mr->iommu_ops->notify_started && > - QLIST_EMPTY(&mr->iommu_notify)) { > - mr->iommu_ops->notify_started(mr); > + if (mr->iommu_ops->notifier_add) { > + mr->iommu_ops->notifier_add(mr, n); > } > QLIST_INSERT_HEAD(&mr->iommu_notify, n, node); > } > @@ -1560,9 +1559,8 @@ void memory_region_unregister_iommu_notifier(Memory= Region *mr, > IOMMUNotifier *n) > { > QLIST_REMOVE(n, node); > - if (mr->iommu_ops->notify_stopped && > - QLIST_EMPTY(&mr->iommu_notify)) { > - mr->iommu_ops->notify_stopped(mr); > + if (mr->iommu_ops->notifier_del) { > + mr->iommu_ops->notifier_del(mr, n); > } > } > =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 --3wfpuDtTLg8/Vq6g Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIcBAEBAgAGBQJXz64+AAoJEGw4ysog2bOSuykQALU2qj293flrOCtZ7RPDytLj q6ze6zUzIKq93CU7nuAveOJplktpMENA98OBtk0i41bkKCDFcPjSXKNgNPXbhUoa AkcxLIe9mrkYz6KCwxOhfe7khZ+ST6gIQr5X3TNUXZaeDntOKwEL48whLvBWV+Ax 0+drMbC1FKltouEGdOgdzDCl44bd5/9b384FsK7gc9euXSUkA6QhVhEIarXvKfub d57VkDkld6x9NWAcXf7V9g3ePJmhZGA0V9rASW/BmfjLDNXI0Jueo+jHd8sMfBEs 4LMOpddFaAeTnasYf9CXU+iSnQJ1KZNLhosmrXSAEKu31q9EccuONSEsN8VH11/D C9FhEp09MRXoa5F04GZrVdGNfh8u1cZsNznQRMsUn1N787sonuLIxtKuk5beT1mn vDjW2Ub/zMIKBkWFmvvZD9YPlZjP2AD9XQLUvIYbQWgE9d0xQhxmSFH+NHehbxpn RsXCp/MTqEhODOM9X9Zjf28jx2MVvFM9GW+2LSCRdF+O8QARedx7+p/yr8T9kbvZ UB2sw9CKT+5qs1Fn9GkrfqsMM/uT0YOrUoM9hrp+UqcjnNlwm5PkQQRpu6bd5KB7 KWJUlqYDY9N05855UxudaEZZNi0SHuhGkTnx7jzG3L1l0k7Bw8PIunpy6vx7UbYp hQGfxeDMVkYBBZl1TOQF =6QWb -----END PGP SIGNATURE----- --3wfpuDtTLg8/Vq6g--