mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sourabh Jain <sourabhjain@linux.ibm.com>
To: akpm@linux-foundation.org
Cc: Sourabh Jain <sourabhjain@linux.ibm.com>,
	Venkat Rao Bagalkote <venkat88@linux.vnet.ibm.com>,
	Alexander Graf <graf@amazon.com>, Baoquan he <bhe@redhat.com>,
	Hari Bathini <hbathini@linux.ibm.com>,
	Madhavan Srinivasan <maddy@linux.ibm.com>,
	"Mike Rapoport (Microsoft)" <rppt@kernel.org>,
	kexec@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: [PATCH] kexec: Fix kexec_locate_mem_hole() for missing CONFIG_KEXEC_HANDOVER
Date: Fri, 14 Feb 2025 18:24:02 +0530	[thread overview]
Message-ID: <20250214125402.90709-1-sourabhjain@linux.ibm.com> (raw)

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


             reply	other threads:[~2025-02-14 12:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-14 12:54 Sourabh Jain [this message]
2025-02-14 23:47 ` Andrew Morton
2025-02-16 14:36 Venkat

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250214125402.90709-1-sourabhjain@linux.ibm.com \
    --to=sourabhjain@linux.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=bhe@redhat.com \
    --cc=graf@amazon.com \
    --cc=hbathini@linux.ibm.com \
    --cc=kexec@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maddy@linux.ibm.com \
    --cc=rppt@kernel.org \
    --cc=venkat88@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®