Skip to content

Commit 35c18f2

Browse files
jiribohacakpm00
authored andcommitted
Add a new optional ",cma" suffix to the crashkernel= command line option
Patch series "kdump: crashkernel reservation from CMA", v5. This series implements a way to reserve additional crash kernel memory using CMA. Currently, all the memory for the crash kernel is not usable by the 1st (production) kernel. It is also unmapped so that it can't be corrupted by the fault that will eventually trigger the crash. This makes sense for the memory actually used by the kexec-loaded crash kernel image and initrd and the data prepared during the load (vmcoreinfo, ...). However, the reserved space needs to be much larger than that to provide enough run-time memory for the crash kernel and the kdump userspace. Estimating the amount of memory to reserve is difficult. Being too careful makes kdump likely to end in OOM, being too generous takes even more memory from the production system. Also, the reservation only allows reserving a single contiguous block (or two with the "low" suffix). I've seen systems where this fails because the physical memory is fragmented. By reserving additional crashkernel memory from CMA, the main crashkernel reservation can be just large enough to fit the kernel and initrd image, minimizing the memory taken away from the production system. Most of the run-time memory for the crash kernel will be memory previously available to userspace in the production system. As this memory is no longer wasted, the reservation can be done with a generous margin, making kdump more reliable. Kernel memory that we need to preserve for dumping is normally not allocated from CMA, unless it is explicitly allocated as movable. Currently this is only the case for memory ballooning and zswap. Such movable memory will be missing from the vmcore. User data is typically not dumped by makedumpfile. When dumping of user data is intended this new CMA reservation cannot be used. There are five patches in this series: The first adds a new ",cma" suffix to the recenly introduced generic crashkernel parsing code. parse_crashkernel() takes one more argument to store the cma reservation size. The second patch implements reserve_crashkernel_cma() which performs the reservation. If the requested size is not available in a single range, multiple smaller ranges will be reserved. The third patch updates Documentation/, explicitly mentioning the potential DMA corruption of the CMA-reserved memory. The fourth patch adds a short delay before booting the kdump kernel, allowing pending DMA transfers to finish. The fifth patch enables the functionality for x86 as a proof of concept. There are just three things every arch needs to do: - call reserve_crashkernel_cma() - include the CMA-reserved ranges in the physical memory map - exclude the CMA-reserved ranges from the memory available through /proc/vmcore by excluding them from the vmcoreinfo PT_LOAD ranges. Adding other architectures is easy and I can do that as soon as this series is merged. With this series applied, specifying crashkernel=100M craskhernel=1G,cma on the command line will make a standard crashkernel reservation of 100M, where kexec will load the kernel and initrd. An additional 1G will be reserved from CMA, still usable by the production system. The crash kernel will have 1.1G memory available. The 100M can be reliably predicted based on the size of the kernel and initrd. The new cma suffix is completely optional. When no crashkernel=size,cma is specified, everything works as before. This patch (of 5): Add a new cma_size parameter to parse_crashkernel(). When not NULL, call __parse_crashkernel to parse the CMA reservation size from "crashkernel=size,cma" and store it in cma_size. Set cma_size to NULL in all calls to parse_crashkernel(). Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Jiri Bohac <[email protected]> Cc: Baoquan He <[email protected]> Cc: Dave Young <[email protected]> Cc: Donald Dutile <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Philipp Rudo <[email protected]> Cc: Pingfan Liu <[email protected]> Cc: Tao Liu <[email protected]> Cc: Vivek Goyal <[email protected]> Cc: David Hildenbrand <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 22c2ed6 commit 35c18f2

File tree

13 files changed

+27
-14
lines changed

13 files changed

+27
-14
lines changed

arch/arm/kernel/setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ static void __init reserve_crashkernel(void)
10041004
total_mem = get_total_mem();
10051005
ret = parse_crashkernel(boot_command_line, total_mem,
10061006
&crash_size, &crash_base,
1007-
NULL, NULL);
1007+
NULL, NULL, NULL);
10081008
/* invalid value specified or crashkernel=0 */
10091009
if (ret || !crash_size)
10101010
return;

arch/arm64/mm/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static void __init arch_reserve_crashkernel(void)
106106

107107
ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(),
108108
&crash_size, &crash_base,
109-
&low_size, &high);
109+
&low_size, NULL, &high);
110110
if (ret)
111111
return;
112112

arch/loongarch/kernel/setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ static void __init arch_reserve_crashkernel(void)
265265
return;
266266

267267
ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(),
268-
&crash_size, &crash_base, &low_size, &high);
268+
&crash_size, &crash_base, &low_size, NULL, &high);
269269
if (ret)
270270
return;
271271

arch/mips/kernel/setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ static void __init mips_parse_crashkernel(void)
458458
total_mem = memblock_phys_mem_size();
459459
ret = parse_crashkernel(boot_command_line, total_mem,
460460
&crash_size, &crash_base,
461-
NULL, NULL);
461+
NULL, NULL, NULL);
462462
if (ret != 0 || crash_size <= 0)
463463
return;
464464

arch/powerpc/kernel/fadump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ static __init u64 fadump_calculate_reserve_size(void)
333333
* memory at a predefined offset.
334334
*/
335335
ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(),
336-
&size, &base, NULL, NULL);
336+
&size, &base, NULL, NULL, NULL);
337337
if (ret == 0 && size > 0) {
338338
unsigned long max_size;
339339

arch/powerpc/kexec/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ void __init arch_reserve_crashkernel(void)
110110

111111
/* use common parsing */
112112
ret = parse_crashkernel(boot_command_line, total_mem_sz, &crash_size,
113-
&crash_base, NULL, NULL);
113+
&crash_base, NULL, NULL, NULL);
114114

115115
if (ret)
116116
return;

arch/powerpc/mm/nohash/kaslr_booke.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static void __init get_crash_kernel(void *fdt, unsigned long size)
178178
int ret;
179179

180180
ret = parse_crashkernel(boot_command_line, size, &crash_size,
181-
&crash_base, NULL, NULL);
181+
&crash_base, NULL, NULL, NULL);
182182
if (ret != 0 || crash_size == 0)
183183
return;
184184
if (crash_base == 0)

arch/riscv/mm/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,7 @@ static void __init arch_reserve_crashkernel(void)
14081408

14091409
ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(),
14101410
&crash_size, &crash_base,
1411-
&low_size, &high);
1411+
&low_size, NULL, &high);
14121412
if (ret)
14131413
return;
14141414

arch/s390/kernel/setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ static void __init reserve_crashkernel(void)
605605
int rc;
606606

607607
rc = parse_crashkernel(boot_command_line, ident_map_size,
608-
&crash_size, &crash_base, NULL, NULL);
608+
&crash_size, &crash_base, NULL, NULL, NULL);
609609

610610
crash_base = ALIGN(crash_base, KEXEC_CRASH_MEM_ALIGN);
611611
crash_size = ALIGN(crash_size, KEXEC_CRASH_MEM_ALIGN);

arch/sh/kernel/machine_kexec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ void __init reserve_crashkernel(void)
146146
return;
147147

148148
ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(),
149-
&crash_size, &crash_base, NULL, NULL);
149+
&crash_size, &crash_base, NULL, NULL, NULL);
150150
if (ret == 0 && crash_size > 0) {
151151
crashk_res.start = crash_base;
152152
crashk_res.end = crash_base + crash_size - 1;

0 commit comments

Comments
 (0)