Re: [PATCH v2 2/2] mm/memblock: only mark/clear KHO scratch memory when needed

From: Mike Rapoport

Date: Fri Nov 28 2025 - 03:26:20 EST


On Thu, Nov 27, 2025 at 08:33:20PM +0000, Usama Arif wrote:
> The scratch memory for kexec handover is used to bootstrap the
> kexec'ed kernel. It is only needed when CONFIG_KEXEC_HANDOVER
> is enabled and only if it is a KHO boot. Add checks to prevent
> marking a KHO scratch region unless needed.

Please add a paragraph along the lines of Pratyush's note from
https://lore.kernel.org/all/86bjknyxgu.fsf@xxxxxxxxxx/:

Yeah, I don't think it will have much of a difference in practice, but I
do think it is a good correctness fix. Marking the lower 1M as scratch
is a hack to get around the limitations with KHO, and we should not be
doing that when KHO isn't involved.

> Fixes: a2daf83e10378 ("x86/e820: temporarily enable KHO scratch for memory below 1M")
> Reported-by: Vlad Poenaru <thevlad@xxxxxxxx>
> Signed-off-by: Usama Arif <usamaarif642@xxxxxxxxx>
> ---
> mm/memblock.c | 74 ++++++++++++++++++++++++++++++---------------------
> 1 file changed, 44 insertions(+), 30 deletions(-)
>
> diff --git a/mm/memblock.c b/mm/memblock.c
> index 8b13d5c28922a..8a2cebcfe0a18 100644
> --- a/mm/memblock.c
> +++ b/mm/memblock.c
> @@ -1114,36 +1114,6 @@ int __init_memblock memblock_reserved_mark_noinit(phys_addr_t base, phys_addr_t
> MEMBLOCK_RSRV_NOINIT);
> }
>
> -/**
> - * memblock_mark_kho_scratch - Mark a memory region as MEMBLOCK_KHO_SCRATCH.
> - * @base: the base phys addr of the region
> - * @size: the size of the region
> - *
> - * Only memory regions marked with %MEMBLOCK_KHO_SCRATCH will be considered
> - * for allocations during early boot with kexec handover.
> - *
> - * Return: 0 on success, -errno on failure.
> - */
> -__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);
> -}
> -
> -/**
> - * memblock_clear_kho_scratch - Clear MEMBLOCK_KHO_SCRATCH flag for a
> - * specified region.
> - * @base: the base phys addr of the region
> - * @size: the size of the region
> - *
> - * Return: 0 on success, -errno on failure.
> - */
> -__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);
> -}

No need to move these functions under #ifdef CONFIG_KEXEC_HANDOVER. We
already have inline stubs when CONFIG_KEXEC_HANDOVER=n in
include/linux/memblock.h

Just add 'if (is_kho_boot())' here and in memblock_mark_kho_scratch().

> static bool should_skip_region(struct memblock_type *type,
> struct memblock_region *m,
> int nid, int flags)

--
Sincerely yours,
Mike.