aboutsummaryrefslogtreecommitdiffstats
path: root/mm
diff options
context:
space:
mode:
authorGregory Fong <gregory.0xf0@gmail.com>2014-12-12 19:54:48 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2014-12-13 15:42:46 -0500
commitb5be83e308f70e16c63c4e520ea7bb03ef57c46f (patch)
tree0828ee0c60cd16d172a815fc5a4adcbc67d034f6 /mm
parent5e19b013f55a884c59a14391b22138899d1cc4cc (diff)
mm: cma: align to physical address, not CMA region position
The alignment in cma_alloc() was done w.r.t. the bitmap. This is a problem when, for example: - a device requires 16M (order 12) alignment - the CMA region is not 16 M aligned In such a case, can result with the CMA region starting at, say, 0x2f800000 but any allocation you make from there will be aligned from there. Requesting an allocation of 32 M with 16 M alignment will result in an allocation from 0x2f800000 to 0x31800000, which doesn't work very well if your strange device requires 16M alignment. Change to use bitmap_find_next_zero_area_off() to account for the difference in alignment at reserve-time and alloc-time. Signed-off-by: Gregory Fong <gregory.0xf0@gmail.com> Acked-by: Michal Nazarewicz <mina86@mina86.com> Cc: Marek Szyprowski <m.szyprowski@samsung.com> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Cc: Kukjin Kim <kgene.kim@samsung.com> Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Cc: Laura Abbott <lauraa@codeaurora.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm')
-rw-r--r--mm/cma.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/mm/cma.c b/mm/cma.c
index 8e9ec13d31db..5c96d7a3ba9c 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -63,6 +63,17 @@ static unsigned long cma_bitmap_aligned_mask(struct cma *cma, int align_order)
63 return (1UL << (align_order - cma->order_per_bit)) - 1; 63 return (1UL << (align_order - cma->order_per_bit)) - 1;
64} 64}
65 65
66static unsigned long cma_bitmap_aligned_offset(struct cma *cma, int align_order)
67{
68 unsigned int alignment;
69
70 if (align_order <= cma->order_per_bit)
71 return 0;
72 alignment = 1UL << (align_order - cma->order_per_bit);
73 return ALIGN(cma->base_pfn, alignment) -
74 (cma->base_pfn >> cma->order_per_bit);
75}
76
66static unsigned long cma_bitmap_maxno(struct cma *cma) 77static unsigned long cma_bitmap_maxno(struct cma *cma)
67{ 78{
68 return cma->count >> cma->order_per_bit; 79 return cma->count >> cma->order_per_bit;
@@ -340,7 +351,7 @@ err:
340 */ 351 */
341struct page *cma_alloc(struct cma *cma, int count, unsigned int align) 352struct page *cma_alloc(struct cma *cma, int count, unsigned int align)
342{ 353{
343 unsigned long mask, pfn, start = 0; 354 unsigned long mask, offset, pfn, start = 0;
344 unsigned long bitmap_maxno, bitmap_no, bitmap_count; 355 unsigned long bitmap_maxno, bitmap_no, bitmap_count;
345 struct page *page = NULL; 356 struct page *page = NULL;
346 int ret; 357 int ret;
@@ -355,13 +366,15 @@ struct page *cma_alloc(struct cma *cma, int count, unsigned int align)
355 return NULL; 366 return NULL;
356 367
357 mask = cma_bitmap_aligned_mask(cma, align); 368 mask = cma_bitmap_aligned_mask(cma, align);
369 offset = cma_bitmap_aligned_offset(cma, align);
358 bitmap_maxno = cma_bitmap_maxno(cma); 370 bitmap_maxno = cma_bitmap_maxno(cma);
359 bitmap_count = cma_bitmap_pages_to_bits(cma, count); 371 bitmap_count = cma_bitmap_pages_to_bits(cma, count);
360 372
361 for (;;) { 373 for (;;) {
362 mutex_lock(&cma->lock); 374 mutex_lock(&cma->lock);
363 bitmap_no = bitmap_find_next_zero_area(cma->bitmap, 375 bitmap_no = bitmap_find_next_zero_area_off(cma->bitmap,
364 bitmap_maxno, start, bitmap_count, mask); 376 bitmap_maxno, start, bitmap_count, mask,
377 offset);
365 if (bitmap_no >= bitmap_maxno) { 378 if (bitmap_no >= bitmap_maxno) {
366 mutex_unlock(&cma->lock); 379 mutex_unlock(&cma->lock);
367 break; 380 break;