diff --git a/kexec/crashdump-elf.c b/kexec/crashdump-elf.c index c048f75..e77b9db 100644 --- a/kexec/crashdump-elf.c +++ b/kexec/crashdump-elf.c @@ -34,6 +34,8 @@ int FUNC(struct kexec_info *info, char *bufp; long int nr_cpus = 0; uint64_t notes_addr, notes_len; + uint64_t mkdfinfo_addr, mkdfinfo_len; + int has_mkdfinfo = 0; int (*get_note_info)(int cpu, uint64_t *addr, uint64_t *len); if (xen_present()) @@ -45,7 +47,11 @@ int FUNC(struct kexec_info *info, return -1; } - sz = sizeof(EHDR) + nr_cpus * sizeof(PHDR) + ranges * sizeof(PHDR); + if (get_kernel_mkdfinfo( &mkdfinfo_addr, &mkdfinfo_len) == 0) { + has_mkdfinfo = 1; + } + + sz = sizeof(EHDR) + (nr_cpus + has_mkdfinfo) * sizeof(PHDR) + ranges * sizeof(PHDR); /* * Certain architectures such as x86_64 and ia64 require a separate @@ -146,6 +152,21 @@ int FUNC(struct kexec_info *info, dbgprintf_phdr("Elf header", phdr); } + if (has_mkdfinfo) { + phdr = (PHDR *) bufp; + bufp += sizeof(PHDR); + phdr->p_type = PT_NOTE; + phdr->p_flags = 0; + phdr->p_offset = phdr->p_paddr = mkdfinfo_addr; + phdr->p_vaddr = 0; + phdr->p_filesz = phdr->p_memsz = mkdfinfo_len; + /* Do we need any alignment of segments? */ + phdr->p_align = 0; + + (elf->e_phnum)++; + dbgprintf_phdr("mkde header", phdr); + } + /* Setup an PT_LOAD type program header for the region where * Kernel is mapped if info->kern_size is non-zero. */ diff --git a/kexec/crashdump.c b/kexec/crashdump.c index 1c08606..7a46efa 100644 --- a/kexec/crashdump.c +++ b/kexec/crashdump.c @@ -108,3 +108,35 @@ int get_crash_notes_per_cpu(int cpu, uint64_t *addr, uint64_t *len) return 0; } + +/* Returns the physical address of start of crash notes buffer for a kernel. */ +int get_kernel_mkdfinfo(uint64_t *addr, uint64_t *len) +{ + char kdump_info[PATH_MAX]; + char line[MAX_LINE]; + int count; + FILE *fp; + unsigned long long temp, temp2; + + *addr = 0; + *len = 0; + + sprintf(kdump_info, "/sys/kernel/mkdfinfo"); + fp = fopen(kdump_info, "r"); + if (!fp) { + die("Could not open \"%s\": %s\n", kdump_info, + strerror(errno)); + return -1; + } + + if (!fgets(line, sizeof(line), fp)) + die("Cannot parse %s: %s\n", kdump_info, strerror(errno)); + count = sscanf(line, "%Lx %Lx", &temp, &temp2); + if (count != 2) + die("Cannot parse %s: %s\n", kdump_info, strerror(errno)); + + *addr = (uint64_t) temp; + *len = (uint64_t) temp2; + + return 0; +} diff --git a/kexec/crashdump.h b/kexec/crashdump.h index e99bdd2..9d31169 100644 --- a/kexec/crashdump.h +++ b/kexec/crashdump.h @@ -2,6 +2,7 @@ #define CRASHDUMP_H extern int get_crash_notes_per_cpu(int cpu, uint64_t *addr, uint64_t *len); +extern int get_kernel_mkdfinfo(uint64_t *addr, uint64_t *len); /* Need to find a better way to determine per cpu notes section size. */ #define MAX_NOTE_BYTES 1024