All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joseph Cathcart <josephc@linux.ibm.com>
To: linux-s390@vger.kernel.org, kexec@lists.infradead.org
Cc: eoin.mcnamara@ibm.com, iii@de.ibm.com,
	Joseph Cathcart <josephc@linux.ibm.com>
Subject: [PATCH v2] kexec-tools/s390: add --reuseinitrd support
Date: Thu, 20 Aug 2026 12:13:50 +0200	[thread overview]
Message-ID: <20260820101350.4413-1-josephc@linux.ibm.com> (raw)

Currently, the --reuseinitrd param is not supported on s390. This
prevents testing kexec in environments such as virtme-ng, which by
default does not store the initrd on disk.

When --reuseinitrd is specified, fetch retained initrd memory range
from /proc/iomem and fill new kernel parmarea directly with retained
initrd base and size, rather than memory range of a new ramdisk.

Add die() cases for when user uses --reuseinitrd:
        - in addition to --ramdisk or --initrd
        - while booting a crash kernel.
        - with kexec-file-load syscall (default syscall)
        - and no initrd entry is found in /proc/iomem

Signed-off-by: Joseph Cathcart <josephc@linux.ibm.com>
---
 kexec/arch/s390/Makefile      |  2 ++
 kexec/arch/s390/kexec-image.c | 15 ++++++++++++++-
 kexec/arch/s390/kexec-s390.c  | 14 ++++++++++++++
 kexec/arch/s390/kexec-s390.h  |  2 ++
 4 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/kexec/arch/s390/Makefile b/kexec/arch/s390/Makefile
index fab3e68..17f9dc8 100644
--- a/kexec/arch/s390/Makefile
+++ b/kexec/arch/s390/Makefile
@@ -6,6 +6,8 @@ s390_KEXEC_SRCS += kexec/arch/s390/kexec-image.c
 s390_KEXEC_SRCS += kexec/arch/s390/kexec-elf-rel-s390.c
 s390_KEXEC_SRCS += kexec/arch/s390/crashdump-s390.c
 
+s390_ARCH_REUSE_INITRD =
+
 dist += kexec/arch/s390/Makefile $(s390_KEXEC_SRCS)			\
 	kexec/arch/s390/kexec-s390.h					\
 	kexec/arch/s390/include/arch/options.h
diff --git a/kexec/arch/s390/kexec-image.c b/kexec/arch/s390/kexec-image.c
index 69aaf96..a9e5442 100644
--- a/kexec/arch/s390/kexec-image.c
+++ b/kexec/arch/s390/kexec-image.c
@@ -78,6 +78,10 @@ int image_s390_load_file(int argc, char **argv, struct kexec_info *info)
 		}
 	}
 
+	if (reuse_initrd)
+		die("--reuseinitrd not supported with --kexec-file-syscall. "
+			"Please use --kexec-syscall\n");
+
 	if (ramdisk) {
 		info->initrd_fd = open(ramdisk, O_RDONLY);
 		if (info->initrd_fd == -1) {
@@ -104,7 +108,7 @@ image_s390_load(int argc, char **argv, const char *kernel_buf,
 	char *rd_buffer;
 	const char *ramdisk;
 	off_t ramdisk_len;
-	unsigned int ramdisk_origin;
+	unsigned long long ramdisk_origin;
 	int opt, ret = -1;
 
 	if (info->file_mode)
@@ -137,6 +141,12 @@ image_s390_load(int argc, char **argv, const char *kernel_buf,
 		}
 	}
 
+	if (ramdisk && reuse_initrd)
+		die("Can't specify --ramdisk or --initrd with --reuseinitrd\n");
+
+	if (reuse_initrd && (info->kexec_flags & KEXEC_ON_CRASH))
+		die("Can't specify --reuseinitrd while booting a crash kernel\n");
+
 	if (info->kexec_flags & KEXEC_ON_CRASH) {
 		if (parse_iomem_single("Crash kernel\n", &crash_base,
 				       &crash_end))
@@ -165,6 +175,9 @@ image_s390_load(int argc, char **argv, const char *kernel_buf,
 		ramdisk_origin = _ALIGN_UP(ramdisk_origin, 0x100000);
 		add_segment_check(info, rd_buffer, ramdisk_len,
 				  ramdisk_origin, ramdisk_len);
+	} else if (reuse_initrd) {
+		ramdisk_origin = retained_initrd_base;
+		ramdisk_len = (off_t)retained_initrd_size;
 	}
 	if (info->kexec_flags & KEXEC_ON_CRASH) {
 		if (load_crashdump_segments(info, crash_base, crash_end))
diff --git a/kexec/arch/s390/kexec-s390.c b/kexec/arch/s390/kexec-s390.c
index 86c9fb8..fd0d87e 100644
--- a/kexec/arch/s390/kexec-s390.c
+++ b/kexec/arch/s390/kexec-s390.c
@@ -25,6 +25,20 @@
 #include <arch/options.h>
 
 static struct memory_range memory_range[MAX_MEMORY_RANGES];
+unsigned long long retained_initrd_base, retained_initrd_size;
+unsigned char reuse_initrd;
+
+void arch_reuse_initrd(void)
+{
+	uint64_t start, end;
+
+	if (parse_iomem_single("initrd\n", &start, &end))
+		die("Couldn't find initrd entry in /proc/iomem\n");
+
+	retained_initrd_base = (unsigned long long)start;
+	retained_initrd_size = (unsigned long long)end - retained_initrd_base + 1;
+	reuse_initrd = 1;
+}
 
 /*
  * Read string from file
diff --git a/kexec/arch/s390/kexec-s390.h b/kexec/arch/s390/kexec-s390.h
index 6a99518..7e85976 100644
--- a/kexec/arch/s390/kexec-s390.h
+++ b/kexec/arch/s390/kexec-s390.h
@@ -34,5 +34,7 @@ extern int load_crashdump_segments(struct kexec_info *info,
 extern int get_memory_ranges_s390(struct memory_range range[], int *ranges,
 				  int with_crashk);
 extern int command_line_add(struct kexec_info *info, const char *str);
+extern unsigned long long retained_initrd_base, retained_initrd_size;
+extern unsigned char reuse_initrd;
 
 #endif /* KEXEC_S390_H */
-- 
2.55.0

base commit: 29898e149feb5c615b3ab6313260d58315bf1d8d


                 reply	other threads:[~2026-08-20 10:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260820101350.4413-1-josephc@linux.ibm.com \
    --to=josephc@linux.ibm.com \
    --cc=eoin.mcnamara@ibm.com \
    --cc=iii@de.ibm.com \
    --cc=kexec@lists.infradead.org \
    --cc=linux-s390@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.