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

Configure Feed

Select the types of activity you want to include in your feed.

mm, arch: consolidate hugetlb CMA reservation

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.

Link: https://lkml.kernel.org/r/20260111082105.290734-28-rppt@kernel.org
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Alex Shi <alexs@kernel.org>
Cc: Andreas Larsson <andreas@gaisler.com>
Cc: "Borislav Petkov (AMD)" <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: David Hildenbrand <david@kernel.org>
Cc: David S. Miller <davem@davemloft.net>
Cc: Dinh Nguyen <dinguyen@kernel.org>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Guo Ren <guoren@kernel.org>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Helge Deller <deller@gmx.de>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Johannes Berg <johannes@sipsolutions.net>
Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Klara Modin <klarasmodin@gmail.com>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Magnus Lindholm <linmag7@gmail.com>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Max Filippov <jcmvbkbc@gmail.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Pratyush Yadav <pratyush@kernel.org>
Cc: Richard Weinberger <richard@nod.at>
Cc: "Ritesh Harjani (IBM)" <ritesh.list@gmail.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Stafford Horne <shorne@gmail.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Vineet Gupta <vgupta@kernel.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Mike Rapoport (Microsoft) and committed by
Andrew Morton
9fac145b 6632314f

+51 -47
+1 -1
Documentation/driver-api/cxl/linux/early-boot.rst
··· 125 125 regions on NUMA nodes during early boot. However, CMA cannot reserve memory 126 126 on NUMA nodes that are not online during early boot. :: 127 127 128 - void __init hugetlb_cma_reserve(int order) { 128 + void __init hugetlb_cma_reserve(void) { 129 129 if (!node_online(nid)) 130 130 /* do not allow reservations */ 131 131 }
-2
arch/arm64/include/asm/hugetlb.h
··· 56 56 #define __HAVE_ARCH_HUGE_PTEP_GET 57 57 extern pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep); 58 58 59 - void __init arm64_hugetlb_cma_reserve(void); 60 - 61 59 #define huge_ptep_modify_prot_start huge_ptep_modify_prot_start 62 60 extern pte_t huge_ptep_modify_prot_start(struct vm_area_struct *vma, 63 61 unsigned long addr, pte_t *ptep);
+3 -7
arch/arm64/mm/hugetlbpage.c
··· 36 36 * huge pages could still be served from those areas. 37 37 */ 38 38 #ifdef CONFIG_CMA 39 - void __init arm64_hugetlb_cma_reserve(void) 39 + unsigned int arch_hugetlb_cma_order(void) 40 40 { 41 - int order; 42 - 43 41 if (pud_sect_supported()) 44 - order = PUD_SHIFT - PAGE_SHIFT; 45 - else 46 - order = CONT_PMD_SHIFT - PAGE_SHIFT; 42 + return PUD_SHIFT - PAGE_SHIFT; 47 43 48 - hugetlb_cma_reserve(order); 44 + return CONT_PMD_SHIFT - PAGE_SHIFT; 49 45 } 50 46 #endif /* CONFIG_CMA */ 51 47
-9
arch/arm64/mm/init.c
··· 311 311 312 312 arch_numa_init(); 313 313 314 - /* 315 - * must be done after arch_numa_init() which calls numa_init() to 316 - * initialize node_online_map that gets used in hugetlb_cma_reserve() 317 - * while allocating required CMA size across online nodes. 318 - */ 319 - #if defined(CONFIG_HUGETLB_PAGE) && defined(CONFIG_CMA) 320 - arm64_hugetlb_cma_reserve(); 321 - #endif 322 - 323 314 kvm_hyp_reserve(); 324 315 dma_limits_init(); 325 316
-5
arch/powerpc/include/asm/hugetlb.h
··· 68 68 unsigned long addr, pte_t *ptep, 69 69 pte_t pte, int dirty); 70 70 71 - void gigantic_hugetlb_cma_reserve(void) __init; 72 71 #include <asm-generic/hugetlb.h> 73 72 74 73 #else /* ! CONFIG_HUGETLB_PAGE */ 75 74 static inline void flush_hugetlb_page(struct vm_area_struct *vma, 76 75 unsigned long vmaddr) 77 - { 78 - } 79 - 80 - static inline void __init gigantic_hugetlb_cma_reserve(void) 81 76 { 82 77 } 83 78
-1
arch/powerpc/kernel/setup-common.c
··· 1003 1003 fadump_cma_init(); 1004 1004 kdump_cma_reserve(); 1005 1005 kvm_cma_reserve(); 1006 - gigantic_hugetlb_cma_reserve(); 1007 1006 1008 1007 early_memtest(min_low_pfn << PAGE_SHIFT, max_low_pfn << PAGE_SHIFT); 1009 1008
+4 -7
arch/powerpc/mm/hugetlbpage.c
··· 200 200 201 201 arch_initcall(hugetlbpage_init); 202 202 203 - void __init gigantic_hugetlb_cma_reserve(void) 203 + unsigned int __init arch_hugetlb_cma_order(void) 204 204 { 205 - unsigned long order = 0; 206 - 207 205 if (radix_enabled()) 208 - order = PUD_SHIFT - PAGE_SHIFT; 206 + return PUD_SHIFT - PAGE_SHIFT; 209 207 else if (!firmware_has_feature(FW_FEATURE_LPAR) && mmu_psize_defs[MMU_PAGE_16G].shift) 210 208 /* 211 209 * For pseries we do use ibm,expected#pages for reserving 16G pages. 212 210 */ 213 - order = mmu_psize_to_shift(MMU_PAGE_16G) - PAGE_SHIFT; 211 + return mmu_psize_to_shift(MMU_PAGE_16G) - PAGE_SHIFT; 214 212 215 - if (order) 216 - hugetlb_cma_reserve(order); 213 + return 0; 217 214 }
+8
arch/riscv/mm/hugetlbpage.c
··· 447 447 } 448 448 arch_initcall(gigantic_pages_init); 449 449 #endif 450 + 451 + unsigned int __init arch_hugetlb_cma_order(void) 452 + { 453 + if (IS_ENABLED(CONFIG_64BIT)) 454 + return PUD_SHIFT - PAGE_SHIFT; 455 + 456 + return 0; 457 + }
-2
arch/riscv/mm/init.c
··· 311 311 memblock_reserve(dtb_early_pa, fdt_totalsize(dtb_early_va)); 312 312 313 313 dma_contiguous_reserve(dma32_phys_limit); 314 - if (IS_ENABLED(CONFIG_64BIT)) 315 - hugetlb_cma_reserve(PUD_SHIFT - PAGE_SHIFT); 316 314 } 317 315 318 316 #ifdef CONFIG_RELOCATABLE
-2
arch/s390/kernel/setup.c
··· 963 963 setup_uv(); 964 964 dma_contiguous_reserve(ident_map_size); 965 965 vmcp_cma_reserve(); 966 - if (cpu_has_edat2()) 967 - hugetlb_cma_reserve(PUD_SHIFT - PAGE_SHIFT); 968 966 969 967 reserve_crashkernel(); 970 968 #ifdef CONFIG_CRASH_DUMP
+8
arch/s390/mm/hugetlbpage.c
··· 255 255 else 256 256 return false; 257 257 } 258 + 259 + unsigned int __init arch_hugetlb_cma_order(void) 260 + { 261 + if (cpu_has_edat2()) 262 + return PUD_SHIFT - PAGE_SHIFT; 263 + 264 + return 0; 265 + }
-4
arch/x86/kernel/setup.c
··· 1189 1189 initmem_init(); 1190 1190 dma_contiguous_reserve(max_pfn_mapped << PAGE_SHIFT); 1191 1191 1192 - if (boot_cpu_has(X86_FEATURE_GBPAGES)) { 1193 - hugetlb_cma_reserve(PUD_SHIFT - PAGE_SHIFT); 1194 - } 1195 - 1196 1192 /* 1197 1193 * Reserve memory for crash kernel after SRAT is parsed so that it 1198 1194 * won't consume hotpluggable memory.
+8
arch/x86/mm/hugetlbpage.c
··· 42 42 arch_initcall(gigantic_pages_init); 43 43 #endif 44 44 #endif 45 + 46 + unsigned int __init arch_hugetlb_cma_order(void) 47 + { 48 + if (boot_cpu_has(X86_FEATURE_GBPAGES)) 49 + return PUD_SHIFT - PAGE_SHIFT; 50 + 51 + return 0; 52 + }
+4 -2
include/linux/hugetlb.h
··· 281 281 void hugetlb_split(struct vm_area_struct *vma, unsigned long addr); 282 282 int hugetlb_vma_lock_alloc(struct vm_area_struct *vma); 283 283 284 + unsigned int arch_hugetlb_cma_order(void); 285 + 284 286 #else /* !CONFIG_HUGETLB_PAGE */ 285 287 286 288 static inline void hugetlb_dup_vma_private(struct vm_area_struct *vma) ··· 1324 1322 } 1325 1323 1326 1324 #if defined(CONFIG_HUGETLB_PAGE) && defined(CONFIG_CMA) 1327 - extern void __init hugetlb_cma_reserve(int order); 1325 + extern void __init hugetlb_cma_reserve(void); 1328 1326 #else 1329 - static inline __init void hugetlb_cma_reserve(int order) 1327 + static inline __init void hugetlb_cma_reserve(void) 1330 1328 { 1331 1329 } 1332 1330 #endif
+14 -5
mm/hugetlb_cma.c
··· 134 134 135 135 early_param("hugetlb_cma_only", cmdline_parse_hugetlb_cma_only); 136 136 137 - void __init hugetlb_cma_reserve(int order) 137 + unsigned int __weak arch_hugetlb_cma_order(void) 138 138 { 139 - unsigned long size, reserved, per_node; 139 + return 0; 140 + } 141 + 142 + void __init hugetlb_cma_reserve(void) 143 + { 144 + unsigned long size, reserved, per_node, order; 140 145 bool node_specific_cma_alloc = false; 141 146 int nid; 147 + 148 + if (!hugetlb_cma_size) 149 + return; 150 + 151 + order = arch_hugetlb_cma_order(); 152 + if (!order) 153 + return; 142 154 143 155 /* 144 156 * HugeTLB CMA reservation is required for gigantic ··· 160 148 */ 161 149 VM_WARN_ON(order <= MAX_PAGE_ORDER); 162 150 cma_reserve_called = true; 163 - 164 - if (!hugetlb_cma_size) 165 - return; 166 151 167 152 hugetlb_bootmem_set_nodes(); 168 153
+1
mm/mm_init.c
··· 2677 2677 2678 2678 void __init mm_core_init_early(void) 2679 2679 { 2680 + hugetlb_cma_reserve(); 2680 2681 hugetlb_bootmem_alloc(); 2681 2682 2682 2683 free_area_init();