All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joseph Cathcart <cathcartj08@gmail.com>
To: kexec@lists.infradead.org, linux-s390@vger.kernel.org
Cc: eoin.mcnamara@ibm.com, iii@de.ibm.com,
	Joseph Cathcart <cathcartj08@gmail.com>
Subject: [PATCH v1] kexec-tools/s390: Improve initrd memory reservation
Date: Fri, 28 Aug 2026 17:22:56 +0200	[thread overview]
Message-ID: <20260828152256.6892-1-cathcartj08@gmail.com> (raw)

Improve memory reservation for initrd. Remove unnecessary initrd
range from memory_ranges[]. Initrd currently falls between
"System RAM" ranges, and is therefore already reserved.

Refactor so that arch_reuse_initrd() is responsible for populating
retained_initrd_base and retained_initrd_size, rather than
get_memory_ranges_s390().

Add die() case for when user uses --reuseinitrd while booting a
crash kernel.

Signed-off-by: Joseph Cathcart <cathcartj08@gmail.com>
---
 kexec/arch/s390/kexec-image.c |  8 ++++++--
 kexec/arch/s390/kexec-s390.c  | 19 ++++++++++---------
 kexec/arch/s390/kexec-s390.h  |  2 +-
 3 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/kexec/arch/s390/kexec-image.c b/kexec/arch/s390/kexec-image.c
index 1a59a32..a9e5442 100644
--- a/kexec/arch/s390/kexec-image.c
+++ b/kexec/arch/s390/kexec-image.c
@@ -79,7 +79,8 @@ 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");
+		die("--reuseinitrd not supported with --kexec-file-syscall. "
+			"Please use --kexec-syscall\n");
 
 	if (ramdisk) {
 		info->initrd_fd = open(ramdisk, O_RDONLY);
@@ -143,6 +144,9 @@ 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))
@@ -173,7 +177,7 @@ image_s390_load(int argc, char **argv, const char *kernel_buf,
 				  ramdisk_origin, ramdisk_len);
 	} else if (reuse_initrd) {
 		ramdisk_origin = retained_initrd_base;
-		ramdisk_len = retained_initrd_size;
+		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 4e77fc4..fd0d87e 100644
--- a/kexec/arch/s390/kexec-s390.c
+++ b/kexec/arch/s390/kexec-s390.c
@@ -26,10 +26,17 @@
 
 static struct memory_range memory_range[MAX_MEMORY_RANGES];
 unsigned long long retained_initrd_base, retained_initrd_size;
-unsigned int reuse_initrd = 0;
+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;
 }
 
@@ -158,7 +165,6 @@ int get_memory_ranges_s390(struct memory_range memory_range[], int *ranges,
 {
 	char crash_kernel[] = "Crash kernel\n";
 	char sys_ram[] = "System RAM\n";
-	char kernel_initrd[] = "initrd\n";
 	const char *iomem = proc_iomem();
 	FILE *fp;
 	char line[80];
@@ -182,16 +188,11 @@ int get_memory_ranges_s390(struct memory_range memory_range[], int *ranges,
 		sscanf(line,"%llx-%llx : %n", &start, &end, &cons);
 		str = line+cons;
 		if ((memcmp(str, sys_ram, strlen(sys_ram)) == 0) ||
-			((memcmp(str, kernel_initrd, strlen(kernel_initrd)) == 0) && reuse_initrd) ||
-			((memcmp(str, crash_kernel, strlen(crash_kernel)) == 0) && with_crashk)) {
+		    ((memcmp(str, crash_kernel, strlen(crash_kernel)) == 0) &&
+		     with_crashk)) {
 			memory_range[current_range].start = start;
 			memory_range[current_range].end = end;
 			memory_range[current_range].type = RANGE_RAM;
-			if (memcmp(str, kernel_initrd, strlen(kernel_initrd)) == 0) {
-				retained_initrd_base = start;
-				retained_initrd_size = end - start + 1;
-			}
-
 			current_range++;
 		}
 		else {
diff --git a/kexec/arch/s390/kexec-s390.h b/kexec/arch/s390/kexec-s390.h
index a990739..7e85976 100644
--- a/kexec/arch/s390/kexec-s390.h
+++ b/kexec/arch/s390/kexec-s390.h
@@ -35,6 +35,6 @@ 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 int reuse_initrd;
+extern unsigned char reuse_initrd;
 
 #endif /* KEXEC_S390_H */
-- 
2.55.0

base commit: 43c5cba85ad23cc69c423527d9587c59b89fa437

             reply	other threads:[~2026-08-28 15:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-28 15:22 Joseph Cathcart [this message]
2026-09-21  9:23 ` [PATCH v1] kexec-tools/s390: Improve initrd memory reservation Ilya Leoshkevich

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=20260828152256.6892-1-cathcartj08@gmail.com \
    --to=cathcartj08@gmail.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.