Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/mm: Consolidate initmem_init()

There are 4 wariants of initmem_init(), for 32 and 64 bits and for
CONFIG_NUMA enabled and disabled.

After commit bbeb69ce3013 ("x86/mm: Remove CONFIG_HIGHMEM64G support")
NUMA is not supported on 32 bit kernels anymore, and
arch/x86/mm/numa_32.c can be just deleted and setup_bootmem_allocator()
with completely misleading name can be folded into initmem_init().

For 64 bits the NUMA variant calls x86_numa_init() and !NUMA variant
sets all memory to node 0. The later can be split out into inline helper
called x86_numa_init() and then both initmem_init() functions become the
same.

Split out memblock_set_node() from initmem_init() for !NUMA on 64 bit
into x86_numa_init() helper and remove arch/x86/mm/numa_*.c that only
contained initmem_init() variants for NUMA configs.

Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: David Woodhouse <dwmw@amazon.co.uk>
Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Cc: Len Brown <len.brown@intel.com>
Link: https://lore.kernel.org/r/20250409122815.420041-1-rppt@kernel.org

authored by

Mike Rapoport (Microsoft) and committed by
Ingo Molnar
35c3151a 78a84fbf

+13 -95
-1
arch/x86/include/asm/page_32_types.h
··· 73 73 extern int sysctl_legacy_va_layout; 74 74 75 75 extern void find_low_pfn_range(void); 76 - extern void setup_bootmem_allocator(void); 77 76 78 77 #endif /* !__ASSEMBLER__ */ 79 78
+1 -1
arch/x86/mm/Makefile
··· 52 52 mmiotrace-y := kmmio.o pf_in.o mmio-mod.o 53 53 obj-$(CONFIG_MMIOTRACE_TEST) += testmmiotrace.o 54 54 55 - obj-$(CONFIG_NUMA) += numa.o numa_$(BITS).o 55 + obj-$(CONFIG_NUMA) += numa.o 56 56 obj-$(CONFIG_AMD_NUMA) += amdtopology.o 57 57 obj-$(CONFIG_ACPI_NUMA) += srat.o 58 58
-7
arch/x86/mm/init_32.c
··· 612 612 highmem_pfn_init(); 613 613 } 614 614 615 - #ifndef CONFIG_NUMA 616 615 void __init initmem_init(void) 617 616 { 618 617 #ifdef CONFIG_HIGHMEM ··· 632 633 printk(KERN_NOTICE "%ldMB LOWMEM available.\n", 633 634 pages_to_mb(max_low_pfn)); 634 635 635 - setup_bootmem_allocator(); 636 - } 637 - #endif /* !CONFIG_NUMA */ 638 - 639 - void __init setup_bootmem_allocator(void) 640 - { 641 636 printk(KERN_INFO " mapped low ram: 0 - %08lx\n", 642 637 max_pfn_mapped<<PAGE_SHIFT); 643 638 printk(KERN_INFO " low ram: 0 - %08lx\n", max_low_pfn<<PAGE_SHIFT);
+6 -1
arch/x86/mm/init_64.c
··· 805 805 } 806 806 807 807 #ifndef CONFIG_NUMA 808 - void __init initmem_init(void) 808 + static inline void x86_numa_init(void) 809 809 { 810 810 memblock_set_node(0, PHYS_ADDR_MAX, &memblock.memory, 0); 811 811 } 812 812 #endif 813 + 814 + void __init initmem_init(void) 815 + { 816 + x86_numa_init(); 817 + } 813 818 814 819 void __init paging_init(void) 815 820 {
+4
arch/x86/mm/mm_internal.h
··· 25 25 26 26 extern unsigned long tlb_single_page_flush_ceiling; 27 27 28 + #ifdef CONFIG_NUMA 29 + void __init x86_numa_init(void); 30 + #endif 31 + 28 32 #endif /* __X86_MM_INTERNAL_H */
+2 -1
arch/x86/mm/numa.c
··· 19 19 #include <asm/proto.h> 20 20 #include <asm/dma.h> 21 21 #include <asm/amd_nb.h> 22 + #include <asm/numa.h> 22 23 23 - #include "numa_internal.h" 24 + #include "mm_internal.h" 24 25 25 26 int numa_off; 26 27
-61
arch/x86/mm/numa_32.c
··· 1 - /* 2 - * Written by: Patricia Gaughen <gone@us.ibm.com>, IBM Corporation 3 - * August 2002: added remote node KVA remap - Martin J. Bligh 4 - * 5 - * Copyright (C) 2002, IBM Corp. 6 - * 7 - * All rights reserved. 8 - * 9 - * This program is free software; you can redistribute it and/or modify 10 - * it under the terms of the GNU General Public License as published by 11 - * the Free Software Foundation; either version 2 of the License, or 12 - * (at your option) any later version. 13 - * 14 - * This program is distributed in the hope that it will be useful, but 15 - * WITHOUT ANY WARRANTY; without even the implied warranty of 16 - * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or 17 - * NON INFRINGEMENT. See the GNU General Public License for more 18 - * details. 19 - * 20 - * You should have received a copy of the GNU General Public License 21 - * along with this program; if not, write to the Free Software 22 - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 - */ 24 - 25 - #include <linux/memblock.h> 26 - #include <linux/init.h> 27 - #include <linux/vmalloc.h> 28 - #include <asm/pgtable_areas.h> 29 - 30 - #include "numa_internal.h" 31 - 32 - extern unsigned long highend_pfn, highstart_pfn; 33 - 34 - void __init initmem_init(void) 35 - { 36 - x86_numa_init(); 37 - 38 - #ifdef CONFIG_HIGHMEM 39 - highstart_pfn = highend_pfn = max_pfn; 40 - if (max_pfn > max_low_pfn) 41 - highstart_pfn = max_low_pfn; 42 - printk(KERN_NOTICE "%ldMB HIGHMEM available.\n", 43 - pages_to_mb(highend_pfn - highstart_pfn)); 44 - high_memory = (void *) __va(highstart_pfn * PAGE_SIZE - 1) + 1; 45 - #else 46 - high_memory = (void *) __va(max_low_pfn * PAGE_SIZE - 1) + 1; 47 - #endif 48 - printk(KERN_NOTICE "%ldMB LOWMEM available.\n", 49 - pages_to_mb(max_low_pfn)); 50 - printk(KERN_DEBUG "max_low_pfn = %lx, highstart_pfn = %lx\n", 51 - max_low_pfn, highstart_pfn); 52 - 53 - printk(KERN_DEBUG "Low memory ends at vaddr %08lx\n", 54 - (ulong) pfn_to_kaddr(max_low_pfn)); 55 - 56 - printk(KERN_DEBUG "High memory starts at vaddr %08lx\n", 57 - (ulong) pfn_to_kaddr(highstart_pfn)); 58 - 59 - __vmalloc_start_set = true; 60 - setup_bootmem_allocator(); 61 - }
-13
arch/x86/mm/numa_64.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - /* 3 - * Generic VM initialization for x86-64 NUMA setups. 4 - * Copyright 2002,2003 Andi Kleen, SuSE Labs. 5 - */ 6 - #include <linux/memblock.h> 7 - 8 - #include "numa_internal.h" 9 - 10 - void __init initmem_init(void) 11 - { 12 - x86_numa_init(); 13 - }
-10
arch/x86/mm/numa_internal.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - #ifndef __X86_MM_NUMA_INTERNAL_H 3 - #define __X86_MM_NUMA_INTERNAL_H 4 - 5 - #include <linux/types.h> 6 - #include <asm/numa.h> 7 - 8 - void __init x86_numa_init(void); 9 - 10 - #endif /* __X86_MM_NUMA_INTERNAL_H */