Blame SOURCES/kexec-tools-2.0.14-arm64-kdump-identify-memory-regions.patch

23ef29
From 2fa1ef9e45b3ce6f7977a2518e58e177934f377c Mon Sep 17 00:00:00 2001
23ef29
Message-Id: <2fa1ef9e45b3ce6f7977a2518e58e177934f377c.1489676829.git.panand@redhat.com>
23ef29
In-Reply-To: <f85183096d31d865c97565614535d84943b12908.1489676829.git.panand@redhat.com>
23ef29
References: <f85183096d31d865c97565614535d84943b12908.1489676829.git.panand@redhat.com>
23ef29
From: AKASHI Takahiro <takahiro.akashi@linaro.org>
23ef29
Date: Wed, 15 Mar 2017 18:38:19 +0900
23ef29
Subject: [PATCH 05/10] arm64: kdump: identify memory regions
23ef29
23ef29
The following regions need to be identified for later use:
23ef29
 a) memory regions which belong to the 1st kernel
23ef29
 b) usable memory reserved for crash dump kernel
23ef29
23ef29
We go through /proc/iomem to find out a) and b) which are marked
23ef29
as "System RAM" and "Crash kernel", respectively.
23ef29
23ef29
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
23ef29
---
23ef29
 kexec/arch/arm64/Makefile          |   2 +
23ef29
 kexec/arch/arm64/crashdump-arm64.c | 100 ++++++++++++++++++++++++++++++++++++-
23ef29
 kexec/arch/arm64/crashdump-arm64.h |  14 +++++-
23ef29
 kexec/arch/arm64/iomem.h           |   1 +
23ef29
 4 files changed, 114 insertions(+), 3 deletions(-)
23ef29
23ef29
diff --git a/kexec/arch/arm64/Makefile b/kexec/arch/arm64/Makefile
23ef29
index 74b677f7784e..2d4ae0eed9e0 100644
23ef29
--- a/kexec/arch/arm64/Makefile
23ef29
+++ b/kexec/arch/arm64/Makefile
23ef29
@@ -6,6 +6,8 @@ arm64_FS2DT_INCLUDE += \
23ef29
 
23ef29
 arm64_DT_OPS += kexec/dt-ops.c
23ef29
 
23ef29
+arm64_MEM_REGIONS = kexec/mem_regions.c
23ef29
+
23ef29
 arm64_CPPFLAGS += -I $(srcdir)/kexec/
23ef29
 
23ef29
 arm64_KEXEC_SRCS += \
23ef29
diff --git a/kexec/arch/arm64/crashdump-arm64.c b/kexec/arch/arm64/crashdump-arm64.c
23ef29
index d2272c8124d0..dcaca434af62 100644
23ef29
--- a/kexec/arch/arm64/crashdump-arm64.c
23ef29
+++ b/kexec/arch/arm64/crashdump-arm64.c
23ef29
@@ -1,5 +1,13 @@
23ef29
 /*
23ef29
  * ARM64 crashdump.
23ef29
+ *     partly derived from arm implementation
23ef29
+ *
23ef29
+ * Copyright (c) 2014-2016 Linaro Limited
23ef29
+ * Author: AKASHI Takahiro <takahiro.akashi@linaro.org>
23ef29
+ *
23ef29
+ * This program is free software; you can redistribute it and/or modify
23ef29
+ * it under the terms of the GNU General Public License version 2 as
23ef29
+ * published by the Free Software Foundation.
23ef29
  */
23ef29
 
23ef29
 #define _GNU_SOURCE
23ef29
@@ -10,12 +18,102 @@
23ef29
 #include "kexec.h"
23ef29
 #include "crashdump.h"
23ef29
 #include "crashdump-arm64.h"
23ef29
+#include "iomem.h"
23ef29
 #include "kexec-arm64.h"
23ef29
 #include "kexec-elf.h"
23ef29
+#include "mem_regions.h"
23ef29
 
23ef29
-struct memory_ranges usablemem_rgns = {};
23ef29
+/* memory ranges on crashed kernel */
23ef29
+static struct memory_range crash_memory_ranges[CRASH_MAX_MEMORY_RANGES];
23ef29
+static struct memory_ranges crash_memory_rgns = {
23ef29
+	.size = 0,
23ef29
+	.max_size = CRASH_MAX_MEMORY_RANGES,
23ef29
+	.ranges = crash_memory_ranges,
23ef29
+};
23ef29
+
23ef29
+/* memory range reserved for crashkernel */
23ef29
+struct memory_range crash_reserved_mem;
23ef29
+struct memory_ranges usablemem_rgns = {
23ef29
+	.size = 0,
23ef29
+	.max_size = 1,
23ef29
+	.ranges = &crash_reserved_mem,
23ef29
+};
23ef29
+
23ef29
+/*
23ef29
+ * iomem_range_callback() - callback called for each iomem region
23ef29
+ * @data: not used
23ef29
+ * @nr: not used
23ef29
+ * @str: name of the memory region
23ef29
+ * @base: start address of the memory region
23ef29
+ * @length: size of the memory region
23ef29
+ *
23ef29
+ * This function is called once for each memory region found in /proc/iomem.
23ef29
+ * It locates system RAM and crashkernel reserved memory and places these to
23ef29
+ * variables, respectively, crash_memory_ranges and crash_reserved_mem.
23ef29
+ */
23ef29
+
23ef29
+static int iomem_range_callback(void *UNUSED(data), int UNUSED(nr),
23ef29
+				char *str, unsigned long long base,
23ef29
+				unsigned long long length)
23ef29
+{
23ef29
+	if (strncmp(str, CRASH_KERNEL, strlen(CRASH_KERNEL)) == 0)
23ef29
+		return mem_regions_add(&usablemem_rgns,
23ef29
+				       base, length, RANGE_RAM);
23ef29
+	else if (strncmp(str, SYSTEM_RAM, strlen(SYSTEM_RAM)) == 0)
23ef29
+		return mem_regions_add(&crash_memory_rgns,
23ef29
+				       base, length, RANGE_RAM);
23ef29
+
23ef29
+	return 0;
23ef29
+}
23ef29
 
23ef29
 int is_crashkernel_mem_reserved(void)
23ef29
 {
23ef29
+	if (!crash_reserved_mem.end)
23ef29
+		kexec_iomem_for_each_line(NULL, iomem_range_callback, NULL);
23ef29
+
23ef29
+	return crash_reserved_mem.start != crash_reserved_mem.end;
23ef29
+}
23ef29
+
23ef29
+/*
23ef29
+ * crash_get_memory_ranges() - read system physical memory
23ef29
+ *
23ef29
+ * Function reads through system physical memory and stores found memory
23ef29
+ * regions in crash_memory_ranges.
23ef29
+ * Regions are sorted in ascending order.
23ef29
+ *
23ef29
+ * Returns 0 in case of success and -1 otherwise (errno is set).
23ef29
+ */
23ef29
+static int crash_get_memory_ranges(void)
23ef29
+{
23ef29
+	/*
23ef29
+	 * First read all memory regions that can be considered as
23ef29
+	 * system memory including the crash area.
23ef29
+	 */
23ef29
+	if (!usablemem_rgns.size)
23ef29
+		kexec_iomem_for_each_line(NULL, iomem_range_callback, NULL);
23ef29
+
23ef29
+	/* allow only a single region for crash dump kernel */
23ef29
+	if (usablemem_rgns.size != 1) {
23ef29
+		errno = EINVAL;
23ef29
+		return -1;
23ef29
+	}
23ef29
+
23ef29
+	dbgprint_mem_range("Reserved memory range", &crash_reserved_mem, 1);
23ef29
+
23ef29
+	if (mem_regions_exclude(&crash_memory_rgns, &crash_reserved_mem)) {
23ef29
+		fprintf(stderr,
23ef29
+			"Error: Number of crash memory ranges excedeed the max limit\n");
23ef29
+		errno = ENOMEM;
23ef29
+		return -1;
23ef29
+	}
23ef29
+
23ef29
+	/*
23ef29
+	 * Make sure that the memory regions are sorted.
23ef29
+	 */
23ef29
+	mem_regions_sort(&crash_memory_rgns);
23ef29
+
23ef29
+	dbgprint_mem_range("Coredump memory ranges",
23ef29
+			   crash_memory_rgns.ranges, crash_memory_rgns.size);
23ef29
+
23ef29
 	return 0;
23ef29
 }
23ef29
diff --git a/kexec/arch/arm64/crashdump-arm64.h b/kexec/arch/arm64/crashdump-arm64.h
23ef29
index f33c7a25b454..07a0ed0bc344 100644
23ef29
--- a/kexec/arch/arm64/crashdump-arm64.h
23ef29
+++ b/kexec/arch/arm64/crashdump-arm64.h
23ef29
@@ -1,12 +1,22 @@
23ef29
 /*
23ef29
  * ARM64 crashdump.
23ef29
+ *
23ef29
+ * Copyright (c) 2014-2016 Linaro Limited
23ef29
+ * Author: AKASHI Takahiro <takahiro.akashi@linaro.org>
23ef29
+ *
23ef29
+ * This program is free software; you can redistribute it and/or modify
23ef29
+ * it under the terms of the GNU General Public License version 2 as
23ef29
+ * published by the Free Software Foundation.
23ef29
  */
23ef29
 
23ef29
-#if !defined(CRASHDUMP_ARM64_H)
23ef29
+#ifndef CRASHDUMP_ARM64_H
23ef29
 #define CRASHDUMP_ARM64_H
23ef29
 
23ef29
 #include "kexec.h"
23ef29
 
23ef29
+#define CRASH_MAX_MEMORY_RANGES	32
23ef29
+
23ef29
 extern struct memory_ranges usablemem_rgns;
23ef29
+extern struct memory_range crash_reserved_mem;
23ef29
 
23ef29
-#endif
23ef29
+#endif /* CRASHDUMP_ARM64_H */
23ef29
diff --git a/kexec/arch/arm64/iomem.h b/kexec/arch/arm64/iomem.h
23ef29
index 7fd66eb063e1..20cda87dbd02 100644
23ef29
--- a/kexec/arch/arm64/iomem.h
23ef29
+++ b/kexec/arch/arm64/iomem.h
23ef29
@@ -2,6 +2,7 @@
23ef29
 #define IOMEM_H
23ef29
 
23ef29
 #define SYSTEM_RAM		"System RAM\n"
23ef29
+#define CRASH_KERNEL		"Crash kernel\n"
23ef29
 #define IOMEM_RESERVED		"reserved\n"
23ef29
 
23ef29
 #endif
23ef29
-- 
23ef29
2.9.3
23ef29