From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51512) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5nCM-0007X9-3K for qemu-devel@nongnu.org; Thu, 26 May 2016 00:47:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b5nCD-0007Lm-UO for qemu-devel@nongnu.org; Thu, 26 May 2016 00:47:06 -0400 Date: Thu, 26 May 2016 13:32:03 +1000 From: David Gibson Message-ID: <20160526033203.GZ17226@voom.fritz.box> References: <1462344751-28281-1-git-send-email-aik@ozlabs.ru> <1462344751-28281-8-git-send-email-aik@ozlabs.ru> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="6749iDyxihQ87e9v" Content-Disposition: inline In-Reply-To: <1462344751-28281-8-git-send-email-aik@ozlabs.ru> Subject: Re: [Qemu-devel] [PATCH qemu v16 07/19] spapr_iommu: Move table allocation to helpers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alexey Kardashevskiy Cc: qemu-devel@nongnu.org, qemu-ppc@nongnu.org, Alexander Graf , Alex Williamson , Paolo Bonzini --6749iDyxihQ87e9v Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, May 04, 2016 at 04:52:19PM +1000, Alexey Kardashevskiy wrote: > At the moment presence of vfio-pci devices on a bus affect the way > the guest view table is allocated. If there is no vfio-pci on a PHB > and the host kernel supports KVM acceleration of H_PUT_TCE, a table > is allocated in KVM. However, if there is vfio-pci and we do yet not > KVM acceleration for these, the table has to be allocated by > the userspace. At the moment the table is allocated once at boot time > but next patches will reallocate it. >=20 > This moves kvmppc_create_spapr_tce/g_malloc0 and their counterparts > to helpers. >=20 > Signed-off-by: Alexey Kardashevskiy > Reviewed-by: David Gibson This is a reasonable clean up on its own, so I've applied to ppc-for-2.7. > --- > hw/ppc/spapr_iommu.c | 58 +++++++++++++++++++++++++++++++++++-----------= ------ > trace-events | 2 +- > 2 files changed, 40 insertions(+), 20 deletions(-) >=20 > diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c > index 277f289..8132f64 100644 > --- a/hw/ppc/spapr_iommu.c > +++ b/hw/ppc/spapr_iommu.c > @@ -75,6 +75,37 @@ static IOMMUAccessFlags spapr_tce_iommu_access_flags(u= int64_t tce) > } > } > =20 > +static uint64_t *spapr_tce_alloc_table(uint32_t liobn, > + uint32_t page_shift, > + uint32_t nb_table, > + int *fd, > + bool need_vfio) > +{ > + uint64_t *table =3D NULL; > + uint64_t window_size =3D (uint64_t)nb_table << page_shift; > + > + if (kvm_enabled() && !(window_size >> 32)) { > + table =3D kvmppc_create_spapr_tce(liobn, window_size, fd, need_v= fio); > + } > + > + if (!table) { > + *fd =3D -1; > + table =3D g_malloc0(nb_table * sizeof(uint64_t)); > + } > + > + trace_spapr_iommu_new_table(liobn, table, *fd); > + > + return table; > +} > + > +static void spapr_tce_free_table(uint64_t *table, int fd, uint32_t nb_ta= ble) > +{ > + if (!kvm_enabled() || > + (kvmppc_remove_spapr_tce(table, fd, nb_table) !=3D 0)) { > + g_free(table); > + } > +} > + > /* Called from RCU critical section */ > static IOMMUTLBEntry spapr_tce_translate_iommu(MemoryRegion *iommu, hwad= dr addr, > bool is_write) > @@ -141,21 +172,13 @@ static MemoryRegionIOMMUOps spapr_iommu_ops =3D { > static int spapr_tce_table_realize(DeviceState *dev) > { > sPAPRTCETable *tcet =3D SPAPR_TCE_TABLE(dev); > - uint64_t window_size =3D (uint64_t)tcet->nb_table << tcet->page_shif= t; > =20 > - if (kvm_enabled() && !(window_size >> 32)) { > - tcet->table =3D kvmppc_create_spapr_tce(tcet->liobn, > - window_size, > - &tcet->fd, > - tcet->need_vfio); > - } > - > - if (!tcet->table) { > - size_t table_size =3D tcet->nb_table * sizeof(uint64_t); > - tcet->table =3D g_malloc0(table_size); > - } > - > - trace_spapr_iommu_new_table(tcet->liobn, tcet, tcet->table, tcet->fd= ); > + tcet->fd =3D -1; > + tcet->table =3D spapr_tce_alloc_table(tcet->liobn, > + tcet->page_shift, > + tcet->nb_table, > + &tcet->fd, > + tcet->need_vfio); > =20 > memory_region_init_iommu(&tcet->iommu, OBJECT(dev), &spapr_iommu_ops, > "iommu-spapr", > @@ -241,11 +264,8 @@ static void spapr_tce_table_unrealize(DeviceState *d= ev, Error **errp) > =20 > QLIST_REMOVE(tcet, list); > =20 > - if (!kvm_enabled() || > - (kvmppc_remove_spapr_tce(tcet->table, tcet->fd, > - tcet->nb_table) !=3D 0)) { > - g_free(tcet->table); > - } > + spapr_tce_free_table(tcet->table, tcet->fd, tcet->nb_table); > + tcet->fd =3D -1; > } > =20 > MemoryRegion *spapr_tce_get_iommu(sPAPRTCETable *tcet) > diff --git a/trace-events b/trace-events > index 8350743..d96d344 100644 > --- a/trace-events > +++ b/trace-events > @@ -1431,7 +1431,7 @@ spapr_iommu_pci_get(uint64_t liobn, uint64_t ioba, = uint64_t ret, uint64_t tce) " > spapr_iommu_pci_indirect(uint64_t liobn, uint64_t ioba, uint64_t tce, ui= nt64_t iobaN, uint64_t tceN, uint64_t ret) "liobn=3D%"PRIx64" ioba=3D0x%"PR= Ix64" tcelist=3D0x%"PRIx64" iobaN=3D0x%"PRIx64" tceN=3D0x%"PRIx64" ret=3D%"= PRId64 > spapr_iommu_pci_stuff(uint64_t liobn, uint64_t ioba, uint64_t tce_value,= uint64_t npages, uint64_t ret) "liobn=3D%"PRIx64" ioba=3D0x%"PRIx64" tceva= lue=3D0x%"PRIx64" npages=3D%"PRId64" ret=3D%"PRId64 > spapr_iommu_xlate(uint64_t liobn, uint64_t ioba, uint64_t tce, unsigned = perm, unsigned pgsize) "liobn=3D%"PRIx64" 0x%"PRIx64" -> 0x%"PRIx64" perm= =3D%u mask=3D%x" > -spapr_iommu_new_table(uint64_t liobn, void *tcet, void *table, int fd) "= liobn=3D%"PRIx64" tcet=3D%p table=3D%p fd=3D%d" > +spapr_iommu_new_table(uint64_t liobn, void *table, int fd) "liobn=3D%"PR= Ix64" table=3D%p fd=3D%d" > =20 > # hw/ppc/ppc.c > ppc_tb_adjust(uint64_t offs1, uint64_t offs2, int64_t diff, int64_t seco= nds) "adjusted from 0x%"PRIx64" to 0x%"PRIx64", diff %"PRId64" (%"PRId64"s)" --=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 --6749iDyxihQ87e9v Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJXRm4yAAoJEGw4ysog2bOSCJAQAJpGuyK9nMESt3B9KnveAacW tL9jnKu/cB7yULT6g7VePdJnZCzBPr+nn+R/wai3RuqEDubWZB5EHaY26JLsMWiV LLe7ks+mXgZGc3Mpzy9olM7Vb9G/H62u/gOer25UHyKmvcBgICogj4/VFZOWmT/q CC6o74r+gTA3+r/nRugHXiCBn2lA8zY/ZaEZSc78PHjl6SscqMax6Nu17uhKXbqm mJKKcK+lXTUcGu0iTWRY9vcSbinVc8OW3zaVksuy8NfLRhTP3qKxYXyeBJb+fMa4 wbaOkAEs8HiMuBATwBjhX/2qatwZ0QpqHSzpTGZsXo1drZqsh/Vj33ppOqrbLDXr v+XE1hZF3VESZbS2tsmu/tABshHBiZz4wPrIkWZ3Yhd1rtg1l7rDwt6bEBXFU/IS UcGn2Bt0HDs9aIkexH0OAz+6UerrSv2BKefKH4S+MM6P+G4+Iz+Sfp+ew7GrG6Vk RlAVroy2kqHxJb5tKzJy8AXjupL6JL9j0M8O5wvV/w5F6lL8VUTCjh7+qg90V8js WoUqEHPOAxgUMrmC/4jHFePcifvp2nEa7CJSBWt+//QlWr1sU5VCDSR9+hgTiBgB OR5VQjfjfGHtmIQBNjzENSNr3QFM0mQGUCpgO9H+gNrIYh8lJ7iTMoyDI912UFIm IkK6cgEjRc+ARAkK98QT =/abF -----END PGP SIGNATURE----- --6749iDyxihQ87e9v--