ARM: mm: dma-mapping: limit iova alignment
Sri Krishna chowdary [Mon, 11 May 2015 09:28:38 +0000 (14:28 +0530)]
iova space is prone to early exhaustion if the default alignment
rule is followed as alignment is of order of mapping size. This patch
tries to restrict arbitrarily large alignments by considering mapping's
alignment as the maximum.

bug 1483482

Change-Id: Id6ee1d8280ba934325bbfd6db733d24a68d05443
Signed-off-by: Sri Krishna chowdary <schowdary@nvidia.com>
Reviewed-on: http://git-master/r/741186
Reviewed-by: Hiroshi Doyu <hdoyu@nvidia.com>

arch/arm/mm/dma-mapping.c
arch/arm64/mm/dma-mapping.c

index 0512c19..62992ef 100644 (file)
@@ -1312,6 +1312,9 @@ static inline dma_addr_t __alloc_iova(struct dma_iommu_mapping *mapping,
        if (order > CONFIG_ARM_DMA_IOMMU_ALIGNMENT)
                order = CONFIG_ARM_DMA_IOMMU_ALIGNMENT;
 
+       if (mapping->alignment && order > get_order(mapping->alignment))
+               order = get_order(mapping->alignment);
+
        count = ((PAGE_ALIGN(size) >> PAGE_SHIFT) +
                 (1 << mapping->order) - 1) >> mapping->order;
 
index 41cc5db..aec227d 100644 (file)
@@ -1363,6 +1363,9 @@ static inline dma_addr_t __alloc_iova(struct dma_iommu_mapping *mapping,
        unsigned int count, start;
        unsigned long flags;
 
+       if (mapping->alignment && order > get_order(mapping->alignment))
+               order = get_order(mapping->alignment);
+
        count = ((PAGE_ALIGN(size) >> PAGE_SHIFT) +
                 (1 << mapping->order) - 1) >> mapping->order;