public inbox for kexec@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH v8 0/7] kexec: put bzImage and ramdisk above 4G for x86 64bit
@ 2013-01-30 21:25 Yinghai Lu
  2013-01-30 21:25 ` [PATCH v8 1/7] kexec, x86: set booloader id in setup_header Yinghai Lu
                   ` (6 more replies)
  0 siblings, 7 replies; 11+ messages in thread
From: Yinghai Lu @ 2013-01-30 21:25 UTC (permalink / raw)
  To: Simon Horman, H. Peter Anvin, Vivek Goyal, Eric W. Biederman
  Cc: Yinghai Lu, kexec

Now we have limit kdump reserved under 896M, because kexec has the limitation.
and also bzImage need to stay under 4g.

kernel parts changes get into tip tree now and could be found at:
	git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86/mm2

here patches are for kexec tools to load bzImage and ramdisk above 4G
acccording to new added boot header fields.

it will only load high with 64bit kernel with 2.12 setup header.

-v3: address review from Eric to use locate_hole at first.
     use xloadflags instead.
-v4: remove the restriction about bzImage not crossing GB boundary.
     add real-mode fix for bzImage.
     add --entry-32bit and --real-mode for skip bzImage64.
-v5: use USE_EXT_BOOT_PARAMS bit in xloadflags.
-v6: use sentinel instead of USE_EXT_BOOT_PARAMS.
     add crashkernel_low support
-v7: Separate bootloader id setting in another patch
-v8: update for CAN_BE_LOADED_ABOVE_4G is changed to bit1.
     also make it appliable to current kexec-tools devel tree.

Yinghai Lu (7):
  kexec, x86: set booloader id in setup_header
  kexec, x86: add boot header member for version 2.12
  kexec, x86: clean boot_params area for entry-32bit path
  kexec, x86: Fix bzImage real-mode booting
  kexec, x86: put ramdisk/cmd_line above 4G for 64bit bzImage
  kexec, x86_64: Load bzImage64 above 4G
  kexec, x86: handle Crash low kernel range

 include/x86/x86-linux.h                |   27 ++-
 kexec/arch/i386/crashdump-x86.c        |   21 +++
 kexec/arch/i386/include/arch/options.h |    4 +-
 kexec/arch/i386/kexec-bzImage.c        |   78 ++++++--
 kexec/arch/i386/x86-linux-setup.c      |   38 +++-
 kexec/arch/i386/x86-linux-setup.h      |   15 +-
 kexec/arch/x86_64/Makefile             |    1 +
 kexec/arch/x86_64/kexec-bzImage64.c    |  312 ++++++++++++++++++++++++++++++++
 kexec/arch/x86_64/kexec-x86_64.c       |    1 +
 kexec/arch/x86_64/kexec-x86_64.h       |    5 +
 10 files changed, 471 insertions(+), 31 deletions(-)
 create mode 100644 kexec/arch/x86_64/kexec-bzImage64.c

-- 
1.7.10.4


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

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

* [PATCH v8 1/7] kexec, x86: set booloader id in setup_header
  2013-01-30 21:25 [PATCH v8 0/7] kexec: put bzImage and ramdisk above 4G for x86 64bit Yinghai Lu
@ 2013-01-30 21:25 ` Yinghai Lu
  2013-01-30 21:25 ` [PATCH v8 2/7] kexec, x86: add boot header member for version 2.12 Yinghai Lu
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Yinghai Lu @ 2013-01-30 21:25 UTC (permalink / raw)
  To: Simon Horman, H. Peter Anvin, Vivek Goyal, Eric W. Biederman
  Cc: Yinghai Lu, kexec

set LOADER_TYPE_KEXEC

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 include/x86/x86-linux.h           |    1 +
 kexec/arch/i386/x86-linux-setup.c |    2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/x86/x86-linux.h b/include/x86/x86-linux.h
