mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] kho: do not reserve empty per-node bootmem areas
@ 2026-10-14 13:15 Pratyush Yadav
  2026-10-15  8:36 ` Mike Rapoport
  2026-10-15  8:39 ` Mike Rapoport
  0 siblings, 2 replies; 4+ messages in thread
From: Pratyush Yadav @ 2026-10-14 13:15 UTC (permalink / raw)
  To: Mike Rapoport, Pasha Tatashin, Pratyush Yadav, Alexander Graf
  Cc: kexec, linux-mm, linux-kernel, Bing Jiao

From: "Pratyush Yadav (Google)" <pratyush@kernel.org>

Some nodes do not allocate any early boot memory. An example is
hotpluggable nodes with movable_node enabled. So the scratch size for
them ends up being zero. Zero size allocations normally don't play well
with memblock. Memblock returns an address, but then doesn't actually
reserve anything. This address ends up being recorded in kho_bootmem
with a size of 0. In case of hotpluggable nodes with movable_nodes, the
allocation on the node actually fails because memblock refuses to
allocate there, and so KHO fails to initialize.

Skip bootmem reservation for such nodes entirely.

To keep the code more robust, avoid overloading kho_bootmem_cnt. use
max_nr_bootmem to store the size of kho_bootmem array. This ensures that
the location of kho_bootmem_cnt assignment does not affect the cleanup
paths.

Fixes: 3dc92c311498 ("kexec: add Kexec HandOver (KHO) generation helpers")
Reported-by: Bing Jiao <bingjiao@google.com>
Signed-off-by: Pratyush Yadav (Google) <pratyush@kernel.org>
---
 kernel/liveupdate/kexec_handover.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c
