mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] kexec: Fix kexec_locate_mem_hole() for missing CONFIG_KEXEC_HANDOVER
@ 2025-02-14 12:54 Sourabh Jain
  2025-02-14 23:47 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Sourabh Jain @ 2025-02-14 12:54 UTC (permalink / raw)
  To: akpm
  Cc: Sourabh Jain, Venkat Rao Bagalkote, Alexander Graf, Baoquan he,
	Hari Bathini, Madhavan Srinivasan, Mike Rapoport (Microsoft),
	kexec, linux-kernel

While adding KHO support, commit 7d128945e003 ("kexec: add KHO support
to kexec file loads") returns early from kexec_locate_mem_hole() if
CONFIG_KEXEC_HANDOVER is not defined.

Due to this, kexec_locate_mem_hole() does not locate a hole for the
kexec segment, and kbuf.mem holds 0x0. This leads to a kexec_file_load
syscall failure in sanity_check_segment_list(). This impacts both
kexec and kdump kernels.

Without this patch included:
----------------------------
kexec --initrd=initrd.img ./vmlinuz --append="`cat /proc/cmdline`" -lsd
Try gzip decompression.
Try LZMA decompression.
[   59.745154] kexec_file: kernel: 000000003473b9a0 kernel_size: 0x2cdacf0
[   59.753713] ima: kexec measurement buffer for the loaded kernel at 0x0.
[   59.753759] kexec_elf: Loaded the kernel at 0x0
[   59.753777] kexec_elf: Loaded purgatory at 0x0
[   59.753783] kexec_elf: Loaded initrd at 0x0
[   59.758657] kexec_elf: Loaded device tree at 0x0
syscall kexec_file_load not available.

With this patch included:
-------------------------
kexec --initrd=initrd.img ./vmlinuz --append="`cat /proc/cmdline`" -lsd
Try gzip decompression.
Try LZMA decompression.
[  112.091308] kexec_file: kernel: 000000009eb0432d kernel_size: 0x2cdacf0
[  112.099881] ima: kexec measurement buffer for the loaded kernel at 0x3fd9c0000.
[  112.099935] kexec_elf: Loaded the kernel at 0x2f60000
[  112.099953] kexec_elf: Loaded purgatory at 0x3fd9b0000
[  112.099969] kexec_elf: Loaded initrd at 0x5eb0000
[  112.104993] kexec_elf: Loaded device tree at 0x3fd650000
[  113.484422] kexec_file: nr_segments = 5
[  113.484452] kexec_file: segment[0]: buf=0x00000000b6970fc9 bufsz=0x82 mem=0x3fd9c0000 memsz=0x10000
[  113.484473] kexec_file: segment[1]: buf=0x00000000cabe3fe7 bufsz=0x2cc9ca4 mem=0x2f60000 memsz=0x2f50000
[  113.489144] kexec_file: segment[2]: buf=0x00000000deec4aaf bufsz=0x310 mem=0x3fd9b0000 memsz=0x10000
[  113.489195] kexec_file: segment[3]: buf=0x0000000081960708 bufsz=0x581a9c6 mem=0x5eb0000 memsz=0x5820000
[  113.498768] kexec_file: segment[4]: buf=0x00000000c1be9ac7 bufsz=0x6632 mem=0x3fd650000 memsz=0x10000
[  113.498819] kexec_file: kexec_file_load: type:0, start:0x3fd9b0000 head:0x5f1c0002 flags:0x8

To fix this, return 1 from kexec_locate_mem_hole() in kexec_internal.h.
This ensures that kexec_locate_mem_hole() locates a memory hole if
CONFIG_KEXEC_HANDOVER is not defined.

Note: The kexec tool printing "kexec_file_load not available" does not
necessarily mean that the kernel lacks support for the kexec_file_load
syscall. Instead, it occurs because multiple errors are handled under
the same condition.

Reported-by: Venkat Rao Bagalkote <venkat88@linux.vnet.ibm.com>
Closes: https://lore.kernel.org/all/8e73069b-5987-4a08-b13d-13fe691092ad@linux.vnet.ibm.com/
Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com>
Cc: Alexander Graf <graf@amazon.com>
Cc: Baoquan he <bhe@redhat.com>
Cc: Hari Bathini <hbathini@linux.ibm.com>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Mike Rapoport (Microsoft) <rppt@kernel.org>
Cc: kexec@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---

Rebased on top of next-20250213

---
 kernel/kexec_internal.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/kexec_internal.h b/kernel/kexec_internal.h
index c535dbd3b5bd..66ce6872fda1 100644
--- a/kernel/kexec_internal.h
+++ b/kernel/kexec_internal.h
@@ -50,7 +50,7 @@ int kho_fill_kimage(struct kimage *image);
 static inline int kho_locate_mem_hole(struct kexec_buf *kbuf,
 				      int (*func)(struct resource *, void *))
 {
-	return 0;
+	return 1;
 }
 
 static inline int kho_fill_kimage(struct kimage *image) { return 0; }
-- 
2.48.1


^ permalink raw reply	[flat|nested] 3+ messages in thread
* Re: [PATCH] kexec: Fix kexec_locate_mem_hole() for missing CONFIG_KEXEC_HANDOVER
@ 2025-02-16 14:36 Venkat
  0 siblings, 0 replies; 3+ messages in thread
From: Venkat @ 2025-02-16 14:36 UTC (permalink / raw)
  To: Sourabh Jain
  Cc: akpm, bhe, graf, Hari Bathini, kexec, linux-kernel, maddy, rppt,
	Venkat Rao Bagalkote


Hello,

I have applied the patch on top of 6.14.0-rc2-next-20250212, and proposed patch fixes the issue reported.

Please add the below tag.

Tested-By:  Venkat Rao Bagalkote <venkat88@linux.vnet.ibm.com>

Regards,
Venkat.

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

end of thread, other threads:[~2025-02-16 14:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-14 12:54 [PATCH] kexec: Fix kexec_locate_mem_hole() for missing CONFIG_KEXEC_HANDOVER Sourabh Jain
2025-02-14 23:47 ` Andrew Morton
2025-02-16 14:36 Venkat

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®