Skip to content

Commit 1424532

Browse files
mszyprowRussell King
authored andcommitted
ARM: 8347/1: dma-mapping: fix off-by-one check in arm_setup_iommu_dma_ops
Patch 22b3c18 ("arm: dma-mapping: limit IOMMU mapping size") added a check for IO address space size. However this patch broke IOMMU initialization for typical platforms initialized from device tree, which get the default IO address space size of 4GiB. This value doesn't fit into size_t and fails a check introduced by that commit resulting in failed dma-mapping/iommu initialization. This patch fixes this issue by adding proper support for full 4GiB address space size. Signed-off-by: Marek Szyprowski <[email protected]> Acked-by: Will Deacon <[email protected]> Signed-off-by: Russell King <[email protected]>
1 parent b787f68 commit 1424532

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

arch/arm/include/asm/dma-iommu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct dma_iommu_mapping {
2525
};
2626

2727
struct dma_iommu_mapping *
28-
arm_iommu_create_mapping(struct bus_type *bus, dma_addr_t base, size_t size);
28+
arm_iommu_create_mapping(struct bus_type *bus, dma_addr_t base, u64 size);
2929

3030
void arm_iommu_release_mapping(struct dma_iommu_mapping *mapping);
3131

arch/arm/mm/dma-mapping.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,14 +1878,18 @@ struct dma_map_ops iommu_coherent_ops = {
18781878
* arm_iommu_attach_device function.
18791879
*/
18801880
struct dma_iommu_mapping *
1881-
arm_iommu_create_mapping(struct bus_type *bus, dma_addr_t base, size_t size)
1881+
arm_iommu_create_mapping(struct bus_type *bus, dma_addr_t base, u64 size)
18821882
{
18831883
unsigned int bits = size >> PAGE_SHIFT;
18841884
unsigned int bitmap_size = BITS_TO_LONGS(bits) * sizeof(long);
18851885
struct dma_iommu_mapping *mapping;
18861886
int extensions = 1;
18871887
int err = -ENOMEM;
18881888

1889+
/* currently only 32-bit DMA address space is supported */
1890+
if (size > DMA_BIT_MASK(32) + 1)
1891+
return ERR_PTR(-ERANGE);
1892+
18891893
if (!bitmap_size)
18901894
return ERR_PTR(-EINVAL);
18911895

@@ -2057,13 +2061,6 @@ static bool arm_setup_iommu_dma_ops(struct device *dev, u64 dma_base, u64 size,
20572061
if (!iommu)
20582062
return false;
20592063

2060-
/*
2061-
* currently arm_iommu_create_mapping() takes a max of size_t
2062-
* for size param. So check this limit for now.
2063-
*/
2064-
if (size > SIZE_MAX)
2065-
return false;
2066-
20672064
mapping = arm_iommu_create_mapping(dev->bus, dma_base, size);
20682065
if (IS_ERR(mapping)) {
20692066
pr_warn("Failed to create %llu-byte IOMMU mapping for device %s\n",

0 commit comments

Comments
 (0)