arm: dma-mapping: set the proper bitmap size
Set the size of bitmap area properly to ensure the proper iova address
to be returned by the bitmap_() API's through alloc_iova(). The current
implementation causes the bitmap index search out of bounds of a page
which can lead to the randomn corruption issues.
This also merge the commit:I66eb15cdbb3 changes.
Change-Id: Ie57ca0b7465c91d318145ed270b7d47d822c8eeb
Fixes:I88ddd98a76b ("arm/arm64: dma-mapping: Fix iova region size")
Signed-off-by: Charan Teja Reddy <charante@codeaurora.org>
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index 19f444e..441063f 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -2170,6 +2170,9 @@ arm_iommu_create_mapping(struct bus_type *bus, dma_addr_t base, u64 size)
if (!bitmap_size)
return ERR_PTR(-EINVAL);
+ WARN(!IS_ALIGNED(size, SZ_128M),
+ "size is not aligned to 128M, alignment enforced");
+
if (bitmap_size > PAGE_SIZE) {
extensions = bitmap_size / PAGE_SIZE;
bitmap_size = PAGE_SIZE;
@@ -2192,7 +2195,7 @@ arm_iommu_create_mapping(struct bus_type *bus, dma_addr_t base, u64 size)
mapping->nr_bitmaps = 1;
mapping->extensions = extensions;
mapping->base = base;
- mapping->bits = bits;
+ mapping->bits = BITS_PER_BYTE * bitmap_size;
spin_lock_init(&mapping->lock);