mirror of
https://github.com/Motorhead1991/qemu.git
synced 2026-02-11 19:39:26 -07:00
vfio/iommufd: reconstruct hwpt
Skip allocation of, and attachment to, hwpt_id. Recover it from CPR state. Signed-off-by: Steve Sistare <steven.sistare@oracle.com> Reviewed-by: Zhenzhong Duan <zhenzhong.duan@intel.com> Link: https://lore.kernel.org/qemu-devel/1751493538-202042-18-git-send-email-steven.sistare@oracle.com Signed-off-by: Cédric Le Goater <clg@redhat.com>
This commit is contained in:
parent
4296ee0745
commit
010643eeb1
1 changed files with 22 additions and 8 deletions
|
|
@ -332,7 +332,14 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *vbasedev,
|
|||
|
||||
/* Try to find a domain */
|
||||
QLIST_FOREACH(hwpt, &container->hwpt_list, next) {
|
||||
ret = iommufd_cdev_attach_ioas_hwpt(vbasedev, hwpt->hwpt_id, errp);
|
||||
if (!cpr_is_incoming()) {
|
||||
ret = iommufd_cdev_attach_ioas_hwpt(vbasedev, hwpt->hwpt_id, errp);
|
||||
} else if (vbasedev->cpr.hwpt_id == hwpt->hwpt_id) {
|
||||
ret = 0;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ret) {
|
||||
/* -EINVAL means the domain is incompatible with the device. */
|
||||
if (ret == -EINVAL) {
|
||||
|
|
@ -349,6 +356,7 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *vbasedev,
|
|||
return false;
|
||||
} else {
|
||||
vbasedev->hwpt = hwpt;
|
||||
vbasedev->cpr.hwpt_id = hwpt->hwpt_id;
|
||||
QLIST_INSERT_HEAD(&hwpt->device_list, vbasedev, hwpt_next);
|
||||
vbasedev->iommu_dirty_tracking = iommufd_hwpt_dirty_tracking(hwpt);
|
||||
return true;
|
||||
|
|
@ -371,6 +379,11 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *vbasedev,
|
|||
flags = IOMMU_HWPT_ALLOC_DIRTY_TRACKING;
|
||||
}
|
||||
|
||||
if (cpr_is_incoming()) {
|
||||
hwpt_id = vbasedev->cpr.hwpt_id;
|
||||
goto skip_alloc;
|
||||
}
|
||||
|
||||
if (!iommufd_backend_alloc_hwpt(iommufd, vbasedev->devid,
|
||||
container->ioas_id, flags,
|
||||
IOMMU_HWPT_DATA_NONE, 0, NULL,
|
||||
|
|
@ -378,19 +391,20 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *vbasedev,
|
|||
return false;
|
||||
}
|
||||
|
||||
ret = iommufd_cdev_attach_ioas_hwpt(vbasedev, hwpt_id, errp);
|
||||
if (ret) {
|
||||
iommufd_backend_free_id(container->be, hwpt_id);
|
||||
return false;
|
||||
}
|
||||
|
||||
skip_alloc:
|
||||
hwpt = g_malloc0(sizeof(*hwpt));
|
||||
hwpt->hwpt_id = hwpt_id;
|
||||
hwpt->hwpt_flags = flags;
|
||||
QLIST_INIT(&hwpt->device_list);
|
||||
|
||||
ret = iommufd_cdev_attach_ioas_hwpt(vbasedev, hwpt->hwpt_id, errp);
|
||||
if (ret) {
|
||||
iommufd_backend_free_id(container->be, hwpt->hwpt_id);
|
||||
g_free(hwpt);
|
||||
return false;
|
||||
}
|
||||
|
||||
vbasedev->hwpt = hwpt;
|
||||
vbasedev->cpr.hwpt_id = hwpt->hwpt_id;
|
||||
vbasedev->iommu_dirty_tracking = iommufd_hwpt_dirty_tracking(hwpt);
|
||||
QLIST_INSERT_HEAD(&hwpt->device_list, vbasedev, hwpt_next);
|
||||
QLIST_INSERT_HEAD(&container->hwpt_list, hwpt, next);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue