All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pratyush Yadav <pratyush@kernel.org>
To: Usama Arif <usamaarif642@gmail.com>
Cc: rppt@kernel.org,  Andrew Morton <akpm@linux-foundation.org>,
	kas@kernel.org,  changyuanl@google.com,  graf@amazon.com,
	leitao@debian.org,  thevlad@meta.com,  pratyush@kernel.org,
	dave.hansen@linux.intel.com,  linux-mm@kvack.org,
	linux-kernel@vger.kernel.org,  kernel-team@meta.com
Subject: Re: [PATCH v2 2/2] mm/memblock: only mark/clear KHO scratch memory when needed
Date: Thu, 27 Nov 2025 22:37:55 +0100	[thread overview]
Message-ID: <867bvbyx58.fsf@kernel.org> (raw)
In-Reply-To: <20251127203724.3177621-3-usamaarif642@gmail.com> (Usama Arif's message of "Thu, 27 Nov 2025 20:33:20 +0000")

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@meta.com>
> Signed-off-by: Usama Arif <usamaarif642@gmail.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@kernel.org>

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

-- 
Regards,
Pratyush Yadav


  parent reply	other threads:[~2025-11-27 21:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-27 20:33 [PATCH v2 0/2] mm: only mark/clear KHO scratch memory when needed Usama Arif
2025-11-27 20:33 ` [PATCH v2 1/2] mm/memblock: remove CONFIG_MEMBLOCK_KHO_SCRATCH option Usama Arif
2025-11-27 21:23   ` Pratyush Yadav
2025-11-28 11:57   ` Kiryl Shutsemau
2025-11-27 20:33 ` [PATCH v2 2/2] mm/memblock: only mark/clear KHO scratch memory when needed Usama Arif
2025-11-27 20:55   ` Andrew Morton
2025-11-27 21:04     ` Usama Arif
2025-11-27 21:30       ` Pratyush Yadav
2025-11-27 21:37   ` Pratyush Yadav [this message]
2025-11-28  8:26   ` Mike Rapoport

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=867bvbyx58.fsf@kernel.org \
    --to=pratyush@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=changyuanl@google.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=graf@amazon.com \
    --cc=kas@kernel.org \
    --cc=kernel-team@meta.com \
    --cc=leitao@debian.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=rppt@kernel.org \
    --cc=thevlad@meta.com \
    --cc=usamaarif642@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.