index 8f7a797..ea11042 100644
--- a/include/x86/x86-linux.h
+++ b/include/x86/x86-linux.h
@@ -142,6 +142,7 @@ struct x86_linux_param_header {
 #define LOADER_TYPE_BOOTSECT_LOADER 2
 #define LOADER_TYPE_SYSLINUX        3
 #define LOADER_TYPE_ETHERBOOT       4
+#define LOADER_TYPE_KEXEC           0x0D
 #define LOADER_TYPE_UNKNOWN         0xFF
 	uint8_t  loader_flags;			/* 0x211 */
 	uint8_t  reserved12[2];			/* 0x212 */
diff --git a/kexec/arch/i386/x86-linux-setup.c b/kexec/arch/i386/x86-linux-setup.c
index ef62553..d09c6ce 100644
--- a/kexec/arch/i386/x86-linux-setup.c
+++ b/kexec/arch/i386/x86-linux-setup.c
@@ -56,7 +56,7 @@ void setup_linux_bootloader_parameters(
 	unsigned long initrd_base, initrd_addr_max;
 
 	/* Say I'm a boot loader */
-	real_mode->loader_type = LOADER_TYPE_UNKNOWN;
+	real_mode->loader_type = LOADER_TYPE_KEXEC << 4;
 
 	/* No loader flags */
 	real_mode->loader_flags = 0;
-- 
1.7.10.4


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

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

* [PATCH v8 2/7] kexec, x86: add boot header member for version 2.12
  2013-01-30 21:25 [PATCH v8 0/7] kexec: put bzImage and ramdisk above 4G for x86 64bit Yinghai Lu
  2013-01-30 21:25 ` [PATCH v8 1/7] kexec, x86: set booloader id in setup_header Yinghai Lu
@ 2013-01-30 21:25 ` Yinghai Lu
  2013-01-30 21:25 ` [PATCH v8 3/7] kexec, x86: clean boot_params area for entry-32bit path Yinghai Lu
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Yinghai Lu @ 2013-01-30 21:25 UTC (permalink / raw)
  To: Simon Horman, H. Peter Anvin, Vivek Goyal, Eric W. Biederman
  Cc: Yinghai Lu, kexec

will use ext_ramdisk_image/size, and xloadflags to put
ramdisk and bzImage high for 64bit.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 include/x86/x86-linux.h |   26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/include/x86/x86-linux.h b/include/x86/x86-linux.h
index ea11042..0949dc2 100644
--- a/include/x86/x86-linux.h
+++ b/include/x86/x86-linux.h
@@ -32,7 +32,7 @@ struct drive_info_struct {
 };
 struct sys_desc_table {
 	uint16_t length;
-	uint8_t  table[318];
+	uint8_t  table[30];
 };
 
 struct apm_bios_info {
@@ -112,6 +112,10 @@ struct x86_linux_param_header {
 	struct apm_bios_info apm_bios_info;	/* 0x40 */
 	struct drive_info_struct drive_info;	/* 0x80 */
 	struct sys_desc_table sys_desc_table;	/* 0xa0 */
+	uint32_t ext_ramdisk_image;		/* 0xc0 */
+	uint32_t ext_ramdisk_size;		/* 0xc4 */
+	uint32_t ext_cmd_line_ptr;		/* 0xc8 */
+	uint8_t reserved4_1[0x1e0 - 0xcc];	/* 0xcc */
 	uint32_t alt_mem_k;			/* 0x1e0 */
 	uint8_t  reserved5[4];			/* 0x1e4 */
 	uint8_t  e820_map_nr;			/* 0x1e8 */
@@ -175,11 +179,18 @@ struct x86_linux_param_header {
 	/* 2.04+ */
 	uint32_t kernel_alignment;		/* 0x230 */
 	uint8_t  relocatable_kernel;		/* 0x234 */
-	uint8_t  reserved15[3];			/* 0x235 */
+	uint8_t  min_alignment;			/* 0x235 */
+	uint16_t xloadflags;			/* 0x236 */
 	uint32_t cmdline_size;			/* 0x238 */
 	uint32_t hardware_subarch;		/* 0x23C */
 	uint64_t hardware_subarch_data;		/* 0x240 */
-	uint8_t  reserved16[0x290 - 0x248];	/* 0x248 */
+	uint32_t payload_offset;		/* 0x248 */
+	uint32_t payload_length;		/* 0x24C */
+	uint64_t setup_data;			/* 0x250 */
+	uint64_t pref_address;			/* 0x258 */
+	uint32_t init_size;			/* 0x260 */
+	uint32_t handover_offset;		/* 0x264 */
+	uint8_t  reserved16[0x290 - 0x268];	/* 0x268 */
 	uint32_t edd_mbr_sig_buffer[EDD_MBR_SIG_MAX];	/* 0x290 */
 #endif
 	struct 	e820entry e820_map[E820MAX];	/* 0x2d0 */
@@ -196,7 +207,11 @@ struct x86_linux_faked_param_header {
 };
 
 struct x86_linux_header {
-	uint8_t  reserved1[0x1f1];		/* 0x000 */
+	uint8_t  reserved1[0xc0];		/* 0x000 */
+	uint32_t ext_ramdisk_image;		/* 0x0c0 */
+	uint32_t ext_ramdisk_size;		/* 0x0c4 */
+	uint32_t ext_cmd_line_ptr;		/* 0x0c8 */
+	uint8_t  reserved1_1[0x1f1-0xcc];	/* 0x0cc */
 	uint8_t  setup_sects;			/* 0x1f1 */
 	uint16_t root_flags;			/* 0x1f2 */
 	uint32_t syssize;			/* 0x1f4 */
@@ -229,7 +244,8 @@ struct x86_linux_header {
 
 	uint32_t kernel_alignment;		/* 0x230 */
 	uint8_t  relocatable_kernel;		/* 0x234 */
-	uint8_t  reserved6[3];			/* 0x235 */
+	uint8_t  min_alignment;			/* 0x235 */
+	uint16_t xloadflags;			/* 0x236 */
 	uint32_t cmdline_size;			/* 0x238 */
 	uint32_t hardware_subarch;		/* 0x23C */
 	uint64_t hardware_subarch_data;		/* 0x240 */
-- 
1.7.10.4


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

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

* [PATCH v8 3/7] kexec, x86: clean boot_params area for entry-32bit path
  2013-01-30 21:25 [PATCH v8 0/7] kexec: put bzImage and ramdisk above 4G for x86 64bit Yinghai Lu
  2013-01-30 21:25 ` [PATCH v8 1/7] kexec, x86: set booloader id in setup_header Yinghai Lu
  2013-01-30 21:25 ` [PATCH v8 2/7] kexec, x86: add boot header member for version 2.12 Yinghai Lu
@ 2013-01-30 21:25 ` Yinghai Lu
  2013-01-30 21:34   ` H. Peter Anvin
  2013-01-30 21:25 ` [PATCH v8 4/7] kexec, x86: Fix bzImage real-mode booting Yinghai Lu
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 11+ messages in thread
From: Yinghai Lu @ 2013-01-30 21:25 UTC (permalink / raw)
  To: Simon Horman, H. Peter Anvin, Vivek Goyal, Eric W. Biederman
  Cc: Yinghai Lu, kexec

kexec bzImage path setup data is shared with real-mode path, and
setup_header is copied together with setup_code.
Later 32bit just use whole area as boot_params for real_mode_data.
but those area for boot_params around setup_header is
not cleaned that will leave some field in boot_param as
non-zero value.

So clean around setup_header area for non real-mode entry path.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 kexec/arch/i386/kexec-bzImage.c |   15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/kexec/arch/i386/kexec-bzImage.c b/kexec/arch/i386/kexec-bzImage.c
index 83a023d..1dfa3d7 100644
--- a/kexec/arch/i386/kexec-bzImage.c
+++ b/kexec/arch/i386/kexec-bzImage.c
@@ -98,6 +98,19 @@ void bzImage_usage(void)
        
 }
 
+static void clean_boot_params(unsigned char *real_mode, unsigned long size)
+{
+	unsigned long end;
+
+	/* clear value before header */
+	memset(real_mode, 0, 0x1f1);
+	/* clear value after setup_header  */
+	end = *(real_mode + 0x201);
+	end += 0x202;
+	if (end < size)
+		memset(real_mode + end, 0, size - end);
+}
+
 int do_bzImage_load(struct kexec_info *info,
 	const char *kernel, off_t kernel_len,
 	const char *command_line, off_t command_line_len,
@@ -212,6 +225,8 @@ int do_bzImage_load(struct kexec_info *info,
 	setup_size = kern16_size + command_line_len + PURGATORY_CMDLINE_SIZE;
 	real_mode = xmalloc(setup_size);
 	memcpy(real_mode, kernel, kern16_size);
+	if (!real_mode_entry)
+		clean_boot_params((unsigned char *)real_mode, kern16_size);
 
 	if (info->kexec_flags & (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT)) {
 		/* If using bzImage for capture kernel, then we will not be
-- 
1.7.10.4


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

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

* [PATCH v8 4/7] kexec, x86: Fix bzImage real-mode booting
  2013-01-30 21:25 [PATCH v8 0/7] kexec: put bzImage and ramdisk above 4G for x86 64bit Yinghai Lu
                   ` (2 preceding siblings ...)
  2013-01-30 21:25 ` [PATCH v8 3/7] kexec, x86: clean boot_params area for entry-32bit path Yinghai Lu
@ 2013-01-30 21:25 ` Yinghai Lu
  2013-01-30 21:25 ` [PATCH v8 5/7] kexec, x86: put ramdisk/cmd_line above 4G for 64bit bzImage Yinghai Lu
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Yinghai Lu @ 2013-01-30 21:25 UTC (permalink / raw)
  To: Simon Horman, H. Peter Anvin, Vivek Goyal, Eric W. Biederman
  Cc: Yinghai Lu, kexec

We need to keep space for bss, heap/stack before command line.
otherwise command_line will be cleared by kernel 16bit init code.

also need to set 32bit start in real_mode header, kernel 16bit code
need to jump there.

Also don't touch regs16 if --real-mode is not specified.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 kexec/arch/i386/kexec-bzImage.c |   63 +++++++++++++++++++++++++++++++--------
 1 file changed, 50 insertions(+), 13 deletions(-)

diff --git a/kexec/arch/i386/kexec-bzImage.c b/kexec/arch/i386/kexec-bzImage.c
index 1dfa3d7..add0646 100644
--- a/kexec/arch/i386/kexec-bzImage.c
+++ b/kexec/arch/i386/kexec-bzImage.c
@@ -130,6 +130,8 @@ int do_bzImage_load(struct kexec_info *info,
 	unsigned long kernel32_load_addr;
 	char *modified_cmdline;
 	unsigned long cmdline_end;
+	unsigned long kern16_size_needed;
+	unsigned long heap_size = 0;
 
 	/*
 	 * Find out about the file I am about to load.
@@ -221,9 +223,31 @@ int do_bzImage_load(struct kexec_info *info,
 		elf_rel_build_load(info, &info->rhdr, purgatory, purgatory_size,
 					0x3000, 640*1024, -1, 0);
 	dbgprintf("Loaded purgatory at addr 0x%lx\n", info->rhdr.rel_addr);
+
 	/* The argument/parameter segment */
-	setup_size = kern16_size + command_line_len + PURGATORY_CMDLINE_SIZE;
+	if (real_mode_entry) {
+		/* need to include size for bss and heap etc */
+		if (setup_header.protocol_version >= 0x0201)
+			kern16_size_needed = setup_header.heap_end_ptr;
+		else
+			kern16_size_needed = kern16_size + 8192; /* bss */
+		if (kern16_size_needed < kern16_size)
+			kern16_size_needed = kern16_size;
+		if (kern16_size_needed > 0xfffc)
+			die("kern16_size_needed is more then 64k\n");
+		heap_size = 0xfffc - kern16_size_needed; /* less 64k */
+		heap_size &= ~(0x200 - 1);
+		kern16_size_needed += heap_size;
+	} else {
+		kern16_size_needed = kern16_size;
+		/* need to bigger than size of struct bootparams */
+		if (kern16_size_needed < 4096)
+			kern16_size_needed = 4096;
+	}
+	setup_size = kern16_size_needed + command_line_len +
+			 PURGATORY_CMDLINE_SIZE;
 	real_mode = xmalloc(setup_size);
+	memset(real_mode, 0, setup_size);
 	memcpy(real_mode, kernel, kern16_size);
 	if (!real_mode_entry)
 		clean_boot_params((unsigned char *)real_mode, kern16_size);
@@ -278,11 +302,18 @@ int do_bzImage_load(struct kexec_info *info,
 
 	/* Tell the kernel what is going on */
 	setup_linux_bootloader_parameters(info, real_mode, setup_base,
-		kern16_size, command_line, command_line_len,
+		kern16_size_needed, command_line, command_line_len,
 		initrd, initrd_len);
 
+	if (real_mode_entry && real_mode->protocol_version >= 0x0201) {
+		real_mode->loader_flags |= 0x80; /* CAN_USE_HEAP */
+		real_mode->heap_end_ptr += heap_size - 0x200; /*stack*/
+	}
+
 	/* Get the initial register values */
-	elf_rel_get_symbol(&info->rhdr, "entry16_regs", &regs16, sizeof(regs16));
+	if (real_mode_entry)
+		elf_rel_get_symbol(&info->rhdr, "entry16_regs",
+					 &regs16, sizeof(regs16));
 	elf_rel_get_symbol(&info->rhdr, "entry32_regs", &regs32, sizeof(regs32));
 	/*
 
@@ -301,16 +332,18 @@ int do_bzImage_load(struct kexec_info *info,
 	/*
 	 * Initialize the 16bit start information.
 	 */
-	regs16.ds = regs16.es = regs16.fs = regs16.gs = setup_base >> 4;
-	regs16.cs = regs16.ds + 0x20;
-	regs16.ip = 0;
-	/* XXX: Documentation/i386/boot.txt says 'ss' must equal 'ds' */
-	regs16.ss = (elf_rel_get_addr(&info->rhdr, "stack_end") - 64*1024) >> 4;
-	/* XXX: Documentation/i386/boot.txt says 'sp' must equal heap_end */
-	regs16.esp = 0xFFFC;
 	if (real_mode_entry) {
+		regs16.ds = regs16.es = regs16.fs = regs16.gs = setup_base >> 4;
+		regs16.cs = regs16.ds + 0x20;
+		regs16.ip = 0;
+		/* XXX: Documentation/i386/boot.txt says 'ss' must equal 'ds' */
+		regs16.ss = (elf_rel_get_addr(&info->rhdr, "stack_end") - 64*1024) >> 4;
+		/* XXX: Documentation/i386/boot.txt says 'sp' must equal heap_end */
+		regs16.esp = 0xFFFC;
+
 		printf("Starting the kernel in real mode\n");
 		regs32.eip = elf_rel_get_addr(&info->rhdr, "entry16");
+		real_mode->kernel_start = kernel32_load_addr;
 	}
 	if (real_mode_entry && kexec_debug) {
 		unsigned long entry16_debug, pre32, first32;
@@ -330,10 +363,14 @@ int do_bzImage_load(struct kexec_info *info,
 	
 		regs32.eip = entry16_debug;
 	}
-	elf_rel_set_symbol(&info->rhdr, "entry16_regs", &regs16, sizeof(regs16));
-	elf_rel_set_symbol(&info->rhdr, "entry16_debug_regs", &regs16, sizeof(regs16));
+	if (real_mode_entry) {
+		elf_rel_set_symbol(&info->rhdr, "entry16_regs",
+					 &regs16, sizeof(regs16));
+		elf_rel_set_symbol(&info->rhdr, "entry16_debug_regs",
+					 &regs16, sizeof(regs16));
+	}
 	elf_rel_set_symbol(&info->rhdr, "entry32_regs", &regs32, sizeof(regs32));
-	cmdline_end = setup_base + kern16_size + command_line_len - 1;
+	cmdline_end = setup_base + kern16_size_needed + command_line_len - 1;
 	elf_rel_set_symbol(&info->rhdr, "cmdline_end", &cmdline_end,
 			   sizeof(unsigned long));
 
-- 
1.7.10.4


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

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

* [PATCH v8 5/7] kexec, x86: put ramdisk/cmd_line above 4G for 64bit bzImage
  2013-01-30 21:25 [PATCH v8 0/7] kexec: put bzImage and ramdisk above 4G for x86 64bit Yinghai Lu
                   ` (3 preceding siblings ...)
  2013-01-30 21:25 ` [PATCH v8 4/7] kexec, x86: Fix bzImage real-mode booting Yinghai Lu
@ 2013-01-30 21:25 ` Yinghai Lu
  2013-01-30 21:25 ` [PATCH v8 6/7] kexec, x86_64: Load bzImage64 above 4G Yinghai Lu
  2013-01-30 21:25 ` [PATCH v8 7/7] kexec, x86: handle Crash low kernel range Yinghai Lu
  6 siblings, 0 replies; 11+ messages in thread
From: Yinghai Lu @ 2013-01-30 21:25 UTC (permalink / raw)
  To: Simon Horman, H. Peter Anvin, Vivek Goyal, Eric W. Biederman
  Cc: Yinghai Lu, kexec

We could put ramdisk/cmdline above for bzImage on 64bit for protocol 2.12.

-v2: change ext_... handling to way that eric like.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 kexec/arch/i386/x86-linux-setup.c |   36 +++++++++++++++++++++++++++---------
 kexec/arch/i386/x86-linux-setup.h |   15 +++++++++++++--
 2 files changed, 40 insertions(+), 11 deletions(-)

diff --git a/kexec/arch/i386/x86-linux-setup.c b/kexec/arch/i386/x86-linux-setup.c
index d09c6ce..e0ddc84 100644
--- a/kexec/arch/i386/x86-linux-setup.c
+++ b/kexec/arch/i386/x86-linux-setup.c
@@ -46,11 +46,11 @@ void init_linux_parameters(struct x86_linux_param_header *real_mode)
 	real_mode->cmdline_size = COMMAND_LINE_SIZE;
 }
 
-void setup_linux_bootloader_parameters(
+void setup_linux_bootloader_parameters_high(
 	struct kexec_info *info, struct x86_linux_param_header *real_mode,
 	unsigned long real_mode_base, unsigned long cmdline_offset,
 	const char *cmdline, off_t cmdline_len,
-	const char *initrd_buf, off_t initrd_size)
+	const char *initrd_buf, off_t initrd_size, int initrd_high)
 {
 	char *cmdline_ptr;
 	unsigned long initrd_base, initrd_addr_max;
@@ -62,10 +62,15 @@ void setup_linux_bootloader_parameters(
 	real_mode->loader_flags = 0;
 
 	/* Find the maximum initial ramdisk address */
-	initrd_addr_max = DEFAULT_INITRD_ADDR_MAX;
-	if (real_mode->protocol_version >= 0x0203) {
-		initrd_addr_max = real_mode->initrd_addr_max;
-		dbgprintf("initrd_addr_max is 0x%lx\n", initrd_addr_max);
+	if (initrd_high)
+		initrd_addr_max = ULONG_MAX;
+	else {
+		initrd_addr_max = DEFAULT_INITRD_ADDR_MAX;
+		if (real_mode->protocol_version >= 0x0203) {
+			initrd_addr_max = real_mode->initrd_addr_max;
+			dbgprintf("initrd_addr_max is 0x%lx\n",
+					 initrd_addr_max);
+		}
 	}
 
 	/* Load the initrd if we have one */
@@ -81,8 +86,16 @@ void setup_linux_bootloader_parameters(
 	}
 
 	/* Ramdisk address and size */
-	real_mode->initrd_start = initrd_base;
-	real_mode->initrd_size  = initrd_size;
+	real_mode->initrd_start = initrd_base & 0xffffffffUL;
+	real_mode->initrd_size  = initrd_size & 0xffffffffUL;
+
+	if (real_mode->protocol_version >= 0x020c &&
+	    (initrd_base & 0xffffffffUL) != initrd_base)
+		real_mode->ext_ramdisk_image = initrd_base >> 32;
+
+	if (real_mode->protocol_version >= 0x020c &&
+	    (initrd_size & 0xffffffffUL) != initrd_size)
+		real_mode->ext_ramdisk_size = initrd_size >> 32;
 
 	/* The location of the command line */
 	/* if (real_mode_base == 0x90000) { */
@@ -91,7 +104,12 @@ void setup_linux_bootloader_parameters(
 		/* setup_move_size */
 	/* } */
 	if (real_mode->protocol_version >= 0x0202) {
-		real_mode->cmd_line_ptr = real_mode_base + cmdline_offset;
+		unsigned long cmd_line_ptr = real_mode_base + cmdline_offset;
+
+		real_mode->cmd_line_ptr = cmd_line_ptr & 0xffffffffUL;
+		if ((real_mode->protocol_version >= 0x020c) &&
+		    ((cmd_line_ptr & 0xffffffffUL) != cmd_line_ptr))
+			real_mode->ext_cmd_line_ptr = cmd_line_ptr >> 32;
 	}
 
 	/* Fill in the command line */
diff --git a/kexec/arch/i386/x86-linux-setup.h b/kexec/arch/i386/x86-linux-setup.h
index 96fbd33..09aed4d 100644
--- a/kexec/arch/i386/x86-linux-setup.h
+++ b/kexec/arch/i386/x86-linux-setup.h
@@ -2,11 +2,22 @@
 #define X86_LINUX_SETUP_H
 
 void init_linux_parameters(struct x86_linux_param_header *real_mode);
-void setup_linux_bootloader_parameters(
+void setup_linux_bootloader_parameters_high(
 	struct kexec_info *info, struct x86_linux_param_header *real_mode,
 	unsigned long real_mode_base, unsigned long cmdline_offset,
 	const char *cmdline, off_t cmdline_len,
-	const char *initrd_buf, off_t initrd_size);
+	const char *initrd_buf, off_t initrd_size, int initrd_high);
+static inline void setup_linux_bootloader_parameters(
+	struct kexec_info *info, struct x86_linux_param_header *real_mode,
+	unsigned long real_mode_base, unsigned long cmdline_offset,
+	const char *cmdline, off_t cmdline_len,
+	const char *initrd_buf, off_t initrd_size)
+{
+	setup_linux_bootloader_parameters_high(info,
+			real_mode, real_mode_base,
+			cmdline_offset, cmdline, cmdline_len,
+			initrd_buf, initrd_size, 0);
+}
 void setup_linux_system_parameters(struct kexec_info *info,
 	struct x86_linux_param_header *real_mode);
 
-- 
1.7.10.4


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

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

* [PATCH v8 6/7] kexec, x86_64: Load bzImage64 above 4G
  2013-01-30 21:25 [PATCH v8 0/7] kexec: put bzImage and ramdisk above 4G for x86 64bit Yinghai Lu
                   ` (4 preceding siblings ...)
  2013-01-30 21:25 ` [PATCH v8 5/7] kexec, x86: put ramdisk/cmd_line above 4G for 64bit bzImage Yinghai Lu
@ 2013-01-30 21:25 ` Yinghai Lu
  2013-01-30 21:25 ` [PATCH v8 7/7] kexec, x86: handle Crash low kernel range Yinghai Lu
  6 siblings, 0 replies; 11+ messages in thread
From: Yinghai Lu @ 2013-01-30 21:25 UTC (permalink / raw)
  To: Simon Horman, H. Peter Anvin, Vivek Goyal, Eric W. Biederman
  Cc: Yinghai Lu, kexec

need to check xloadflags to see the bzImage is for 64bit relocatable.

-v2: add kexec-bzImage64.c according to Eric.
-v3: don't need to purgatory under 2g after Eric's change to purgatory code.
-v4: use locate_hole find position first then add_buffer... suggested by Eric
     add buffer for kernel image at last to make kexec-load faster.
     use xloadflags in setup_header to tell if is bzImage64.
     remove not cross GB boundary searching.
     add --entry-32bit and --real-mode for skipping bzImage64.
-v5: add buffer with runtime size instead, so kernel could use BRK
     early and safely.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 kexec/arch/i386/include/arch/options.h |    4 +-
 kexec/arch/x86_64/Makefile             |    1 +
 kexec/arch/x86_64/kexec-bzImage64.c    |  312 ++++++++++++++++++++++++++++++++
 kexec/arch/x86_64/kexec-x86_64.c       |    1 +
 kexec/arch/x86_64/kexec-x86_64.h       |    5 +
 5 files changed, 322 insertions(+), 1 deletion(-)
 create mode 100644 kexec/arch/x86_64/kexec-bzImage64.c

diff --git a/kexec/arch/i386/include/arch/options.h b/kexec/arch/i386/include/arch/options.h
index 89dbd26..aaac731 100644
--- a/kexec/arch/i386/include/arch/options.h
+++ b/kexec/arch/i386/include/arch/options.h
@@ -29,6 +29,7 @@
 #define OPT_MOD 		(OPT_ARCH_MAX+7)
 #define OPT_VGA 		(OPT_ARCH_MAX+8)
 #define OPT_REAL_MODE		(OPT_ARCH_MAX+9)
+#define OPT_ENTRY_32BIT		(OPT_ARCH_MAX+10)
 
 /* Options relevant to the architecture (excluding loader-specific ones): */
 #define KEXEC_ARCH_OPTIONS \
@@ -68,7 +69,8 @@
 	{ "args-linux",		0, NULL, OPT_ARGS_LINUX },	\
 	{ "args-none",		0, NULL, OPT_ARGS_NONE },	\
 	{ "module",		1, 0, OPT_MOD },		\
-	{ "real-mode",		0, NULL, OPT_REAL_MODE },
+	{ "real-mode",		0, NULL, OPT_REAL_MODE },	\
+	{ "entry-32bit",	0, NULL, OPT_ENTRY_32BIT },
 
 #define KEXEC_ALL_OPT_STR KEXEC_ARCH_OPT_STR
 
diff --git a/kexec/arch/x86_64/Makefile b/kexec/arch/x86_64/Makefile
index 405bdf5..1cf10f9 100644
--- a/kexec/arch/x86_64/Makefile
+++ b/kexec/arch/x86_64/Makefile
@@ -13,6 +13,7 @@ x86_64_KEXEC_SRCS += kexec/arch/i386/crashdump-x86.c
 x86_64_KEXEC_SRCS_native =  kexec/arch/x86_64/kexec-x86_64.c
 x86_64_KEXEC_SRCS_native += kexec/arch/x86_64/kexec-elf-x86_64.c
 x86_64_KEXEC_SRCS_native += kexec/arch/x86_64/kexec-elf-rel-x86_64.c
+x86_64_KEXEC_SRCS_native += kexec/arch/x86_64/kexec-bzImage64.c
 
 x86_64_KEXEC_SRCS += $(x86_64_KEXEC_SRCS_native)
 
diff --git a/kexec/arch/x86_64/kexec-bzImage64.c b/kexec/arch/x86_64/kexec-bzImage64.c
new file mode 100644
index 0000000..0075f28
--- /dev/null
+++ b/kexec/arch/x86_64/kexec-bzImage64.c
@@ -0,0 +1,312 @@
+/*
+ * kexec: Linux boots Linux
+ *
+ * Copyright (C) 2003-2010  Eric Biederman (ebiederm@xmission.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation (version 2 of the License).
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#define _GNU_SOURCE
+#include <stddef.h>
+#include <stdio.h>
+#include <string.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <elf.h>
+#include <boot/elf_boot.h>
+#include <ip_checksum.h>
+#include <x86/x86-linux.h>
+#include "../../kexec.h"
+#include "../../kexec-elf.h"
+#include "../../kexec-syscall.h"
+#include "kexec-x86_64.h"
+#include "../i386/x86-linux-setup.h"
+#include "../i386/crashdump-x86.h"
+#include <arch/options.h>
+
+static const int probe_debug = 0;
+
+int bzImage64_probe(const char *buf, off_t len)
+{
+	const struct x86_linux_header *header;
+
+	if ((uintmax_t)len < (uintmax_t)(2 * 512)) {
+		if (probe_debug)
+			fprintf(stderr, "File is too short to be a bzImage!\n");
+		return -1;
+	}
+	header = (const struct x86_linux_header *)buf;
+	if (memcmp(header->header_magic, "HdrS", 4) != 0) {
+		if (probe_debug)
+			fprintf(stderr, "Not a bzImage\n");
+		return -1;
+	}
+	if (header->boot_sector_magic != 0xAA55) {
+		if (probe_debug)
+			fprintf(stderr, "No x86 boot sector present\n");
+		/* No x86 boot sector present */
+		return -1;
+	}
+	if (header->protocol_version < 0x020C) {
+		if (probe_debug)
+			fprintf(stderr, "Must be at least protocol version 2.12\n");
+		/* Must be at least protocol version 2.12 */
+		return -1;
+	}
+	if ((header->loadflags & 1) == 0) {
+		if (probe_debug)
+			fprintf(stderr, "zImage not a bzImage\n");
+		/* Not a bzImage */
+		return -1;
+	}
+	if ((header->xloadflags & 3) != 3) {
+		if (probe_debug)
+			fprintf(stderr, "Not a relocatable bzImage64\n");
+		/* Must be KERNEL_64 and CAN_BE_LOADED_ABOVE_4G */
+		return -1;
+	}
+	/* I've got a relocatable bzImage64 */
+	if (probe_debug)
+		fprintf(stderr, "It's a relocatable bzImage64\n");
+	return 0;
+}
+
+void bzImage64_usage(void)
+{
+	printf( "    --entry-32bit         Use the kernels 32bit entry point.\n"
+		"    --real-mode           Use the kernels real mode entry point.\n"
+		"    --command-line=STRING Set the kernel command line to STRING.\n"
+		"    --append=STRING       Set the kernel command line to STRING.\n"
+		"    --reuse-cmdline       Use kernel command line from running system.\n"
+		"    --initrd=FILE         Use FILE as the kernel's initial ramdisk.\n"
+		"    --ramdisk=FILE        Use FILE as the kernel's initial ramdisk.\n"
+		);
+}
+
+static void clean_boot_params(unsigned char *real_mode, unsigned long size)
+{
+	unsigned long end;
+
+	/* clear value before header */
+	memset(real_mode, 0, 0x1f1);
+	/* clear value after setup_header  */
+	end = *(real_mode + 0x201);
+	end += 0x202;
+	if (end < size)
+		memset(real_mode + end, 0, size - end);
+}
+
+static int do_bzImage64_load(struct kexec_info *info,
+			const char *kernel, off_t kernel_len,
+			const char *command_line, off_t command_line_len,
+			const char *initrd, off_t initrd_len)
+{
+	struct x86_linux_header setup_header;
+	struct x86_linux_param_header *real_mode;
+	int setup_sects;
+	size_t size;
+	int kern16_size;
+	unsigned long setup_base, setup_size;
+	struct entry64_regs regs64;
+	char *modified_cmdline;
+	unsigned long cmdline_end;
+	unsigned long align, addr, k_size;
+	unsigned kern16_size_needed;
+
+	/*
+	 * Find out about the file I am about to load.
+	 */
+	if ((uintmax_t)kernel_len < (uintmax_t)(2 * 512))
+		return -1;
+
+	memcpy(&setup_header, kernel, sizeof(setup_header));
+	setup_sects = setup_header.setup_sects;
+	if (setup_sects == 0)
+		setup_sects = 4;
+	kern16_size = (setup_sects + 1) * 512;
+	if (kernel_len < kern16_size) {
+		fprintf(stderr, "BzImage truncated?\n");
+		return -1;
+	}
+
+	if ((uintmax_t)command_line_len > (uintmax_t)setup_header.cmdline_size) {
+		dbgprintf("Kernel command line too long for kernel!\n");
+		return -1;
+	}
+
+	/* Need to append some command line parameters internally in case of
+	 * taking crash dumps.
+	 */
+	if (info->kexec_flags & (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT)) {
+		modified_cmdline = xmalloc(COMMAND_LINE_SIZE);
+		memset((void *)modified_cmdline, 0, COMMAND_LINE_SIZE);
+		if (command_line) {
+			strncpy(modified_cmdline, command_line,
+					COMMAND_LINE_SIZE);
+			modified_cmdline[COMMAND_LINE_SIZE - 1] = '\0';
+		}
+
+		/* If panic kernel is being loaded, additional segments need
+		 * to be created. load_crashdump_segments will take care of
+		 * loading the segments as high in memory as possible, hence
+		 * in turn as away as possible from kernel to avoid being
+		 * stomped by the kernel.
+		 */
+		if (load_crashdump_segments(info, modified_cmdline, -1, 0) < 0)
+			return -1;
+
+		/* Use new command line buffer */
+		command_line = modified_cmdline;
+		command_line_len = strlen(command_line) + 1;
+	}
+
+	/* x86_64 purgatory could be anywhere */
+	elf_rel_build_load(info, &info->rhdr, purgatory, purgatory_size,
+				0x3000, -1, -1, 0);
+	dbgprintf("Loaded purgatory at addr 0x%lx\n", info->rhdr.rel_addr);
+	/* The argument/parameter segment */
+	kern16_size_needed = kern16_size;
+	if (kern16_size_needed < 4096)
+		kern16_size_needed = 4096;
+	setup_size = kern16_size_needed + command_line_len +
+				PURGATORY_CMDLINE_SIZE;
+	real_mode = xmalloc(setup_size);
+	memset(real_mode, 0, setup_size);
+	memcpy(real_mode, kernel, kern16_size);
+	clean_boot_params((unsigned char *)real_mode, kern16_size);
+
+	/* No real mode code will be executing. setup segment can be loaded
+	 * anywhere as we will be just reading command line.
+	 */
+	setup_base = add_buffer(info, real_mode, setup_size, setup_size,
+				16, 0x3000, -1, -1);
+
+	dbgprintf("Loaded real_mode_data and command line at 0x%lx\n",
+			setup_base);
+
+	/* The main kernel segment */
+	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 = (real_mode->init_size + (4096 - 1)) & ~(4096 - 1);
+	align = real_mode->kernel_alignment;
+	addr = add_buffer(info, kernel + kern16_size, k_size,
+			  size, align, 0x100000, -1, -1);
+	if (addr == ULONG_MAX)
+		die("can not load bzImage64");
+	dbgprintf("Loaded 64bit kernel at 0x%lx\n", addr);
+
+	/* Tell the kernel what is going on */
+	setup_linux_bootloader_parameters_high(info, real_mode, setup_base,
+			kern16_size_needed, command_line, command_line_len,
+			initrd, initrd_len, 1); /* put initrd high too */
+
+	elf_rel_get_symbol(&info->rhdr, "entry64_regs", &regs64,
+				 sizeof(regs64));
+	regs64.rbx = 0;           /* Bootstrap processor */
+	regs64.rsi = setup_base;  /* Pointer to the parameters */
+	regs64.rip = addr + 0x200; /* the entry point for startup_64 */
+	regs64.rsp = elf_rel_get_addr(&info->rhdr, "stack_end"); /* Stack, unused */
+	elf_rel_set_symbol(&info->rhdr, "entry64_regs", &regs64,
+				 sizeof(regs64));
+
+	cmdline_end = setup_base + kern16_size_needed + command_line_len - 1;
+	elf_rel_set_symbol(&info->rhdr, "cmdline_end", &cmdline_end,
+			   sizeof(unsigned long));
+
+	/* Fill in the information BIOS calls would normally provide. */
+	setup_linux_system_parameters(info, real_mode);
+
+	return 0;
+}
+
+int bzImage64_load(int argc, char **argv, const char *buf, off_t len,
+	struct kexec_info *info)
+{
+	char *command_line = NULL;
+	const char *ramdisk = NULL, *append = NULL;
+	char *ramdisk_buf;
+	off_t ramdisk_length = 0;
+	int command_line_len;
+	int entry_16bit = 0, entry_32bit = 0;
+	int opt;
+	int result;
+
+	/* See options.h -- add any more there, too. */
+	static const struct option options[] = {
+		KEXEC_ARCH_OPTIONS
+		{ "command-line",	1, 0, OPT_APPEND },
+		{ "append",		1, 0, OPT_APPEND },
+		{ "reuse-cmdline",	0, 0, OPT_REUSE_CMDLINE },
+		{ "initrd",		1, 0, OPT_RAMDISK },
+		{ "ramdisk",		1, 0, OPT_RAMDISK },
+		{ "real-mode",		0, 0, OPT_REAL_MODE },
+		{ "entry-32bit",	0, 0, OPT_ENTRY_32BIT },
+		{ 0,			0, 0, 0 },
+	};
+	static const char short_options[] = KEXEC_ARCH_OPT_STR "d";
+
+	while ((opt = getopt_long(argc, argv, short_options, options, 0)) != -1) {
+		switch (opt) {
+		default:
+			/* Ignore core options */
+			if (opt < OPT_ARCH_MAX)
+				break;
+		case '?':
+			usage();
+			return -1;
+			break;
+		case OPT_APPEND:
+			append = optarg;
+			break;
+		case OPT_REUSE_CMDLINE:
+			command_line = get_command_line();
+			break;
+		case OPT_RAMDISK:
+			ramdisk = optarg;
+			break;
+		case OPT_REAL_MODE:
+			entry_16bit = 1;
+			break;
+		case OPT_ENTRY_32BIT:
+			entry_32bit = 1;
+			break;
+		}
+	}
+	command_line = concat_cmdline(command_line, append);
+	command_line_len = 0;
+	if (command_line)
+		command_line_len = strlen(command_line) + 1;
+	ramdisk_buf = 0;
+	if (ramdisk)
+		ramdisk_buf = slurp_file(ramdisk, &ramdisk_length);
+
+	if (entry_16bit || entry_32bit)
+		result = do_bzImage_load(info, buf, len, command_line,
+					command_line_len, ramdisk_buf,
+					ramdisk_length, entry_16bit);
+	else
+		result = do_bzImage64_load(info, buf, len, command_line,
+					command_line_len, ramdisk_buf,
+					ramdisk_length);
+
+	free(command_line);
+	return result;
+}
diff --git a/kexec/arch/x86_64/kexec-x86_64.c b/kexec/arch/x86_64/kexec-x86_64.c
index 6c42c32..5c23e01 100644
--- a/kexec/arch/x86_64/kexec-x86_64.c
+++ b/kexec/arch/x86_64/kexec-x86_64.c
@@ -37,6 +37,7 @@ struct file_type file_type[] = {
 	{ "multiboot-x86", multiboot_x86_probe, multiboot_x86_load,
 	  multiboot_x86_usage },
 	{ "elf-x86", elf_x86_probe, elf_x86_load, elf_x86_usage },
+	{ "bzImage64", bzImage64_probe, bzImage64_load, bzImage64_usage },
 	{ "bzImage", bzImage_probe, bzImage_load, bzImage_usage },
 	{ "beoboot-x86", beoboot_probe, beoboot_load, beoboot_usage },
 	{ "nbi-x86", nbi_probe, nbi_load, nbi_usage },
diff --git a/kexec/arch/x86_64/kexec-x86_64.h b/kexec/arch/x86_64/kexec-x86_64.h
index a97cd71..4cdeffb 100644
--- a/kexec/arch/x86_64/kexec-x86_64.h
+++ b/kexec/arch/x86_64/kexec-x86_64.h
@@ -28,4 +28,9 @@ int elf_x86_64_load(int argc, char **argv, const char *buf, off_t len,
 	struct kexec_info *info);
 void elf_x86_64_usage(void);
 
+int bzImage64_probe(const char *buf, off_t len);
+int bzImage64_load(int argc, char **argv, const char *buf, off_t len,
+			struct kexec_info *info);
+void bzImage64_usage(void);
+
 #endif /* KEXEC_X86_64_H */
-- 
1.7.10.4


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

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

* [PATCH v8 7/7] kexec, x86: handle Crash low kernel range
  2013-01-30 21:25 [PATCH v8 0/7] kexec: put bzImage and ramdisk above 4G for x86 64bit Yinghai Lu
                   ` (5 preceding siblings ...)
  2013-01-30 21:25 ` [PATCH v8 6/7] kexec, x86_64: Load bzImage64 above 4G Yinghai Lu
@ 2013-01-30 21:25 ` Yinghai Lu
  6 siblings, 0 replies; 11+ messages in thread
From: Yinghai Lu @ 2013-01-30 21:25 UTC (permalink / raw)
  To: Simon Horman, H. Peter Anvin, Vivek Goyal, Eric W. Biederman
  Cc: Yinghai Lu, kexec

kernel could have that in /proc/iomem, will use it for kdump kernel
for dma32

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 kexec/arch/i386/crashdump-x86.c |   21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/kexec/arch/i386/crashdump-x86.c b/kexec/arch/i386/crashdump-x86.c
index 245402c..83bff5e 100644
--- a/kexec/arch/i386/crashdump-x86.c
+++ b/kexec/arch/i386/crashdump-x86.c
@@ -188,6 +188,8 @@ static struct memory_range crash_memory_range[CRASH_MAX_MEMORY_RANGES];
 
 /* Memory region reserved for storing panic kernel and other data. */
 static struct memory_range crash_reserved_mem;
+/* under 4G parts */
+static struct memory_range crash_reserved_low_mem;
 
 /* Reads the appropriate file and retrieves the SYSTEM RAM regions for whom to
  * create Elf headers. Keeping it separate from get_memory_ranges() as
@@ -282,6 +284,10 @@ static int get_crash_memory_ranges(struct memory_range **range, int *ranges,
 	if (exclude_region(&memory_ranges, crash_reserved_mem.start,
 				crash_reserved_mem.end) < 0)
 		return -1;
+	if (crash_reserved_low_mem.start &&
+	    exclude_region(&memory_ranges, crash_reserved_low_mem.start,
+				crash_reserved_low_mem.end) < 0)
+		return -1;
 	if (gart) {
 		/* exclude GART region if the system has one */
 		if (exclude_region(&memory_ranges, gart_start, gart_end) < 0)
@@ -984,6 +990,12 @@ int load_crashdump_segments(struct kexec_info *info, char* mod_cmdline,
 		return ENOCRASHKERNEL;
 	}
 
+	if (crash_reserved_low_mem.start) {
+		sz = crash_reserved_low_mem.end - crash_reserved_low_mem.start
+					 +1;
+		add_memmap(memmap_p, crash_reserved_low_mem.start, sz);
+	}
+
 	/* Create a backup region segment to store backup data*/
 	if (!(info->kexec_flags & KEXEC_PRESERVE_CONTEXT)) {
 		sz = (info->backup_src_size + align) & ~(align - 1);
@@ -1059,5 +1071,14 @@ int is_crashkernel_mem_reserved(void)
 	crash_reserved_mem.end = end;
 	crash_reserved_mem.type = RANGE_RAM;
 
+	/* If there is no Crash low kernel, still can go on */
+	if (parse_iomem_single("Crash kernel low\n", &start, &end) ||
+					start == end)
+		return 1;
+
+	crash_reserved_low_mem.start = start;
+	crash_reserved_low_mem.end = end;
+	crash_reserved_low_mem.type = RANGE_RAM;
+
 	return 1;
 }
-- 
1.7.10.4


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

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

* Re: [PATCH v8 3/7] kexec, x86: clean boot_params area for entry-32bit path
  2013-01-30 21:25 ` [PATCH v8 3/7] kexec, x86: clean boot_params area for entry-32bit path Yinghai Lu
@ 2013-01-30 21:34   ` H. Peter Anvin
  2013-01-30 22:09     ` Yinghai Lu
  0 siblings, 1 reply; 11+ messages in thread
From: H. Peter Anvin @ 2013-01-30 21:34 UTC (permalink / raw)
  To: Yinghai Lu; +Cc: Simon Horman, kexec, Eric W. Biederman, Vivek Goyal

On 01/30/2013 01:25 PM, Yinghai Lu wrote:
>  
> +static void clean_boot_params(unsigned char *real_mode, unsigned long size)
> +{
> +	unsigned long end;
> +
> +	/* clear value before header */
> +	memset(real_mode, 0, 0x1f1);
> +	/* clear value after setup_header  */
> +	end = *(real_mode + 0x201);

real_mode[0x201] might be clearer...

> +	end += 0x202;
> +	if (end < size)
> +		memset(real_mode + end, 0, size - end);
> +}

You don't actually need the test... the value is inherently smaller than
0x301 which is less than the size.

That being said, if you want to sanity-check it you can check that the
value is in a sensible range -- the permitted range is 0x22 to 0x7f
inclusive, corresponding to a total end value of 0x224 to 0x281.

	-hpa


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

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

* Re: [PATCH v8 3/7] kexec, x86: clean boot_params area for entry-32bit path
  2013-01-30 21:34   ` H. Peter Anvin
@ 2013-01-30 22:09     ` Yinghai Lu
  2013-01-30 22:11       ` H. Peter Anvin
  0 siblings, 1 reply; 11+ messages in thread
From: Yinghai Lu @ 2013-01-30 22:09 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: Simon Horman, kexec, Eric W. Biederman, Vivek Goyal

On Wed, Jan 30, 2013 at 1:34 PM, H. Peter Anvin <hpa@zytor.com> wrote:
> On 01/30/2013 01:25 PM, Yinghai Lu wrote:
>>
>> +static void clean_boot_params(unsigned char *real_mode, unsigned long size)
>> +{
>> +     unsigned long end;
>> +
>> +     /* clear value before header */
>> +     memset(real_mode, 0, 0x1f1);
>> +     /* clear value after setup_header  */
>> +     end = *(real_mode + 0x201);
>
> real_mode[0x201] might be clearer...
>
>> +     end += 0x202;
>> +     if (end < size)
>> +             memset(real_mode + end, 0, size - end);
>> +}
>
> You don't actually need the test... the value is inherently smaller than
> 0x301 which is less than the size.
>
> That being said, if you want to sanity-check it you can check that the
> value is in a sensible range -- the permitted range is 0x22 to 0x7f
> inclusive, corresponding to a total end value of 0x224 to 0x281.

yes.

how about clear all and copy only setup_header?

that looks more readable.

Index: kexec-tools/kexec/arch/i386/kexec-bzImage.c
===================================================================
--- kexec-tools.orig/kexec/arch/i386/kexec-bzImage.c
+++ kexec-tools/kexec/arch/i386/kexec-bzImage.c
@@ -211,7 +211,16 @@ int do_bzImage_load(struct kexec_info *i
        /* The argument/parameter segment */
        setup_size = kern16_size + command_line_len + PURGATORY_CMDLINE_SIZE;
        real_mode = xmalloc(setup_size);
-       memcpy(real_mode, kernel, kern16_size);
+       if (!real_mode_entry) {
+               unsigned long size = kernel[0x201] + 0x202 - 0x1f1;
+
+               /* only copy setup_header */
+               memset(real_mode, 0, setup_size);
+               if (size > 0x7f)
+                       size = 0x7f;
+               memcpy(real_mode + 0x1f1, kernel + 0x1f1, size);
+       } else
+               memcpy(real_mode, kernel, kern16_size);

        if (info->kexec_flags & (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT)) {
                /* If using bzImage for capture kernel, then we will not be

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

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

* Re: [PATCH v8 3/7] kexec, x86: clean boot_params area for entry-32bit path
  2013-01-30 22:09     ` Yinghai Lu
@ 2013-01-30 22:11       ` H. Peter Anvin
  0 siblings, 0 replies; 11+ messages in thread
From: H. Peter Anvin @ 2013-01-30 22:11 UTC (permalink / raw)
  To: Yinghai Lu; +Cc: Simon Horman, kexec, Eric W. Biederman, Vivek Goyal

On 01/30/2013 02:09 PM, Yinghai Lu wrote:
> 
> yes.
> 
> how about clear all and copy only setup_header?
> 
> that looks more readable.
> 

Yes, and that is the recommended procedure anyway.

	-hpa


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

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

end of thread, other threads:[~2013-01-30 22:11 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-30 21:25 [PATCH v8 0/7] kexec: put bzImage and ramdisk above 4G for x86 64bit Yinghai Lu
2013-01-30 21:25 ` [PATCH v8 1/7] kexec, x86: set booloader id in setup_header Yinghai Lu
2013-01-30 21:25 ` [PATCH v8 2/7] kexec, x86: add boot header member for version 2.12 Yinghai Lu
2013-01-30 21:25 ` [PATCH v8 3/7] kexec, x86: clean boot_params area for entry-32bit path Yinghai Lu
2013-01-30 21:34   ` H. Peter Anvin
2013-01-30 22:09     ` Yinghai Lu
2013-01-30 22:11       ` H. Peter Anvin
2013-01-30 21:25 ` [PATCH v8 4/7] kexec, x86: Fix bzImage real-mode booting Yinghai Lu
2013-01-30 21:25 ` [PATCH v8 5/7] kexec, x86: put ramdisk/cmd_line above 4G for 64bit bzImage Yinghai Lu
2013-01-30 21:25 ` [PATCH v8 6/7] kexec, x86_64: Load bzImage64 above 4G Yinghai Lu
2013-01-30 21:25 ` [PATCH v8 7/7] kexec, x86: handle Crash low kernel range Yinghai Lu

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