treewide: remove unreachable memblock_reserve() return value checks in early boot
Subsystems (6)
v2 cover treewide: remove unreachable memblock_reserve() return value checks in early boot
memblock_reserve() can only return an error after memblock_allow_resize() has been called. Before that it either succeeds or panics, never returning an error.
Before memblock_allow_resize() is called, the return value checks of memblock_reserve() are unreachable and can be removed.
All the 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.
---
Changes from v1 [1]
- add reviewed-by tag
- rebased onto latest memblock for-next
[1] https://lore.kernel.org/all/[email protected]/
---
Hello Mike,
Like the previous memblock cleanup series, could you review and take this patch series to the memblock tree?
Thank you for taking valuable time.
Best Regards,
Sang-Heon Jeon
---
Sang-Heon Jeon (5):
x86/setup: remove unreachable memblock_reserve() return value check
sh: remove unreachable memblock_reserve() return value check powerpc/fadump: remove unreachable memblock_reserve() return value
checks
xtensa: remove unreachable memblock_reserve() return value checks Revert "tpm: do not ignore memblock_reserve return value"
arch/powerpc/kernel/fadump.c | 14 +++----------- arch/sh/kernel/machine_kexec.c | 7 +------ arch/x86/kernel/setup.c | 7 ++----- arch/xtensa/kernel/setup.c | 13 +++++++------ drivers/firmware/efi/tpm.c | 7 +------ 5 files changed, 14 insertions(+), 34 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/5 x86/setup: remove unreachable memblock_reserve() return value check
trim_snb_memory() runs from early_reserve_memory() in setup_arch(), before e820__memblock_setup() calls memblock_allow_resize(). At that point memblock_reserve() either succeeds or panics, never returning an error.
Therefore the return value check is unreachable, so remove it and the related logic.
No functional change.
--- arch/x86/kernel/setup.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
arch/x86/kernel/setup.c +2 -5
@@ -742,11 +742,8 @@ static void __init trim_snb_memory(void)* setup_arch(), so there is no need to reserve it here. */ -for (i =0 ; i <ARRAY_SIZE (bad_pages); i++) { -if (memblock_reserve (bad_pages[i],PAGE_SIZE )) -printk (KERN_WARNING "failed to reserve 0x%08lx\n" , - bad_pages[i]); - } +for (i =0 ; i <ARRAY_SIZE (bad_pages); i++) +memblock_reserve (bad_pages[i],PAGE_SIZE ); }static void __init trim_bios_range (void )
Signature · 1 line
2.43.0
PATCH v2 2/5 sh: remove unreachable memblock_reserve() return value check
In reply to Sang-Heon Jeonreserve_crashkernel() runs from early_reserve_mem() in paging_init(), before the same function calls memblock_allow_resize(). At that point memblock_reserve() either succeeds or panics, never returning an error.
Therefore the return value check is unreachable, so remove it and the related logic.
No functional change.
--- arch/sh/kernel/machine_kexec.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
arch/sh/kernel/machine_kexec.c +1 -6
@@ -165,12 +165,7 @@ void __init reserve_crashkernel(void) goto disable; } }else { - ret =memblock_reserve (crashk_res.start, crash_size); -if (unlikely (ret <0 )) { -pr_err ("crashkernel reservation failed - " -"memory is in use\n" ); - goto disable; - } +memblock_reserve (crashk_res.start, crash_size); } crashk_res.end = crashk_res.start + crash_size -1 ;
Signature · 1 line
2.43.0
PATCH v2 3/5 powerpc/fadump: remove unreachable memblock_reserve() return value checks
In reply to Sang-Heon Jeonfadump_append_bootargs() and fadump_reserve_mem() both run from early_init_devtree(), before it calls memblock_allow_resize(). At that point memblock_reserve() either succeeds or panics, never returning an error.
Therefore the return value checks are unreachable, so remove them and the related logic.
No functional change.
--- arch/powerpc/kernel/fadump.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)
arch/powerpc/kernel/fadump.c +3 -11
@@ -154,13 +154,8 @@ void __init fadump_append_bootargs(void)if (!fw_dump.dump_active || !fw_dump.param_area_supported || !fw_dump.param_area)return ; -if (fw_dump.param_area < fw_dump.boot_mem_top) { -if (memblock_reserve (fw_dump.param_area,COMMAND_LINE_SIZE )) { -pr_warn ("WARNING: Can't use additional parameters area!\n" ); - fw_dump.param_area =0 ; -return ; - } - } +if (fw_dump.param_area < fw_dump.boot_mem_top) +memblock_reserve (fw_dump.param_area,COMMAND_LINE_SIZE ); append_args = (char *)fw_dump.param_area; len =strlen (boot_command_line);
@@ -632,10 +627,7 @@ int __init fadump_reserve_mem(void) (fw_dump.ops->fadump_setup_metadata(&fw_dump) < 0)) goto error_out; -if (memblock_reserve (base, size)) { -pr_err ("Failed to reserve memory!\n" ); - goto error_out; - } +memblock_reserve (base, size);pr_info ("Reserved %lldMB of memory at %#016llx (System RAM: %lldMB)\n" , (size >>20 ), base, (memblock_phys_mem_size () >>20 ));
Signature · 1 line
2.43.0
PATCH v2 4/5 xtensa: remove unreachable memblock_reserve() return value checks
In reply to Sang-Heon Jeonmem_reserve() wraps memblock_reserve(), and its callers check the return value. xtensa never calls memblock_allow_resize(), so memblock_reserve() either succeeds or panics, never returning an error.
Therefore the return value checks are unreachable, so remove them and make mem_reserve() return void.
No functional change.
--- arch/xtensa/kernel/setup.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
arch/xtensa/kernel/setup.c +7 -6
@@ -268,10 +268,10 @@ void __init init_arch(bp_tag_t *bp_start)* Initialize system. Setup memory and reserve regions. */ -static inline int __init_memblock mem_reserve(unsigned long start, -unsigned long end) +static inline void __init_memblock mem_reserve(unsigned long start, +unsigned long end) { -return memblock_reserve (start, end - start); +memblock_reserve (start, end - start); }void __init setup_arch (char **cmdline_p)
@@ -290,11 +290,12 @@ void __init setup_arch(char **cmdline_p)/* Reserve some memory regions */ #ifdef CONFIG_BLK_DEV_INITRD -if (initrd_start < initrd_end && - !mem_reserve (__pa (initrd_start),__pa (initrd_end))) +if (initrd_start < initrd_end) { +mem_reserve (__pa (initrd_start),__pa (initrd_end)); initrd_below_start_ok =1 ; -else + }else { initrd_start =0 ; + }#endif mem_reserve (__pa (_stext),__pa (_end));
Signature · 1 line
2.43.0
PATCH v2 5/5 Revert "tpm: do not ignore memblock_reserve return value"
In reply to Sang-Heon JeonThis reverts commit c33c28f9f6e017702374e1ab907dfa5a63db5301.
efi_tpm_eventlog_init() runs from efi_config_parse_tables() during early EFI initialization, before memblock_allow_resize(). At that point memblock_reserve() either succeeds or panics, never returning an error.
Therefore the return value check is unreachable, so restore the original unconditional memblock_reserve().
No functional change.
--- drivers/firmware/efi/tpm.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/firmware/efi/tpm.c +1 -6
@@ -61,12 +61,7 @@ int __init efi_tpm_eventlog_init(void) } tbl_size =sizeof (*log_tbl) + log_tbl->size; -if (memblock_reserve (efi.tpm_log, tbl_size)) { -pr_err ("TPM Event Log memblock reserve fails (0x%lx, 0x%x)\n" , - efi.tpm_log, tbl_size); - ret = -ENOMEM ; - goto out; - } +memblock_reserve (efi.tpm_log, tbl_size);if (efi.tpm_final_log ==EFI_INVALID_TABLE_ADDR ) {pr_info ("TPM Final Events table not present\n" );
Signature · 1 line
2.43.0
Hi Sang-Heon,
Quoted 6 lines · Sang-Heon Jeon
memblock_reserve()can only return an error aftermemblock_allow_resize()has been called. Before that it either succeeds or panics, never returning an error.Before
memblock_allow_resize()is called, the return value checks ofmemblock_reserve()are unreachable and can be removed.
I'd rather keep these checks.
Removing them relies on internal details of memblock_reserve() implementation and the existing event sequence. If the code would move around relying on panic in memblock_reserve() may not be correct.
And the few bytes and cycles the change saves do not worth the churn.
Signature · 2 lines
Sincerely yours, Mike.
Hi Mike,
Quoted 11 lines · Mike Rapoport
Hi Sang-Heon,
Quoted 6 lines · Sang-Heon Jeon
memblock_reserve()can only return an error aftermemblock_allow_resize()has been called. Before that it either succeeds or panics, never returning an error.Before
memblock_allow_resize()is called, the return value checks ofmemblock_reserve()are unreachable and can be removed.
Quoted 7 lines
I'd rather keep these checks.
Removing them relies on internal details of
memblock_reserve()implementation and the existing event sequence. If the code would move around relying on panic inmemblock_reserve()may not be correct.And the few bytes and cycles the change saves do not worth the churn.
Makes sense to me.
But most early boot callers of memblock_reserve() don't check the return value, so I thought we already rely on its internal behavior anyway. So the few remaining checks just looked a bit inconsistent to me.
Would you still prefer to keep these checks? If so, I'm fine with dropping this patch series. It's not a big deal :)
Thank you for taking the time to review this series.
Quoted 3 lines
--
Sincerely yours,
Mike.
Best Regards,
Sang-Heon Jeon
Quoted 20 lines · Sang-Heon Jeon
Hi Mike,
Quoted 17 lines · Mike Rapoport
Hi Sang-Heon,
Quoted 6 lines · Sang-Heon Jeon
memblock_reserve()can only return an error aftermemblock_allow_resize()has been called. Before that it either succeeds or panics, never returning an error.Before
memblock_allow_resize()is called, the return value checks ofmemblock_reserve()are unreachable and can be removed.I'd rather keep these checks.
Removing them relies on internal details of
memblock_reserve()implementation and the existing event sequence. If the code would move around relying on panic inmemblock_reserve()may not be correct.
Quoted 8 lines
Quoted 1 line
And the few bytes and cycles the change saves do not worth the churn.
Makes sense to me.
But most early boot callers of
memblock_reserve()don't check the return value, so I thought we already rely on its internal behavior anyway. So the few remaining checks just looked a bit inconsistent to me.
In reality it's very unlikely for memblock_reserve() to fail, especially after resize is allowed.
And if it does fail, the system would trip on a memory error, usually sooner than later.
Quoted 2 lines
Would you still prefer to keep these checks? If so, I'm fine with dropping this patch series. It's not a big deal :)
Let's keep the checks as they are now.
Quoted 2 lines
Best Regards,
Sang-Heon Jeon
Signature · 2 lines
Sincerely yours, Mike.