Kexec Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: kexec@lists.infradead.org
Cc: horms@verge.net.au, Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH v1 1/1] kexec: x86: Use init_size in 32-bit case as well
Date: Wed,  6 Nov 2024 19:58:07 +0200	[thread overview]
Message-ID: <20241106175807.1042574-1-andriy.shevchenko@linux.intel.com> (raw)

If the region of the memory is not enough for the decompressed
kernel, e.g., it follows by reserved memory, Bad Things may happen
as it's proven to be in practice on Intel Merrifield platform.

Include decompressed kernel size into the calculations for finding
the appropriate hole in memory to load kernel to.

Note, this has been already done for 64-bit case, this just
synchronises the approach for 32-bit case.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 kexec/arch/i386/kexec-bzImage.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/kexec/arch/i386/kexec-bzImage.c b/kexec/arch/i386/kexec-bzImage.c
index 1b8f20c5b7d6..62260139862c 100644
--- a/kexec/arch/i386/kexec-bzImage.c
+++ b/kexec/arch/i386/kexec-bzImage.c
@@ -116,9 +116,9 @@ int do_bzImage_load(struct kexec_info *info,
 	struct entry32_regs regs32;
 	struct entry16_regs regs16;
 	unsigned int relocatable_kernel = 0;
-	unsigned long kernel32_load_addr;
 	char *modified_cmdline;
 	unsigned long cmdline_end;
+	unsigned long kernel32_load_addr, k_size;
 	unsigned long kern16_size_needed;
 	unsigned long heap_size = 0;
 
@@ -274,8 +274,10 @@ int do_bzImage_load(struct kexec_info *info,
 	}
 	
 	/* The main kernel segment */
-	size = kernel_len - kern16_size;
-
+	k_size = kernel_len - kern16_size;
+	/* need to use run-time size for buffer searching */
+	dbgprintf("kernel init_size 0x%x\n", real_mode->init_size);
+	size = _ALIGN(real_mode->init_size, 4096);
 	if (real_mode->protocol_version >=0x0205 && relocatable_kernel) {
 		/* Relocatable bzImage */
 		unsigned long kern_align = real_mode->kernel_alignment;
@@ -285,14 +287,13 @@ int do_bzImage_load(struct kexec_info *info,
 			kernel32_max_addr = real_mode->initrd_addr_max;
 
 		kernel32_load_addr = add_buffer(info, kernel + kern16_size,
-						size, size, kern_align,
+						k_size, size, kern_align,
 						0x100000, kernel32_max_addr,
 						1);
-	}
-	else {
+	} else {
 		kernel32_load_addr = KERN32_BASE;
-		add_segment(info, kernel + kern16_size, size,
-				kernel32_load_addr, size);
+		add_segment(info, kernel + kern16_size, k_size,
+				kernel32_load_addr, k_size);
 	}
 		
 	dbgprintf("Loaded 32bit kernel at 0x%lx\n", kernel32_load_addr);
-- 
2.43.0.rc1.1336.g36b5255a03ac


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

             reply	other threads:[~2024-11-06 17:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-06 17:58 Andy Shevchenko [this message]
2024-11-08  8:02 ` [PATCH v1 1/1] kexec: x86: Use init_size in 32-bit case as well Simon Horman

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=20241106175807.1042574-1-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=horms@verge.net.au \
    --cc=kexec@lists.infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox