From nobody Tue Nov 26 22:28:46 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 1704699334995448.25613684292216; Sun, 7 Jan 2024 23:35:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rMk8A-0003BL-EF; Mon, 08 Jan 2024 02:33:06 -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 1rMk88-00039T-Mq for qemu-devel@nongnu.org; Mon, 08 Jan 2024 02:33:04 -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 1rMk85-0004aS-8p for qemu-devel@nongnu.org; Mon, 08 Jan 2024 02:33:04 -0500 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4T7m4W5nH3z4wy9; Mon, 8 Jan 2024 18:32:59 +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 4T7m4T5Y4Wz4wcc; Mon, 8 Jan 2024 18:32:57 +1100 (AEDT) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Eric Auger , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Zhenzhong Duan , Eric Farman Subject: [PULL 08/17] vfio/iommufd: Introduce a VFIOIOMMU iommufd QOM interface Date: Mon, 8 Jan 2024 08:32:23 +0100 Message-ID: <20240108073232.118228-9-clg@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240108073232.118228-1-clg@redhat.com> References: <20240108073232.118228-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=P3fH=IS=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.248, 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: 1704699335236100004 As previously done for the sPAPR and legacy IOMMU backends, convert the VFIOIOMMUOps struct to a QOM interface. The set of of operations for this backend can be referenced with a literal typename instead of a C struct. Reviewed-by: Zhenzhong Duan Tested-by: Eric Farman Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-common.h | 1 - include/hw/vfio/vfio-container-base.h | 2 +- hw/vfio/common.c | 2 +- hw/vfio/iommufd.c | 35 ++++++++++++++++++++------- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 14c497b6b0a79466e8f567aceed384ec2c75ea90..9b7ef7d02b5a0ad5266bcc4d06c= d6874178978e4 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -210,7 +210,6 @@ typedef QLIST_HEAD(VFIOGroupList, VFIOGroup) VFIOGroupL= ist; typedef QLIST_HEAD(VFIODeviceList, VFIODevice) VFIODeviceList; extern VFIOGroupList vfio_group_list; extern VFIODeviceList vfio_device_list; -extern const VFIOIOMMUOps vfio_iommufd_ops; extern const MemoryListener vfio_memory_listener; extern int vfio_kvm_device_fd; =20 diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-c= ontainer-base.h index 9e21d7811f3810ca2c63d9f28bdcc9aa6f75f9ad..b2813b0c117985425c842d91f01= 1bb895955d738 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -17,7 +17,6 @@ =20 typedef struct VFIODevice VFIODevice; typedef struct VFIOIOMMUClass VFIOIOMMUClass; -#define VFIOIOMMUOps VFIOIOMMUClass /* To remove */ =20 typedef struct { unsigned long *bitmap; @@ -96,6 +95,7 @@ void vfio_container_destroy(VFIOContainerBase *bcontainer= ); #define TYPE_VFIO_IOMMU "vfio-iommu" #define TYPE_VFIO_IOMMU_LEGACY TYPE_VFIO_IOMMU "-legacy" #define TYPE_VFIO_IOMMU_SPAPR TYPE_VFIO_IOMMU "-spapr" +#define TYPE_VFIO_IOMMU_IOMMUFD TYPE_VFIO_IOMMU "-iommufd" =20 /* * VFIOContainerBase is not an abstract QOM object because it felt diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 2329d0efc8c1d617f0bfee5283e82b295d2d477d..89ff1c7aeda14d20b2e24f8bc25= 1db0a71d4527c 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1508,7 +1508,7 @@ int vfio_attach_device(char *name, VFIODevice *vbased= ev, =20 #ifdef CONFIG_IOMMUFD if (vbasedev->iommufd) { - ops =3D &vfio_iommufd_ops; + ops =3D VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_IOMM= UFD)); } #endif =20 diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 87a561c54580adc6d7b2711331a00940ff13bd43..d4c586e842def8f04d3a914843f= 5eece2c75ea30 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -319,6 +319,8 @@ static int iommufd_cdev_attach(const char *name, VFIODe= vice *vbasedev, int ret, devfd; uint32_t ioas_id; Error *err =3D NULL; + const VFIOIOMMUClass *iommufd_vioc =3D + VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_IOMMUFD)); =20 if (vbasedev->fd < 0) { devfd =3D iommufd_cdev_getfd(vbasedev->sysfsdev, errp); @@ -340,7 +342,7 @@ static int iommufd_cdev_attach(const char *name, VFIODe= vice *vbasedev, /* try to attach to an existing container in this space */ QLIST_FOREACH(bcontainer, &space->containers, next) { container =3D container_of(bcontainer, VFIOIOMMUFDContainer, bcont= ainer); - if (bcontainer->ops !=3D &vfio_iommufd_ops || + if (bcontainer->ops !=3D iommufd_vioc || vbasedev->iommufd !=3D container->be) { continue; } @@ -374,7 +376,7 @@ static int iommufd_cdev_attach(const char *name, VFIODe= vice *vbasedev, container->ioas_id =3D ioas_id; =20 bcontainer =3D &container->bcontainer; - vfio_container_init(bcontainer, space, &vfio_iommufd_ops); + vfio_container_init(bcontainer, space, iommufd_vioc); QLIST_INSERT_HEAD(&space->containers, bcontainer, next); =20 ret =3D iommufd_cdev_attach_container(vbasedev, container, errp); @@ -476,9 +478,11 @@ static void iommufd_cdev_detach(VFIODevice *vbasedev) static VFIODevice *iommufd_cdev_pci_find_by_devid(__u32 devid) { VFIODevice *vbasedev_iter; + const VFIOIOMMUClass *iommufd_vioc =3D + VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_IOMMUFD)); =20 QLIST_FOREACH(vbasedev_iter, &vfio_device_list, global_next) { - if (vbasedev_iter->bcontainer->ops !=3D &vfio_iommufd_ops) { + if (vbasedev_iter->bcontainer->ops !=3D iommufd_vioc) { continue; } if (devid =3D=3D vbasedev_iter->devid) { @@ -621,10 +625,23 @@ out_single: return ret; } =20 -const VFIOIOMMUOps vfio_iommufd_ops =3D { - .dma_map =3D iommufd_cdev_map, - .dma_unmap =3D iommufd_cdev_unmap, - .attach_device =3D iommufd_cdev_attach, - .detach_device =3D iommufd_cdev_detach, - .pci_hot_reset =3D iommufd_cdev_pci_hot_reset, +static void vfio_iommu_iommufd_class_init(ObjectClass *klass, void *data) +{ + VFIOIOMMUClass *vioc =3D VFIO_IOMMU_CLASS(klass); + + vioc->dma_map =3D iommufd_cdev_map; + vioc->dma_unmap =3D iommufd_cdev_unmap; + vioc->attach_device =3D iommufd_cdev_attach; + vioc->detach_device =3D iommufd_cdev_detach; + vioc->pci_hot_reset =3D iommufd_cdev_pci_hot_reset; }; + +static const TypeInfo types[] =3D { + { + .name =3D TYPE_VFIO_IOMMU_IOMMUFD, + .parent =3D TYPE_VFIO_IOMMU, + .class_init =3D vfio_iommu_iommufd_class_init, + }, +}; + +DEFINE_TYPES(types) --=20 2.43.0