]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
LoongArch: Consolidate max_pfn & max_low_pfn calculation
authorHuacai Chen <chenhuacai@loongson.cn>
Sun, 9 Nov 2025 08:02:01 +0000 (16:02 +0800)
committerHuacai Chen <chenhuacai@loongson.cn>
Mon, 10 Nov 2025 00:37:06 +0000 (08:37 +0800)
Now there 5 places which calculate max_pfn & max_low_pfn:
1. in fdt_setup() for FDT systems;
2. in memblock_init() for ACPI systems;
3. in init_numa_memory() for NUMA systems;
4. in arch_mem_init() to recalculate for "mem=" cmdline;
5. in paging_init() to recalculate for NUMA systems.

Since memblock_init() is called both for ACPI and FDT systems, move the
calculation out of the for_each_efi_memory_desc() loop can eliminate the
first case. The last case is very questionable (may be derived from the
MIPS/Loongson code) and breaks the "mem=" cmdline, so should be removed.
And then the NUMA version of paging_init() can be also eliminated.

After consolidation there are 3 places of calculation:
1. in memblock_init() for both ACPI and FDT systems;
2. in init_numa_memory() to recalculate for NUMA systems;
3. in arch_mem_init() to recalculate for the "mem=" cmdline.

For all cases the calculation is:
max_pfn = PFN_DOWN(memblock_end_of_DRAM());
max_low_pfn = min(PFN_DOWN(HIGHMEM_START), max_pfn);

Cc: stable@vger.kernel.org
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
arch/loongarch/kernel/mem.c
arch/loongarch/kernel/numa.c
arch/loongarch/kernel/setup.c
arch/loongarch/mm/init.c

index aed901c57fb439493c560de777fbc86689f827ae..8ab1ffedc52c518b5504085627202d14348e18da 100644 (file)
@@ -13,7 +13,7 @@
 void __init memblock_init(void)
 {
        u32 mem_type;
-       u64 mem_start, mem_end, mem_size;
+       u64 mem_start, mem_size;
        efi_memory_desc_t *md;
 
        /* Parse memory information */
@@ -21,7 +21,6 @@ void __init memblock_init(void)
                mem_type = md->type;
                mem_start = md->phys_addr;
                mem_size = md->num_pages << EFI_PAGE_SHIFT;
-               mem_end = mem_start + mem_size;
 
                switch (mem_type) {
                case EFI_LOADER_CODE:
@@ -31,8 +30,6 @@ void __init memblock_init(void)
                case EFI_PERSISTENT_MEMORY:
                case EFI_CONVENTIONAL_MEMORY:
                        memblock_add(mem_start, mem_size);
-                       if (max_low_pfn < (mem_end >> PAGE_SHIFT))
-                               max_low_pfn = mem_end >> PAGE_SHIFT;
                        break;
                case EFI_PAL_CODE:
                case EFI_UNUSABLE_MEMORY:
@@ -49,6 +46,8 @@ void __init memblock_init(void)
                }
        }
 
+       max_pfn = PFN_DOWN(memblock_end_of_DRAM());
+       max_low_pfn = min(PFN_DOWN(HIGHMEM_START), max_pfn);
        memblock_set_current_limit(PFN_PHYS(max_low_pfn));
 
        /* Reserve the first 2MB */
index d6e73e8f9c0b66554c10e6533742dc4e1d94ef8a..ab9c660526a3452052a6062b3c9ea80c3512c36c 100644 (file)
@@ -272,7 +272,8 @@ int __init init_numa_memory(void)
                node_mem_init(node);
                node_set_online(node);
        }
-       max_low_pfn = PHYS_PFN(memblock_end_of_DRAM());
+       max_pfn = PFN_DOWN(memblock_end_of_DRAM());
+       max_low_pfn = min(PFN_DOWN(HIGHMEM_START), max_pfn);
 
        setup_nr_node_ids();
        loongson_sysconf.nr_nodes = nr_node_ids;
@@ -283,26 +284,6 @@ int __init init_numa_memory(void)
 
 #endif
 
-void __init paging_init(void)
-{
-       unsigned int node;
-       unsigned long zones_size[MAX_NR_ZONES] = {0, };
-
-       for_each_online_node(node) {
-               unsigned long start_pfn, end_pfn;
-
-               get_pfn_range_for_nid(node, &start_pfn, &end_pfn);
-
-               if (end_pfn > max_low_pfn)
-                       max_low_pfn = end_pfn;
-       }
-#ifdef CONFIG_ZONE_DMA32
-       zones_size[ZONE_DMA32] = MAX_DMA32_PFN;
-#endif
-       zones_size[ZONE_NORMAL] = max_low_pfn;
-       free_area_init(zones_size);
-}
-
 int pcibus_to_node(struct pci_bus *bus)
 {
        return dev_to_node(&bus->dev);
index 69c17d162fff3cc0e85632f5e01f29e7c121c1e2..25a87378e48e43d7d9d121f7371010758b032a13 100644 (file)
@@ -294,8 +294,6 @@ static void __init fdt_setup(void)
 
        early_init_dt_scan(fdt_pointer, __pa(fdt_pointer));
        early_init_fdt_reserve_self();
-
-       max_low_pfn = PFN_PHYS(memblock_end_of_DRAM());
 #endif
 }
 
@@ -390,7 +388,8 @@ static void __init check_kernel_sections_mem(void)
 static void __init arch_mem_init(char **cmdline_p)
 {
        /* Recalculate max_low_pfn for "mem=xxx" */
-       max_pfn = max_low_pfn = PHYS_PFN(memblock_end_of_DRAM());
+       max_pfn = PFN_DOWN(memblock_end_of_DRAM());
+       max_low_pfn = min(PFN_DOWN(HIGHMEM_START), max_pfn);
 
        if (usermem)
                pr_info("User-defined physical RAM map overwrite\n");
index c3e4586a7975783b7eadbd6883c849d6446f8c8f..6bfd4b8dad1b65a034dadacaca9fed6cbed50ea5 100644 (file)
@@ -60,7 +60,6 @@ int __ref page_is_ram(unsigned long pfn)
        return memblock_is_memory(addr) && !memblock_is_reserved(addr);
 }
 
-#ifndef CONFIG_NUMA
 void __init paging_init(void)
 {
        unsigned long max_zone_pfns[MAX_NR_ZONES];
@@ -72,7 +71,6 @@ void __init paging_init(void)
 
        free_area_init(max_zone_pfns);
 }
-#endif /* !CONFIG_NUMA */
 
 void __ref free_initmem(void)
 {