iommu/sva: Fix SVA handle sharing in multi device case
authorZhangfei Gao <zhangfei.gao@linaro.org>
Tue, 27 Feb 2024 06:48:21 +0000 (06:48 +0000)
committerJoerg Roedel <jroedel@suse.de>
Fri, 1 Mar 2024 12:53:58 +0000 (13:53 +0100)
iommu_sva_bind_device will directly goto out in multi-device
case when found existing domain, ignoring list_add handle,
which causes the handle to fail to be shared.

Fixes: 65d4418c5002 ("iommu/sva: Restore SVA handle sharing")
Signed-off-by: Zhangfei Gao <zhangfei.gao@linaro.org>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Link: https://lore.kernel.org/r/20240227064821.128-1-zhangfei.gao@linaro.org
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/iommu-sva.c

index 7f91c8d0064b71c481395d7febacee8f56567a49..65814cbc84020021df67d0b7dab9db2c61351b56 100644 (file)
@@ -117,11 +117,11 @@ struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct mm_struct *mm
        if (ret)
                goto out_free_domain;
        domain->users = 1;
-       refcount_set(&handle->users, 1);
        list_add(&domain->next, &mm->iommu_mm->sva_domains);
-       list_add(&handle->handle_item, &mm->iommu_mm->sva_handles);
 
 out:
+       refcount_set(&handle->users, 1);
+       list_add(&handle->handle_item, &mm->iommu_mm->sva_handles);
        mutex_unlock(&iommu_sva_lock);
        handle->dev = dev;
        handle->domain = domain;