diff options
-rw-r--r-- | kexec/Makefile | 1 | ||||
-rw-r--r-- | kexec/crashdump-elf.c | 13 | ||||
-rw-r--r-- | kexec/crashdump-xen.c | 80 | ||||
-rw-r--r-- | kexec/crashdump.h | 4 |
4 files changed, 95 insertions, 3 deletions
diff --git a/kexec/Makefile b/kexec/Makefile index 4ff1bdf..6ad9461 100644 --- a/kexec/Makefile +++ b/kexec/Makefile @@ -18,6 +18,7 @@ KEXEC_C_SRCS+= kexec/kexec-elf-rel.c KEXEC_C_SRCS+= kexec/kexec-elf-boot.c KEXEC_C_SRCS+= kexec/kexec-iomem.c KEXEC_C_SRCS+= kexec/crashdump.c +KEXEC_C_SRCS+= kexec/crashdump-xen.c KEXEC_C_GENERATED_SRCS+= $(PURGATORY_HEX_C) KEXEC_S_SRCS:= KEXEC_S_GENERATED_SRCS:= diff --git a/kexec/crashdump-elf.c b/kexec/crashdump-elf.c index 9e3121f..4c55baf 100644 --- a/kexec/crashdump-elf.c +++ b/kexec/crashdump-elf.c @@ -18,7 +18,11 @@ int FUNC(struct kexec_info *info, uint64_t notes_addr, notes_len; int (*get_note_info)(int cpu, uint64_t *addr, uint64_t *len); - nr_cpus = sysconf(_SC_NPROCESSORS_CONF); + if (xen_present()) + nr_cpus = xen_get_nr_phys_cpus(); + else + nr_cpus = sysconf(_SC_NPROCESSORS_CONF); + if (nr_cpus < 0) { return -1; } @@ -45,7 +49,7 @@ int FUNC(struct kexec_info *info, * PT_LOAD program header and in the physical RAM program headers. */ - if (info->kern_size) { + if (info->kern_size && !xen_present()) { sz += sizeof(PHDR); } @@ -87,6 +91,9 @@ int FUNC(struct kexec_info *info, if (!get_note_info) get_note_info = get_crash_notes_per_cpu; + if (xen_present()) + get_note_info = xen_get_note; + /* PT_NOTE program headers. One per cpu */ for (i = 0; i < nr_cpus; i++) { @@ -118,7 +125,7 @@ int FUNC(struct kexec_info *info, * Kernel is mapped if info->kern_size is non-zero. */ - if (info->kern_size) { + if (info->kern_size && !xen_present()) { phdr = (PHDR *) bufp; bufp += sizeof(PHDR); phdr->p_type = PT_LOAD; diff --git a/kexec/crashdump-xen.c b/kexec/crashdump-xen.c new file mode 100644 index 0000000..aa096e6 --- /dev/null +++ b/kexec/crashdump-xen.c @@ -0,0 +1,80 @@ +#define _GNU_SOURCE +#include <stdio.h> +#include <stdarg.h> +#include <string.h> +#include <stdlib.h> +#include <errno.h> +#include <limits.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <fcntl.h> +#include "kexec.h" +#include "crashdump.h" + +struct crash_note_info { + unsigned long base; + unsigned long length; +}; + +int xen_phys_cpus = 0; +struct crash_note_info *xen_phys_notes; + +int xen_present(void) +{ + struct stat buf; + + return stat("/proc/xen", &buf) == 0; +} + +static int xen_crash_note_callback(void *data, int nr, + char *str, + unsigned long base, + unsigned long length) +{ + struct crash_note_info *note = xen_phys_notes + nr; + + note->base = base; + note->length = length; + + return 0; +} + +int xen_get_nr_phys_cpus(void) +{ + char *match = "Crash note\n"; + int cpus, n; + + if (xen_phys_cpus) + return xen_phys_cpus; + + if ((cpus = kexec_iomem_for_each_line(match, NULL, NULL))) { + n = sizeof(struct crash_note_info) * cpus; + xen_phys_notes = malloc(n); + if (xen_phys_notes) { + memset(xen_phys_notes, 0, n); + kexec_iomem_for_each_line(match, + xen_crash_note_callback, + NULL); + } + + xen_phys_cpus = cpus; + } + + return cpus; +} + +int xen_get_note(int cpu, uint64_t *addr, uint64_t *len) +{ + struct crash_note_info *note; + + if (xen_phys_cpus <= 0) + return -1; + + note = xen_phys_notes + cpu; + + *addr = note->base; + *len = note->length; + + return 0; +} diff --git a/kexec/crashdump.h b/kexec/crashdump.h index 4dbecf8..10cffe0 100644 --- a/kexec/crashdump.h +++ b/kexec/crashdump.h @@ -34,4 +34,8 @@ int crash_create_elf64_headers(struct kexec_info *info, struct memory_range *range, int ranges, void **buf, unsigned long *size); +int xen_present(void); +int xen_get_nr_phys_cpus(void); +int xen_get_note(int cpu, uint64_t *addr, uint64_t *len); + #endif /* CRASHDUMP_H */ |