From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43089) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zeto9-0007nN-4O for qemu-devel@nongnu.org; Wed, 23 Sep 2015 19:50:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zeto5-0000PC-LV for qemu-devel@nongnu.org; Wed, 23 Sep 2015 19:50:41 -0400 Date: Thu, 24 Sep 2015 09:50:54 +1000 From: David Gibson Message-ID: <20150923235054.GF15944@voom.fritz.box> References: <1442495357-26547-1-git-send-email-david@gibson.dropbear.id.au> <1442495357-26547-7-git-send-email-david@gibson.dropbear.id.au> <1442508864.23936.208.camel@redhat.com> <20150917233157.GC2547@voom.fritz.box> <560286C8.3010903@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="DO5DiztRLs659m5i" Content-Disposition: inline In-Reply-To: <560286C8.3010903@redhat.com> Subject: Re: [Qemu-devel] [RFC PATCH 06/10] vfio: Allow hotplug of containers onto existing guest IOMMU mappings List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Thomas Huth Cc: lvivier@redhat.com, aik@ozlabs.ru, gwshan@linux.vnet.ibm.com, qemu-devel@nongnu.org, Alex Williamson , qemu-ppc@nongnu.org, pbonzini@redhat.com --DO5DiztRLs659m5i Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Sep 23, 2015 at 01:02:32PM +0200, Thomas Huth wrote: > On 18/09/15 01:31, David Gibson wrote: > > On Thu, Sep 17, 2015 at 10:54:24AM -0600, Alex Williamson wrote: > >> On Thu, 2015-09-17 at 23:09 +1000, David Gibson wrote: > >>> At present the memory listener used by vfio to keep host IOMMU mappin= gs > >>> in sync with the guest memory image assumes that if a guest IOMMU > >>> appears, then it has no existing mappings. > >>> > >>> 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. > >>> > >>> 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. > >>> > >>> Signed-off-by: David Gibson > >>> --- > >>> hw/vfio/common.c | 34 +++++++++++++++++++--------------- > >>> 1 file changed, 19 insertions(+), 15 deletions(-) > >>> > >>> diff --git a/hw/vfio/common.c b/hw/vfio/common.c > >>> index daaac48..543c38e 100644 > >>> --- a/hw/vfio/common.c > >>> +++ b/hw/vfio/common.c > >>> @@ -312,6 +312,22 @@ out: > >>> rcu_read_unlock(); > >>> } > >>> =20 > >>> +static hwaddr vfio_container_granularity(VFIOContainer *container) > >>> +{ > >>> + uint64_t pgsize; > >>> + > >>> + assert(container->iommu_data.iova_pgsizes); > >> > >> return (hwaddr)1 << (ffsl(container->iommu_data.iova_pgsizes) - 1; > >=20 > > Ah, yes, that should work. I didn't do it that way mostly because I > > tend to confuse myself when I try to remember exactly how ffs > > semantics work. >=20 > Maybe use ffsll instead of ffsl, in case the code ever runs on a 32-bit > host instead of a 64-bit host ? Already done :) --=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 --DO5DiztRLs659m5i Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJWAzreAAoJEGw4ysog2bOSbHAP/ibNFWRoDGUCjLQhJnQ6hAo+ 2cchYLaiO80n6k1ll+11fQ/DHYuEr6fS+2ywqPjyvhlOhiV6reoXrdSNUzxNWPQr sm5ZqdphmXn4qExT9pKaF1vGXrofiGqmlI6hzIn3Pc0o86cRpj8aq7vqCPkSVxkC hKIrv1AoZn3L7zypGEqApdiZlFtdg9RAXlznWzuZcWMA4Lty9a8Jf8yKPNQhFEMQ kGqdqPY8mcNAIx9MM5CnCIZwMdgy0jATCrqFCgu6wxa/+BdMEU3t96lbLPOheCmA 8Vp2Gl9p4wB/3LNsrJkr0nESZX1zX4UAnKHwEvWRWVGgPNqeEz7e8nvfNJOGVr+x TWv2PZeeLJuxuINkgAAA39EYKWXHf3tM+ho8kBCKSY4pQiQDBf94+bnLArnfNrku NDvZd65YriOq4psBHHMCUVEJKFgFvsgX9lgekNfbSON9FoXa5Y83Tev3bscN+z7F r88tEgby1+aaua6R+TtPyyywAXyhjVn1tpxkSir41G4vg71+qOHT5Y1f1c117PEk zDgrvLVJG4f8gWdj3bv/H+LqJ53g3XjXhlQ7w8PeSngZf4MCAUnDLrLqzYzf4eA/ DBMYShcRHVjNqmFKxvjYMN5pv9/dmgHm6Iiq2ZbY6IMYms4aBof2FyZYrUfqVgiB vLty0XKZanh2LcHD6iIq =Ljn7 -----END PGP SIGNATURE----- --DO5DiztRLs659m5i--