Message ID | 20240722035701.696874-3-ruanjinjie@huawei.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | crash: Fix crash memory reserve exceed system memory bug | expand |
Context | Check | Description |
---|---|---|
conchuod/vmtest-fixes-PR | fail | merge-conflict |
On Mon, Jul 22, 2024 at 11:57:00AM +0800, Jinjie Ruan wrote: > Similar with x86_32, on Qemu vexpress-a9 with 1GB memory, the crash kernel > "crashkernel=4G" is ok as below: > Reserving 4096MB of memory at 2432MB for crashkernel (System RAM: 1024MB) > > The cause is that the crash_size is parsed and printed with "unsigned long > long" data type which is 8 bytes but allocated used with "phys_addr_t" > which is 4 bytes in memblock_phys_alloc_range(). > > Fix it by checking if the crash_size is greater than system RAM size and > warn out as parse_crashkernel_mem() do it if so as Baoquan suggested. > > After this patch, it fails and there is no above confusing reserve > success info. > > Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> > Suggested-by: Baoquan He <bhe@redhat.com> Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk> Thanks!
diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index fc0ada003f6d..aea320dcac41 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -1005,6 +1005,11 @@ static void __init arch_reserve_crashkernel(void) if (ret || !crash_size) return; + if (crash_size >= total_mem) { + pr_warn("Crashkernel: invalid size."); + return; + } + reserve_crashkernel_generic(boot_command_line, crash_size, crash_base, low_size, high); if (arm_has_idmap_alias()) {
Similar with x86_32, on Qemu vexpress-a9 with 1GB memory, the crash kernel "crashkernel=4G" is ok as below: Reserving 4096MB of memory at 2432MB for crashkernel (System RAM: 1024MB) The cause is that the crash_size is parsed and printed with "unsigned long long" data type which is 8 bytes but allocated used with "phys_addr_t" which is 4 bytes in memblock_phys_alloc_range(). Fix it by checking if the crash_size is greater than system RAM size and warn out as parse_crashkernel_mem() do it if so as Baoquan suggested. After this patch, it fails and there is no above confusing reserve success info. Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> Suggested-by: Baoquan He <bhe@redhat.com> --- v4: - Update the warn info to align with parse_crashkernel_mem(). - Rebased on the "ARM: Use generic interface to simplify crashkernel reservation" patch. - Update the commit message. v3: - Handle the check in reserve_crashkernel() Baoquan suggested. - Split x86_32 and arm32. - Add Suggested-by. - Drop the wrong fix tag. v2: - Also fix for x86_32. - Update the fix method. - Peel off the other two patches. - Update the commit message. --- arch/arm/kernel/setup.c | 5 +++++ 1 file changed, 5 insertions(+)