Skip to contentSkip to conversation

kexec jump support for kexec-tools

PATCH In review Huang Ying 1 participant 1 message Oct 29, 2008

Subsystems (2)
lore
Share & tools
lore

Huang Ying

author
#0 lore raw

PATCH 1/2 kexec jump support for kexec-tools

To support memory backup/restore an option named --load-preserve-context is added to kexec. When it is specified toggether with --mem-max, most segments for crash dump support are loaded, and the memory range between mem_min to mem_max which has no segments loaded are loaded as backup segments. To support jump back from kexeced, options named --load-jump-back-helper and --entry are added to load a helper image with specified entry to jump back.

---
 kexec/arch/i386/crashdump-x86.c     |   51 +++++++---
 kexec/arch/i386/kexec-bzImage.c     |   10 +-
 kexec/arch/i386/kexec-elf-x86.c     |    4 
 kexec/arch/i386/kexec-x86-common.c  |    3 
 kexec/arch/i386/x86-linux-setup.h   |    3 
 kexec/crashdump-elf.c               |    2 
 kexec/crashdump.c                   |    1 
 kexec/kexec-syscall.h               |    5 -
 kexec/kexec.c                       |  177 +++++++++++++++++++++++++++++++++++-
 kexec/kexec.h                       |   12 ++
 purgatory/arch/i386/purgatory-x86.c |   14 ++
 purgatory/arch/i386/setup-x86.S     |    3 
 purgatory/include/purgatory.h       |    1 
 purgatory/printf.c                  |   38 ++++++-
 14 files changed, 291 insertions(+), 33 deletions(-)
kexec/kexec-syscall.h +3 -2
@@ -75,8 +75,9 @@ static inline long kexec_reboot(void)
 }
 
 
-#define KEXEC_ON_CRASH  0x00000001
-#define KEXEC_ARCH_MASK 0xffff0000
+#define KEXEC_ON_CRASH		0x00000001
+#define KEXEC_PRESERVE_CONTEXT	0x00000002
+#define KEXEC_ARCH_MASK		0xffff0000
 
 /* These values match the ELF architecture values. 
  * Unless there is a good reason that should continue to be the case.
kexec/kexec.c +175 -2

248 lines not on this page · raw message

kexec/kexec.h +11 -1
@@ -174,7 +174,10 @@ extern int file_types;
 #define OPT_MEM_MIN             256
 #define OPT_MEM_MAX             257
 #define OPT_REUSE_INITRD	258
-#define OPT_MAX			259
+#define OPT_LOAD_PRESERVE_CONTEXT 259
+#define OPT_LOAD_JUMP_BACK_HELPER 260
+#define OPT_ENTRY		261
+#define OPT_MAX			262
 #define KEXEC_OPTIONS \
 	{ "help",		0, 0, OPT_HELP }, \
 	{ "version",		0, 0, OPT_VERSION }, \
@@ -183,6 +186,9 @@ extern int file_types;
 	{ "load",		0, 0, OPT_LOAD }, \
 	{ "unload",		0, 0, OPT_UNLOAD }, \
 	{ "exec",		0, 0, OPT_EXEC }, \
+	{ "load-preserve-context", 0, 0, OPT_LOAD_PRESERVE_CONTEXT}, \
+	{ "load-jump-back-helper", 0, 0, OPT_LOAD_JUMP_BACK_HELPER }, \
+	{ "entry",		1, 0, OPT_ENTRY }, \
 	{ "type",		1, 0, OPT_TYPE }, \
 	{ "load-panic",         0, 0, OPT_PANIC }, \
 	{ "mem-min",		1, 0, OPT_MEM_MIN }, \
@@ -242,6 +248,10 @@ int kexec_iomem_for_each_line(char *matc
 int parse_iomem_single(char *str, uint64_t *start, uint64_t *end);
 const char * proc_iomem(void);
 
+extern int add_backup_segments(struct kexec_info *info,
+			       unsigned long backup_base,
+			       unsigned long backup_size);
+
 #define MAX_LINE	160
 
 #ifdef DEBUG
kexec/arch/i386/kexec-bzImage.c +7 -3
@@ -114,6 +114,7 @@ int do_bzImage_load(struct kexec_info *i
 	unsigned int relocatable_kernel = 0;
 	unsigned long kernel32_load_addr;
 	char *modified_cmdline;
+	unsigned long cmdline_end;
 
 	/*
 	 * Find out about the file I am about to load.
@@ -166,7 +167,7 @@ int do_bzImage_load(struct kexec_info *i
 	/* Need to append some command line parameters internally in case of
 	 * taking crash dumps.
 	 */
