linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Rob Herring <robh@kernel.org>
To: Oreoluwa Babatunde <oreoluwa.babatunde@oss.qualcomm.com>
Cc: m.szyprowski@samsung.com, ye.li@oss.nxp.com,
	kernel@oss.qualcomm.com,  saravanak@google.com,
	akpm@linux-foundation.org, david@redhat.com,
	 lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com,
	vbabka@suse.cz,  rppt@kernel.org, surenb@google.com,
	mhocko@suse.com, robin.murphy@arm.com,
	 devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org,  iommu@lists.linux.dev,
	quic_c_gdjako@quicinc.com
Subject: Re: [PATCH] of: reserved_mem: Allow reserved_mem framework detect "cma=" kernel param
Date: Wed, 10 Dec 2025 08:07:40 -0600	[thread overview]
Message-ID: <CAL_JsqL6VVQ7K_ZAbHJ8Gb7ei_jusLx6wRn=AdOVgV50dX0ejQ@mail.gmail.com> (raw)
In-Reply-To: <20251210002027.1171519-1-oreoluwa.babatunde@oss.qualcomm.com>

On Tue, Dec 9, 2025 at 6:20 PM Oreoluwa Babatunde
<oreoluwa.babatunde@oss.qualcomm.com> wrote:
>
> When initializing the default cma region, the "cma=" kernel parameter
> takes priority over a DT defined linux,cma-default region. Hence, give
> the reserved_mem framework the ability to detect this so that the DT
> defined cma region can skip initialization accordingly.

Please explain here why this is a new problem. Presumably the
RESERVEDMEM_OF_DECLARE hook after commit xxxx gets called before the
early_param hook. And why is it now earlier?

I don't really like the state/ordering having to be worried about in 2 places.

