lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <867bvbyx58.fsf@kernel.org>
Date: Thu, 27 Nov 2025 22:37:55 +0100
From: Pratyush Yadav <pratyush@...nel.org>
To: Usama Arif <usamaarif642@...il.com>
Cc: rppt@...nel.org,  Andrew Morton <akpm@...ux-foundation.org>,
  kas@...nel.org,  changyuanl@...gle.com,  graf@...zon.com,
  leitao@...ian.org,  thevlad@...a.com,  pratyush@...nel.org,
  dave.hansen@...ux.intel.com,  linux-mm@...ck.org,
  linux-kernel@...r.kernel.org,  kernel-team@...a.com
Subject: Re: [PATCH v2 2/2] mm/memblock: only mark/clear KHO scratch memory
 when needed

On Thu, Nov 27 2025, 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.
>
> Fixes: a2daf83e10378 ("x86/e820: temporarily enable KHO scratch for memory below 1M")
> Reported-by: Vlad Poenaru <thevlad@...a.com>
> Signed-off-by: Usama Arif <usamaarif642@...il.com>
> ---
>  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);
> -}
> -
>  static bool should_skip_region(struct memblock_type *type,
>  			       struct memblock_region *m,
>  			       int nid, int flags)
> @@ -2617,12 +2587,56 @@ static bool __init reserve_mem_kho_revive(const char *name, phys_addr_t size,
>  
>  	return true;
>  }
> +
> +/**
> + * 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)
> +{
> +	if (is_kho_boot())
> +		return memblock_setclr_flag(&memblock.memory, base, size, 1,
> +					    MEMBLOCK_KHO_SCRATCH);
> +	return 0;
> +}
> +
> +/**
> + * 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)
> +{
> +	if (is_kho_boot())
> +		return memblock_setclr_flag(&memblock.memory, base, size, 0,
> +					    MEMBLOCK_KHO_SCRATCH);
> +	return 0;
> +}
>  #else
>  static bool __init reserve_mem_kho_revive(const char *name, phys_addr_t size,
>  					  phys_addr_t align)
>  {
>  	return false;
>  }
> +
> +__init int memblock_mark_kho_scratch(phys_addr_t base, phys_addr_t size)
> +{
> +	return 0;
> +}
> +
> +__init int memblock_clear_kho_scratch(phys_addr_t base, phys_addr_t size)
> +{
> +	return 0;
> +}

Nit: I don't think we need the alternate version here. When
CONFIG_KEXEC_HANDOVER is disabled, is_kho_boot() is

	static inline bool is_kho_boot(void)
	{
		return false;
	}

So the above functions work for both cases.

I would prefer to not have two variants, but I don't think it is a
blocker. Up to you.

Reviewed-by: Pratyush Yadav <pratyush@...nel.org>

>  #endif /* CONFIG_KEXEC_HANDOVER */
>  
>  /*

-- 
Regards,
Pratyush Yadav

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