lkml.org 
[lkml]   [2019]   [Jun]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] cma: fail if fixed declaration can't be honored
On Mon, 24 Jun 2019 17:20:51 -0700 Doug Berger <opendmb@gmail.com> wrote:

> The description of the cma_declare_contiguous() function 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.
>
> ...
>
> --- 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);

CMA functions do like to use pr_err() when the caller messed something
up. It should be using WARN_ON() or WARN_ON_ONCE(), mainly so we get a
backtrace to find out which caller messed up.

There are probably other sites which should be converted, but I think
it would be best to get these new ones correct. So something like

if (WARN_ONCE(fixed && base & (alignment - 1)),
"region at %pa must be aligned to %pa bytes",
&base, &alignment) {
ret = -EINVAL;
goto err;
}


\
 
 \ /
  Last update: 2019-06-25 22:25    [W:0.023 / U:12.676 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site