[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240708133348.3592667-2-ruanjinjie@huawei.com>
Date: Mon, 8 Jul 2024 21:33:46 +0800
From: Jinjie Ruan <ruanjinjie@...wei.com>
To: <linux@...linux.org.uk>, <bhe@...hat.com>, <vgoyal@...hat.com>,
<dyoung@...hat.com>, <paul.walmsley@...ive.com>, <palmer@...belt.com>,
<aou@...s.berkeley.edu>, <arnd@...db.de>, <afd@...com>,
<akpm@...ux-foundation.org>, <rmk+kernel@...linux.org.uk>,
<linus.walleij@...aro.org>, <eric.devolder@...cle.com>,
<gregkh@...uxfoundation.org>, <deller@....de>, <javierm@...hat.com>,
<robh@...nel.org>, <thunder.leizhen@...wei.com>, <austindh.kim@...il.com>,
<linux-arm-kernel@...ts.infradead.org>, <linux-kernel@...r.kernel.org>,
<kexec@...ts.infradead.org>
CC: <ruanjinjie@...wei.com>
Subject: [PATCH 1/3] crash: Fix memory reserve dead loop bug in reserve_crashkernel_generic()
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 = CRASH_ADDR_LOW_MAX(same as CRASH_ADDR_HIGH_MAX)
-> call memblock_phys_alloc_range() again and fail agin.
-> search_end == 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 <ruanjinjie@...wei.com>
---
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 = CRASH_ADDR_LOW_MAX;
search_end = CRASH_ADDR_HIGH_MAX;
+
+ if (search_base >= search_end) {
+ pr_warn("crashkernel high memory reservation failed.\n");
+ return;
+ }
}
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 == CRASH_ADDR_LOW_MAX) {
+ if (!high && search_end == CRASH_ADDR_LOW_MAX &&
+ CRASH_ADDR_HIGH_MAX > CRASH_ADDR_LOW_MAX) {
search_end = CRASH_ADDR_HIGH_MAX;
search_base = CRASH_ADDR_LOW_MAX;
crash_low_size = DEFAULT_CRASH_KERNEL_LOW_SIZE;
--
2.34.1
Powered by blists - more mailing lists