of/fdt, LoongArch, MIPS: fix misleading reservation success message
Subsystems (3)
cover of/fdt, LoongArch, MIPS: fix misleading reservation success message
While reading the elfcorehdr reservation paths I noticed that fdt_reserve_elfcorehdr(), LoongArch's arch_reserve_vmcore() and MIPS's mips_reserve_vmcore() ignore the return value of memblock_reserve() and print a success message even when the reservation fails.
memblock_reserve() is unlikely to fail this early in boot. However, printing success on a failed reservation is misleading. I think it is worth fixing, but feel free to drop it if you disagree.
The three call sites are in different trees, so I split the change into one patch per arch/subsystem. The patches are independent and can be applied separately.
Sang-Heon Jeon (3):
of/fdt: fix misleading elfcorehdr reservation success message
LoongArch: fix misleading elfcorehdr reservation success message
MIPS: fix misleading elfcorehdr reservation success message
arch/loongarch/kernel/setup.c | 5 ++++- arch/mips/kernel/setup.c | 7 +++++-- drivers/of/fdt.c | 5 ++++- 3 files changed, 13 insertions(+), 4 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/3 of/fdt: fix misleading elfcorehdr reservation success message
fdt_reserve_elfcorehdr() does not check the return value of memblock_reserve(), so a success message is falsely printed when the reservation fails.
Check the return value and warn on failure instead.
--- drivers/of/fdt.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/of/fdt.c +4 -1
@@ -479,7 +479,10 @@ static void __init fdt_reserve_elfcorehdr(void)return ; } -memblock_reserve (elfcorehdr_addr, elfcorehdr_size); +if (memblock_reserve (elfcorehdr_addr, elfcorehdr_size)) { +pr_warn ("Failed to reserve memory for elfcorehdr\n" ); +return ; + }pr_info ("Reserving %llu KiB of memory at 0x%llx for elfcorehdr\n" , elfcorehdr_size >>10 , elfcorehdr_addr);
Signature · 1 line
2.43.0
Rob Herring
maintainerRe: [PATCH 1/3] of/fdt: fix misleading elfcorehdr reservation success message
Quoted 16 lines · Sang-Heon Jeon
fdt_reserve_elfcorehdr()does not check the return value ofmemblock_reserve(), so a success message is falsely printed when the reservation fails.Check the return value and warn on failure instead.
Signed-off-by Sang-Heon Jeon <[email protected]>--- drivers/of/fdt.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/of/fdt.c +0
-0
drivers/of/fdt.c static void __init fdt_reserve_elfcorehdr(void) · line 483
Quoted 6 lines
drivers/of/fdt.c +2
-1@@ -479,7 +479,10 @@ static void __init fdt_reserve_elfcorehdr(void)return ; } -memblock_reserve (elfcorehdr_addr, elfcorehdr_size); +if (memblock_reserve (elfcorehdr_addr, elfcorehdr_size)) { +pr_warn ("Failed to reserve memory for elfcorehdr\n" );
I would think memblock_reserve() should always succeed and if not it should print a message rather than having every caller print a message.
Rob
Re: [PATCH 1/3] of/fdt: fix misleading elfcorehdr reservation success message
Quoted 21 lines · Rob Herring
Quoted 19 lines · Sang-Heon Jeon
fdt_reserve_elfcorehdr()does not check the return value ofmemblock_reserve(), so a success message is falsely printed when the reservation fails.Check the return value and warn on failure instead.
Signed-off-by Sang-Heon Jeon <[email protected]>--- drivers/of/fdt.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/of/fdt.c +0
-0@@ -479,7 +479,10 @@ static void __init fdt_reserve_elfcorehdr(void)return ; }
Quoted 6 lines
drivers/of/fdt.c static void __init fdt_reserve_elfcorehdr(void) · line 483
Quoted 3 lines
drivers/of/fdt.c +2
-1-memblock_reserve (elfcorehdr_addr, elfcorehdr_size); +if (memblock_reserve (elfcorehdr_addr, elfcorehdr_size)) { +pr_warn ("Failed to reserve memory for elfcorehdr\n" );I would think
memblock_reserve()should always succeed and if not it should print a message rather than having every caller print a message.
Thanks for reviewing, Rob.
You're right. After taking a closer look, memblock_reserve() either succeeds or panics before memblock_allow_resize() called. So the check that I added in this patchset is totally unreachable.
Please drop this patchset. I'll be more careful when sending patches next time.
Quoted 1 line
Rob
Best Regards,
Sang-Heon Jeon
PATCH 2/3 LoongArch: fix misleading elfcorehdr reservation success message
In reply to Sang-Heon Jeonarch_reserve_vmcore() does not check the return value of memblock_reserve(), so a success message is falsely printed when the reservation fails.
Check the return value and warn on failure instead.
--- arch/loongarch/kernel/setup.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
arch/loongarch/kernel/setup.c +4 -1
@@ -255,7 +255,10 @@ static void __init arch_reserve_vmcore(void)return ; } -memblock_reserve (elfcorehdr_addr, elfcorehdr_size); +if (memblock_reserve (elfcorehdr_addr, elfcorehdr_size)) { +pr_warn ("Failed to reserve memory for elfcorehdr\n" ); +return ; + }pr_info ("Reserving %llu KiB of memory at 0x%llx for elfcorehdr\n" , elfcorehdr_size >>10 , elfcorehdr_addr);
Signature · 1 line
2.43.0
PATCH 3/3 MIPS: fix misleading elfcorehdr reservation success message
In reply to Sang-Heon Jeonmips_reserve_vmcore() does not check the return value of memblock_reserve(), so a success message is falsely printed when the reservation fails.
Reserve before printing the success message. Check the return value and warn on failure instead.
--- arch/mips/kernel/setup.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
arch/mips/kernel/setup.c +5 -2
@@ -437,10 +437,13 @@ static void __init mips_reserve_vmcore(void) } } +if (memblock_reserve (elfcorehdr_addr, elfcorehdr_size)) { +pr_warn ("Failed to reserve memory for kdump\n" ); +return ; + } +pr_info ("Reserving %ldKB of memory at %ldKB for kdump\n" , (unsigned long )elfcorehdr_size >>10 , (unsigned long )elfcorehdr_addr >>10 ); - -memblock_reserve (elfcorehdr_addr, elfcorehdr_size);#endif }
Signature · 1 line
2.43.0