>-----Original Message----- >From: Cédric Le Goater <c...@redhat.com> >Subject: Re: [PATCH v2 08/10] vfio: Create host IOMMU device instance > >On 4/8/24 10:12, Zhenzhong Duan wrote: >> Create host IOMMU device instance and initialize it based on backend. >> >> Signed-off-by: Zhenzhong Duan <zhenzhong.d...@intel.com> >> --- >> include/hw/vfio/vfio-common.h | 1 + >> hw/vfio/container.c | 5 +++++ >> hw/vfio/iommufd.c | 8 ++++++++ >> 3 files changed, 14 insertions(+) >> >> diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio- >common.h >> index d382b12ec1..4fbba85018 100644 >> --- a/include/hw/vfio/vfio-common.h >> +++ b/include/hw/vfio/vfio-common.h >> @@ -126,6 +126,7 @@ typedef struct VFIODevice { >> OnOffAuto pre_copy_dirty_page_tracking; >> bool dirty_pages_supported; >> bool dirty_tracking; >> + HostIOMMUDevice *hiod; >> int devid; >> IOMMUFDBackend *iommufd; >> } VFIODevice; >> diff --git a/hw/vfio/container.c b/hw/vfio/container.c >> index ba0ad4a41b..fc0c027501 100644 >> --- a/hw/vfio/container.c >> +++ b/hw/vfio/container.c >> @@ -915,6 +915,7 @@ static int vfio_legacy_attach_device(const char >*name, VFIODevice *vbasedev, >> VFIODevice *vbasedev_iter; >> VFIOGroup *group; >> VFIOContainerBase *bcontainer; >> + HIODLegacyVFIO *hiod_vfio; > >s/hiod_vfio/hiod/ please. Same below.
Will do. Thanks Zhenzhong > > >Thanks, > >C. > > > >> int ret; >> >> if (groupid < 0) { >> @@ -945,6 +946,9 @@ static int vfio_legacy_attach_device(const char >*name, VFIODevice *vbasedev, >> vbasedev->bcontainer = bcontainer; >> QLIST_INSERT_HEAD(&bcontainer->device_list, vbasedev, >container_next); >> QLIST_INSERT_HEAD(&vfio_device_list, vbasedev, global_next); >> + hiod_vfio = >HIOD_LEGACY_VFIO(object_new(TYPE_HIOD_LEGACY_VFIO)); >> + hiod_vfio->vdev = vbasedev; >> + vbasedev->hiod = HOST_IOMMU_DEVICE(hiod_vfio); >> >> return ret; >> } >> @@ -959,6 +963,7 @@ static void vfio_legacy_detach_device(VFIODevice >*vbasedev) >> trace_vfio_detach_device(vbasedev->name, group->groupid); >> vfio_put_base_device(vbasedev); >> vfio_put_group(group); >> + object_unref(vbasedev->hiod); >> } >> >> static int vfio_legacy_pci_hot_reset(VFIODevice *vbasedev, bool single) >> diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c >> index 115b9f8e7f..b6d058339b 100644 >> --- a/hw/vfio/iommufd.c >> +++ b/hw/vfio/iommufd.c >> @@ -308,6 +308,7 @@ static int iommufd_cdev_attach(const char *name, >VFIODevice *vbasedev, >> VFIOIOMMUFDContainer *container; >> VFIOAddressSpace *space; >> struct vfio_device_info dev_info = { .argsz = sizeof(dev_info) }; >> + HIODIOMMUFDVFIO *hiod_vfio; >> int ret, devfd; >> uint32_t ioas_id; >> Error *err = NULL; >> @@ -431,6 +432,12 @@ found_container: >> QLIST_INSERT_HEAD(&bcontainer->device_list, vbasedev, >container_next); >> QLIST_INSERT_HEAD(&vfio_device_list, vbasedev, global_next); >> >> + hiod_vfio = >HIOD_IOMMUFD_VFIO(object_new(TYPE_HIOD_IOMMUFD_VFIO)); >> + hiod_iommufd_init(HIOD_IOMMUFD(hiod_vfio), vbasedev->iommufd, >> + vbasedev->devid); >> + hiod_vfio->vdev = vbasedev; >> + vbasedev->hiod = HOST_IOMMU_DEVICE(hiod_vfio); >> + >> trace_iommufd_cdev_device_info(vbasedev->name, devfd, vbasedev- >>num_irqs, >> vbasedev->num_regions, vbasedev->flags); >> return 0; >> @@ -468,6 +475,7 @@ static void iommufd_cdev_detach(VFIODevice >*vbasedev) >> iommufd_cdev_detach_container(vbasedev, container); >> iommufd_cdev_container_destroy(container); >> vfio_put_address_space(space); >> + object_unref(vbasedev->hiod); >> >> iommufd_cdev_unbind_and_disconnect(vbasedev); >> close(vbasedev->fd);