kexec-tools/0036-kexec-generalize-and-rename-get_kernel_stext_sym.patch
Tony Jones 080f64dafa Accepting request 500203 from home:tiwai:branches:Kernel:kdump
- Update to version 2.0.14 (bsc#1039937, FATE#320672, FATE#320671)
  Changelog: http://git.kernel.org/cgit/utils/kernel/kexec/kexec-tools.git/log/?id=refs/tags/v2.0.13..v2.0.14
- Backport upstream fixes  (bsc#1039937, FATE#320672, FATE#320671)
  0001-kexec-tools-2.0.14.git.patch
  0002-ppc64-Reduce-number-of-ELF-LOAD-segments.patch
  0003-kexec-Increase-the-upper-limit-for-RAM-segments.patch
  0004-alpha-add-missing-__NR_kexec_load-definition.patch
  0005-kexec-implemented-XEN-KEXEC-STATUS-to-determine-if-a.patch
  0006-kexec-Remove-redundant-space-from-help-message.patch
  0007-purgatory-Add-purgatory.map-and-purgatory.ro.sym-to-.patch
  0008-kexec-Add-option-to-get-crash-kernel-region-size.patch
  0009-crashdump-arm-Add-get_crash_kernel_load_range-functi.patch
  0010-crashdump-arm64-Add-get_crash_kernel_load_range-func.patch
  0011-crashdump-cris-Add-get_crash_kernel_load_range-funct.patch
  0012-crashdump-ia64-Add-get_crash_kernel_load_range-funct.patch
  0013-crashdump-m68k-Add-get_crash_kernel_load_range-funct.patch
  0014-crashdump-mips-Add-get_crash_kernel_load_range-funct.patch
  0015-crashdump-ppc-Add-get_crash_kernel_load_range-functi.patch
  0016-crashdump-ppc64-Add-get_crash_kernel_load_range-func.patch
  0017-crashdump-s390-Add-get_crash_kernel_load_range-funct.patch
  0018-crashdump-sh-Add-get_crash_kernel_load_range-functio.patch
  0019-gitignore-add-two-generated-files-in-purgatory.patch
  0020-Only-print-debug-message-when-failed-to-serach-for-k.patch
  0021-build_mem_phdrs-check-if-p_paddr-is-invalid.patch
  0022-uImage-fix-realloc-pointer-confusion.patch
  0023-uImage-Fix-uImage_load-for-little-endian-machines.patch
  0024-uImage-Add-new-IH_ARCH_xxx-definitions.patch
  0025-uImage-use-char-instead-of-unsigned-char-for-uImage_.patch
  0026-uImage-use-char-instead-of-unsigned-char-for-uImage_.patch
  0027-arm64-add-uImage-support.patch

OBS-URL: https://build.opensuse.org/request/show/500203
OBS-URL: https://build.opensuse.org/package/show/Kernel:kdump/kexec-tools?expand=0&rev=83
2017-05-31 20:00:34 +00:00

188 lines
5.4 KiB
Diff

From 325804055e99dbf40af5e6fa546320b821d9d821 Mon Sep 17 00:00:00 2001
From: Pratyush Anand <panand@redhat.com>
Date: Wed, 17 May 2017 14:51:42 +0900
Subject: [PATCH 36/45] kexec: generalize and rename get_kernel_stext_sym()
get_kernel_stext_sym() has been defined for both arm and i386. Other
architecture might need some other kernel symbol address. Therefore rewrite
this function as generic function to get any kernel symbol address.
More over, kallsyms is not arch specific representation, therefore have
common function for all arches.
Signed-off-by: Pratyush Anand <panand@redhat.com>
[created symbols.c]
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Tested-by: David Woodhouse <dwmw@amazon.co.uk>
Tested-by: Pratyush Anand <panand@redhat.com>
Signed-off-by: Simon Horman <horms@verge.net.au>
---
kexec/Makefile | 1 +
kexec/arch/arm/crashdump-arm.c | 40 +---------------------------------------
kexec/arch/i386/crashdump-x86.c | 29 -----------------------------
kexec/kexec.h | 2 ++
kexec/symbols.c | 34 ++++++++++++++++++++++++++++++++++
5 files changed, 38 insertions(+), 68 deletions(-)
create mode 100644 kexec/symbols.c
diff --git a/kexec/Makefile b/kexec/Makefile
index 39f365f543d7..2b4fb3d162ec 100644
--- a/kexec/Makefile
+++ b/kexec/Makefile
@@ -26,6 +26,7 @@ KEXEC_SRCS_base += kexec/kernel_version.c
KEXEC_SRCS_base += kexec/lzma.c
KEXEC_SRCS_base += kexec/zlib.c
KEXEC_SRCS_base += kexec/kexec-xen.c
+KEXEC_SRCS_base += kexec/symbols.c
KEXEC_GENERATED_SRCS += $(PURGATORY_HEX_C)
diff --git a/kexec/arch/arm/crashdump-arm.c b/kexec/arch/arm/crashdump-arm.c
index ac76e0a812d5..daa478868b49 100644
--- a/kexec/arch/arm/crashdump-arm.c
+++ b/kexec/arch/arm/crashdump-arm.c
@@ -73,48 +73,10 @@ static struct crash_elf_info elf_info = {
extern unsigned long long user_page_offset;
-/* Retrieve kernel _stext symbol virtual address from /proc/kallsyms */
-static unsigned long long get_kernel_stext_sym(void)
-{
- const char *kallsyms = "/proc/kallsyms";
- const char *stext = "_stext";
- char sym[128];
- char line[128];
- FILE *fp;
- unsigned long long vaddr = 0;
- char type;
-
- fp = fopen(kallsyms, "r");
- if (!fp) {
- fprintf(stderr, "Cannot open %s\n", kallsyms);
- return 0;
- }
-
- while(fgets(line, sizeof(line), fp) != NULL) {
- unsigned long long addr;
-
- if (sscanf(line, "%Lx %c %s", &addr, &type, sym) != 3)
- continue;
-
- if (strcmp(sym, stext) == 0) {
- dbgprintf("kernel symbol %s vaddr = %#llx\n", stext, addr);
- vaddr = addr;
- break;
- }
- }
-
- fclose(fp);
-
- if (vaddr == 0)
- fprintf(stderr, "Cannot get kernel %s symbol address\n", stext);
-
- return vaddr;
-}
-
static int get_kernel_page_offset(struct kexec_info *info,
struct crash_elf_info *elf_info)
{
- unsigned long long stext_sym_addr = get_kernel_stext_sym();
+ unsigned long long stext_sym_addr = get_kernel_sym("_stext");
if (stext_sym_addr == 0) {
if (user_page_offset != (-1ULL)) {
elf_info->page_offset = user_page_offset;
diff --git a/kexec/arch/i386/crashdump-x86.c b/kexec/arch/i386/crashdump-x86.c
index 285dea9abd4b..69a063a5670b 100644
--- a/kexec/arch/i386/crashdump-x86.c
+++ b/kexec/arch/i386/crashdump-x86.c
@@ -102,35 +102,6 @@ static int get_kernel_paddr(struct kexec_info *UNUSED(info),
return -1;
}
-/* Retrieve kernel symbol virtual address from /proc/kallsyms */
-static unsigned long long get_kernel_sym(const char *symbol)
-{
- const char *kallsyms = "/proc/kallsyms";
- char sym[128];
- char line[128];
- FILE *fp;
- unsigned long long vaddr;
- char type;
-
- fp = fopen(kallsyms, "r");
- if (!fp) {
- fprintf(stderr, "Cannot open %s\n", kallsyms);
- return 0;
- }
-
- while(fgets(line, sizeof(line), fp) != NULL) {
- if (sscanf(line, "%llx %c %s", &vaddr, &type, sym) != 3)
- continue;
- if (strcmp(sym, symbol) == 0) {
- dbgprintf("kernel symbol %s vaddr = %16llx\n", symbol, vaddr);
- return vaddr;
- }
- }
-
- dbgprintf("Cannot get kernel %s symbol address\n", symbol);
- return 0;
-}
-
/* Retrieve info regarding virtual address kernel has been compiled for and
* size of the kernel from /proc/kcore. Current /proc/kcore parsing from
* from kexec-tools fails because of malformed elf notes. A kernel patch has
diff --git a/kexec/kexec.h b/kexec/kexec.h
index 52bef9b3c0f5..26225d2c002a 100644
--- a/kexec/kexec.h
+++ b/kexec/kexec.h
@@ -317,4 +317,6 @@ int xen_kexec_unload(uint64_t kexec_flags);
void xen_kexec_exec(void);
int xen_kexec_status(uint64_t kexec_flags);
+extern unsigned long long get_kernel_sym(const char *text);
+
#endif /* KEXEC_H */
diff --git a/kexec/symbols.c b/kexec/symbols.c
new file mode 100644
index 000000000000..e88f7f342d3b
--- /dev/null
+++ b/kexec/symbols.c
@@ -0,0 +1,34 @@
+#include <stdio.h>
+#include <string.h>
+#include "kexec.h"
+
+/* Retrieve kernel symbol virtual address from /proc/kallsyms */
+unsigned long long get_kernel_sym(const char *symbol)
+{
+ const char *kallsyms = "/proc/kallsyms";
+ char sym[128];
+ char line[128];
+ FILE *fp;
+ unsigned long long vaddr;
+ char type;
+
+ fp = fopen(kallsyms, "r");
+ if (!fp) {
+ fprintf(stderr, "Cannot open %s\n", kallsyms);
+ return 0;
+ }
+
+ while (fgets(line, sizeof(line), fp) != NULL) {
+ if (sscanf(line, "%llx %c %s", &vaddr, &type, sym) != 3)
+ continue;
+ if (strcmp(sym, symbol) == 0) {
+ dbgprintf("kernel symbol %s vaddr = %16llx\n",
+ symbol, vaddr);
+ return vaddr;
+ }
+ }
+
+ dbgprintf("Cannot get kernel %s symbol address\n", symbol);
+
+ return 0;
+}
--
2.13.0