From 594e9cd10ee7a3739e9d1a7b477582ca43fb830f Mon Sep 17 00:00:00 2001 From: Laura Abbott Date: Sat, 27 Apr 2013 18:27:38 -0700 Subject: [PATCH] msm: iommu: Lock the genpool allocation Previously, IOMMU allocation and mapping was handled through Ion. Ion provided very coarse locking that essentially serialized access to iova allocation. Now that IOMMU allocation is out of Ion, the genpool allocation for IOVAs needs to be serialized again. Take the pool lock for each IOVA pool to prevent against races. Change-Id: I6d38995549cabd3d082697e440e3aafc1bdcfaa5 CRs-Fixed: 481328 Signed-off-by: Laura Abbott --- arch/arm/mach-msm/iommu_domains.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/arm/mach-msm/iommu_domains.c b/arch/arm/mach-msm/iommu_domains.c index 18562a3f78a..1d3ccc317dc 100644 --- a/arch/arm/mach-msm/iommu_domains.c +++ b/arch/arm/mach-msm/iommu_domains.c @@ -330,7 +330,9 @@ int msm_allocate_iova_address(unsigned int iommu_domain, if (!pool->gpool) return -EINVAL; + mutex_lock(&pool->pool_mutex); va = gen_pool_alloc_aligned(pool->gpool, size, ilog2(align)); + mutex_unlock(&pool->pool_mutex); if (va) { pool->free -= size; /* Offset because genpool can't handle 0 addresses */ @@ -375,7 +377,9 @@ void msm_free_iova_address(unsigned long iova, if (pool->paddr == 0) iova += SZ_4K; + mutex_lock(&pool->pool_mutex); gen_pool_free(pool->gpool, iova, size); + mutex_unlock(&pool->pool_mutex); } int msm_register_domain(struct msm_iova_layout *layout) @@ -410,6 +414,7 @@ int msm_register_domain(struct msm_iova_layout *layout) pools[i].paddr = layout->partitions[i].start; pools[i].size = layout->partitions[i].size; + mutex_init(&pools[i].pool_mutex); /* * genalloc can't handle a pool starting at address 0.