Commit e7023d13 authored by Doug Berger's avatar Doug Berger Committed by Greg Kroah-Hartman

cma: fix calculation of aligned offset

commit e048cb32 upstream.

The align_offset parameter is used by bitmap_find_next_zero_area_off()
to represent the offset of map's base from the previous alignment
boundary; the function ensures that the returned index, plus the
align_offset, honors the specified align_mask.

The logic introduced by commit b5be83e3 ("mm: cma: align to physical
address, not CMA region position") has the cma driver calculate the
offset to the *next* alignment boundary.  In most cases, the base
alignment is greater than that specified when making allocations,
resulting in a zero offset whether we align up or down.  In the example
given with the commit, the base alignment (8MB) was half the requested
alignment (16MB) so the math also happened to work since the offset is
8MB in both directions.  However, when requesting allocations with an
alignment greater than twice that of the base, the returned index would
not be correctly aligned.

Also, the align_order arguments of cma_bitmap_aligned_mask() and
cma_bitmap_aligned_offset() should not be negative so the argument type
was made unsigned.

Fixes: b5be83e3 ("mm: cma: align to physical address, not CMA region position")
Link: http://lkml.kernel.org/r/20170628170742.2895-1-opendmb@gmail.comSigned-off-by: default avatarAngus Clark <angus@angusclark.org>
Signed-off-by: default avatarDoug Berger <opendmb@gmail.com>
Acked-by: default avatarGregory Fong <gregory.0xf0@gmail.com>
Cc: Doug Berger <opendmb@gmail.com>
Cc: Angus Clark <angus@angusclark.org>
Cc: Laura Abbott <labbott@redhat.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Lucas Stach <l.stach@pengutronix.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Shiraz Hashim <shashim@codeaurora.org>
Cc: Jaewon Kim <jaewon31.kim@samsung.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent fcd5675c
...@@ -58,7 +58,7 @@ unsigned long cma_get_size(const struct cma *cma) ...@@ -58,7 +58,7 @@ unsigned long cma_get_size(const struct cma *cma)
} }
static unsigned long cma_bitmap_aligned_mask(const struct cma *cma, static unsigned long cma_bitmap_aligned_mask(const struct cma *cma,
int align_order) unsigned int align_order)
{ {
if (align_order <= cma->order_per_bit) if (align_order <= cma->order_per_bit)
return 0; return 0;
...@@ -66,17 +66,14 @@ static unsigned long cma_bitmap_aligned_mask(const struct cma *cma, ...@@ -66,17 +66,14 @@ static unsigned long cma_bitmap_aligned_mask(const struct cma *cma,
} }
/* /*
* Find a PFN aligned to the specified order and return an offset represented in * Find the offset of the base PFN from the specified align_order.
* order_per_bits. * The value returned is represented in order_per_bits.
*/ */
static unsigned long cma_bitmap_aligned_offset(const struct cma *cma, static unsigned long cma_bitmap_aligned_offset(const struct cma *cma,
int align_order) unsigned int align_order)
{ {
if (align_order <= cma->order_per_bit) return (cma->base_pfn & ((1UL << align_order) - 1))
return 0; >> cma->order_per_bit;
return (ALIGN(cma->base_pfn, (1UL << align_order))
- cma->base_pfn) >> cma->order_per_bit;
} }
static unsigned long cma_bitmap_maxno(struct cma *cma) static unsigned long cma_bitmap_maxno(struct cma *cma)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment