From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58515) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZhRG9-0005p4-Pp for qemu-devel@nongnu.org; Wed, 30 Sep 2015 19:58:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZhRG8-0005Zw-DZ for qemu-devel@nongnu.org; Wed, 30 Sep 2015 19:58:05 -0400 Date: Thu, 1 Oct 2015 09:56:43 +1000 From: David Gibson Message-ID: <20150930235643.GG23574@voom> References: <1443579237-9636-1-git-send-email-david@gibson.dropbear.id.au> <1443579237-9636-7-git-send-email-david@gibson.dropbear.id.au> <560BA6BD.2000409@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="c7hkjup166d4FzgN" Content-Disposition: inline In-Reply-To: <560BA6BD.2000409@redhat.com> Subject: Re: [Qemu-devel] [PATCHv3 6/7] vfio: Allow hotplug of containers onto existing guest IOMMU mappings List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Laurent Vivier Cc: thuth@redhat.com, qemu-devel@nongnu.org, aik@ozlabs.ru, mdroth@linux.vnet.ibm.com, abologna@redhat.com, alex.williamson@redhat.com, qemu-ppc@nongnu.org, pbonzini@redhat.com, gwshan@linux.vnet.ibm.com --c7hkjup166d4FzgN Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Sep 30, 2015 at 11:09:17AM +0200, Laurent Vivier wrote: >=20 >=20 > On 30/09/2015 04:13, David Gibson wrote: > > At present the memory listener used by vfio to keep host IOMMU mappings > > in sync with the guest memory image assumes that if a guest IOMMU > > appears, then it has no existing mappings. > >=20 > > This may not be true if a VFIO device is hotplugged onto a guest bus > > which didn't previously include a VFIO device, and which has existing > > guest IOMMU mappings. > >=20 > > Therefore, use the memory_region_register_iommu_notifier_replay() > > function in order to fix this case, replaying existing guest IOMMU > > mappings, bringing the host IOMMU into sync with the guest IOMMU. > >=20 > > Signed-off-by: David Gibson > > --- > > hw/vfio/common.c | 23 +++++++++-------------- > > 1 file changed, 9 insertions(+), 14 deletions(-) > >=20 > > diff --git a/hw/vfio/common.c b/hw/vfio/common.c > > index f666de2..6797208 100644 > > --- a/hw/vfio/common.c > > +++ b/hw/vfio/common.c > > @@ -312,6 +312,11 @@ 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) > > { > > @@ -369,26 +374,16 @@ static void vfio_listener_region_add(MemoryListen= er *listener, > > * would be the right place to wire that up (tell the KVM > > * device emulation the VFIO iommu handles to use). > > */ > > - /* > > - * This assumes that the guest IOMMU is empty of > > - * mappings at this point. > > - * > > - * One way of doing this is: > > - * 1. Avoid sharing IOMMUs between emulated devices or differe= nt > > - * IOMMU groups. > > - * 2. Implement VFIO_IOMMU_ENABLE in the host kernel to fail if > > - * there are some mappings in IOMMU. > > - * > > - * VFIO on SPAPR does that. Other IOMMU models may do that dif= ferent, > > - * they must make sure there are no existing mappings or > > - * loop through existing mappings to map them into VFIO. > > - */ > > giommu =3D g_malloc0(sizeof(*giommu)); > > giommu->iommu =3D section->mr; > > giommu->container =3D container; > > giommu->n.notify =3D vfio_iommu_map_notify; > > QLIST_INSERT_HEAD(&container->giommu_list, giommu, giommu_next= ); > > + > > memory_region_register_iommu_notifier(giommu->iommu, &giommu->= n); > > + memory_region_iommu_replay(giommu->iommu, &giommu->n, > > + vfio_container_granularity(containe= r), > > + false); >=20 > I'm wondering if it has any sense to provide the "is_write" information > at this level of the API: I don't think we can have access to this > information when we call this function (so it will be always used with > false, or called twice once with false, once with true). I think it > would be better to manage this internally. I agree it's pretty ugly, but I'm not really sure how to handle it better. The translate function itself wants is_write; I'm pretty sure "false" is the right thing here, but I'm not sure it would be right for all potential replay cases. --=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 --c7hkjup166d4FzgN Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJWDHa7AAoJEGw4ysog2bOS6asQAOCwytoRpSmm62yf3bIksPZ4 bWDZQ65fibAJO1h9K9Su2LOO1OyoIdmtnkhib5F4eNMIT6XFtOjt1qmwV1bXNlxd JFfDP6zzxLWHPLa8RRw5S6FB1vKko0jyDof3chee41p0jgzlt12YpTFS5CKExUlD Qjeyc2Ghr6v+2MeAzHf/vmhIn3DvwU3S681pRNcXBY7rgPIWJ742WdChafsqjOuS dYYI9WTvWtD2YG7+JvS3n+z/vb5CtQx6my7PKc+v3CmyWhXPT6x7RZVA/w79VW5C WybwK+wdyGZ3BNkr/Wbgr1CvpDD6iISAkl3bJJxLdf5RBPVNkDN+mRZOcBRkGLb6 u+k+KqGbtgF2WQM/xI6Lkmswndn9aimzzf+7bwFgg4yD03lghCINZWOEC+UdFKak ta4kzmQBdsSBcoGx0SXwSl7vWiZlRdAEJK6YXgd+mUon8GMFRnn3nWa9PBWewl13 YDq4L3QHuFhmjlDZve863FIKhz3yg9l/wxWPrrB+9hqkrK+UtU3JLe8Ue1UyLMAM WCdAM11lHcqrJkhSXH5cka07G82L4ErrZVBMZsmXD2Wb7z1ITYQ/W+iX5o89Wp4Y zHzzxCR193Pj62hjdedPlaWliS7ES1LqIIdfEUuMbIidfyU/9wutuG/WOTe2CAwz Ze1tb8oc3s0YI7uLgEJw =gOkr -----END PGP SIGNATURE----- --c7hkjup166d4FzgN--