mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-05 00:33:55 -06:00
vfio/{iommufd, container}: Invoke HostIOMMUDevice::realize() during attach_device()
Move the HostIOMMUDevice::realize() to be invoked during the attach of the device before we allocate IOMMUFD hardware pagetable objects (HWPT). This allows the use of the hw_caps obtained by IOMMU_GET_HW_INFO that essentially tell if the IOMMU behind the device supports dirty tracking. Note: The HostIOMMUDevice data from legacy backend is static and doesn't need any information from the (type1-iommu) backend to be initialized. In contrast however, the IOMMUFD HostIOMMUDevice data requires the iommufd FD to be connected and having a devid to be able to successfully GET_HW_INFO. This means vfio_device_hiod_realize() is called in different places within the backend .attach_device() implementation. Suggested-by: Cédric Le Goater <clg@redhat.cm> Signed-off-by: Joao Martins <joao.m.martins@oracle.com> Reviewed-by: Zhenzhong Duan <zhenzhong.duan@intel.com> Reviewed-by: Cédric Le Goater <clg@redhat.com> [ clg: Fixed error handling in iommufd_cdev_attach() ] Signed-off-by: Cédric Le Goater <clg@redhat.com> Reviewed-by: Eric Auger <eric.auger@redhat.com>
This commit is contained in:
parent
21e8d3a3aa
commit
83a4d596a9
5 changed files with 35 additions and 12 deletions
|
@ -1536,7 +1536,7 @@ bool vfio_attach_device(char *name, VFIODevice *vbasedev,
|
|||
{
|
||||
const VFIOIOMMUClass *ops =
|
||||
VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_LEGACY));
|
||||
HostIOMMUDevice *hiod;
|
||||
HostIOMMUDevice *hiod = NULL;
|
||||
|
||||
if (vbasedev->iommufd) {
|
||||
ops = VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_IOMMUFD));
|
||||
|
@ -1544,21 +1544,17 @@ bool vfio_attach_device(char *name, VFIODevice *vbasedev,
|
|||
|
||||
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)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (vbasedev->mdev) {
|
||||
return true;
|
||||
}
|
||||
|
||||
hiod = HOST_IOMMU_DEVICE(object_new(ops->hiod_typename));
|
||||
if (!HOST_IOMMU_DEVICE_GET_CLASS(hiod)->realize(hiod, vbasedev, errp)) {
|
||||
object_unref(hiod);
|
||||
ops->detach_device(vbasedev);
|
||||
vbasedev->hiod = NULL;
|
||||
return false;
|
||||
}
|
||||
vbasedev->hiod = hiod;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue