Skip to content

Commit a64bae6

Browse files
Xu Yilunjgunthorpe
authored andcommitted
iommufd/viommu: Roll back to use iommufd_object_alloc() for vdevice
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/[email protected] Reviewed-by: Nicolin Chen <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Tested-by: Nicolin Chen <[email protected]> Signed-off-by: Xu Yilun <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 5d8b1d9 commit a64bae6

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

drivers/iommu/iommufd/viommu.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ int iommufd_vdevice_alloc_ioctl(struct iommufd_ucmd *ucmd)
167167
vdev_size = viommu->ops->vdevice_size;
168168
}
169169

170-
vdev = (struct iommufd_vdevice *)_iommufd_object_alloc_ucmd(
171-
ucmd, vdev_size, IOMMUFD_OBJ_VDEVICE);
170+
vdev = (struct iommufd_vdevice *)_iommufd_object_alloc(
171+
ucmd->ictx, vdev_size, IOMMUFD_OBJ_VDEVICE);
172172
if (IS_ERR(vdev)) {
173173
rc = PTR_ERR(vdev);
174174
goto out_put_idev;
@@ -183,18 +183,24 @@ int iommufd_vdevice_alloc_ioctl(struct iommufd_ucmd *ucmd)
183183
curr = xa_cmpxchg(&viommu->vdevs, virt_id, NULL, vdev, GFP_KERNEL);
184184
if (curr) {
185185
rc = xa_err(curr) ?: -EEXIST;
186-
goto out_put_idev;
186+
goto out_abort;
187187
}
188188

189189
if (viommu->ops && viommu->ops->vdevice_init) {
190190
rc = viommu->ops->vdevice_init(vdev);
191191
if (rc)
192-
goto out_put_idev;
192+
goto out_abort;
193193
}
194194

195195
cmd->out_vdevice_id = vdev->obj.id;
196196
rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd));
197+
if (rc)
198+
goto out_abort;
199+
iommufd_object_finalize(ucmd->ictx, &vdev->obj);
200+
goto out_put_idev;
197201

202+
out_abort:
203+
iommufd_object_abort_and_destroy(ucmd->ictx, &vdev->obj);
198204
out_put_idev:
199205
iommufd_put_object(ucmd->ictx, &idev->obj);
200206
out_put_viommu:

0 commit comments

Comments
 (0)