of: fdt: skip KHO when booting as crash kernel
Subsystems (3)
PATCH 1/1 of: fdt: skip KHO when booting as crash kernel
KHO preserves state across kexec by passing a KHO-specific FDT pointer and scratch memory region to the incoming kernel. These point to physical addresses in the outgoing kernel's memory that the incoming kernel is expected to access and restore from. This falls apart when the incoming kernel is a crash kernel as the crash kernel can run in a small reserved memory region. The scratch regions can sit outside this reservation, so the end result is quite unpleasant.
kho_add_chosen() unconditionally propagates KHO properties into the device tree for all kexec image types, including crash images. The crash kernel then discovers these properties during early_init_dt_check_kho(), records the stale physical addresses via kho_populate(), and later faults in kho_memory_init() when it tries phys_to_virt() on the KHO FDT address:
Unable to handle kernel paging request at virtual address xxxxxxxx
...
fdt_offset_ptr+...
fdt_check_node_offset_+...
fdt_first_property_offset+...
fdt_get_property_namelen_+...
fdt_getprop+...
kho_memory_init+...
mm_core_init+...
start_kernel+...
kho_locate_mem_hole() already skips KHO logic for KEXEC_TYPE_CRASH images, but the DT property propagation and the consumer side were both missing the same guard.
Fix this at both ends. Have kho_add_chosen() skip writing KHO properties for crash images so the stale pointers never reach the crash kernel's device tree. Also have early_init_dt_check_kho() bail out when is_kdump_kernel() is true. This way even if KHO properties end up in the DT through some other path, the crash kernel will not act on them.
---
I think we should backport the fix on KHO compatible versions (6.16+), hence the "Fixes:" tag. Tested on an arm64 system.
drivers/of/fdt.c | 3 +++ drivers/of/kexec.c | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-)
drivers/of/fdt.c +3 -0
@@ -926,6 +926,9 @@ static void __init early_init_dt_check_kho(void)if (!IS_ENABLED (CONFIG_KEXEC_HANDOVER ) || (long )node <0 )return ; +if (is_kdump_kernel ()) +return ; +if (!of_flat_dt_get_addr_size (node,"linux,kho-fdt" , &fdt_start, &fdt_size))return ;
drivers/of/kexec.c +2 -1
@@ -271,7 +271,8 @@ static int kho_add_chosen(const struct kimage *image, void *fdt, int chosen_nodeif (ret && ret != -FDT_ERR_NOTFOUND )return ret; -if (!image->kho.fdt || !image->kho.scratch) +if (!image->kho.fdt || !image->kho.scratch || + image->type ==KEXEC_TYPE_CRASH )return 0 ; fdt_mem = image->kho.fdt;
Signature · 12 lines
2.43.0 Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13 10243 Berlin Geschaeftsfuehrung: Christof Hellmis, Andreas Stieger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B Sitz: Berlin Ust-ID: DE 365 538 597
Mike Rapoport
maintainerHi Evangelos,
Quoted 38 lines · Evangelos Petrongonas
KHO preserves state across kexec by passing a KHO-specific FDT pointer and scratch memory region to the incoming kernel. These point to physical addresses in the outgoing kernel's memory that the incoming kernel is expected to access and restore from. This falls apart when the incoming kernel is a crash kernel as the crash kernel can run in a small reserved memory region. The scratch regions can sit outside this reservation, so the end result is quite unpleasant.
kho_add_chosen()unconditionally propagates KHO properties into the device tree for all kexec image types, including crash images. The crash kernel then discovers these properties duringearly_init_dt_check_kho(), records the stale physical addresses viakho_populate(), and later faults inkho_memory_init()when it triesphys_to_virt()on the KHO FDT address:Unable to handle kernel paging request at virtual address xxxxxxxx...
fdt_offset_ptr+...
fdt_check_node_offset_+...
fdt_first_property_offset+...
fdt_get_property_namelen_+...
fdt_getprop+...
kho_memory_init+...
mm_core_init+...
start_kernel+...
kho_locate_mem_hole()already skips KHO logic forKEXEC_TYPE_CRASHimages, but the DT property propagation and the consumer side were both missing the same guard.Fix this at both ends. Have
kho_add_chosen()skip writing KHO properties for crash images so the stale pointers never reach the crash kernel's device tree. Also haveearly_init_dt_check_kho()bail out whenis_kdump_kernel()is true. This way even if KHO properties end up in the DT through some other path, the crash kernel will not act on them.Fixes 274cdcb1c004 ("arm64: add KHO support")Signed-off-by Evangelos Petrongonas <[email protected]>
Quoted 8 lines
---
I think we should backport the fix on KHO compatible versions (6.16+), hence the "Fixes:" tag. Tested on an arm64 system.
drivers/of/fdt.c | 3 +++ drivers/of/kexec.c | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-)
What about x86? ;-)
drivers/of/fdt.c static void __init early_init_dt_check_kho(void) · line 931
Quoted 11 lines
drivers/of/fdt.c +3
-0@@ -926,6 +926,9 @@ static void __init early_init_dt_check_kho(void)if (!IS_ENABLED (CONFIG_KEXEC_HANDOVER ) || (long )node <0 )return ; +if (is_kdump_kernel ()) +return ; +
This seems redundant if don't add KHO nodes at the first place.
Quoted 8 lines
drivers/of/fdt.c +0
-0if (!of_flat_dt_get_addr_size (node,"linux,kho-fdt" , &fdt_start, &fdt_size))return ;drivers/of/kexec.c +0
-0
drivers/of/kexec.c static int kho_add_chosen(const struct kimage *image, void *fdt, int chosen_node · line 278
Quoted 9 lines
drivers/of/kexec.c +2
-1@@ -271,7 +271,8 @@ static int kho_add_chosen(const struct kimage *image, void *fdt, int chosen_nodeif (ret && ret != -FDT_ERR_NOTFOUND )return ret; -if (!image->kho.fdt || !image->kho.scratch) +if (!image->kho.fdt || !image->kho.scratch || + image->type ==KEXEC_TYPE_CRASH )return 0 ; fdt_mem = image->kho.fdt;
kho_add_chosen() bails out if there's no KHO buffer in kimage, so if kho_fill_kimage won't add KHO buffer to kexec_crash_image it should be enough.
Quoted 14 lines
Signature · 12 lines
2.43.0 Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13 10243 Berlin Geschaeftsfuehrung: Christof Hellmis, Andreas Stieger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B Sitz: Berlin Ust-ID: DE 365 538 597
Signature · 2 lines
Sincerely yours, Mike.
Quoted 5 lines · On Thu, Apr 09, 2026 at 05:22:11PM +0300 Mike Rapoport wrote:
Hi Evangelos,
On Tue, Apr 07, 2026 at 03:06:33PM +0000, Evangelos Petrongonas wrote:
What about x86? ;-)
Well... I was planning to reply with "we will sort it out in a followup". I have a suspicion though, that you knew that the kho_fill_kimage() approach would take care of it. Nice! Thanks for the tip.
I will post soon the v2.
Quoted 8 lines
Quoted 8 lines
drivers/of/fdt.c +0
-0@@ -926,6 +926,9 @@ static void __init early_init_dt_check_kho(void)if (!IS_ENABLED (CONFIG_KEXEC_HANDOVER ) || (long )node <0 )return ;
Quoted 6 lines
drivers/of/fdt.c static void __init early_init_dt_check_kho(void) · line 931
Quoted 3 lines
drivers/of/fdt.c +3
-0+if (is_kdump_kernel ()) +return ; +This seems redundant if don't add KHO nodes at the first place.
Indeed it is, it was more of a defense in depth in case there were stale data somehow, but I will drop it in v2.
Quoted 16 lines
Quoted 16 lines
drivers/of/fdt.c +0
-0if (!of_flat_dt_get_addr_size (node,"linux,kho-fdt" , &fdt_start, &fdt_size))return ;drivers/of/kexec.c +2
-1@@ -271,7 +271,8 @@ static int kho_add_chosen(const struct kimage *image, void *fdt, int chosen_nodeif (ret && ret != -FDT_ERR_NOTFOUND )return ret; -if (!image->kho.fdt || !image->kho.scratch) +if (!image->kho.fdt || !image->kho.scratch || + image->type ==KEXEC_TYPE_CRASH )return 0 ;
Quoted 6 lines
drivers/of/kexec.c static int kho_add_chosen(const struct kimage *image, void *fdt, int chosen_node · line 278
Quoted 1 line
drivers/of/kexec.c +0
-0fdt_mem = image->kho.fdt;
kho_add_chosen()bails out if there's no KHO buffer in kimage, so ifkho_fill_kimagewon't add KHO buffer tokexec_crash_imageit should be enough.
Indeed, one guard to rule them all. Much more elegant than the "let's sprinkle checks everywhere (apart from x86))" approach.
Quoted 6 lines
Quoted 6 lines
Signature · 1 line
2.43.0
Quoted 12 lines
Quoted 8 lines
Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13
10243 Berlin
Geschaeftsfuehrung: Christof Hellmis, Andreas Stieger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B
Sitz: Berlin
Ust-ID: DE 365 538 597Signature · 2 lines
Sincerely yours, Mike.
Kind Regards,
Evangelos
Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13
10243 Berlin
Geschaeftsfuehrung: Christof Hellmis, Andreas Stieger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B
Sitz: Berlin
Ust-ID: DE 365 538 597