arch, mm: consolidate hugetlb early reservation
Subsystems (33)
Mike Rapoport
maintainerv3 cover arch, mm: consolidate hugetlb early reservation
From: "Mike Rapoport (Microsoft)" <[email protected]>
Hi,
Order in which early memory reservation for hugetlb happens depends on architecture, on configuration options and on command line parameters.
Some architectures rely on the core MM to call hugetlb_bootmem_alloc() while others call it very early to allow pre-allocation of HVO-style vmemmap.
When hugetlb_cma is supported by an architecture it is initialized during setup_arch() and then later hugetlb_init code needs to understand did it happen or not.
To make everything consistent and unified, both reservation of hugetlb memory from bootmem and creation of CMA areas for hugetlb must be called from core MM initialization and it would have been a simple change. However, HVO-style pre-initialization ordering requirements slightly complicate things and for HVO pre-init to work sparse and memory map should be initialized after hugetlb reservations.
This required pulling out the call to free_area_init() out of setup_arch() path and moving it MM initialization and this is what the first 23 patches do.
These changes are deliberately split into per-arch patches that change how the zone limits are calculated for each architecture and the patches 22 and 23 just remove the calls to free_area_init() and sprase_init() from arch/*.
Patch 24 is a simple cleanup for MIPS.
Patches 25 and 26 actually consolidate hugetlb reservations and patches 27 and 28 perform some aftermath cleanups.
I tried to trim the distribution list and although it's still quite long if you feel that someone was wrongly excluded please add them back.
The changes also available in git:
https://git.kernel.org/pub/scm/linux/kernel/git/rppt/linux.git/log/?h=hugetlb-init/v3
v3 changes:
* fix empty_zero_page initialization on arm
* fix ZONE_DMA limit calculation on powerpc
* add Acks
v2: https://lore.kernel.org/all/[email protected]
* move the hugetlb and memory map initializaion to mm_core_init_early()
* add Acks
v1: https://lore.kernel.org/all/[email protected]
Klara Modin (1):
arm: make initialization of zero page independent of the memory map
Mike Rapoport (Microsoft) (28):
alpha: introduce arch_zone_limits_init()
arc: introduce arch_zone_limits_init()
arm: introduce arch_zone_limits_init()
arm64: introduce arch_zone_limits_init()
csky: introduce arch_zone_limits_init()
hexagon: introduce arch_zone_limits_init()
loongarch: introduce arch_zone_limits_init()
m68k: introduce arch_zone_limits_init()
microblaze: introduce arch_zone_limits_init()
mips: introduce arch_zone_limits_init()
nios2: introduce arch_zone_limits_init()
openrisc: introduce arch_zone_limits_init()
parisc: introduce arch_zone_limits_init()
powerpc: introduce arch_zone_limits_init()
riscv: introduce arch_zone_limits_init()
s390: introduce arch_zone_limits_init()
sh: introduce arch_zone_limits_init()
sparc: introduce arch_zone_limits_init()
um: introduce arch_zone_limits_init()
x86: introduce arch_zone_limits_init()
xtensa: introduce arch_zone_limits_init()
arch, mm: consolidate initialization of nodes, zones and memory map arch, mm: consolidate initialization of SPARSE memory model
mips: drop paging_init()
x86: don't reserve hugetlb memory in setup_arch()
mm, arch: consolidate hugetlb CMA reservation
mm/hugetlb: drop hugetlb_cma_check()
Revert "mm/hugetlb: deal with multiple calls to hugetlb_bootmem_alloc"
.../driver-api/cxl/linux/early-boot.rst | 2 +- Documentation/mm/memory-model.rst | 3 -- .../translations/zh_CN/mm/memory-model.rst | 2 - arch/alpha/kernel/setup.c | 1 - arch/alpha/mm/init.c | 16 ++++---- arch/arc/mm/init.c | 37 +++++++++--------- arch/arm/include/asm/pgtable.h | 4 +- arch/arm/mm/init.c | 25 ++---------- arch/arm/mm/mmu.c | 10 +---- arch/arm/mm/nommu.c | 10 +---- arch/arm64/include/asm/hugetlb.h | 2 - arch/arm64/mm/hugetlbpage.c | 10 ++--- arch/arm64/mm/init.c | 39 ++++++++----------- arch/csky/kernel/setup.c | 16 ++++---- arch/hexagon/mm/init.c | 19 +++------ arch/loongarch/include/asm/pgtable.h | 2 - arch/loongarch/kernel/setup.c | 10 ----- arch/loongarch/mm/init.c | 6 +-- arch/m68k/mm/init.c | 8 ++-- arch/m68k/mm/mcfmmu.c | 3 -- arch/m68k/mm/motorola.c | 6 +-- arch/m68k/mm/sun3mmu.c | 9 ----- arch/microblaze/mm/init.c | 22 +++++------ arch/mips/include/asm/pgalloc.h | 2 - arch/mips/include/asm/pgtable.h | 2 +- arch/mips/kernel/setup.c | 15 +------ arch/mips/loongson64/numa.c | 10 ++--- arch/mips/mm/init.c | 8 +--- arch/mips/sgi-ip27/ip27-memory.c | 8 +--- arch/nios2/mm/init.c | 12 +++--- arch/openrisc/mm/init.c | 10 +---- arch/parisc/mm/init.c | 11 +----- arch/powerpc/include/asm/hugetlb.h | 5 --- arch/powerpc/include/asm/setup.h | 4 ++ arch/powerpc/kernel/setup-common.c | 1 - arch/powerpc/mm/hugetlbpage.c | 11 ++---- arch/powerpc/mm/mem.c | 27 +++++-------- arch/powerpc/mm/numa.c | 2 - arch/riscv/mm/hugetlbpage.c | 8 ++++ arch/riscv/mm/init.c | 10 +---- arch/s390/kernel/setup.c | 2 - arch/s390/mm/hugetlbpage.c | 8 ++++ arch/s390/mm/init.c | 13 +++---- arch/sh/mm/init.c | 12 +++--- arch/sparc/mm/init_64.c | 17 +++----- arch/sparc/mm/srmmu.c | 17 ++++---- arch/um/kernel/mem.c | 10 ++--- arch/x86/kernel/setup.c | 5 --- arch/x86/mm/hugetlbpage.c | 8 ++++ arch/x86/mm/init.c | 8 +--- arch/x86/mm/init_32.c | 2 - arch/x86/mm/init_64.c | 4 -- arch/x86/mm/mm_internal.h | 1 - arch/xtensa/mm/init.c | 14 +++---- include/linux/hugetlb.h | 12 ++---- include/linux/mm.h | 5 ++- include/linux/mmzone.h | 2 - init/main.c | 1 + mm/hugetlb.c | 13 ------- mm/hugetlb_cma.c | 33 ++++++++-------- mm/hugetlb_cma.h | 5 --- mm/hugetlb_vmemmap.c | 11 ------ mm/internal.h | 6 +++ mm/mm_init.c | 20 ++++++---- 64 files changed, 223 insertions(+), 414 deletions(-)
base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8
Signature · 1 line
2.51.0
Mike Rapoport
maintainerPATCH v3 1/29 alpha: introduce arch_zone_limits_init()
From: "Mike Rapoport (Microsoft)" <[email protected]>
Move calculations of zone limits to a dedicated arch_zone_limits_init() function.
Later MM core will use this function as an architecture specific callback during nodes and zones initialization and thus there won't be a need to call free_area_init() from every architecture.
--- arch/alpha/mm/init.c | 15 ++++++++++----- include/linux/mm.h | 1 + 2 files changed, 11 insertions(+), 5 deletions(-)
arch/alpha/mm/init.c +10 -5
@@ -208,12 +208,8 @@ callback_init(void * kernel_end)return kernel_end; } -/* -* paging_init() sets up the memory map. -*/ -void __init paging_init (void ) +void __init arch_zone_limits_init (unsigned long *max_zone_pfn) { -unsigned long max_zone_pfn[MAX_NR_ZONES ] = {0 , };unsigned long dma_pfn; dma_pfn =virt_to_phys ((char *)MAX_DMA_ADDRESS ) >>PAGE_SHIFT ;
@@ -221,8 +217,17 @@ void __init paging_init(void) max_zone_pfn[ZONE_DMA ] = dma_pfn; max_zone_pfn[ZONE_NORMAL ] = max_pfn; +} + +/* +* paging_init() sets up the memory map. +*/ +void __init paging_init (void ) +{ +unsigned long max_zone_pfn[MAX_NR_ZONES ] = {0 , };/* Initialize mem_map[]. */ +arch_zone_limits_init (max_zone_pfn);free_area_init (max_zone_pfn);/* Initialize the kernel's ZERO_PGE. */
include/linux/mm.h +1 -0
@@ -3552,6 +3552,7 @@ static inline unsigned long get_num_physpages(void)* free_area_init(max_zone_pfns); */ void free_area_init (unsigned long *max_zone_pfn); +void arch_zone_limits_init (unsigned long *max_zone_pfn);unsigned long node_map_pfn_alignment (void );extern unsigned long absent_pages_in_range (unsigned long start_pfn,unsigned long end_pfn);
Signature · 1 line
2.51.0
Mike Rapoport
maintainerPATCH v3 2/29 arc: introduce arch_zone_limits_init()
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Move calculations of zone limits to a dedicated arch_zone_limits_init() function.
Later MM core will use this function as an architecture specific callback during nodes and zones initialization and thus there won't be a need to call free_area_init() from every architecture.
--- arch/arc/mm/init.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-)
arch/arc/mm/init.c +20 -14
@@ -75,6 +75,25 @@ void __init early_init_dt_add_memory_arch(u64 base, u64 size) base, TO_MB(size), !in_use ? "Not used":""); } +void __init arch_zone_limits_init (unsigned long *max_zone_pfn) +{ +/*----------------- node/zones setup --------------------------*/ + max_zone_pfn[ZONE_NORMAL ] = max_low_pfn; + +#ifdef CONFIG_HIGHMEM +/* +* max_high_pfn should be ok here for both HIGHMEM and HIGHMEM+PAE. +* For HIGHMEM without PAE max_high_pfn should be less than +* min_low_pfn to guarantee that these two regions don't overlap. +* For PAE case highmem is greater than lowmem, so it is natural +* to use max_high_pfn. +* +* In both cases, holes should be handled by pfn_valid(). +*/ + max_zone_pfn[ZONE_HIGHMEM ] = max_high_pfn; +#endif +} +/* * First memory setup routine called from setup_arch() * 1. setup swapper's mm @init_mm
@@ -122,9 +141,6 @@ void __init setup_arch_memory(void)memblock_dump_all (); -/*----------------- node/zones setup --------------------------*/ - max_zone_pfn[ZONE_NORMAL ] = max_low_pfn; -#ifdef CONFIG_HIGHMEM /* * On ARC (w/o PAE) HIGHMEM addresses are actually smaller (0 based)
@@ -139,21 +155,11 @@ void __init setup_arch_memory(void) min_high_pfn =PFN_DOWN (high_mem_start); max_high_pfn =PFN_DOWN (high_mem_start + high_mem_sz); -/* -* max_high_pfn should be ok here for both HIGHMEM and HIGHMEM+PAE. -* For HIGHMEM without PAE max_high_pfn should be less than -* min_low_pfn to guarantee that these two regions don't overlap. -* For PAE case highmem is greater than lowmem, so it is natural -* to use max_high_pfn. -* -* In both cases, holes should be handled by pfn_valid(). -*/ - max_zone_pfn[ZONE_HIGHMEM ] = max_high_pfn; - arch_pfn_offset =min (min_low_pfn, min_high_pfn);kmap_init ();#endif /* CONFIG_HIGHMEM */ +arch_zone_limits_init (max_zone_pfn);free_area_init (max_zone_pfn); }
Signature · 1 line
2.51.0
Mike Rapoport
maintainerPATCH v3 3/29 arm: introduce arch_zone_limits_init()
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Move calculations of zone limits to a dedicated arch_zone_limits_init() function.
Later MM core will use this function as an architecture specific callback during nodes and zones initialization and thus there won't be a need to call free_area_init() from every architecture.
--- arch/arm/mm/init.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
arch/arm/mm/init.c +12 -7
@@ -107,18 +107,23 @@ void __init setup_dma_zone(const struct machine_desc *mdesc)#endif } -static void __init zone_sizes_init (unsigned long min,unsigned long max_low, -unsigned long max_high) +void __init arch_zone_limits_init (unsigned long *max_zone_pfn) { -unsigned long max_zone_pfn[MAX_NR_ZONES ] = {0 }; -#ifdef CONFIG_ZONE_DMA - max_zone_pfn[ZONE_DMA ] =min (arm_dma_pfn_limit, max_low); + max_zone_pfn[ZONE_DMA ] =min (arm_dma_pfn_limit, max_low_pfn);#endif - max_zone_pfn[ZONE_NORMAL ] = max_low; + max_zone_pfn[ZONE_NORMAL ] = max_low_pfn;#ifdef CONFIG_HIGHMEM - max_zone_pfn[ZONE_HIGHMEM ] = max_high; + max_zone_pfn[ZONE_HIGHMEM ] = max_pfn;#endif +} + +static void __init zone_sizes_init (unsigned long min,unsigned long max_low, +unsigned long max_high) +{ +unsigned long max_zone_pfn[MAX_NR_ZONES ] = {0 }; + +arch_zone_limits_init (max_zone_pfn);free_area_init (max_zone_pfn); }
Signature · 1 line
2.51.0
Mike Rapoport
maintainerPATCH v3 4/29 arm: make initialization of zero page independent of the memory map
In reply to Mike RapoportFrom: Klara Modin <[email protected]>
Unlike most architectures, arm keeps a struct page pointer to the empty_zero_page and to initialize it requires conversion of a virtual address to page which makes it necessary to have memory map initialized before creating the empty_zero_page.
Make empty_zero_page a stataic array in BSS to decouple it's initialization from the initialization of the memory map.
This also aligns arm with vast majorty of architectures.
--- arch/arm/include/asm/pgtable.h | 4 ++-- arch/arm/mm/mmu.c | 10 +--------- arch/arm/mm/nommu.c | 10 +--------- 3 files changed, 4 insertions(+), 20 deletions(-)
arch/arm/include/asm/pgtable.h +2 -2
@@ -15,8 +15,8 @@* ZERO_PAGE is a global shared page that is always zero: used * for zero-mapped memory areas etc.. */ -extern struct page *empty_zero_page; -#define ZERO_PAGE (vaddr) (empty_zero_page) +extern unsigned long empty_zero_page[PAGE_SIZE /sizeof (unsigned long )]; +#define ZERO_PAGE (vaddr) (virt_to_page(empty_zero_page))#endif #include <asm-generic/pgtable-nopud.h>
arch/arm/mm/mmu.c +1 -9
@@ -45,7 +45,7 @@ extern unsigned long __atags_pointer;* empty_zero_page is a special page that is used for * zero-initialized data and COW. */ -struct page *empty_zero_page; +unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)] __page_aligned_bss;EXPORT_SYMBOL (empty_zero_page);/*
@@ -1754,8 +1754,6 @@ static void __init early_fixmap_shutdown(void)*/ void __init paging_init (const struct machine_desc *mdesc) { -void *zero_page; -#ifdef CONFIG_XIP_KERNEL /* Store the kernel RW RAM region start/end in these variables */ kernel_sec_start =CONFIG_PHYS_OFFSET &SECTION_MASK ;
@@ -1781,13 +1779,7 @@ void __init paging_init(const struct machine_desc *mdesc) top_pmd =pmd_off_k (0xffff0000 ); -/* allocate the zero page. */ - zero_page =early_alloc (PAGE_SIZE ); -bootmem_init (); - - empty_zero_page =virt_to_page (zero_page); -__flush_dcache_folio (NULL ,page_folio (empty_zero_page)); }void __init early_mm_init (const struct machine_desc *mdesc)
arch/arm/mm/nommu.c +1 -9
@@ -31,7 +31,7 @@ unsigned long vectors_base;* empty_zero_page is a special page that is used for * zero-initialized data and COW. */ -struct page *empty_zero_page; +unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)] __page_aligned_bss;EXPORT_SYMBOL (empty_zero_page);#ifdef CONFIG_ARM_MPU
@@ -156,18 +156,10 @@ void __init adjust_lowmem_bounds(void)*/ void __init paging_init (const struct machine_desc *mdesc) { -void *zero_page; -early_trap_init ((void *)vectors_base);mpu_setup (); -/* allocate the zero page. */ - zero_page = (void *)memblock_alloc_or_panic (PAGE_SIZE ,PAGE_SIZE ); -bootmem_init (); - - empty_zero_page =virt_to_page (zero_page); -flush_dcache_page (empty_zero_page); }/*
Signature · 1 line
2.51.0
Mike Rapoport
maintainerPATCH v3 5/29 arm64: introduce arch_zone_limits_init()
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Move calculations of zone limits to a dedicated arch_zone_limits_init() function.
Later MM core will use this function as an architecture specific callback during nodes and zones initialization and thus there won't be a need to call free_area_init() from every architecture.
While on it rename zone_sizes_init() to dma_limits_init() to better reflect what that function does.
--- arch/arm64/mm/init.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)
arch/arm64/mm/init.c +17 -5
@@ -118,7 +118,21 @@ static phys_addr_t __init max_zone_phys(phys_addr_t zone_limit)return min (zone_limit,memblock_end_of_DRAM () -1 ) +1 ; } -static void __init zone_sizes_init (void ) +void __init arch_zone_limits_init (unsigned long *max_zone_pfns) +{ +phys_addr_t __maybe_unused dma32_phys_limit = +max_zone_phys (DMA_BIT_MASK (32 )); + +#ifdef CONFIG_ZONE_DMA + max_zone_pfns[ZONE_DMA ] =PFN_DOWN (max_zone_phys (zone_dma_limit)); +#endif +#ifdef CONFIG_ZONE_DMA32 + max_zone_pfns[ZONE_DMA32 ] =PFN_DOWN (dma32_phys_limit); +#endif + max_zone_pfns[ZONE_NORMAL ] = max_pfn; +} + +static void __init dma_limits_init (void ) {unsigned long max_zone_pfns[MAX_NR_ZONES ] = {0 };phys_addr_t __maybe_unused acpi_zone_dma_limit;
@@ -139,17 +153,15 @@ static void __init zone_sizes_init(void)if (memblock_start_of_DRAM () <U32_MAX ) zone_dma_limit =min (zone_dma_limit,U32_MAX ); arm64_dma_phys_limit =max_zone_phys (zone_dma_limit); - max_zone_pfns[ZONE_DMA ] =PFN_DOWN (arm64_dma_phys_limit);#endif #ifdef CONFIG_ZONE_DMA32 - max_zone_pfns[ZONE_DMA32 ] =PFN_DOWN (dma32_phys_limit);if (!arm64_dma_phys_limit) arm64_dma_phys_limit = dma32_phys_limit;#endif if (!arm64_dma_phys_limit) arm64_dma_phys_limit =PHYS_MASK +1 ; - max_zone_pfns[ZONE_NORMAL ] = max_pfn; +arch_zone_limits_init (max_zone_pfns);free_area_init (max_zone_pfns); }
@@ -319,7 +331,7 @@ void __init bootmem_init(void)* done after the fixed reservations */ sparse_init (); -zone_sizes_init (); +dma_limits_init ();/* * Reserve the CMA area after arm64_dma_phys_limit was initialised.
Signature · 1 line
2.51.0
Mike Rapoport
maintainerPATCH v3 6/29 csky: introduce arch_zone_limits_init()
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Move calculations of zone limits to a dedicated arch_zone_limits_init() function.
Later MM core will use this function as an architecture specific callback during nodes and zones initialization and thus there won't be a need to call free_area_init() from every architecture.
--- arch/csky/kernel/setup.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
arch/csky/kernel/setup.c +9 -3
@@ -51,6 +51,14 @@ static void __init setup_initrd(void) }#endif +void __init arch_zone_limits_init (unsigned long *max_zone_pfns) +{ + max_zone_pfns[ZONE_NORMAL ] = max_low_pfn; +#ifdef CONFIG_HIGHMEM + max_zone_pfns[ZONE_HIGHMEM ] = max_pfn; +#endif +} +static void __init csky_memblock_init (void ) {unsigned long lowmem_size =PFN_DOWN (LOWMEM_LIMIT -PHYS_OFFSET_OFFSET );
@@ -83,12 +91,9 @@ static void __init csky_memblock_init(void)setup_initrd ();#endif - max_zone_pfn[ZONE_NORMAL ] = max_low_pfn; -mmu_init (min_low_pfn, max_low_pfn);#ifdef CONFIG_HIGHMEM - max_zone_pfn[ZONE_HIGHMEM ] = max_pfn; highstart_pfn = max_low_pfn; highend_pfn = max_pfn;
@@ -97,6 +102,7 @@ static void __init csky_memblock_init(void)dma_contiguous_reserve (0 ); +arch_zone_limits_init (max_zone_pfn);free_area_init (max_zone_pfn); }
Signature · 1 line
2.51.0
Mike Rapoport
maintainerPATCH v3 7/29 hexagon: introduce arch_zone_limits_init()
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Move calculations of zone limits to a dedicated arch_zone_limits_init() function.
Later MM core will use this function as an architecture specific callback during nodes and zones initialization and thus there won't be a need to call free_area_init() from every architecture.
--- arch/hexagon/mm/init.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)
arch/hexagon/mm/init.c +13 -10
@@ -54,6 +54,18 @@ void sync_icache_dcache(pte_t pte)__vmcache_idsync (addr,PAGE_SIZE ); } +void __init arch_zone_limits_init (unsigned long *max_zone_pfns) +{ +/* +* This is not particularly well documented anywhere, but +* give ZONE_NORMAL all the memory, including the big holes +* left by the kernel+bootmem_map which are already left as reserved +* in the bootmem_map; free_area_init should see those bits and +* adjust accordingly. +*/ + max_zone_pfns[ZONE_NORMAL ] = max_low_pfn; +} +/* * In order to set up page allocator "nodes", * somebody has to call free_area_init() for UMA.
@@ -65,16 +77,7 @@ static void __init paging_init(void) {unsigned long max_zone_pfn[MAX_NR_ZONES ] = {0 , }; -/* -* This is not particularly well documented anywhere, but -* give ZONE_NORMAL all the memory, including the big holes -* left by the kernel+bootmem_map which are already left as reserved -* in the bootmem_map; free_area_init should see those bits and -* adjust accordingly. -*/ - - max_zone_pfn[ZONE_NORMAL ] = max_low_pfn; - +arch_zone_limits_init (max_zone_pfn);free_area_init (max_zone_pfn);/* sets up the zonelists and mem_map */ /*
Signature · 1 line
2.51.0
Mike Rapoport
maintainerPATCH v3 8/29 loongarch: introduce arch_zone_limits_init()
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Move calculations of zone limits to a dedicated arch_zone_limits_init() function.
Later MM core will use this function as an architecture specific callback during nodes and zones initialization and thus there won't be a need to call free_area_init() from every architecture.
--- arch/loongarch/mm/init.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
arch/loongarch/mm/init.c +7 -3
@@ -60,15 +60,19 @@ int __ref page_is_ram(unsigned long pfn)return memblock_is_memory (addr) && !memblock_is_reserved (addr); } -void __init paging_init (void ) +void __init arch_zone_limits_init (unsigned long *max_zone_pfns) { -unsigned long max_zone_pfns[MAX_NR_ZONES ]; -#ifdef CONFIG_ZONE_DMA32 max_zone_pfns[ZONE_DMA32 ] =MAX_DMA32_PFN ;#endif max_zone_pfns[ZONE_NORMAL ] = max_low_pfn; +} + +void __init paging_init (void ) +{ +unsigned long max_zone_pfns[MAX_NR_ZONES ]; +arch_zone_limits_init (max_zone_pfns);free_area_init (max_zone_pfns); }
Signature · 1 line
2.51.0
Mike Rapoport
maintainerPATCH v3 9/29 m68k: introduce arch_zone_limits_init()
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Move calculations of zone limits to a dedicated arch_zone_limits_init() function.
Later MM core will use this function as an architecture specific callback during nodes and zones initialization and thus there won't be a need to call free_area_init() from every architecture.
Since all variants of m68k add all memory to ZONE_DMA, it is possible to use unified implementation for arch_zone_limits_init() that sets the end of ZONE_DMA to memblock_end_of_DRAM().
--- arch/m68k/mm/init.c | 7 ++++++- arch/m68k/mm/mcfmmu.c | 2 +- arch/m68k/mm/motorola.c | 2 +- arch/m68k/mm/sun3mmu.c | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-)
arch/m68k/mm/init.c +6 -1
@@ -40,6 +40,11 @@void *empty_zero_page;EXPORT_SYMBOL (empty_zero_page); +void __init arch_zone_limits_init (unsigned long *max_zone_pfns) +{ + max_zone_pfns[ZONE_DMA ] =PFN_DOWN (memblock_end_of_DRAM ()); +} +#ifdef CONFIG_MMU int m68k_virt_to_node_shift;
@@ -69,7 +74,7 @@ void __init paging_init(void) high_memory = (void *) end_mem; empty_zero_page =memblock_alloc_or_panic (PAGE_SIZE ,PAGE_SIZE ); - max_zone_pfn[ZONE_DMA ] = end_mem >>PAGE_SHIFT ; +arch_zone_limits_init (max_zone_pfn);free_area_init (max_zone_pfn); }
arch/m68k/mm/mcfmmu.c +1 -1
@@ -73,7 +73,7 @@ void __init paging_init(void) } current->mm =NULL ; - max_zone_pfn[ZONE_DMA ] =PFN_DOWN (_ramend); +arch_zone_limits_init (max_zone_pfn);free_area_init (max_zone_pfn); }
arch/m68k/mm/motorola.c +1 -1
@@ -517,6 +517,6 @@ void __init paging_init(void)if (node_present_pages (i))node_set_state (i,N_NORMAL_MEMORY ); - max_zone_pfn[ZONE_DMA ] =memblock_end_of_DRAM (); +arch_zone_limits_init (max_zone_pfn);free_area_init (max_zone_pfn); }
arch/m68k/mm/sun3mmu.c +1 -1
@@ -82,7 +82,7 @@ void __init paging_init(void) current->mm =NULL ;/* memory sizing is a hack stolen from motorola.c.. hope it works for us */ - max_zone_pfn[ZONE_DMA ] = ((unsigned long )high_memory) >>PAGE_SHIFT ; +arch_zone_limits_init (max_zone_pfn);/* I really wish I knew why the following change made things better... -- Sam */ free_area_init (max_zone_pfn);
Signature · 1 line
2.51.0
Mike Rapoport
maintainerPATCH v3 10/29 microblaze: introduce arch_zone_limits_init()
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Move calculations of zone limits to a dedicated arch_zone_limits_init() function.
Later MM core will use this function as an architecture specific callback during nodes and zones initialization and thus there won't be a need to call free_area_init() from every architecture.
--- arch/microblaze/mm/init.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
arch/microblaze/mm/init.c +11 -6
@@ -54,6 +54,16 @@ static void __init highmem_init(void) }#endif /* CONFIG_HIGHMEM */ +void __init arch_zone_limits_init (unsigned long *max_zone_pfns) +{ +#ifdef CONFIG_HIGHMEM + max_zone_pfns[ZONE_DMA ] = max_low_pfn; + max_zone_pfns[ZONE_HIGHMEM ] = max_pfn; +#else + max_zone_pfns[ZONE_DMA ] = max_pfn; +#endif +} +/* * paging_init() sets up the page tables - in fact we've already done this. */
@@ -71,13 +81,8 @@ static void __init paging_init(void)#ifdef CONFIG_HIGHMEM highmem_init (); - - zones_size[ZONE_DMA ] = max_low_pfn; - zones_size[ZONE_HIGHMEM ] = max_pfn; -#else - zones_size[ZONE_DMA ] = max_pfn;#endif - +arch_zone_limits_init (zones_size);/* We don't have holes in memory map */ free_area_init (zones_size); }
Signature · 1 line
2.51.0
Mike Rapoport
maintainerPATCH v3 11/29 mips: introduce arch_zone_limits_init()
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Move calculations of zone limits to a dedicated arch_zone_limits_init() function.
Later MM core will use this function as an architecture specific callback during nodes and zones initialization and thus there won't be a need to call free_area_init() from every architecture.
--- arch/mips/loongson64/numa.c | 9 +++++++-- arch/mips/mm/init.c | 14 +++++++++----- arch/mips/sgi-ip27/ip27-memory.c | 7 ++++++- 3 files changed, 22 insertions(+), 8 deletions(-)
arch/mips/loongson64/numa.c +7 -2
@@ -154,13 +154,18 @@ static __init void prom_meminit(void) } } +void __init arch_zone_limits_init (unsigned long *max_zone_pfns) +{ + max_zone_pfns[ZONE_DMA32 ] =MAX_DMA32_PFN ; + max_zone_pfns[ZONE_NORMAL ] = max_low_pfn; +} +void __init paging_init (void ) {unsigned long zones_size[MAX_NR_ZONES ] = {0 , };pagetable_init (); - zones_size[ZONE_DMA32 ] =MAX_DMA32_PFN ; - zones_size[ZONE_NORMAL ] = max_low_pfn; +arch_zone_limits_init (zones_size);free_area_init (zones_size); }
arch/mips/mm/init.c +9 -5
@@ -394,12 +394,8 @@ void maar_init(void) }#ifndef CONFIG_NUMA -void __init paging_init (void ) +void __init arch_zone_limits_init (unsigned long *max_zone_pfns) { -unsigned long max_zone_pfns[MAX_NR_ZONES ]; - -pagetable_init (); -#ifdef CONFIG_ZONE_DMA max_zone_pfns[ZONE_DMA ] =MAX_DMA_PFN ;#endif
@@ -417,7 +413,15 @@ void __init paging_init(void) max_zone_pfns[ZONE_HIGHMEM] = max_low_pfn; }#endif +} + +void __init paging_init (void ) +{ +unsigned long max_zone_pfns[MAX_NR_ZONES ]; + +pagetable_init (); +arch_zone_limits_init (max_zone_pfns);free_area_init (max_zone_pfns); }
arch/mips/sgi-ip27/ip27-memory.c +6 -1
@@ -406,11 +406,16 @@ void __init prom_meminit(void) } } +void __init arch_zone_limits_init (unsigned long *max_zone_pfns) +{ + max_zone_pfns[ZONE_NORMAL ] = max_low_pfn; +} +void __init paging_init (void ) {unsigned long zones_size[MAX_NR_ZONES ] = {0 , };pagetable_init (); - zones_size[ZONE_NORMAL ] = max_low_pfn; +arch_zone_limits_init (zones_size);free_area_init (zones_size); }
Signature · 1 line
2.51.0
Mike Rapoport
maintainerPATCH v3 12/29 nios2: introduce arch_zone_limits_init()
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Move calculations of zone limits to a dedicated arch_zone_limits_init() function.
Later MM core will use this function as an architecture specific callback during nodes and zones initialization and thus there won't be a need to call free_area_init() from every architecture.
--- arch/nios2/mm/init.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
arch/nios2/mm/init.c +6 -2
@@ -38,6 +38,11 @@pgd_t *pgd_current; +void __init arch_zone_limits_init (unsigned long *max_zone_pfns) +{ + max_zone_pfns[ZONE_NORMAL ] = max_low_pfn; +} +/* * paging_init() continues the virtual memory environment setup which * was begun by the code in arch/head.S.
@@ -51,8 +56,7 @@ void __init paging_init(void)pagetable_init (); pgd_current = swapper_pg_dir; - max_zone_pfn[ZONE_NORMAL ] = max_low_pfn; - +arch_zone_limits_init (max_zone_pfn);/* pass the memory from the bootmem allocator to the main allocator */ free_area_init (max_zone_pfn);
Signature · 1 line
2.51.0
Mike Rapoport
maintainerPATCH v3 13/29 openrisc: introduce arch_zone_limits_init()
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Move calculations of zone limits to a dedicated arch_zone_limits_init() function.
Later MM core will use this function as an architecture specific callback during nodes and zones initialization and thus there won't be a need to call free_area_init() from every architecture.
--- arch/openrisc/mm/init.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
arch/openrisc/mm/init.c +8 -4
@@ -39,15 +39,19 @@int mem_init_done; -static void __init zone_sizes_init (void ) +void __init arch_zone_limits_init (unsigned long *max_zone_pfns) { -unsigned long max_zone_pfn[MAX_NR_ZONES ] = {0 }; -/* * We use only ZONE_NORMAL */ - max_zone_pfn[ZONE_NORMAL ] = max_low_pfn; + max_zone_pfns[ZONE_NORMAL ] = max_low_pfn; +} + +static void __init zone_sizes_init (void ) +{ +unsigned long max_zone_pfn[MAX_NR_ZONES ] = {0 }; +arch_zone_limits_init (max_zone_pfn);free_area_init (max_zone_pfn); }
Signature · 1 line
2.51.0
Mike Rapoport
maintainerPATCH v3 14/29 parisc: introduce arch_zone_limits_init()
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Move calculations of zone limits to a dedicated arch_zone_limits_init() function.
Later MM core will use this function as an architecture specific callback during nodes and zones initialization and thus there won't be a need to call free_area_init() from every architecture.
--- arch/parisc/mm/init.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
arch/parisc/mm/init.c +6 -2
@@ -693,12 +693,16 @@ static void __init fixmap_init(void) }while (addr < end); } +void __init arch_zone_limits_init (unsigned long *max_zone_pfns) +{ + max_zone_pfns[ZONE_NORMAL ] =PFN_DOWN (memblock_end_of_DRAM ()); +} +static void __init parisc_bootmem_free (void ) {unsigned long max_zone_pfn[MAX_NR_ZONES ] = {0 , }; - max_zone_pfn[0 ] =memblock_end_of_DRAM (); - +arch_zone_limits_init (max_zone_pfn);free_area_init (max_zone_pfn); }
Signature · 1 line
2.51.0
Mike Rapoport
maintainerPATCH v3 15/29 powerpc: introduce arch_zone_limits_init()
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Move calculations of zone limits to a dedicated arch_zone_limits_init() function.
Later MM core will use this function as an architecture specific callback during nodes and zones initialization and thus there won't be a need to call free_area_init() from every architecture.
--- arch/powerpc/mm/mem.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)
arch/powerpc/mm/mem.c +12 -10
@@ -221,13 +221,23 @@ static int __init mark_nonram_nosave(void)* anyway) will take a first dip into ZONE_NORMAL and get otherwise served by * ZONE_DMA. */ -static unsigned long max_zone_pfns[MAX_NR_ZONES ]; +void __init arch_zone_limits_init (unsigned long *max_zone_pfns) +{ +#ifdef CONFIG_ZONE_DMA + max_zone_pfns[ZONE_DMA ] =min ((zone_dma_limit >>PAGE_SHIFT ) +1 , max_low_pfn); +#endif + max_zone_pfns[ZONE_NORMAL ] = max_low_pfn; +#ifdef CONFIG_HIGHMEM + max_zone_pfns[ZONE_HIGHMEM ] = max_pfn; +#endif +}/* * paging_init() sets up the page tables - in fact we've already done this. */ void __init paging_init (void ) { +unsigned long max_zone_pfns[MAX_NR_ZONES ] = {0 };unsigned long long total_ram =memblock_phys_mem_size ();phys_addr_t top_of_ram =memblock_end_of_DRAM ();int zone_dma_bits;
@@ -259,15 +269,7 @@ void __init paging_init(void) zone_dma_limit =DMA_BIT_MASK (zone_dma_bits); -#ifdef CONFIG_ZONE_DMA - max_zone_pfns[ZONE_DMA ] =min (max_low_pfn, -1UL << (zone_dma_bits -PAGE_SHIFT )); -#endif - max_zone_pfns[ZONE_NORMAL ] = max_low_pfn; -#ifdef CONFIG_HIGHMEM - max_zone_pfns[ZONE_HIGHMEM ] = max_pfn; -#endif - +arch_zone_limits_init (max_zone_pfns);free_area_init (max_zone_pfns);mark_nonram_nosave ();
Signature · 1 line
2.51.0
Re: [PATCH v3 15/29] powerpc: introduce arch_zone_limits_init()
Quoted 5 lines · Mike Rapoport
From: "Mike Rapoport (Microsoft)" <[email protected]>
Move calculations of zone limits to a dedicated
arch_zone_limits_init()function.
Quoted 8 lines
Later MM core will use this function as an architecture specific callback during nodes and zones initialization and thus there won't be a need to call
free_area_init()from every architecture.Signed-off-by Mike Rapoport (Microsoft) <[email protected]>--- arch/powerpc/mm/mem.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)
This v2 looks good to me.
I have also done a basic bootup testing using Linux PPC CI.
Please feel free to add:
Mike Rapoport
maintainerPATCH v3 16/29 riscv: introduce arch_zone_limits_init()
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Move calculations of zone limits to a dedicated arch_zone_limits_init() function.
Later MM core will use this function as an architecture specific callback during nodes and zones initialization and thus there won't be a need to call free_area_init() from every architecture.
--- arch/riscv/mm/init.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
arch/riscv/mm/init.c +7 -3
@@ -79,15 +79,19 @@ uintptr_t _dtb_early_pa __initdata;phys_addr_t dma32_phys_limit__initdata ; -static void __init zone_sizes_init (void ) +void __init arch_zone_limits_init (unsigned long *max_zone_pfns) { -unsigned long max_zone_pfns[MAX_NR_ZONES ] = {0 , }; -#ifdef CONFIG_ZONE_DMA32 max_zone_pfns[ZONE_DMA32 ] =PFN_DOWN (dma32_phys_limit);#endif max_zone_pfns[ZONE_NORMAL ] = max_low_pfn; +} + +static void __init zone_sizes_init (void ) +{ +unsigned long max_zone_pfns[MAX_NR_ZONES ] = {0 , }; +arch_zone_limits_init (max_zone_pfns);free_area_init (max_zone_pfns); }
Signature · 1 line
2.51.0
Mike Rapoport
maintainerPATCH v3 17/29 s390: introduce arch_zone_limits_init()
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Move calculations of zone limits to a dedicated arch_zone_limits_init() function.
Later MM core will use this function as an architecture specific callback during nodes and zones initialization and thus there won't be a need to call free_area_init() from every architecture.
--- arch/s390/mm/init.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
arch/s390/mm/init.c +7 -2
@@ -86,6 +86,12 @@ static void __init setup_zero_pages(void) zero_page_mask = ((PAGE_SIZE << order) -1 ) &PAGE_MASK ; } +void __init arch_zone_limits_init (unsigned long *max_zone_pfns) +{ + max_zone_pfns[ZONE_DMA ] =virt_to_pfn (MAX_DMA_ADDRESS ); + max_zone_pfns[ZONE_NORMAL ] = max_low_pfn; +} +/* * paging_init() sets up the page tables */
@@ -97,8 +103,7 @@ void __init paging_init(void)sparse_init (); zone_dma_limit =DMA_BIT_MASK (31 );memset (max_zone_pfns,0 ,sizeof (max_zone_pfns)); - max_zone_pfns[ZONE_DMA ] =virt_to_pfn (MAX_DMA_ADDRESS ); - max_zone_pfns[ZONE_NORMAL ] = max_low_pfn; +arch_zone_limits_init (max_zone_pfns);free_area_init (max_zone_pfns); }
Signature · 1 line
2.51.0
Alexander Gordeev
maintainerRe: [PATCH v3 17/29] s390: introduce arch_zone_limits_init()
On Sun, Jan 11, 2026 at 10:20:51AM +0200, Mike Rapoport wrote:
Hi Mike,
...
Quoted 10 lines
arch/s390/mm/init.c +6
-0+void __init arch_zone_limits_init (unsigned long *max_zone_pfns) +{ + max_zone_pfns[ZONE_DMA ] =virt_to_pfn (MAX_DMA_ADDRESS ); + max_zone_pfns[ZONE_NORMAL ] = max_low_pfn; +} +/* * paging_init() sets up the page tables */
arch/s390/mm/init.c void __init paging_init(void) · line 106
Quoted 6 lines
arch/s390/mm/init.c +1
-2@@ -97,8 +103,7 @@ void __init paging_init(void)sparse_init (); zone_dma_limit =DMA_BIT_MASK (31 );memset (max_zone_pfns,0 ,sizeof (max_zone_pfns)); - max_zone_pfns[ZONE_DMA ] =virt_to_pfn (MAX_DMA_ADDRESS ); - max_zone_pfns[ZONE_NORMAL ] = max_low_pfn; +arch_zone_limits_init (max_zone_pfns);
You move initialization of max_zone_pfns[] to a function, name the function arch_zone_limits_init(), but leave the initializatio of max_zone_pfns[] to zeroes outside. Should not it be brought along?
arch/s390/mm/init.c void __init paging_init(void) · line 108
Quoted 2 lines
arch/s390/mm/init.c +0
-0free_area_init (max_zone_pfns); }
Thanks!
Mike Rapoport
maintainerRe: [PATCH v3 17/29] s390: introduce arch_zone_limits_init()
Hi,
Quoted 17 lines · Alexander Gordeev
On Sun, Jan 11, 2026 at 10:20:51AM +0200, Mike Rapoport wrote:
Hi Mike,
...
Quoted 12 lines
arch/s390/mm/init.c +6
-0+void __init arch_zone_limits_init (unsigned long *max_zone_pfns) +{ + max_zone_pfns[ZONE_DMA ] =virt_to_pfn (MAX_DMA_ADDRESS ); + max_zone_pfns[ZONE_NORMAL ] = max_low_pfn; +} +/* * paging_init() sets up the page tables */ @@ -97,8 +103,7 @@ void __init paging_init(void)sparse_init (); zone_dma_limit =DMA_BIT_MASK (31 );
Quoted 8 lines
arch/s390/mm/init.c void __init paging_init(void) · line 106
Quoted 4 lines
arch/s390/mm/init.c +1
-2memset (max_zone_pfns,0 ,sizeof (max_zone_pfns)); - max_zone_pfns[ZONE_DMA ] =virt_to_pfn (MAX_DMA_ADDRESS ); - max_zone_pfns[ZONE_NORMAL ] = max_low_pfn; +arch_zone_limits_init (max_zone_pfns);You move initialization of max_zone_pfns[] to a function, name the function
arch_zone_limits_init(), but leave the initializatio of max_zone_pfns[] to zeroes outside. Should not it be brought along?
The idea is that is the caller responsibility to initialize max_zone_pfns to zero. After patch 24: "arch, mm: consolidate initialization of SPARSE memory model" there is a single caller of arch_zone_limits_init() and having initialization of max_zone_pfns() there is more optimal than having 20-something of those.
Quoted 4 lines
arch/s390/mm/init.c void __init paging_init(void) · line 108
Quoted 2 lines
arch/s390/mm/init.c +0
-0free_area_init (max_zone_pfns); }Thanks!
Signature · 2 lines
Sincerely yours, Mike.
Mike Rapoport
maintainerPATCH v3 18/29 sh: introduce arch_zone_limits_init()
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Move calculations of zone limits to a dedicated arch_zone_limits_init() function.
Later MM core will use this function as an architecture specific callback during nodes and zones initialization and thus there won't be a need to call free_area_init() from every architecture.
--- arch/sh/mm/init.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/sh/mm/init.c +6 -1
@@ -264,6 +264,11 @@ static void __init early_reserve_mem(void)reserve_crashkernel (); } +void __init arch_zone_limits_init (unsigned long *max_zone_pfns) +{ + max_zone_pfns[ZONE_NORMAL ] = max_low_pfn; +} +void __init paging_init (void ) {unsigned long max_zone_pfns[MAX_NR_ZONES ];
@@ -322,7 +327,7 @@ void __init paging_init(void)kmap_coherent_init ();memset (max_zone_pfns,0 ,sizeof (max_zone_pfns)); - max_zone_pfns[ZONE_NORMAL ] = max_low_pfn; +arch_zone_limits_init (max_zone_pfns);free_area_init (max_zone_pfns); }
Signature · 1 line
2.51.0
Mike Rapoport
maintainerPATCH v3 19/29 sparc: introduce arch_zone_limits_init()
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Move calculations of zone limits to a dedicated arch_zone_limits_init() function.
Later MM core will use this function as an architecture specific callback during nodes and zones initialization and thus there won't be a need to call free_area_init() from every architecture.
--- arch/sparc/mm/init_64.c | 6 ++++++ arch/sparc/mm/srmmu.c | 12 ++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-)
arch/sparc/mm/init_64.c +6 -0
@@ -2279,6 +2279,11 @@ static void __init reduce_memory(phys_addr_t limit_ram)memblock_enforce_memory_limit (limit_ram); } +void __init arch_zone_limits_init (unsigned long *max_zone_pfns) +{ + max_zone_pfns[ZONE_NORMAL ] = last_valid_pfn; +} +void __init paging_init (void ) {unsigned long end_pfn, shift, phys_base;
@@ -2461,6 +2466,7 @@ void __init paging_init(void) max_zone_pfns[ZONE_NORMAL ] = end_pfn; +arch_zone_limits_init (max_zone_pfns);free_area_init (max_zone_pfns); }
arch/sparc/mm/srmmu.c +8 -4
@@ -884,6 +884,13 @@ static void __init map_kernel(void)void (*poke_srmmu)(void ) =NULL ; +void __init arch_zone_limits_init (unsigned long *max_zone_pfns) +{ + max_zone_pfns[ZONE_DMA ] = max_low_pfn; + max_zone_pfns[ZONE_NORMAL ] = max_low_pfn; + max_zone_pfns[ZONE_HIGHMEM ] = highend_pfn; +} +void __init srmmu_paging_init (void ) {int i;
@@ -967,10 +974,7 @@ void __init srmmu_paging_init(void) {unsigned long max_zone_pfn[MAX_NR_ZONES ] = {0 }; - max_zone_pfn[ZONE_DMA ] = max_low_pfn; - max_zone_pfn[ZONE_NORMAL ] = max_low_pfn; - max_zone_pfn[ZONE_HIGHMEM ] = highend_pfn; - +arch_zone_limits_init (max_zone_pfn);free_area_init (max_zone_pfn); } }
Signature · 1 line
2.51.0
Re: [PATCH v3 19/29] sparc: introduce arch_zone_limits_init()
Quoted 9 lines · Mike Rapoport
From: "Mike Rapoport (Microsoft)" <[email protected]>
Move calculations of zone limits to a dedicated
arch_zone_limits_init()function.Later MM core will use this function as an architecture specific callback during nodes and zones initialization and thus there won't be a need to call
free_area_init()from every architecture.
Quoted 5 lines
Signed-off-by Mike Rapoport (Microsoft) <[email protected]>--- arch/sparc/mm/init_64.c | 6 ++++++ arch/sparc/mm/srmmu.c | 12 ++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-)
Hi Mike,
Thanks for this nice cleanup series.
Quoted 17 lines
arch/sparc/mm/init_64.c +5
-0@@ -2279,6 +2279,11 @@ static void __init reduce_memory(phys_addr_t limit_ram)memblock_enforce_memory_limit (limit_ram); } +void __init arch_zone_limits_init (unsigned long *max_zone_pfns) +{ + max_zone_pfns[ZONE_NORMAL ] = last_valid_pfn; +} +void __init paging_init (void ) {unsigned long end_pfn, shift, phys_base;
arch/sparc/mm/init_64.c void __init paging_init(void) · line 2467
Quoted 2 lines
arch/sparc/mm/init_64.c +0
-0@@ -2461,6 +2466,7 @@ void __init paging_init(void) max_zone_pfns[ZONE_NORMAL ] = end_pfn;
This old initialization of max_zone_pfns[ZONE_NORMAL] should also be removed, right? With that removed it makes the local end_pfn variable set but unused, so could you please also remove that one?
I know that this whole code block gets removed later, but the cleanup max_zone_pfns[ZONE_NORMAL] and the removal of end_pfn (that is not done later in this version of the series) fits logically in this patch.
Quoted 25 lines
arch/sparc/mm/init_64.c +1
-0+arch_zone_limits_init (max_zone_pfns);free_area_init (max_zone_pfns); }arch/sparc/mm/srmmu.c +7
-0@@ -884,6 +884,13 @@ static void __init map_kernel(void)void (*poke_srmmu)(void ) =NULL ; +void __init arch_zone_limits_init (unsigned long *max_zone_pfns) +{ + max_zone_pfns[ZONE_DMA ] = max_low_pfn; + max_zone_pfns[ZONE_NORMAL ] = max_low_pfn; + max_zone_pfns[ZONE_HIGHMEM ] = highend_pfn; +} +void __init srmmu_paging_init (void ) {int i;@@ -967,10 +974,7 @@ void __init srmmu_paging_init(void) {
arch/sparc/mm/srmmu.c void __init srmmu_paging_init(void) · line 980
Quoted 10 lines
arch/sparc/mm/srmmu.c +1
-4unsigned long max_zone_pfn[MAX_NR_ZONES ] = {0 }; - max_zone_pfn[ZONE_DMA ] = max_low_pfn; - max_zone_pfn[ZONE_NORMAL ] = max_low_pfn; - max_zone_pfn[ZONE_HIGHMEM ] = highend_pfn; - +arch_zone_limits_init (max_zone_pfn);free_area_init (max_zone_pfn); } }
With the feedback for arch/sparc/mm/init_64.c addressed:
Cheers,
Andreas
Mike Rapoport
maintainerPATCH v3 20/29 um: introduce arch_zone_limits_init()
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Move calculations of zone limits to a dedicated arch_zone_limits_init() function.
Later MM core will use this function as an architecture specific callback during nodes and zones initialization and thus there won't be a need to call free_area_init() from every architecture.
--- arch/um/kernel/mem.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/um/kernel/mem.c +6 -1
@@ -84,6 +84,11 @@ void __init mem_init(void) kmalloc_ok =1 ; } +void __init arch_zone_limits_init (unsigned long *max_zone_pfns) +{ + max_zone_pfns[ZONE_NORMAL ] = high_physmem >>PAGE_SHIFT ; +} +void __init paging_init (void ) {unsigned long max_zone_pfn[MAX_NR_ZONES ] = {0 };
@@ -94,7 +99,7 @@ void __init paging_init(void)panic ("%s: Failed to allocate %lu bytes align=%lx\n" , __func__,PAGE_SIZE ,PAGE_SIZE ); - max_zone_pfn[ZONE_NORMAL ] = high_physmem >>PAGE_SHIFT ; +arch_zone_limits_init (max_zone_pfn);free_area_init (max_zone_pfn); }
Signature · 1 line
2.51.0
Mike Rapoport
maintainerPATCH v3 21/29 x86: introduce arch_zone_limits_init()
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Move calculations of zone limits to a dedicated arch_zone_limits_init() function.
Later MM core will use this function as an architecture specific callback during nodes and zones initialization and thus there won't be a need to call free_area_init() from every architecture.
--- arch/x86/mm/init.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
arch/x86/mm/init.c +9 -5
@@ -997,12 +997,8 @@ void __init free_initrd_mem(unsigned long start, unsigned long end) }#endif -void __init zone_sizes_init (void ) +void __init arch_zone_limits_init (unsigned long *max_zone_pfns) { -unsigned long max_zone_pfns[MAX_NR_ZONES ]; - -memset (max_zone_pfns,0 ,sizeof (max_zone_pfns)); -#ifdef CONFIG_ZONE_DMA max_zone_pfns[ZONE_DMA ] =min (MAX_DMA_PFN , max_low_pfn);#endif
@@ -1013,7 +1009,15 @@ void __init zone_sizes_init(void)#ifdef CONFIG_HIGHMEM max_zone_pfns[ZONE_HIGHMEM ] = max_pfn;#endif +} + +void __init zone_sizes_init (void ) +{ +unsigned long max_zone_pfns[MAX_NR_ZONES ]; + +memset (max_zone_pfns,0 ,sizeof (max_zone_pfns)); +arch_zone_limits_init (max_zone_pfns);free_area_init (max_zone_pfns); }
Signature · 1 line
2.51.0
Mike Rapoport
maintainerPATCH v3 22/29 xtensa: introduce arch_zone_limits_init()
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Move calculations of zone limits to a dedicated arch_zone_limits_init() function.
Later MM core will use this function as an architecture specific callback during nodes and zones initialization and thus there won't be a need to call free_area_init() from every architecture.
--- arch/xtensa/mm/init.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
arch/xtensa/mm/init.c +10 -6
@@ -116,15 +116,19 @@ static void __init print_vm_layout(void) (unsigned long)(__bss_stop - __bss_start) >> 10); } -void __init zones_init (void ) +void __init arch_zone_limits_init (unsigned long *max_zone_pfns) { -/* All pages are DMA-able, so we put them all in the DMA zone. */ -unsigned long max_zone_pfn[MAX_NR_ZONES ] = { - [ZONE_NORMAL ] = max_low_pfn, + max_zone_pfns[ZONE_NORMAL ] = max_low_pfn;#ifdef CONFIG_HIGHMEM - [ZONE_HIGHMEM ] = max_pfn, + max_zone_pfns[ZONE_HIGHMEM ] = max_pfn;#endif - }; +} + +void __init zones_init (void ) +{ +unsigned long max_zone_pfn[MAX_NR_ZONES ] = {0 , }; + +arch_zone_limits_init (max_zone_pfn);free_area_init (max_zone_pfn);print_vm_layout (); }
Signature · 1 line
2.51.0
Mike Rapoport
maintainerPATCH v3 23/29 arch, mm: consolidate initialization of nodes, zones and memory map
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
To initialize node, zone and memory map data structures every architecture calls free_area_init() during setup_arch() and passes it an array of zone limits.
Beside code duplication it creates "interesting" ordering cases between allocation and initialization of hugetlb and the memory map. Some architectures allocate hugetlb pages very early in setup_arch() in certain cases, some only create hugetlb CMA areas in setup_arch() and sometimes hugetlb allocations happen mm_core_init().
With arch_zone_limits_init() helper available now on all architectures it is no longer necessary to call free_area_init() from architecture setup code. Rather core MM initialization can call arch_zone_limits_init() in a single place.
This allows to unify ordering of hugetlb vs memory map allocation and initialization.
Remove the call to free_area_init() from architecture specific code and place it in a new mm_core_init_early() function that is called immediately after setup_arch().
After this refactoring it is possible to consolidate hugetlb allocations and eliminate differences in ordering of hugetlb and memory map initialization among different architectures.
As the first step of this consolidation move hugetlb_bootmem_alloc() to mm_core_early_init().
--- arch/alpha/mm/init.c | 9 +-------- arch/arc/mm/init.c | 5 ----- arch/arm/mm/init.c | 16 ---------------- arch/arm64/mm/init.c | 4 ---- arch/csky/kernel/setup.c | 4 ---- arch/hexagon/mm/init.c | 12 ------------ arch/loongarch/include/asm/pgtable.h | 2 -- arch/loongarch/kernel/setup.c | 2 -- arch/loongarch/mm/init.c | 8 -------- arch/m68k/mm/init.c | 3 --- arch/m68k/mm/mcfmmu.c | 3 --- arch/m68k/mm/motorola.c | 6 +----- arch/m68k/mm/sun3mmu.c | 9 --------- arch/microblaze/mm/init.c | 7 ------- arch/mips/loongson64/numa.c | 4 ---- arch/mips/mm/init.c | 5 ----- arch/mips/sgi-ip27/ip27-memory.c | 4 ---- arch/nios2/mm/init.c | 6 ------ arch/openrisc/mm/init.c | 10 ---------- arch/parisc/mm/init.c | 9 --------- arch/powerpc/mm/mem.c | 4 ---- arch/riscv/mm/init.c | 9 --------- arch/s390/mm/init.c | 5 ----- arch/sh/mm/init.c | 5 ----- arch/sparc/mm/init_64.c | 11 ----------- arch/sparc/mm/srmmu.c | 7 ------- arch/um/kernel/mem.c | 5 ----- arch/x86/mm/init.c | 10 ---------- arch/x86/mm/init_32.c | 1 - arch/x86/mm/init_64.c | 2 -- arch/x86/mm/mm_internal.h | 1 - arch/xtensa/mm/init.c | 4 ---- include/linux/mm.h | 4 ++-- init/main.c | 1 + mm/mm_init.c | 18 ++++++++++-------- 35 files changed, 15 insertions(+), 200 deletions(-)
arch/alpha/mm/init.c +1 -8
@@ -220,17 +220,10 @@ void __init arch_zone_limits_init(unsigned long *max_zone_pfn) }/* -* paging_init() sets up the memory map. +* paging_init() initializes the kernel's ZERO_PGE. */ void __init paging_init (void ) { -unsigned long max_zone_pfn[MAX_NR_ZONES ] = {0 , }; - -/* Initialize mem_map[]. */ -arch_zone_limits_init (max_zone_pfn); -free_area_init (max_zone_pfn); - -/* Initialize the kernel's ZERO_PGE. */ memset (absolute_pointer (ZERO_PGE ),0 ,PAGE_SIZE ); }
arch/arc/mm/init.c +0 -5
@@ -102,8 +102,6 @@ void __init arch_zone_limits_init(unsigned long *max_zone_pfn)*/ void __init setup_arch_memory (void ) { -unsigned long max_zone_pfn[MAX_NR_ZONES ] = {0 }; -setup_initial_init_mm (_text, _etext, _edata, _end);/* first page of system - kernel .vector starts here */
@@ -158,9 +156,6 @@ void __init setup_arch_memory(void) arch_pfn_offset =min (min_low_pfn, min_high_pfn);kmap_init ();#endif /* CONFIG_HIGHMEM */ - -arch_zone_limits_init (max_zone_pfn); -free_area_init (max_zone_pfn); }void __init arch_mm_preinit (void )
arch/arm/mm/init.c +0 -16
@@ -118,15 +118,6 @@ void __init arch_zone_limits_init(unsigned long *max_zone_pfn)#endif } -static void __init zone_sizes_init (unsigned long min,unsigned long max_low, -unsigned long max_high) -{ -unsigned long max_zone_pfn[MAX_NR_ZONES ] = {0 }; - -arch_zone_limits_init (max_zone_pfn); -free_area_init (max_zone_pfn); -} -#ifdef CONFIG_HAVE_ARCH_PFN_VALID int pfn_valid (unsigned long pfn) {
@@ -222,13 +213,6 @@ void __init bootmem_init(void)* done after the fixed reservations */ sparse_init (); - -/* -* Now free the memory - free_area_init needs -* the sparse mem_map arrays initialized by sparse_init() -* for memmap_init_zone(), otherwise all PFNs are invalid. -*/ -zone_sizes_init (min_low_pfn, max_low_pfn, max_pfn); }/*
arch/arm64/mm/init.c +0 -4
@@ -134,7 +134,6 @@ void __init arch_zone_limits_init(unsigned long *max_zone_pfns)static void __init dma_limits_init (void ) { -unsigned long max_zone_pfns[MAX_NR_ZONES ] = {0 };phys_addr_t __maybe_unused acpi_zone_dma_limit;phys_addr_t __maybe_unused dt_zone_dma_limit; phys_addr_t __maybe_unused dma32_phys_limit =
@@ -160,9 +159,6 @@ static void __init dma_limits_init(void)#endif if (!arm64_dma_phys_limit) arm64_dma_phys_limit =PHYS_MASK +1 ; - -arch_zone_limits_init (max_zone_pfns); -free_area_init (max_zone_pfns); }int pfn_is_map_memory (unsigned long pfn)
arch/csky/kernel/setup.c +0 -4
@@ -63,7 +63,6 @@ static void __init csky_memblock_init(void) {unsigned long lowmem_size =PFN_DOWN (LOWMEM_LIMIT -PHYS_OFFSET_OFFSET );unsigned long sseg_size =PFN_DOWN (SSEG_SIZE -PHYS_OFFSET_OFFSET ); -unsigned long max_zone_pfn[MAX_NR_ZONES ] = {0 };signed long size;memblock_reserve (__pa (_start), _end - _start);
@@ -101,9 +100,6 @@ static void __init csky_memblock_init(void)memblock_set_current_limit (PFN_PHYS (max_low_pfn));dma_contiguous_reserve (0 ); - -arch_zone_limits_init (max_zone_pfn); -free_area_init (max_zone_pfn); }void __init setup_arch (char **cmdline_p)
arch/hexagon/mm/init.c +0 -12
@@ -66,20 +66,8 @@ void __init arch_zone_limits_init(unsigned long *max_zone_pfns) max_zone_pfns[ZONE_NORMAL ] = max_low_pfn; } -/* -* In order to set up page allocator "nodes", -* somebody has to call free_area_init() for UMA. -* -* In this mode, we only have one pg_data_t -* structure: contig_mem_data. -*/ static void __init paging_init (void ) { -unsigned long max_zone_pfn[MAX_NR_ZONES ] = {0 , }; - -arch_zone_limits_init (max_zone_pfn); -free_area_init (max_zone_pfn);/* sets up the zonelists and mem_map */ -/* * Set the init_mm descriptors "context" value to point to the * initial kernel segment table's physical address.
arch/loongarch/include/asm/pgtable.h +0 -2
@@ -353,8 +353,6 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte)return pte; } -extern void paging_init (void ); -#define pte_none (pte) (!(pte_val(pte) & ~_PAGE_GLOBAL))#define pte_present (pte) (pte_val(pte) & (_PAGE_PRESENT | _PAGE_PROTNONE))#define pte_no_exec (pte) (pte_val(pte) & _PAGE_NO_EXEC)
arch/loongarch/kernel/setup.c +0 -2
@@ -621,8 +621,6 @@ void __init setup_arch(char **cmdline_p)prefill_possible_map ();#endif -paging_init (); -#ifdef CONFIG_KASAN kasan_init ();#endif
arch/loongarch/mm/init.c +0 -8
@@ -68,14 +68,6 @@ void __init arch_zone_limits_init(unsigned long *max_zone_pfns) max_zone_pfns[ZONE_NORMAL ] = max_low_pfn; } -void __init paging_init (void ) -{ -unsigned long max_zone_pfns[MAX_NR_ZONES ]; - -arch_zone_limits_init (max_zone_pfns); -free_area_init (max_zone_pfns); -} -void __ref free_initmem (void ) {free_initmem_default (POISON_FREE_INITMEM );
arch/m68k/mm/init.c +0 -3
@@ -69,13 +69,10 @@ void __init paging_init(void)* page_alloc get different views of the world. */ unsigned long end_mem = memory_end &PAGE_MASK ; -unsigned long max_zone_pfn[MAX_NR_ZONES ] = {0 , }; high_memory = (void *) end_mem; empty_zero_page = memblock_alloc_or_panic(PAGE_SIZE, PAGE_SIZE); -arch_zone_limits_init (max_zone_pfn); - free_area_init(max_zone_pfn); }#endif /* CONFIG_MMU */
arch/m68k/mm/mcfmmu.c +0 -3
@@ -39,7 +39,6 @@ void __init paging_init(void)pte_t *pg_table;unsigned long address, size;unsigned long next_pgtable; -unsigned long max_zone_pfn[MAX_NR_ZONES ] = {0 };int i; empty_zero_page =memblock_alloc_or_panic (PAGE_SIZE ,PAGE_SIZE );
@@ -73,8 +72,6 @@ void __init paging_init(void) } current->mm =NULL ; -arch_zone_limits_init (max_zone_pfn); -free_area_init (max_zone_pfn); }int cf_tlb_miss (struct pt_regs *regs,int write,int dtlb,int extension_word)
arch/m68k/mm/motorola.c +1 -5
@@ -429,7 +429,6 @@ DECLARE_VM_GET_PAGE_PROT*/ void __init paging_init (void ) { -unsigned long max_zone_pfn[MAX_NR_ZONES ] = {0 , };unsigned long min_addr, max_addr;unsigned long addr;int i;
@@ -511,12 +510,9 @@ void __init paging_init(void)set_fc (USER_DATA );#ifdef DEBUG -printk ("before free_area_init\n" ); +printk ("before node_set_state\n" );#endif for (i =0 ; i < m68k_num_memory; i++)if (node_present_pages (i))node_set_state (i,N_NORMAL_MEMORY ); - -arch_zone_limits_init (max_zone_pfn); -free_area_init (max_zone_pfn); }
arch/m68k/mm/sun3mmu.c +0 -9
@@ -41,7 +41,6 @@ void __init paging_init(void)unsigned long address;unsigned long next_pgtable;unsigned long bootmem_end; -unsigned long max_zone_pfn[MAX_NR_ZONES ] = {0 , };unsigned long size; empty_zero_page =memblock_alloc_or_panic (PAGE_SIZE ,PAGE_SIZE );
@@ -80,14 +79,6 @@ void __init paging_init(void)mmu_emu_init (bootmem_end); current->mm =NULL ; - -/* memory sizing is a hack stolen from motorola.c.. hope it works for us */ -arch_zone_limits_init (max_zone_pfn); - -/* I really wish I knew why the following change made things better... -- Sam */ -free_area_init (max_zone_pfn); - - }static const pgprot_t protection_map[16 ] = {
arch/microblaze/mm/init.c +0 -7
@@ -69,22 +69,15 @@ void __init arch_zone_limits_init(unsigned long *max_zone_pfns)*/ static void __init paging_init (void ) { -unsigned long zones_size[MAX_NR_ZONES ];int idx;/* Setup fixmaps */ for (idx =0 ; idx < __end_of_fixed_addresses; idx++)clear_fixmap (idx); -/* Clean every zones */ -memset (zones_size,0 ,sizeof (zones_size)); -#ifdef CONFIG_HIGHMEM highmem_init ();#endif -arch_zone_limits_init (zones_size); -/* We don't have holes in memory map */ -free_area_init (zones_size); }void __init setup_memory (void )
arch/mips/loongson64/numa.c +0 -4
@@ -162,11 +162,7 @@ void __init arch_zone_limits_init(unsigned long *max_zone_pfns)void __init paging_init (void ) { -unsigned long zones_size[MAX_NR_ZONES ] = {0 , }; -pagetable_init (); -arch_zone_limits_init (zones_size); -free_area_init (zones_size); }/* All PCI device belongs to logical Node-0 */
arch/mips/mm/init.c +0 -5
@@ -417,12 +417,7 @@ void __init arch_zone_limits_init(unsigned long *max_zone_pfns)void __init paging_init (void ) { -unsigned long max_zone_pfns[MAX_NR_ZONES ]; -pagetable_init (); - -arch_zone_limits_init (max_zone_pfns); -free_area_init (max_zone_pfns); }#ifdef CONFIG_64BIT
arch/mips/sgi-ip27/ip27-memory.c +0 -4
@@ -413,9 +413,5 @@ void __init arch_zone_limits_init(unsigned long *max_zone_pfns)void __init paging_init (void ) { -unsigned long zones_size[MAX_NR_ZONES ] = {0 , }; -pagetable_init (); -arch_zone_limits_init (zones_size); -free_area_init (zones_size); }
arch/nios2/mm/init.c +0 -6
@@ -51,15 +51,9 @@ void __init arch_zone_limits_init(unsigned long *max_zone_pfns)*/ void __init paging_init (void ) { -unsigned long max_zone_pfn[MAX_NR_ZONES ] = {0 }; -pagetable_init (); pgd_current = swapper_pg_dir; -arch_zone_limits_init (max_zone_pfn); -/* pass the memory from the bootmem allocator to the main allocator */ -free_area_init (max_zone_pfn); -flush_dcache_range ((unsigned long )empty_zero_page, (unsigned long )empty_zero_page +PAGE_SIZE ); }
arch/openrisc/mm/init.c +0 -10
@@ -47,14 +47,6 @@ void __init arch_zone_limits_init(unsigned long *max_zone_pfns) max_zone_pfns[ZONE_NORMAL ] = max_low_pfn; } -static void __init zone_sizes_init (void ) -{ -unsigned long max_zone_pfn[MAX_NR_ZONES ] = {0 }; - -arch_zone_limits_init (max_zone_pfn); -free_area_init (max_zone_pfn); -} -extern const char _s_kernel_ro[], _e_kernel_ro[];/*
@@ -145,8 +137,6 @@ void __init paging_init(void)map_ram (); -zone_sizes_init (); -/* self modifying code ;) */ /* Since the old TLB miss handler has been running up until now, * the kernel pages are still all RW, so we can still modify the
arch/parisc/mm/init.c +0 -9
@@ -698,14 +698,6 @@ void __init arch_zone_limits_init(unsigned long *max_zone_pfns) max_zone_pfns[ZONE_NORMAL ] =PFN_DOWN (memblock_end_of_DRAM ()); } -static void __init parisc_bootmem_free (void ) -{ -unsigned long max_zone_pfn[MAX_NR_ZONES ] = {0 , }; - -arch_zone_limits_init (max_zone_pfn); -free_area_init (max_zone_pfn); -} -void __init paging_init (void ) {setup_bootmem ();
@@ -716,7 +708,6 @@ void __init paging_init(void)flush_tlb_all_local (NULL );sparse_init (); -parisc_bootmem_free (); } static void alloc_btlb(unsigned long start, unsigned long end, int *slot,
arch/powerpc/mm/mem.c +0 -4
@@ -237,7 +237,6 @@ void __init arch_zone_limits_init(unsigned long *max_zone_pfns)*/ void __init paging_init (void ) { -unsigned long max_zone_pfns[MAX_NR_ZONES ] = {0 };unsigned long long total_ram =memblock_phys_mem_size ();phys_addr_t top_of_ram =memblock_end_of_DRAM ();int zone_dma_bits;
@@ -269,9 +268,6 @@ void __init paging_init(void) zone_dma_limit =DMA_BIT_MASK (zone_dma_bits); -arch_zone_limits_init (max_zone_pfns); -free_area_init (max_zone_pfns); -mark_nonram_nosave (); }
arch/riscv/mm/init.c +0 -9
@@ -87,14 +87,6 @@ void __init arch_zone_limits_init(unsigned long *max_zone_pfns) max_zone_pfns[ZONE_NORMAL ] = max_low_pfn; } -static void __init zone_sizes_init (void ) -{ -unsigned long max_zone_pfns[MAX_NR_ZONES ] = {0 , }; - -arch_zone_limits_init (max_zone_pfns); -free_area_init (max_zone_pfns); -} -#if defined(CONFIG_MMU ) && defined(CONFIG_DEBUG_VM )#define LOG2_SZ_1K ilog2(SZ_1K)
@@ -1443,7 +1435,6 @@ void __init misc_mem_init(void)/* The entire VMEMMAP region has been populated. Flush TLB for this region */ local_flush_tlb_kernel_range (VMEMMAP_START ,VMEMMAP_END );#endif -zone_sizes_init ();arch_reserve_crashkernel ();memblock_dump_all (); }
arch/s390/mm/init.c +0 -5
@@ -97,14 +97,9 @@ void __init arch_zone_limits_init(unsigned long *max_zone_pfns)*/ void __init paging_init (void ) { -unsigned long max_zone_pfns[MAX_NR_ZONES ]; -vmem_map_init ();sparse_init (); zone_dma_limit =DMA_BIT_MASK (31 ); -memset (max_zone_pfns,0 ,sizeof (max_zone_pfns)); -arch_zone_limits_init (max_zone_pfns); -free_area_init (max_zone_pfns); }void mark_rodata_ro (void )
arch/sh/mm/init.c +0 -5
@@ -271,7 +271,6 @@ void __init arch_zone_limits_init(unsigned long *max_zone_pfns)void __init paging_init (void ) { -unsigned long max_zone_pfns[MAX_NR_ZONES ];unsigned long vaddr, end; sh_mv.mv_mem_init ();
@@ -325,10 +324,6 @@ void __init paging_init(void)page_table_range_init (vaddr, end, swapper_pg_dir);kmap_coherent_init (); - -memset (max_zone_pfns,0 ,sizeof (max_zone_pfns)); -arch_zone_limits_init (max_zone_pfns); -free_area_init (max_zone_pfns); }unsigned int mem_init_done =0 ;
arch/sparc/mm/init_64.c +0 -11
@@ -2459,17 +2459,6 @@ void __init paging_init(void)kernel_physical_mapping_init (); - { -unsigned long max_zone_pfns[MAX_NR_ZONES ]; - -memset (max_zone_pfns,0 ,sizeof (max_zone_pfns)); - - max_zone_pfns[ZONE_NORMAL ] = end_pfn; - -arch_zone_limits_init (max_zone_pfns); -free_area_init (max_zone_pfns); - } -printk ("Booting Linux...\n" ); }
arch/sparc/mm/srmmu.c +0 -7
@@ -970,13 +970,6 @@ void __init srmmu_paging_init(void)flush_tlb_all ();sparc_context_init (num_contexts); - - { -unsigned long max_zone_pfn[MAX_NR_ZONES ] = {0 }; - -arch_zone_limits_init (max_zone_pfn); -free_area_init (max_zone_pfn); - } }void mmu_info (struct seq_file *m)
arch/um/kernel/mem.c +0 -5
@@ -91,16 +91,11 @@ void __init arch_zone_limits_init(unsigned long *max_zone_pfns)void __init paging_init (void ) { -unsigned long max_zone_pfn[MAX_NR_ZONES ] = {0 }; - empty_zero_page = (unsigned long *)memblock_alloc_low (PAGE_SIZE ,PAGE_SIZE );if (!empty_zero_page)panic ("%s: Failed to allocate %lu bytes align=%lx\n" , __func__,PAGE_SIZE ,PAGE_SIZE ); - -arch_zone_limits_init (max_zone_pfn); -free_area_init (max_zone_pfn); }/*
arch/x86/mm/init.c +0 -10
@@ -1011,16 +1011,6 @@ void __init arch_zone_limits_init(unsigned long *max_zone_pfns)#endif } -void __init zone_sizes_init (void ) -{ -unsigned long max_zone_pfns[MAX_NR_ZONES ]; - -memset (max_zone_pfns,0 ,sizeof (max_zone_pfns)); - -arch_zone_limits_init (max_zone_pfns); -free_area_init (max_zone_pfns); -} -__visible DEFINE_PER_CPU_ALIGNED (struct tlb_state ,cpu_tlbstate ) = { .loaded_mm = &init_mm, .next_asid =1 ,
arch/x86/mm/init_32.c +0 -1
@@ -655,7 +655,6 @@ void __init paging_init(void)*/ olpc_dt_build_devicetree ();sparse_init (); -zone_sizes_init (); }/*
arch/x86/mm/init_64.c +0 -2
@@ -843,8 +843,6 @@ void __init paging_init(void)*/ node_clear_state (0 ,N_MEMORY );node_clear_state (0 ,N_NORMAL_MEMORY ); - -zone_sizes_init (); }#define PAGE_UNUSED 0xFD
arch/x86/mm/mm_internal.h +0 -1
@@ -17,7 +17,6 @@ unsigned long kernel_physical_mapping_init(unsigned long start,unsigned long kernel_physical_mapping_change (unsigned long start,unsigned long end,unsigned long page_size_mask); -void zone_sizes_init (void );extern int after_bootmem;
arch/xtensa/mm/init.c +0 -4
@@ -126,10 +126,6 @@ void __init arch_zone_limits_init(unsigned long *max_zone_pfns)void __init zones_init (void ) { -unsigned long max_zone_pfn[MAX_NR_ZONES ] = {0 , }; - -arch_zone_limits_init (max_zone_pfn); -free_area_init (max_zone_pfn);print_vm_layout (); }
include/linux/mm.h +2 -2
@@ -45,6 +45,7 @@ struct pt_regs;struct folio_batch ;void arch_mm_preinit (void ); +void mm_core_init_early (void );void mm_core_init (void );void init_mm_internals (void );
@@ -3536,7 +3537,7 @@ static inline unsigned long get_num_physpages(void) }/* -* Using memblock node mappings, an architecture may initialise its +* FIXME: Using memblock node mappings, an architecture may initialise its * zones, allocate the backing mem_map and account for memory holes in an * architecture independent manner. *
@@ -3551,7 +3552,6 @@ static inline unsigned long get_num_physpages(void)* memblock_add_node(base, size, nid, MEMBLOCK_NONE) * free_area_init(max_zone_pfns); */ -void free_area_init (unsigned long *max_zone_pfn);void arch_zone_limits_init (unsigned long *max_zone_pfn);unsigned long node_map_pfn_alignment (void ); extern unsigned long absent_pages_in_range(unsigned long start_pfn,
init/main.c +1 -0
@@ -1025,6 +1025,7 @@ void start_kernel(void)page_address_init ();pr_notice ("%s" , linux_banner);setup_arch (&command_line); +mm_core_init_early ();/* Static keys and static calls are needed by LSMs */ jump_label_init ();static_call_init ();
mm/mm_init.c +10 -8
@@ -1810,7 +1810,6 @@ static void __init set_high_memory(void)/** * free_area_init - Initialise all pg_data_t and zone data -* @max_zone_pfn: an array of max PFNs for each zone * * This will call free_area_init_node() for each active node in the system. * Using the page ranges provided by memblock_set_node(), the size of each
@@ -1821,17 +1820,14 @@ static void __init set_high_memory(void)* starts where the previous one ended. For example, ZONE_DMA32 starts * at arch_max_dma_pfn. */ -void __init free_area_init (unsigned long *max_zone_pfn) +static void __init free_area_init (void ) { +unsigned long max_zone_pfn[MAX_NR_ZONES ] = {0 };unsigned long start_pfn, end_pfn;int i, nid, zone;bool descending; -/* Record where the zone boundaries are */ -memset (arch_zone_lowest_possible_pfn,0 , -sizeof (arch_zone_lowest_possible_pfn)); -memset (arch_zone_highest_possible_pfn,0 , -sizeof (arch_zone_highest_possible_pfn)); +arch_zone_limits_init (max_zone_pfn); start_pfn =PHYS_PFN (memblock_start_of_DRAM ()); descending =arch_has_descending_max_zone_pfns ();
@@ -2681,13 +2677,19 @@ void __init __weak mem_init(void) { } +void __init mm_core_init_early (void ) +{ +hugetlb_bootmem_alloc (); + +free_area_init (); +} +/* * Set up kernel memory allocators */ void __init mm_core_init (void ) {arch_mm_preinit (); -hugetlb_bootmem_alloc ();/* Initializations relying on SMP setup */ BUILD_BUG_ON (MAX_ZONELISTS >2 );
Signature · 1 line
2.51.0
Re: [PATCH v3 23/29] arch, mm: consolidate initialization of nodes, zones and memory map
Quoted 24 lines · Mike Rapoport
From: "Mike Rapoport (Microsoft)" <[email protected]>
To initialize node, zone and memory map data structures every architecture calls
free_area_init()duringsetup_arch()and passes it an array of zone limits.Beside code duplication it creates "interesting" ordering cases between allocation and initialization of hugetlb and the memory map. Some architectures allocate hugetlb pages very early in
setup_arch()in certain cases, some only create hugetlb CMA areas insetup_arch()and sometimes hugetlb allocations happenmm_core_init().With
arch_zone_limits_init()helper available now on all architectures it is no longer necessary to callfree_area_init()from architecture setup code. Rather core MM initialization can callarch_zone_limits_init()in a single place.This allows to unify ordering of hugetlb vs memory map allocation and initialization.
Remove the call to
free_area_init()from architecture specific code and place it in a newmm_core_init_early()function that is called immediately aftersetup_arch().
Quoted 8 lines
After this refactoring it is possible to consolidate hugetlb allocations and eliminate differences in ordering of hugetlb and memory map initialization among different architectures.
As the first step of this consolidation move
hugetlb_bootmem_alloc()tomm_core_early_init().Signed-off-by Mike Rapoport (Microsoft) <[email protected]>
I've bisected a problem with virtme-ng testing a NUMA memoryless node setup (on x86_64) to this patch (commit d49004c5f0c1).
It's executed like this, where node 0 has memory and node 1 only cpus:
vng -vr . -p 8 -m 4G --numa 4G,cpus=0-3 --numa 0,cpus=4-7
This fails to boot due to:
[ 0.095894] BUG: unable to handle page fault for address: 0000000000004620 [ 0.097196] #PF: supervisor read access in kernel mode [ 0.098180] #PF: error_code(0x0000) - not-present page [ 0.099155] PGD 0 P4D 0 [ 0.099641] Oops: Oops: 0000 [#1] SMP NOPTI [ 0.100437] CPU: 0 UID: 0 PID: 0 Comm: swapper Not tainted 6.19.0-rc6-00152-gf206359553c9 #53 PREEMPT [ 0.102201] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.17.0-2-g4f253b9b-prebuilt.qemu.org 04/01/2014 [ 0.104313] RIP: 0010:mm_core_init_early+0x263/0x900 [ 0.105271] Code: 93 ff 72 09 8b 7c 24 30 e8 da 82 00 00 48 63 44 24 30 45 31 db 4c 8b 24 c5 a0 7b 1d 9a 48 89 c3 4c 89 5c 24 50 4c 89 5c 24 58 <41> 83 bc 24 20 46 00 00 00 75 0b 41 83 bc 24 14 47 00 00 00 74 04 [ 0.108863] RSP: 0000:ffffffff99403e38 EFLAGS: 00010046 [ 0.109861] RAX: 0000000000000001 RBX: 0000000000000001 RCX: 0000000000000001 [ 0.111223] RDX: 0000000000000040 RSI: 0000000000100000 RDI: ffff89597fffae00 [ 0.112577] RBP: 0000000000000005 R08: 0000000000000000 R09: ffff89597fffa200 [ 0.113924] R10: 80000000ffffe000 R11: 0000000000000000 R12: 0000000000000000 [ 0.115294] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000 [ 0.116656] FS: 0000000000000000(0000) GS:0000000000000000(0000) knlGS:0000000000000000 [ 0.118193] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 0.119283] CR2: 0000000000004620 CR3: 0000000060048000 CR4: 00000000000000b0 [ 0.120645] Call Trace: [ 0.121122] <TASK> [ 0.121521] start_kernel+0x5d/0x780 [ 0.122206] x86_64_start_reservations+0x24/0x30 [ 0.123079] x86_64_start_kernel+0xd1/0xe0 [ 0.123860] common_startup_64+0x12c/0x138 [ 0.124641] </TASK> [ 0.125061] Modules linked in: [ 0.125646] CR2: 0000000000004620 [ 0.126279] ---[ end trace 0000000000000000 ]--- [ 0.127162] RIP: 0010:mm_core_init_early+0x263/0x900 [ 0.128106] Code: 93 ff 72 09 8b 7c 24 30 e8 da 82 00 00 48 63 44 24 30 45 31 db 4c 8b 24 c5 a0 7b 1d 9a 48 89 c3 4c 89 5c 24 50 4c 89 5c 24 58 <41> 83 bc 24 20 46 00 00 00 75 0b 41 83 bc 24 14 47 00 00 00 74 04 [ 0.131676] RSP: 0000:ffffffff99403e38 EFLAGS: 00010046 [ 0.132684] RAX: 0000000000000001 RBX: 0000000000000001 RCX: 0000000000000001 [ 0.134033] RDX: 0000000000000040 RSI: 0000000000100000 RDI: ffff89597fffae00 [ 0.135412] RBP: 0000000000000005 R08: 0000000000000000 R09: ffff89597fffa200 [ 0.136763] R10: 80000000ffffe000 R11: 0000000000000000 R12: 0000000000000000 [ 0.138112] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000 [ 0.139487] FS: 0000000000000000(0000) GS:0000000000000000(0000) knlGS:0000000000000000 [ 0.141014] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 0.142094] CR2: 0000000000004620 CR3: 0000000060048000 CR4: 00000000000000b0 [ 0.143448] Kernel panic - not syncing: Attempted to kill the idle task! [ 0.144833] ---[ end Kernel panic - not syncing: Attempted to kill the idle task! ]---
Quoted 1 line
./scripts/faddr2linevmlinuxmm_core_init_early+0x263/0x900
mm_core_init_early+0x263/0x900:free_area_init_node at mm/mm_init.c:1721 (inlined by) free_area_init at mm/mm_init.c:1902 (inlined by) mm_core_init_early at mm/mm_init.c:2681
It crashes at WARN_ON(pgdat->nr_zones || pgdat->kswapd_highest_zoneidx); because pgdat is NULL.
With some debug printk's I've figured out that in free_area_init() we have:
if (!node_online(nid))
alloc_offline_node_data(nid);
pgdat = NODE_DATA(nid);
free_area_init_node(nid);But node_online() is true so this allocation doesn't happen, and pgdat remains NULL.
And node_online() becomes true in init_cpu_to_node():
if (!node_online(node))
node_set_online(node);But without having a pgdat allocated.
I was able to workaround this by changing the code in free_area_init() to
if (!node_online(nid) || !NODE_DATA(nid))
alloc_offline_node_data(nid);But I don't have the bigger picture, and also didn't check yet what exactly about this patch results in the failure. Probably ordering of various related actions. Thoughts?
Mike Rapoport
maintainerRe: [PATCH v3 23/29] arch, mm: consolidate initialization of nodes, zones and memory map
Hi Vlastimil,
Quoted 111 lines · Vlastimil Babka
Quoted 24 lines · Mike Rapoport
From: "Mike Rapoport (Microsoft)" <[email protected]>
To initialize node, zone and memory map data structures every architecture calls
free_area_init()duringsetup_arch()and passes it an array of zone limits.Beside code duplication it creates "interesting" ordering cases between allocation and initialization of hugetlb and the memory map. Some architectures allocate hugetlb pages very early in
setup_arch()in certain cases, some only create hugetlb CMA areas insetup_arch()and sometimes hugetlb allocations happenmm_core_init().With
arch_zone_limits_init()helper available now on all architectures it is no longer necessary to callfree_area_init()from architecture setup code. Rather core MM initialization can callarch_zone_limits_init()in a single place.This allows to unify ordering of hugetlb vs memory map allocation and initialization.
Remove the call to
free_area_init()from architecture specific code and place it in a newmm_core_init_early()function that is called immediately aftersetup_arch().Quoted 8 lines
After this refactoring it is possible to consolidate hugetlb allocations and eliminate differences in ordering of hugetlb and memory map initialization among different architectures.
As the first step of this consolidation move
hugetlb_bootmem_alloc()tomm_core_early_init().Signed-off-by Mike Rapoport (Microsoft) <[email protected]>I've bisected a problem with virtme-ng testing a NUMA memoryless node setup (on
x86_64) to this patch (commitd49004c5f0c1).It's executed like this, where node 0 has memory and node 1 only cpus:
vng -vr . -p 8 -m 4G --numa 4G,cpus=0-3 --numa 0,cpus=4-7
This fails to boot due to:
[ 0.095894] BUG: unable to handle page fault for address: 0000000000004620 [ 0.097196] #PF: supervisor read access in kernel mode [ 0.098180] #PF: error_code(0x0000) - not-present page [ 0.099155] PGD 0 P4D 0 [ 0.099641] Oops: Oops: 0000 [#1] SMP NOPTI [ 0.100437] CPU: 0 UID: 0 PID: 0 Comm: swapper Not tainted 6.19.0-rc6-00152-gf206359553c9 #53 PREEMPT [ 0.102201] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.17.0-2-g4f253b9b-prebuilt.qemu.org 04/01/2014 [ 0.104313] RIP: 0010:mm_core_init_early+0x263/0x900 [ 0.105271] Code: 93 ff 72 09 8b 7c 24 30 e8 da 82 00 00 48 63 44 24 30 45 31 db 4c 8b 24 c5 a0 7b 1d 9a 48 89 c3 4c 89 5c 24 50 4c 89 5c 24 58 <41> 83 bc 24 20 46 00 00 00 75 0b 41 83 bc 24 14 47 00 00 00 74 04 [ 0.108863] RSP: 0000:ffffffff99403e38 EFLAGS: 00010046 [ 0.109861] RAX: 0000000000000001 RBX: 0000000000000001 RCX: 0000000000000001 [ 0.111223] RDX: 0000000000000040 RSI: 0000000000100000 RDI: ffff89597fffae00 [ 0.112577] RBP: 0000000000000005 R08: 0000000000000000 R09: ffff89597fffa200 [ 0.113924] R10: 80000000ffffe000 R11: 0000000000000000 R12: 0000000000000000 [ 0.115294] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000 [ 0.116656] FS: 0000000000000000(0000) GS:0000000000000000(0000) knlGS:0000000000000000 [ 0.118193] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 0.119283] CR2: 0000000000004620 CR3: 0000000060048000 CR4: 00000000000000b0 [ 0.120645] Call Trace: [ 0.121122] <TASK> [ 0.121521] start_kernel+0x5d/0x780 [ 0.122206] x86_64_start_reservations+0x24/0x30 [ 0.123079] x86_64_start_kernel+0xd1/0xe0 [ 0.123860] common_startup_64+0x12c/0x138 [ 0.124641] </TASK> [ 0.125061] Modules linked in: [ 0.125646] CR2: 0000000000004620 [ 0.126279] ---[ end trace 0000000000000000 ]--- [ 0.127162] RIP: 0010:mm_core_init_early+0x263/0x900 [ 0.128106] Code: 93 ff 72 09 8b 7c 24 30 e8 da 82 00 00 48 63 44 24 30 45 31 db 4c 8b 24 c5 a0 7b 1d 9a 48 89 c3 4c 89 5c 24 50 4c 89 5c 24 58 <41> 83 bc 24 20 46 00 00 00 75 0b 41 83 bc 24 14 47 00 00 00 74 04 [ 0.131676] RSP: 0000:ffffffff99403e38 EFLAGS: 00010046 [ 0.132684] RAX: 0000000000000001 RBX: 0000000000000001 RCX: 0000000000000001 [ 0.134033] RDX: 0000000000000040 RSI: 0000000000100000 RDI: ffff89597fffae00 [ 0.135412] RBP: 0000000000000005 R08: 0000000000000000 R09: ffff89597fffa200 [ 0.136763] R10: 80000000ffffe000 R11: 0000000000000000 R12: 0000000000000000 [ 0.138112] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000 [ 0.139487] FS: 0000000000000000(0000) GS:0000000000000000(0000) knlGS:0000000000000000 [ 0.141014] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 0.142094] CR2: 0000000000004620 CR3: 0000000060048000 CR4: 00000000000000b0 [ 0.143448] Kernel panic - not syncing: Attempted to kill the idle task! [ 0.144833] ---[ end Kernel panic - not syncing: Attempted to kill the idle task! ]---Quoted 1 line
./scripts/faddr2linevmlinuxmm_core_init_early+0x263/0x900
mm_core_init_early+0x263/0x900:free_area_init_nodeatmm/mm_init.c:1721(inlined by)free_area_initatmm/mm_init.c:1902(inlined by)mm_core_init_earlyatmm/mm_init.c:2681It crashes at
WARN_ON(pgdat->nr_zones || pgdat->kswapd_highest_zoneidx); because pgdat is NULL.With some debug printk's I've figured out that in
free_area_init()we have:if (!node_online(nid)) alloc_offline_node_data(nid); pgdat = NODE_DATA(nid); free_area_init_node(nid);But
node_online()is true so this allocation doesn't happen, and pgdat remains NULL.And
node_online()becomes true ininit_cpu_to_node():if (!node_online(node)) node_set_online(node);
Quoted 6 lines
But without having a pgdat allocated.
I was able to workaround this by changing the code in
free_area_init()toif (!node_online(nid) || !NODE_DATA(nid)) alloc_offline_node_data(nid);
if (!NODE_DATA(nid)) is enough ...
Quoted 3 lines
But I don't have the bigger picture, and also didn't check yet what exactly about this patch results in the failure. Probably ordering of various related actions. Thoughts?
... and there's a fix already in the mm-hotfixes-stable:
Signature · 2 lines
Sincerely yours, Mike.
Mike Rapoport
maintainerPATCH v3 24/29 arch, mm: consolidate initialization of SPARSE memory model
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Every architecture calls sparse_init() during setup_arch() although the data structures created by sparse_init() are not used until the initialization of the core MM.
Beside the code duplication, calling sparse_init() from architecture specific code causes ordering differences of vmemmap and HVO initialization on different architectures.
Move the call to sparse_init() from architecture specific code to free_area_init() to ensure that vmemmap and HVO initialization order is always the same.
--- Documentation/mm/memory-model.rst | 3 --- Documentation/translations/zh_CN/mm/memory-model.rst | 2 -- arch/alpha/kernel/setup.c | 1 - arch/arm/mm/init.c | 6 ------ arch/arm64/mm/init.c | 6 ------ arch/csky/kernel/setup.c | 2 -- arch/loongarch/kernel/setup.c | 8 -------- arch/mips/kernel/setup.c | 11 ----------- arch/parisc/mm/init.c | 2 -- arch/powerpc/include/asm/setup.h | 4 ++++ arch/powerpc/mm/mem.c | 5 ----- arch/powerpc/mm/numa.c | 2 -- arch/riscv/mm/init.c | 1 - arch/s390/mm/init.c | 1 - arch/sh/mm/init.c | 2 -- arch/sparc/mm/init_64.c | 2 -- arch/x86/mm/init_32.c | 1 - arch/x86/mm/init_64.c | 2 -- include/linux/mmzone.h | 2 -- mm/internal.h | 6 ++++++ mm/mm_init.c | 1 + 21 files changed, 11 insertions(+), 59 deletions(-)
Documentation/mm/memory-model.rst +0 -3
@@ -97,9 +97,6 @@ sections: `mem_section` objects and the number of rows is calculated to fit all the memory sections. -The architecture setup code should call sparse_init() to -initialize the memory sections and the memory maps. - With SPARSEMEM there are two possible ways to convert a PFN to the corresponding `struct page` - a "classic sparse" and "sparse vmemmap". The selection is made at build time and it is determined by
Documentation/translations/zh_CN/mm/memory-model.rst +0 -2
@@ -83,8 +83,6 @@ SPARSEMEM模型将物理内存显示为一个部分的集合。一个区段用me 每一行包含价值 `PAGE_SIZE` 的 `mem_section` 对象,行数的计算是为了适应所有的 内存区。 -架构设置代码应该调用sparse_init()来初始化内存区和内存映射。 - 通过SPARSEMEM,有两种可能的方式将PFN转换为相应的 `struct page` --"classic sparse"和 "sparse vmemmap"。选择是在构建时进行的,它由 `CONFIG_SPARSEMEM_VMEMMAP` 的 值决定。
arch/alpha/kernel/setup.c +0 -1
@@ -607,7 +607,6 @@ setup_arch(char **cmdline_p)/* Find our memory. */ setup_memory (kernel_end);memblock_set_bottom_up (true); -sparse_init ();/* First guess at cpu cache sizes. Do this before init_arch. */ determine_cpu_caches (cpu->type);
arch/arm/mm/init.c +0 -6
@@ -207,12 +207,6 @@ void __init bootmem_init(void)early_memtest ((phys_addr_t )min_low_pfn <<PAGE_SHIFT , (phys_addr_t )max_low_pfn <<PAGE_SHIFT ); - -/* -* sparse_init() tries to allocate memory from memblock, so must be -* done after the fixed reservations -*/ -sparse_init (); }/*
arch/arm64/mm/init.c +0 -6
@@ -321,12 +321,6 @@ void __init bootmem_init(void)#endif kvm_hyp_reserve (); - -/* -* sparse_init() tries to allocate memory from memblock, so must be -* done after the fixed reservations -*/ -sparse_init ();dma_limits_init ();/*
arch/csky/kernel/setup.c +0 -2
@@ -123,8 +123,6 @@ void __init setup_arch(char **cmdline_p)setup_smp ();#endif -sparse_init (); -fixaddr_init ();#ifdef CONFIG_HIGHMEM
arch/loongarch/kernel/setup.c +0 -8
@@ -402,14 +402,6 @@ static void __init arch_mem_init(char **cmdline_p)check_kernel_sections_mem (); -/* -* In order to reduce the possibility of kernel panic when failed to -* get IO TLB memory under CONFIG_SWIOTLB, it is better to allocate -* low memory as small as possible before swiotlb_init(), so make -* sparse_init() using top-down allocation. -*/ -memblock_set_bottom_up (false); -sparse_init ();memblock_set_bottom_up (true);swiotlb_init (true,SWIOTLB_VERBOSE );
arch/mips/kernel/setup.c +0 -11
@@ -614,7 +614,6 @@ static void __init bootcmdline_init(void)* kernel but generic memory management system is still entirely uninitialized. * * o bootmem_init() -* o sparse_init() * o paging_init() * o dma_contiguous_reserve() *
@@ -665,16 +664,6 @@ static void __init arch_mem_init(char **cmdline_p)mips_parse_crashkernel ();device_tree_init (); -/* -* In order to reduce the possibility of kernel panic when failed to -* get IO TLB memory under CONFIG_SWIOTLB, it is better to allocate -* low memory as small as possible before plat_swiotlb_setup(), so -* make sparse_init() using top-down allocation. -*/ -memblock_set_bottom_up (false); -sparse_init (); -memblock_set_bottom_up (true); -plat_swiotlb_setup ();dma_contiguous_reserve (PFN_PHYS (max_low_pfn));
arch/parisc/mm/init.c +0 -2
@@ -706,8 +706,6 @@ void __init paging_init(void)fixmap_init ();flush_cache_all_local ();/* start with known state */ flush_tlb_all_local (NULL ); - -sparse_init (); } static void alloc_btlb(unsigned long start, unsigned long end, int *slot,
arch/powerpc/include/asm/setup.h +4 -0
@@ -20,7 +20,11 @@ extern void reloc_got2(unsigned long);void check_for_initrd (void );void mem_topology_setup (void ); +#ifdef CONFIG_NUMA void initmem_init (void ); +#else +static inline void initmem_init (void ) {} +#endif void setup_panic (void );#define ARCH_PANIC_TIMEOUT 180
arch/powerpc/mm/mem.c +0 -5
@@ -182,11 +182,6 @@ void __init mem_topology_setup(void)memblock_set_node (0 ,PHYS_ADDR_MAX , &memblock.memory,0 ); } -void __init initmem_init (void ) -{ -sparse_init (); -} -/* mark pages that don't exist as nosave */ static int __init mark_nonram_nosave (void ) {
arch/powerpc/mm/numa.c +0 -2
@@ -1213,8 +1213,6 @@ void __init initmem_init(void)setup_node_data (nid, start_pfn, end_pfn); } -sparse_init (); -/* * We need the numa_cpu_lookup_table to be accurate for all CPUs, * even before we online them, so that we can use cpu_to_{node,mem}
arch/riscv/mm/init.c +0 -1
@@ -1430,7 +1430,6 @@ void __init misc_mem_init(void) {early_memtest (min_low_pfn <<PAGE_SHIFT , max_low_pfn <<PAGE_SHIFT );arch_numa_init (); -sparse_init ();#ifdef CONFIG_SPARSEMEM_VMEMMAP /* The entire VMEMMAP region has been populated. Flush TLB for this region */ local_flush_tlb_kernel_range (VMEMMAP_START ,VMEMMAP_END );
arch/s390/mm/init.c +0 -1
@@ -98,7 +98,6 @@ void __init arch_zone_limits_init(unsigned long *max_zone_pfns)void __init paging_init (void ) {vmem_map_init (); -sparse_init (); zone_dma_limit =DMA_BIT_MASK (31 ); }
arch/sh/mm/init.c +0 -2
@@ -227,8 +227,6 @@ static void __init do_init_bootmem(void)node_set_online (0 );plat_mem_setup (); - -sparse_init (); }static void __init early_reserve_mem (void )
arch/sparc/mm/init_64.c +0 -2
@@ -1615,8 +1615,6 @@ static unsigned long __init bootmem_init(unsigned long phys_base)/* XXX cpu notifier XXX */ -sparse_init (); -return end_pfn; }
arch/x86/mm/init_32.c +0 -1
@@ -654,7 +654,6 @@ void __init paging_init(void)* NOTE: at this point the bootmem allocator is fully available. */ olpc_dt_build_devicetree (); -sparse_init (); }/*
arch/x86/mm/init_64.c +0 -2
@@ -833,8 +833,6 @@ void __init initmem_init(void)void __init paging_init (void ) { -sparse_init (); -/* * clear the default setting with node 0 * note: don't use nodes_clear here, that is really clearing when
include/linux/mmzone.h +0 -2
@@ -2285,9 +2285,7 @@ static inline unsigned long next_present_section_nr(unsigned long section_nr)#define pfn_to_nid (pfn) (0)#endif -void sparse_init (void );#else -#define sparse_init () do {} while (0)#define sparse_index_init (_sec, _nid) do {} while (0)#define sparse_vmemmap_init_nid_early (_nid) do {} while (0)#define sparse_vmemmap_init_nid_late (_nid) do {} while (0)
mm/internal.h +6 -0
@@ -860,6 +860,12 @@ void memmap_init_range(unsigned long, int, unsigned long, unsigned long, unsigned long, enum meminit_context, struct vmem_altmap *, int, bool); +#ifdef CONFIG_SPARSEMEM +void sparse_init (void ); +#else +static inline void sparse_init (void ) {} +#endif /* CONFIG_SPARSEMEM */ +#if definedCONFIG_COMPACTION || definedCONFIG_CMA /*
mm/mm_init.c +1 -0
@@ -1828,6 +1828,7 @@ static void __init free_area_init(void)bool descending;arch_zone_limits_init (max_zone_pfn); +sparse_init (); start_pfn =PHYS_PFN (memblock_start_of_DRAM ()); descending =arch_has_descending_max_zone_pfns ();
Signature · 1 line
2.51.0
Re: [PATCH v3 24/29] arch, mm: consolidate initialization of SPARSE memory model
Hi everyone,
Quoted 11 lines · Mike Rapoport
Every architecture calls
sparse_init()duringsetup_arch()although the data structures created bysparse_init()are not used until the initialization of the core MM.Beside the code duplication, calling
sparse_init()from architecture specific code causes ordering differences of vmemmap and HVO initialization on different architectures.Move the call to
sparse_init()from architecture specific code tofree_area_init()to ensure that vmemmap and HVO initialization order is always the same.
This broke the boot on RISC-V 32-bit (rv32_defconfig) for me.
Specifically if sparse_init() is *not* called before the following callchain, the kernel dies at that point.
start_kernel()
setup_arch()
apply_boot_alternatives()
_apply_alternatives()
riscv_cpufeature_patch_func()
patch_text_nosync()
riscv_alternative_fix_offsets()
Simple reproducer, using kunit:
./tools/testing/kunit/kunit.py run --raw_output=all --make_options LLVM=1 --arch riscv32 --kconfig_add CONFIG_SPARSEMEM_MANUAL=y --kconfig_add CONFIG_SPARSEMEM=y
Quoted 25 lines
Signed-off-by Mike Rapoport (Microsoft) <[email protected]>--- Documentation/mm/memory-model.rst | 3 --- Documentation/translations/zh_CN/mm/memory-model.rst | 2 -- arch/alpha/kernel/setup.c | 1 - arch/arm/mm/init.c | 6 ------ arch/arm64/mm/init.c | 6 ------ arch/csky/kernel/setup.c | 2 -- arch/loongarch/kernel/setup.c | 8 -------- arch/mips/kernel/setup.c | 11 ----------- arch/parisc/mm/init.c | 2 -- arch/powerpc/include/asm/setup.h | 4 ++++ arch/powerpc/mm/mem.c | 5 ----- arch/powerpc/mm/numa.c | 2 -- arch/riscv/mm/init.c | 1 - arch/s390/mm/init.c | 1 - arch/sh/mm/init.c | 2 -- arch/sparc/mm/init_64.c | 2 -- arch/x86/mm/init_32.c | 1 - arch/x86/mm/init_64.c | 2 -- include/linux/mmzone.h | 2 -- mm/internal.h | 6 ++++++ mm/mm_init.c | 1 + 21 files changed, 11 insertions(+), 59 deletions(-)
(...)
Mike Rapoport
maintainerRe: [PATCH v3 24/29] arch, mm: consolidate initialization of SPARSE memory model
Hi Thomas,
Quoted 20 lines · Thomas Weißschuh
Hi everyone,
Quoted 11 lines · Mike Rapoport
Every architecture calls
sparse_init()duringsetup_arch()although the data structures created bysparse_init()are not used until the initialization of the core MM.Beside the code duplication, calling
sparse_init()from architecture specific code causes ordering differences of vmemmap and HVO initialization on different architectures.Move the call to
sparse_init()from architecture specific code tofree_area_init()to ensure that vmemmap and HVO initialization order is always the same.This broke the boot on RISC-V 32-bit (
rv32_defconfig) for me.Specifically if
sparse_init()is *not* called before the following callchain, the kernel dies at that point.
Quoted 7 lines
start_kernel()
setup_arch()
apply_boot_alternatives()
_apply_alternatives()
riscv_cpufeature_patch_func()
patch_text_nosync()
riscv_alternative_fix_offsets()
Hm, most architectures do alternatives patching much later in the boot, when much more subsystems (including mm) is already initialized.
Any particular reason riscv does it that early?
Quoted 3 lines
Simple reproducer, using kunit:
./tools/testing/kunit/kunit.pyrun --raw_output=all --make_options LLVM=1 --arch riscv32 --kconfig_addCONFIG_SPARSEMEM_MANUAL=y--kconfig_addCONFIG_SPARSEMEM=y
Looking at patch_map it's quite clear why movement of sparse_init() cased a crash:
if (core_kernel_text(uintaddr) || is_kernel_exittext(uintaddr)) page = phys_to_page(__pa_symbol(addr));
phys_to_page() with CONFIG_SPARSEMEM=y will try to access memory section that are initialized in sparse_init().
What I don't understand is why patch_map() needs a struct page for kernel text patching at all, __pa_symbol() should work just fine. And the BUG_ON(!page) is completely bogus for phys_to_page() conversion, because that one is pure arithmetics.
If moving apply_boot_alternatives() is not an option for riscv, something like the patch below should fix the issue with access to nonexistent memory sections. But I think moving apply_boot_alternatives() later in boot would make things less fragile.
arch/riscv/kernel/patch.c +9 -8
@@ -43,18 +43,19 @@ static __always_inline void *patch_map(void *addr, const unsigned int fixmap) {uintptr_t uintaddr = (uintptr_t ) addr;struct page *page; +phys_addr_t phys; -if (core_kernel_text (uintaddr) ||is_kernel_exittext (uintaddr)) - page =phys_to_page (__pa_symbol (addr)); -else if (IS_ENABLED (CONFIG_STRICT_MODULE_RWX )) +if (core_kernel_text (uintaddr) ||is_kernel_exittext (uintaddr)) { + phys =__pa_symbol (addr); + }else if (IS_ENABLED (CONFIG_STRICT_MODULE_RWX )) { page =vmalloc_to_page (addr); -else +BUG_ON (!page); + phys =page_to_phys (page); + }else {return addr; + } -BUG_ON (!page); - -return (void *)set_fixmap_offset (fixmap,page_to_phys (page) + -offset_in_page (addr)); +return (void *)set_fixmap_offset (fixmap, phys +offset_in_page (addr)); }static void patch_unmap (int fixmap)
Signature · 2 lines
Sincerely yours, Mike.
[BUG] SPARSEMEM broken on RISC-V; was: [PATCH] arch, mm: consolidate initialization of SPARSE memory model
Hi RISC-V maintainers,
SPARSEMEM on RISC-V is currently broken in mainline.
Could you take a look at my report and the suggestions from Mike below?
Quoted 87 lines · Mike Rapoport
Quoted 18 lines · Thomas Weißschuh
Quoted 11 lines · Mike Rapoport
Every architecture calls
sparse_init()duringsetup_arch()although the data structures created bysparse_init()are not used until the initialization of the core MM.Beside the code duplication, calling
sparse_init()from architecture specific code causes ordering differences of vmemmap and HVO initialization on different architectures.Move the call to
sparse_init()from architecture specific code tofree_area_init()to ensure that vmemmap and HVO initialization order is always the same.This broke the boot on RISC-V 32-bit (
rv32_defconfig) for me.Specifically if
sparse_init()is *not* called before the following callchain, the kernel dies at that point.Quoted 7 lines
start_kernel()
setup_arch()
apply_boot_alternatives()
_apply_alternatives()
riscv_cpufeature_patch_func()
patch_text_nosync()
riscv_alternative_fix_offsets()Hm, most architectures do alternatives patching much later in the boot, when much more subsystems (including mm) is already initialized.
Any particular reason riscv does it that early?
Quoted 3 lines
Simple reproducer, using kunit:
./tools/testing/kunit/kunit.pyrun --raw_output=all --make_options LLVM=1 --arch riscv32 --kconfig_addCONFIG_SPARSEMEM_MANUAL=y--kconfig_addCONFIG_SPARSEMEM=yLooking at
patch_mapit's quite clear why movement ofsparse_init()cased a crash:if (core_kernel_text(uintaddr) || is_kernel_exittext(uintaddr)) page = phys_to_page(__pa_symbol(addr));
phys_to_page()withCONFIG_SPARSEMEM=ywill try to access memory section that are initialized insparse_init().What I don't understand is why
patch_map()needs a struct page for kernel text patching at all,__pa_symbol()should work just fine. And theBUG_ON(!page)is completely bogus forphys_to_page()conversion, because that one is pure arithmetics.If moving
apply_boot_alternatives()is not an option for riscv, something like the patch below should fix the issue with access to nonexistent memory sections. But I think movingapply_boot_alternatives()later in boot would make things less fragile.arch/riscv/kernel/patch.c +9
-8@@ -43,18 +43,19 @@ static __always_inline void *patch_map(void *addr, const unsigned int fixmap) {uintptr_t uintaddr = (uintptr_t ) addr;struct page *page; +phys_addr_t phys; -if (core_kernel_text (uintaddr) ||is_kernel_exittext (uintaddr)) - page =phys_to_page (__pa_symbol (addr)); -else if (IS_ENABLED (CONFIG_STRICT_MODULE_RWX )) +if (core_kernel_text (uintaddr) ||is_kernel_exittext (uintaddr)) { + phys =__pa_symbol (addr); + }else if (IS_ENABLED (CONFIG_STRICT_MODULE_RWX )) { page =vmalloc_to_page (addr); -else +BUG_ON (!page); + phys =page_to_phys (page); + }else {return addr; + } -BUG_ON (!page); - -return (void *)set_fixmap_offset (fixmap,page_to_phys (page) + -offset_in_page (addr)); +return (void *)set_fixmap_offset (fixmap, phys +offset_in_page (addr)); }static void patch_unmap (int fixmap)
Re: [BUG] SPARSEMEM broken on RISC-V; was: [PATCH] arch, mm: consolidate initialization of SPARSE memory model
Quoted 4 lines · Thomas WeiÃschuh
Hi RISC-V maintainers,
SPARSEMEM on RISC-V is currently broken in mainline.
Could you take a look at my report and the suggestions from Mike below?
Not riscv maintainer, just happened to be taking look at 32-bit RISC-V lately...
Fortunately this is a 32-bit only thing. On 64-bit we enable vmemmap, which means that phys_to_page is also just arithmetic. Almost all (or just all?) commercially available riscv w/ MMU stuff are 64-bit.
I guess RV32 needs some more love?
Quoted 26 lines · Mike Rapoport
Quoted 25 lines · Thomas Weißschuh
Quoted 24 lines · Mike Rapoport
Quoted 11 lines
Every architecture calls
sparse_init()duringsetup_arch()although the data structures created bysparse_init()are not used until the initialization of the core MM.Beside the code duplication, calling
sparse_init()from architecture specific code causes ordering differences of vmemmap and HVO initialization on different architectures.Move the call to
sparse_init()from architecture specific code tofree_area_init()to ensure that vmemmap and HVO initialization order is always the same.This broke the boot on RISC-V 32-bit (
rv32_defconfig) for me.Specifically if
sparse_init()is *not* called before the following callchain, the kernel dies at that point.
start_kernel()
setup_arch()
apply_boot_alternatives()
_apply_alternatives()
riscv_cpufeature_patch_func()
patch_text_nosync()
riscv_alternative_fix_offsets()
Quoted 4 lines
Quoted 4 lines
Hm, most architectures do alternatives patching much later in the boot, when much more subsystems (including mm) is already initialized.
Any particular reason riscv does it that early?
Theoretically, it could be moved by making sure more things don't use alternatives on boot.
In practice, a bunch of random things call the alternatives-using versions of macros to check for extensions that I'd say (again, not maintainer, just taking a look) I'd rather have this be as early as possible, to minimize the minefield where random functions give the wrong answer. (Since those are all supposed to generate only a single nop or jump, WARN is not a good option.) Just looking at callees of arch/riscv/kernel/setup.c setup_arch(), I see:
* init_rt_signal_env() -> get_rt_frame_size() -> has_vector() -> riscv_has_extension_unlikely()
* init_rt_signal_env() -> get_rt_frame_size() -> has_xtheadvector() -> riscv_has_vendor_extension_unlikely()
* riscv_user_isa_enable() -> riscv_has_extension_unlikely()
And it's probably only going to get worse as more extensions come that have architectural state.
Quoted 9 lines
Quoted 9 lines
Quoted 3 lines
Simple reproducer, using kunit:
./tools/testing/kunit/kunit.pyrun --raw_output=all --make_options LLVM=1 --arch riscv32 --kconfig_addCONFIG_SPARSEMEM_MANUAL=y--kconfig_addCONFIG_SPARSEMEM=yLooking at
patch_mapit's quite clear why movement ofsparse_init()cased a crash:if (core_kernel_text(uintaddr) || is_kernel_exittext(uintaddr)) page = phys_to_page(__pa_symbol(addr));
Quoted 7 lines
Quoted 7 lines
phys_to_page()withCONFIG_SPARSEMEM=ywill try to access memory section that are initialized insparse_init().What I don't understand is why
patch_map()needs a struct page for kernel text patching at all,__pa_symbol()should work just fine. And theBUG_ON(!page)is completely bogus forphys_to_page()conversion, because that one is pure arithmetics.
"Copied from arm64" was the reason, I believe. See code pre/post commit 8d09e2d569f6 ("arm64: patching: avoid early page_to_phys()") where the exact same idea as yours was applied to arch/arm64/kernel/patching.c patch_map(). Evidently riscv needs the same fix.
Quoted 29 lines
Quoted 29 lines
If moving
apply_boot_alternatives()is not an option for riscv, something like the patch below should fix the issue with access to nonexistent memory sections. But I think movingapply_boot_alternatives()later in boot would make things less fragile.arch/riscv/kernel/patch.c +8
-4@@ -43,18 +43,19 @@ static __always_inline void *patch_map(void *addr, const unsigned int fixmap) {uintptr_t uintaddr = (uintptr_t ) addr;struct page *page; +phys_addr_t phys; -if (core_kernel_text (uintaddr) ||is_kernel_exittext (uintaddr)) - page =phys_to_page (__pa_symbol (addr)); -else if (IS_ENABLED (CONFIG_STRICT_MODULE_RWX )) +if (core_kernel_text (uintaddr) ||is_kernel_exittext (uintaddr)) { + phys =__pa_symbol (addr); + }else if (IS_ENABLED (CONFIG_STRICT_MODULE_RWX )) { page =vmalloc_to_page (addr); -else +BUG_ON (!page); + phys =page_to_phys (page); + }else {return addr; + }
Quoted 8 lines
arch/riscv/kernel/patch.c static __always_inline void *patch_map(void *addr, const unsigned int fixmap) · line 61
Quoted 8 lines
arch/riscv/kernel/patch.c +1
-4-BUG_ON (!page); - -return (void *)set_fixmap_offset (fixmap,page_to_phys (page) + -offset_in_page (addr)); +return (void *)set_fixmap_offset (fixmap, phys +offset_in_page (addr)); }static void patch_unmap (int fixmap)
The __pa_symbol(addr) case looks wrong - it adds an offset to an address already with offset. This matches what arm64 did and should look pretty similar to commit 8d09e2d569f6 ("arm64: patching: avoid early page_to_phys()"):
arch/riscv/kernel/patch.c +11 -11
@@ -42,19 +42,19 @@ static inline bool is_kernel_exittext(uintptr_t addr) static __always_inline void *patch_map(void *addr, const unsigned int fixmap) {uintptr_t uintaddr = (uintptr_t ) addr; -struct page *page; - -if (core_kernel_text (uintaddr) ||is_kernel_exittext (uintaddr)) - page =phys_to_page (__pa_symbol (addr)); -else if (IS_ENABLED (CONFIG_STRICT_MODULE_RWX )) - page =vmalloc_to_page (addr); -else +phys_addr_t phys; + +if (core_kernel_text (uintaddr) ||is_kernel_exittext (uintaddr)) { + phys =__pa_symbol (addr); + }else if (IS_ENABLED (CONFIG_STRICT_MODULE_RWX )) { +struct page *page =vmalloc_to_page (addr); +BUG_ON (!page); + phys =page_to_phys (page) +offset_in_page (addr); + }else {return addr; + } -BUG_ON (!page); - -return (void *)set_fixmap_offset (fixmap,page_to_phys (page) + -offset_in_page (addr)); +return (void *)set_fixmap_offset (fixmap, phys); }static void patch_unmap (int fixmap)
I can confirm this fixes riscv32 boot oops on QEMU. I can send it out as a proper patch later, pending making checkpatch.pl happy/happier and testing.
For reference this is arm64:
static void __kprobes *patch_map(void *addr, int fixmap)
{
phys_addr_t phys;
if (is_image_text((unsigned long)addr)) {
phys = __pa_symbol(addr);
} else {
struct page *page = vmalloc_to_page(addr);
BUG_ON(!page);
phys = page_to_phys(page) + offset_in_page(addr);
}
return (void *)set_fixmap_offset(fixmap, phys);
}Ritesh Harjani (IBM)
reviewerRe: [PATCH v3 24/29] arch, mm: consolidate initialization of SPARSE memory model
In reply to Mike RapoportQuoted 6 lines · Mike Rapoport
From: "Mike Rapoport (Microsoft)" <[email protected]>
Every architecture calls
sparse_init()duringsetup_arch()although the data structures created bysparse_init()are not used until the initialization of the core MM.
Quoted 8 lines
Beside the code duplication, calling
sparse_init()from architecture specific code causes ordering differences of vmemmap and HVO initialization on different architectures.Move the call to
sparse_init()from architecture specific code tofree_area_init()to ensure that vmemmap and HVO initialization order is always the same.
Hello Mike,
[ 0.000000][ T0] ------------[ cut here ]------------ [ 0.000000][ T0] WARNING: arch/powerpc/include/asm/io.h:879 at virt_to_phys+0x44/0x1b8, CPU#0: swapper/0 [ 0.000000][ T0] Modules linked in: [ 0.000000][ T0] CPU: 0 UID: 0 PID: 0 Comm: swapper Not tainted 6.19.0-12139-gc57b1c00145a #31 PREEMPT [ 0.000000][ T0] Hardware name: IBM pSeries (emulated by qemu) POWER10 (architected) 0x801200 0xf000006 of:SLOF,git-ee03ae pSeries [ 0.000000][ T0] NIP: c000000000601584 LR: c000000004075de4 CTR: c000000000601548 [ 0.000000][ T0] REGS: c000000004d1f870 TRAP: 0700 Not tainted (6.19.0-12139-gc57b1c00145a) [ 0.000000][ T0] MSR: 8000000000021033 <SF,ME,IR,DR,RI,LE> CR: 48022448 XER: 20040000 [ 0.000000][ T0] CFAR: c0000000006016c4 IRQMASK: 1 [ 0.000000][ T0] GPR00: c000000004075dd4 c000000004d1fb10 c00000000304bb00 c000000180000000 [ 0.000000][ T0] GPR04: 0000000000000009 0000000000000009 c000000004ec94a0 0000000000000000 [ 0.000000][ T0] GPR08: 0000000000018000 0000000000000001 c000000004921280 0000000048022448 [ 0.000000][ T0] GPR12: c000000000601548 c000000004fe0000 0000000000000004 0000000000000004 [ 0.000000][ T0] GPR16: 000000000287fb08 0000000000000060 0000000000000002 0000000002831750 [ 0.000000][ T0] GPR20: 0000000002831778 fffffffffffffffd c000000004d78050 00000000051cbb00 [ 0.000000][ T0] GPR24: 0000000005a40008 c000000000000000 c000000000400000 0000000000000100 [ 0.000000][ T0] GPR28: c000000004d78050 0000000000000000 c000000004ecd4a8 0000000000000001 [ 0.000000][ T0] NIP [c000000000601584] virt_to_phys+0x44/0x1b8 [ 0.000000][ T0] LR [c000000004075de4] alloc_bootmem+0x144/0x1a8 [ 0.000000][ T0] Call Trace: [ 0.000000][ T0] [c000000004d1fb50] [c000000004075dd4] alloc_bootmem+0x134/0x1a8 [ 0.000000][ T0] [c000000004d1fba0] [c000000004075fac] __alloc_bootmem_huge_page+0x164/0x230 [ 0.000000][ T0] [c000000004d1fbe0] [c000000004030bc4] alloc_bootmem_huge_page+0x44/0x138 [ 0.000000][ T0] [c000000004d1fc10] [c000000004076e48] hugetlb_hstate_alloc_pages+0x350/0x5ac [ 0.000000][ T0] [c000000004d1fd30] [c0000000040782f0] hugetlb_bootmem_alloc+0x15c/0x19c [ 0.000000][ T0] [c000000004d1fd70] [c00000000406d7b4] mm_core_init_early+0x7c/0xdf4 [ 0.000000][ T0] [c000000004d1ff30] [c000000004011d84] start_kernel+0xac/0xc58 [ 0.000000][ T0] [c000000004d1ffe0] [c00000000000e99c] start_here_common+0x1c/0x20 [ 0.000000][ T0] Code: 6129ffff 792907c6 6529ffff 6129ffff 7c234840 40810018 3d2201e8 3929a7a8 e9290000 7c291840 41810044 3be00001 <0b1f0000> 3d20bfff 6129ffff 792907c6
I think this is happening because, now in mm_core_early_init(), the order of initialization between hugetlb_bootmem_alloc() and free_area_init() is reversed. Since free_area_init() -> sparse_init() is responsible for setting SECTIONS and vmemmap area.
Then in alloc_bootmem() (from hugetlb_bootmem_alloc() path), it uses virt_to_phys(m)...
/*
* For pre-HVO to work correctly, pages need to be on
* the list for the node they were actually allocated
* from. That node may be different in the case of
* fallback by memblock_alloc_try_nid_raw. So,
* extract the actual node first.
*/
if (m)
listnode = early_pfn_to_nid(PHYS_PFN(virt_to_phys(m)));
... virt_to_phys on powerpc uses:
static inline unsigned long virt_to_phys(const volatile void * address)
{
WARN_ON(IS_ENABLED(CONFIG_DEBUG_VIRTUAL) && !virt_addr_valid(address));
return __pa((unsigned long)address);
}#define virt_addr_valid(vaddr) ({ \
unsigned long _addr = (unsigned long)vaddr; \
_addr >= PAGE_OFFSET && _addr < (unsigned long)high_memory && \
pfn_valid(virt_to_pfn((void *)_addr)); \
})I think the above warning in dmesg gets printed from above WARN_ON, i.e. because pfn_valid() is false, since we haven't done sparse_init() yet.
So, what I wanted to check was - do you think instead of virt_to_phys(), we could directly use __pa() here() in mm/hugetlb.c, since these are memblock alloc addresses? i.e.:
// alloc_bootmem():
- listnode = early_pfn_to_nid(PHYS_PFN(virt_to_phys(m)));
+ listnode = early_pfn_to_nid(PHYS_PFN(__pa(m)));
// __alloc_bootmem_huge_page():
- memblock_reserved_mark_noinit(virt_to_phys((void *)m + PAGE_SIZE),
+ memblock_reserved_mark_noinit(__pa((void *)m + PAGE_SIZE),
Thoughts?
-ritesh
Mike Rapoport
maintainerRe: [PATCH v3 24/29] arch, mm: consolidate initialization of SPARSE memory model
Hello Ritesh,
Quoted 84 lines · Ritesh Harjani
Quoted 6 lines · Mike Rapoport
From: "Mike Rapoport (Microsoft)" <[email protected]>
Every architecture calls
sparse_init()duringsetup_arch()although the data structures created bysparse_init()are not used until the initialization of the core MM.Quoted 8 lines
Beside the code duplication, calling
sparse_init()from architecture specific code causes ordering differences of vmemmap and HVO initialization on different architectures.Move the call to
sparse_init()from architecture specific code tofree_area_init()to ensure that vmemmap and HVO initialization order is always the same.Hello Mike,
[ 0.000000][ T0] ------------[ cut here ]------------ [ 0.000000][ T0] WARNING: arch/powerpc/include/asm/io.h:879 at virt_to_phys+0x44/0x1b8, CPU#0: swapper/0 [ 0.000000][ T0] Modules linked in: [ 0.000000][ T0] CPU: 0 UID: 0 PID: 0 Comm: swapper Not tainted 6.19.0-12139-gc57b1c00145a #31 PREEMPT [ 0.000000][ T0] Hardware name: IBM pSeries (emulated by qemu) POWER10 (architected) 0x801200 0xf000006 of:SLOF,git-ee03ae pSeries [ 0.000000][ T0] NIP: c000000000601584 LR: c000000004075de4 CTR: c000000000601548 [ 0.000000][ T0] REGS: c000000004d1f870 TRAP: 0700 Not tainted (6.19.0-12139-gc57b1c00145a) [ 0.000000][ T0] MSR: 8000000000021033 <SF,ME,IR,DR,RI,LE> CR: 48022448 XER: 20040000 [ 0.000000][ T0] CFAR: c0000000006016c4 IRQMASK: 1 [ 0.000000][ T0] GPR00: c000000004075dd4 c000000004d1fb10 c00000000304bb00 c000000180000000 [ 0.000000][ T0] GPR04: 0000000000000009 0000000000000009 c000000004ec94a0 0000000000000000 [ 0.000000][ T0] GPR08: 0000000000018000 0000000000000001 c000000004921280 0000000048022448 [ 0.000000][ T0] GPR12: c000000000601548 c000000004fe0000 0000000000000004 0000000000000004 [ 0.000000][ T0] GPR16: 000000000287fb08 0000000000000060 0000000000000002 0000000002831750 [ 0.000000][ T0] GPR20: 0000000002831778 fffffffffffffffd c000000004d78050 00000000051cbb00 [ 0.000000][ T0] GPR24: 0000000005a40008 c000000000000000 c000000000400000 0000000000000100 [ 0.000000][ T0] GPR28: c000000004d78050 0000000000000000 c000000004ecd4a8 0000000000000001 [ 0.000000][ T0] NIP [c000000000601584] virt_to_phys+0x44/0x1b8 [ 0.000000][ T0] LR [c000000004075de4] alloc_bootmem+0x144/0x1a8 [ 0.000000][ T0] Call Trace: [ 0.000000][ T0] [c000000004d1fb50] [c000000004075dd4] alloc_bootmem+0x134/0x1a8 [ 0.000000][ T0] [c000000004d1fba0] [c000000004075fac] __alloc_bootmem_huge_page+0x164/0x230 [ 0.000000][ T0] [c000000004d1fbe0] [c000000004030bc4] alloc_bootmem_huge_page+0x44/0x138 [ 0.000000][ T0] [c000000004d1fc10] [c000000004076e48] hugetlb_hstate_alloc_pages+0x350/0x5ac [ 0.000000][ T0] [c000000004d1fd30] [c0000000040782f0] hugetlb_bootmem_alloc+0x15c/0x19c [ 0.000000][ T0] [c000000004d1fd70] [c00000000406d7b4] mm_core_init_early+0x7c/0xdf4 [ 0.000000][ T0] [c000000004d1ff30] [c000000004011d84] start_kernel+0xac/0xc58 [ 0.000000][ T0] [c000000004d1ffe0] [c00000000000e99c] start_here_common+0x1c/0x20 [ 0.000000][ T0] Code: 6129ffff 792907c6 6529ffff 6129ffff 7c234840 40810018 3d2201e8 3929a7a8 e9290000 7c291840 41810044 3be00001 <0b1f0000> 3d20bfff 6129ffff 792907c6I think this is happening because, now in
mm_core_early_init(), the order of initialization betweenhugetlb_bootmem_alloc()andfree_area_init()is reversed. Sincefree_area_init()->sparse_init()is responsible for setting SECTIONS and vmemmap area.Then in
alloc_bootmem()(fromhugetlb_bootmem_alloc()path), it usesvirt_to_phys(m).../*
* For pre-HVO to work correctly, pages need to be on
* the list for the node they were actually allocated
* from. That node may be different in the case of
* fallback bymemblock_alloc_try_nid_raw. So,
* extract the actual node first.
*/
if (m)
listnode = early_pfn_to_nid(PHYS_PFN(virt_to_phys(m)));...
virt_to_physon powerpc uses:static inline unsigned long
virt_to_phys(const volatile void * address){ WARN_ON(IS_ENABLED(CONFIG_DEBUG_VIRTUAL) && !virt_addr_valid(address)); return __pa((unsigned long)address); }#define virt_addr_valid(vaddr) ({ \ unsigned long _addr = (unsigned long)vaddr; \ _addr >= PAGE_OFFSET && _addr < (unsigned long)high_memory && \ pfn_valid(virt_to_pfn((void *)_addr)); \ })
Quoted 2 lines
I think the above warning in dmesg gets printed from above
WARN_ON, i.e. becausepfn_valid()is false, since we haven't donesparse_init()yet.
Yes, I agree.
Review
Quoted 11 lines
So, what I wanted to check was - do you think instead of
virt_to_phys(), we could directly use__pa()here()inmm/hugetlb.c, since these are memblock alloc addresses? i.e.://
alloc_bootmem():(quoted diff) +1
-1- listnode = early_pfn_to_nid(PHYS_PFN(virt_to_phys(m))); + listnode = early_pfn_to_nid(PHYS_PFN(__pa(m)));//
__alloc_bootmem_huge_page():(quoted diff) +1
-1- memblock_reserved_mark_noinit(virt_to_phys((void *)m + PAGE_SIZE), + memblock_reserved_mark_noinit(__pa((void *)m + PAGE_SIZE),
It surely will work for powerpc :)
I checked the definitions of __pa() on other architectures and it seems the safest and the easiest way to fix this.
Would you send a formal patch?
Quoted 3 lines
Thoughts?
-ritesh
Signature · 2 lines
Sincerely yours, Mike.
Ritesh Harjani (IBM)
reviewerRe: [PATCH v3 24/29] arch, mm: consolidate initialization of SPARSE memory model
Quoted 104 lines · Mike Rapoport
Hello Ritesh,
Quoted 84 lines · Ritesh Harjani
Quoted 6 lines · Mike Rapoport
From: "Mike Rapoport (Microsoft)" <[email protected]>
Every architecture calls
sparse_init()duringsetup_arch()although the data structures created bysparse_init()are not used until the initialization of the core MM.Quoted 8 lines
Beside the code duplication, calling
sparse_init()from architecture specific code causes ordering differences of vmemmap and HVO initialization on different architectures.Move the call to
sparse_init()from architecture specific code tofree_area_init()to ensure that vmemmap and HVO initialization order is always the same.Hello Mike,
[ 0.000000][ T0] ------------[ cut here ]------------ [ 0.000000][ T0] WARNING: arch/powerpc/include/asm/io.h:879 at virt_to_phys+0x44/0x1b8, CPU#0: swapper/0 [ 0.000000][ T0] Modules linked in: [ 0.000000][ T0] CPU: 0 UID: 0 PID: 0 Comm: swapper Not tainted 6.19.0-12139-gc57b1c00145a #31 PREEMPT [ 0.000000][ T0] Hardware name: IBM pSeries (emulated by qemu) POWER10 (architected) 0x801200 0xf000006 of:SLOF,git-ee03ae pSeries [ 0.000000][ T0] NIP: c000000000601584 LR: c000000004075de4 CTR: c000000000601548 [ 0.000000][ T0] REGS: c000000004d1f870 TRAP: 0700 Not tainted (6.19.0-12139-gc57b1c00145a) [ 0.000000][ T0] MSR: 8000000000021033 <SF,ME,IR,DR,RI,LE> CR: 48022448 XER: 20040000 [ 0.000000][ T0] CFAR: c0000000006016c4 IRQMASK: 1 [ 0.000000][ T0] GPR00: c000000004075dd4 c000000004d1fb10 c00000000304bb00 c000000180000000 [ 0.000000][ T0] GPR04: 0000000000000009 0000000000000009 c000000004ec94a0 0000000000000000 [ 0.000000][ T0] GPR08: 0000000000018000 0000000000000001 c000000004921280 0000000048022448 [ 0.000000][ T0] GPR12: c000000000601548 c000000004fe0000 0000000000000004 0000000000000004 [ 0.000000][ T0] GPR16: 000000000287fb08 0000000000000060 0000000000000002 0000000002831750 [ 0.000000][ T0] GPR20: 0000000002831778 fffffffffffffffd c000000004d78050 00000000051cbb00 [ 0.000000][ T0] GPR24: 0000000005a40008 c000000000000000 c000000000400000 0000000000000100 [ 0.000000][ T0] GPR28: c000000004d78050 0000000000000000 c000000004ecd4a8 0000000000000001 [ 0.000000][ T0] NIP [c000000000601584] virt_to_phys+0x44/0x1b8 [ 0.000000][ T0] LR [c000000004075de4] alloc_bootmem+0x144/0x1a8 [ 0.000000][ T0] Call Trace: [ 0.000000][ T0] [c000000004d1fb50] [c000000004075dd4] alloc_bootmem+0x134/0x1a8 [ 0.000000][ T0] [c000000004d1fba0] [c000000004075fac] __alloc_bootmem_huge_page+0x164/0x230 [ 0.000000][ T0] [c000000004d1fbe0] [c000000004030bc4] alloc_bootmem_huge_page+0x44/0x138 [ 0.000000][ T0] [c000000004d1fc10] [c000000004076e48] hugetlb_hstate_alloc_pages+0x350/0x5ac [ 0.000000][ T0] [c000000004d1fd30] [c0000000040782f0] hugetlb_bootmem_alloc+0x15c/0x19c [ 0.000000][ T0] [c000000004d1fd70] [c00000000406d7b4] mm_core_init_early+0x7c/0xdf4 [ 0.000000][ T0] [c000000004d1ff30] [c000000004011d84] start_kernel+0xac/0xc58 [ 0.000000][ T0] [c000000004d1ffe0] [c00000000000e99c] start_here_common+0x1c/0x20 [ 0.000000][ T0] Code: 6129ffff 792907c6 6529ffff 6129ffff 7c234840 40810018 3d2201e8 3929a7a8 e9290000 7c291840 41810044 3be00001 <0b1f0000> 3d20bfff 6129ffff 792907c6I think this is happening because, now in
mm_core_early_init(), the order of initialization betweenhugetlb_bootmem_alloc()andfree_area_init()is reversed. Sincefree_area_init()->sparse_init()is responsible for setting SECTIONS and vmemmap area.Then in
alloc_bootmem()(fromhugetlb_bootmem_alloc()path), it usesvirt_to_phys(m).../*
* For pre-HVO to work correctly, pages need to be on
* the list for the node they were actually allocated
* from. That node may be different in the case of
* fallback bymemblock_alloc_try_nid_raw. So,
* extract the actual node first.
*/
if (m)
listnode = early_pfn_to_nid(PHYS_PFN(virt_to_phys(m)));...
virt_to_physon powerpc uses:static inline unsigned long
virt_to_phys(const volatile void * address){ WARN_ON(IS_ENABLED(CONFIG_DEBUG_VIRTUAL) && !virt_addr_valid(address)); return __pa((unsigned long)address); }#define virt_addr_valid(vaddr) ({ \ unsigned long _addr = (unsigned long)vaddr; \ _addr >= PAGE_OFFSET && _addr < (unsigned long)high_memory && \ pfn_valid(virt_to_pfn((void *)_addr)); \ })Quoted 2 lines
I think the above warning in dmesg gets printed from above
WARN_ON, i.e. becausepfn_valid()is false, since we haven't donesparse_init()yet.Yes, I agree.
Review
Quoted 11 lines
So, what I wanted to check was - do you think instead of
virt_to_phys(), we could directly use__pa()here()inmm/hugetlb.c, since these are memblock alloc addresses? i.e.://
alloc_bootmem():(quoted diff) +1
-1- listnode = early_pfn_to_nid(PHYS_PFN(virt_to_phys(m))); + listnode = early_pfn_to_nid(PHYS_PFN(__pa(m)));//
__alloc_bootmem_huge_page():(quoted diff) +1
-1- memblock_reserved_mark_noinit(virt_to_phys((void *)m + PAGE_SIZE), + memblock_reserved_mark_noinit(__pa((void *)m + PAGE_SIZE),
Quoted 6 lines
It surely will work for powerpc :)
I checked the definitions of__pa()on other architectures and it seems the safest and the easiest way to fix this.Would you send a formal patch?
Thanks Mike for taking a look at above and confirming. Sure, let me prepare the patch and send it by tomorrow.
-ritesh
Mike Rapoport
maintainerPATCH v3 25/29 mips: drop paging_init()
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
All three variants of paging_init() on MIPS are wrappers for pagetable_init().
Instead of having three identical wrappers, call pagetable_init() directly from setup_arch() and remove the unnecessary paging_init() functions.
--- arch/mips/include/asm/pgalloc.h | 2 -- arch/mips/include/asm/pgtable.h | 2 +- arch/mips/kernel/setup.c | 4 ++-- arch/mips/loongson64/numa.c | 5 ----- arch/mips/mm/init.c | 5 ----- arch/mips/sgi-ip27/ip27-memory.c | 5 ----- 6 files changed, 3 insertions(+), 20 deletions(-)
arch/mips/include/asm/pgalloc.h +0 -2
@@ -101,6 +101,4 @@ static inline void p4d_populate(struct mm_struct *mm, p4d_t *p4d, pud_t *pud)#endif /* __PAGETABLE_PUD_FOLDED */ -extern void pagetable_init (void ); -#endif /* _ASM_PGALLOC_H */
arch/mips/include/asm/pgtable.h +1 -1
@@ -56,7 +56,7 @@ extern unsigned long zero_page_mask; (virt_to_page((void *)(empty_zero_page + (((unsigned long)(vaddr)) & zero_page_mask))))#define __HAVE_COLOR_ZERO_PAGE -extern void paging_init (void ); +extern void pagetable_init (void );/* * Conversion functions: convert a page and protection to a page entry,
arch/mips/kernel/setup.c +2 -2
@@ -614,7 +614,7 @@ static void __init bootcmdline_init(void)* kernel but generic memory management system is still entirely uninitialized. * * o bootmem_init() -* o paging_init() +* o pagetable_init() * o dma_contiguous_reserve() * * At this stage the bootmem allocator is ready to use.
@@ -778,7 +778,7 @@ void __init setup_arch(char **cmdline_p)prefill_possible_map ();cpu_cache_init (); -paging_init (); +pagetable_init ();memblock_dump_all ();
arch/mips/loongson64/numa.c +0 -5
@@ -160,11 +160,6 @@ void __init arch_zone_limits_init(unsigned long *max_zone_pfns) max_zone_pfns[ZONE_NORMAL ] = max_low_pfn; } -void __init paging_init (void ) -{ -pagetable_init (); -} -/* All PCI device belongs to logical Node-0 */ int pcibus_to_node (struct pci_bus *bus) {
arch/mips/mm/init.c +0 -5
@@ -415,11 +415,6 @@ void __init arch_zone_limits_init(unsigned long *max_zone_pfns)#endif } -void __init paging_init (void ) -{ -pagetable_init (); -} -#ifdef CONFIG_64BIT static struct kcore_list kcore_kseg0;#endif
arch/mips/sgi-ip27/ip27-memory.c +0 -5
@@ -410,8 +410,3 @@ void __init arch_zone_limits_init(unsigned long *max_zone_pfns) { max_zone_pfns[ZONE_NORMAL ] = max_low_pfn; } - -void __init paging_init (void ) -{ -pagetable_init (); -}
Signature · 1 line
2.51.0
Mike Rapoport
maintainerPATCH v3 26/29 x86: don't reserve hugetlb memory in setup_arch()
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Commit 665eaf313314 ("x86/setup: call hugetlb_bootmem_alloc early") added an early call to hugetlb_bootmem_alloc() to setup_arch() to allow HVO style pre-initialization of vmemmap on x86.
With the ordering of hugetlb reservation vs memory map initialization sorted out in core MM this no longer needs to be an architecture specific quirk.
Drop the call to hugetlb_bootmem_alloc() from x86::setup_arch().
--- arch/x86/kernel/setup.c | 1 - 1 file changed, 1 deletion(-)
arch/x86/kernel/setup.c +0 -1
@@ -1191,7 +1191,6 @@ void __init setup_arch(char **cmdline_p)if (boot_cpu_has (X86_FEATURE_GBPAGES )) {hugetlb_cma_reserve (PUD_SHIFT -PAGE_SHIFT ); -hugetlb_bootmem_alloc (); }/*
Signature · 1 line
2.51.0
Mike Rapoport
maintainerPATCH v3 27/29 mm, arch: consolidate hugetlb CMA reservation
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Every architecture that supports hugetlb_cma command line parameter reserves CMA areas for hugetlb during setup_arch().
This obfuscates the ordering of hugetlb CMA initialization with respect to the rest initialization of the core MM.
Introduce arch_hugetlb_cma_order() callback to allow architectures report the desired order-per-bit of CMA areas and provide a week implementation of arch_hugetlb_cma_order() for architectures that don't support hugetlb with CMA.
Use this callback in hugetlb_cma_reserve() instead if passing the order as parameter and call hugetlb_cma_reserve() from mm_core_init_early() rather than have it spread over architecture specific code.
--- .../driver-api/cxl/linux/early-boot.rst | 2 +- arch/arm64/include/asm/hugetlb.h | 2 -- arch/arm64/mm/hugetlbpage.c | 10 +++------- arch/arm64/mm/init.c | 9 --------- arch/powerpc/include/asm/hugetlb.h | 5 ----- arch/powerpc/kernel/setup-common.c | 1 - arch/powerpc/mm/hugetlbpage.c | 11 ++++------- arch/riscv/mm/hugetlbpage.c | 8 ++++++++ arch/riscv/mm/init.c | 2 -- arch/s390/kernel/setup.c | 2 -- arch/s390/mm/hugetlbpage.c | 8 ++++++++ arch/x86/kernel/setup.c | 4 ---- arch/x86/mm/hugetlbpage.c | 8 ++++++++ include/linux/hugetlb.h | 6 ++++-- mm/hugetlb_cma.c | 19 ++++++++++++++----- mm/mm_init.c | 1 + 16 files changed, 51 insertions(+), 47 deletions(-)
Documentation/driver-api/cxl/linux/early-boot.rst +1 -1
@@ -125,7 +125,7 @@ The contiguous memory allocator (CMA) enables reservation of contiguous memory regions on NUMA nodes during early boot. However, CMA cannot reserve memory on NUMA nodes that are not online during early boot. :: - void __init hugetlb_cma_reserve(int order) { + void __init hugetlb_cma_reserve(void) { if (!node_online(nid)) /* do not allow reservations */ }
arch/arm64/include/asm/hugetlb.h +0 -2
@@ -56,8 +56,6 @@ extern void huge_pte_clear(struct mm_struct *mm, unsigned long addr,#define __HAVE_ARCH_HUGE_PTEP_GETextern pte_t huge_ptep_get (struct mm_struct *mm,unsigned long addr,pte_t *ptep); -void __init arm64_hugetlb_cma_reserve (void ); -#define huge_ptep_modify_prot_start huge_ptep_modify_prot_startextern pte_t huge_ptep_modify_prot_start (struct vm_area_struct *vma,unsigned long addr,pte_t *ptep);
arch/arm64/mm/hugetlbpage.c +3 -7
@@ -36,16 +36,12 @@* huge pages could still be served from those areas. */ #ifdef CONFIG_CMA -void __init arm64_hugetlb_cma_reserve (void ) +unsigned int arch_hugetlb_cma_order (void ) { -int order; -if (pud_sect_supported ()) - order =PUD_SHIFT -PAGE_SHIFT ; -else - order =CONT_PMD_SHIFT -PAGE_SHIFT ; +return PUD_SHIFT -PAGE_SHIFT ; -hugetlb_cma_reserve (order); +return CONT_PMD_SHIFT -PAGE_SHIFT ; }#endif /* CONFIG_CMA */
arch/arm64/mm/init.c +0 -9
@@ -311,15 +311,6 @@ void __init bootmem_init(void)arch_numa_init (); -/* -* must be done after arch_numa_init() which calls numa_init() to -* initialize node_online_map that gets used in hugetlb_cma_reserve() -* while allocating required CMA size across online nodes. -*/ -#if defined(CONFIG_HUGETLB_PAGE ) && defined(CONFIG_CMA ) -arm64_hugetlb_cma_reserve (); -#endif -kvm_hyp_reserve ();dma_limits_init ();
arch/powerpc/include/asm/hugetlb.h +0 -5
@@ -68,7 +68,6 @@ int huge_ptep_set_access_flags(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep, pte_t pte, int dirty); -void gigantic_hugetlb_cma_reserve (void )__init ;#include <asm-generic/hugetlb.h> #else /* ! CONFIG_HUGETLB_PAGE */
@@ -77,10 +76,6 @@ static inline void flush_hugetlb_page(struct vm_area_struct *vma, { } -static inline void __init gigantic_hugetlb_cma_reserve (void ) -{ -} -static inline void __init hugetlbpage_init_defaultsize (void ) { }
arch/powerpc/kernel/setup-common.c +0 -1
@@ -1003,7 +1003,6 @@ void __init setup_arch(char **cmdline_p)fadump_cma_init ();kdump_cma_reserve ();kvm_cma_reserve (); -gigantic_hugetlb_cma_reserve ();early_memtest (min_low_pfn <<PAGE_SHIFT , max_low_pfn <<PAGE_SHIFT );
arch/powerpc/mm/hugetlbpage.c +4 -7
@@ -200,18 +200,15 @@ static int __init hugetlbpage_init(void)arch_initcall (hugetlbpage_init); -void __init gigantic_hugetlb_cma_reserve (void ) +unsigned int __init arch_hugetlb_cma_order (void ) { -unsigned long order =0 ; -if (radix_enabled ()) - order =PUD_SHIFT -PAGE_SHIFT ; +return PUD_SHIFT -PAGE_SHIFT ;else if (!firmware_has_feature (FW_FEATURE_LPAR ) && mmu_psize_defs[MMU_PAGE_16G ].shift)/* * For pseries we do use ibm,expected#pages for reserving 16G pages. */ - order =mmu_psize_to_shift (MMU_PAGE_16G ) -PAGE_SHIFT ; +return mmu_psize_to_shift (MMU_PAGE_16G ) -PAGE_SHIFT ; -if (order) -hugetlb_cma_reserve (order); +return 0 ; }
arch/riscv/mm/hugetlbpage.c +8 -0
@@ -447,3 +447,11 @@ static __init int gigantic_pages_init(void) }arch_initcall (gigantic_pages_init);#endif + +unsigned int __init arch_hugetlb_cma_order (void ) +{ +if (IS_ENABLED (CONFIG_64BIT )) +return PUD_SHIFT -PAGE_SHIFT ; + +return 0 ; +}
arch/riscv/mm/init.c +0 -2
@@ -311,8 +311,6 @@ static void __init setup_bootmem(void)memblock_reserve (dtb_early_pa,fdt_totalsize (dtb_early_va));dma_contiguous_reserve (dma32_phys_limit); -if (IS_ENABLED (CONFIG_64BIT )) -hugetlb_cma_reserve (PUD_SHIFT -PAGE_SHIFT ); }#ifdef CONFIG_RELOCATABLE
arch/s390/kernel/setup.c +0 -2
@@ -963,8 +963,6 @@ void __init setup_arch(char **cmdline_p)setup_uv ();dma_contiguous_reserve (ident_map_size);vmcp_cma_reserve (); -if (cpu_has_edat2 ()) -hugetlb_cma_reserve (PUD_SHIFT -PAGE_SHIFT );reserve_crashkernel ();#ifdef CONFIG_CRASH_DUMP
arch/s390/mm/hugetlbpage.c +8 -0
@@ -255,3 +255,11 @@ bool __init arch_hugetlb_valid_size(unsigned long size)else return false; } + +unsigned int __init arch_hugetlb_cma_order (void ) +{ +if (cpu_has_edat2 ()) +return PUD_SHIFT -PAGE_SHIFT ; + +return 0 ; +}
arch/x86/kernel/setup.c +0 -4
@@ -1189,10 +1189,6 @@ void __init setup_arch(char **cmdline_p)initmem_init ();dma_contiguous_reserve (max_pfn_mapped <<PAGE_SHIFT ); -if (boot_cpu_has (X86_FEATURE_GBPAGES )) { -hugetlb_cma_reserve (PUD_SHIFT -PAGE_SHIFT ); - } -/* * Reserve memory for crash kernel after SRAT is parsed so that it * won't consume hotpluggable memory.
arch/x86/mm/hugetlbpage.c +8 -0
@@ -42,3 +42,11 @@ static __init int gigantic_pages_init(void)arch_initcall (gigantic_pages_init);#endif #endif + +unsigned int __init arch_hugetlb_cma_order (void ) +{ +if (boot_cpu_has (X86_FEATURE_GBPAGES )) +return PUD_SHIFT -PAGE_SHIFT ; + +return 0 ; +}
include/linux/hugetlb.h +4 -2
@@ -279,6 +279,8 @@ void fixup_hugetlb_reservations(struct vm_area_struct *vma);void hugetlb_split (struct vm_area_struct *vma,unsigned long addr);int hugetlb_vma_lock_alloc (struct vm_area_struct *vma); +unsigned int arch_hugetlb_cma_order (void ); +#else /* !CONFIG_HUGETLB_PAGE */ static inline void hugetlb_dup_vma_private (struct vm_area_struct *vma)
@@ -1316,9 +1318,9 @@ static inline spinlock_t *huge_pte_lock(struct hstate *h, }#if defined(CONFIG_HUGETLB_PAGE ) && defined(CONFIG_CMA ) -extern void __init hugetlb_cma_reserve (int order); +extern void __init hugetlb_cma_reserve (void );#else -static inline __init void hugetlb_cma_reserve (int order) +static inline __init void hugetlb_cma_reserve (void ) { }#endif
mm/hugetlb_cma.c +14 -5
@@ -134,12 +134,24 @@ static int __init cmdline_parse_hugetlb_cma_only(char *p)early_param ("hugetlb_cma_only" , cmdline_parse_hugetlb_cma_only); -void __init hugetlb_cma_reserve (int order) +unsigned int __weak arch_hugetlb_cma_order (void ) { -unsigned long size, reserved, per_node; +return 0 ; +} + +void __init hugetlb_cma_reserve (void ) +{ +unsigned long size, reserved, per_node, order;bool node_specific_cma_alloc = false;int nid; +if (!hugetlb_cma_size) +return ; + + order =arch_hugetlb_cma_order (); +if (!order) +return ; +/* * HugeTLB CMA reservation is required for gigantic * huge pages which could not be allocated via the
@@ -149,9 +161,6 @@ void __init hugetlb_cma_reserve(int order)VM_WARN_ON (order <=MAX_PAGE_ORDER ); cma_reserve_called = true; -if (!hugetlb_cma_size) -return ; -hugetlb_bootmem_set_nodes ();for (nid =0 ; nid <MAX_NUMNODES ; nid++) {
mm/mm_init.c +1 -0
@@ -2680,6 +2680,7 @@ void __init __weak mem_init(void)void __init mm_core_init_early (void ) { +hugetlb_cma_reserve ();hugetlb_bootmem_alloc ();free_area_init ();
Signature · 1 line
2.51.0
Mike Rapoport
maintainerPATCH v3 28/29 mm/hugetlb: drop hugetlb_cma_check()
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
hugetlb_cma_check() was required when the ordering of hugetlb_cma_reserve() and hugetlb_bootmem_alloc() was architecture depended.
Since hugetlb_cma_reserve() is always called before hugetlb_bootmem_alloc() there is no need to check whether hugetlb_cma_reserve() was already called.
Drop unneeded hugetlb_cma_check() function.
--- mm/hugetlb.c | 1 - mm/hugetlb_cma.c | 16 +++------------- mm/hugetlb_cma.h | 5 ----- 3 files changed, 3 insertions(+), 19 deletions(-)
mm/hugetlb.c +0 -1
@@ -4159,7 +4159,6 @@ static int __init hugetlb_init(void) } } -hugetlb_cma_check ();hugetlb_init_hstates ();gather_bootmem_prealloc ();report_hugepages ();
mm/hugetlb_cma.c +3 -13
@@ -85,9 +85,6 @@ hugetlb_cma_alloc_bootmem(struct hstate *h, int *nid, bool node_exact)return m; } - -static bool cma_reserve_called__initdata ; -static int __init cmdline_parse_hugetlb_cma (char *p) {int nid, count =0 ;
@@ -149,8 +146,10 @@ void __init hugetlb_cma_reserve(void)return ; order =arch_hugetlb_cma_order (); -if (!order) +if (!order) { +pr_warn ("hugetlb_cma: the option isn't supported by current arch\n" );return ; + }/* * HugeTLB CMA reservation is required for gigantic
@@ -159,7 +158,6 @@ void __init hugetlb_cma_reserve(void)* breaking this assumption. */ VM_WARN_ON (order <=MAX_PAGE_ORDER ); - cma_reserve_called = true;hugetlb_bootmem_set_nodes ();
@@ -253,14 +251,6 @@ void __init hugetlb_cma_reserve(void) hugetlb_cma_size =0 ; } -void __init hugetlb_cma_check (void ) -{ -if (!hugetlb_cma_size || cma_reserve_called) -return ; - -pr_warn ("hugetlb_cma: the option isn't supported by current arch\n" ); -} -bool hugetlb_cma_exclusive_alloc (void ) {return hugetlb_cma_only;
mm/hugetlb_cma.h +0 -5
@@ -8,7 +8,6 @@ struct folio *hugetlb_cma_alloc_folio(int order, gfp_t gfp_mask, int nid, nodemask_t *nodemask);struct huge_bootmem_page *hugetlb_cma_alloc_bootmem (struct hstate *h,int *nid,bool node_exact); -void hugetlb_cma_check (void );bool hugetlb_cma_exclusive_alloc (void );unsigned long hugetlb_cma_total_size (void );void hugetlb_cma_validate_params (void );
@@ -31,10 +30,6 @@ struct huge_bootmem_page *hugetlb_cma_alloc_bootmem(struct hstate *h, int *nid,return NULL ; } -static inline void hugetlb_cma_check (void ) -{ -} -static inline bool hugetlb_cma_exclusive_alloc (void ) {return false;
Signature · 1 line
2.51.0
Mike Rapoport
maintainerPATCH v3 29/29 Revert "mm/hugetlb: deal with multiple calls to hugetlb_bootmem_alloc"
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
This reverts commit d58b2498200724e4f8c12d71a5953da03c8c8bdf.
hugetlb_bootmem_alloc() is called only once, no need to check if it was called already at its entry.
Other checks performed during HVO initialization are also no longer necessary because sparse_init() that calls hugetlb_vmemmap_init_early() and hugetlb_vmemmap_init_late() is always called after hugetlb_bootmem_alloc().
--- include/linux/hugetlb.h | 6 ------ mm/hugetlb.c | 12 ------------ mm/hugetlb_vmemmap.c | 11 ----------- 3 files changed, 29 deletions(-)
include/linux/hugetlb.h +0 -6
@@ -175,7 +175,6 @@ extern int sysctl_hugetlb_shm_group __read_mostly;extern struct list_head huge_boot_pages[MAX_NUMNODES ];void hugetlb_bootmem_alloc (void ); -bool hugetlb_bootmem_allocated (void );extern nodemask_t hugetlb_bootmem_nodes;void hugetlb_bootmem_set_nodes (void );
@@ -1300,11 +1299,6 @@ static inline bool hugetlbfs_pagecache_present(static inline void hugetlb_bootmem_alloc (void ) { } - -static inline bool hugetlb_bootmem_allocated (void ) -{ -return false; -}#endif /* CONFIG_HUGETLB_PAGE */ static inline spinlock_t *huge_pte_lock(struct hstate *h,
mm/hugetlb.c +0 -12
@@ -4470,21 +4470,11 @@ void __init hugetlb_bootmem_set_nodes(void) } } -static bool __hugetlb_bootmem_allocated__initdata ; - -bool __init hugetlb_bootmem_allocated (void ) -{ -return __hugetlb_bootmem_allocated; -} -void __init hugetlb_bootmem_alloc (void ) {struct hstate *h;int i; -if (__hugetlb_bootmem_allocated) -return ; -hugetlb_bootmem_set_nodes ();for (i =0 ; i <MAX_NUMNODES ; i++)
@@ -4498,8 +4488,6 @@ void __init hugetlb_bootmem_alloc(void)if (hstate_is_gigantic (h))hugetlb_hstate_alloc_pages (h); } - - __hugetlb_bootmem_allocated = true; }/*
mm/hugetlb_vmemmap.c +0 -11
@@ -794,14 +794,6 @@ void __init hugetlb_vmemmap_init_early(int nid)struct huge_bootmem_page *m =NULL ;void *map; -/* -* Noting to do if bootmem pages were not allocated -* early in boot, or if HVO wasn't enabled in the -* first place. -*/ -if (!hugetlb_bootmem_allocated ()) -return ; -if (!READ_ONCE (vmemmap_optimize_enabled))return ;
@@ -847,9 +839,6 @@ void __init hugetlb_vmemmap_init_late(int nid)struct hstate *h;void *map; -if (!hugetlb_bootmem_allocated ()) -return ; -if (!READ_ONCE (vmemmap_optimize_enabled))return ;
Signature · 1 line
2.51.0
Andrew Morton
maintainerQuoted 4 lines · On Sun, 11 Jan 2026 10:20:34 +0200 Mike Rapoport <[email protected]> wrote:
v3 changes:
* fixempty_zero_pageinitialization on arm
* fixZONE_DMAlimit calculation on powerpc
* add Acks
updated, thanks. I'll suppress the ensuing email flood.
Kalle, can you please retest sometime, see if the BeagleBone Black boot failure was fixed?
Seems we haven't heard back from rmk regarding
https://lkml.kernel.org/r/[email protected].
Quoted 7 lines · Andrew Morton
Quoted 4 lines · On Sun, 11 Jan 2026 10:20:34 +0200 Mike Rapoport <[email protected]> wrote:
v3 changes:
* fixempty_zero_pageinitialization on arm
* fixZONE_DMAlimit calculation on powerpc
* add Acks
Quoted 7 lines
updated, thanks. I'll suppress the ensuing email flood.
Kalle, can you please retest sometime, see if the BeagleBone Black boot failure was fixed?
Seems we haven't heard back from rmk regarding
https://lkml.kernel.org/r/[email protected].
Hello!
I will test this v3 patch ASAP and reply results here. Collective sorry for the delay; I have been busy!
BR
Kalle
Quoted 16 lines · Kalle Niemi
Quoted 7 lines · Andrew Morton
Quoted 4 lines · On Sun, 11 Jan 2026 10:20:34 +0200 Mike Rapoport <[email protected]> wrote:
v3 changes:
* fixempty_zero_pageinitialization on arm
* fixZONE_DMAlimit calculation on powerpc
* add AcksQuoted 7 lines
updated, thanks. I'll suppress the ensuing email flood.
Kalle, can you please retest sometime, see if the BeagleBone Black boot failure was fixed?
Seems we haven't heard back from rmk regarding
https://lkml.kernel.org/r/[email protected].
Quoted 7 lines
Hello!
I will test this v3 patch ASAP and reply results here. Collective sorry for the delay; I have been busy!
BR
Kalle
Hello!
I tried this patch by cloning https://git.kernel.org/pub/scm/linux/kernel/git/rppt/linux.git/log/?h=hugetlb-init/v3
Boots succesfully on BeagleBone Black!
BR
Kalle
This series was applied to riscv/linux.git (fixes) by Andrew Morton <[email protected]>:
Hello:
This series was applied to riscv/linux.git (fixes) by Andrew Morton <[email protected]>:
Quoted 8 lines · On Sun, 11 Jan 2026 10:20:34 +0200 you wrote:
From: "Mike Rapoport (Microsoft)" <[email protected]>
Hi,
Order in which early memory reservation for hugetlb happens depends on architecture, on configuration options and on command line parameters.
[...]
Here is the summary with links:
- [v3,01/29] alpha: introduce arch_zone_limits_init()
https://git.kernel.org/riscv/c/ba1c86874e25 - [v3,02/29] arc: introduce arch_zone_limits_init() https://git.kernel.org/riscv/c/7988e8518904 - [v3,03/29] arm: introduce arch_zone_limits_init() https://git.kernel.org/riscv/c/30a66f8a8cd3 - [v3,04/29] arm: make initialization of zero page independent of the memory map https://git.kernel.org/riscv/c/18b7cc70dea8 - [v3,05/29] arm64: introduce arch_zone_limits_init() https://git.kernel.org/riscv/c/60b35af0a6aa - [v3,06/29] csky: introduce arch_zone_limits_init() https://git.kernel.org/riscv/c/37318eb97f23 - [v3,07/29] hexagon: introduce arch_zone_limits_init() https://git.kernel.org/riscv/c/934afdf7f4cc - [v3,08/29] loongarch: introduce arch_zone_limits_init() https://git.kernel.org/riscv/c/63cadcb731c9 - [v3,09/29] m68k: introduce arch_zone_limits_init() https://git.kernel.org/riscv/c/41b08a7abf89 - [v3,10/29] microblaze: introduce arch_zone_limits_init() https://git.kernel.org/riscv/c/2ce38c9ae840 - [v3,11/29] mips: introduce arch_zone_limits_init() https://git.kernel.org/riscv/c/f61385e29444 - [v3,12/29] nios2: introduce arch_zone_limits_init() https://git.kernel.org/riscv/c/3b1b0e5797bd - [v3,13/29] openrisc: introduce arch_zone_limits_init() https://git.kernel.org/riscv/c/1d28b1142383 - [v3,14/29] parisc: introduce arch_zone_limits_init() https://git.kernel.org/riscv/c/950696afe400 - [v3,15/29] powerpc: introduce arch_zone_limits_init() https://git.kernel.org/riscv/c/27bebe446f8d - [v3,16/29] riscv: introduce arch_zone_limits_init() https://git.kernel.org/riscv/c/db8cdb0ad603 - [v3,17/29] s390: introduce arch_zone_limits_init() https://git.kernel.org/riscv/c/76c4c463bbc0 - [v3,18/29] sh: introduce arch_zone_limits_init() https://git.kernel.org/riscv/c/8bfa6c2259f4 - [v3,19/29] sparc: introduce arch_zone_limits_init() https://git.kernel.org/riscv/c/6ad7ea22cf6f - [v3,20/29] um: introduce arch_zone_limits_init() https://git.kernel.org/riscv/c/531de7f02d51 - [v3,21/29] x86: introduce arch_zone_limits_init() https://git.kernel.org/riscv/c/34f6b9c6e417 - [v3,22/29] xtensa: introduce arch_zone_limits_init() https://git.kernel.org/riscv/c/2d3c8c5f33e0 - [v3,23/29] arch, mm: consolidate initialization of nodes, zones and memory map https://git.kernel.org/riscv/c/d49004c5f0c1 - [v3,24/29] arch, mm: consolidate initialization of SPARSE memory model https://git.kernel.org/riscv/c/4267739cabb8 - [v3,25/29] mips: drop paging_init() https://git.kernel.org/riscv/c/5dea39496c68 - [v3,26/29] x86: don't reserve hugetlb memory in setup_arch() https://git.kernel.org/riscv/c/6632314fddc4 - [v3,27/29] mm, arch: consolidate hugetlb CMA reservation https://git.kernel.org/riscv/c/9fac145b6d3f - [v3,28/29] mm/hugetlb: drop hugetlb_cma_check() https://git.kernel.org/riscv/c/7a9c0bf0aec6 - [v3,29/29] Revert "mm/hugetlb: deal with multiple calls to hugetlb_bootmem_alloc" https://git.kernel.org/riscv/c/743758ccf8be
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html