-	if (info->kexec_flags & KEXEC_ON_CRASH) {
+	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) {
@@ -205,11 +206,11 @@ int do_bzImage_load(struct kexec_info *i
 					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;
+	setup_size = kern16_size + command_line_len + PURGATORY_CMDLINE_SIZE;
 	real_mode = xmalloc(setup_size);
 	memcpy(real_mode, kernel, kern16_size);
 
-	if (info->kexec_flags & KEXEC_ON_CRASH) {
+	if (info->kexec_flags & (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT)) {
 		/* If using bzImage for capture kernel, then we will not be
 		 * executing real mode code. setup segment can be loaded
 		 * anywhere as we will be just reading command line.
@@ -316,6 +317,9 @@ int do_bzImage_load(struct kexec_info *i
 	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;
+	elf_rel_set_symbol(&info->rhdr, "cmdline_end", &cmdline_end,
+			   sizeof(unsigned long));
 
 	/* Fill in the information BIOS calls would normally provide. */
 	if (!real_mode_entry) {
kexec/arch/i386/x86-linux-setup.h +3 -0
@@ -15,4 +15,7 @@ void setup_linux_system_parameters(struc
 #define KERN32_BASE  0x100000 /* 1MB */
 #define INITRD_BASE 0x1000000 /* 16MB */
 
+/* command line parameter may be appended by purgatory */
+#define PURGATORY_CMDLINE_SIZE 64
+
 #endif /* X86_LINUX_SETUP_H */
purgatory/arch/i386/purgatory-x86.c +13 -1
@@ -31,6 +31,8 @@ uint8_t reset_vga = 0;
 uint8_t legacy_timer = 0;
 uint8_t legacy_pic   = 0;
 uint8_t panic_kernel = 0;
+unsigned long jump_back_entry = 0;
+char *cmdline_end = 0;
 
 void setup_arch(void)
 {
@@ -40,8 +42,18 @@ void setup_arch(void)
 	/* if (legacy_timer) x86_setup_legacy_timer(); */
 }
 
+extern void x86_setup_jump_back_entry();
+
 /* This function can be used to execute after the SHA256 verification. */
 void post_verification_setup_arch(void)
 {
-	if (panic_kernel)   crashdump_backup_memory();
+	if (panic_kernel)    crashdump_backup_memory();
+	if (jump_back_entry) x86_setup_jump_back_entry();
+}
+
+void x86_setup_jump_back_entry()
+{
+	if (cmdline_end)
+		sprintf(cmdline_end, " kexec_jump_back_entry=0x%x",
+			jump_back_entry);
 }
purgatory/arch/i386/setup-x86.S +3 -0
@@ -41,6 +41,9 @@ purgatory_start:
 	ljmp	$0x10,$1f
 1:		
 
+	movl	0(%esp), %eax
+	movl	%eax, jump_back_entry
+
 	/* Setup a stack */
 	movl	$lstack_end, %esp
 
purgatory/printf.c +32 -6
@@ -33,19 +33,23 @@ PRINTF and friends
 		%s	- string
 	Note: width specification not supported
 **************************************************************************/
-void printf(const char *fmt, ...)
+void vsprintf(char *buffer, const char *fmt, va_list args)
 {
-	va_list args;
 	char *p;
-	va_start(args, fmt);
 	for ( ; *fmt != '\0'; ++fmt) {
 		if (*fmt != '%') {
-			putchar(*fmt);
+			if (buffer)
+				*buffer++ = *fmt;
+			else
+				putchar(*fmt);
 			continue;
 		}
 		if (*++fmt == 's') {
 			for(p = va_arg(args, char *); *p != '\0'; p++) 
-				putchar(*p);
+				if (buffer)
+					*buffer++ = *p;
+				else
+					putchar(*p);
 		}
 		else {	/* Length of item is bounded */
 			char tmp[40], *q = tmp;
@@ -121,8 +125,30 @@ void printf(const char *fmt, ...)
 				*q++ = *fmt;
 			/* now output the saved string */
 			for (p = tmp; p < q; ++p)
-				putchar(*p);
+				if (buffer)
+					*buffer++ = *p;
+				else
+					putchar(*p);
 		}
 	}
+	if (buffer)
+		*buffer = '\0';
+}
+
+void sprintf(char *buffer, const char *fmt, ...)
+{
+	va_list args;
+
+	va_start(args, fmt);
+	vsprintf(buffer, fmt, args);
+	va_end(args);
+}
+
+void printf(const char *fmt, ...)
+{
+	va_list args;
+
+	va_start(args, fmt);
+	vsprintf(0, fmt, args);
 	va_end(args);
 }
purgatory/include/purgatory.h +1 -0
@@ -2,6 +2,7 @@
 #define PURGATORY_H
 
 void putchar(int ch);
+void sprintf(char *buffer, const char *fmt, ...);
 void printf(const char *fmt, ...);
 void setup_arch(void);
 void post_verification_setup_arch(void);
kexec/arch/i386/crashdump-x86.c +37 -14

81 lines not on this page · raw message

kexec/crashdump-elf.c +1 -1
@@ -164,7 +164,7 @@ int FUNC(struct kexec_info *info,
 		dbgprintf_phdr("Elf header", phdr);
 	}
 
-	if (has_vmcoreinfo) {
+	if (has_vmcoreinfo && !(info->kexec_flags & KEXEC_PRESERVE_CONTEXT)) {
 		phdr = (PHDR *) bufp;
 		bufp += sizeof(PHDR);
 		phdr->p_type	= PT_NOTE;
kexec/arch/i386/kexec-elf-x86.c +2 -2
@@ -170,7 +170,7 @@ int elf_x86_load(int argc, char **argv, 
 	/* Need to append some command line parameters internally in case of
 	 * taking crash dumps.
 	 */
-	if (info->kexec_flags & KEXEC_ON_CRASH) {
+	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) {
@@ -257,7 +257,7 @@ int elf_x86_load(int argc, char **argv, 
 
 		/* If panic kernel is being loaded, additional segments need
 		 * to be created. */
-		if (info->kexec_flags & KEXEC_ON_CRASH) {
+		if (info->kexec_flags & (KEXEC_ON_CRASH|KEXEC_PRESERVE_CONTEXT)) {
 			rc = load_crashdump_segments(info, modified_cmdline,
 						max_addr, 0);
 			if (rc < 0)
kexec/arch/i386/kexec-x86-common.c +2 -1
@@ -174,7 +174,8 @@ int get_memory_ranges(struct memory_rang
 	 * Override user values only if kernel exported values are
 	 * subset of user defined values.
 	 */
-	if (kexec_flags & KEXEC_ON_CRASH) {
+	if ((kexec_flags & KEXEC_ON_CRASH) &&
+	    !(kexec_flags & KEXEC_PRESERVE_CONTEXT)) {
 		unsigned long long start, end;
 
 		ret = parse_iomem_single("Crash kernel\n", &start, &end);
kexec/crashdump.c +1 -0
@@ -29,6 +29,7 @@
 #include <elf.h>
 #include "kexec.h"
 #include "crashdump.h"
+#include "kexec-syscall.h"
 
 /* include "crashdump-elf.c" twice to create two functions from one */
 

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec