aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Berger <[email protected]>2019-07-16 16:26:24 -0700
committerLinus Torvalds <[email protected]>2019-07-16 19:23:21 -0700
commitc633324e311243586675e732249339685e5d6faa (patch)
tree8bf128fc3f110de26db69c8292049ccc7a52e893
parentc92d2f38563db20c20c8db2f98fa1349290477d5 (diff)
mm/cma.c: fail if fixed declaration can't be honored
The description of cma_declare_contiguous() indicates that if the 'fixed' argument is true the reserved contiguous area must be exactly at the address of the 'base' argument. However, the function currently allows the 'base', 'size', and 'limit' arguments to be silently adjusted to meet alignment constraints. This commit enforces the documented behavior through explicit checks that return an error if the region does not fit within a specified region. Link: http://lkml.kernel.org/r/[email protected] Fixes: 5ea3b1b2f8ad ("cma: add placement specifier for "cma=" kernel parameter") Signed-off-by: Doug Berger <[email protected]> Acked-by: Michal Nazarewicz <[email protected]> Cc: Yue Hu <[email protected]> Cc: Mike Rapoport <[email protected]> Cc: Laura Abbott <[email protected]> Cc: Peng Fan <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Marek Szyprowski <[email protected]> Cc: Andrey Konovalov <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
-rw-r--r--mm/cma.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/mm/cma.c b/mm/cma.c
index d415dfc0965e..7fe0b8356775 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -278,6 +278,12 @@ int __init cma_declare_contiguous(phys_addr_t base,
*/
alignment = max(alignment, (phys_addr_t)PAGE_SIZE <<
max_t(unsigned long, MAX_ORDER - 1, pageblock_order));
+ if (fixed && base & (alignment - 1)) {
+ ret = -EINVAL;
+ pr_err("Region at %pa must be aligned to %pa bytes\n",
+ &base, &alignment);
+ goto err;
+ }
base = ALIGN(base, alignment);
size = ALIGN(size, alignment);
limit &= ~(alignment - 1);
@@ -308,6 +314,13 @@ int __init cma_declare_contiguous(phys_addr_t base,
if (limit == 0 || limit > memblock_end)
limit = memblock_end;
+ if (base + size > limit) {
+ ret = -EINVAL;
+ pr_err("Size (%pa) of region at %pa exceeds limit (%pa)\n",
+ &size, &base, &limit);
+ goto err;
+ }
+
/* Reserve memory */
if (fixed) {
if (memblock_is_region_reserved(base, size) ||