From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60090) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aiCuH-0005cE-1L for qemu-devel@nongnu.org; Mon, 21 Mar 2016 23:22:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aiCuF-0002kD-ME for qemu-devel@nongnu.org; Mon, 21 Mar 2016 23:22:56 -0400 Date: Tue, 22 Mar 2016 14:02:59 +1100 From: David Gibson Message-ID: <20160322030259.GY23586@voom.redhat.com> References: <1458546426-26222-1-git-send-email-aik@ozlabs.ru> <1458546426-26222-12-git-send-email-aik@ozlabs.ru> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="wHYmV+hLPeNaasdK" Content-Disposition: inline In-Reply-To: <1458546426-26222-12-git-send-email-aik@ozlabs.ru> Subject: Re: [Qemu-devel] [PATCH qemu v14 11/18] memory: Add reporting of supported page sizes List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alexey Kardashevskiy Cc: Alex Williamson , qemu-ppc@nongnu.org, qemu-devel@nongnu.org --wHYmV+hLPeNaasdK Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Mar 21, 2016 at 06:46:59PM +1100, Alexey Kardashevskiy wrote: > Every IOMMU has some granularity which MemoryRegionIOMMUOps::translate > uses when translating, however this information is not available outside > the translate context for various checks. >=20 > This adds a get_page_sizes callback to MemoryRegionIOMMUOps and > a wrapper for it so IOMMU users (such as VFIO) can know the actual > page size(s) used by an IOMMU. >=20 > The qemu_real_host_page_mask is used as fallback. You're still mismatching concepts here. The MemoryRegionIOMMUOps represents a guest IOMMU, so falling back to qemu_real_host_page_mask (a host property) makes no sense. I think what you want is to fall back to TARGET_PAGE_SIZE. > This removes vfio_container_granularity() and uses new callback in > memory_region_iommu_replay() when replaying IOMMU mappings on added > IOMMU memory region. >=20 > Signed-off-by: Alexey Kardashevskiy > --- > Changes: > v14: > * removed vfio_container_granularity(), changed memory_region_iommu_repla= y() >=20 > v4: > * s/1< --- > hw/ppc/spapr_iommu.c | 8 ++++++++ > hw/vfio/common.c | 6 ------ > include/exec/memory.h | 18 ++++++++++++++---- > memory.c | 17 ++++++++++++++--- > 4 files changed, 36 insertions(+), 13 deletions(-) >=20 > diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c > index dd662da..6dc3c45 100644 > --- a/hw/ppc/spapr_iommu.c > +++ b/hw/ppc/spapr_iommu.c > @@ -144,6 +144,13 @@ static void spapr_tce_table_pre_save(void *opaque) > tcet->mig_table =3D tcet->table; > } > =20 > +static uint64_t spapr_tce_get_page_sizes(MemoryRegion *iommu) > +{ > + sPAPRTCETable *tcet =3D container_of(iommu, sPAPRTCETable, iommu); > + > + return 1ULL << tcet->page_shift; > +} > + > static void spapr_tce_table_do_enable(sPAPRTCETable *tcet); > static void spapr_tce_table_do_disable(sPAPRTCETable *tcet); > =20 > @@ -203,6 +210,7 @@ static const VMStateDescription vmstate_spapr_tce_tab= le =3D { > =20 > static MemoryRegionIOMMUOps spapr_iommu_ops =3D { > .translate =3D spapr_tce_translate_iommu, > + .get_page_sizes =3D spapr_tce_get_page_sizes, > }; > =20 > static int spapr_tce_table_realize(DeviceState *dev) > diff --git a/hw/vfio/common.c b/hw/vfio/common.c > index d45e2db..55723c9 100644 > --- a/hw/vfio/common.c > +++ b/hw/vfio/common.c > @@ -313,11 +313,6 @@ out: > rcu_read_unlock(); > } > =20 > -static hwaddr vfio_container_granularity(VFIOContainer *container) > -{ > - return (hwaddr)1 << ctz64(container->iova_pgsizes); > -} > - > static void vfio_listener_region_add(MemoryListener *listener, > MemoryRegionSection *section) > { > @@ -385,7 +380,6 @@ static void vfio_listener_region_add(MemoryListener *= listener, > =20 > memory_region_register_iommu_notifier(giommu->iommu, &giommu->n); > memory_region_iommu_replay(giommu->iommu, &giommu->n, > - vfio_container_granularity(container), > false); > =20 > return; > diff --git a/include/exec/memory.h b/include/exec/memory.h > index 2de7898..eb5ce67 100644 > --- a/include/exec/memory.h > +++ b/include/exec/memory.h > @@ -150,6 +150,8 @@ typedef struct MemoryRegionIOMMUOps MemoryRegionIOMMU= Ops; > struct MemoryRegionIOMMUOps { > /* Return a TLB entry that contains a given address. */ > IOMMUTLBEntry (*translate)(MemoryRegion *iommu, hwaddr addr, bool is= _write); > + /* Returns supported page sizes */ > + uint64_t (*get_page_sizes)(MemoryRegion *iommu); > }; > =20 > typedef struct CoalescedMemoryRange CoalescedMemoryRange; > @@ -573,6 +575,15 @@ static inline bool memory_region_is_iommu(MemoryRegi= on *mr) > =20 > =20 > /** > + * memory_region_iommu_get_page_sizes: get supported page sizes in an io= mmu > + * > + * Returns %bitmap of supported page sizes for an iommu. > + * > + * @mr: the memory region being queried > + */ > +uint64_t memory_region_iommu_get_page_sizes(MemoryRegion *mr); > + > +/** > * memory_region_notify_iommu: notify a change in an IOMMU translation e= ntry. > * > * @mr: the memory region that was changed > @@ -596,16 +607,15 @@ void memory_region_register_iommu_notifier(MemoryRe= gion *mr, Notifier *n); > =20 > /** > * memory_region_iommu_replay: replay existing IOMMU translations to > - * a notifier > + * a notifier with the minimum page granularity returned by > + * mr->iommu_ops->get_page_sizes(). > * > * @mr: the memory region to observe > * @n: the notifier to which to replay iommu mappings > - * @granularity: Minimum page granularity to replay notifications for > * @is_write: Whether to treat the replay as a translate "write" > * through the iommu > */ > -void memory_region_iommu_replay(MemoryRegion *mr, Notifier *n, > - hwaddr granularity, bool is_write); > +void memory_region_iommu_replay(MemoryRegion *mr, Notifier *n, bool is_w= rite); > =20 > /** > * memory_region_unregister_iommu_notifier: unregister a notifier for > diff --git a/memory.c b/memory.c > index 95f7209..64a84d3 100644 > --- a/memory.c > +++ b/memory.c > @@ -1512,12 +1512,14 @@ void memory_region_register_iommu_notifier(Memory= Region *mr, Notifier *n) > notifier_list_add(&mr->iommu_notify, n); > } > =20 > -void memory_region_iommu_replay(MemoryRegion *mr, Notifier *n, > - hwaddr granularity, bool is_write) > +void memory_region_iommu_replay(MemoryRegion *mr, Notifier *n, bool is_w= rite) > { > - hwaddr addr; > + hwaddr addr, granularity; > IOMMUTLBEntry iotlb; > =20 > + g_assert(mr->iommu_ops && mr->iommu_ops->get_page_sizes); > + granularity =3D (hwaddr)1 << ctz64(mr->iommu_ops->get_page_sizes(mr)= ); > + > for (addr =3D 0; addr < memory_region_size(mr); addr +=3D granularit= y) { > iotlb =3D mr->iommu_ops->translate(mr, addr, is_write); > if (iotlb.perm !=3D IOMMU_NONE) { > @@ -1544,6 +1546,15 @@ void memory_region_notify_iommu(MemoryRegion *mr, > notifier_list_notify(&mr->iommu_notify, &entry); > } > =20 > +uint64_t memory_region_iommu_get_page_sizes(MemoryRegion *mr) > +{ > + assert(memory_region_is_iommu(mr)); > + if (mr->iommu_ops && mr->iommu_ops->get_page_sizes) { > + return mr->iommu_ops->get_page_sizes(mr); > + } > + return qemu_real_host_page_size; > +} > + > void memory_region_set_log(MemoryRegion *mr, bool log, unsigned client) > { > uint8_t mask =3D 1 << client; --=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 --wHYmV+hLPeNaasdK Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJW8LXjAAoJEGw4ysog2bOSPjkP/RW8ZtSeuE7fb5T1M5bbn0HV YHDpmKj/aaSNE231GO7larV8aCgxg6EYJJRyo+kSJZOAYH3vESrDge+eSBhtwWRc vR62aw1SSkmhXLE+7o6O9RFHFPvZRE49cO6rUFfU9X0fEQk0SoN1NKaXMSssyVt3 V2NeNbrUnIimwOPI0eCNPHbEK6tvx1gZB30WxjqXvDl5tKNElByhiuLU99lFYGLR xrMRZ/Lu1BrL1ZXJcSXyC87R6/c6WrnyqpC4kneV3tP04YiGqbdJmXSPg+EfxX6d m2WTtBruBC0Mj6fOQDvRldwj55MqhF3RZ7SaSONgEcAz7WStHcmc5FM9zvjVZJn6 hLiU4dfB4iuMsn5YwUdDMzb1W0h2Wlam1tE0gHkWmQMp2SoklFkuUg/Vohk+QI0L ULsDwrnV2lpsaD3ItKNpf6ZXW0WZKXXfAwwmB5/57HZbeBzz+tiNKhan7BUR097v I1vunCBHREN2qzPMbQURMJRxF3d4CGVpZ3W7KNdCsIKP3sxcn38/31wuA56Ec7Y3 2q9ARfjuIndRfswuFhW2q0l+NBMc+lWSbPmA8aC/QEo9+HCPFDYbthRszH7pwITX mGbRO04GQ+L+KlRS7cNO/5pAlBDJbGvNv7n6SsUoE58Gs3jxs3st29wPiBnWF1we +/NicmKcNa2PE6FTcFzs =Z8+7 -----END PGP SIGNATURE----- --wHYmV+hLPeNaasdK--