* [PATCH v2 0/2] mm: only mark/clear KHO scratch memory when needed
@ 2025-11-27 20:33 Usama Arif
2025-11-27 20:33 ` [PATCH v2 1/2] mm/memblock: remove CONFIG_MEMBLOCK_KHO_SCRATCH option Usama Arif
2025-11-27 20:33 ` [PATCH v2 2/2] mm/memblock: only mark/clear KHO scratch memory when needed Usama Arif
0 siblings, 2 replies; 10+ messages in thread
From: Usama Arif @ 2025-11-27 20:33 UTC (permalink / raw)
To: rppt, Andrew Morton
Cc: kas, changyuanl, graf, leitao, thevlad, pratyush, dave.hansen,
linux-mm, linux-kernel, kernel-team, Usama Arif
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.
CONFIG_MEMBLOCK_KHO_SCRATCH is also removed as its only selected
by KEXEC_HANDOVER.
v1 -> v2:
- Remove CONFIG_MEMBLOCK_KHO_SCRATCH (Kiryl Shutsemau)
- Move memblock_mark/clear_kho_scratch under alread existing
CONFIG_KEXEC_HANDOVER in memblock.c.
Usama Arif (2):
mm/memblock: remove CONFIG_MEMBLOCK_KHO_SCRATCH option
mm/memblock: only mark/clear KHO scratch memory when needed
include/linux/memblock.h | 2 +-
kernel/Kconfig.kexec | 1 -
mm/Kconfig | 4 ---
mm/memblock.c | 78 +++++++++++++++++++++++-----------------
4 files changed, 47 insertions(+), 38 deletions(-)
--
2.47.3
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 1/2] mm/memblock: remove CONFIG_MEMBLOCK_KHO_SCRATCH option
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 ` 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
1 sibling, 2 replies; 10+ messages in thread
From: Usama Arif @ 2025-11-27 20:33 UTC (permalink / raw)
To: rppt, Andrew Morton
Cc: kas, changyuanl, graf, leitao, thevlad, pratyush, dave.hansen,
linux-mm, linux-kernel, kernel-team, Usama Arif
The only defconfig that selects this is CONFIG_KEXEC_HANDOVER.
Replace CONFIG_MEMBLOCK_KHO_SCRATCH with CONFIG_KEXEC_HANDOVER
to simplify code.
No functional change intended.
Suggested-by: Kiryl Shutsemau <kas@kernel.org>
Signed-off-by: Usama Arif <usamaarif642@gmail.com>
---
include/linux/memblock.h | 2 +-
kernel/Kconfig.kexec | 1 -
mm/Kconfig | 4 ----
mm/memblock.c | 4 ++--
4 files changed, 3 insertions(+), 8 deletions(-)
diff --git a/include/linux/memblock.h b/include/linux/memblock.h
index 221118b5a16e1..8bd9bcaccceb8 100644
--- a/include/linux/memblock.h
+++ b/include/linux/memblock.h
@@ -611,7 +611,7 @@ static inline void early_memtest(phys_addr_t start, phys_addr_t end) { }
static inline void memtest_report_meminfo(struct seq_file *m) { }
#endif
-#ifdef CONFIG_MEMBLOCK_KHO_SCRATCH
+#ifdef CONFIG_KEXEC_HANDOVER
void memblock_set_kho_scratch_only(void);
void memblock_clear_kho_scratch_only(void);
void memmap_init_kho_scratch_pages(void);
diff --git a/kernel/Kconfig.kexec b/kernel/Kconfig.kexec
index 54e5810726176..06a7c43652cfd 100644
--- a/kernel/Kconfig.kexec
+++ b/kernel/Kconfig.kexec
@@ -98,7 +98,6 @@ config KEXEC_HANDOVER
bool "kexec handover"
depends on ARCH_SUPPORTS_KEXEC_HANDOVER && ARCH_SUPPORTS_KEXEC_FILE
depends on !DEFERRED_STRUCT_PAGE_INIT
- select MEMBLOCK_KHO_SCRATCH
select KEXEC_FILE
select DEBUG_FS
select LIBFDT
diff --git a/mm/Kconfig b/mm/Kconfig
index bd0ea5454af82..6d6002f57c18f 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -442,10 +442,6 @@ config HAVE_GUP_FAST
depends on MMU
bool
-# Enable memblock support for scratch memory which is needed for kexec handover
-config MEMBLOCK_KHO_SCRATCH
- bool
-
# Don't discard allocated memory used to track "memory" and "reserved" memblocks
# after early boot, so it can still be used to test for validity of memory.
# Also, memblocks are updated with memory hot(un)plug.
diff --git a/mm/memblock.c b/mm/memblock.c
index e23e16618e9b3..8b13d5c28922a 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -112,7 +112,7 @@ unsigned long min_low_pfn;
unsigned long max_pfn;
unsigned long long max_possible_pfn;
-#ifdef CONFIG_MEMBLOCK_KHO_SCRATCH
+#ifdef CONFIG_KEXEC_HANDOVER
/* When set to true, only allocate from MEMBLOCK_KHO_SCRATCH ranges */
static bool kho_scratch_only;
#else
@@ -948,7 +948,7 @@ int __init_memblock memblock_physmem_add(phys_addr_t base, phys_addr_t size)
}
#endif
-#ifdef CONFIG_MEMBLOCK_KHO_SCRATCH
+#ifdef CONFIG_KEXEC_HANDOVER
__init void memblock_set_kho_scratch_only(void)
{
kho_scratch_only = true;
--
2.47.3
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 2/2] mm/memblock: only mark/clear KHO scratch memory when needed
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 20:33 ` Usama Arif
2025-11-27 20:55 ` Andrew Morton
` (2 more replies)
1 sibling, 3 replies; 10+ messages in thread
From: Usama Arif @ 2025-11-27 20:33 UTC (permalink / raw)
To: rppt, Andrew Morton
Cc: kas, changyuanl, graf, leitao, thevlad, pratyush, dave.hansen,
linux-mm, linux-kernel, kernel-team, Usama Arif
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;
+}
#endif /* CONFIG_KEXEC_HANDOVER */
/*
--
2.47.3
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 2/2] mm/memblock: only mark/clear KHO scratch memory when needed
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:37 ` Pratyush Yadav
2025-11-28 8:26 ` Mike Rapoport
2 siblings, 1 reply; 10+ messages in thread
From: Andrew Morton @ 2025-11-27 20:55 UTC (permalink / raw)
To: Usama Arif
Cc: rppt, kas, changyuanl, graf, leitao, thevlad, pratyush,
dave.hansen, linux-mm, linux-kernel, kernel-team
On Thu, 27 Nov 2025 20:33:20 +0000 Usama Arif <usamaarif642@gmail.com> 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.
What effect does this change have? Lessened memory consumption,
presumably. Of what magnitude and for what time period?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 2/2] mm/memblock: only mark/clear KHO scratch memory when needed
2025-11-27 20:55 ` Andrew Morton
@ 2025-11-27 21:04 ` Usama Arif
2025-11-27 21:30 ` Pratyush Yadav
0 siblings, 1 reply; 10+ messages in thread
From: Usama Arif @ 2025-11-27 21:04 UTC (permalink / raw)
To: Andrew Morton
Cc: rppt, kas, changyuanl, graf, leitao, thevlad, pratyush,
dave.hansen, linux-mm, linux-kernel, kernel-team
On 27/11/2025 20:55, Andrew Morton wrote:
> On Thu, 27 Nov 2025 20:33:20 +0000 Usama Arif <usamaarif642@gmail.com> 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.
>
> What effect does this change have? Lessened memory consumption,
> presumably. Of what magnitude and for what time period?
For some context, this came out of https://lore.kernel.org/all/ba690e06-c2a1-4d2e-9428-9ca2ea9f2b86@gmail.com/
(I should have probably added that in the commit message..)
We are experiencing several warnings a day in meta fleet due to a warning introduced
in that patch. We dont have CONFIG_KEXEC_HANDOVER enabled in the fleet. The IMA memory
seems to conincide with the 1st MB, but as Mike pointed out they are different arrays
so this scratch memory is likely not a cause of the warnings. But it is not useful (and
was a bit confusing) seeing KHO scratch memory being marked even when KHO is disabled.
The imapct is as you said, but its only marked for a very short period of time.
I think a better reason for this patch is just to not mark the memory at all when KHO
is disabled (or not in use) for clarity.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 1/2] mm/memblock: remove CONFIG_MEMBLOCK_KHO_SCRATCH option
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
1 sibling, 0 replies; 10+ messages in thread
From: Pratyush Yadav @ 2025-11-27 21:23 UTC (permalink / raw)
To: Usama Arif
Cc: rppt, Andrew Morton, kas, changyuanl, graf, leitao, thevlad,
pratyush, dave.hansen, linux-mm, linux-kernel, kernel-team
On Thu, Nov 27 2025, Usama Arif wrote:
> The only defconfig that selects this is CONFIG_KEXEC_HANDOVER.
> Replace CONFIG_MEMBLOCK_KHO_SCRATCH with CONFIG_KEXEC_HANDOVER
> to simplify code.
> No functional change intended.
>
> Suggested-by: Kiryl Shutsemau <kas@kernel.org>
> Signed-off-by: Usama Arif <usamaarif642@gmail.com>
Reviewed-by: Pratyush Yadav <pratyush@kernel.org>
[...]
--
Regards,
Pratyush Yadav
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 2/2] mm/memblock: only mark/clear KHO scratch memory when needed
2025-11-27 21:04 ` Usama Arif
@ 2025-11-27 21:30 ` Pratyush Yadav
0 siblings, 0 replies; 10+ messages in thread
From: Pratyush Yadav @ 2025-11-27 21:30 UTC (permalink / raw)
To: Usama Arif
Cc: Andrew Morton, rppt, kas, changyuanl, graf, leitao, thevlad,
pratyush, dave.hansen, linux-mm, linux-kernel, kernel-team
On Thu, Nov 27 2025, Usama Arif wrote:
> On 27/11/2025 20:55, Andrew Morton wrote:
>> On Thu, 27 Nov 2025 20:33:20 +0000 Usama Arif <usamaarif642@gmail.com> 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.
>>
>> What effect does this change have? Lessened memory consumption,
>> presumably. Of what magnitude and for what time period?
>
> For some context, this came out of https://lore.kernel.org/all/ba690e06-c2a1-4d2e-9428-9ca2ea9f2b86@gmail.com/
> (I should have probably added that in the commit message..)
> We are experiencing several warnings a day in meta fleet due to a warning introduced
> in that patch. We dont have CONFIG_KEXEC_HANDOVER enabled in the fleet. The IMA memory
> seems to conincide with the 1st MB, but as Mike pointed out they are different arrays
> so this scratch memory is likely not a cause of the warnings. But it is not useful (and
> was a bit confusing) seeing KHO scratch memory being marked even when KHO is disabled.
Yeah, it is not yet clear if this is really the root cause for your
issue.
>
> The imapct is as you said, but its only marked for a very short period of time.
> I think a better reason for this patch is just to not mark the memory at all when KHO
> is disabled (or not in use) for clarity.
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.
--
Regards,
Pratyush Yadav
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 2/2] mm/memblock: only mark/clear KHO scratch memory when needed
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:37 ` Pratyush Yadav
2025-11-28 8:26 ` Mike Rapoport
2 siblings, 0 replies; 10+ messages in thread
From: Pratyush Yadav @ 2025-11-27 21:37 UTC (permalink / raw)
To: Usama Arif
Cc: rppt, Andrew Morton, kas, changyuanl, graf, leitao, thevlad,
pratyush, dave.hansen, linux-mm, linux-kernel, kernel-team
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 2/2] mm/memblock: only mark/clear KHO scratch memory when needed
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:37 ` Pratyush Yadav
@ 2025-11-28 8:26 ` Mike Rapoport
2 siblings, 0 replies; 10+ messages in thread
From: Mike Rapoport @ 2025-11-28 8:26 UTC (permalink / raw)
To: Usama Arif
Cc: Andrew Morton, kas, changyuanl, graf, leitao, thevlad, pratyush,
dave.hansen, linux-mm, linux-kernel, kernel-team
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@kernel.org/:
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@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);
> -}
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.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 1/2] mm/memblock: remove CONFIG_MEMBLOCK_KHO_SCRATCH option
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
1 sibling, 0 replies; 10+ messages in thread
From: Kiryl Shutsemau @ 2025-11-28 11:57 UTC (permalink / raw)
To: Usama Arif
Cc: rppt, Andrew Morton, changyuanl, graf, leitao, thevlad, pratyush,
dave.hansen, linux-mm, linux-kernel, kernel-team
On Thu, Nov 27, 2025 at 08:33:19PM +0000, Usama Arif wrote:
> The only defconfig that selects this is CONFIG_KEXEC_HANDOVER.
defconfig? Maybe "config option"?
> Replace CONFIG_MEMBLOCK_KHO_SCRATCH with CONFIG_KEXEC_HANDOVER
> to simplify code.
> No functional change intended.
>
> Suggested-by: Kiryl Shutsemau <kas@kernel.org>
> Signed-off-by: Usama Arif <usamaarif642@gmail.com>
Reviewed-by: Kiryl Shutsemau <kas@kernel.org>
--
Kiryl Shutsemau / Kirill A. Shutemov
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2025-11-28 11:57 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2025-11-28 8:26 ` Mike Rapoport
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox