mm/memblock: only mark/clear KHO scratch memory when needed
PATCH 1/1 mm/memblock: only mark/clear KHO scratch memory when needed
The scratch memory for kexec handover is used to bootstrap the kexec'ed kernel. It is only needed when CONFIG_MEMBLOCK_KHO_SCRATCH is enabled (selected by KHO) and if it is a KHO boot. Add checks to prevent marking a KHO scratch region unless needed.
kexec_handover.h is now unconditionally included for is_kho_boot.
--- mm/memblock.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
mm/memblock.c +11 -5
@@ -20,8 +20,8 @@#ifdef CONFIG_KEXEC_HANDOVER #include <linux/libfdt.h> -#include <linux/kexec_handover.h> #endif /* CONFIG_KEXEC_HANDOVER */ +#include <linux/kexec_handover.h> #include <asm/sections.h> #include <linux/io.h>
@@ -1126,8 +1126,11 @@ int __init_memblock memblock_reserved_mark_noinit(phys_addr_t base, phys_addr_t*/ __init int memblock_mark_kho_scratch (phys_addr_t base,phys_addr_t size) { -return memblock_setclr_flag (&memblock.memory, base, size,1 , -MEMBLOCK_KHO_SCRATCH ); +if (IS_ENABLED (CONFIG_MEMBLOCK_KHO_SCRATCH ) &&is_kho_boot ()) +return memblock_setclr_flag (&memblock.memory, base, size,1 , +MEMBLOCK_KHO_SCRATCH ); +else +return 0 ; }/**
@@ -1140,8 +1143,11 @@ __init int memblock_mark_kho_scratch(phys_addr_t base, phys_addr_t size)*/ __init int memblock_clear_kho_scratch (phys_addr_t base,phys_addr_t size) { -return memblock_setclr_flag (&memblock.memory, base, size,0 , -MEMBLOCK_KHO_SCRATCH ); +if (IS_ENABLED (CONFIG_MEMBLOCK_KHO_SCRATCH ) &&is_kho_boot ()) +return memblock_setclr_flag (&memblock.memory, base, size,0 , +MEMBLOCK_KHO_SCRATCH ); +else +return 0 ; } static bool should_skip_region(struct memblock_type *type,
Signature · 1 line
2.47.3
mm/memblock.c int __init_memblock memblock_reserved_mark_noinit(phys_addr_t base, phys_addr_t · line 1129
Quoted 7 lines · Usama Arif
mm/memblock.c +1
-2@@ -1126,8 +1126,11 @@ int __init_memblock memblock_reserved_mark_noinit(phys_addr_t base, phys_addr_t*/ __init int memblock_mark_kho_scratch (phys_addr_t base,phys_addr_t size) { -return memblock_setclr_flag (&memblock.memory, base, size,1 , -MEMBLOCK_KHO_SCRATCH ); +if (IS_ENABLED (CONFIG_MEMBLOCK_KHO_SCRATCH ) &&is_kho_boot ())
It makes me wounder why CONFIG_MEMBLOCK_KHO_SCRATCH exists? It seems to be a proxy for CONFIG_KEXEC_HANDOVER which is the only option that selects it and does it always.
Can we make s/CONFIG_MEMBLOCK_KHO_SCRATCH/CONFIG_KEXEC_HANDOVER/ and remove IS_ENABLED() from this check? Just is_kho_boot() is enough.
Signature · 1 line
Kiryl Shutsemau / Kirill A. Shutemov
Quoted 13 lines · Kiryl Shutsemau
mm/memblock.c int __init_memblock memblock_reserved_mark_noinit(phys_addr_t base, phys_addr_t · line 1129
Quoted 7 lines · Usama Arif
mm/memblock.c +1
-2@@ -1126,8 +1126,11 @@ int __init_memblock memblock_reserved_mark_noinit(phys_addr_t base, phys_addr_t*/ __init int memblock_mark_kho_scratch (phys_addr_t base,phys_addr_t size) { -return memblock_setclr_flag (&memblock.memory, base, size,1 , -MEMBLOCK_KHO_SCRATCH ); +if (IS_ENABLED (CONFIG_MEMBLOCK_KHO_SCRATCH ) &&is_kho_boot ())It makes me wounder why
CONFIG_MEMBLOCK_KHO_SCRATCHexists? It seems to be a proxy forCONFIG_KEXEC_HANDOVERwhich is the only option that selects it and does it always.
Quoted 4 lines
Can we make s/CONFIG_MEMBLOCK_KHO_SCRATCH/CONFIG_KEXEC_HANDOVER/ and remove
IS_ENABLED()from this check? Justis_kho_boot()is enough.
Thats a very good point! I imagine it might have been for maybe debug purposes?
Looking at the code, CONFIG_MEMBLOCK_KHO_SCRATCH shouldnt be needed. I guess this might be a good time to clean it up. If Mike is happy for it to be replaced with CONFIG_KEXEC_HANDOVER (and removed where needed), happy to send that for review instead of this.
Thanks
Usama
Mike Rapoport
maintainerQuoted 20 lines · Usama Arif
Quoted 13 lines · Kiryl Shutsemau
mm/memblock.c int __init_memblock memblock_reserved_mark_noinit(phys_addr_t base, phys_addr_t · line 1129
Quoted 7 lines · Usama Arif
mm/memblock.c +1
-2@@ -1126,8 +1126,11 @@ int __init_memblock memblock_reserved_mark_noinit(phys_addr_t base, phys_addr_t*/ __init int memblock_mark_kho_scratch (phys_addr_t base,phys_addr_t size) { -return memblock_setclr_flag (&memblock.memory, base, size,1 , -MEMBLOCK_KHO_SCRATCH ); +if (IS_ENABLED (CONFIG_MEMBLOCK_KHO_SCRATCH ) &&is_kho_boot ())It makes me wounder why
CONFIG_MEMBLOCK_KHO_SCRATCHexists? It seems to be a proxy forCONFIG_KEXEC_HANDOVERwhich is the only option that selects it and does it always.Quoted 4 lines
Can we make s/CONFIG_MEMBLOCK_KHO_SCRATCH/CONFIG_KEXEC_HANDOVER/ and remove
IS_ENABLED()from this check? Justis_kho_boot()is enough.
Quoted 6 lines
Thats a very good point! I imagine it might have been for maybe debug purposes?
Looking at the code,
CONFIG_MEMBLOCK_KHO_SCRATCHshouldnt be needed. I guess this might be a good time to clean it up. If Mike is happy for it to be replaced withCONFIG_KEXEC_HANDOVER(and removed where needed), happy to send that for review instead of this.
Yeah, let's kill CONFIG_MEMBLOCK_KHO_SCRATCH and use CONFIG_KEXEC_HANDOVER where needed.IS_ENABLED() is not needed in the check because with CONFIG_MEMBLOCK_KHO_SCRATCH=n both mark_kho_scratch() and clear_kho_scratch() are empty stubs, so it's enough to check is_kho_boot().
Quoted 2 lines
Thanks
Usama
Signature · 2 lines
Sincerely yours, Mike.
Mike Rapoport
maintainerQuoted 29 lines · Usama Arif
The scratch memory for kexec handover is used to bootstrap the kexec'ed kernel. It is only needed when
CONFIG_MEMBLOCK_KHO_SCRATCHis enabled (selected by KHO) and if it is a KHO boot. Add checks to prevent marking a KHO scratch region unless needed.
kexec_handover.his now unconditionally included foris_kho_boot.Fixes a2daf83e10378 ("x86/e820: temporarily enable KHO scratch for memory below 1M")Reported-by Vlad Poenaru <[email protected]>Signed-off-by Usama Arif <[email protected]>--- mm/memblock.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)mm/memblock.c +1
-1@@ -20,8 +20,8 @@#ifdef CONFIG_KEXEC_HANDOVER #include <linux/libfdt.h> -#include <linux/kexec_handover.h> #endif /* CONFIG_KEXEC_HANDOVER */ +#include <linux/kexec_handover.h> #include <asm/sections.h> #include <linux/io.h>
mm/memblock.c int __init_memblock memblock_reserved_mark_noinit(phys_addr_t base, phys_addr_t · line 1132
Quoted 9 lines
mm/memblock.c +4
-2@@ -1126,8 +1126,11 @@ int __init_memblock memblock_reserved_mark_noinit(phys_addr_t base, phys_addr_t*/ __init int memblock_mark_kho_scratch (phys_addr_t base,phys_addr_t size) { -return memblock_setclr_flag (&memblock.memory, base, size,1 , -MEMBLOCK_KHO_SCRATCH ); +if (IS_ENABLED (CONFIG_MEMBLOCK_KHO_SCRATCH ) &&is_kho_boot ()) +return memblock_setclr_flag (&memblock.memory, base, size,1 , +MEMBLOCK_KHO_SCRATCH ); +else
else is not needed.
Quoted 5 lines
mm/memblock.c +1
-0+return 0 ; }/**
mm/memblock.c __init int memblock_mark_kho_scratch(phys_addr_t base, phys_addr_t size) · line 1149
Quoted 9 lines
mm/memblock.c +4
-2@@ -1140,8 +1143,11 @@ __init int memblock_mark_kho_scratch(phys_addr_t base, phys_addr_t size)*/ __init int memblock_clear_kho_scratch (phys_addr_t base,phys_addr_t size) { -return memblock_setclr_flag (&memblock.memory, base, size,0 , -MEMBLOCK_KHO_SCRATCH ); +if (IS_ENABLED (CONFIG_MEMBLOCK_KHO_SCRATCH ) &&is_kho_boot ()) +return memblock_setclr_flag (&memblock.memory, base, size,0 , +MEMBLOCK_KHO_SCRATCH ); +else
Ditto.
Quoted 7 lines
mm/memblock.c +1
-0+return 0 ; } static bool should_skip_region(struct memblock_type *type,Signature · 1 line
2.47.3
Signature · 2 lines
Sincerely yours, Mike.