Commit a15bc0b8 authored by Joonsoo Kim's avatar Joonsoo Kim Committed by Linus Torvalds

DMA, CMA: support alignment constraint on CMA region

PPC KVM's CMA area management needs alignment constraint on CMA region.
So support it to prepare generalization of CMA area management
functionality.

Additionally, add some comments which tell us why alignment constraint
is needed on CMA region.
Signed-off-by: default avatarJoonsoo Kim <iamjoonsoo.kim@lge.com>
Acked-by: default avatarMichal Nazarewicz <mina86@mina86.com>
Reviewed-by: default avatarAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Cc: Alexander Graf <agraf@suse.de>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Cc: Gleb Natapov <gleb@kernel.org>
Acked-by: default avatarMarek Szyprowski <m.szyprowski@samsung.com>
Tested-by: default avatarMarek Szyprowski <m.szyprowski@samsung.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 3162bbd7
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <linux/swap.h> #include <linux/swap.h>
#include <linux/mm_types.h> #include <linux/mm_types.h>
#include <linux/dma-contiguous.h> #include <linux/dma-contiguous.h>
#include <linux/log2.h>
struct cma { struct cma {
unsigned long base_pfn; unsigned long base_pfn;
...@@ -215,17 +216,16 @@ core_initcall(cma_init_reserved_areas); ...@@ -215,17 +216,16 @@ core_initcall(cma_init_reserved_areas);
static int __init __dma_contiguous_reserve_area(phys_addr_t size, static int __init __dma_contiguous_reserve_area(phys_addr_t size,
phys_addr_t base, phys_addr_t limit, phys_addr_t base, phys_addr_t limit,
phys_addr_t alignment,
struct cma **res_cma, bool fixed) struct cma **res_cma, bool fixed)
{ {
struct cma *cma = &cma_areas[cma_area_count]; struct cma *cma = &cma_areas[cma_area_count];
phys_addr_t alignment;
int ret = 0; int ret = 0;
pr_debug("%s(size %lx, base %08lx, limit %08lx)\n", __func__, pr_debug("%s(size %lx, base %08lx, limit %08lx alignment %08lx)\n",
(unsigned long)size, (unsigned long)base, __func__, (unsigned long)size, (unsigned long)base,
(unsigned long)limit); (unsigned long)limit, (unsigned long)alignment);
/* Sanity checks */
if (cma_area_count == ARRAY_SIZE(cma_areas)) { if (cma_area_count == ARRAY_SIZE(cma_areas)) {
pr_err("Not enough slots for CMA reserved regions!\n"); pr_err("Not enough slots for CMA reserved regions!\n");
return -ENOSPC; return -ENOSPC;
...@@ -234,8 +234,17 @@ static int __init __dma_contiguous_reserve_area(phys_addr_t size, ...@@ -234,8 +234,17 @@ static int __init __dma_contiguous_reserve_area(phys_addr_t size,
if (!size) if (!size)
return -EINVAL; return -EINVAL;
/* Sanitise input arguments */ if (alignment && !is_power_of_2(alignment))
alignment = PAGE_SIZE << max(MAX_ORDER - 1, pageblock_order); return -EINVAL;
/*
* Sanitise input arguments.
* Pages both ends in CMA area could be merged into adjacent unmovable
* migratetype page by page allocator's buddy algorithm. In the case,
* you couldn't get a contiguous memory, which is not what we want.
*/
alignment = max(alignment,
(phys_addr_t)PAGE_SIZE << max(MAX_ORDER - 1, pageblock_order));
base = ALIGN(base, alignment); base = ALIGN(base, alignment);
size = ALIGN(size, alignment); size = ALIGN(size, alignment);
limit &= ~(alignment - 1); limit &= ~(alignment - 1);
...@@ -299,7 +308,8 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base, ...@@ -299,7 +308,8 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base,
{ {
int ret; int ret;
ret = __dma_contiguous_reserve_area(size, base, limit, res_cma, fixed); ret = __dma_contiguous_reserve_area(size, base, limit, 0,
res_cma, fixed);
if (ret) if (ret)
return ret; return ret;
......
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