Skip to contentSkip to conversation

kexec updates

PATCH Superseded Milton Miller 4 participants 21 messages Jan 2, 2009 – Jan 15, 2009

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover kexec updates

Follwing this mail are 5 patches for kexec userspace and two for the kernel. The first fixes an array overflow and the second updates userspace to the merged 2.6.28 kdump support. The remaining are cleanups and warning fixes, including one for the common code.

The two patchs for the kernel are independent.

milton

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

#1 lore raw

Subject [PATCH kexec-tools 1/5] ppc64: always check number of ranges when adding
Date: Fri, 02 Jan 2009 14:43:49 -0600
Subject: (No subject header)
X-Originating-IP: 205.232.218.102

make the idom "always call realloc_memory_ranges when filling a range entry"

kexec was core dumping after using 5 exclude_range pairs when only 3 were allocated.

also delcare realloc_memory_ranges to take no arguments.

kexec/arch/ppc64/kexec-ppc64.c +11 -1
Index: kexec-tools/kexec/arch/ppc64/kexec-ppc64.c
===================================================================
@@ -96,7 +96,7 @@ err1:
 
 }
 
-static int realloc_memory_ranges()
+static int realloc_memory_ranges(void)
 {
 	size_t memory_range_len;
 
@@ -469,6 +469,8 @@ static int get_devtree_details(unsigned 
 				exclude_range[i].start = initrd_start;
 				exclude_range[i].end = initrd_end;
 				i++;
+				if (i >= max_memory_ranges)
+					realloc_memory_ranges();
 			}
 		} /* chosen */
 
@@ -581,6 +583,8 @@ static int get_devtree_details(unsigned 
 			exclude_range[i].start = tce_base;
 			exclude_range[i].end = tce_base + tce_size;
 			i++;
+			if (i >= max_memory_ranges)
+				realloc_memory_ranges();
 			if (kexec_flags & KEXEC_ON_CRASH)
 				add_usable_mem_rgns(tce_base, tce_size);
 			closedir(cdir);
@@ -634,6 +638,8 @@ int setup_memory_ranges(unsigned long ke
 				memory_range[j].end = exclude_range[i].start - 1;
 				memory_range[j].type = RANGE_RAM;
 				j++;
+				if (j >= max_memory_ranges)
+					realloc_memory_ranges();
 			}
 		} /* i == 0 */
 		/* If the last exclude range does not end at memory_max, include
@@ -646,6 +652,8 @@ int setup_memory_ranges(unsigned long ke
 				memory_range[j].end = memory_max;
 				memory_range[j].type = RANGE_RAM;
 				j++;
+				if (j >= max_memory_ranges)
+					realloc_memory_ranges();
 				/* Limit the end to rmo_top */
 				if (memory_range[j-1].start >= rmo_top) {
 					j--;
@@ -666,6 +674,8 @@ int setup_memory_ranges(unsigned long ke
 		memory_range[j].end = exclude_range[i+1].start - 1;
 		memory_range[j].type = RANGE_RAM;
 		j++;
+		if (i >= max_memory_ranges)
+			realloc_memory_ranges();
 		/* Limit range to rmo_top */
 		if (memory_range[j-1].start >= rmo_top) {
 			j--;
#2 lore raw

In reply to Milton Miller

Subject [PATCH kexec-tools 2/5] ppc64: update kdump for 2.6.28 relocatable kernel
Date: Fri, 02 Jan 2009 14:44:01 -0600
Subject: (No subject header)
X-Originating-IP: 205.232.218.102

The kernel updated its ABI to tell the relocatable kernel to run where it was loaded.

We now need to set a flag in the kernel image. Since we only have the kernel image avialable as const data to kexec-tools c code, set the flag in the copy we put in purgatory, and have it set the flag in the kernel (after purgatory has run its checksum). To simplfy the purgatory code we can always copy the flag word back to the kernel as the c code made a copy of the original flag value.

---
v3:
purgatory now copies the flag to the kernel master entrypoint instead of the kernel reading the value copied to 0 with the slave spinloop.

rename the local varable to my_run_at_load to be more consistent, and change its type to uint32_t from unsigned int

purgatory/arch/ppc64/v2wrap.S +9 -12
Index: kexec-tools/purgatory/arch/ppc64/v2wrap.S
===================================================================
@@ -45,11 +45,14 @@
 	oris    rn,rn,name##@h;         \
 	ori     rn,rn,name##@l
 
-#define KDUMP_SIGNATURE 0xfeed1234
-
 	.machine ppc64
 	.globl purgatory_start
 purgatory_start:	b	master
+	.org purgatory_start + 0x5c     # ABI: possible run_at_load flag at 0x5c
+	.globl run_at_load
+run_at_load:
+	.long 0
+	.size run_at_load, . - run_at_load
 	.org purgatory_start + 0x60     # ABI: slaves start at 60 with r3=phys
 slave:	b $
 	.org purgatory_start + 0x100    # ABI: end of copied region
@@ -57,7 +60,7 @@ slave:	b $
 
 #
 # The above 0x100 bytes at purgatory_start are replaced with the
-# code from the kernel (or next stage) by kexec/arch/ppc64/kexec-ppc64.c
+# code from the kernel (or next stage) by kexec/arch/ppc64/kexec-elf-ppc64.c
 #
 
 master:
@@ -65,7 +68,6 @@ master:
 	isync
 	mr      17,3            # save cpu id to r17
 	mr      15,4            # save physical address in reg15
-	mr      18,6            # save kdump flag in reg18
 
 	LOADADDR(6,my_toc)
 	ld      2,0(6)          #setup toc
@@ -92,18 +94,13 @@ master:
 80:
 	LOADADDR(6,kernel)
 	ld      4,0(6)          # load the kernel address
+	LOADADDR(6,run_at_load) # the load flag
+	lwz	7,0(6)		# possibly patched by kexec-elf-ppc64
+	stw	7,0x5c(4)	# and patch it into the kernel
 	li	5,0		# r5 will be 0 for kernel
 	mtctr	4		# prepare branch too
 	mr      3,16            # restore dt address
 
-	LOADADDR(6,KDUMP_SIGNATURE)
-	cmpd	18,6
-	bne	regular
-	li	7,1
-	std	7,24(4)		# mark kdump flag at kernel
-regular:
-	lwz	7,0(4)		# get the first instruction that we stole
-	stw	7,0(0)		# and put it in the slave loop at 0
 				# skip cache flush, do we care?
 
 	bctr			# start kernel
kexec/arch/ppc64/crashdump-ppc64.h +2 -0
Index: kexec-tools/kexec/arch/ppc64/crashdump-ppc64.h
===================================================================
@@ -23,6 +23,8 @@ void add_usable_mem_rgns(unsigned long l
 #define _ALIGN_UP(addr,size)	(((addr)+((size)-1))&(~((size)-1)))
 #define _ALIGN_DOWN(addr,size)	((addr)&(~((size)-1)))
 
+#define KERNEL_RUN_AT_ZERO_MAGIC 0x72756e30	/* "run0" */
+
 extern uint64_t crash_base;
 extern uint64_t crash_size;
 extern unsigned int rtas_base;
kexec/arch/ppc64/kexec-elf-ppc64.c +17 -0
Index: kexec-tools/kexec/arch/ppc64/kexec-elf-ppc64.c
===================================================================
@@ -92,6 +92,7 @@ int elf_ppc64_load(int argc, char **argv
 	unsigned int my_panic_kernel;
 	uint64_t my_stack, my_backup_start;
 	uint64_t toc_addr;
+	uint32_t my_run_at_load;
 	unsigned int slave_code[256/sizeof (unsigned int)], master_entry;
 
 #define OPT_APPEND     (OPT_ARCH_MAX+0)
@@ -307,6 +308,18 @@ int elf_ppc64_load(int argc, char **argv
 		my_backup_start = info->backup_start;
 		elf_rel_set_symbol(&info->rhdr, "backup_start",
 				&my_backup_start, sizeof(my_backup_start));
+
+		/* Tell relocatable kernel to run at load address
+		 * via word before slave code in purgatory
+		 */
+
+		elf_rel_get_symbol(&info->rhdr, "run_at_load", &my_run_at_load,
+				sizeof(my_run_at_load));
+		if (my_run_at_load == KERNEL_RUN_AT_ZERO_MAGIC)
+			my_run_at_load = 1;
+			/* else it should be a fixed offset image */
+		elf_rel_set_symbol(&info->rhdr, "run_at_load", &my_run_at_load,
+				sizeof(my_run_at_load));
 	}
 
 	/* Set stack address */
@@ -325,10 +338,13 @@ int elf_ppc64_load(int argc, char **argv
 	my_backup_start = 0;
 	my_stack = 0;
 	toc_addr = 0;
+	my_run_at_load = 0;
 
 	elf_rel_get_symbol(&info->rhdr, "kernel", &my_kernel, sizeof(my_kernel));
 	elf_rel_get_symbol(&info->rhdr, "dt_offset", &my_dt_offset,
 				sizeof(my_dt_offset));
+	elf_rel_get_symbol(&info->rhdr, "run_at_load", &my_run_at_load,
+				sizeof(my_run_at_load));
 	elf_rel_get_symbol(&info->rhdr, "panic_kernel", &my_panic_kernel,
 				sizeof(my_panic_kernel));
 	elf_rel_get_symbol(&info->rhdr, "backup_start", &my_backup_start,
@@ -341,6 +357,7 @@ int elf_ppc64_load(int argc, char **argv
 	fprintf(stderr, "kernel is %llx\n", (unsigned long long)my_kernel);
 	fprintf(stderr, "dt_offset is %llx\n",
 		(unsigned long long)my_dt_offset);
+	fprintf(stderr, "run_at_load flag is %x\n", my_run_at_load);
 	fprintf(stderr, "panic_kernel is %x\n", my_panic_kernel);
 	fprintf(stderr, "backup_start is %llx\n",
 		(unsigned long long)my_backup_start);
#3 lore raw

In reply to Milton Miller

Subject [PATCH kexec-tools 4/5] ppc64: cleanups
Date: Fri, 02 Jan 2009 14:44:26 -0600
Subject: (No subject header)
X-Originating-IP: 205.232.218.102

don't copy purgatory, as elf-load-rel does that for us (like x86_64).

move function declarations from c to h files

remove casts between void * and various pointers

change some pointers between char and unsigned char *

change args to be vars of the right type instead of casting or copying between types

---
we still need to cast purgatory or we get a signed-ness warning on the pointer

kexec/arch/ppc64/fs2dt.c +3 -7
Index: kexec-tools/kexec/arch/ppc64/fs2dt.c
===================================================================
@@ -46,8 +46,6 @@ static unsigned long long mem_rsrv[2*MEM
 
 static int crash_param = 0;
 static char local_cmdline[COMMAND_LINE_SIZE] = { "" };
-static unsigned *dt_len; /* changed len of modified cmdline
-			    in flat device-tree */
 extern mem_rgns_t usablemem_rgns;
 static struct bootblock bb[1];
 
@@ -314,7 +312,6 @@ static void putprops(char *fn, struct di
 		len = statbuf.st_size;
 
 		*dt++ = 3;
-		dt_len = dt;
 		*dt++ = len;
 		*dt++ = propnum(fn);
 
@@ -509,12 +506,11 @@ static void putnode(void)
 	free(namelist);
 }
 
-int create_flatten_tree(struct kexec_info *info, unsigned char **bufp,
-			unsigned long *sizep, char *cmdline)
+int create_flatten_tree(char **bufp, off_t *sizep, char *cmdline)
 {
 	unsigned long len;
 	unsigned long tlen;
-	unsigned char *buf;
+	char *buf;
 	unsigned long me;
 
 	me = 0;
@@ -556,7 +552,7 @@ int create_flatten_tree(struct kexec_inf
 
 	reserve(me, bb->totalsize); /* patched later in kexec_load */
 
-	buf = (unsigned char *) malloc(bb->totalsize);
+	buf = malloc(bb->totalsize);
 	*bufp = buf;
 	memcpy(buf, bb, bb->off_mem_rsvmap);
 	tlen = bb->off_mem_rsvmap;
kexec/arch/ppc64/kexec-elf-ppc64.c +8 -34

98 lines not on this page · raw message

kexec/arch/ppc64/kexec-elf-rel-ppc64.c +1 -0
Index: kexec-tools/kexec/arch/ppc64/kexec-elf-rel-ppc64.c
===================================================================
@@ -3,6 +3,7 @@
 #include <string.h>
 #include "../../kexec.h"
 #include "../../kexec-elf.h"
+#include "kexec-ppc64.h"
 
 int machine_verify_elf_rel(struct mem_ehdr *ehdr)
 {
kexec/arch/ppc64/kexec-ppc64.h +3 -0
Index: kexec-tools/kexec/arch/ppc64/kexec-ppc64.h
===================================================================
@@ -14,6 +14,9 @@ int elf_ppc64_load(int argc, char **argv
 void elf_ppc64_usage(void);
 void reserve(unsigned long long where, unsigned long long length);
 
+int create_flatten_tree(char **, off_t *, char *);
+unsigned long my_r2(const struct mem_ehdr *ehdr);
+
 extern uint64_t initrd_base, initrd_size;
 extern int max_memory_ranges;
 extern unsigned char reuse_initrd;
#4 lore raw

In reply to Milton Miller

Subject [PATCH kexec-tools 5/5] entry wants to be void *
Date: Fri, 02 Jan 2009 14:44:40 -0600
Subject: (No subject header)
X-Originating-IP: 205.232.218.102

The kexec info struct defines entry to be a void *, so pass around the user supplied value as one.

This fixes the following warning:

gcc -g -O2 -fno-strict-aliasing -Wall -Wstrict-prototypes -I./include -I./util_lib/include -Iinclude/ -I./kexec/arch/ppc64/include -c -MD -o kexec/kexec.o kexec/kexec.c kexec/kexec.c: In function ‘my_load’:
kexec/kexec.c:773: warning: assignment makes pointer from integer without a cast

---

kexec/kexec.c +6 -9
Index: kexec-tools/kexec/kexec.c
===================================================================
@@ -666,7 +666,7 @@ static void update_purgatory(struct kexe
  *	Load the new kernel
  */
 static int my_load(const char *type, int fileind, int argc, char **argv,
-		   unsigned long kexec_flags, unsigned long entry)
+		   unsigned long kexec_flags, void *entry)
 {
 	char *kernel;
 	char *kernel_buf;
@@ -846,23 +846,20 @@ static int my_exec(void)
 
 static int kexec_loaded(void);
 
-static int load_jump_back_helper_image(unsigned long kexec_flags,
-				       unsigned long entry)
+static int load_jump_back_helper_image(unsigned long kexec_flags, void *entry)
 {
 	int result;
 	struct kexec_segment seg;
 
 	memset(&seg, 0, sizeof(seg));
-	result = kexec_load((void *)entry, 1, &seg,
-			    kexec_flags);
+	result = kexec_load(entry, 1, &seg, kexec_flags);
 	return result;
 }
 
 /*
  *	Jump back to the original kernel
  */
-static int my_load_jump_back_helper(unsigned long kexec_flags,
-				    unsigned long entry)
+static int my_load_jump_back_helper(unsigned long kexec_flags, void *entry)
 {
 	int result;
 
@@ -1036,7 +1033,7 @@ int main(int argc, char *argv[])
 	int do_ifdown = 0;
 	int do_unload = 0;
 	int do_reuse_initrd = 0;
-	unsigned long entry = 0;
+	void *entry = 0;
 	char *type = 0;
 	char *endptr;
 	int opt;
@@ -1096,7 +1093,7 @@ int main(int argc, char *argv[])
 			kexec_flags = KEXEC_PRESERVE_CONTEXT;
 			break;
 		case OPT_ENTRY:
-			entry = strtoul(optarg, &endptr, 0);
+			entry = (void *)strtoul(optarg, &endptr, 0);
 			if (*endptr) {
 				fprintf(stderr,
 					"Bad option value in --load-jump-back-helper=%s\n",
#5 lore raw

PATCH 1/1 powerpc: make dummy section a valid note header

In reply to Milton Miller

We are declaring the dummy section (used to work around a binutils bug) as PT_NOTE, but we don't have enough bytes for it to be a valid note header, and kexec userspace complains:

Warning: Elf Note name is not null terminated
Warning: append= option is not passed. Using the first kernel root partition
Warning: Elf Note name is not null terminated

Instead of using the arbitray value 0xf177 (aka "fill"), declare a no-name no-description note of type 0.

---
verified on binutils-2.6.17 that the workaround still works (that is we get a phdr that does not have all zeros in the paddr field, and a relocatable kernel booted).

arch/powerpc/kernel/vmlinux.lds.S +3 -1
Index: common/arch/powerpc/kernel/vmlinux.lds.S
===================================================================
@@ -87,7 +87,9 @@ SECTIONS
 	/* The dummy segment contents for the bug workaround mentioned above
 	   near PHDRS.  */
 	.dummy : AT(ADDR(.dummy) - LOAD_OFFSET) {
-		LONG(0xf177)
+		LONG(0)
+		LONG(0)
+		LONG(0)
 	} :kernel :dummy
 
 /*
#6 lore raw

PATCH 1/1 powerpc: check crash_base for relocatable kernel

In reply to Milton Miller

Enforce that the crash kernel region never overlaps the current kernel, as it will be written directly on kexec load.

Also, default to the previous KDUMP_KERNELBASE if the start is 0.

Other architectures (x86, ia64) state that specifying the start address 0 (or omitting it) will result in the kernel allocating it. Before the relocatable patch in 2.6.28, powerpc would adjust any other start value to the hardcoded KDUMP_KERNELBASE of 32M.

---
consider for stable 2.6.28:

A crash region start of 0 results either in a kernel panic (if all of segemnt 0 is reserved) or confused kexec userspace (as the start and length are not exported to userspace):

Starting new kernel
Reserving 512MB of memory at 0MB for crashkernel (System RAM: 2048MB) Using pSeries machine description

...

[boot]0012 Setup Arch

Kernel panic - not syncing: ERROR: Failed to allocate 0x4000 bytes below 0x10000000.

or

# kexec -p /root/vmlinux
Memory for crashkernel is not reserved
Please reserve memory by passing "crashkernel=X@Y" parameter to the kernel
Then try loading kdump kernel
# cat /proc/cmdline
retain_initrd crashkernel=64M
#
arch/powerpc/kernel/machine_kexec.c +26 -0
Index: common/arch/powerpc/kernel/machine_kexec.c
===================================================================
@@ -13,6 +13,7 @@
 #include <linux/reboot.h>
 #include <linux/threads.h>
 #include <linux/lmb.h>
+#include <asm/sections.h>
 #include <asm/machdep.h>
 #include <asm/prom.h>
 
@@ -94,10 +95,35 @@ void __init reserve_crashkernel(void)
 				KDUMP_KERNELBASE);
 
 	crashk_res.start = KDUMP_KERNELBASE;
+#else
+	if (!crashk_res.start) {
+		/*
+		 * unspecified address, choose a region of specified size
+		 * can overlap with initrd (ignoring corruption when retained)
+		 * ppc64 requires kernel and some stacks to be in first segemnt
+		 */
+		crashk_res.start = KDUMP_KERNELBASE;
+	}
+
+	crash_base = PAGE_ALIGN(crashk_res.start);
+	if (crash_base != crashk_res.start) {
+		printk("Crash kernel base must be aligned to 0x%lx\n",
+				PAGE_SIZE);
+		crashk_res.start = crash_base;
+	}
+
 #endif
 	crash_size = PAGE_ALIGN(crash_size);
 	crashk_res.end = crashk_res.start + crash_size - 1;
 
+	/* The crash region must not overlap the current kernel */
+	if (overlaps_crashkernel(__pa(_stext), _end - _stext)) {
+		printk(KERN_WARNING
+			"Crash kernel can not overlap current kernel\n");
+		crashk_res.start = crashk_res.end = 0;
+		return;
+	}
+
 	/* Crash kernel trumps memory limit */
 	if (memory_limit && memory_limit <= crashk_res.end) {
 		memory_limit = crashk_res.end + 1;
#10 lore raw

PATCH 1/5 ppc64: always check number of ranges when adding

In reply to Milton Miller

make the idom "always call realloc_memory_ranges when filling a range entry"

kexec was core dumping after using 5 exclude_range pairs when only 3 were allocated.

also delcare realloc_memory_ranges to take no arguments.

kexec/arch/ppc64/kexec-ppc64.c +11 -1
Index: kexec-tools/kexec/arch/ppc64/kexec-ppc64.c
===================================================================
@@ -96,7 +96,7 @@ err1:
 
 }
 
-static int realloc_memory_ranges()
+static int realloc_memory_ranges(void)
 {
 	size_t memory_range_len;
 
@@ -469,6 +469,8 @@ static int get_devtree_details(unsigned 
 				exclude_range[i].start = initrd_start;
 				exclude_range[i].end = initrd_end;
 				i++;
+				if (i >= max_memory_ranges)
+					realloc_memory_ranges();
 			}
 		} /* chosen */
 
@@ -581,6 +583,8 @@ static int get_devtree_details(unsigned 
 			exclude_range[i].start = tce_base;
 			exclude_range[i].end = tce_base + tce_size;
 			i++;
+			if (i >= max_memory_ranges)
+				realloc_memory_ranges();
 			if (kexec_flags & KEXEC_ON_CRASH)
 				add_usable_mem_rgns(tce_base, tce_size);
 			closedir(cdir);
@@ -634,6 +638,8 @@ int setup_memory_ranges(unsigned long ke
 				memory_range[j].end = exclude_range[i].start - 1;
 				memory_range[j].type = RANGE_RAM;
 				j++;
+				if (j >= max_memory_ranges)
+					realloc_memory_ranges();
 			}
 		} /* i == 0 */
 		/* If the last exclude range does not end at memory_max, include
@@ -646,6 +652,8 @@ int setup_memory_ranges(unsigned long ke
 				memory_range[j].end = memory_max;
 				memory_range[j].type = RANGE_RAM;
 				j++;
+				if (j >= max_memory_ranges)
+					realloc_memory_ranges();
 				/* Limit the end to rmo_top */
 				if (memory_range[j-1].start >= rmo_top) {
 					j--;
@@ -666,6 +674,8 @@ int setup_memory_ranges(unsigned long ke
 		memory_range[j].end = exclude_range[i+1].start - 1;
 		memory_range[j].type = RANGE_RAM;
 		j++;
+		if (i >= max_memory_ranges)
+			realloc_memory_ranges();
 		/* Limit range to rmo_top */
 		if (memory_range[j-1].start >= rmo_top) {
 			j--;

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

#15 lore raw

PATCH 4/5 ppc64: cleanups

In reply to Milton Miller

don't copy purgatory, as elf-load-rel does that for us (like x86_64).

move function declarations from c to h files

remove casts between void * and various pointers

change some pointers between char and unsigned char *

change args to be vars of the right type instead of casting or copying between types

---
we still need to cast purgatory or we get a signed-ness warning on the pointer

kexec/arch/ppc64/fs2dt.c +3 -7
Index: kexec-tools/kexec/arch/ppc64/fs2dt.c
===================================================================
@@ -46,8 +46,6 @@ static unsigned long long mem_rsrv[2*MEM
 
 static int crash_param = 0;
 static char local_cmdline[COMMAND_LINE_SIZE] = { "" };
-static unsigned *dt_len; /* changed len of modified cmdline
-			    in flat device-tree */
 extern mem_rgns_t usablemem_rgns;
 static struct bootblock bb[1];
 
@@ -314,7 +312,6 @@ static void putprops(char *fn, struct di
 		len = statbuf.st_size;
 
 		*dt++ = 3;
-		dt_len = dt;
 		*dt++ = len;
 		*dt++ = propnum(fn);
 
@@ -509,12 +506,11 @@ static void putnode(void)
 	free(namelist);
 }
 
-int create_flatten_tree(struct kexec_info *info, unsigned char **bufp,
-			unsigned long *sizep, char *cmdline)
+int create_flatten_tree(char **bufp, off_t *sizep, char *cmdline)
 {
 	unsigned long len;
 	unsigned long tlen;
-	unsigned char *buf;
+	char *buf;
 	unsigned long me;
 
 	me = 0;
@@ -556,7 +552,7 @@ int create_flatten_tree(struct kexec_inf
 
 	reserve(me, bb->totalsize); /* patched later in kexec_load */
 
-	buf = (unsigned char *) malloc(bb->totalsize);
+	buf = malloc(bb->totalsize);
 	*bufp = buf;
 	memcpy(buf, bb, bb->off_mem_rsvmap);
 	tlen = bb->off_mem_rsvmap;
kexec/arch/ppc64/kexec-elf-ppc64.c +8 -34

98 lines not on this page · raw message

kexec/arch/ppc64/kexec-elf-rel-ppc64.c +1 -0
Index: kexec-tools/kexec/arch/ppc64/kexec-elf-rel-ppc64.c
===================================================================
@@ -3,6 +3,7 @@
 #include <string.h>
 #include "../../kexec.h"
 #include "../../kexec-elf.h"
+#include "kexec-ppc64.h"
 
 int machine_verify_elf_rel(struct mem_ehdr *ehdr)
 {
kexec/arch/ppc64/kexec-ppc64.h +3 -0
Index: kexec-tools/kexec/arch/ppc64/kexec-ppc64.h
===================================================================
@@ -14,6 +14,9 @@ int elf_ppc64_load(int argc, char **argv
 void elf_ppc64_usage(void);
 void reserve(unsigned long long where, unsigned long long length);
 
+int create_flatten_tree(char **, off_t *, char *);
+unsigned long my_r2(const struct mem_ehdr *ehdr);
+
 extern uint64_t initrd_base, initrd_size;
 extern int max_memory_ranges;
 extern unsigned char reuse_initrd;

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

#16 lore raw

PATCH 5/5 entry wants to be void *

In reply to Milton Miller

The kexec info struct defines entry to be a void *, so pass around the user supplied value as one.

This fixes the following warning:

gcc -g -O2 -fno-strict-aliasing -Wall -Wstrict-prototypes -I./include -I./util_lib/include -Iinclude/ -I./kexec/arch/ppc64/include -c -MD -o kexec/kexec.o kexec/kexec.c kexec/kexec.c: In function ‘my_load’:
kexec/kexec.c:773: warning: assignment makes pointer from integer without a cast

---

kexec/kexec.c +6 -9
Index: kexec-tools/kexec/kexec.c
===================================================================
@@ -666,7 +666,7 @@ static void update_purgatory(struct kexe
  *	Load the new kernel
  */
 static int my_load(const char *type, int fileind, int argc, char **argv,
-		   unsigned long kexec_flags, unsigned long entry)
+		   unsigned long kexec_flags, void *entry)
 {
 	char *kernel;
 	char *kernel_buf;
@@ -846,23 +846,20 @@ static int my_exec(void)
 
 static int kexec_loaded(void);
 
-static int load_jump_back_helper_image(unsigned long kexec_flags,
-				       unsigned long entry)
+static int load_jump_back_helper_image(unsigned long kexec_flags, void *entry)
 {
 	int result;
 	struct kexec_segment seg;
 
 	memset(&seg, 0, sizeof(seg));
-	result = kexec_load((void *)entry, 1, &seg,
-			    kexec_flags);
+	result = kexec_load(entry, 1, &seg, kexec_flags);
 	return result;
 }
 
 /*
  *	Jump back to the original kernel
  */
-static int my_load_jump_back_helper(unsigned long kexec_flags,
-				    unsigned long entry)
+static int my_load_jump_back_helper(unsigned long kexec_flags, void *entry)
 {
 	int result;
 
@@ -1036,7 +1033,7 @@ int main(int argc, char *argv[])
 	int do_ifdown = 0;
 	int do_unload = 0;
 	int do_reuse_initrd = 0;
-	unsigned long entry = 0;
+	void *entry = 0;
 	char *type = 0;
 	char *endptr;
 	int opt;
@@ -1096,7 +1093,7 @@ int main(int argc, char *argv[])
 			kexec_flags = KEXEC_PRESERVE_CONTEXT;
 			break;
 		case OPT_ENTRY:
-			entry = strtoul(optarg, &endptr, 0);
+			entry = (void *)strtoul(optarg, &endptr, 0);
 			if (*endptr) {
 				fprintf(stderr,
 					"Bad option value in --load-jump-back-helper=%s\n",
#14 lore raw

PATCH 2/5 ppc64: update kdump for 2.6.28 relocatable kernel

In reply to Milton Miller

The kernel updated its ABI to tell the relocatable kernel to run where it was loaded.

We now need to set a flag in the kernel image. Since we only have the kernel image avialable as const data to kexec-tools c code, set the flag in the copy we put in purgatory, and have it set the flag in the kernel (after purgatory has run its checksum). To simplfy the purgatory code we can always copy the flag word back to the kernel as the c code made a copy of the original flag value.

---
v3:
purgatory now copies the flag to the kernel master entrypoint instead of the kernel reading the value copied to 0 with the slave spinloop.

rename the local varable to my_run_at_load to be more consistent, and change its type to uint32_t from unsigned int

purgatory/arch/ppc64/v2wrap.S +9 -12
Index: kexec-tools/purgatory/arch/ppc64/v2wrap.S
===================================================================
@@ -45,11 +45,14 @@
 	oris    rn,rn,name##@h;         \
 	ori     rn,rn,name##@l
 
-#define KDUMP_SIGNATURE 0xfeed1234
-
 	.machine ppc64
 	.globl purgatory_start
 purgatory_start:	b	master
+	.org purgatory_start + 0x5c     # ABI: possible run_at_load flag at 0x5c
+	.globl run_at_load
+run_at_load:
+	.long 0
+	.size run_at_load, . - run_at_load
 	.org purgatory_start + 0x60     # ABI: slaves start at 60 with r3=phys
 slave:	b $
 	.org purgatory_start + 0x100    # ABI: end of copied region
@@ -57,7 +60,7 @@ slave:	b $
 
 #
 # The above 0x100 bytes at purgatory_start are replaced with the
-# code from the kernel (or next stage) by kexec/arch/ppc64/kexec-ppc64.c
+# code from the kernel (or next stage) by kexec/arch/ppc64/kexec-elf-ppc64.c
 #
 
 master:
@@ -65,7 +68,6 @@ master:
 	isync
 	mr      17,3            # save cpu id to r17
 	mr      15,4            # save physical address in reg15
-	mr      18,6            # save kdump flag in reg18
 
 	LOADADDR(6,my_toc)
 	ld      2,0(6)          #setup toc
@@ -92,18 +94,13 @@ master:
 80:
 	LOADADDR(6,kernel)
 	ld      4,0(6)          # load the kernel address
+	LOADADDR(6,run_at_load) # the load flag
+	lwz	7,0(6)		# possibly patched by kexec-elf-ppc64
+	stw	7,0x5c(4)	# and patch it into the kernel
 	li	5,0		# r5 will be 0 for kernel
 	mtctr	4		# prepare branch too
 	mr      3,16            # restore dt address
 
-	LOADADDR(6,KDUMP_SIGNATURE)
-	cmpd	18,6
-	bne	regular
-	li	7,1
-	std	7,24(4)		# mark kdump flag at kernel
-regular:
-	lwz	7,0(4)		# get the first instruction that we stole
-	stw	7,0(0)		# and put it in the slave loop at 0
 				# skip cache flush, do we care?
 
 	bctr			# start kernel
kexec/arch/ppc64/crashdump-ppc64.h +2 -0
Index: kexec-tools/kexec/arch/ppc64/crashdump-ppc64.h
===================================================================
@@ -23,6 +23,8 @@ void add_usable_mem_rgns(unsigned long l
 #define _ALIGN_UP(addr,size)	(((addr)+((size)-1))&(~((size)-1)))
 #define _ALIGN_DOWN(addr,size)	((addr)&(~((size)-1)))
 
+#define KERNEL_RUN_AT_ZERO_MAGIC 0x72756e30	/* "run0" */
+
 extern uint64_t crash_base;
 extern uint64_t crash_size;
 extern unsigned int rtas_base;
kexec/arch/ppc64/kexec-elf-ppc64.c +17 -0
Index: kexec-tools/kexec/arch/ppc64/kexec-elf-ppc64.c
===================================================================
@@ -92,6 +92,7 @@ int elf_ppc64_load(int argc, char **argv
 	unsigned int my_panic_kernel;
 	uint64_t my_stack, my_backup_start;
 	uint64_t toc_addr;
+	uint32_t my_run_at_load;
 	unsigned int slave_code[256/sizeof (unsigned int)], master_entry;
 
 #define OPT_APPEND     (OPT_ARCH_MAX+0)
@@ -307,6 +308,18 @@ int elf_ppc64_load(int argc, char **argv
 		my_backup_start = info->backup_start;
 		elf_rel_set_symbol(&info->rhdr, "backup_start",
 				&my_backup_start, sizeof(my_backup_start));
+
+		/* Tell relocatable kernel to run at load address
+		 * via word before slave code in purgatory
+		 */
+
+		elf_rel_get_symbol(&info->rhdr, "run_at_load", &my_run_at_load,
+				sizeof(my_run_at_load));
+		if (my_run_at_load == KERNEL_RUN_AT_ZERO_MAGIC)
+			my_run_at_load = 1;
+			/* else it should be a fixed offset image */
+		elf_rel_set_symbol(&info->rhdr, "run_at_load", &my_run_at_load,
+				sizeof(my_run_at_load));
 	}
 
 	/* Set stack address */
@@ -325,10 +338,13 @@ int elf_ppc64_load(int argc, char **argv
 	my_backup_start = 0;
 	my_stack = 0;
 	toc_addr = 0;
+	my_run_at_load = 0;
 
 	elf_rel_get_symbol(&info->rhdr, "kernel", &my_kernel, sizeof(my_kernel));
 	elf_rel_get_symbol(&info->rhdr, "dt_offset", &my_dt_offset,
 				sizeof(my_dt_offset));
+	elf_rel_get_symbol(&info->rhdr, "run_at_load", &my_run_at_load,
+				sizeof(my_run_at_load));
 	elf_rel_get_symbol(&info->rhdr, "panic_kernel", &my_panic_kernel,
 				sizeof(my_panic_kernel));
 	elf_rel_get_symbol(&info->rhdr, "backup_start", &my_backup_start,
@@ -341,6 +357,7 @@ int elf_ppc64_load(int argc, char **argv
 	fprintf(stderr, "kernel is %llx\n", (unsigned long long)my_kernel);
 	fprintf(stderr, "dt_offset is %llx\n",
 		(unsigned long long)my_dt_offset);
+	fprintf(stderr, "run_at_load flag is %x\n", my_run_at_load);
 	fprintf(stderr, "panic_kernel is %x\n", my_panic_kernel);
 	fprintf(stderr, "backup_start is %llx\n",
 		(unsigned long long)my_backup_start);

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

#7 lore raw

Re: [PATCH] powerpc: check crash_base for relocatable kernel

In reply to Milton Miller
Quoted 22 lines · Milton Miller
arch/powerpc/kernel/machine_kexec.c +17 -0
@@ -94,10 +95,35 @@ void __init reserve_crashkernel(void)
 				KDUMP_KERNELBASE);
 
 	crashk_res.start = KDUMP_KERNELBASE;
+#else
+	if (!crashk_res.start) {
+		/*
+		 * unspecified address, choose a region of specified size
+		 * can overlap with initrd (ignoring corruption when retained)
+		 * ppc64 requires kernel and some stacks to be in first segemnt
+		 */
+		crashk_res.start = KDUMP_KERNELBASE;
+	}
+
+	crash_base = PAGE_ALIGN(crashk_res.start);
+	if (crash_base != crashk_res.start) {
+		printk("Crash kernel base must be aligned to 0x%lx\n",
+				PAGE_SIZE);
+		crashk_res.start = crash_base;
+	}
+
 #endif

arch/powerpc/kernel/machine_kexec.c void __init reserve_crashkernel(void) · line 125

Quoted 10 lines
arch/powerpc/kernel/machine_kexec.c +7 -0
 	crash_size = PAGE_ALIGN(crash_size);
 	crashk_res.end = crashk_res.start + crash_size - 1;
 
+	/* The crash region must not overlap the current kernel */
+	if (overlaps_crashkernel(__pa(_stext), _end - _stext)) {
+		printk(KERN_WARNING
+			"Crash kernel can not overlap current kernel\n");
+		crashk_res.start = crashk_res.end = 0;
+		return;
+	}

I think we can be smarter here. Why don't we adjust the crash kernel region so that it doesn't overlap the first kernel? ie. move it up a bit.

There's also the issue of the RMO, I'm not sure what we should do there, but I think the kernel needs some smarts otherwise users are going to shoot themselves in the foot.

We could ignore the @x setting and split the RMO between both kernels somewhat intelligently.

What might work is multiple crash regions, that way we could have some space in the RMO for the second kernel (say 32MB?), but the rest outside
- leaving some RMO for the first kernel. But I think that would require some serious surgery.

cheers

Signature · 8 lines
Michael Ellerman
OzLabs, IBM Australia Development Lab

wwweb: http://michael.ellerman.id.au
phone: +61 2 6212 1183 (tie line 70 21183)

We do not inherit the earth from our ancestors,
we borrow it from our children. - S.M.A.R.T Person
#11 lore raw

Re: [PATCH kexec-tools 1/5] ppc64: always check number of ranges when adding

In reply to Milton Miller
Quoted 59 lines · Milton Miller

make the idom "always call realloc_memory_ranges when filling a range entry"

kexec was core dumping after using 5 exclude_range pairs when only 3 were allocated.

also delcare realloc_memory_ranges to take no arguments.

Index: kexec-tools/kexec/arch/ppc64/kexec-ppc64.c
===================================================================

kexec/arch/ppc64/kexec-ppc64.c +9 -1
@@ -96,7 +96,7 @@ err1:
 
 }
 
-static int realloc_memory_ranges()
+static int realloc_memory_ranges(void)
 {
 	size_t memory_range_len;
 
@@ -469,6 +469,8 @@ static int get_devtree_details(unsigned 
 				exclude_range[i].start = initrd_start;
 				exclude_range[i].end = initrd_end;
 				i++;
+				if (i >= max_memory_ranges)
+					realloc_memory_ranges();
 			}
 		} /* chosen */
 
@@ -581,6 +583,8 @@ static int get_devtree_details(unsigned 
 			exclude_range[i].start = tce_base;
 			exclude_range[i].end = tce_base + tce_size;
 			i++;
+			if (i >= max_memory_ranges)
+				realloc_memory_ranges();
 			if (kexec_flags & KEXEC_ON_CRASH)
 				add_usable_mem_rgns(tce_base, tce_size);
 			closedir(cdir);
@@ -634,6 +638,8 @@ int setup_memory_ranges(unsigned long ke
 				memory_range[j].end = exclude_range[i].start - 1;
 				memory_range[j].type = RANGE_RAM;
 				j++;
+				if (j >= max_memory_ranges)
+					realloc_memory_ranges();
 			}
 		} /* i == 0 */
 		/* If the last exclude range does not end at memory_max, include
@@ -646,6 +652,8 @@ int setup_memory_ranges(unsigned long ke
 				memory_range[j].end = memory_max;
 				memory_range[j].type = RANGE_RAM;
 				j++;
+				if (j >= max_memory_ranges)
+					realloc_memory_ranges();
 				/* Limit the end to rmo_top */
 				if (memory_range[j-1].start >= rmo_top) {
 					j--;

kexec/arch/ppc64/kexec-ppc64.c int setup_memory_ranges(unsigned long ke · line 678

Quoted 5 lines
kexec/arch/ppc64/kexec-ppc64.c +2 -0
@@ -666,6 +674,8 @@ int setup_memory_ranges(unsigned long ke
 		memory_range[j].end = exclude_range[i+1].start - 1;
 		memory_range[j].type = RANGE_RAM;
 		j++;
+		if (i >= max_memory_ranges)
+			realloc_memory_ranges();

Should this be checking against i or j?

cheers

Signature · 8 lines
Michael Ellerman
OzLabs, IBM Australia Development Lab

wwweb: http://michael.ellerman.id.au
phone: +61 2 6212 1183 (tie line 70 21183)

We do not inherit the earth from our ancestors,
we borrow it from our children. - S.M.A.R.T Person
#12 lore raw

Re: [PATCH kexec-tools 1/5] ppc64: always check number of ranges when adding

Quoted 4 lines · Michael Ellerman
Quoted 2 lines · Milton Miller

make the idom "always call realloc_memory_ranges when filling a range entry"

Quoted 9 lines

kexec/arch/ppc64/kexec-ppc64.c int setup_memory_ranges(unsigned long ke · line 678

Quoted 6 lines
kexec/arch/ppc64/kexec-ppc64.c +2 -0
@@ -666,6 +674,8 @@ int setup_memory_ranges(unsigned long ke
 		memory_range[j].end = exclude_range[i+1].start - 1;
 		memory_range[j].type = RANGE_RAM;
 		j++;
+		if (i >= max_memory_ranges)
+			realloc_memory_ranges();

Should this be checking against i or j?

It does look like it should be against j. I'll build test and respin later.

milton

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

#8 lore raw

Re: [PATCH] powerpc: check crash_base for relocatable kernel

In reply to Michael Ellerman

[removed Paul from cc and fixed Mohan's email]

Quoted 26 lines · Michael Ellerman
Quoted 25 lines · Milton Miller
arch/powerpc/kernel/machine_kexec.c +17 -0
@@ -94,10 +95,35 @@ void __init reserve_crashkernel(void)
 				KDUMP_KERNELBASE);
 
 	crashk_res.start = KDUMP_KERNELBASE;
+#else
+	if (!crashk_res.start) {
+		/*
+		 * unspecified address, choose a region of specified size
+		 * can overlap with initrd (ignoring corruption when retained)
+		 * ppc64 requires kernel and some stacks to be in first segemnt
+		 */
+		crashk_res.start = KDUMP_KERNELBASE;
+	}
+
+	crash_base = PAGE_ALIGN(crashk_res.start);
+	if (crash_base != crashk_res.start) {
+		printk("Crash kernel base must be aligned to 0x%lx\n",
+				PAGE_SIZE);
+		crashk_res.start = crash_base;
+	}
+
 #endif
 	crash_size = PAGE_ALIGN(crash_size);
 	crashk_res.end = crashk_res.start + crash_size - 1;
 
Quoted 11 lines

arch/powerpc/kernel/machine_kexec.c void __init reserve_crashkernel(void) · line 125

Quoted 7 lines
arch/powerpc/kernel/machine_kexec.c +7 -0
+	/* The crash region must not overlap the current kernel */
+	if (overlaps_crashkernel(__pa(_stext), _end - _stext)) {
+		printk(KERN_WARNING
+			"Crash kernel can not overlap current kernel\n");
+		crashk_res.start = crashk_res.end = 0;
+		return;
+	}

I think we can be smarter here. Why don't we adjust the crash kernel region so that it doesn't overlap the first kernel? ie. move it up a bit.

How much? In addition to the size of the kernel, we have to allocate
(1) the emergeency stacks as we use them to bring up secondary cpus (2)
the irq stacks in the first segment. While the second could be met
easier on systems with 1TB slbs we don't take advantage of that yet.

Quoted 5 lines

There's also the issue of the RMO, I'm not sure what we should do there,
but I think the kernel needs some smarts otherwise users are going to shoot themselves in the foot.

I was looking at the code in kexec-tools for the rmo, and it seems extremely broken (ie it sets rmo_top on every memory block instead of the lowest; the clamp to 768M is the savior for systems with multiple blocks).

Do we care about loading a kernel below a relocated kernel (between the
interrupt vectors and the new kernel)? I ignored that for now,
arguing that we always run the first kernel at 0.

Quoted 10 lines

We could ignore the @x setting and split the RMO between both kernels somewhat intelligently.

What might work is multiple crash regions, that way we could have some space in the RMO for the second kernel (say 32MB?), but the rest outside
- leaving some RMO for the first kernel. But I think that would require some serious surgery.

Other archs have this, i guess because they read the memory out of
/proc/iomem. The trick is knowing what has to be put in real space
and what can go abvoe the rmo. Also, we have those horrible hard-code
rmo to 768M max because some platform (one of the cell ones?) didn't make the device tree to show it. Maybe we can track it down and add linux,usable-mem-ranges to fix it up?

Does the generic code support loading into the split regions, or is it just for giving the kernel room to run?

So while all of these are nice, what do you think about merging this as an interm measure, especially for backporting to 2.6.28 stable (and any distro that wants to pick up relocatable kdump)?

milton

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

#9 lore raw

Re: [PATCH] powerpc: check crash_base for relocatable kernel

Quoted 42 lines · Milton Miller

[removed Paul from cc and fixed Mohan's email]

Quoted 26 lines · Michael Ellerman
Quoted 25 lines · Milton Miller
arch/powerpc/kernel/machine_kexec.c +17 -0
@@ -94,10 +95,35 @@ void __init reserve_crashkernel(void)
 				KDUMP_KERNELBASE);
 
 	crashk_res.start = KDUMP_KERNELBASE;
+#else
+	if (!crashk_res.start) {
+		/*
+		 * unspecified address, choose a region of specified size
+		 * can overlap with initrd (ignoring corruption when retained)
+		 * ppc64 requires kernel and some stacks to be in first segemnt
+		 */
+		crashk_res.start = KDUMP_KERNELBASE;
+	}
+
+	crash_base = PAGE_ALIGN(crashk_res.start);
+	if (crash_base != crashk_res.start) {
+		printk("Crash kernel base must be aligned to 0x%lx\n",
+				PAGE_SIZE);
+		crashk_res.start = crash_base;
+	}
+
 #endif
 	crash_size = PAGE_ALIGN(crash_size);
 	crashk_res.end = crashk_res.start + crash_size - 1;
 
Quoted 11 lines

arch/powerpc/kernel/machine_kexec.c void __init reserve_crashkernel(void) · line 125

Quoted 7 lines
arch/powerpc/kernel/machine_kexec.c +7 -0
+	/* The crash region must not overlap the current kernel */
+	if (overlaps_crashkernel(__pa(_stext), _end - _stext)) {
+		printk(KERN_WARNING
+			"Crash kernel can not overlap current kernel\n");
+		crashk_res.start = crashk_res.end = 0;
+		return;
+	}

I think we can be smarter here. Why don't we adjust the crash kernel region so that it doesn't overlap the first kernel? ie. move it up a bit.

Quoted 4 lines

How much? In addition to the size of the kernel, we have to allocate
(1) the emergeency stacks as we use them to bring up secondary cpus (2)
the irq stacks in the first segment. While the second could be met
easier on systems with 1TB slbs we don't take advantage of that yet.

Hmm, we could try and work it out though. I guess we don't know how many CPUs we have at that point, which makes it a little trickier.

So we have the emergency stack and the hard & soft irq stacks per cpu, which is 48KB AFAICT. So for a 256-way system that would be 12MB.

I don't think I've seen an RMO smaller than 128MB, though I notice our RPA note specifies 64M as the minimum we'll accept. That would probably be a bit tight.

How about something like:

min_space = _end + 16MB (16 to be safe?)

if min_space < rmo_size / 2:
min_space = rmo_size / 2

if crash_base < min_space:
crash_base = min_space

Quoted 9 lines
Quoted 4 lines

There's also the issue of the RMO, I'm not sure what we should do there,
but I think the kernel needs some smarts otherwise users are going to shoot themselves in the foot.

I was looking at the code in kexec-tools for the rmo, and it seems extremely broken (ie it sets rmo_top on every memory block instead of the lowest; the clamp to 768M is the savior for systems with multiple blocks).

Oh surprise.

Quoted 3 lines

Do we care about loading a kernel below a relocated kernel (between the
interrupt vectors and the new kernel)? I ignored that for now,
arguing that we always run the first kernel at 0.

No I don't think so.

Quoted 10 lines
Quoted 9 lines

We could ignore the @x setting and split the RMO between both kernels somewhat intelligently.

What might work is multiple crash regions, that way we could have some space in the RMO for the second kernel (say 32MB?), but the rest outside
- leaving some RMO for the first kernel. But I think that would require some serious surgery.

Quoted 6 lines

Other archs have this, i guess because they read the memory out of
/proc/iomem. The trick is knowing what has to be put in real space
and what can go abvoe the rmo. Also, we have those horrible hard-code
rmo to 768M max because some platform (one of the cell ones?) didn't make the device tree to show it. Maybe we can track it down and add linux,usable-mem-ranges to fix it up?

Dunno about the cell, but some of the early blades did have crufty firmware.

Quoted 2 lines

Does the generic code support loading into the split regions, or is it just for giving the kernel room to run?

I don't think so. I don't see any logic that deals with gaps in the crashk region.

Quoted 3 lines

So while all of these are nice, what do you think about merging this as an interm measure, especially for backporting to 2.6.28 stable (and any distro that wants to pick up relocatable kdump)?

I guess. I'd rather do something smarter, like I suggested above.

cheers

Signature · 8 lines
Michael Ellerman
OzLabs, IBM Australia Development Lab

wwweb: http://michael.ellerman.id.au
phone: +61 2 6212 1183 (tie line 70 21183)

We do not inherit the earth from our ancestors,
we borrow it from our children. - S.M.A.R.T Person
#13 lore raw

PATCH v2 1/1 ppc64: always check number of ranges when adding them

In reply to Michael Ellerman

make the idom "always call realloc_memory_ranges when filling a range entry"

kexec was core dumping after using 5 exclude_range pairs when only 3 were allocated.

also delcare realloc_memory_ranges to take void.

---
v2: compare variable j not i in a spot noticed by Michael Ellerman

kexec/arch/ppc64/kexec-ppc64.c +11 -1
Index: kexec-tools/kexec/arch/ppc64/kexec-ppc64.c
===================================================================
@@ -96,7 +96,7 @@ err1:
 
 }
 
-static int realloc_memory_ranges()
+static int realloc_memory_ranges(void)
 {
 	size_t memory_range_len;
 
@@ -469,6 +469,8 @@ static int get_devtree_details(unsigned 
 				exclude_range[i].start = initrd_start;
 				exclude_range[i].end = initrd_end;
 				i++;
+				if (i >= max_memory_ranges)
+					realloc_memory_ranges();
 			}
 		} /* chosen */
 
@@ -581,6 +583,8 @@ static int get_devtree_details(unsigned 
 			exclude_range[i].start = tce_base;
 			exclude_range[i].end = tce_base + tce_size;
 			i++;
+			if (i >= max_memory_ranges)
+				realloc_memory_ranges();
 			if (kexec_flags & KEXEC_ON_CRASH)
 				add_usable_mem_rgns(tce_base, tce_size);
 			closedir(cdir);
@@ -634,6 +638,8 @@ int setup_memory_ranges(unsigned long ke
 				memory_range[j].end = exclude_range[i].start - 1;
 				memory_range[j].type = RANGE_RAM;
 				j++;
+				if (j >= max_memory_ranges)
+					realloc_memory_ranges();
 			}
 		} /* i == 0 */
 		/* If the last exclude range does not end at memory_max, include
@@ -646,6 +652,8 @@ int setup_memory_ranges(unsigned long ke
 				memory_range[j].end = memory_max;
 				memory_range[j].type = RANGE_RAM;
 				j++;
+				if (j >= max_memory_ranges)
+					realloc_memory_ranges();
 				/* Limit the end to rmo_top */
 				if (memory_range[j-1].start >= rmo_top) {
 					j--;
@@ -666,6 +674,8 @@ int setup_memory_ranges(unsigned long ke
 		memory_range[j].end = exclude_range[i+1].start - 1;
 		memory_range[j].type = RANGE_RAM;
 		j++;
+		if (j >= max_memory_ranges)
+			realloc_memory_ranges();
 		/* Limit range to rmo_top */
 		if (memory_range[j-1].start >= rmo_top) {
 			j--;

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

#17 lore raw
In reply to Milton Miller
Quoted 6 lines · Milton Miller

Follwing this mail are 5 patches for kexec userspace and two for the kernel. The first fixes an array overflow and the second updates userspace to the merged 2.6.28 kdump support. The remaining are cleanups and warning fixes, including one for the common code.

The two patchs for the kernel are independent.

Hi all,

sorry to be a bit slow in responding, this email landed just as I was leaving for a weeks holiday.

The kexec-tools patches seem reasonable to me and I'm happy to merge what I think are the latest versions - thanks Michael for your review.

Milton, here are the Subjects, Dates and Message-Ids of what I have in my queue. If you could confirm this or repost that would be great.

#1
Subject: [PATCH kexec-tools v2] ppc64: always check number of ranges when adding them
Date: Thu, 08 Jan 2009 06:33:50 -0600
Message-ID: <[email protected]>

#2
Subject: [PATCH kexec-tools 2/5] ppc64: update kdump for 2.6.28 relocatable kernel
Date: Fri, 02 Jan 2009 15:04:42 -0600
Message-Id: <[email protected]>

#3
Subject: [PATCH kexec-tools 3/5] ppc64: segments may be reordered
Date: Fri, 02 Jan 2009 15:04:45 -0600
Message-Id: <[email protected]>

#4
Subject: [PATCH kexec-tools 4/5] ppc64: cleanups
Date: Fri, 02 Jan 2009 15:04:48 -0600
Message-Id: <[email protected]>

#5
Subject: [PATCH kexec-tools 5/5] entry wants to be void *
Date: Fri, 02 Jan 2009 15:04:51 -0600
Message-Id: <[email protected]>

Signature · 9 lines
Simon Horman
  VA Linux Systems Japan K.K., Sydney, Australia Satellite Office
  H: www.vergenet.net/~horms/             W: www.valinux.co.jp/en


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#18 lore raw
Quoted 8 lines · Milton Miller
Quoted 6 lines

Follwing this mail are 5 patches for kexec userspace and two for the kernel. The first fixes an array overflow and the second updates userspace to the merged 2.6.28 kdump support. The remaining are cleanups and warning fixes, including one for the common code.

The two patchs for the kernel are independent.

Quoted 7 lines

Hi all,

sorry to be a bit slow in responding, this email landed just as I was leaving for a weeks holiday.

The kexec-tools patches seem reasonable to me and I'm happy to merge what I think are the latest versions - thanks Michael for your review.

Hi,

I tested both kernel and kexec-tools patches and kdump works fine. Tested on a POWER5 machine.

Regards,
Mohan.

#19 lore raw
In reply to Simon Horman
Quoted 6 lines · Simon Horman
Quoted 5 lines · Milton Miller

Follwing this mail are 5 patches for kexec userspace and two for the kernel. The first fixes an array overflow and the second updates userspace to the merged 2.6.28 kdump support. The remaining are cleanups and warning fixes, including one for the common code.

Quoted 7 lines
Quoted 1 line

The two patchs for the kernel are independent.

Hi all,

sorry to be a bit slow in responding, this email landed just as I was leaving for a weeks holiday.

No problem, I figured as much.

Quoted 26 lines

The kexec-tools patches seem reasonable to me and I'm happy to merge what I think are the latest versions - thanks Michael for your review.

Milton, here are the Subjects, Dates and Message-Ids of what I have in my queue. If you could confirm this or repost that would be great.

#1
Subject: [PATCH kexec-tools v2] ppc64: always check number of ranges when adding them
Date: Thu, 08 Jan 2009 06:33:50 -0600
Message-ID: <[email protected]>

#2
Subject: [PATCH kexec-tools 2/5] ppc64: update kdump for 2.6.28 relocatable kernel
Date: Fri, 02 Jan 2009 15:04:42 -0600
Message-Id: <[email protected]>

#3
Subject: [PATCH kexec-tools 3/5] ppc64: segments may be reordered
Date: Fri, 02 Jan 2009 15:04:45 -0600
Message-Id: <[email protected]>

#4
Subject: [PATCH kexec-tools 4/5] ppc64: cleanups
Date: Fri, 02 Jan 2009 15:04:48 -0600
Message-Id: <[email protected]>

Quoted 4 lines

#5
Subject: [PATCH kexec-tools 5/5] entry wants to be void *
Date: Fri, 02 Jan 2009 15:04:51 -0600
Message-Id: <[email protected]>

Based on the subjects, yes, those are the lastest versions.

And I assume you saw Mohan's tested message.

Thanks,
milton

#20 lore raw
Quoted 47 lines · Milton Miller
Quoted 6 lines · Simon Horman
Quoted 5 lines · Milton Miller

Follwing this mail are 5 patches for kexec userspace and two for the kernel. The first fixes an array overflow and the second updates userspace to the merged 2.6.28 kdump support. The remaining are cleanups and warning fixes, including one for the common code.

Quoted 7 lines
Quoted 1 line

The two patchs for the kernel are independent.

Hi all,

sorry to be a bit slow in responding, this email landed just as I was leaving for a weeks holiday.

No problem, I figured as much.

Quoted 30 lines

The kexec-tools patches seem reasonable to me and I'm happy to merge what I
think are the latest versions - thanks Michael for your review.

Milton, here are the Subjects, Dates and Message-Ids of what I have in my
queue. If you could confirm this or repost that would be great.

#1
Subject: [PATCH kexec-tools v2] ppc64: always check number of ranges when adding them
Date: Thu, 08 Jan 2009 06:33:50 -0600
Message-ID: <[email protected]>

#2
Subject: [PATCH kexec-tools 2/5] ppc64: update kdump for 2.6.28 relocatable kernel
Date: Fri, 02 Jan 2009 15:04:42 -0600
Message-Id: <[email protected]>

#3
Subject: [PATCH kexec-tools 3/5] ppc64: segments may be reordered
Date: Fri, 02 Jan 2009 15:04:45 -0600
Message-Id: <[email protected]>

#4
Subject: [PATCH kexec-tools 4/5] ppc64: cleanups
Date: Fri, 02 Jan 2009 15:04:48 -0600
Message-Id: <[email protected]>

Quoted 8 lines
Quoted 4 lines

#5
Subject: [PATCH kexec-tools 5/5] entry wants to be void *
Date: Fri, 02 Jan 2009 15:04:51 -0600
Message-Id: <[email protected]>

Based on the subjects, yes, those are the lastest versions.

And I assume you saw Mohan's tested message.

Thanks. I've added a "Tested-by: M. Mohan Kumar <[email protected]>" tag to each of the five patches and applied them.

Signature · 3 lines
Simon Horman
  VA Linux Systems Japan K.K., Sydney, Australia Satellite Office
  H: www.vergenet.net/~horms/             W: www.valinux.co.jp/en