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.

riscv: kdump: use generic interface to simplify crashkernel 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>, and define CRASH_ALIGN,
CRASH_ADDR_LOW_MAX, CRASH_ADDR_HIGH_MAX and
DEFAULT_CRASH_KERNEL_LOW_SIZE 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/riscv/Kconfig.

The old reserve_crashkernel_low() and reserve_crashkernel() can be
removed.

[chenjiahao16@huawei.com: fix crashkernel reserving problem on RISC-V]
Link: https://lkml.kernel.org/r/20230925024333.730964-1-chenjiahao16@huawei.com
Link: https://lkml.kernel.org/r/20230914033142.676708-9-bhe@redhat.com
Signed-off-by: Baoquan He <bhe@redhat.com>
Signed-off-by: Chen Jiahao <chenjiahao16@huawei.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Chen Jiahao <chenjiahao16@huawei.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Baoquan He and committed by
Andrew Morton
39365395 fdc26823

+27 -143
+3
arch/riscv/Kconfig
··· 694 694 config ARCH_SUPPORTS_CRASH_DUMP 695 695 def_bool y 696 696 697 + config ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION 698 + def_bool CRASH_CORE 699 + 697 700 config COMPAT 698 701 bool "Kernel support for 32-bit U-mode" 699 702 default 64BIT
+11
arch/riscv/include/asm/crash_core.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + #ifndef _RISCV_CRASH_CORE_H 3 + #define _RISCV_CRASH_CORE_H 4 + 5 + #define CRASH_ALIGN PMD_SIZE 6 + 7 + #define CRASH_ADDR_LOW_MAX dma32_phys_limit 8 + #define CRASH_ADDR_HIGH_MAX memblock_end_of_DRAM() 9 + 10 + extern phys_addr_t memblock_end_of_DRAM(void); 11 + #endif
+2
arch/riscv/include/asm/processor.h
··· 116 116 __asm__ __volatile__ ("wfi"); 117 117 } 118 118 119 + extern phys_addr_t dma32_phys_limit; 120 + 119 121 struct device_node; 120 122 int riscv_of_processor_hartid(struct device_node *node, unsigned long *hartid); 121 123 int riscv_early_of_processor_hartid(struct device_node *node, unsigned long *hartid);
-13
arch/riscv/kernel/setup.c
··· 173 173 if (ret < 0) 174 174 goto error; 175 175 176 - #ifdef CONFIG_KEXEC_CORE 177 - if (crashk_res.start != crashk_res.end) { 178 - ret = add_resource(&iomem_resource, &crashk_res); 179 - if (ret < 0) 180 - goto error; 181 - } 182 - if (crashk_low_res.start != crashk_low_res.end) { 183 - ret = add_resource(&iomem_resource, &crashk_low_res); 184 - if (ret < 0) 185 - goto error; 186 - } 187 - #endif 188 - 189 176 #ifdef CONFIG_CRASH_DUMP 190 177 if (elfcorehdr_size > 0) { 191 178 elfcorehdr_res.start = elfcorehdr_addr;
+11 -130
arch/riscv/mm/init.c
··· 65 65 void *_dtb_early_va __initdata; 66 66 uintptr_t _dtb_early_pa __initdata; 67 67 68 - static phys_addr_t dma32_phys_limit __initdata; 68 + phys_addr_t dma32_phys_limit __initdata; 69 69 70 70 static void __init zone_sizes_init(void) 71 71 { ··· 1333 1333 } 1334 1334 #endif /* CONFIG_MMU */ 1335 1335 1336 - /* Reserve 128M low memory by default for swiotlb buffer */ 1337 - #define DEFAULT_CRASH_KERNEL_LOW_SIZE (128UL << 20) 1338 - 1339 - static int __init reserve_crashkernel_low(unsigned long long low_size) 1340 - { 1341 - unsigned long long low_base; 1342 - 1343 - low_base = memblock_phys_alloc_range(low_size, PMD_SIZE, 0, dma32_phys_limit); 1344 - if (!low_base) { 1345 - pr_err("cannot allocate crashkernel low memory (size:0x%llx).\n", low_size); 1346 - return -ENOMEM; 1347 - } 1348 - 1349 - pr_info("crashkernel low memory reserved: 0x%016llx - 0x%016llx (%lld MB)\n", 1350 - low_base, low_base + low_size, low_size >> 20); 1351 - 1352 - crashk_low_res.start = low_base; 1353 - crashk_low_res.end = low_base + low_size - 1; 1354 - 1355 - return 0; 1356 - } 1357 - 1358 1336 /* 1359 1337 * reserve_crashkernel() - reserves memory for crash kernel 1360 1338 * ··· 1340 1362 * line parameter. The memory reserved is used by dump capture kernel when 1341 1363 * primary kernel is crashing. 1342 1364 */ 1343 - static void __init reserve_crashkernel(void) 1365 + static void __init arch_reserve_crashkernel(void) 1344 1366 { 1345 - unsigned long long crash_base = 0; 1346 - unsigned long long crash_size = 0; 1347 - unsigned long long crash_low_size = 0; 1348 - unsigned long search_start = memblock_start_of_DRAM(); 1349 - unsigned long search_end = (unsigned long)dma32_phys_limit; 1367 + unsigned long long low_size = 0; 1368 + unsigned long long crash_base, crash_size; 1350 1369 char *cmdline = boot_command_line; 1351 - bool fixed_base = false; 1352 1370 bool high = false; 1353 - 1354 - int ret = 0; 1371 + int ret; 1355 1372 1356 1373 if (!IS_ENABLED(CONFIG_KEXEC_CORE)) 1357 1374 return; 1358 - /* 1359 - * Don't reserve a region for a crash kernel on a crash kernel 1360 - * since it doesn't make much sense and we have limited memory 1361 - * resources. 1362 - */ 1363 - if (is_kdump_kernel()) { 1364 - pr_info("crashkernel: ignoring reservation request\n"); 1365 - return; 1366 - } 1367 1375 1368 1376 ret = parse_crashkernel(cmdline, memblock_phys_mem_size(), 1369 - &crash_size, &crash_base, NULL, NULL); 1370 - if (ret == -ENOENT) { 1371 - /* Fallback to crashkernel=X,[high,low] */ 1372 - ret = parse_crashkernel_high(cmdline, 0, &crash_size, &crash_base); 1373 - if (ret || !crash_size) 1374 - return; 1375 - 1376 - /* 1377 - * crashkernel=Y,low is valid only when crashkernel=X,high 1378 - * is passed. 1379 - */ 1380 - ret = parse_crashkernel_low(cmdline, 0, &crash_low_size, &crash_base); 1381 - if (ret == -ENOENT) 1382 - crash_low_size = DEFAULT_CRASH_KERNEL_LOW_SIZE; 1383 - else if (ret) 1384 - return; 1385 - 1386 - search_start = (unsigned long)dma32_phys_limit; 1387 - search_end = memblock_end_of_DRAM(); 1388 - high = true; 1389 - } else if (ret || !crash_size) { 1390 - /* Invalid argument value specified */ 1377 + &crash_size, &crash_base, 1378 + &low_size, &high); 1379 + if (ret) 1391 1380 return; 1392 - } 1393 1381 1394 - crash_size = PAGE_ALIGN(crash_size); 1395 - 1396 - if (crash_base) { 1397 - fixed_base = true; 1398 - search_start = crash_base; 1399 - search_end = crash_base + crash_size; 1400 - } 1401 - 1402 - /* 1403 - * Current riscv boot protocol requires 2MB alignment for 1404 - * RV64 and 4MB alignment for RV32 (hugepage size) 1405 - * 1406 - * Try to alloc from 32bit addressible physical memory so that 1407 - * swiotlb can work on the crash kernel. 1408 - */ 1409 - crash_base = memblock_phys_alloc_range(crash_size, PMD_SIZE, 1410 - search_start, search_end); 1411 - if (crash_base == 0) { 1412 - /* 1413 - * For crashkernel=size[KMG]@offset[KMG], print out failure 1414 - * message if can't reserve the specified region. 1415 - */ 1416 - if (fixed_base) { 1417 - pr_warn("crashkernel: allocating failed with given size@offset\n"); 1418 - return; 1419 - } 1420 - 1421 - if (high) { 1422 - /* 1423 - * For crashkernel=size[KMG],high, if the first attempt was 1424 - * for high memory, fall back to low memory. 1425 - */ 1426 - search_start = memblock_start_of_DRAM(); 1427 - search_end = (unsigned long)dma32_phys_limit; 1428 - } else { 1429 - /* 1430 - * For crashkernel=size[KMG], if the first attempt was for 1431 - * low memory, fall back to high memory, the minimum required 1432 - * low memory will be reserved later. 1433 - */ 1434 - search_start = (unsigned long)dma32_phys_limit; 1435 - search_end = memblock_end_of_DRAM(); 1436 - crash_low_size = DEFAULT_CRASH_KERNEL_LOW_SIZE; 1437 - } 1438 - 1439 - crash_base = memblock_phys_alloc_range(crash_size, PMD_SIZE, 1440 - search_start, search_end); 1441 - if (crash_base == 0) { 1442 - pr_warn("crashkernel: couldn't allocate %lldKB\n", 1443 - crash_size >> 10); 1444 - return; 1445 - } 1446 - } 1447 - 1448 - if ((crash_base >= dma32_phys_limit) && crash_low_size && 1449 - reserve_crashkernel_low(crash_low_size)) { 1450 - memblock_phys_free(crash_base, crash_size); 1451 - return; 1452 - } 1453 - 1454 - pr_info("crashkernel: reserved 0x%016llx - 0x%016llx (%lld MB)\n", 1455 - crash_base, crash_base + crash_size, crash_size >> 20); 1456 - 1457 - crashk_res.start = crash_base; 1458 - crashk_res.end = crash_base + crash_size - 1; 1382 + reserve_crashkernel_generic(cmdline, crash_size, crash_base, 1383 + low_size, high); 1459 1384 } 1460 1385 1461 1386 void __init paging_init(void) ··· 1376 1495 arch_numa_init(); 1377 1496 sparse_init(); 1378 1497 zone_sizes_init(); 1379 - reserve_crashkernel(); 1498 + arch_reserve_crashkernel(); 1380 1499 memblock_dump_all(); 1381 1500 } 1382 1501