Kexec Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/1] kexec: x86: Use init_size in 32-bit case as well
@ 2024-11-06 17:58 Andy Shevchenko
  2024-11-08  8:02 ` Simon Horman
  0 siblings, 1 reply; 2+ messages in thread
From: Andy Shevchenko @ 2024-11-06 17:58 UTC (permalink / raw)
  To: kexec; +Cc: horms, Andy Shevchenko

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

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

* Re: [PATCH v1 1/1] kexec: x86: Use init_size in 32-bit case as well
  2024-11-06 17:58 [PATCH v1 1/1] kexec: x86: Use init_size in 32-bit case as well Andy Shevchenko
@ 2024-11-08  8:02 ` Simon Horman
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Horman @ 2024-11-08  8:02 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: kexec

On Wed, Nov 06, 2024 at 07:58:07PM +0200, Andy Shevchenko wrote:
> 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>

Thanks Andy, applied.

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

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

end of thread, other threads:[~2024-11-08  8:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-06 17:58 [PATCH v1 1/1] kexec: x86: Use init_size in 32-bit case as well Andy Shevchenko
2024-11-08  8:02 ` Simon Horman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox