From nobody Sun Feb 8 23:41:37 2026 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD52213774A for ; Mon, 8 Jul 2024 13:29:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720445395; cv=none; b=HJllPsoTStREuSYMtTRJy7ChyshK4W05xwPNXmvfNU2FTZyigTfNBdljGQ+K5/fWVkxEK7j5m0CWmJLQ9hgRtYnevgrOw1199lXapX4oI5F+jyOT3WNU2AlYEFPXIfMZp0T5Av8uFV23ebZdpnZIfTwZ647+3DIkT4kBTWZzcy0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720445395; c=relaxed/simple; bh=hDmU0jR2eMDhbsTHQrUhsRIFhS1zJ2pGotJO/aAfgBk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AumIi4Wg2uuMVReKarZJVmK1Nde2Yo7yHEtNUzYzToMK6jNAd/AWDR6U0tXmL2JqZodNF0ARNL15WWDv3NdBh5Fr1wgGp1mhDp8W98GiMI88sejtO3Lg4jIh5a1gPHVZLPwcL6hz7uUAmPpu8PKnJbGjMmDjRLii7lJx88sODbo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4WHlHl00R7zQksh; Mon, 8 Jul 2024 21:25:54 +0800 (CST) Received: from kwepemi100008.china.huawei.com (unknown [7.221.188.57]) by mail.maildlp.com (Postfix) with ESMTPS id B5267140415; Mon, 8 Jul 2024 21:29:48 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemi100008.china.huawei.com (7.221.188.57) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Mon, 8 Jul 2024 21:29:47 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH 1/3] crash: Fix memory reserve dead loop bug in reserve_crashkernel_generic() Date: Mon, 8 Jul 2024 21:33:46 +0800 Message-ID: <20240708133348.3592667-2-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240708133348.3592667-1-ruanjinjie@huawei.com> References: <20240708133348.3592667-1-ruanjinjie@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemi100008.china.huawei.com (7.221.188.57) Content-Type: text/plain; charset="utf-8" If the platform do not support memory above 4G, such as 32 bit arch, and CRASH_ADDR_LOW_MAX is equal to CRASH_ADDR_HIGH_MAX, the high crash kernel memory reservation is meaningless and it will cause dead loop and system stall: -> reserve_crashkernel_generic() and high is true -> memblock_phys_alloc_range() fail and return 0 -> search_end =3D CRASH_ADDR_LOW_MAX(same as CRASH_ADDR_HIGH_MAX) -> call memblock_phys_alloc_range() again and fail agin. -> search_end =3D=3D CRASH_ADDR_HIGH_MAX satisfy again ...... However, the current check only considers the case where CRASH_ADDR_HIGH_MAX is greater than CRASH_ADDR_LOW_MAX. Fix it. Fixes: 0ab97169aa05 ("crash_core: add generic function to do reservation") Signed-off-by: Jinjie Ruan Reviewed-by: Linus Walleij --- kernel/crash_reserve.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kernel/crash_reserve.c b/kernel/crash_reserve.c index 5b2722a93a48..e18fb1bb5d28 100644 --- a/kernel/crash_reserve.c +++ b/kernel/crash_reserve.c @@ -390,6 +390,11 @@ void __init reserve_crashkernel_generic(char *cmdline, } else if (high) { search_base =3D CRASH_ADDR_LOW_MAX; search_end =3D CRASH_ADDR_HIGH_MAX; + + if (search_base >=3D search_end) { + pr_warn("crashkernel high memory reservation failed.\n"); + return; + } } =20 retry: @@ -410,7 +415,8 @@ void __init reserve_crashkernel_generic(char *cmdline, * low memory, fall back to high memory, the minimum required * low memory will be reserved later. */ - if (!high && search_end =3D=3D CRASH_ADDR_LOW_MAX) { + if (!high && search_end =3D=3D CRASH_ADDR_LOW_MAX && + CRASH_ADDR_HIGH_MAX > CRASH_ADDR_LOW_MAX) { search_end =3D CRASH_ADDR_HIGH_MAX; search_base =3D CRASH_ADDR_LOW_MAX; crash_low_size =3D DEFAULT_CRASH_KERNEL_LOW_SIZE; --=20 2.34.1 From nobody Sun Feb 8 23:41:37 2026 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 675B3137757 for ; Mon, 8 Jul 2024 13:29:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720445394; cv=none; b=HFfyMV7LuA4H9DEiLRwyDCJqiWUlXPQ/agvx9zvF3QDlK/lTMYmr9N28i3QoBuE8VPwGbzok2zf0CujTLDZRRmjR272SJYKjcAtZfKzF0U2WfNZozcJ/QfqY2/89/M8BYNQ+9aTNP9fAG9wdF8ZIqslYiuqCUQQtvgdhrxRNRLA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720445394; c=relaxed/simple; bh=v0m01wOgJdCx25vKCu7GRWUXyEUDmtefnlx+KwmQUEU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=P8Ip8Bi51GrWgYygVNxboGLFX5SUTsubR22LVCYVvC98s2Rn9bzT76VghSTVUye26XutAV6tTMADNtrRilkJD+XOoX05EUbsGE25VGj62uCU9bX4s55PvwpcKRqarM485me4KbPeala4dnMw8qa5rvxK+4U2yvrm6b5GazbSLyE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4WHlGs2J4bzwWPg; Mon, 8 Jul 2024 21:25:09 +0800 (CST) Received: from kwepemi100008.china.huawei.com (unknown [7.221.188.57]) by mail.maildlp.com (Postfix) with ESMTPS id 8465C180087; Mon, 8 Jul 2024 21:29:49 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemi100008.china.huawei.com (7.221.188.57) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Mon, 8 Jul 2024 21:29:48 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH 2/3] ARM: Fix crash kenrel data type bug Date: Mon, 8 Jul 2024 21:33:47 +0800 Message-ID: <20240708133348.3592667-3-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240708133348.3592667-1-ruanjinjie@huawei.com> References: <20240708133348.3592667-1-ruanjinjie@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemi100008.china.huawei.com (7.221.188.57) Content-Type: text/plain; charset="utf-8" On QEMU vexpress-a9 with 1GB memory, the crash kernel "crashkernel=3D4G" is ok as below: Reserving 4096MB of memory at 2432MB for crashkernel (System RAM: 1024MB) The above info is confusing, because the System memory is as below: # cat /proc/iomem | grep Sys 60000000-9fffffff : System RAM The cause is that the crash_size is parsed and printed with "unsigned long long" data type which is 8 bytes but used with "phys_addr_t" which is 4 bytes in memblock_phys_alloc_range(). Fixes: 9d17f3372306 ("ARM: 9190/1: kdump: add invalid input check for 'cras= hkernel=3D0'") Signed-off-by: Jinjie Ruan --- arch/arm/kernel/setup.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index e6a857bf0ce6..59e1a13b5cf6 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -1012,6 +1012,7 @@ static void __init reserve_crashkernel(void) &crash_size, &crash_base, NULL, NULL); /* invalid value specified or crashkernel=3D0 */ + crash_size =3D (phys_addr_t)crash_size; if (ret || !crash_size) return; =20 --=20 2.34.1 From nobody Sun Feb 8 23:41:37 2026 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 03E3A137923 for ; Mon, 8 Jul 2024 13:29:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720445395; cv=none; b=mp6TrYMeWUiyWuyxmyfCd0ldtkl8sWcWDwzpRprmKGXVd38FDxcMPXJpFnHgKi8l9Z7yZMOcx/vPiuMarmRC1S5rllgxK+6+0sWfyj631/9GWhZFcJytuw4yetFn6snehjESAXe3p2Tpe/4ZJsrmrgbD+Z9hhgnXvzVXi+Vzmts= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720445395; c=relaxed/simple; bh=+v1vN4nVdfPzeqBmxm+ZPwaumg7jxBDFH3+la7D2d1g=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EXUcc7BPrDSCl0CNinrgn/+SpxAW71YWJw5iJ06oMsY92vhsTsxtqJfNzARW/RbJEt3OwgS2QbkcDu5BCEtb4hP3srnQTKZZSn3QoUALEphN+weVSgUeZEcBR1w12t7vltq6qK4aH9QK+jRH1lrXjUbbQhyyE89bmiB7bqO15/0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4WHlHm4ZpBzQktx; Mon, 8 Jul 2024 21:25:56 +0800 (CST) Received: from kwepemi100008.china.huawei.com (unknown [7.221.188.57]) by mail.maildlp.com (Postfix) with ESMTPS id 5CB6B14022D; Mon, 8 Jul 2024 21:29:50 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemi100008.china.huawei.com (7.221.188.57) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Mon, 8 Jul 2024 21:29:49 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH 3/3] ARM: Use generic interface to simplify crashkernel reservation Date: Mon, 8 Jul 2024 21:33:48 +0800 Message-ID: <20240708133348.3592667-4-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240708133348.3592667-1-ruanjinjie@huawei.com> References: <20240708133348.3592667-1-ruanjinjie@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemi100008.china.huawei.com (7.221.188.57) Content-Type: text/plain; charset="utf-8" Currently, x86, arm64, riscv and loongarch has been switched to generic crashkernel reservation. With the help of function parse_crashkernel() and generic reserve_crashkernel_generic(), arm32 crashkernel reservation can also be simplified by steps: 1) Add a new header file , and define CRASH_ALIGN, CRASH_ADDR_LOW_MAX, CRASH_ADDR_HIGH_MAX in it; 2) Add arch_reserve_crashkernel() to call parse_crashkernel() and reserve_crashkernel_generic(); 3) Add ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION Kconfig in arch/arm/Kconfig. The old reserve_crashkernel() can be removed. Following test cases have been performed as expected on QEMU vexpress-a9 (1GB system memory): 1) crashkernel=3D4G,high // invalid 2) crashkernel=3D1G,high // invalid 3) crashkernel=3D1G,high crashkernel=3D0M,low // invalid 4) crashkernel=3D256M,high // invalid 5) crashkernel=3D256M,low // invalid 6) crashkernel=3D256M crashkernel=3D256M,high // high is ignored, ok 7) crashkernel=3D256M crashkernel=3D256M,low // low is ignored, ok 8) crashkernel=3D256M,high crashkernel=3D256M,low // invalid 9) crashkernel=3D256M,high crashkernel=3D4G,low // invalid 10) crashkernel=3D256M // ok 11) crashkernel=3D512M // ok 12) crashkernel=3D256M@0x88000000 // ok 13) crashkernel=3D256M@0x78000000 // ok 14) crashkernel=3D512M@0x78000000 // ok Signed-off-by: Jinjie Ruan --- arch/arm/Kconfig | 3 ++ arch/arm/include/asm/crash_reserve.h | 24 +++++++++++ arch/arm/kernel/setup.c | 62 ++++------------------------ 3 files changed, 36 insertions(+), 53 deletions(-) create mode 100644 arch/arm/include/asm/crash_reserve.h diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 68990e1645d5..02e620e185c0 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -1596,6 +1596,9 @@ config ATAGS_PROC config ARCH_SUPPORTS_CRASH_DUMP def_bool y =20 +config ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION + def_bool CRASH_RESERVE + config AUTO_ZRELADDR bool "Auto calculation of the decompressed kernel image address" if !ARCH= _MULTIPLATFORM default !(ARCH_FOOTBRIDGE || ARCH_RPC || ARCH_SA1100) diff --git a/arch/arm/include/asm/crash_reserve.h b/arch/arm/include/asm/cr= ash_reserve.h new file mode 100644 index 000000000000..85c9298bd3b7 --- /dev/null +++ b/arch/arm/include/asm/crash_reserve.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _ARM_CRASH_RESERVE_H +#define _ARM_CRASH_RESERVE_H + +/* + * The crash region must be aligned to 128MB to avoid + * zImage relocating below the reserved region. + */ +#define CRASH_ALIGN (128 << 20) + +#define CRASH_ADDR_LOW_MAX crash_addr_low_max() +#define CRASH_ADDR_HIGH_MAX memblock_end_of_DRAM() + +static inline unsigned long crash_addr_low_max(void) +{ + unsigned long long crash_max =3D idmap_to_phys((u32)~0); + unsigned long long lowmem_max =3D __pa(high_memory - 1) + 1; + + return (crash_max > lowmem_max) ? lowmem_max : crash_max; +} + + +#define HAVE_ARCH_ADD_CRASH_RES_TO_IOMEM_EARLY +#endif diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index 59e1a13b5cf6..3a8b6f08f4ec 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -979,13 +979,6 @@ static int __init init_machine_late(void) } late_initcall(init_machine_late); =20 -#ifdef CONFIG_CRASH_RESERVE -/* - * The crash region must be aligned to 128MB to avoid - * zImage relocating below the reserved region. - */ -#define CRASH_ALIGN (128 << 20) - static inline unsigned long long get_total_mem(void) { unsigned long total; @@ -994,61 +987,27 @@ static inline unsigned long long get_total_mem(void) return total << PAGE_SHIFT; } =20 -/** - * reserve_crashkernel() - reserves memory are for crash kernel - * - * This function reserves memory area given in "crashkernel=3D" kernel com= mand - * line parameter. The memory reserved is used by a dump capture kernel wh= en - * primary kernel is crashing. - */ -static void __init reserve_crashkernel(void) +static void __init arch_reserve_crashkernel(void) { unsigned long long crash_size, crash_base; + unsigned long long low_size =3D 0; unsigned long long total_mem; + bool high =3D false; int ret; =20 + if (!IS_ENABLED(CONFIG_CRASH_RESERVE)) + return; + total_mem =3D get_total_mem(); ret =3D parse_crashkernel(boot_command_line, total_mem, &crash_size, &crash_base, - NULL, NULL); + &low_size, &high); /* invalid value specified or crashkernel=3D0 */ crash_size =3D (phys_addr_t)crash_size; if (ret || !crash_size) return; =20 - if (crash_base <=3D 0) { - unsigned long long crash_max =3D idmap_to_phys((u32)~0); - unsigned long long lowmem_max =3D __pa(high_memory - 1) + 1; - if (crash_max > lowmem_max) - crash_max =3D lowmem_max; - - crash_base =3D memblock_phys_alloc_range(crash_size, CRASH_ALIGN, - CRASH_ALIGN, crash_max); - if (!crash_base) { - pr_err("crashkernel reservation failed - No suitable area found.\n"); - return; - } - } else { - unsigned long long crash_max =3D crash_base + crash_size; - unsigned long long start; - - start =3D memblock_phys_alloc_range(crash_size, SECTION_SIZE, - crash_base, crash_max); - if (!start) { - pr_err("crashkernel reservation failed - memory is in use.\n"); - return; - } - } - - pr_info("Reserving %ldMB of memory at %ldMB for crashkernel (System RAM: = %ldMB)\n", - (unsigned long)(crash_size >> 20), - (unsigned long)(crash_base >> 20), - (unsigned long)(total_mem >> 20)); - - /* The crashk resource must always be located in normal mem */ - crashk_res.start =3D crash_base; - crashk_res.end =3D crash_base + crash_size - 1; - insert_resource(&iomem_resource, &crashk_res); + reserve_crashkernel_generic(boot_command_line, crash_size, crash_base, lo= w_size, high); =20 if (arm_has_idmap_alias()) { /* @@ -1065,9 +1024,6 @@ static void __init reserve_crashkernel(void) insert_resource(&iomem_resource, &crashk_boot_res); } } -#else -static inline void reserve_crashkernel(void) {} -#endif /* CONFIG_CRASH_RESERVE*/ =20 void __init hyp_mode_check(void) { @@ -1190,7 +1146,7 @@ void __init setup_arch(char **cmdline_p) if (!is_smp()) hyp_mode_check(); =20 - reserve_crashkernel(); + arch_reserve_crashkernel(); =20 #ifdef CONFIG_VT #if defined(CONFIG_VGA_CONSOLE) --=20 2.34.1