From b624eb6efa8482fb60a56192f872398fb8df98c8 Mon Sep 17 00:00:00 2001 From: Hongchen Zhang Date: Thu, 23 May 2024 10:15:04 +0800 Subject: [PATCH 1/4] anolis: Revert "LoongArch: kdump: Add high memory reservation" ANBZ: #9163 This reverts commit 63601a110e3c57cea9d460d5a1800593c8fdda01 There is no need to reserve extra memory to the crash kernel, as if the kdump test failed, we should increase the size of the crash kernel instead of reserve high memory for user. Signed-off-by: Hongchen Zhang --- arch/loongarch/kernel/setup.c | 49 +++-------------------------------- 1 file changed, 3 insertions(+), 46 deletions(-) diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c index 4bd592c5019d..14d885821533 100644 --- a/arch/loongarch/kernel/setup.c +++ b/arch/loongarch/kernel/setup.c @@ -383,49 +383,13 @@ static void __init bootcmdline_init(char **cmdline_p) * memory area used by the previous production kernel should be reserved to * avoid destroy to the captured data. */ -static void reserve_oldmem_region(int node, unsigned long s0, unsigned long e0) +static void reserve_oldmem_region(void) { #ifdef CONFIG_CRASH_DUMP - unsigned long s1, e1; - if (!is_kdump_kernel()) return; - if ((e0 - s0) > (SZ_1G >> PAGE_SHIFT)) - e0 = e0 - (SZ_512M >> PAGE_SHIFT); - - /* crashmem_start is crashk_res reserved by primary production kernel */ - s1 = PFN_UP(crashmem_start); - e1 = PFN_DOWN(crashmem_start + crashmem_size); - - if (s1 == 0) - return; - - if (node == 0) { - memblock_reserve(PFN_PHYS(s0), (s1 - s0) << PAGE_SHIFT); - memblock_reserve(PFN_PHYS(e1), (e0 - e1) << PAGE_SHIFT); - } else { - memblock_reserve(PFN_PHYS(s0), (e0 - s0) << PAGE_SHIFT); - } -#endif -} - -/* Traditionally, LoongArch's contiguous low memory is 256M, so crashkernel=X@Y is - * unable to be large enough in some cases. Thus, if the total memory of a node - * is more than 1GB, we reserve the top 512MB for the capture kernel - */ -static void reserve_crashm_region(int node, unsigned long s0, unsigned long e0) -{ -#ifdef CONFIG_KEXEC - if (crashk_res.start == crashk_res.end) - return; - - if ((e0 - s0) <= (SZ_1G >> PAGE_SHIFT)) - return; - - s0 = e0 - (SZ_512M >> PAGE_SHIFT); - - memblock_reserve(PFN_PHYS(s0), (e0 - s0) << PAGE_SHIFT); + memblock_cap_memory_range(crashmem_start, crashmem_size); #endif } @@ -468,16 +432,9 @@ static void __init check_kernel_sections_mem(void) */ static void __init arch_mem_init(char **cmdline_p) { - unsigned int node; - unsigned long start_pfn, end_pfn; - arch_reserve_vmcore(); arch_parse_crashkernel(); - for_each_online_node(node) { - get_pfn_range_for_nid(node, &start_pfn, &end_pfn); - reserve_crashm_region(node, start_pfn, end_pfn); - reserve_oldmem_region(node, start_pfn, end_pfn); - } + reserve_oldmem_region(); if (usermem) pr_info("User-defined physical RAM map overwrite\n"); -- Gitee From e1cf9d11119ecd3da75e53291a49ce7ca41bce57 Mon Sep 17 00:00:00 2001 From: Hongchen Zhang Date: Thu, 23 May 2024 10:15:05 +0800 Subject: [PATCH 2/4] anolis: Revert "LoongArch: Fix kdump failure on v40 interface specification" ANBZ: #9163 This reverts commit c9a5527a4071c59723e99fbfec02ff980352d2f5. This patch is only a work around, and the root cause is efi map table error. Therefore, we fix the problem of efi map table error at the following patch instead of adding this work around. Signed-off-by: Hongchen Zhang --- arch/loongarch/kernel/setup.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c index 14d885821533..837feea45413 100644 --- a/arch/loongarch/kernel/setup.c +++ b/arch/loongarch/kernel/setup.c @@ -395,6 +395,10 @@ static void reserve_oldmem_region(void) void __init platform_init(void) { + arch_reserve_vmcore(); + arch_parse_crashkernel(); + reserve_oldmem_region(); + #ifdef CONFIG_ACPI_TABLE_UPGRADE acpi_table_upgrade(); #endif @@ -432,10 +436,6 @@ static void __init check_kernel_sections_mem(void) */ static void __init arch_mem_init(char **cmdline_p) { - arch_reserve_vmcore(); - arch_parse_crashkernel(); - reserve_oldmem_region(); - if (usermem) pr_info("User-defined physical RAM map overwrite\n"); -- Gitee From 080a83bd2620724a57114bc16fdf193f7093b80c Mon Sep 17 00:00:00 2001 From: Hongchen Zhang Date: Thu, 23 May 2024 10:15:06 +0800 Subject: [PATCH 3/4] anolis: Revert "LoongArch: kdump: Add memory reservation for old kernel" ANBZ: #9163 This reverts commit beda9aa1f7bba0f0a68d64565c1b97917da3e3d6. In the current state, elfcorehdr will not be destroyed, because it is allocated at the memory reserved for crash kernel, so this patch is not required. Signed-off-by: Hongchen Zhang --- arch/loongarch/kernel/setup.c | 45 ++++++++--------------------------- 1 file changed, 10 insertions(+), 35 deletions(-) diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c index 837feea45413..8af027e89ad5 100644 --- a/arch/loongarch/kernel/setup.c +++ b/arch/loongarch/kernel/setup.c @@ -69,8 +69,6 @@ EXPORT_SYMBOL(cpu_data); struct loongson_board_info b_info; static const char dmi_empty_string[] = " "; -static phys_addr_t crashmem_start, crashmem_size; - /* * Setup information * @@ -208,15 +206,6 @@ static int __init early_parse_mem(char *p) return -EINVAL; } - start = 0; - size = memparse(p, &p); - if (*p == '@') - start = memparse(p + 1, &p); - else { - pr_err("Invalid format!\n"); - return -EINVAL; - } - /* * If a user specifies memory size, we * blow away any automatically generated @@ -224,14 +213,16 @@ static int __init early_parse_mem(char *p) */ if (usermem == 0) { usermem = 1; - if (!strstr(boot_command_line, "elfcorehdr")) { - memblock_remove(memblock_start_of_DRAM(), - memblock_end_of_DRAM() - memblock_start_of_DRAM()); - } else { - crashmem_start = start; - crashmem_size = size; - return 0; - } + memblock_remove(memblock_start_of_DRAM(), + memblock_end_of_DRAM() - memblock_start_of_DRAM()); + } + start = 0; + size = memparse(p, &p); + if (*p == '@') + start = memparse(p + 1, &p); + else { + pr_err("Invalid format!\n"); + return -EINVAL; } if (!IS_ENABLED(CONFIG_NUMA)) @@ -378,26 +369,10 @@ static void __init bootcmdline_init(char **cmdline_p) *cmdline_p = boot_command_line; } -/* - * After the kdump operation is performed to enter the capture kernel, the - * memory area used by the previous production kernel should be reserved to - * avoid destroy to the captured data. - */ -static void reserve_oldmem_region(void) -{ -#ifdef CONFIG_CRASH_DUMP - if (!is_kdump_kernel()) - return; - - memblock_cap_memory_range(crashmem_start, crashmem_size); -#endif -} - void __init platform_init(void) { arch_reserve_vmcore(); arch_parse_crashkernel(); - reserve_oldmem_region(); #ifdef CONFIG_ACPI_TABLE_UPGRADE acpi_table_upgrade(); -- Gitee From 757ae853ba64351258e59eae50fb51f1814ea32e Mon Sep 17 00:00:00 2001 From: Hongchen Zhang Date: Thu, 23 May 2024 10:15:07 +0800 Subject: [PATCH 4/4] anolis: LoongArch: fix efi map page table error ANBZ: #9163 There should map all efi used memory, not the kernel usable memory. Signed-off-by: Yun Liu Signed-off-by: Hongchen Zhang --- arch/loongarch/kernel/efi.c | 39 +++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/arch/loongarch/kernel/efi.c b/arch/loongarch/kernel/efi.c index b132af112664..140b43d3f182 100644 --- a/arch/loongarch/kernel/efi.c +++ b/arch/loongarch/kernel/efi.c @@ -69,8 +69,10 @@ static int __init efimap_populate_hugepages( if (pud_none(*pud)) { void *p = memblock_alloc_low(PAGE_SIZE, PAGE_SIZE); - if (!p) + if (!p) { + pr_err("can not alloc efimap huge pages!\n"); return -1; + } pmd_init(p); pud_populate(&init_mm, pud, p); } @@ -88,7 +90,8 @@ static void __init efi_map_pgt(void) { unsigned long node; unsigned long start, end; - unsigned long start_pfn, end_pfn; + efi_memory_desc_t *md; + u32 mem_type; pgd_efi = memblock_alloc_low(PAGE_SIZE, PAGE_SIZE); if (!pgd_efi) { @@ -105,13 +108,33 @@ static void __init efi_map_pgt(void) /* MMIO Registers, Uncached */ efimap_populate_hugepages(SZ_256M | (node << 44), SZ_512M | (node << 44), PAGE_KERNEL_SUC); + } - get_pfn_range_for_nid(node, &start_pfn, &end_pfn); - start = ALIGN_DOWN(start_pfn << PAGE_SHIFT, PMD_SIZE); - end = ALIGN(end_pfn << PAGE_SHIFT, PMD_SIZE); - - /* System memory, Cached */ - efimap_populate_hugepages(node ? start : SZ_512M, end, PAGE_KERNEL); + /* Parse memory information */ + for_each_efi_memory_desc(md) { + mem_type = md->type; + start = ALIGN_DOWN(md->phys_addr, PMD_SIZE); + end = ALIGN(start + (md->num_pages << EFI_PAGE_SHIFT), PMD_SIZE); + node = start >> 44; + + switch (mem_type) { + case EFI_LOADER_CODE: + case EFI_LOADER_DATA: + case EFI_BOOT_SERVICES_CODE: + case EFI_BOOT_SERVICES_DATA: + case EFI_PAL_CODE: + case EFI_UNUSABLE_MEMORY: + case EFI_ACPI_RECLAIM_MEMORY: + case EFI_RESERVED_TYPE: + case EFI_RUNTIME_SERVICES_CODE: + case EFI_RUNTIME_SERVICES_DATA: + efimap_populate_hugepages(node ? start : SZ_512M, end, PAGE_KERNEL); + break; + case EFI_MEMORY_MAPPED_IO: + case EFI_MEMORY_MAPPED_IO_PORT_SPACE: + efimap_populate_hugepages(node ? start : SZ_512M, end, PAGE_KERNEL_SUC); + break; + } } } -- Gitee