From nobody Tue Sep 9 17:14:33 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 151CCC636D7 for ; Thu, 23 Feb 2023 11:06:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233997AbjBWLGk (ORCPT ); Thu, 23 Feb 2023 06:06:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233871AbjBWLGh (ORCPT ); Thu, 23 Feb 2023 06:06:37 -0500 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 00A1553EED for ; Thu, 23 Feb 2023 03:06:33 -0800 (PST) Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8AxJIS4SPdjFBsEAA--.2655S3; Thu, 23 Feb 2023 19:06:32 +0800 (CST) Received: from bogon.localdomain (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxK763SPdjgJg5AA--.39214S3; Thu, 23 Feb 2023 19:06:32 +0800 (CST) From: Youling Tang To: Huacai Chen Cc: Xuerui Wang , loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] LoongArch: kdump: Add single kernel image implementation Date: Thu, 23 Feb 2023 19:06:30 +0800 Message-Id: <1677150391-12838-2-git-send-email-tangyouling@loongson.cn> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1677150391-12838-1-git-send-email-tangyouling@loongson.cn> References: <1677150391-12838-1-git-send-email-tangyouling@loongson.cn> X-CM-TRANSID: AQAAf8DxK763SPdjgJg5AA--.39214S3 X-CM-SenderInfo: 5wdqw5prxox03j6o00pqjv00gofq/ X-Coremail-Antispam: 1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ence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This feature depends on the kernel being relocatable. Enable using single kernel image for kdump, and then no longer need to build two kernels (production kernel and capture kernel share single kernel image= ). Also enable CONFIG_CRASH_DUMP in loongson3_defconfig. Signed-off-by: Youling Tang --- arch/loongarch/Kconfig | 12 +----------- arch/loongarch/Makefile | 4 ---- arch/loongarch/configs/loongson3_defconfig | 1 + arch/loongarch/include/asm/addrspace.h | 2 ++ arch/loongarch/kernel/head.S | 2 +- 5 files changed, 5 insertions(+), 16 deletions(-) diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig index bafdfc8c7a4d..7342a36e8a15 100644 --- a/arch/loongarch/Kconfig +++ b/arch/loongarch/Kconfig @@ -513,6 +513,7 @@ config KEXEC =20 config CRASH_DUMP bool "Build kdump crash kernel" + select RELOCATABLE help Generate crash dump after being started by kexec. This should be normally only set in special crash dump kernels which are @@ -522,17 +523,6 @@ config CRASH_DUMP =20 For more details see Documentation/admin-guide/kdump/kdump.rst =20 -config PHYSICAL_START - hex "Physical address where the kernel is loaded" - default "0x90000000a0000000" - depends on CRASH_DUMP - help - This gives the XKPRANGE address where the kernel is loaded. - If you plan to use kernel for capturing the crash dump change - this value to start of the reserved region (the "X" value as - specified in the "crashkernel=3DYM@XM" command line boot parameter - passed to the panic-ed kernel). - config RELOCATABLE bool "Relocatable kernel" help diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile index 768592998b39..f71edf574101 100644 --- a/arch/loongarch/Makefile +++ b/arch/loongarch/Makefile @@ -79,11 +79,7 @@ endif cflags-y +=3D -ffreestanding cflags-y +=3D $(call cc-option, -mno-check-zero-division) =20 -ifndef CONFIG_PHYSICAL_START load-y =3D 0x9000000000200000 -else -load-y =3D $(CONFIG_PHYSICAL_START) -endif bootvars-y =3D VMLINUX_LOAD_ADDRESS=3D$(load-y) =20 drivers-$(CONFIG_PCI) +=3D arch/loongarch/pci/ diff --git a/arch/loongarch/configs/loongson3_defconfig b/arch/loongarch/co= nfigs/loongson3_defconfig index cb52774c80e8..7885f6e5de93 100644 --- a/arch/loongarch/configs/loongson3_defconfig +++ b/arch/loongarch/configs/loongson3_defconfig @@ -48,6 +48,7 @@ CONFIG_HOTPLUG_CPU=3Dy CONFIG_NR_CPUS=3D64 CONFIG_NUMA=3Dy CONFIG_KEXEC=3Dy +CONFIG_CRASH_DUMP=3Dy CONFIG_SUSPEND=3Dy CONFIG_HIBERNATION=3Dy CONFIG_ACPI=3Dy diff --git a/arch/loongarch/include/asm/addrspace.h b/arch/loongarch/includ= e/asm/addrspace.h index d342935e5a72..4edcb3c21cf5 100644 --- a/arch/loongarch/include/asm/addrspace.h +++ b/arch/loongarch/include/asm/addrspace.h @@ -125,4 +125,6 @@ extern unsigned long vm_map_base; #define ISA_IOSIZE SZ_16K #define IO_SPACE_LIMIT (PCI_IOSIZE - 1) =20 +#define PHYS_LINK_ADDR PHYSADDR(VMLINUX_LOAD_ADDRESS) + #endif /* _ASM_ADDRSPACE_H */ diff --git a/arch/loongarch/kernel/head.S b/arch/loongarch/kernel/head.S index 1d35becc01ee..7fb32aa26c2c 100644 --- a/arch/loongarch/kernel/head.S +++ b/arch/loongarch/kernel/head.S @@ -24,7 +24,7 @@ _head: .org 0x8 .dword kernel_entry /* Kernel entry point */ .dword _end - _text /* Kernel image effective size */ - .quad 0 /* Kernel image load offset from start of RAM */ + .quad PHYS_LINK_ADDR /* Kernel image load offset from start of RAM */ .org 0x38 /* 0x20 ~ 0x37 reserved */ .long LINUX_PE_MAGIC .long pe_header - _head /* Offset to the PE header */ --=20 2.37.3 From nobody Tue Sep 9 17:14:33 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2B1EC636D6 for ; Thu, 23 Feb 2023 11:06:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233991AbjBWLGm (ORCPT ); Thu, 23 Feb 2023 06:06:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233883AbjBWLGh (ORCPT ); Thu, 23 Feb 2023 06:06:37 -0500 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1CA1754551 for ; Thu, 23 Feb 2023 03:06:33 -0800 (PST) Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8Ax69m5SPdjGRsEAA--.2624S3; Thu, 23 Feb 2023 19:06:33 +0800 (CST) Received: from bogon.localdomain (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxK763SPdjgJg5AA--.39214S4; Thu, 23 Feb 2023 19:06:33 +0800 (CST) From: Youling Tang To: Huacai Chen Cc: Xuerui Wang , loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] LoongArch: kdump: Add crashkernel=YM handling Date: Thu, 23 Feb 2023 19:06:31 +0800 Message-Id: <1677150391-12838-3-git-send-email-tangyouling@loongson.cn> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1677150391-12838-1-git-send-email-tangyouling@loongson.cn> References: <1677150391-12838-1-git-send-email-tangyouling@loongson.cn> X-CM-TRANSID: AQAAf8DxK763SPdjgJg5AA--.39214S4 X-CM-SenderInfo: 5wdqw5prxox03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoW7WFy3tF1kXr4Uur1xXrW8WFg_yoW8ZFWrpr 1UAF45tFW5GF93G3yrAr9rur1rA3Wxua4jgFZ0y34kAF9xXrn8tw4kW3ZrZFyUK3s3WF4j vrZYqF9Iga18taDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU b7xYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_JrI_Jryl8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW8JVW5JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwA2z4 x0Y4vEx4A2jsIE14v26F4UJVW0owA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Cr1j6rxdM2AI xVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx1l5I8CrVACY4xI64 kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r126r1DMcIj6I8E87Iv67AKxVW8JVWxJwAm 72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I 0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWU GVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI 0_JFI_Gr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0 rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r1j6r 4UYxBIdaVFxhVjvjDU0xZFpf9x07jY38nUUUUU= Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When the kernel crashkernel parameter is specified with just a size, we are supposed to allocate a region from RAM to store the crashkernel, "crashkernel=3D512M" would be recommended for kdump. Fix this by lifting similar code from x86, importing it to LoongArch with the LoongArch specific parameters added. We allocate the crashkernel region from the first 4G of physical memory (SWIOTLB needs to be allocated on low 4G). Currently LoongArch does not implement crashkernel_low and crashkernel_high like x86. When X is not specified, crash_base defaults to 0 (crashkernel=3DYM@XM). Signed-off-by: Youling Tang --- arch/loongarch/kernel/setup.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c index 4344502c0b31..ac2aad988fdb 100644 --- a/arch/loongarch/kernel/setup.c +++ b/arch/loongarch/kernel/setup.c @@ -234,11 +234,14 @@ static void __init arch_reserve_vmcore(void) #endif } =20 +/* 16M alignment for crash kernel regions */ +#define CRASH_ALIGN SZ_16M +#define CRASH_ADDR_MAX SZ_4G + static void __init arch_parse_crashkernel(void) { #ifdef CONFIG_KEXEC int ret; - unsigned long long start; unsigned long long total_mem; unsigned long long crash_base, crash_size; =20 @@ -247,8 +250,14 @@ static void __init arch_parse_crashkernel(void) if (ret < 0 || crash_size <=3D 0) return; =20 - start =3D memblock_phys_alloc_range(crash_size, 1, crash_base, crash_base= + crash_size); - if (start !=3D crash_base) { + if (crash_base <=3D 0) { + crash_base =3D memblock_phys_alloc_range(crash_size, CRASH_ALIGN, CRASH_= ALIGN, + CRASH_ADDR_MAX); + if (!crash_base) { + pr_warn("crashkernel reservation failed - No suitable area found.\n"); + return; + } + } else if (!memblock_phys_alloc_range(crash_size, 1, crash_base, crash_ba= se + crash_size)) { pr_warn("Invalid memory region reserved for crash kernel\n"); return; } --=20 2.37.3