From nobody Wed Nov 27 00:41:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1703012543150166.50488013185213; Tue, 19 Dec 2023 11:02:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rFfHe-0001zf-G3; Tue, 19 Dec 2023 13:57:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rFfHa-0001zD-UY for qemu-devel@nongnu.org; Tue, 19 Dec 2023 13:57:34 -0500 Received: from gandalf.ozlabs.org ([150.107.74.76]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rFfHY-00070N-Ny for qemu-devel@nongnu.org; Tue, 19 Dec 2023 13:57:34 -0500 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4SvmCZ5Ldmz4xCj; Wed, 20 Dec 2023 05:57:30 +1100 (AEDT) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4SvmCV0sdVz4wx5; Wed, 20 Dec 2023 05:57:25 +1100 (AEDT) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Eric Auger , Zhenzhong Duan , Peter Maydell , Richard Henderson , Nicholas Piggin , Harsh Prateek Bora , Thomas Huth , Eric Farman , Alex Williamson , Matthew Rosato , Yi Liu , Yi Sun , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 06/47] vfio/container: Move space field to base container Date: Tue, 19 Dec 2023 19:56:02 +0100 Message-ID: <20231219185643.725448-7-clg@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231219185643.725448-1-clg@redhat.com> References: <20231219185643.725448-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=150.107.74.76; envelope-from=SRS0=7/MV=H6=redhat.com=clg@ozlabs.org; helo=gandalf.ozlabs.org X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1703012544742100007 From: Eric Auger Move the space field to the base object. Also the VFIOAddressSpace now contains a list of base containers. No functional change intended. Signed-off-by: Eric Auger Signed-off-by: Yi Liu Signed-off-by: Yi Sun Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-common.h | 8 -------- include/hw/vfio/vfio-container-base.h | 9 +++++++++ hw/ppc/spapr_pci_vfio.c | 10 +++++----- hw/vfio/common.c | 4 ++-- hw/vfio/container-base.c | 6 +++++- hw/vfio/container.c | 18 ++++++++---------- 6 files changed, 29 insertions(+), 26 deletions(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 6be082b8f20c2dfa28dbed85c343667ea20e2b73..bd4de6cb3aff7cb85e34960fe42= 38d82b30867cd 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -73,17 +73,10 @@ typedef struct VFIOMigration { bool initial_data_sent; } VFIOMigration; =20 -typedef struct VFIOAddressSpace { - AddressSpace *as; - QLIST_HEAD(, VFIOContainer) containers; - QLIST_ENTRY(VFIOAddressSpace) list; -} VFIOAddressSpace; - struct VFIOGroup; =20 typedef struct VFIOContainer { VFIOContainerBase bcontainer; - VFIOAddressSpace *space; int fd; /* /dev/vfio/vfio, empowered by the attached groups */ MemoryListener listener; MemoryListener prereg_listener; @@ -98,7 +91,6 @@ typedef struct VFIOContainer { QLIST_HEAD(, VFIOHostDMAWindow) hostwin_list; QLIST_HEAD(, VFIOGroup) group_list; QLIST_HEAD(, VFIORamDiscardListener) vrdl_list; - QLIST_ENTRY(VFIOContainer) next; QLIST_HEAD(, VFIODevice) device_list; GList *iova_ranges; } VFIOContainer; diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-c= ontainer-base.h index a11aec575544d7a4f29c0e33200ed962568372cf..c7cc6ec9c55e93e4f7c6be5576e= d59b5dea58b1e 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -24,12 +24,20 @@ typedef struct { hwaddr pages; } VFIOBitmap; =20 +typedef struct VFIOAddressSpace { + AddressSpace *as; + QLIST_HEAD(, VFIOContainerBase) containers; + QLIST_ENTRY(VFIOAddressSpace) list; +} VFIOAddressSpace; + /* * This is the base object for vfio container backends */ typedef struct VFIOContainerBase { const VFIOIOMMUOps *ops; + VFIOAddressSpace *space; QLIST_HEAD(, VFIOGuestIOMMU) giommu_list; + QLIST_ENTRY(VFIOContainerBase) next; } VFIOContainerBase; =20 typedef struct VFIOGuestIOMMU { @@ -48,6 +56,7 @@ int vfio_container_dma_unmap(VFIOContainerBase *bcontaine= r, IOMMUTLBEntry *iotlb); =20 void vfio_container_init(VFIOContainerBase *bcontainer, + VFIOAddressSpace *space, const VFIOIOMMUOps *ops); void vfio_container_destroy(VFIOContainerBase *bcontainer); =20 diff --git a/hw/ppc/spapr_pci_vfio.c b/hw/ppc/spapr_pci_vfio.c index f283f7e38d619fd65985146b5e1572c221f95c53..d1d07bec4644da4ae6a99d3357d= 6d17ff66264de 100644 --- a/hw/ppc/spapr_pci_vfio.c +++ b/hw/ppc/spapr_pci_vfio.c @@ -84,27 +84,27 @@ static int vfio_eeh_container_op(VFIOContainer *contain= er, uint32_t op) static VFIOContainer *vfio_eeh_as_container(AddressSpace *as) { VFIOAddressSpace *space =3D vfio_get_address_space(as); - VFIOContainer *container =3D NULL; + VFIOContainerBase *bcontainer =3D NULL; =20 if (QLIST_EMPTY(&space->containers)) { /* No containers to act on */ goto out; } =20 - container =3D QLIST_FIRST(&space->containers); + bcontainer =3D QLIST_FIRST(&space->containers); =20 - if (QLIST_NEXT(container, next)) { + if (QLIST_NEXT(bcontainer, next)) { /* * We don't yet have logic to synchronize EEH state across * multiple containers */ - container =3D NULL; + bcontainer =3D NULL; goto out; } =20 out: vfio_put_address_space(space); - return container; + return container_of(bcontainer, VFIOContainer, bcontainer); } =20 static bool vfio_eeh_as_ok(AddressSpace *as) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 43580bcc43c72336a50b002e17f4415035aa8798..1d8202537ea4f27f49f2d477537= d6c7c557bd61f 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -145,7 +145,7 @@ void vfio_unblock_multiple_devices_migration(void) =20 bool vfio_viommu_preset(VFIODevice *vbasedev) { - return vbasedev->container->space->as !=3D &address_space_memory; + return vbasedev->container->bcontainer.space->as !=3D &address_space_m= emory; } =20 static void vfio_set_migration_error(int err) @@ -922,7 +922,7 @@ static void vfio_dirty_tracking_init(VFIOContainer *con= tainer, dirty.container =3D container; =20 memory_listener_register(&dirty.listener, - container->space->as); + container->bcontainer.space->as); =20 *ranges =3D dirty.ranges; =20 diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c index 20bcb9669a6122f951119c025b9950854c53f88e..3933391e0db26116401509c5917= eaceabcd98443 100644 --- a/hw/vfio/container-base.c +++ b/hw/vfio/container-base.c @@ -31,9 +31,11 @@ int vfio_container_dma_unmap(VFIOContainerBase *bcontain= er, return bcontainer->ops->dma_unmap(bcontainer, iova, size, iotlb); } =20 -void vfio_container_init(VFIOContainerBase *bcontainer, const VFIOIOMMUOps= *ops) +void vfio_container_init(VFIOContainerBase *bcontainer, VFIOAddressSpace *= space, + const VFIOIOMMUOps *ops) { bcontainer->ops =3D ops; + bcontainer->space =3D space; QLIST_INIT(&bcontainer->giommu_list); } =20 @@ -41,6 +43,8 @@ void vfio_container_destroy(VFIOContainerBase *bcontainer) { VFIOGuestIOMMU *giommu, *tmp; =20 + QLIST_REMOVE(bcontainer, next); + QLIST_FOREACH_SAFE(giommu, &bcontainer->giommu_list, giommu_next, tmp)= { memory_region_unregister_iommu_notifier( MEMORY_REGION(giommu->iommu_mr), &giommu->n); diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 133d3c8f5c08e6476cebb3c707ebd115a068af2d..f12fcb6fe11d578838b1052f70e= e5099b9018e94 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -514,7 +514,8 @@ static int vfio_connect_container(VFIOGroup *group, Add= ressSpace *as, * details once we know which type of IOMMU we are using. */ =20 - QLIST_FOREACH(container, &space->containers, next) { + QLIST_FOREACH(bcontainer, &space->containers, next) { + container =3D container_of(bcontainer, VFIOContainer, bcontainer); if (!ioctl(group->fd, VFIO_GROUP_SET_CONTAINER, &container->fd)) { ret =3D vfio_ram_block_discard_disable(container, true); if (ret) { @@ -550,7 +551,6 @@ static int vfio_connect_container(VFIOGroup *group, Add= ressSpace *as, } =20 container =3D g_malloc0(sizeof(*container)); - container->space =3D space; container->fd =3D fd; container->error =3D NULL; container->dirty_pages_supported =3D false; @@ -558,7 +558,7 @@ static int vfio_connect_container(VFIOGroup *group, Add= ressSpace *as, container->iova_ranges =3D NULL; QLIST_INIT(&container->vrdl_list); bcontainer =3D &container->bcontainer; - vfio_container_init(bcontainer, &vfio_legacy_ops); + vfio_container_init(bcontainer, space, &vfio_legacy_ops); =20 ret =3D vfio_init_container(container, group->fd, errp); if (ret) { @@ -613,14 +613,14 @@ static int vfio_connect_container(VFIOGroup *group, A= ddressSpace *as, vfio_kvm_device_add_group(group); =20 QLIST_INIT(&container->group_list); - QLIST_INSERT_HEAD(&space->containers, container, next); + QLIST_INSERT_HEAD(&space->containers, bcontainer, next); =20 group->container =3D container; QLIST_INSERT_HEAD(&container->group_list, group, container_next); =20 container->listener =3D vfio_memory_listener; =20 - memory_listener_register(&container->listener, container->space->as); + memory_listener_register(&container->listener, bcontainer->space->as); =20 if (container->error) { ret =3D -1; @@ -634,7 +634,7 @@ static int vfio_connect_container(VFIOGroup *group, Add= ressSpace *as, return 0; listener_release_exit: QLIST_REMOVE(group, container_next); - QLIST_REMOVE(container, next); + QLIST_REMOVE(bcontainer, next); vfio_kvm_device_del_group(group); memory_listener_unregister(&container->listener); if (container->iommu_type =3D=3D VFIO_SPAPR_TCE_v2_IOMMU || @@ -684,9 +684,7 @@ static void vfio_disconnect_container(VFIOGroup *group) } =20 if (QLIST_EMPTY(&container->group_list)) { - VFIOAddressSpace *space =3D container->space; - - QLIST_REMOVE(container, next); + VFIOAddressSpace *space =3D bcontainer->space; =20 vfio_container_destroy(bcontainer); =20 @@ -707,7 +705,7 @@ static VFIOGroup *vfio_get_group(int groupid, AddressSp= ace *as, Error **errp) QLIST_FOREACH(group, &vfio_group_list, next) { if (group->groupid =3D=3D groupid) { /* Found it. Now is it already in the right context? */ - if (group->container->space->as =3D=3D as) { + if (group->container->bcontainer.space->as =3D=3D as) { return group; } else { error_setg(errp, "group %d used in multiple address spaces= ", --=20 2.43.0