index 7018e25e4eda..6f1f55fe3181 100644
--- a/kernel/liveupdate/kexec_handover.c
+++ b/kernel/liveupdate/kexec_handover.c
@@ -831,8 +831,8 @@ bool kho_bootmem_overlap(phys_addr_t phys, size_t size)
  */
 static void __init kho_reserve_bootmem(void)
 {
+	int nid, i = 0, max_nr_bootmem;
 	phys_addr_t addr, size;
-	int nid, i = 0;
 
 	if (!kho_enable)
 		return;
@@ -840,8 +840,8 @@ static void __init kho_reserve_bootmem(void)
 	bootmem_size_update();
 
 	/* FIXME: deal with node hot-plug/remove */
-	kho_bootmem_cnt = nodes_weight(node_states[N_MEMORY]) + 2;
-	size = kho_bootmem_cnt * sizeof(*kho_bootmem);
+	max_nr_bootmem = nodes_weight(node_states[N_MEMORY]) + 2;
+	size = max_nr_bootmem * sizeof(*kho_bootmem);
 	kho_bootmem = memblock_alloc(size, PAGE_SIZE);
 	if (!kho_bootmem) {
 		pr_err("Failed to reserve bootmem array\n");
@@ -882,6 +882,9 @@ static void __init kho_reserve_bootmem(void)
 	 */
 	for_each_node_state(nid, N_MEMORY) {
 		size = bootmem_size_node(nid);
+		if (!size)
+			continue;
+
 		addr = memblock_alloc_range_nid(size, BOOTMEM_ALIGNMENT_BYTES,
 						0, MEMBLOCK_ALLOC_ACCESSIBLE,
 						nid, true);
@@ -895,13 +898,19 @@ static void __init kho_reserve_bootmem(void)
 		i++;
 	}
 
+	/*
+	 * Nodes that needed no bootmem were skipped, so fewer areas than
+	 * initially estimated may have been reserved.
+	 */
+	kho_bootmem_cnt = i;
+
 	return;
 
 err_free_bootmem_areas:
 	for (i--; i >= 0; i--)
 		memblock_phys_free(kho_bootmem[i].addr, kho_bootmem[i].size);
 err_free_bootmem_desc:
-	memblock_free(kho_bootmem, kho_bootmem_cnt * sizeof(*kho_bootmem));
+	memblock_free(kho_bootmem, max_nr_bootmem * sizeof(*kho_bootmem));
 err_disable_kho:
 	pr_warn("Failed to reserve bootmem, disabling kexec handover\n");
 	kho_enable = false;

base-commit: e1fe7daedae7a4a23aca6dbd58e1746750b632dc
-- 
2.56.0.385.gd3acb90ef8-goog


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] kho: do not reserve empty per-node bootmem areas
  2026-10-14 13:15 [PATCH] kho: do not reserve empty per-node bootmem areas Pratyush Yadav
@ 2026-10-15  8:36 ` Mike Rapoport
  2026-10-15 11:08   ` Pratyush Yadav
  2026-10-15  8:39 ` Mike Rapoport
  1 sibling, 1 reply; 4+ messages in thread
From: Mike Rapoport @ 2026-10-15  8:36 UTC (permalink / raw)
  To: Pratyush Yadav
  Cc: Pasha Tatashin, Alexander Graf, kexec, linux-mm, linux-kernel, Bing Jiao

On Wed, Oct 14, 2026 at 03:15:44PM +0200, Pratyush Yadav wrote:
> From: "Pratyush Yadav (Google)" <pratyush@kernel.org>
> 
> Some nodes do not allocate any early boot memory. An example is
> hotpluggable nodes with movable_node enabled. So the scratch size for

                          Let's use the new naming please ^ ;-)

I'll fix it up when applying.

> them ends up being zero. Zero size allocations normally don't play well
> with memblock. Memblock returns an address, but then doesn't actually
> reserve anything. This address ends up being recorded in kho_bootmem
> with a size of 0. In case of hotpluggable nodes with movable_nodes, the
> allocation on the node actually fails because memblock refuses to
> allocate there, and so KHO fails to initialize.
> 
> Skip bootmem reservation for such nodes entirely.
> 
> To keep the code more robust, avoid overloading kho_bootmem_cnt. use
> max_nr_bootmem to store the size of kho_bootmem array. This ensures that
> the location of kho_bootmem_cnt assignment does not affect the cleanup
> paths.
> 
> Fixes: 3dc92c311498 ("kexec: add Kexec HandOver (KHO) generation helpers")
> Reported-by: Bing Jiao <bingjiao@google.com>
> Signed-off-by: Pratyush Yadav (Google) <pratyush@kernel.org>
> ---
>  kernel/liveupdate/kexec_handover.c | 17 +++++++++++++----
>  1 file changed, 13 insertions(+), 4 deletions(-)
> 
> diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c
> index 7018e25e4eda..6f1f55fe3181 100644
> --- a/kernel/liveupdate/kexec_handover.c
> +++ b/kernel/liveupdate/kexec_handover.c
> @@ -831,8 +831,8 @@ bool kho_bootmem_overlap(phys_addr_t phys, size_t size)
>   */
>  static void __init kho_reserve_bootmem(void)
>  {
> +	int nid, i = 0, max_nr_bootmem;
>  	phys_addr_t addr, size;
> -	int nid, i = 0;
>  
>  	if (!kho_enable)
>  		return;
> @@ -840,8 +840,8 @@ static void __init kho_reserve_bootmem(void)
>  	bootmem_size_update();
>  
>  	/* FIXME: deal with node hot-plug/remove */
> -	kho_bootmem_cnt = nodes_weight(node_states[N_MEMORY]) + 2;
> -	size = kho_bootmem_cnt * sizeof(*kho_bootmem);
> +	max_nr_bootmem = nodes_weight(node_states[N_MEMORY]) + 2;
> +	size = max_nr_bootmem * sizeof(*kho_bootmem);
>  	kho_bootmem = memblock_alloc(size, PAGE_SIZE);
>  	if (!kho_bootmem) {
>  		pr_err("Failed to reserve bootmem array\n");
> @@ -882,6 +882,9 @@ static void __init kho_reserve_bootmem(void)
>  	 */
>  	for_each_node_state(nid, N_MEMORY) {
>  		size = bootmem_size_node(nid);
> +		if (!size)
> +			continue;
> +
>  		addr = memblock_alloc_range_nid(size, BOOTMEM_ALIGNMENT_BYTES,
>  						0, MEMBLOCK_ALLOC_ACCESSIBLE,
>  						nid, true);
> @@ -895,13 +898,19 @@ static void __init kho_reserve_bootmem(void)
>  		i++;
>  	}
>  
> +	/*
> +	 * Nodes that needed no bootmem were skipped, so fewer areas than
> +	 * initially estimated may have been reserved.
> +	 */
> +	kho_bootmem_cnt = i;
> +
>  	return;
>  
>  err_free_bootmem_areas:
>  	for (i--; i >= 0; i--)
>  		memblock_phys_free(kho_bootmem[i].addr, kho_bootmem[i].size);
>  err_free_bootmem_desc:
> -	memblock_free(kho_bootmem, kho_bootmem_cnt * sizeof(*kho_bootmem));
> +	memblock_free(kho_bootmem, max_nr_bootmem * sizeof(*kho_bootmem));
>  err_disable_kho:
>  	pr_warn("Failed to reserve bootmem, disabling kexec handover\n");
>  	kho_enable = false;
> 
> base-commit: e1fe7daedae7a4a23aca6dbd58e1746750b632dc
> -- 
> 2.56.0.385.gd3acb90ef8-goog
> 

-- 
Sincerely yours,
Mike.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] kho: do not reserve empty per-node bootmem areas
  2026-10-14 13:15 [PATCH] kho: do not reserve empty per-node bootmem areas Pratyush Yadav
  2026-10-15  8:36 ` Mike Rapoport
@ 2026-10-15  8:39 ` Mike Rapoport
  1 sibling, 0 replies; 4+ messages in thread
From: Mike Rapoport @ 2026-10-15  8:39 UTC (permalink / raw)
  To: Pasha Tatashin, Alexander Graf, Pratyush Yadav
  Cc: Mike Rapoport, kexec, linux-mm, linux-kernel, Bing Jiao

From: Mike Rapoport (Microsoft) <rppt@kernel.org>

On Wed, 14 Oct 2026 15:15:44 +0200, Pratyush Yadav wrote:
> Some nodes do not allocate any early boot memory. An example is
> hotpluggable nodes with movable_node enabled. So the scratch size for
> them ends up being zero. Zero size allocations normally don't play well
> with memblock. Memblock returns an address, but then doesn't actually
> reserve anything. This address ends up being recorded in kho_bootmem
> with a size of 0. In case of hotpluggable nodes with movable_nodes, the
> allocation on the node actually fails because memblock refuses to
> allocate there, and so KHO fails to initialize.
> 
> [...]

Applied to next branch of liveupdate/linux.git tree, thanks!

[1/1] kho: do not reserve empty per-node bootmem areas
      commit: 9a6a70aefe77f6fb9ff2b3037dcf87f6dff65c8c

tree: https://git.kernel.org/pub/scm/linux/kernel/git/liveupdate/linux
branch: next

--
Sincerely yours,
Mike.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] kho: do not reserve empty per-node bootmem areas
  2026-10-15  8:36 ` Mike Rapoport
@ 2026-10-15 11:08   ` Pratyush Yadav
  0 siblings, 0 replies; 4+ messages in thread
From: Pratyush Yadav @ 2026-10-15 11:08 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: Pratyush Yadav, Pasha Tatashin, Alexander Graf, kexec, linux-mm,
	linux-kernel, Bing Jiao

On Thu, Oct 15 2026, Mike Rapoport wrote:

> On Wed, Oct 14, 2026 at 03:15:44PM +0200, Pratyush Yadav wrote:
>> From: "Pratyush Yadav (Google)" <pratyush@kernel.org>
>> 
>> Some nodes do not allocate any early boot memory. An example is
>> hotpluggable nodes with movable_node enabled. So the scratch size for
>
>                           Let's use the new naming please ^ ;-)

Argh, muscle memory...

>
> I'll fix it up when applying.

Thanks!

>
>> them ends up being zero. Zero size allocations normally don't play well
>> with memblock. Memblock returns an address, but then doesn't actually
>> reserve anything. This address ends up being recorded in kho_bootmem
>> with a size of 0. In case of hotpluggable nodes with movable_nodes, the
>> allocation on the node actually fails because memblock refuses to
>> allocate there, and so KHO fails to initialize.
>> 
>> Skip bootmem reservation for such nodes entirely.
>> 
>> To keep the code more robust, avoid overloading kho_bootmem_cnt. use
>> max_nr_bootmem to store the size of kho_bootmem array. This ensures that
>> the location of kho_bootmem_cnt assignment does not affect the cleanup
>> paths.
[...]

-- 
Regards,
Pratyush Yadav

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-10-15 11:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-14 13:15 [PATCH] kho: do not reserve empty per-node bootmem areas Pratyush Yadav
2026-10-15  8:36 ` Mike Rapoport
2026-10-15 11:08   ` Pratyush Yadav
2026-10-15  8:39 ` Mike Rapoport

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®