Blame SOURCES/kexec-tools-2.0.4-kdump-x86-Process-multiple-Crash-kernel-in-proc-iome.patch

ab224c
From e25e6e7593cae350ecaa3fcd6d20c7de87f4c309 Mon Sep 17 00:00:00 2001
ab224c
From: Yinghai Lu <yinghai@kernel.org>
ab224c
Date: Fri, 22 Mar 2013 13:54:06 -0700
ab224c
Subject: [PATCH] kdump, x86: Process multiple Crash kernel in /proc/iomem
ab224c
ab224c
Vivek found specical handling crashkernel low in not good.
ab224c
We should extend kexec-tools to handle multiple Crash kernel instead.
ab224c
ab224c
Extend crash_reserved_mem to array instead and use
ab224c
kexec_iomem_for_each_line directly.  After that we can drop
ab224c
crashkernel low.
ab224c
ab224c
-v2: fix left over calling of parse_iomem_single() found by Vivek.
ab224c
ab224c
Suggested-by: Vivek Goyal <vgoyal@redhat.com>
ab224c
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
ab224c
Signed-off-by: Simon Horman <horms@verge.net.au>
ab224c
---
ab224c
 kexec/arch/i386/crashdump-x86.c    | 107 +++++++++++++++++++++----------------
ab224c
 kexec/arch/i386/kexec-x86-common.c |   4 +-
ab224c
 kexec/kexec.h                      |   1 +
ab224c
 3 files changed, 65 insertions(+), 47 deletions(-)
ab224c
ab224c
diff --git a/kexec/arch/i386/crashdump-x86.c b/kexec/arch/i386/crashdump-x86.c
ab224c
index 9ab648b..4167e5e 100644
ab224c
--- a/kexec/arch/i386/crashdump-x86.c
ab224c
+++ b/kexec/arch/i386/crashdump-x86.c
ab224c
@@ -188,9 +188,9 @@ static int exclude_region(int *nr_ranges, uint64_t start, uint64_t end);
ab224c
 static struct memory_range crash_memory_range[CRASH_MAX_MEMORY_RANGES];
ab224c
 
ab224c
 /* Memory region reserved for storing panic kernel and other data. */
ab224c
-static struct memory_range crash_reserved_mem;
ab224c
-/* under 4G parts */
ab224c
-static struct memory_range crash_reserved_low_mem;
ab224c
+#define CRASH_RESERVED_MEM_NR	8
ab224c
+static struct memory_range crash_reserved_mem[CRASH_RESERVED_MEM_NR];
ab224c
+static int crash_reserved_mem_nr;
ab224c
 
ab224c
 /* Reads the appropriate file and retrieves the SYSTEM RAM regions for whom to
ab224c
  * create Elf headers. Keeping it separate from get_memory_ranges() as
ab224c
@@ -207,7 +207,7 @@ static int get_crash_memory_ranges(struct memory_range **range, int *ranges,
ab224c
 				   int kexec_flags, unsigned long lowmem_limit)
ab224c
 {
ab224c
 	const char *iomem = proc_iomem();
ab224c
-	int memory_ranges = 0, gart = 0;
ab224c
+	int memory_ranges = 0, gart = 0, i;
ab224c
 	char line[MAX_LINE];
ab224c
 	FILE *fp;
ab224c
 	unsigned long long start, end;
ab224c
@@ -268,29 +268,28 @@ static int get_crash_memory_ranges(struct memory_range **range, int *ranges,
ab224c
 	}
ab224c
 	fclose(fp);
ab224c
 	if (kexec_flags & KEXEC_PRESERVE_CONTEXT) {
ab224c
-		int i;
ab224c
 		for (i = 0; i < memory_ranges; i++) {
ab224c
 			if (crash_memory_range[i].end > 0x0009ffff) {
ab224c
-				crash_reserved_mem.start = \
ab224c
+				crash_reserved_mem[0].start = \
ab224c
 					crash_memory_range[i].start;
ab224c
 				break;
ab224c
 			}
ab224c
 		}
ab224c
-		if (crash_reserved_mem.start >= mem_max) {
ab224c
+		if (crash_reserved_mem[0].start >= mem_max) {
ab224c
 			fprintf(stderr, "Too small mem_max: 0x%llx.\n",
ab224c
 				mem_max);
ab224c
 			return -1;
ab224c
 		}
ab224c
-		crash_reserved_mem.end = mem_max;
ab224c
-		crash_reserved_mem.type = RANGE_RAM;
ab224c
+		crash_reserved_mem[0].end = mem_max;
ab224c
+		crash_reserved_mem[0].type = RANGE_RAM;
ab224c
+		crash_reserved_mem_nr = 1;
ab224c
 	}
ab224c
-	if (exclude_region(&memory_ranges, crash_reserved_mem.start,
ab224c
-				crash_reserved_mem.end) < 0)
ab224c
-		return -1;
ab224c
-	if (crash_reserved_low_mem.start &&
ab224c
-	    exclude_region(&memory_ranges, crash_reserved_low_mem.start,
ab224c
-				crash_reserved_low_mem.end) < 0)
ab224c
-		return -1;
ab224c
+
ab224c
+	for (i = 0; i < crash_reserved_mem_nr; i++)
ab224c
+		if (exclude_region(&memory_ranges, crash_reserved_mem[i].start,
ab224c
+				crash_reserved_mem[i].end) < 0)
ab224c
+			return -1;
ab224c
+
ab224c
 	if (gart) {
ab224c
 		/* exclude GART region if the system has one */
ab224c
 		if (exclude_region(&memory_ranges, gart_start, gart_end) < 0)
ab224c
@@ -351,9 +350,10 @@ static int get_crash_memory_ranges_xen(struct memory_range **range,
ab224c
 
ab224c
 	qsort(*range, *ranges, sizeof(struct memory_range), compare_ranges);
ab224c
 
ab224c
-	if (exclude_region(ranges, crash_reserved_mem.start,
ab224c
-						crash_reserved_mem.end) < 0)
ab224c
-		goto err;
ab224c
+	for (i = 0; i < crash_reserved_mem_nr; i++)
ab224c
+		if (exclude_region(ranges, crash_reserved_mem[i].start,
ab224c
+						crash_reserved_mem[i].end) < 0)
ab224c
+			goto err;
ab224c
 
ab224c
 	ret = 0;
ab224c
 
ab224c
@@ -434,9 +434,10 @@ static int get_crash_memory_ranges_xen(struct memory_range **range,
ab224c
 
ab224c
 	qsort(*range, *ranges, sizeof(struct memory_range), compare_ranges);
ab224c
 
ab224c
-	if (exclude_region(ranges, crash_reserved_mem.start,
ab224c
-						crash_reserved_mem.end) < 0)
ab224c
-		goto err;
ab224c
+	for (i = 0; i < crash_reserved_mem_nr; i++)
ab224c
+		if (exclude_region(ranges, crash_reserved_mem[i].start,
ab224c
+						crash_reserved_mem[i].end) < 0)
ab224c
+			goto err;
ab224c
 
ab224c
 	ret = 0;
ab224c
 
ab224c
@@ -1014,15 +1015,10 @@ int load_crashdump_segments(struct kexec_info *info, char* mod_cmdline,
ab224c
 	memmap_p = xmalloc(sz);
ab224c
 	memset(memmap_p, 0, sz);
ab224c
 	add_memmap(memmap_p, info->backup_src_start, info->backup_src_size);
ab224c
-	sz = crash_reserved_mem.end - crash_reserved_mem.start +1;
ab224c
-	if (add_memmap(memmap_p, crash_reserved_mem.start, sz) < 0) {
ab224c
-		return ENOCRASHKERNEL;
ab224c
-	}
ab224c
-
ab224c
-	if (crash_reserved_low_mem.start) {
ab224c
-		sz = crash_reserved_low_mem.end - crash_reserved_low_mem.start
ab224c
-					 +1;
ab224c
-		add_memmap(memmap_p, crash_reserved_low_mem.start, sz);
ab224c
+	for (i = 0; i < crash_reserved_mem_nr; i++) {
ab224c
+		sz = crash_reserved_mem[i].end - crash_reserved_mem[i].start +1;
ab224c
+		if (add_memmap(memmap_p, crash_reserved_mem[i].start, sz) < 0)
ab224c
+			return ENOCRASHKERNEL;
ab224c
 	}
ab224c
 
ab224c
 	/* Create a backup region segment to store backup data*/
ab224c
@@ -1093,25 +1089,46 @@ int load_crashdump_segments(struct kexec_info *info, char* mod_cmdline,
ab224c
 	return 0;
ab224c
 }
ab224c
 
ab224c
-int is_crashkernel_mem_reserved(void)
ab224c
+int get_max_crash_kernel_limit(uint64_t *start, uint64_t *end)
ab224c
 {
ab224c
-	uint64_t start, end;
ab224c
+	int i, idx = -1;
ab224c
+	unsigned long sz_max = 0, sz;
ab224c
 
ab224c
-	if (parse_iomem_single("Crash kernel\n", &start, &end) || start == end)
ab224c
-		return 0;
ab224c
+	if (!crash_reserved_mem_nr)
ab224c
+		return -1;
ab224c
 
ab224c
-	crash_reserved_mem.start = start;
ab224c
-	crash_reserved_mem.end = end;
ab224c
-	crash_reserved_mem.type = RANGE_RAM;
ab224c
+	for (i = crash_reserved_mem_nr - 1; i >= 0; i--) {
ab224c
+		sz = crash_reserved_mem[i].end - crash_reserved_mem[i].start +1;
ab224c
+		if (sz <= sz_max)
ab224c
+			continue;
ab224c
+		sz_max = sz;
ab224c
+		idx = i;
ab224c
+	}
ab224c
+
ab224c
+	*start = crash_reserved_mem[idx].start;
ab224c
+	*end = crash_reserved_mem[idx].end;
ab224c
+
ab224c
+	return 0;
ab224c
+}
ab224c
 
ab224c
-	/* If there is no Crash low kernel, still can go on */
ab224c
-	if (parse_iomem_single("Crash kernel low\n", &start, &end) ||
ab224c
-					start == end)
ab224c
+static int crashkernel_mem_callback(void *UNUSED(data), int nr,
ab224c
+                                          char *UNUSED(str),
ab224c
+                                          unsigned long base,
ab224c
+                                          unsigned long length)
ab224c
+{
ab224c
+	if (nr >= CRASH_RESERVED_MEM_NR)
ab224c
 		return 1;
ab224c
 
ab224c
-	crash_reserved_low_mem.start = start;
ab224c
-	crash_reserved_low_mem.end = end;
ab224c
-	crash_reserved_low_mem.type = RANGE_RAM;
ab224c
+	crash_reserved_mem[nr].start = base;
ab224c
+	crash_reserved_mem[nr].end   = base + length - 1;
ab224c
+	crash_reserved_mem[nr].type  = RANGE_RAM;
ab224c
+	return 0;
ab224c
+}
ab224c
+
ab224c
+int is_crashkernel_mem_reserved(void)
ab224c
+{
ab224c
+	crash_reserved_mem_nr = kexec_iomem_for_each_line("Crash kernel\n",
ab224c
+                                       crashkernel_mem_callback, NULL);
ab224c
 
ab224c
-	return 1;
ab224c
+	return !!crash_reserved_mem_nr;
ab224c
 }
ab224c
diff --git a/kexec/arch/i386/kexec-x86-common.c b/kexec/arch/i386/kexec-x86-common.c
ab224c
index 234823c..ed6c950 100644
ab224c
--- a/kexec/arch/i386/kexec-x86-common.c
ab224c
+++ b/kexec/arch/i386/kexec-x86-common.c
ab224c
@@ -465,9 +465,9 @@ int get_memory_ranges(struct memory_range **range, int *ranges,
ab224c
 	    !(kexec_flags & KEXEC_PRESERVE_CONTEXT)) {
ab224c
 		uint64_t start, end;
ab224c
 
ab224c
-		ret = parse_iomem_single("Crash kernel\n", &start, &end;;
ab224c
+		ret = get_max_crash_kernel_limit(&start, &end;;
ab224c
 		if (ret != 0) {
ab224c
-			fprintf(stderr, "parse_iomem_single failed.\n");
ab224c
+			fprintf(stderr, "get_max_crash_kernel_limit failed.\n");
ab224c
 			return -1;
ab224c
 		}
ab224c
 
ab224c
diff --git a/kexec/kexec.h b/kexec/kexec.h
ab224c
index 916a24b..5ded390 100644
ab224c
--- a/kexec/kexec.h
ab224c
+++ b/kexec/kexec.h
ab224c
@@ -272,6 +272,7 @@ int arch_process_options(int argc, char **argv);
ab224c
 int arch_compat_trampoline(struct kexec_info *info);
ab224c
 void arch_update_purgatory(struct kexec_info *info);
ab224c
 int is_crashkernel_mem_reserved(void);
ab224c
+int get_max_crash_kernel_limit(uint64_t *start, uint64_t *end);
ab224c
 char *get_command_line(void);
ab224c
 
ab224c
 int kexec_iomem_for_each_line(char *match,
ab224c
-- 
ab224c
1.8.3.1
ab224c