linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Michał Nazarewicz" <mina86@mina86.com>
To: Doug Berger <opendmb@gmail.com>
Cc: linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
	 Yue Hu <huyue2@yulong.com>, Mike Rapoport <rppt@linux.ibm.com>,
	 Laura Abbott <labbott@redhat.com>, Peng Fan <peng.fan@nxp.com>,
	 Thomas Gleixner <tglx@linutronix.de>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	 Andrey Konovalov <andreyknvl@google.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] cma: fail if fixed declaration can't be honored
Date: Tue, 25 Jun 2019 10:24:06 +0100	[thread overview]
Message-ID: <CA+pa1O1Y8T9c-gD6qBteiNM4FCf6A2M-7o3vvCxMdR3hL7-+SA@mail.gmail.com> (raw)
In-Reply-To: <1561422051-16142-1-git-send-email-opendmb@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2266 bytes --]

On Tue, 25 Jun 2019 at 01:22, 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.
>
> Fixes: 5ea3b1b2f8ad ("cma: add placement specifier for "cma=" kernel
> parameter")
> Signed-off-by: Doug Berger <opendmb@gmail.com>
>

Acked-by: Michal Nazarewicz <mina86@mina86.com>


> ---
>  mm/cma.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
>
> diff --git a/mm/cma.c b/mm/cma.c
> index 3340ef34c154..4973d253dc83 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) ||
> --
> 2.7.4
>
>

-- 
Best regards
ミハウ “𝓶𝓲𝓷𝓪86” ナザレヴイツ
«If at first you don’t succeed, give up skydiving»

[-- Attachment #2: Type: text/html, Size: 3398 bytes --]

  reply	other threads:[~2019-06-25  9:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-25  0:20 Doug Berger
2019-06-25  9:24 ` Michał Nazarewicz [this message]
2019-06-25 20:23 ` Andrew Morton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CA+pa1O1Y8T9c-gD6qBteiNM4FCf6A2M-7o3vvCxMdR3hL7-+SA@mail.gmail.com \
    --to=mina86@mina86.com \
    --cc=akpm@linux-foundation.org \
    --cc=andreyknvl@google.com \
    --cc=huyue2@yulong.com \
    --cc=labbott@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=m.szyprowski@samsung.com \
    --cc=opendmb@gmail.com \
    --cc=peng.fan@nxp.com \
    --cc=rppt@linux.ibm.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox