]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iommufd: Apply the new iommufd_object_alloc_ucmd helper
authorNicolin Chen <nicolinc@nvidia.com>
Sat, 14 Jun 2025 06:35:26 +0000 (23:35 -0700)
committerJason Gunthorpe <jgg@nvidia.com>
Thu, 19 Jun 2025 18:43:30 +0000 (15:43 -0300)
Now the new ucmd-based object allocator eases the finalize/abort routine,
apply this to all existing allocators that aren't protected by any lock.

Upgrade the for-driver vIOMMU alloctor too, and pass down to all existing
viommu_alloc op accordingly.

Note that __iommufd_object_alloc_ucmd() builds in some static tests that
cover both static_asserts in the iommufd_viommu_alloc(). Thus drop them.

Link: https://patch.msgid.link/r/107b24a3b791091bb09c92ffb0081c56c413b26d.1749882255.git.nicolinc@nvidia.com
Suggested-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/iommu/iommufd/eventq.c
drivers/iommu/iommufd/viommu.c

index e373b9eec7f5f54509164f4c4770eb24125a7f77..fc4de63b0bce64898cde893aed44872fc79c59a2 100644 (file)
@@ -427,8 +427,8 @@ int iommufd_fault_alloc(struct iommufd_ucmd *ucmd)
        if (cmd->flags)
                return -EOPNOTSUPP;
 
-       fault = __iommufd_object_alloc(ucmd->ictx, fault, IOMMUFD_OBJ_FAULT,
-                                      common.obj);
+       fault = __iommufd_object_alloc_ucmd(ucmd, fault, IOMMUFD_OBJ_FAULT,
+                                           common.obj);
        if (IS_ERR(fault))
                return PTR_ERR(fault);
 
@@ -437,10 +437,8 @@ int iommufd_fault_alloc(struct iommufd_ucmd *ucmd)
 
        fdno = iommufd_eventq_init(&fault->common, "[iommufd-pgfault]",
                                   ucmd->ictx, &iommufd_fault_fops);
-       if (fdno < 0) {
-               rc = fdno;
-               goto out_abort;
-       }
+       if (fdno < 0)
+               return fdno;
 
        cmd->out_fault_id = fault->common.obj.id;
        cmd->out_fault_fd = fdno;
@@ -448,7 +446,6 @@ int iommufd_fault_alloc(struct iommufd_ucmd *ucmd)
        rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd));
        if (rc)
                goto out_put_fdno;
-       iommufd_object_finalize(ucmd->ictx, &fault->common.obj);
 
        fd_install(fdno, fault->common.filep);
 
@@ -456,9 +453,6 @@ int iommufd_fault_alloc(struct iommufd_ucmd *ucmd)
 out_put_fdno:
        put_unused_fd(fdno);
        fput(fault->common.filep);
-out_abort:
-       iommufd_object_abort_and_destroy(ucmd->ictx, &fault->common.obj);
-
        return rc;
 }
 
index 044e3ef06e0f4c6487977fef2d26fc16cb75e1ee..25ac08fbb52a76112e9b5a6d4a2207f2648d012d 100644 (file)
@@ -63,8 +63,8 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd)
                goto out_put_hwpt;
        }
 
-       viommu = (struct iommufd_viommu *)_iommufd_object_alloc(
-               ucmd->ictx, viommu_size, IOMMUFD_OBJ_VIOMMU);
+       viommu = (struct iommufd_viommu *)_iommufd_object_alloc_ucmd(
+               ucmd, viommu_size, IOMMUFD_OBJ_VIOMMU);
        if (IS_ERR(viommu)) {
                rc = PTR_ERR(viommu);
                goto out_put_hwpt;
@@ -86,23 +86,17 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd)
 
        rc = ops->viommu_init(viommu, hwpt_paging->common.domain);
        if (rc)
-               goto out_abort;
+               goto out_put_hwpt;
 
        /* It is a driver bug that viommu->ops isn't filled */
        if (WARN_ON_ONCE(!viommu->ops)) {
                rc = -EOPNOTSUPP;
-               goto out_abort;
+               goto out_put_hwpt;
        }
 
        cmd->out_viommu_id = viommu->obj.id;
        rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd));
-       if (rc)
-               goto out_abort;
-       iommufd_object_finalize(ucmd->ictx, &viommu->obj);
-       goto out_put_hwpt;
 
-out_abort:
-       iommufd_object_abort_and_destroy(ucmd->ictx, &viommu->obj);
 out_put_hwpt:
        iommufd_put_object(ucmd->ictx, &hwpt_paging->common.obj);
 out_put_idev:
@@ -150,7 +144,7 @@ int iommufd_vdevice_alloc_ioctl(struct iommufd_ucmd *ucmd)
                goto out_put_idev;
        }
 
-       vdev = iommufd_object_alloc(ucmd->ictx, vdev, IOMMUFD_OBJ_VDEVICE);
+       vdev = iommufd_object_alloc_ucmd(ucmd, vdev, IOMMUFD_OBJ_VDEVICE);
        if (IS_ERR(vdev)) {
                rc = PTR_ERR(vdev);
                goto out_put_idev;
@@ -165,18 +159,12 @@ 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_abort;
+               goto out_put_idev;
        }
 
        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: