Skip to content

Commit 78de91b

Browse files
tangyoulingchenhuacai
authored andcommitted
LoongArch: Use generic interface to support crashkernel=X,[high,low]
LoongArch already supports two crashkernel regions in kexec-tools, so we can directly use the common interface to support crashkernel=X,[high,low] after commit 0ab9716 ("crash_core: add generic function to do reservation"). With the help of newly changed function parse_crashkernel() and generic reserve_crashkernel_generic(), crashkernel reservation can be simplified by steps: 1) Add a new header file <asm/crash_core.h>, then define CRASH_ALIGN, CRASH_ADDR_LOW_MAX and CRASH_ADDR_HIGH_MAX and in <asm/crash_core.h>; 2) Add arch_reserve_crashkernel() to call parse_crashkernel() and reserve_crashkernel_generic(); 3) Add ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION Kconfig in arch/loongarch/Kconfig. One can reserve the crash kernel from high memory above DMA zone range by explicitly passing "crashkernel=X,high"; or reserve a memory range below 4G with "crashkernel=X,low". Besides, there are few rules need to take notice: 1) "crashkernel=X,[high,low]" will be ignored if "crashkernel=size" is specified. 2) "crashkernel=X,low" is valid only when "crashkernel=X,high" is passed and there is enough memory to be allocated under 4G. 3) When allocating crashkernel above 4G and no "crashkernel=X,low" is specified, a 128M low memory will be allocated automatically for swiotlb bounce buffer. See Documentation/admin-guide/kernel-parameters.txt for more information. Following test cases have been performed as expected: 1) crashkernel=256M //low=256M 2) crashkernel=1G //low=1G 3) crashkernel=4G //high=4G, low=128M(default) 4) crashkernel=4G crashkernel=256M,high //high=4G, low=128M(default), high is ignored 5) crashkernel=4G crashkernel=256M,low //high=4G, low=128M(default), low is ignored 6) crashkernel=4G,high //high=4G, low=128M(default) 7) crashkernel=256M,low //low=0M, invalid 8) crashkernel=4G,high crashkernel=256M,low //high=4G, low=256M 9) crashkernel=4G,high crashkernel=4G,low //high=0M, low=0M, invalid 10) crashkernel=512M@2560M //low=512M 11) crashkernel=1G,high crashkernel=0M,low //high=1G, low=0M Recommended usage in general: 1) In the case of small memory: crashkernel=512M 2) In the case of large memory: crashkernel=1024M,high crashkernel=128M,low Signed-off-by: Youling Tang <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent c239665 commit 78de91b

File tree

4 files changed

+38
-45
lines changed

4 files changed

+38
-45
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -877,9 +877,9 @@
877877
memory region [offset, offset + size] for that kernel
878878
image. If '@offset' is omitted, then a suitable offset
879879
is selected automatically.
880-
[KNL, X86-64, ARM64, RISCV] Select a region under 4G first, and
881-
fall back to reserve region above 4G when '@offset'
882-
hasn't been specified.
880+
[KNL, X86-64, ARM64, RISCV, LoongArch] Select a region
881+
under 4G first, and fall back to reserve region above
882+
4G when '@offset' hasn't been specified.
883883
See Documentation/admin-guide/kdump/kdump.rst for further details.
884884

885885
crashkernel=range1:size1[,range2:size2,...][@offset]
@@ -890,25 +890,27 @@
890890
Documentation/admin-guide/kdump/kdump.rst for an example.
891891

892892
crashkernel=size[KMG],high
893-
[KNL, X86-64, ARM64, RISCV] range could be above 4G.
893+
[KNL, X86-64, ARM64, RISCV, LoongArch] range could be
894+
above 4G.
894895
Allow kernel to allocate physical memory region from top,
895896
so could be above 4G if system have more than 4G ram
896897
installed. Otherwise memory region will be allocated
897898
below 4G, if available.
898899
It will be ignored if crashkernel=X is specified.
899900
crashkernel=size[KMG],low
900-
[KNL, X86-64, ARM64, RISCV] range under 4G. When crashkernel=X,high
901-
is passed, kernel could allocate physical memory region
902-
above 4G, that cause second kernel crash on system
903-
that require some amount of low memory, e.g. swiotlb
904-
requires at least 64M+32K low memory, also enough extra
905-
low memory is needed to make sure DMA buffers for 32-bit
906-
devices won't run out. Kernel would try to allocate
901+
[KNL, X86-64, ARM64, RISCV, LoongArch] range under 4G.
902+
When crashkernel=X,high is passed, kernel could allocate
903+
physical memory region above 4G, that cause second kernel
904+
crash on system that require some amount of low memory,
905+
e.g. swiotlb requires at least 64M+32K low memory, also
906+
enough extra low memory is needed to make sure DMA buffers
907+
for 32-bit devices won't run out. Kernel would try to allocate
907908
default size of memory below 4G automatically. The default
908909
size is platform dependent.
909910
--> x86: max(swiotlb_size_or_default() + 8MiB, 256MiB)
910911
--> arm64: 128MiB
911912
--> riscv: 128MiB
913+
--> loongarch: 128MiB
912914
This one lets the user specify own low range under 4G
913915
for second kernel instead.
914916
0: to disable low allocation.

arch/loongarch/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,9 @@ config ARCH_SELECTS_CRASH_DUMP
594594
depends on CRASH_DUMP
595595
select RELOCATABLE
596596

597+
config ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION
598+
def_bool CRASH_CORE
599+
597600
config RELOCATABLE
598601
bool "Relocatable kernel"
599602
help
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
#ifndef _LOONGARCH_CRASH_CORE_H
3+
#define _LOONGARCH_CRASH_CORE_H
4+
5+
#define CRASH_ALIGN SZ_2M
6+
7+
#define CRASH_ADDR_LOW_MAX SZ_4G
8+
#define CRASH_ADDR_HIGH_MAX memblock_end_of_DRAM()
9+
10+
extern phys_addr_t memblock_end_of_DRAM(void);
11+
12+
#endif

arch/loongarch/kernel/setup.c

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -252,38 +252,23 @@ static void __init arch_reserve_vmcore(void)
252252
#endif
253253
}
254254

255-
/* 2MB alignment for crash kernel regions */
256-
#define CRASH_ALIGN SZ_2M
257-
#define CRASH_ADDR_MAX SZ_4G
258-
259-
static void __init arch_parse_crashkernel(void)
255+
static void __init arch_reserve_crashkernel(void)
260256
{
261-
#ifdef CONFIG_KEXEC
262257
int ret;
263-
unsigned long long total_mem;
258+
unsigned long long low_size = 0;
264259
unsigned long long crash_base, crash_size;
260+
char *cmdline = boot_command_line;
261+
bool high = false;
265262

266-
total_mem = memblock_phys_mem_size();
267-
ret = parse_crashkernel(boot_command_line, total_mem,
268-
&crash_size, &crash_base,
269-
NULL, NULL);
270-
if (ret < 0 || crash_size <= 0)
263+
if (!IS_ENABLED(CONFIG_KEXEC_CORE))
271264
return;
272265

273-
if (crash_base <= 0) {
274-
crash_base = memblock_phys_alloc_range(crash_size, CRASH_ALIGN, CRASH_ALIGN, CRASH_ADDR_MAX);
275-
if (!crash_base) {
276-
pr_warn("crashkernel reservation failed - No suitable area found.\n");
277-
return;
278-
}
279-
} else if (!memblock_phys_alloc_range(crash_size, CRASH_ALIGN, crash_base, crash_base + crash_size)) {
280-
pr_warn("Invalid memory region reserved for crash kernel\n");
266+
ret = parse_crashkernel(cmdline, memblock_phys_mem_size(),
267+
&crash_size, &crash_base, &low_size, &high);
268+
if (ret)
281269
return;
282-
}
283270

284-
crashk_res.start = crash_base;
285-
crashk_res.end = crash_base + crash_size - 1;
286-
#endif
271+
reserve_crashkernel_generic(cmdline, crash_size, crash_base, low_size, high);
287272
}
288273

289274
static void __init fdt_setup(void)
@@ -363,7 +348,7 @@ static void __init bootcmdline_init(char **cmdline_p)
363348
void __init platform_init(void)
364349
{
365350
arch_reserve_vmcore();
366-
arch_parse_crashkernel();
351+
arch_reserve_crashkernel();
367352

368353
#ifdef CONFIG_ACPI_TABLE_UPGRADE
369354
acpi_table_upgrade();
@@ -473,15 +458,6 @@ static void __init resource_init(void)
473458
request_resource(res, &data_resource);
474459
request_resource(res, &bss_resource);
475460
}
476-
477-
#ifdef CONFIG_KEXEC
478-
if (crashk_res.start < crashk_res.end) {
479-
insert_resource(&iomem_resource, &crashk_res);
480-
pr_info("Reserving %ldMB of memory at %ldMB for crashkernel\n",
481-
(unsigned long)((crashk_res.end - crashk_res.start + 1) >> 20),
482-
(unsigned long)(crashk_res.start >> 20));
483-
}
484-
#endif
485461
}
486462

487463
static int __init add_legacy_isa_io(struct fwnode_handle *fwnode,

0 commit comments

Comments
 (0)