goto group_put_exit;
}
- if (!vfio_device_hiod_realize(vbasedev, errp)) {
+ if (!vfio_device_hiod_create_and_realize(vbasedev,
+ TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO,
+ errp)) {
goto device_put_exit;
}
QLIST_REMOVE(vbasedev, container_next);
vbasedev->bcontainer = NULL;
trace_vfio_device_detach(vbasedev->name, group->groupid);
+ object_unref(vbasedev->hiod);
vfio_device_put(vbasedev);
vfio_group_put(group);
}
return subsys && (strcmp(subsys, "/sys/bus/mdev") == 0);
}
-bool vfio_device_hiod_realize(VFIODevice *vbasedev, Error **errp)
+bool vfio_device_hiod_create_and_realize(VFIODevice *vbasedev,
+ const char *typename, Error **errp)
{
- HostIOMMUDevice *hiod = vbasedev->hiod;
+ HostIOMMUDevice *hiod;
- if (!hiod) {
+ if (vbasedev->mdev) {
return true;
}
- return HOST_IOMMU_DEVICE_GET_CLASS(hiod)->realize(hiod, vbasedev, errp);
+ hiod = HOST_IOMMU_DEVICE(object_new(typename));
+
+ if (!HOST_IOMMU_DEVICE_GET_CLASS(hiod)->realize(hiod, vbasedev, errp)) {
+ object_unref(hiod);
+ return false;
+ }
+
+ vbasedev->hiod = hiod;
+ return true;
}
VFIODevice *vfio_get_vfio_device(Object *obj)
{
const VFIOIOMMUClass *ops =
VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_LEGACY));
- HostIOMMUDevice *hiod = NULL;
if (vbasedev->iommufd) {
ops = VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_IOMMUFD));
assert(ops);
-
- if (!vbasedev->mdev) {
- hiod = HOST_IOMMU_DEVICE(object_new(ops->hiod_typename));
- vbasedev->hiod = hiod;
- }
-
- if (!ops->attach_device(name, vbasedev, as, errp)) {
- object_unref(hiod);
- vbasedev->hiod = NULL;
- return false;
- }
-
- return true;
+ return ops->attach_device(name, vbasedev, as, errp);
}
void vfio_device_detach(VFIODevice *vbasedev)
if (!vbasedev->bcontainer) {
return;
}
- object_unref(vbasedev->hiod);
VFIO_IOMMU_GET_CLASS(vbasedev->bcontainer)->detach_device(vbasedev);
}
goto err_listener_register;
}
- if (!vfio_device_hiod_realize(vbasedev, errp)) {
+ if (!vfio_device_hiod_create_and_realize(vbasedev,
+ TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO, errp)) {
goto err_hiod_realize;
}
iommufd_cdev_ram_block_discard_disable(false);
}
+ object_unref(vbasedev->hiod);
vfio_cpr_unregister_container(bcontainer);
iommufd_cdev_detach_container(vbasedev, container);
iommufd_cdev_container_destroy(container);
void vfio_device_reset_handler(void *opaque);
bool vfio_device_is_mdev(VFIODevice *vbasedev);
-bool vfio_device_hiod_realize(VFIODevice *vbasedev, Error **errp);
+bool vfio_device_hiod_create_and_realize(VFIODevice *vbasedev,
+ const char *typename, Error **errp);
bool vfio_device_attach(char *name, VFIODevice *vbasedev,
AddressSpace *as, Error **errp);
void vfio_device_detach(VFIODevice *vbasedev);