From nobody Fri Oct 18 06:22:16 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=movementarian.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1717000168262233.4865270639383; Wed, 29 May 2024 09:29:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sCM7V-0001wn-4V; Wed, 29 May 2024 12:25:45 -0400 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 1sCM6y-0001BQ-IV for qemu-devel@nongnu.org; Wed, 29 May 2024 12:25:14 -0400 Received: from ssh.movementarian.org ([139.162.205.133] helo=movementarian.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sCM6v-0006KZ-D3 for qemu-devel@nongnu.org; Wed, 29 May 2024 12:25:12 -0400 Received: from movement by movementarian.org with local (Exim 4.95) (envelope-from ) id 1sCM6i-006COk-V7; Wed, 29 May 2024 17:24:56 +0100 From: John Levon To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, jag.raman@oracle.com, thanos.makatos@nutanix.com, John Levon Subject: [PATCH 05/26] vfio: add vfio_prepare_device() Date: Wed, 29 May 2024 17:22:58 +0100 Message-Id: <20240529162319.1476680-6-levon@movementarian.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240529162319.1476680-1-levon@movementarian.org> References: <20240529162319.1476680-1-levon@movementarian.org> MIME-Version: 1.0 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=139.162.205.133; envelope-from=movement@movementarian.org; helo=movementarian.org X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZM-MESSAGEID: 1717000168934100009 Content-Type: text/plain; charset="utf-8" From: John Levon Commonize some initialization code shared by the legacy and iommufd vfio implementations (and later by vfio-user). Signed-off-by: John Levon --- hw/vfio/common.c | 19 +++++++++++++++++++ hw/vfio/container.c | 14 +------------- hw/vfio/iommufd.c | 9 +-------- include/hw/vfio/vfio-common.h | 2 ++ 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 8c3b6ad75a..81f4c88f2d 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1542,6 +1542,25 @@ retry: return info; } =20 +void vfio_prepare_device(VFIODevice *vbasedev, VFIOContainerBase *bcontain= er, + VFIOGroup *group, struct vfio_device_info *info) +{ + vbasedev->group =3D group; + + vbasedev->num_irqs =3D info->num_irqs; + vbasedev->num_regions =3D info->num_regions; + vbasedev->flags =3D info->flags; + vbasedev->reset_works =3D !!(info->flags & VFIO_DEVICE_FLAGS_RESET); + + vbasedev->bcontainer =3D bcontainer; + QLIST_INSERT_HEAD(&bcontainer->device_list, vbasedev, container_next); + if (group) { + QLIST_INSERT_HEAD(&group->device_list, vbasedev, next); + } + + QLIST_INSERT_HEAD(&vfio_device_list, vbasedev, global_next); +} + bool vfio_attach_device_by_iommu_type(const char *iommu_type, char *name, VFIODevice *vbasedev, AddressSpace *= as, Error **errp) diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 27ddb894e9..1bbcbaa874 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -881,17 +881,11 @@ static bool vfio_get_device(VFIOGroup *group, const c= har *name, } =20 vbasedev->fd =3D fd; - vbasedev->group =3D group; - QLIST_INSERT_HEAD(&group->device_list, vbasedev, next); =20 - vbasedev->num_irqs =3D info->num_irqs; - vbasedev->num_regions =3D info->num_regions; - vbasedev->flags =3D info->flags; + vfio_prepare_device(vbasedev, &group->container->bcontainer, group, in= fo); =20 trace_vfio_get_device(name, info->flags, info->num_regions, info->num_= irqs); =20 - vbasedev->reset_works =3D !!(info->flags & VFIO_DEVICE_FLAGS_RESET); - return true; } =20 @@ -944,7 +938,6 @@ static bool vfio_legacy_attach_device(const char *name,= VFIODevice *vbasedev, int groupid =3D vfio_device_groupid(vbasedev, errp); VFIODevice *vbasedev_iter; VFIOGroup *group; - VFIOContainerBase *bcontainer; =20 if (groupid < 0) { return false; @@ -969,11 +962,6 @@ static bool vfio_legacy_attach_device(const char *name= , VFIODevice *vbasedev, return false; } =20 - bcontainer =3D &group->container->bcontainer; - vbasedev->bcontainer =3D bcontainer; - QLIST_INSERT_HEAD(&bcontainer->device_list, vbasedev, container_next); - QLIST_INSERT_HEAD(&vfio_device_list, vbasedev, global_next); - return true; } =20 diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 7bcadacd0b..dad83e45d7 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -425,14 +425,7 @@ found_container: iommufd_cdev_ram_block_discard_disable(false); } =20 - vbasedev->group =3D 0; - vbasedev->num_irqs =3D dev_info.num_irqs; - vbasedev->num_regions =3D dev_info.num_regions; - vbasedev->flags =3D dev_info.flags; - vbasedev->reset_works =3D !!(dev_info.flags & VFIO_DEVICE_FLAGS_RESET); - vbasedev->bcontainer =3D bcontainer; - QLIST_INSERT_HEAD(&bcontainer->device_list, vbasedev, container_next); - QLIST_INSERT_HEAD(&vfio_device_list, vbasedev, global_next); + vfio_prepare_device(vbasedev, bcontainer, NULL, &dev_info); =20 trace_iommufd_cdev_device_info(vbasedev->name, devfd, vbasedev->num_ir= qs, vbasedev->num_regions, vbasedev->flags); diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 8e13d30d2c..ee022c9cbd 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -223,6 +223,8 @@ void vfio_region_exit(VFIORegion *region); void vfio_region_finalize(VFIORegion *region); void vfio_reset_handler(void *opaque); struct vfio_device_info *vfio_get_device_info(int fd); +void vfio_prepare_device(VFIODevice *vbasedev, VFIOContainerBase *bcontain= er, + VFIOGroup *group, struct vfio_device_info *info); bool vfio_attach_device(char *name, VFIODevice *vbasedev, AddressSpace *as, Error **errp); bool vfio_attach_device_by_iommu_type(const char *iommu_type, char *name, --=20 2.34.1