Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm/cma: fix cma bitmap aligned mask computing

The current cma bitmap aligned mask computation is incorrect. It could
cause an unexpected alignment when using cma_alloc() if the wanted align
order is larger than cma->order_per_bit.

Take kvm for example (PAGE_SHIFT = 12), kvm_cma->order_per_bit is set to
6. When kvm_alloc_rma() tries to alloc kvm_rma_pages, it will use 15 as
the expected align value. After using the current implementation however,
we get 0 as cma bitmap aligned mask other than 511.

This patch fixes the cma bitmap aligned mask calculation.

[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: Weijie Yang <weijie.yang@samsung.com>
Acked-by: Michal Nazarewicz <mina86@mina86.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
Cc: <stable@vger.kernel.org> [3.17]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Weijie Yang and committed by
Linus Torvalds
68faed63 85c9f4b0

+3 -1
+3 -1
mm/cma.c
··· 58 58 59 59 static unsigned long cma_bitmap_aligned_mask(struct cma *cma, int align_order) 60 60 { 61 - return (1UL << (align_order >> cma->order_per_bit)) - 1; 61 + if (align_order <= cma->order_per_bit) 62 + return 0; 63 + return (1UL << (align_order - cma->order_per_bit)) - 1; 62 64 } 63 65 64 66 static unsigned long cma_bitmap_maxno(struct cma *cma)