mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-30 22:26:55 +00:00
mm/cma.c: fail if fixed declaration can't be honored
[ Upstream commitc633324e31
] 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/1561422051-16142-1-git-send-email-opendmb@gmail.com Fixes:5ea3b1b2f8
("cma: add placement specifier for "cma=" kernel parameter") Signed-off-by: Doug Berger <opendmb@gmail.com> Acked-by: Michal Nazarewicz <mina86@mina86.com> Cc: Yue Hu <huyue2@yulong.com> Cc: Mike Rapoport <rppt@linux.ibm.com> Cc: Laura Abbott <labbott@redhat.com> Cc: Peng Fan <peng.fan@nxp.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Marek Szyprowski <m.szyprowski@samsung.com> Cc: Andrey Konovalov <andreyknvl@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
ca5732b311
commit
2aca945f09
1 changed files with 13 additions and 0 deletions
13
mm/cma.c
13
mm/cma.c
|
@ -277,6 +277,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);
|
||||
|
@ -307,6 +313,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) ||
|
||||
|
|
Loading…
Reference in a new issue