Kexec Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] memblock: don't allocate new reserve_mem regions on a KHO boot
@ 2026-11-04 20:42 Jose A. Perez de Azpillaga
  2026-11-05  2:28 ` Pasha Tatashin
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Jose A. Perez de Azpillaga @ 2026-11-04 20:42 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton, Kees Cook, Changyuan Lyu,
	Alexander Graf
  Cc: Tony Luck, Pasha Tatashin, linux-mm, kexec, linux-kernel,
	Jose A. Perez de Azpillaga, Pratyush Yadav

On a KHO boot, a reserve_mem region that can't be revived is allocated
from KHO_NOPRSRV memory, which includes the bootmem the next kernel
boots out of. With CONFIG_KEXEC_HANDOVER_DEBUG, preserving the region
then fails:

  WARNING: kernel/liveupdate/kexec_handover.c:1245 at kho_preserve_pages+0x168/0x180
  failed to prepare memblock FDT for KHO: -22

Without it, the next kernel puts its memmap on top of the region and
the ramoops records in it are lost.

There is no use case for adding regions across a live update, so fail
instead of allocating, and drop the TODO.

Fixes: f99230780211 ("memblock: add KHO support for reserve_mem")
Signed-off-by: Jose A. Perez de Azpillaga <azpijr@gmail.com>
---
Changes in v2:
- fail on a KHO boot instead of allocating outside bootmem, as agreed
  with Pratyush [1]. this drops v1's patch 1.
- not an RFC anymore.
- based on v7.4-rc1.

v1: https://lore.kernel.org/all/20261021211058.83483-3-azpijr@gmail.com/

[1] https://lore.kernel.org/all/2vxzfqxglrg6.fsf@kernel.org/

 mm/memblock.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/mm/memblock.c b/mm/memblock.c
index a450092a80fb..e325e0542c9a 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -2827,7 +2827,16 @@ static int __init reserve_mem(char *p)
 	if (reserve_mem_kho_revive(name, size, align))
 		return 1;
 
-	/* TODO: Allocation must be outside of KHO_NOPRSRV region */
+	/*
+	 * On a KHO boot memblock only allocates from KHO_NOPRSRV memory here,
+	 * which includes the bootmem the next kernel boots out of. Only regions
+	 * handed over by the previous kernel are supported.
+	 */
+	if (is_kho_boot()) {
+		pr_err("reserve_mem: can't allocate \"%s\" on a KHO boot\n", name);
+		return -EOPNOTSUPP;
+	}
+
 	start = memblock_phys_alloc(size, align);
 	if (!start) {
 		pr_err("reserve_mem: memblock allocation failed\n");

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
-- 
2.56.0



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

* Re: [PATCH v2] memblock: don't allocate new reserve_mem regions on a KHO boot
  2026-11-04 20:42 [PATCH v2] memblock: don't allocate new reserve_mem regions on a KHO boot Jose A. Perez de Azpillaga
@ 2026-11-05  2:28 ` Pasha Tatashin
  2026-11-05  7:59 ` Mike Rapoport
  2026-11-05 20:44 ` sashiko-bot
  2 siblings, 0 replies; 5+ messages in thread
From: Pasha Tatashin @ 2026-11-05  2:28 UTC (permalink / raw)
  To: Jose A. Perez de Azpillaga
  Cc: Tony Luck, Pasha Tatashin, linux-mm, Kees Cook, Changyuan Lyu,
	kexec, linux-kernel, Alexander Graf, Pratyush Yadav,
	Andrew Morton, Mike Rapoport

On Wed, 04 Nov 2026 21:42:17 +0100, Jose A. Perez de Azpillaga <azpijr@gmail.com> wrote:
> On a KHO boot, a reserve_mem region that can't be revived is allocated
> from KHO_NOPRSRV memory, which includes the bootmem the next kernel
> boots out of. With CONFIG_KEXEC_HANDOVER_DEBUG, preserving the region
> then fails:
> 
>   WARNING: kernel/liveupdate/kexec_handover.c:1245 at kho_preserve_pages+0x168/0x180
>   failed to prepare memblock FDT for KHO: -22
> 
> [...]

Reviewed-by: Pasha Tatashin <pasha.tatashin@soleen.com>

-- 
Pasha



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

* Re: [PATCH v2] memblock: don't allocate new reserve_mem regions on a KHO boot
  2026-11-04 20:42 [PATCH v2] memblock: don't allocate new reserve_mem regions on a KHO boot Jose A. Perez de Azpillaga
  2026-11-05  2:28 ` Pasha Tatashin
@ 2026-11-05  7:59 ` Mike Rapoport
  2026-11-05 11:56   ` Jose A. Perez de Azpillaga
  2026-11-05 20:44 ` sashiko-bot
  2 siblings, 1 reply; 5+ messages in thread
