Skip to content

Commit

Permalink
mm/cma: fix cma bitmap aligned mask computing
Browse files Browse the repository at this point in the history
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.

[[email protected]: coding-style fixes]
Signed-off-by: Weijie Yang <[email protected]>
Acked-by: Michal Nazarewicz <[email protected]>
Cc: Joonsoo Kim <[email protected]>
Cc: "Aneesh Kumar K.V" <[email protected]>
Cc: <[email protected]>	[3.17]
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Weijie Yang authored and torvalds committed Oct 14, 2014
1 parent 85c9f4b commit 68faed6
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion mm/cma.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ unsigned long cma_get_size(struct cma *cma)

static unsigned long cma_bitmap_aligned_mask(struct cma *cma, int align_order)
{
return (1UL << (align_order >> cma->order_per_bit)) - 1;
if (align_order <= cma->order_per_bit)
return 0;
return (1UL << (align_order - cma->order_per_bit)) - 1;
}

static unsigned long cma_bitmap_maxno(struct cma *cma)
Expand Down

0 comments on commit 68faed6

Please sign in to comment.