From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:59770) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UcQlw-0004HJ-Li for qemu-devel@nongnu.org; Tue, 14 May 2013 21:44:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UcQlr-0007dE-LP for qemu-devel@nongnu.org; Tue, 14 May 2013 21:44:52 -0400 Date: Wed, 15 May 2013 11:18:05 +1000 From: David Gibson Message-ID: <20130515011805.GM14944@truffula.fritz.box> References: <1368522837-20747-1-git-send-email-david@gibson.dropbear.id.au> <1368522837-20747-8-git-send-email-david@gibson.dropbear.id.au> <1368550392.5520.116.camel@ul30vt.home> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="CKf/2jVYos1l2hij" Content-Disposition: inline In-Reply-To: <1368550392.5520.116.camel@ul30vt.home> Subject: Re: [Qemu-devel] [Qemu-ppc] [PATCH 07/11] vfio: Introduce VFIO address spaces List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alex Williamson Cc: pbonzini@redhat.com, qemu-ppc@nongnu.org, qemu-devel@nongnu.org, mst@redhat.com --CKf/2jVYos1l2hij Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, May 14, 2013 at 10:53:12AM -0600, Alex Williamson wrote: > On Tue, 2013-05-14 at 19:13 +1000, David Gibson wrote: > > The only model so far supported for VFIO passthrough devices is the mod= el > > usually used on x86, where all of the guest's RAM is mapped into the > > (host) IOMMU and there is no IOMMU visible in the guest. > >=20 > > This patch begins to relax this model, introducing the notion of a > > VFIOAddressSpace. This represents a logical DMA address space which wi= ll > > be visible to one or more VFIO devices by appropriate mapping in the (h= ost) > > IOMMU. Thus the currently global list of containers becomes local to > > a VFIOAddressSpace, and we verify that we don't attempt to add a VFIO > > group to multiple address spaces. > >=20 > > For now, only one VFIOAddressSpace is created and used, corresponding to > > main system memory, that will change in future patches. > >=20 > > Signed-off-by: David Gibson > > --- > > hw/misc/vfio.c | 63 ++++++++++++++++++++++++++++++++++++++++++------= -------- > > 1 file changed, 48 insertions(+), 15 deletions(-) > >=20 > > diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c > > index c4a8853..e557f69 100644 > > --- a/hw/misc/vfio.c > > +++ b/hw/misc/vfio.c > > @@ -113,9 +113,17 @@ enum { > > VFIO_INT_MSIX =3D 3, > > }; > > =20 > > +typedef struct VFIOAddressSpace { > > + AddressSpace *as; > > + QLIST_HEAD(, VFIOContainer) containers; > > +} VFIOAddressSpace; > > + > > +static VFIOAddressSpace vfio_address_space_memory; > > + > > struct VFIOGroup; > > =20 > > typedef struct VFIOContainer { > > + VFIOAddressSpace *space; > > int fd; /* /dev/vfio/vfio, empowered by the attached groups */ > > struct { > > /* enable abstraction to support various iommu backends */ > > @@ -178,9 +186,6 @@ typedef struct VFIOGroup { > > =20 > > #define MSIX_CAP_LENGTH 12 > > =20 > > -static QLIST_HEAD(, VFIOContainer) > > - container_list =3D QLIST_HEAD_INITIALIZER(container_list); > > - > > static QLIST_HEAD(, VFIOGroup) > > group_list =3D QLIST_HEAD_INITIALIZER(group_list); > > =20 > > @@ -2624,16 +2629,28 @@ static int vfio_load_rom(VFIODevice *vdev) > > return 0; > > } > > =20 > > -static int vfio_connect_container(VFIOGroup *group) > > +static void vfio_address_space_init(VFIOAddressSpace *space, AddressSp= ace *as) > > +{ > > + space->as =3D as; > > + QLIST_INIT(&space->containers); > > +} > > + > > +static int vfio_connect_container(VFIOGroup *group, VFIOAddressSpace *= space) > > { > > VFIOContainer *container; > > int ret, fd; > > =20 > > if (group->container) { > > - return 0; > > + if (group->container->space =3D=3D space) { > > + return 0; > > + } else { > > + error_report("vfio: group %d used in multiple address spac= es", > > + group->groupid); > > + return -EBUSY; > > + } > > } > > =20 > > - QLIST_FOREACH(container, &container_list, next) { > > + QLIST_FOREACH(container, &space->containers, next) { > > if (!ioctl(group->fd, VFIO_GROUP_SET_CONTAINER, &container->fd= )) { > > group->container =3D container; > > QLIST_INSERT_HEAD(&container->group_list, group, container= _next); > > @@ -2656,6 +2673,7 @@ static int vfio_connect_container(VFIOGroup *grou= p) > > } > > =20 > > container =3D g_malloc0(sizeof(*container)); > > + container->space =3D space; > > container->fd =3D fd; > > =20 > > if (ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU)) { > > @@ -2678,7 +2696,8 @@ static int vfio_connect_container(VFIOGroup *grou= p) > > container->iommu_data.listener =3D vfio_memory_listener; > > container->iommu_data.release =3D vfio_listener_release; > > =20 > > - memory_listener_register(&container->iommu_data.listener, &add= ress_space_memory); > > + memory_listener_register(&container->iommu_data.listener, > > + container->space->as); > > } else { > > error_report("vfio: No available IOMMU models"); > > g_free(container); > > @@ -2687,7 +2706,7 @@ static int vfio_connect_container(VFIOGroup *grou= p) > > } > > =20 > > QLIST_INIT(&container->group_list); > > - QLIST_INSERT_HEAD(&container_list, container, next); > > + QLIST_INSERT_HEAD(&space->containers, container, next); > > =20 > > group->container =3D container; > > QLIST_INSERT_HEAD(&container->group_list, group, container_next); > > @@ -2700,7 +2719,7 @@ static void vfio_disconnect_container(VFIOGroup *= group) > > VFIOContainer *container =3D group->container; > > =20 > > if (ioctl(group->fd, VFIO_GROUP_UNSET_CONTAINER, &container->fd)) { > > - error_report("vfio: error disconnecting group %d from containe= r", > > + error_report("vfio: error disconnecting group %d from context", > > group->groupid); > > } > > =20 > > @@ -2712,13 +2731,13 @@ static void vfio_disconnect_container(VFIOGroup= *group) > > container->iommu_data.release(container); > > } > > QLIST_REMOVE(container, next); > > - DPRINTF("vfio_disconnect_container: close container->fd\n"); > > + DPRINTF("vfio_disconnect: close container->fd\n"); > > close(container->fd); > > g_free(container); > > } > > } >=20 > Drop the above two chunks. > =20 > > -static VFIOGroup *vfio_get_group(int groupid) > > +static VFIOGroup *vfio_get_group(int groupid, VFIOAddressSpace *space) > > { > > VFIOGroup *group; > > char path[32]; > > @@ -2726,7 +2745,15 @@ static VFIOGroup *vfio_get_group(int groupid) > > =20 > > QLIST_FOREACH(group, &group_list, next) { > > if (group->groupid =3D=3D groupid) { > > - return group; > > + /* Found it. Now is it already in the right context? */ > > + assert(group->container); > > + if (group->container->space =3D=3D space) { > > + return group; > > + } else { > > + error_report("vfio: group %d used in multiple address = spaces", > > + group->groupid); > > + return NULL; > > + } > > } > > } > > =20 > > @@ -2759,8 +2786,8 @@ static VFIOGroup *vfio_get_group(int groupid) > > group->groupid =3D groupid; > > QLIST_INIT(&group->device_list); > > =20 > > - if (vfio_connect_container(group)) { > > - error_report("vfio: failed to setup container for group %d", g= roupid); > > + if (vfio_connect_container(group, space)) { > > + error_report("vfio: failed to setup context for group %d", gro= upid); >=20 > s/container/context/ is unnecessary now. Ah, yes, fixed. --=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 --CKf/2jVYos1l2hij Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAlGS4k0ACgkQaILKxv3ab8Z43ACbBQSYHr88NL5/sVph6H/2ZxLY NsMAn1MmiGCjmCLUQfNYCoM95WQRMEf0 =qNQo -----END PGP SIGNATURE----- --CKf/2jVYos1l2hij--