From: Mike Rapoport @ 2026-11-05  7:59 UTC (permalink / raw)
  To: Jose A. Perez de Azpillaga
  Cc: Tony Luck, Pasha Tatashin, linux-mm, Kees Cook, Changyuan Lyu,
	kexec, linux-kernel, Alexander Graf, Andrew Morton,
	Pratyush Yadav

On Wed, Nov 04, 2026 at 09:42:17PM +0100, Jose A. Perez de Azpillaga wrote:
> On a KHO boot, a reserve_mem region that can't be revived is allocated
> from KHO_NOPRSRV memory, which includes the bootmem the next kernel
> boots out of. With CONFIG_KEXEC_HANDOVER_DEBUG, preserving the region
> then fails:
> 
>   WARNING: kernel/liveupdate/kexec_handover.c:1245 at kho_preserve_pages+0x168/0x180
>   failed to prepare memblock FDT for KHO: -22
> 
> Without it, the next kernel puts its memmap on top of the region and
> the ramoops records in it are lost.
> 
> There is no use case for adding regions across a live update, so fail
> instead of allocating, and drop the TODO.
> 
> Fixes: f99230780211 ("memblock: add KHO support for reserve_mem")
> Signed-off-by: Jose A. Perez de Azpillaga <azpijr@gmail.com>
> ---
> Changes in v2:
> - fail on a KHO boot instead of allocating outside bootmem, as agreed
>   with Pratyush [1]. this drops v1's patch 1.
> - not an RFC anymore.
> - based on v7.4-rc1.
> 
> v1: https://lore.kernel.org/all/20261021211058.83483-3-azpijr@gmail.com/
> 
> [1] https://lore.kernel.org/all/2vxzfqxglrg6.fsf@kernel.org/
> 
>  mm/memblock.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/memblock.c b/mm/memblock.c
> index a450092a80fb..e325e0542c9a 100644
> --- a/mm/memblock.c
> +++ b/mm/memblock.c
> @@ -2827,7 +2827,16 @@ static int __init reserve_mem(char *p)
>  	if (reserve_mem_kho_revive(name, size, align))
>  		return 1;
>  
> -	/* TODO: Allocation must be outside of KHO_NOPRSRV region */
> +	/*
> +	 * On a KHO boot memblock only allocates from KHO_NOPRSRV memory here,
> +	 * which includes the bootmem the next kernel boots out of. Only regions
> +	 * handed over by the previous kernel are supported.
> +	 */
> +	if (is_kho_boot()) {

This breaks memblock tests, please add a stub there.

> +		pr_err("reserve_mem: can't allocate \"%s\" on a KHO boot\n", name);
> +		return -EOPNOTSUPP;
> +	}
> +
>  	start = memblock_phys_alloc(size, align);
>  	if (!start) {
>  		pr_err("reserve_mem: memblock allocation failed\n");
> 
> base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
> -- 
> 2.56.0
> 

-- 
Sincerely yours,
Mike.


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

* Re: [PATCH v2] memblock: don't allocate new reserve_mem regions on a KHO boot
  2026-11-05  7:59 ` Mike Rapoport
@ 2026-11-05 11:56   ` Jose A. Perez de Azpillaga
  0 siblings, 0 replies; 5+ messages in thread
From: Jose A. Perez de Azpillaga @ 2026-11-05 11:56 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: Tony Luck, Pasha Tatashin, linux-mm, Kees Cook, Changyuan Lyu,
	kexec, linux-kernel, Alexander Graf, Andrew Morton,
	Pratyush Yadav

On 11/5/26 8:59 AM, Mike Rapoport wrote:
> On Wed, Nov 04, 2026 at 09:42:17PM +0100, Jose A. Perez de Azpillaga wrote:
>> On a KHO boot, a reserve_mem region that can't be revived is allocated
>> from KHO_NOPRSRV memory, which includes the bootmem the next kernel
>> boots out of. With CONFIG_KEXEC_HANDOVER_DEBUG, preserving the region
>> then fails:
>>
>>   WARNING: kernel/liveupdate/kexec_handover.c:1245 at kho_preserve_pages+0x168/0x180
>>   failed to prepare memblock FDT for KHO: -22
>>
>> Without it, the next kernel puts its memmap on top of the region and
>> the ramoops records in it are lost.
>>
>> There is no use case for adding regions across a live update, so fail
>> instead of allocating, and drop the TODO.
>>
>> Fixes: f99230780211 ("memblock: add KHO support for reserve_mem")
>> Signed-off-by: Jose A. Perez de Azpillaga <azpijr@gmail.com>
>> ---
>> Changes in v2:
>> - fail on a KHO boot instead of allocating outside bootmem, as agreed
>>   with Pratyush [1]. this drops v1's patch 1.
>> - not an RFC anymore.
>> - based on v7.4-rc1.
>>
>> v1: https://lore.kernel.org/all/20261021211058.83483-3-azpijr@gmail.com/
>>
>> [1] https://lore.kernel.org/all/2vxzfqxglrg6.fsf@kernel.org/
>>
>>  mm/memblock.c | 11 ++++++++++-
>>  1 file changed, 10 insertions(+), 1 deletion(-)
>>
>> diff --git a/mm/memblock.c b/mm/memblock.c
>> index a450092a80fb..e325e0542c9a 100644
>> --- a/mm/memblock.c
>> +++ b/mm/memblock.c
>> @@ -2827,7 +2827,16 @@ static int __init reserve_mem(char *p)
>>  	if (reserve_mem_kho_revive(name, size, align))
>>  		return 1;
>>  
>> -	/* TODO: Allocation must be outside of KHO_NOPRSRV region */
>> +	/*
>> +	 * On a KHO boot memblock only allocates from KHO_NOPRSRV memory here,
>> +	 * which includes the bootmem the next kernel boots out of. Only regions
>> +	 * handed over by the previous kernel are supported.
>> +	 */
>> +	if (is_kho_boot()) {
> 
> This breaks memblock tests, please add a stub there.


oops, sorry. will add it in v3 :)

-- 
cheers,
jose a. p-a


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

* Re: [PATCH v2] memblock: don't allocate new reserve_mem regions on a KHO boot
  2026-11-04 20:42 [PATCH v2] memblock: don't allocate new reserve_mem regions on a KHO boot Jose A. Perez de Azpillaga
  2026-11-05  2:28 ` Pasha Tatashin
  2026-11-05  7:59 ` Mike Rapoport
@ 2026-11-05 20:44 ` sashiko-bot
  2 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-05 20:44 UTC (permalink / raw)
  To: Jose A. Perez de Azpillaga, Mike Rapoport, Andrew Morton,
	Kees Cook, Changyuan Lyu, Alexander Graf
  Cc: Tony Luck, Pasha Tatashin, linux-mm, kexec, Pratyush Yadav

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] memblock: missing is_kho_boot() stub breaks tools/testing/memblock build
--

commit 19549caf363a437d6178ec835c2f8f9d0ecc7f1d
Author: Jose A. Perez de Azpillaga <azpijr@gmail.com>

memblock: don't allocate new reserve_mem regions on a KHO boot

This patch rejects allocating new reserve_mem regions during a KHO boot
when the region cannot be revived from the previous kernel, returning
-EOPNOTSUPP instead of allocating from KHO_NOPRSRV memory.

> diff --git a/mm/memblock.c b/mm/memblock.c
> index a450092a80fb5..e325e0542c9a8 100644
> --- a/mm/memblock.c
> +++ b/mm/memblock.c
> @@ -2827,7 +2827,16 @@ static int __init reserve_mem(char *p)
>  	if (reserve_mem_kho_revive(name, size, align))
>  		return 1;
>  
> -	/* TODO: Allocation must be outside of KHO_NOPRSRV region */
> +	/*
> +	 * On a KHO boot memblock only allocates from KHO_NOPRSRV memory here,
> +	 * which includes the bootmem the next kernel boots out of. Only regions
> +	 * handed over by the previous kernel are supported.
> +	 */
> +	if (is_kho_boot()) {
> +		pr_err("reserve_mem: can't allocate \"%s\" on a KHO boot\n", name);
> +		return -EOPNOTSUPP;
> +	}

[Severity: Low]
Does calling is_kho_boot() in reserve_mem() break the user-space memblock
test suite build in tools/testing/memblock?

When building tools/testing/memblock, mm/memblock.c is compiled with -I.
before -I../../include and without CONFIG_KEXEC_HANDOVER defined. As a
result, #include <linux/kexec_handover.h> resolves to the empty stub header
in tools/testing/memblock/linux/kexec_handover.h rather than
include/linux/kexec_handover.h:

tools/testing/memblock/linux/kexec_handover.h:
    #ifndef LINUX_KEXEC_HANDOVER_H
    #define LINUX_KEXEC_HANDOVER_H

    /*
     * Header stub to avoid test build breakage; we don't need to actually implement
     * any KHO functions as they are not used in the tests.
     */
    #endif /* LINUX_KEXEC_HANDOVER_H */

Other KHO helpers called unconditionally from mm/memblock.c, such as
kho_bootmem_overlap(), have stubs in tools/testing/memblock/internal.h:

tools/testing/memblock/internal.h:
    static inline bool kho_bootmem_overlap(phys_addr_t phys, size_t size)
    {
            return false;
    }

Should a stub for is_kho_boot() be added to tools/testing/memblock as well?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261104204235.9066-1-azpijr@gmail.com?part=1


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

end of thread, other threads:[~2026-11-05 20:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-04 20:42 [PATCH v2] memblock: don't allocate new reserve_mem regions on a KHO boot Jose A. Perez de Azpillaga
2026-11-05  2:28 ` Pasha Tatashin
2026-11-05  7:59 ` Mike Rapoport
2026-11-05 11:56   ` Jose A. Perez de Azpillaga
2026-11-05 20:44 ` sashiko-bot

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