> Signed-off-by: Oreoluwa Babatunde <oreoluwa.babatunde@oss.qualcomm.com>
> ---
>  drivers/of/of_reserved_mem.c | 19 +++++++++++++++++--
>  include/linux/cma.h          |  1 +
>  kernel/dma/contiguous.c      | 16 ++++++++++------
>  3 files changed, 28 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
> index 2e9ea751ed2d..bef68a4916b5 100644
> --- a/drivers/of/of_reserved_mem.c
> +++ b/drivers/of/of_reserved_mem.c
> @@ -158,7 +158,7 @@ static int __init __reserved_mem_reserve_reg(unsigned long node,
>         phys_addr_t base, size;
>         int len;
>         const __be32 *prop;
> -       bool nomap;
> +       bool nomap, default_cma;
>
>         prop = of_get_flat_dt_prop(node, "reg", &len);
>         if (!prop)
> @@ -171,6 +171,12 @@ static int __init __reserved_mem_reserve_reg(unsigned long node,
>         }
>
>         nomap = of_get_flat_dt_prop(node, "no-map", NULL) != NULL;
> +       default_cma = of_get_flat_dt_prop(node, "linux,cma-default", NULL);
> +
> +       if (default_cma && cma_skip_dt_default_reserved_mem()) {
> +               pr_err("Skipping dt linux,cma-default for \"cma=\" kernel param.\n");
> +               return -EINVAL;
> +       }
>
>         while (len >= t_len) {
>                 base = dt_mem_next_cell(dt_root_addr_cells, &prop);
> @@ -256,12 +262,15 @@ void __init fdt_scan_reserved_mem_reg_nodes(void)
>
>         fdt_for_each_subnode(child, fdt, node) {
>                 const char *uname;
> +               bool default_cma = of_get_flat_dt_prop(child, "linux,cma-default", NULL);
>
>                 prop = of_get_flat_dt_prop(child, "reg", &len);
>                 if (!prop)
>                         continue;
>                 if (!of_fdt_device_is_available(fdt, child))
>                         continue;
> +               if (default_cma && cma_skip_dt_default_reserved_mem())
> +                       continue;
>
>                 uname = fdt_get_name(fdt, child, NULL);
>                 if (len && len % t_len != 0) {
> @@ -406,7 +415,7 @@ static int __init __reserved_mem_alloc_size(unsigned long node, const char *unam
>         phys_addr_t base = 0, align = 0, size;
>         int len;
>         const __be32 *prop;
> -       bool nomap;
> +       bool nomap, default_cma;
>         int ret;
>
>         prop = of_get_flat_dt_prop(node, "size", &len);
> @@ -430,6 +439,12 @@ static int __init __reserved_mem_alloc_size(unsigned long node, const char *unam
>         }
>
>         nomap = of_get_flat_dt_prop(node, "no-map", NULL) != NULL;
> +       default_cma = of_get_flat_dt_prop(node, "linux,cma-default", NULL);
> +
> +       if (default_cma && cma_skip_dt_default_reserved_mem()) {
> +               pr_err("Skipping dt linux,cma-default for \"cma=\" kernel param.\n");
> +               return -EINVAL;
> +       }
>
>         /* Need adjust the alignment to satisfy the CMA requirement */
>         if (IS_ENABLED(CONFIG_CMA)
> diff --git a/include/linux/cma.h b/include/linux/cma.h
> index 62d9c1cf6326..3d3047029950 100644
> --- a/include/linux/cma.h
> +++ b/include/linux/cma.h
> @@ -47,6 +47,7 @@ extern int cma_init_reserved_mem(phys_addr_t base, phys_addr_t size,
>                                         unsigned int order_per_bit,
>                                         const char *name,
>                                         struct cma **res_cma);
> +extern bool cma_skip_dt_default_reserved_mem(void);
>  extern struct page *cma_alloc(struct cma *cma, unsigned long count, unsigned int align,
>                               bool no_warn);
>  extern bool cma_pages_valid(struct cma *cma, const struct page *pages, unsigned long count);
> diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c
> index d9b9dcba6ff7..9071c08650e3 100644
> --- a/kernel/dma/contiguous.c
> +++ b/kernel/dma/contiguous.c
> @@ -90,6 +90,16 @@ static int __init early_cma(char *p)
>  }
>  early_param("cma", early_cma);
>
> +/*
> + * cma_skip_dt_default_reserved_mem - This is called from the
> + * reserved_mem framework to detect if the default cma region is being
> + * set by the "cma=" kernel parameter.
> + */
> +bool __init cma_skip_dt_default_reserved_mem(void)
> +{
> +       return size_cmdline != -1;
> +}
> +
>  #ifdef CONFIG_DMA_NUMA_CMA
>
>  static struct cma *dma_contiguous_numa_area[MAX_NUMNODES];
> @@ -463,12 +473,6 @@ static int __init rmem_cma_setup(struct reserved_mem *rmem)
>         struct cma *cma;
>         int err;
>
> -       if (size_cmdline != -1 && default_cma) {
> -               pr_info("Reserved memory: bypass %s node, using cmdline CMA params instead\n",
> -                       rmem->name);
> -               return -EBUSY;
> -       }
> -
>         if (!of_get_flat_dt_prop(node, "reusable", NULL) ||
>             of_get_flat_dt_prop(node, "no-map", NULL))
>                 return -EINVAL;
> --
> 2.34.1
>
>


  reply	other threads:[~2025-12-10 14:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-10  0:20 [PATCH] of: reserved_mem: Allow reserved_mem framework detect "cma=" kernel param Oreoluwa Babatunde
2025-12-10 14:07 ` Rob Herring [this message]
2025-12-12 11:19 ` kernel test robot
2025-12-12 11:19 ` kernel test robot

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='CAL_JsqL6VVQ7K_ZAbHJ8Gb7ei_jusLx6wRn=AdOVgV50dX0ejQ@mail.gmail.com' \
    --to=robh@kernel.org \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=devicetree@vger.kernel.org \
    --cc=iommu@lists.linux.dev \
    --cc=kernel@oss.qualcomm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=m.szyprowski@samsung.com \
    --cc=mhocko@suse.com \
    --cc=oreoluwa.babatunde@oss.qualcomm.com \
    --cc=quic_c_gdjako@quicinc.com \
    --cc=robin.murphy@arm.com \
    --cc=rppt@kernel.org \
    --cc=saravanak@google.com \
    --cc=surenb@google.com \
    --cc=vbabka@suse.cz \
    --cc=ye.li@oss.nxp.com \
    /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;
as well as URLs for NNTP newsgroup(s).