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.

powerpc/crash: use generic crashkernel reservation

Commit 0ab97169aa05 ("crash_core: add generic function to do reservation")
added a generic function to reserve crashkernel memory. So let's use the
same function on powerpc and remove the architecture-specific code that
essentially does the same thing.

The generic crashkernel reservation also provides a way to split the
crashkernel reservation into high and low memory reservations, which can
be enabled for powerpc in the future.

Along with moving to the generic crashkernel reservation, the code related
to finding the base address for the crashkernel has been separated into
its own function name get_crash_base() for better readability and
maintainability.

Link: https://lkml.kernel.org/r/20250131113830.925179-8-sourabhjain@linux.ibm.com
Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com>
Reviewed-by: Mahesh Salgaonkar <mahesh@linux.ibm.com>
Acked-by: Hari Bathini <hbathini@linux.ibm.com>
Cc: Baoquan he <bhe@redhat.com>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Sourabh Jain and committed by
Andrew Morton
e3185ee4 bce074bd

+54 -55
+3
arch/powerpc/Kconfig
··· 721 721 def_bool y 722 722 depends on PPC64 723 723 724 + config ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION 725 + def_bool CRASH_RESERVE 726 + 724 727 config FA_DUMP 725 728 bool "Firmware-assisted dump" 726 729 depends on CRASH_DUMP && PPC64 && (PPC_RTAS || PPC_POWERNV)
+8
arch/powerpc/include/asm/crash_reserve.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _ASM_POWERPC_CRASH_RESERVE_H 3 + #define _ASM_POWERPC_CRASH_RESERVE_H 4 + 5 + /* crash kernel regions are Page size agliged */ 6 + #define CRASH_ALIGN PAGE_SIZE 7 + 8 + #endif /* _ASM_POWERPC_CRASH_RESERVE_H */
+2 -2
arch/powerpc/include/asm/kexec.h
··· 114 114 115 115 #ifdef CONFIG_CRASH_RESERVE 116 116 int __init overlaps_crashkernel(unsigned long start, unsigned long size); 117 - extern void reserve_crashkernel(void); 117 + extern void arch_reserve_crashkernel(void); 118 118 #else 119 - static inline void reserve_crashkernel(void) {} 119 + static inline void arch_reserve_crashkernel(void) {} 120 120 static inline int overlaps_crashkernel(unsigned long start, unsigned long size) { return 0; } 121 121 #endif 122 122
+1 -1
arch/powerpc/kernel/prom.c
··· 860 860 */ 861 861 if (fadump_reserve_mem() == 0) 862 862 #endif 863 - reserve_crashkernel(); 863 + arch_reserve_crashkernel(); 864 864 early_reserve_mem(); 865 865 866 866 if (memory_limit > memblock_phys_mem_size())
+40 -52
arch/powerpc/kexec/core.c
··· 58 58 } 59 59 60 60 #ifdef CONFIG_CRASH_RESERVE 61 - void __init reserve_crashkernel(void) 61 + 62 + static unsigned long long __init get_crash_base(unsigned long long crash_base) 62 63 { 63 - unsigned long long crash_size, crash_base, total_mem_sz; 64 - int ret; 65 - 66 - total_mem_sz = memory_limit ? memory_limit : memblock_phys_mem_size(); 67 - /* use common parsing */ 68 - ret = parse_crashkernel(boot_command_line, total_mem_sz, 69 - &crash_size, &crash_base, NULL, NULL); 70 - if (ret == 0 && crash_size > 0) { 71 - crashk_res.start = crash_base; 72 - crashk_res.end = crash_base + crash_size - 1; 73 - } 74 - 75 - if (crashk_res.end == crashk_res.start) { 76 - crashk_res.start = crashk_res.end = 0; 77 - return; 78 - } 79 - 80 - /* We might have got these values via the command line or the 81 - * device tree, either way sanitise them now. */ 82 - 83 - crash_size = resource_size(&crashk_res); 84 64 85 65 #ifndef CONFIG_NONSTATIC_KERNEL 86 - if (crashk_res.start != KDUMP_KERNELBASE) 66 + if (crash_base != KDUMP_KERNELBASE) 87 67 printk("Crash kernel location must be 0x%x\n", 88 68 KDUMP_KERNELBASE); 89 69 90 - crashk_res.start = KDUMP_KERNELBASE; 70 + return KDUMP_KERNELBASE; 91 71 #else 92 - if (!crashk_res.start) { 72 + unsigned long long crash_base_align; 73 + 74 + if (!crash_base) { 93 75 #ifdef CONFIG_PPC64 94 76 /* 95 77 * On the LPAR platform place the crash kernel to mid of ··· 83 101 * kernel starts at 128MB offset on other platforms. 84 102 */ 85 103 if (firmware_has_feature(FW_FEATURE_LPAR)) 86 - crashk_res.start = min_t(u64, ppc64_rma_size / 2, SZ_512M); 104 + crash_base = min_t(u64, ppc64_rma_size / 2, SZ_512M); 87 105 else 88 - crashk_res.start = min_t(u64, ppc64_rma_size / 2, SZ_128M); 106 + crash_base = min_t(u64, ppc64_rma_size / 2, SZ_128M); 89 107 #else 90 - crashk_res.start = KDUMP_KERNELBASE; 108 + crash_base = KDUMP_KERNELBASE; 91 109 #endif 92 110 } 93 111 94 - crash_base = PAGE_ALIGN(crashk_res.start); 95 - if (crash_base != crashk_res.start) { 96 - printk("Crash kernel base must be aligned to 0x%lx\n", 97 - PAGE_SIZE); 98 - crashk_res.start = crash_base; 99 - } 112 + crash_base_align = PAGE_ALIGN(crash_base); 113 + if (crash_base != crash_base_align) 114 + pr_warn("Crash kernel base must be aligned to 0x%lx\n", PAGE_SIZE); 100 115 116 + return crash_base_align; 101 117 #endif 102 - crash_size = PAGE_ALIGN(crash_size); 103 - crashk_res.end = crashk_res.start + crash_size - 1; 118 + } 119 + 120 + void __init arch_reserve_crashkernel(void) 121 + { 122 + unsigned long long crash_size, crash_base, crash_end; 123 + unsigned long long kernel_start, kernel_size; 124 + unsigned long long total_mem_sz; 125 + int ret; 126 + 127 + total_mem_sz = memory_limit ? memory_limit : memblock_phys_mem_size(); 128 + 129 + /* use common parsing */ 130 + ret = parse_crashkernel(boot_command_line, total_mem_sz, &crash_size, 131 + &crash_base, NULL, NULL); 132 + 133 + if (ret) 134 + return; 135 + 136 + crash_base = get_crash_base(crash_base); 137 + crash_end = crash_base + crash_size - 1; 138 + 139 + kernel_start = __pa(_stext); 140 + kernel_size = _end - _stext; 104 141 105 142 /* The crash region must not overlap the current kernel */ 106 - if (overlaps_crashkernel(__pa(_stext), _end - _stext)) { 107 - printk(KERN_WARNING 108 - "Crash kernel can not overlap current kernel\n"); 109 - crashk_res.start = crashk_res.end = 0; 143 + if ((kernel_start + kernel_size > crash_base) && (kernel_start <= crash_end)) { 144 + pr_warn("Crash kernel can not overlap current kernel\n"); 110 145 return; 111 146 } 112 147 113 - printk(KERN_INFO "Reserving %ldMB of memory at %ldMB " 114 - "for crashkernel (System RAM: %ldMB)\n", 115 - (unsigned long)(crash_size >> 20), 116 - (unsigned long)(crashk_res.start >> 20), 117 - (unsigned long)(total_mem_sz >> 20)); 118 - 119 - if (!memblock_is_region_memory(crashk_res.start, crash_size) || 120 - memblock_reserve(crashk_res.start, crash_size)) { 121 - pr_err("Failed to reserve memory for crashkernel!\n"); 122 - crashk_res.start = crashk_res.end = 0; 123 - return; 124 - } 148 + reserve_crashkernel_generic(crash_size, crash_base, 0, false); 125 149 } 126 150 127 151 int __init overlaps_crashkernel(unsigned long start, unsigned long size)