[PATCH 1/4] kdump: Introduce ELFCORE_ADDR_NEWMEM
From: Michael Holzheu
Date: Mon May 06 2013 - 09:11:30 EST
Currently vmcore gets the ELF header from oldmem using the global variable
"elfcorehdr_addr". This patch introduces a new possible value
ELFCORE_ADDR_NEWMEM. This indicates that the ELF header is allocated
in the new (2nd) kernel. In this case a new architecture function
arch_vmcore_get_elf_hdr() is called to obtain address and length of the
ELF header. The ELF header that is created in the 2nd kernel already
contains the correct relative offsets in the ELF notes and loads sections.
Signed-off-by: Michael Holzheu <holzheu@xxxxxxxxxxxxxxxxxx>
---
fs/proc/vmcore.c | 65 ++++++++++++++++++++++++++++++++++++++++++++--
include/linux/crash_dump.h | 4 ++-
2 files changed, 66 insertions(+), 3 deletions(-)
diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
index 17f7e08..71db4e6 100644
--- a/fs/proc/vmcore.c
+++ b/fs/proc/vmcore.c
@@ -487,6 +487,18 @@ static int __init process_ptload_program_headers_elf32(char *elfptr,
}
/* Sets offset fields of vmcore elements. */
+static void __init set_vmcore_list_offsets_newmem(struct list_head *vc_list)
+{
+ loff_t vmcore_off = elfcorebuf_sz;
+ struct vmcore *m;
+
+ list_for_each_entry(m, vc_list, list) {
+ m->offset = vmcore_off;
+ vmcore_off += m->size;
+ }
+}
+
+/* Sets offset fields of vmcore elements. */
static void __init set_vmcore_list_offsets_elf64(char *elfptr,
struct list_head *vc_list)
{
@@ -636,7 +648,7 @@ static int __init parse_crash_elf32_headers(void)
return 0;
}
-static int __init parse_crash_elf_headers(void)
+static int __init parse_crash_elf_headers_oldmem(void)
{
unsigned char e_ident[EI_NIDENT];
u64 addr;
@@ -672,6 +684,52 @@ static int __init parse_crash_elf_headers(void)
return 0;
}
+/*
+ * provide an empty default implementation here -- architecture
+ * code may override this
+ */
+int __weak arch_vmcore_get_elf_hdr(char **elfcorebuf, size_t *elfcorebuf_sz)
+{
+ return -EOPNOTSUPP;
+}
+
+static int parse_crash_elf_headers_newmem(void)
+{
+ unsigned char e_ident[EI_NIDENT];
+ int rc;
+
+ rc = arch_vmcore_get_elf_hdr(&elfcorebuf, &elfcorebuf_sz);
+ if (rc)
+ return rc;
+ memcpy(e_ident, elfcorebuf, EI_NIDENT);
+ if (memcmp(e_ident, ELFMAG, SELFMAG) != 0) {
+ pr_warn("Warning: Core image elf header not found\n");
+ rc = -EINVAL;
+ goto fail;
+ }
+ if (e_ident[EI_CLASS] == ELFCLASS64) {
+ rc = process_ptload_program_headers_elf64(elfcorebuf,
+ elfcorebuf_sz,
+ &vmcore_list);
+ if (rc)
+ goto fail;
+ set_vmcore_list_offsets_newmem(&vmcore_list);
+ vmcore_size = get_vmcore_size_elf64(elfcorebuf);
+ } else if (e_ident[EI_CLASS] == ELFCLASS32) {
+ rc = process_ptload_program_headers_elf32(elfcorebuf,
+ elfcorebuf_sz,
+ &vmcore_list);
+ if (rc)
+ goto fail;
+ set_vmcore_list_offsets_newmem(&vmcore_list);
+ vmcore_size = get_vmcore_size_elf32(elfcorebuf);
+ }
+ return 0;
+fail:
+ kfree(elfcorebuf);
+ return rc;
+}
+
/* Init function for vmcore module. */
static int __init vmcore_init(void)
{
@@ -680,7 +738,10 @@ static int __init vmcore_init(void)
/* If elfcorehdr= has been passed in cmdline, then capture the dump.*/
if (!(is_vmcore_usable()))
return rc;
- rc = parse_crash_elf_headers();
+ if (elfcorehdr_addr == ELFCORE_ADDR_NEWMEM)
+ rc = parse_crash_elf_headers_newmem();
+ else
+ rc = parse_crash_elf_headers_oldmem();
if (rc) {
pr_warn("Kdump: vmcore not initialized\n");
return rc;
diff --git a/include/linux/crash_dump.h b/include/linux/crash_dump.h
index 37e4f8d..9424d4fc 100644
--- a/include/linux/crash_dump.h
+++ b/include/linux/crash_dump.h
@@ -8,10 +8,12 @@
#define ELFCORE_ADDR_MAX (-1ULL)
#define ELFCORE_ADDR_ERR (-2ULL)
+#define ELFCORE_ADDR_NEWMEM (-3ULL)
extern unsigned long long elfcorehdr_addr;
extern unsigned long long elfcorehdr_size;
-
+extern int arch_vmcore_get_elf_hdr(char **elfcorebuf,
+ size_t *elfcorebuf_sz);
extern ssize_t copy_oldmem_page(unsigned long, char *, size_t,
unsigned long, int);
--
1.8.1.6
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/