]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iommufd/viommu: Roll back to use iommufd_object_alloc() for vdevice
authorXu Yilun <yilun.xu@linux.intel.com>
Wed, 16 Jul 2025 07:03:42 +0000 (15:03 +0800)
committerJason Gunthorpe <jgg@nvidia.com>
Fri, 18 Jul 2025 20:33:07 +0000 (17:33 -0300)
To solve the vdevice lifecycle issue, future patches make the vdevice
allocation protected by lock. That will make
_iommufd_object_alloc_ucmd() not applicable for vdevice. Roll back to
use _iommufd_object_alloc() for preparation.

Link: https://patch.msgid.link/r/20250716070349.1807226-2-yilun.xu@linux.intel.com
Reviewed-by: Nicolin Chen <nicolinc@nvidia.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Tested-by: Nicolin Chen <nicolinc@nvidia.com>
Signed-off-by: Xu Yilun <yilun.xu@linux.intel.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/iommu/iommufd/viommu.c

index 91339f7999161f165c33f52b3588aae0f60b3744..dcf8a85b9f6ec2f217ca8bdaa2e2486f94cf3db0 100644 (file)
@@ -167,8 +167,8 @@ int iommufd_vdevice_alloc_ioctl(struct iommufd_ucmd *ucmd)
                vdev_size = viommu->ops->vdevice_size;
        }
 
-       vdev = (struct iommufd_vdevice *)_iommufd_object_alloc_ucmd(
-               ucmd, vdev_size, IOMMUFD_OBJ_VDEVICE);
+       vdev = (struct iommufd_vdevice *)_iommufd_object_alloc(
+               ucmd->ictx, vdev_size, IOMMUFD_OBJ_VDEVICE);
        if (IS_ERR(vdev)) {
                rc = PTR_ERR(vdev);
                goto out_put_idev;
@@ -183,18 +183,24 @@ int iommufd_vdevice_alloc_ioctl(struct iommufd_ucmd *ucmd)
        curr = xa_cmpxchg(&viommu->vdevs, virt_id, NULL, vdev, GFP_KERNEL);
        if (curr) {
                rc = xa_err(curr) ?: -EEXIST;
-               goto out_put_idev;
+               goto out_abort;
        }
 
        if (viommu->ops && viommu->ops->vdevice_init) {
                rc = viommu->ops->vdevice_init(vdev);
                if (rc)
-                       goto out_put_idev;
+                       goto out_abort;
        }
 
        cmd->out_vdevice_id = vdev->obj.id;
        rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd));
+       if (rc)
+               goto out_abort;
+       iommufd_object_finalize(ucmd->ictx, &vdev->obj);
+       goto out_put_idev;
 
+out_abort:
+       iommufd_object_abort_and_destroy(ucmd->ictx, &vdev->obj);
 out_put_idev:
        iommufd_put_object(ucmd->ictx, &idev->obj);
 out_put_viommu: