Skip to content

Commit 31422df

Browse files
committed
iommufd: Fix locking around hwpt allocation
Due to the auto_domains mechanism the ioas->mutex must be held until the hwpt is completely setup by iommufd_object_abort_and_destroy() or iommufd_object_finalize(). This prevents a concurrent iommufd_device_auto_get_domain() from seeing an incompletely initialized object through the ioas->hwpt_list. To make this more consistent move the unlock until after finalize. Fixes: e8d5721 ("iommufd: Add kAPI toward external drivers for physical devices") Link: https://lore.kernel.org/r/11-v8-6659224517ea+532-iommufd_alloc_jgg@nvidia.com Reviewed-by: Kevin Tian <kevin.tian@intel.com> Tested-by: Nicolin Chen <nicolinc@nvidia.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent 70eadc7 commit 31422df

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/iommu/iommufd/device.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,8 @@ static int iommufd_device_auto_get_domain(struct iommufd_device *idev,
441441
hwpt->auto_domain = true;
442442
*pt_id = hwpt->obj.id;
443443

444-
mutex_unlock(&ioas->mutex);
445444
iommufd_object_finalize(idev->ictx, &hwpt->obj);
445+
mutex_unlock(&ioas->mutex);
446446
return 0;
447447
out_unlock:
448448
mutex_unlock(&ioas->mutex);

0 commit comments

Comments
 (0)