Question about the "Dynamic reserved memory" patch

양원혁 kjhg4321 at naver.com
Thu Mar 12 23:06:37 EDT 2020


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 :)


More information about the Kernelnewbies mailing list