Commit 237603a4 authored by Yi Liu's avatar Yi Liu Committed by Jason Gunthorpe
Browse files

iommu: Make @handle mandatory in iommu_{attach|replace}_group_handle()

Caller of the two APIs always provide a valid handle, make @handle as
mandatory parameter. Take this chance incoporate the handle->domain
set under the protection of group->mutex in iommu_attach_group_handle().

Link: https://patch.msgid.link/r/20250226011849.5102-2-yi.l.liu@intel.com


Reviewed-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Reviewed-by: default avatarNicolin Chen <nicolinc@nvidia.com>
Reviewed-by: default avatarKevin Tian <kevin.tian@intel.com>
Reviewed-by: default avatarLu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: default avatarYi Liu <yi.l.liu@intel.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
parent 40f5175d
Loading
Loading
Loading
Loading
+8 −9
Original line number Diff line number Diff line
@@ -3511,10 +3511,11 @@ int iommu_attach_group_handle(struct iommu_domain *domain,
{
	int ret;

	if (handle)
		handle->domain = domain;
	if (!handle)
		return -EINVAL;

	mutex_lock(&group->mutex);
	handle->domain = domain;
	ret = xa_insert(&group->pasid_array, IOMMU_NO_PASID, handle, GFP_KERNEL);
	if (ret)
		goto err_unlock;
@@ -3568,16 +3569,14 @@ int iommu_replace_group_handle(struct iommu_group *group,
	void *curr;
	int ret;

	if (!new_domain)
	if (!new_domain || !handle)
		return -EINVAL;

	mutex_lock(&group->mutex);
	if (handle) {
	handle->domain = new_domain;
	ret = xa_reserve(&group->pasid_array, IOMMU_NO_PASID, GFP_KERNEL);
	if (ret)
		goto err_unlock;
		handle->domain = new_domain;
	}

	ret = __iommu_group_set_domain(group, new_domain);
	if (ret)