FROMGIT: iommu/io-pgtable-arm-v7s: Add error handle for page table allocation failure
In __arm_v7s_alloc_table function:
iommu call kmem_cache_alloc to allocate page table, this function
allocate memory may fail, when kmem_cache_alloc fails to allocate
table, call virt_to_phys will be abnomal and return unexpected phys
and goto out_free, then call kmem_cache_free to release table will
trigger KE, __get_free_pages and free_pages have similar problem,
so add error handle for page table allocation failure.
Fixes: 29859aeb8a
("iommu/io-pgtable-arm-v7s: Abort allocation when table address overflows the PTE")
Signed-off-by: Yunfei Wang <yf.wang@mediatek.com>
Cc: <stable@vger.kernel.org> # 5.10.*
Acked-by: Robin Murphy <robin.murphy@arm.com>
Link: https://lore.kernel.org/r/20211207113315.29109-1-yf.wang@mediatek.com
Signed-off-by: Will Deacon <will@kernel.org>
Bug: 210958369
(cherry picked from commit a556cfe4cabc6d79cbb7733f118bbb420b376fe6
https://git.kernel.org/pub/scm/linux/kernel/git/will/linux.git for-joerg/arm-smmu/updates)
Signed-off-by: Yunfei Wang <yf.wang@mediatek.com>
Change-Id: I6435903336d1e15b5a57d08c284b3d3d66ea985d
This commit is contained in:

committed by
Suren Baghdasaryan

parent
99ad261273
commit
28d62c68d1
@@ -246,13 +246,17 @@ static void *__arm_v7s_alloc_table(int lvl, gfp_t gfp,
|
|||||||
__GFP_ZERO | ARM_V7S_TABLE_GFP_DMA, get_order(size));
|
__GFP_ZERO | ARM_V7S_TABLE_GFP_DMA, get_order(size));
|
||||||
else if (lvl == 2)
|
else if (lvl == 2)
|
||||||
table = kmem_cache_zalloc(data->l2_tables, gfp);
|
table = kmem_cache_zalloc(data->l2_tables, gfp);
|
||||||
|
|
||||||
|
if (!table)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
phys = virt_to_phys(table);
|
phys = virt_to_phys(table);
|
||||||
if (phys != (arm_v7s_iopte)phys) {
|
if (phys != (arm_v7s_iopte)phys) {
|
||||||
/* Doesn't fit in PTE */
|
/* Doesn't fit in PTE */
|
||||||
dev_err(dev, "Page table does not fit in PTE: %pa", &phys);
|
dev_err(dev, "Page table does not fit in PTE: %pa", &phys);
|
||||||
goto out_free;
|
goto out_free;
|
||||||
}
|
}
|
||||||
if (table && !cfg->coherent_walk) {
|
if (!cfg->coherent_walk) {
|
||||||
dma = dma_map_single(dev, table, size, DMA_TO_DEVICE);
|
dma = dma_map_single(dev, table, size, DMA_TO_DEVICE);
|
||||||
if (dma_mapping_error(dev, dma))
|
if (dma_mapping_error(dev, dma))
|
||||||
goto out_free;
|
goto out_free;
|
||||||
|
Reference in New Issue
Block a user