All of lore.kernel.org
 help / color / mirror / Atom feed
* Question about the "Dynamic reserved memory" patch
@ 2020-03-13  3:06 양원혁
  2020-03-13  3:54 ` Valdis Klētnieks
  0 siblings, 1 reply; 3+ messages in thread
From: 양원혁 @ 2020-03-13  3:06 UTC (permalink / raw)
  To: kernelnewbies

Hi. 

Recently, I read about the "Dynamic reserved memory" patch.

In the __reserved_mem_reserve_reg() function, I found something that 
I couldn't easily understand. 

To get help, I sent an e-mail to this mailing list.

I attached the code below.

static int __init __reserved_mem_reserve_reg(unsigned long node,
                                             const char *uname)
{
        int t_len = (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32);
        phys_addr_t base, size;
        int len;
        const __be32 *prop;
        int nomap, first = 1;
        prop = of_get_flat_dt_prop(node, "reg", &len);
        if (!prop)
                return -ENOENT;
        if (len && len % t_len != 0) {
                pr_err("Reserved memory: invalid reg property in '%s',skipping node.\n",
                       uname);
                return -EINVAL;
        }
        nomap = of_get_flat_dt_prop(node, "no-map", NULL) != NULL;
        while (len >= t_len) {
                base = dt_mem_next_cell(dt_root_addr_cells, &prop);
                size = dt_mem_next_cell(dt_root_size_cells, &prop);
                if (size &&
                    early_init_dt_reserve_memory_arch(base, size, nomap) == 0)
                        pr_debug("Reserved memory: reserved region for node '%s': base %pa, size %ld MiB\n",
                                uname, &base, (unsigned long)size / SZ_1M);
                else
                        pr_info("Reserved memory: failed to reserve memory for node '%s': base %pa, size %ld MiB\n",
                                uname, &base, (unsigned long)size / SZ_1M);
                len -= t_len;
                if (first) {
                        fdt_reserved_mem_save_node(node, uname, base, size);
                        first = 0;
                }
        }
        return 0;
}

I found that fdt_reserved_mem_save_node() is called the regardless of
memblock remove/reserve success.

I think early_init_dt_reserve_memory_arch() can fail.(ex. for the lack
of memblock's region)

So I wonder there will be a situation where reserved_mem
initialization will be executed without memory reservation.

I would appreciate it if you let me know if I missed anything :)
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Question about the "Dynamic reserved memory" patch
  2020-03-13  3:06 Question about the "Dynamic reserved memory" patch 양원혁
@ 2020-03-13  3:54 ` Valdis Klētnieks
  2020-03-13  5:13   ` 양원혁
  0 siblings, 1 reply; 3+ messages in thread
From: Valdis Klētnieks @ 2020-03-13  3:54 UTC (permalink / raw)
  To: kjhg4321; +Cc: kernelnewbies


[-- Attachment #1.1: Type: text/plain, Size: 1772 bytes --]

On Fri, 13 Mar 2020 12:06:37 +0900, <kjhg4321@naver.com> said:

> In the __reserved_mem_reserve_reg() function, I found something that
> I couldn't easily understand.
>
> To get help, I sent an e-mail to this mailing list.

>                 if (first) {
>                         fdt_reserved_mem_save_node(node, uname, base, size);
>                         first = 0;
>                 }

> I found that fdt_reserved_mem_save_node() is called the regardless of
> memblock remove/reserve success.
>
> I think early_init_dt_reserve_memory_arch() can fail.(ex. for the lack
> of memblock's region)
>
> So I wonder there will be a situation where reserved_mem
> initialization will be executed without memory reservation.

What you probably missed is that function is wrapped in a #ifdef
CONFIG_OF_EARLY_FLATTREE - and is called to read in the OF devicetree data and
save it in a form the kernel can use.

So there usually shouldn't be a problem in reserving memory early in boot,
unless of course somebody bollixed up a devicetree entry and put in bad values
for base, size, and nomap.   If that happens, the pr_info() call will fire and
hopefully notify somebody there's a problem.

However, fdt_reserved_mem_save_node() needs to happen anyhow, because that's
not initialiing the memory that wasn't actually reserved, it's recording the
fact that the devicetree had a reserved memory request in it, and that needs to
be remembered because there's a second pass over the devicetree data later on
(or so the comments in drivers/of/of_reserved_mem.c tell me).

Having said that, it *may* make sense to elevate the pr_info() call to a
pr_err(), to make it *obvious* that something went pear-shaped in the
devicetree. But that's a decision for the devicetree/OF maintainers.


[-- Attachment #1.2: Type: application/pgp-signature, Size: 832 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Question about the "Dynamic reserved memory" patch
  2020-03-13  3:54 ` Valdis Klētnieks
@ 2020-03-13  5:13   ` 양원혁
  0 siblings, 0 replies; 3+ messages in thread
From: 양원혁 @ 2020-03-13  5:13 UTC (permalink / raw)
  To: kernelnewbies

 
> On Fri, 13 Mar 2020 12:06:37 +0900, <kjhg4321@naver.com> said:
>
> > In the __reserved_mem_reserve_reg() function, I found something that
> > I couldn't easily understand.
> >
> > To get help, I sent an e-mail to this mailing list.
> >
> >                 if (first) {
> >                         fdt_reserved_mem_save_node(node, uname, base, size);
> >                         first = 0;
> >                 }
> >
> > I found that fdt_reserved_mem_save_node() is called the regardless of
> > memblock remove/reserve success.
> >
> > I think early_init_dt_reserve_memory_arch() can fail.(ex. for the lack
> > of memblock's region)
> >
> > So I wonder there will be a situation where reserved_mem
> > initialization will be executed without memory reservation.
>
> What you probably missed is that function is wrapped in a #ifdef
> CONFIG_OF_EARLY_FLATTREE - and is called to read in the OF devicetree data and
> save it in a form the kernel can use.
>
> So there usually shouldn't be a problem in reserving memory early in boot,
> unless of course somebody bollixed up a devicetree entry and put in bad values
> for base, size, and nomap.   

But, This is when the early memory allocation is not active. Therefore, if memblock's 
region[128] is full, memblock_reserve/remove() can fail.(Of course, there should be 
more than 128 reserved memory.)

>However, fdt_reserved_mem_save_node() needs to happen anyhow, because that's
>not initialiing the memory that wasn't actually reserved, it's recording the
>fact that the devicetree had a reserved memory request in it, and that needs to
>be remembered because there's a second pass over the devicetree data later on
>(or so the comments in drivers/of/of_reserved_mem.c tell me).

Yes, fdt_reserved_mem_save_node() just register the reseved memory in the reserve_mem.
then, reserved_mem is passed to _reserved_mem_init_node(). But In this function, 
If the node is "cma", it will call rmem_cma_setup() and it will initializing the cma struct,

So what I was wondering was wouldn't the cma structure be initialized without memory 
being reserved?

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-03-13  5:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-13  3:06 Question about the "Dynamic reserved memory" patch 양원혁
2020-03-13  3:54 ` Valdis Klētnieks
2020-03-13  5:13   ` 양원혁

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.