On Mon, 24 Jun 2019 17:20:51 -0700 Doug Berger <open...@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;
        }


Reply via email to