iommu/arm-smmu: avoid possible deadlock during map_sg

A possible deadlock could occur with the following flow:

    arm_smmu_map_sg()
    -->arm_smmu_secure_domain_lock()
    -->ops->map_sg() //this returns an error with ret = 0
    -->size_to_unmap = iova + size - __saved_iova_start;
    -->goto out;
    -->arm_smmu_assign_table()
    -->arm_smmu_unmap()
    ---->arm_smmu_secure_domain_lock() //DEADLOCKed!!!!!
    -------->mutex_lock()

The secure domain lock is needed to protect hyp assign and unassign.
Hence, its safe to call arm_smmu_secure_domain_unlock() after the
map and assign is done. Do this to avoid any runtime deadlocks.

Change-Id: I35effc170d8432d32c0cab3081be4897830d9212
Signed-off-by: Sudarshan Rajagopalan <sudaraja@codeaurora.org>
Signed-off-by: Isaac J. Manjarres <isaacm@codeaurora.org>
This commit is contained in:
Sudarshan Rajagopalan 2019-12-19 18:03:43 -08:00 • committed by Isaac J. Manjarres
commit 92b97fee78

View file

@ -3046,12 +3046,12 @@ static size_t arm_smmu_map_sg(struct iommu_domain *domain, unsigned long iova,
out:
arm_smmu_assign_table(smmu_domain);
arm_smmu_secure_domain_unlock(smmu_domain);
if (size_to_unmap) {
arm_smmu_unmap(domain, __saved_iova_start, size_to_unmap, NULL);
iova = __saved_iova_start;
}
arm_smmu_secure_domain_unlock(smmu_domain);
return iova - __saved_iova_start;
}