mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-16 00:34:20 +08:00
4e62d1d865
This patch adds support for kdump. In kdump case the normal kernel will reserve a region for the crash kernel and jump there on panic. Arch-specific functions are added to allow for implementing a crash dump file interface, /proc/vmcore, which can be viewed as a ELF file. A user-space tool, such as kexec-tools, is responsible for allocating a separate region for the core's ELF header within the crash kdump kernel memory and filling it in when executing kexec_load(). Then, its location will be advertised to the crash dump kernel via a command line argument "elfcorehdr=", and the crash dump kernel will preserve this region for later use with arch_reserve_vmcore() at boot time. At the same time, the crash kdump kernel is also limited within the "crashkernel" area via a command line argument "mem=", so as not to destroy the original kernel dump data. In the crash dump kernel environment, /proc/vmcore is used to access the primary kernel's memory with copy_oldmem_page(). I tested kdump on LoongArch machines (Loongson-3A5000) and it works as expected (suggested crashkernel parameter is "crashkernel=512M@2560M"), you may test it by triggering a crash through /proc/sysrq-trigger: $ sudo kexec -p /boot/vmlinux-kdump --reuse-cmdline --append="nr_cpus=1" # echo c > /proc/sysrq-trigger Signed-off-by: Youling Tang <tangyouling@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
62 lines
1.5 KiB
C
62 lines
1.5 KiB
C
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
/*
|
|
* Copyright (C) 2020-2022 Loongson Technology Corporation Limited
|
|
*/
|
|
#include <linux/efi.h>
|
|
#include <linux/initrd.h>
|
|
#include <linux/memblock.h>
|
|
|
|
#include <asm/bootinfo.h>
|
|
#include <asm/loongson.h>
|
|
#include <asm/sections.h>
|
|
|
|
void __init memblock_init(void)
|
|
{
|
|
u32 mem_type;
|
|
u64 mem_start, mem_end, mem_size;
|
|
efi_memory_desc_t *md;
|
|
|
|
/* Parse memory information */
|
|
for_each_efi_memory_desc(md) {
|
|
mem_type = md->type;
|
|
mem_start = md->phys_addr;
|
|
mem_size = md->num_pages << EFI_PAGE_SHIFT;
|
|
mem_end = mem_start + mem_size;
|
|
|
|
switch (mem_type) {
|
|
case EFI_LOADER_CODE:
|
|
case EFI_LOADER_DATA:
|
|
case EFI_BOOT_SERVICES_CODE:
|
|
case EFI_BOOT_SERVICES_DATA:
|
|
case EFI_PERSISTENT_MEMORY:
|
|
case EFI_CONVENTIONAL_MEMORY:
|
|
memblock_add(mem_start, mem_size);
|
|
if (max_low_pfn < (mem_end >> PAGE_SHIFT))
|
|
max_low_pfn = mem_end >> PAGE_SHIFT;
|
|
break;
|
|
case EFI_PAL_CODE:
|
|
case EFI_UNUSABLE_MEMORY:
|
|
case EFI_ACPI_RECLAIM_MEMORY:
|
|
memblock_add(mem_start, mem_size);
|
|
fallthrough;
|
|
case EFI_RESERVED_TYPE:
|
|
case EFI_RUNTIME_SERVICES_CODE:
|
|
case EFI_RUNTIME_SERVICES_DATA:
|
|
case EFI_MEMORY_MAPPED_IO:
|
|
case EFI_MEMORY_MAPPED_IO_PORT_SPACE:
|
|
memblock_reserve(mem_start, mem_size);
|
|
break;
|
|
}
|
|
}
|
|
|
|
memblock_set_current_limit(PFN_PHYS(max_low_pfn));
|
|
memblock_set_node(0, PHYS_ADDR_MAX, &memblock.memory, 0);
|
|
|
|
/* Reserve the first 2MB */
|
|
memblock_reserve(PHYS_OFFSET, 0x200000);
|
|
|
|
/* Reserve the kernel text/data/bss */
|
|
memblock_reserve(__pa_symbol(&_text),
|
|
__pa_symbol(&_end) - __pa_symbol(&_text));
|
|
}
|