* [PATCH 0/7] kdump: Xen fixes
@ 2012-09-10 11:57 Daniel Kiper
[not found] ` <1347278271-5211-1-git-send-email-daniel.kiper-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2012-09-14 3:30 ` [PATCH 0/7] kdump: Xen fixes Simon Horman
0 siblings, 2 replies; 11+ messages in thread
From: Daniel Kiper @ 2012-09-10 11:57 UTC (permalink / raw)
To: konrad.wilk-QHcLZuEGTsvQT0dZR+AlfA,
andrew.cooper3-Sxgqhf6Nn4DQT0dZR+AlfA,
olaf-QOLJcTWqO2uzQB+pC5nmwQ, jbeulich-IBi9RG/b67k,
ptesarik-AlSwsSmVLrQ, kexec-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
Hi,
Here I am sending Xen kdump fixes.
Daniel
Daniel Kiper (7):
kexec: Define some constants and structures conditionally
xen: Rename e820_to_kexec_type() to xen_e820_to_kexec_type() and export it
kexec: Move crash kernel area placement and size detection to is_crashkernel_mem_reserved()
kexec: Add segregate_lowmem_region()
kexec: Get backup area start address and size directly from mem_range
kexec: Move crash memory ranges logging
xen: Fix Xen kdump support
include/x86/x86-linux.h | 7 +-
kexec/arch/i386/crashdump-x86.c | 322 +++++++++++++++++++++++++++--------
kexec/arch/i386/kexec-x86-common.c | 6 +-
kexec/arch/i386/kexec-x86.h | 2 +
4 files changed, 259 insertions(+), 78 deletions(-)
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 1/7] kexec: Define some constants and structures conditionally
[not found] ` <1347278271-5211-1-git-send-email-daniel.kiper-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
@ 2012-09-10 11:57 ` Daniel Kiper
[not found] ` <1347278271-5211-2-git-send-email-daniel.kiper-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
0 siblings, 1 reply; 11+ messages in thread
From: Daniel Kiper @ 2012-09-10 11:57 UTC (permalink / raw)
To: konrad.wilk-QHcLZuEGTsvQT0dZR+AlfA,
andrew.cooper3-Sxgqhf6Nn4DQT0dZR+AlfA,
olaf-QOLJcTWqO2uzQB+pC5nmwQ, jbeulich-IBi9RG/b67k,
ptesarik-AlSwsSmVLrQ, kexec-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
Some definitions in include/x86/x86-linux.h conflicts
with definitions placed in Xen headers. Make them
conditional. This patch is required by future
Xen kdump fixes.
Signed-off-by: Daniel Kiper <daniel.kiper-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
---
include/x86/x86-linux.h | 7 ++++++-
1 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/include/x86/x86-linux.h b/include/x86/x86-linux.h
index 2ebcc3a..27af02b 100644
--- a/include/x86/x86-linux.h
+++ b/include/x86/x86-linux.h
@@ -4,13 +4,17 @@
#define TENATIVE 0 /* Code that is tenatively correct but hasn't yet been officially accepted */
#define E820MAP 0x2d0 /* our map */
-#define E820MAX 128 /* number of entries in E820MAP */
#define E820NR 0x1e8 /* # entries in E820MAP */
+#ifndef E820MAX
+#define E820MAX 128 /* number of entries in E820MAP */
+#endif
+
#ifndef ASSEMBLY
#define PACKED __attribute__((packed))
+#ifndef E820_RAM
struct e820entry {
uint64_t addr; /* start of memory segment */
uint64_t size; /* size of memory segment */
@@ -20,6 +24,7 @@ struct e820entry {
#define E820_ACPI 3 /* usable as RAM once ACPI tables have been read */
#define E820_NVS 4
} PACKED;
+#endif
/* FIXME expand on drive_info_)struct... */
struct drive_info_struct {
--
1.5.6.5
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 2/7] xen: Rename e820_to_kexec_type() to xen_e820_to_kexec_type() and export it
[not found] ` <1347278271-5211-2-git-send-email-daniel.kiper-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
@ 2012-09-10 11:57 ` Daniel Kiper
[not found] ` <1347278271-5211-3-git-send-email-daniel.kiper-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
0 siblings, 1 reply; 11+ messages in thread
From: Daniel Kiper @ 2012-09-10 11:57 UTC (permalink / raw)
To: konrad.wilk-QHcLZuEGTsvQT0dZR+AlfA,
andrew.cooper3-Sxgqhf6Nn4DQT0dZR+AlfA,
olaf-QOLJcTWqO2uzQB+pC5nmwQ, jbeulich-IBi9RG/b67k,
ptesarik-AlSwsSmVLrQ, kexec-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
Rename e820_to_kexec_type() to xen_e820_to_kexec_type() and export it.
Signed-off-by: Daniel Kiper <daniel.kiper-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
---
kexec/arch/i386/kexec-x86-common.c | 6 +++---
kexec/arch/i386/kexec-x86.h | 2 ++
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/kexec/arch/i386/kexec-x86-common.c b/kexec/arch/i386/kexec-x86-common.c
index 609d35d..02471a8 100644
--- a/kexec/arch/i386/kexec-x86-common.c
+++ b/kexec/arch/i386/kexec-x86-common.c
@@ -151,7 +151,7 @@ static int get_memory_ranges_sysfs(struct memory_range **range, int *ranges)
}
#ifdef HAVE_LIBXENCTRL
-static unsigned e820_to_kexec_type(uint32_t type)
+unsigned xen_e820_to_kexec_type(uint32_t type)
{
switch (type) {
case E820_RAM:
@@ -213,7 +213,7 @@ static int get_memory_ranges_xen(struct memory_range **range, int *ranges)
for (i = 0; i < rc; ++i) {
memory_range[i].start = e820entries[i].addr;
memory_range[i].end = e820entries[i].addr + e820entries[i].size;
- memory_range[i].type = e820_to_kexec_type(e820entries[i].type);
+ memory_range[i].type = xen_e820_to_kexec_type(e820entries[i].type);
}
qsort(memory_range, rc, sizeof(struct memory_range), compare_ranges);
@@ -289,7 +289,7 @@ static int get_memory_ranges_xen(struct memory_range **range, int *ranges)
for (i = 0; i < xen_memory_map->nr_entries; ++i) {
memory_range[i].start = e820entries[i].addr;
memory_range[i].end = e820entries[i].addr + e820entries[i].size;
- memory_range[i].type = e820_to_kexec_type(e820entries[i].type);
+ memory_range[i].type = xen_e820_to_kexec_type(e820entries[i].type);
}
qsort(memory_range, xen_memory_map->nr_entries, sizeof(struct memory_range), compare_ranges);
diff --git a/kexec/arch/i386/kexec-x86.h b/kexec/arch/i386/kexec-x86.h
index dfcc51d..5aa2a46 100644
--- a/kexec/arch/i386/kexec-x86.h
+++ b/kexec/arch/i386/kexec-x86.h
@@ -81,4 +81,6 @@ int nbi_probe(const char *buf, off_t len);
int nbi_load(int argc, char **argv, const char *buf, off_t len,
struct kexec_info *info);
void nbi_usage(void);
+
+extern unsigned xen_e820_to_kexec_type(uint32_t type);
#endif /* KEXEC_X86_H */
--
1.5.6.5
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 3/7] kexec: Move crash kernel area placement and size detection to is_crashkernel_mem_reserved()
[not found] ` <1347278271-5211-3-git-send-email-daniel.kiper-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
@ 2012-09-10 11:57 ` Daniel Kiper
[not found] ` <1347278271-5211-4-git-send-email-daniel.kiper-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
0 siblings, 1 reply; 11+ messages in thread
From: Daniel Kiper @ 2012-09-10 11:57 UTC (permalink / raw)
To: konrad.wilk-QHcLZuEGTsvQT0dZR+AlfA,
andrew.cooper3-Sxgqhf6Nn4DQT0dZR+AlfA,
olaf-QOLJcTWqO2uzQB+pC5nmwQ, jbeulich-IBi9RG/b67k,
ptesarik-AlSwsSmVLrQ, kexec-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
Move crash kernel area placement and size detection
from get_crash_memory_ranges() to is_crashkernel_mem_reserved().
Former one will not be used by fixed Xen kdump support.
Signed-off-by: Daniel Kiper <daniel.kiper-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
---
kexec/arch/i386/crashdump-x86.c | 17 ++++++++---------
1 files changed, 8 insertions(+), 9 deletions(-)
diff --git a/kexec/arch/i386/crashdump-x86.c b/kexec/arch/i386/crashdump-x86.c
index 2af090c..ec9432b 100644
--- a/kexec/arch/i386/crashdump-x86.c
+++ b/kexec/arch/i386/crashdump-x86.c
@@ -212,13 +212,6 @@ static int get_crash_memory_ranges(struct memory_range **range, int *ranges,
/* Only Dumping memory of type System RAM. */
if (memcmp(str, "System RAM\n", 11) == 0) {
type = RANGE_RAM;
- } else if (memcmp(str, "Crash kernel\n", 13) == 0) {
- /* Reserved memory region. New kernel can
- * use this region to boot into. */
- crash_reserved_mem.start = start;
- crash_reserved_mem.end = end;
- crash_reserved_mem.type = RANGE_RAM;
- continue;
} else if (memcmp(str, "ACPI Tables\n", 12) == 0) {
/*
* ACPI Tables area need to be passed to new
@@ -849,6 +842,12 @@ int is_crashkernel_mem_reserved(void)
{
uint64_t start, end;
- return parse_iomem_single("Crash kernel\n", &start, &end) == 0 ?
- (start != end) : 0;
+ if (parse_iomem_single("Crash kernel\n", &start, &end) || start == end)
+ return 0;
+
+ crash_reserved_mem.start = start;
+ crash_reserved_mem.end = end;
+ crash_reserved_mem.type = RANGE_RAM;
+
+ return 1;
}
--
1.5.6.5
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 4/7] kexec: Add segregate_lowmem_region()
[not found] ` <1347278271-5211-4-git-send-email-daniel.kiper-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
@ 2012-09-10 11:57 ` Daniel Kiper
[not found] ` <1347278271-5211-5-git-send-email-daniel.kiper-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
0 siblings, 1 reply; 11+ messages in thread
From: Daniel Kiper @ 2012-09-10 11:57 UTC (permalink / raw)
To: konrad.wilk-QHcLZuEGTsvQT0dZR+AlfA,
andrew.cooper3-Sxgqhf6Nn4DQT0dZR+AlfA,
olaf-QOLJcTWqO2uzQB+pC5nmwQ, jbeulich-IBi9RG/b67k,
ptesarik-AlSwsSmVLrQ, kexec-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
Extract code segregating lowmem region and move it to new
segregate_lowmem_region(). This function will be used by
fixed Xen kdump support, too.
Signed-off-by: Daniel Kiper <daniel.kiper-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
---
kexec/arch/i386/crashdump-x86.c | 38 +++++++++++++++++++++++++++-----------
1 files changed, 27 insertions(+), 11 deletions(-)
diff --git a/kexec/arch/i386/crashdump-x86.c b/kexec/arch/i386/crashdump-x86.c
index ec9432b..77a1329 100644
--- a/kexec/arch/i386/crashdump-x86.c
+++ b/kexec/arch/i386/crashdump-x86.c
@@ -159,6 +159,7 @@ static int get_kernel_vaddr_and_size(struct kexec_info *UNUSED(info),
}
/* Forward Declaration. */
+static void segregate_lowmem_region(int *nr_ranges, unsigned long lowmem_limit);
static int exclude_region(int *nr_ranges, uint64_t start, uint64_t end);
/* Stores a sorted list of RAM memory ranges for which to create elf headers.
@@ -235,19 +236,10 @@ static int get_crash_memory_ranges(struct memory_range **range, int *ranges,
crash_memory_range[memory_ranges].start = start;
crash_memory_range[memory_ranges].end = end;
crash_memory_range[memory_ranges].type = type;
- memory_ranges++;
- /* Segregate linearly mapped region. */
- if (lowmem_limit &&
- (lowmem_limit - 1) >= start && (lowmem_limit - 1) <= end) {
- crash_memory_range[memory_ranges-1].end = lowmem_limit -1;
+ segregate_lowmem_region(&memory_ranges, lowmem_limit);
- /* Add segregated region. */
- crash_memory_range[memory_ranges].start = lowmem_limit;
- crash_memory_range[memory_ranges].end = end;
- crash_memory_range[memory_ranges].type = type;
- memory_ranges++;
- }
+ memory_ranges++;
}
fclose(fp);
if (kexec_flags & KEXEC_PRESERVE_CONTEXT) {
@@ -289,6 +281,30 @@ static int get_crash_memory_ranges(struct memory_range **range, int *ranges,
return 0;
}
+static void segregate_lowmem_region(int *nr_ranges, unsigned long lowmem_limit)
+{
+ unsigned long long end, start;
+ unsigned type;
+
+ start = crash_memory_range[*nr_ranges].start;
+ end = crash_memory_range[*nr_ranges].end;
+ type = crash_memory_range[*nr_ranges].type;
+
+ if (!(lowmem_limit && lowmem_limit > start && lowmem_limit < end))
+ return;
+
+ crash_memory_range[*nr_ranges].end = lowmem_limit - 1;
+
+ if (*nr_ranges >= CRASH_MAX_MEMORY_RANGES - 1)
+ return;
+
+ ++*nr_ranges;
+
+ crash_memory_range[*nr_ranges].start = lowmem_limit;
+ crash_memory_range[*nr_ranges].end = end;
+ crash_memory_range[*nr_ranges].type = type;
+}
+
/* Removes crash reserve region from list of memory chunks for whom elf program
* headers have to be created. Assuming crash reserve region to be a single
* continuous area fully contained inside one of the memory chunks */
--
1.5.6.5
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 5/7] kexec: Get backup area start address and size directly from mem_range
[not found] ` <1347278271-5211-5-git-send-email-daniel.kiper-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
@ 2012-09-10 11:57 ` Daniel Kiper
[not found] ` <1347278271-5211-6-git-send-email-daniel.kiper-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
0 siblings, 1 reply; 11+ messages in thread
From: Daniel Kiper @ 2012-09-10 11:57 UTC (permalink / raw)
To: konrad.wilk-QHcLZuEGTsvQT0dZR+AlfA,
andrew.cooper3-Sxgqhf6Nn4DQT0dZR+AlfA,
olaf-QOLJcTWqO2uzQB+pC5nmwQ, jbeulich-IBi9RG/b67k,
ptesarik-AlSwsSmVLrQ, kexec-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
Get backup area start address and size directly from mem_range.
Under Xen /proc/iomem contains invalid values.
Signed-off-by: Daniel Kiper <daniel.kiper-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
---
kexec/arch/i386/crashdump-x86.c | 55 +++++++++++++-------------------------
1 files changed, 19 insertions(+), 36 deletions(-)
diff --git a/kexec/arch/i386/crashdump-x86.c b/kexec/arch/i386/crashdump-x86.c
index 77a1329..56ef59e 100644
--- a/kexec/arch/i386/crashdump-x86.c
+++ b/kexec/arch/i386/crashdump-x86.c
@@ -667,44 +667,28 @@ static int cmdline_add_memmap_acpi(char *cmdline, unsigned long start,
return 0;
}
-static void get_backup_area(unsigned long *start, unsigned long *end)
+static void get_backup_area(struct kexec_info *info,
+ struct memory_range *range, int ranges)
{
- const char *iomem = proc_iomem();
- char line[MAX_LINE];
- FILE *fp;
+ int i;
- fp = fopen(iomem, "r");
- if (!fp) {
- fprintf(stderr, "Cannot open %s: %s\n",
- iomem, strerror(errno));
- return;
- }
+ /* Look for first 640 KiB RAM region. */
+ for (i = 0; i < ranges; ++i) {
+ if (range[i].type != RANGE_RAM || range[i].end > 0xa0000)
+ continue;
- while(fgets(line, sizeof(line), fp) != 0) {
- char *str;
- int count, consumed;
- unsigned long mstart, mend;
+ info->backup_src_start = range[i].start;
+ info->backup_src_size = range[i].end - range[i].start + 1;
- count = sscanf(line, "%lx-%lx : %n",
- &mstart, &mend, &consumed);
- if (count != 2)
- continue;
- str = line + consumed;
- dbgprintf("%016lx-%016lx : %s",
- mstart, mend, str);
-
- /* Hopefully there is only one RAM region in the first 640K */
- if (memcmp(str, "System RAM\n", 11) == 0 && mend <= 0xa0000 ) {
- dbgprintf("%s: %016lx-%016lx : %s", __func__, mstart, mend, str);
- *start = mstart;
- *end = mend;
- fclose(fp);
- return;
- }
+ dbgprintf("%s: %016llx-%016llx : System RAM\n", __func__,
+ range[i].start, range[i].end);
+
+ return;
}
- *start = BACKUP_SRC_START;
- *end = BACKUP_SRC_END;
- fclose(fp);
+
+ /* First 640 KiB RAM region not found. Assume defaults. */
+ info->backup_src_start = BACKUP_SRC_START;
+ info->backup_src_size = BACKUP_SRC_END - BACKUP_SRC_START + 1;
}
/* Loads additional segments in case of a panic kernel is being loaded.
@@ -720,15 +704,12 @@ int load_crashdump_segments(struct kexec_info *info, char* mod_cmdline,
struct memory_range *mem_range, *memmap_p;
struct crash_elf_info elf_info;
unsigned kexec_arch;
- unsigned long tmp_backup_end = 0;
memset(&elf_info, 0x0, sizeof(elf_info));
/* Constant parts of the elf_info */
memset(&elf_info, 0, sizeof(elf_info));
elf_info.data = ELFDATA2LSB;
- get_backup_area(&info->backup_src_start, &tmp_backup_end);
- info->backup_src_size = tmp_backup_end - info->backup_src_start + 1;
/* Get the architecture of the running kernel */
kexec_arch = info->kexec_flags & KEXEC_ARCH_MASK;
@@ -756,6 +737,8 @@ int load_crashdump_segments(struct kexec_info *info, char* mod_cmdline,
elf_info.lowmem_limit) < 0)
return -1;
+ get_backup_area(info, mem_range, nr_ranges);
+
/*
* if the core type has not been set on command line, set it here
* automatically
--
1.5.6.5
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 6/7] kexec: Move crash memory ranges logging
[not found] ` <1347278271-5211-6-git-send-email-daniel.kiper-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
@ 2012-09-10 11:57 ` Daniel Kiper
[not found] ` <1347278271-5211-7-git-send-email-daniel.kiper-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
0 siblings, 1 reply; 11+ messages in thread
From: Daniel Kiper @ 2012-09-10 11:57 UTC (permalink / raw)
To: konrad.wilk-QHcLZuEGTsvQT0dZR+AlfA,
andrew.cooper3-Sxgqhf6Nn4DQT0dZR+AlfA,
olaf-QOLJcTWqO2uzQB+pC5nmwQ, jbeulich-IBi9RG/b67k,
ptesarik-AlSwsSmVLrQ, kexec-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
Move crash memory ranges logging from get_crash_memory_ranges()
to load_crashdump_segments(). This solution will be used by
fixed Xen kdump support, too.
Signed-off-by: Daniel Kiper <daniel.kiper-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
---
kexec/arch/i386/crashdump-x86.c | 13 +++++--------
1 files changed, 5 insertions(+), 8 deletions(-)
diff --git a/kexec/arch/i386/crashdump-x86.c b/kexec/arch/i386/crashdump-x86.c
index 56ef59e..c6b9354 100644
--- a/kexec/arch/i386/crashdump-x86.c
+++ b/kexec/arch/i386/crashdump-x86.c
@@ -270,14 +270,6 @@ static int get_crash_memory_ranges(struct memory_range **range, int *ranges,
*range = crash_memory_range;
*ranges = memory_ranges;
- int i;
- dbgprintf("CRASH MEMORY RANGES\n");
- for(i = 0; i < memory_ranges; i++) {
- start = crash_memory_range[i].start;
- end = crash_memory_range[i].end;
- dbgprintf("%016Lx-%016Lx\n", start, end);
- }
-
return 0;
}
@@ -739,6 +731,11 @@ int load_crashdump_segments(struct kexec_info *info, char* mod_cmdline,
get_backup_area(info, mem_range, nr_ranges);
+ dbgprintf("CRASH MEMORY RANGES\n");
+
+ for(i = 0; i < nr_ranges; ++i)
+ dbgprintf("%016Lx-%016Lx\n", mem_range[i].start, mem_range[i].end);
+
/*
* if the core type has not been set on command line, set it here
* automatically
--
1.5.6.5
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 7/7] xen: Fix Xen kdump support
[not found] ` <1347278271-5211-7-git-send-email-daniel.kiper-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
@ 2012-09-10 11:57 ` Daniel Kiper
0 siblings, 0 replies; 11+ messages in thread
From: Daniel Kiper @ 2012-09-10 11:57 UTC (permalink / raw)
To: konrad.wilk-QHcLZuEGTsvQT0dZR+AlfA,
andrew.cooper3-Sxgqhf6Nn4DQT0dZR+AlfA,
olaf-QOLJcTWqO2uzQB+pC5nmwQ, jbeulich-IBi9RG/b67k,
ptesarik-AlSwsSmVLrQ, kexec-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR
get_crash_memory_ranges() is unreliable under Xen. Proper machine
memory map could be obtained under Xen by calling __HYPERVISOR_memory_op
hypercall with XENMEM_machine_memory_map argument. get_crash_memory_ranges_xen()
does that. It is implemented using ioctl() or libxenctrl interface.
This solution is compatible with 3.x and 4.x Xen versions.
Signed-off-by: Daniel Kiper <daniel.kiper-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
---
kexec/arch/i386/crashdump-x86.c | 203 ++++++++++++++++++++++++++++++++++++---
1 files changed, 191 insertions(+), 12 deletions(-)
diff --git a/kexec/arch/i386/crashdump-x86.c b/kexec/arch/i386/crashdump-x86.c
index c6b9354..09c3fd4 100644
--- a/kexec/arch/i386/crashdump-x86.c
+++ b/kexec/arch/i386/crashdump-x86.c
@@ -18,21 +18,41 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+
+#define _XOPEN_SOURCE 600
+#define _BSD_SOURCE
+
+#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <limits.h>
#include <elf.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "../../kexec.h"
#include "../../kexec-elf.h"
#include "../../kexec-syscall.h"
+#include "../../firmware_memmap.h"
#include "../../crashdump.h"
#include "kexec-x86.h"
#include "crashdump-x86.h"
+
+#ifdef HAVE_LIBXENCTRL
+#ifdef HAVE_XC_GET_MACHINE_MEMORY_MAP
+#include <xenctrl.h>
+#else
+#define __XEN_TOOLS__ 1
+#include <xen/xen.h>
+#include <xen/memory.h>
+#include <xen/sys/privcmd.h>
+#endif /* HAVE_XC_GET_MACHINE_MEMORY_MAP */
+#endif /* HAVE_LIBXENCTRL */
+
#include <x86/x86-linux.h>
extern struct arch_options_t arch_options;
@@ -273,6 +293,162 @@ static int get_crash_memory_ranges(struct memory_range **range, int *ranges,
return 0;
}
+#ifdef HAVE_LIBXENCTRL
+#ifdef HAVE_XC_GET_MACHINE_MEMORY_MAP
+static int get_crash_memory_ranges_xen(struct memory_range **range,
+ int *ranges, unsigned long lowmem_limit)
+{
+ int j, rc, ret = -1;
+ struct e820entry e820entries[CRASH_MAX_MEMORY_RANGES];
+ unsigned int i;
+#ifdef XENCTRL_HAS_XC_INTERFACE
+ xc_interface *xc;
+#else
+ int xc;
+#endif
+
+#ifdef XENCTRL_HAS_XC_INTERFACE
+ xc = xc_interface_open(NULL, NULL, 0);
+
+ if (!xc) {
+ fprintf(stderr, "%s: Failed to open Xen control interface\n", __func__);
+ goto err;
+ }
+#else
+ xc = xc_interface_open();
+
+ if (xc == -1) {
+ fprintf(stderr, "%s: Failed to open Xen control interface\n", __func__);
+ goto err;
+ }
+#endif
+
+ rc = xc_get_machine_memory_map(xc, e820entries, CRASH_MAX_MEMORY_RANGES);
+
+ if (rc < 0) {
+ fprintf(stderr, "%s: xc_get_machine_memory_map: %s\n", __func__, strerror(-rc));
+ goto err;
+ }
+
+ for (i = 0, j = 0; i < rc && j < CRASH_MAX_MEMORY_RANGES; ++i, ++j) {
+ crash_memory_range[j].start = e820entries[i].addr;
+ crash_memory_range[j].end = e820entries[i].addr + e820entries[i].size - 1;
+ crash_memory_range[j].type = xen_e820_to_kexec_type(e820entries[i].type);
+ segregate_lowmem_region(&j, lowmem_limit);
+ }
+
+ *range = crash_memory_range;
+ *ranges = j;
+
+ qsort(*range, *ranges, sizeof(struct memory_range), compare_ranges);
+
+ if (exclude_region(ranges, crash_reserved_mem.start,
+ crash_reserved_mem.end) < 0)
+ goto err;
+
+ ret = 0;
+
+err:
+ xc_interface_close(xc);
+
+ return ret;
+}
+#else
+static int get_crash_memory_ranges_xen(struct memory_range **range,
+ int *ranges, unsigned long lowmem_limit)
+{
+ int fd, j, rc, ret = -1;
+ privcmd_hypercall_t hypercall;
+ struct e820entry *e820entries = NULL;
+ struct xen_memory_map *xen_memory_map = NULL;
+ unsigned int i;
+
+ fd = open("/proc/xen/privcmd", O_RDWR);
+
+ if (fd == -1) {
+ fprintf(stderr, "%s: open(/proc/xen/privcmd): %m\n", __func__);
+ goto err;
+ }
+
+ rc = posix_memalign((void **)&e820entries, getpagesize(),
+ sizeof(struct e820entry) * CRASH_MAX_MEMORY_RANGES);
+
+ if (rc) {
+ fprintf(stderr, "%s: posix_memalign(e820entries): %s\n", __func__, strerror(rc));
+ e820entries = NULL;
+ goto err;
+ }
+
+ rc = posix_memalign((void **)&xen_memory_map, getpagesize(),
+ sizeof(struct xen_memory_map));
+
+ if (rc) {
+ fprintf(stderr, "%s: posix_memalign(xen_memory_map): %s\n", __func__, strerror(rc));
+ xen_memory_map = NULL;
+ goto err;
+ }
+
+ if (mlock(e820entries, sizeof(struct e820entry) * CRASH_MAX_MEMORY_RANGES) == -1) {
+ fprintf(stderr, "%s: mlock(e820entries): %m\n", __func__);
+ goto err;
+ }
+
+ if (mlock(xen_memory_map, sizeof(struct xen_memory_map)) == -1) {
+ fprintf(stderr, "%s: mlock(xen_memory_map): %m\n", __func__);
+ goto err;
+ }
+
+ xen_memory_map->nr_entries = CRASH_MAX_MEMORY_RANGES;
+ set_xen_guest_handle(xen_memory_map->buffer, e820entries);
+
+ hypercall.op = __HYPERVISOR_memory_op;
+ hypercall.arg[0] = XENMEM_machine_memory_map;
+ hypercall.arg[1] = (__u64)xen_memory_map;
+
+ rc = ioctl(fd, IOCTL_PRIVCMD_HYPERCALL, &hypercall);
+
+ if (rc == -1) {
+ fprintf(stderr, "%s: ioctl(IOCTL_PRIVCMD_HYPERCALL): %m\n", __func__);
+ goto err;
+ }
+
+ for (i = 0, j = 0; i < xen_memory_map->nr_entries &&
+ j < CRASH_MAX_MEMORY_RANGES; ++i, ++j) {
+ crash_memory_range[j].start = e820entries[i].addr;
+ crash_memory_range[j].end = e820entries[i].addr + e820entries[i].size - 1;
+ crash_memory_range[j].type = xen_e820_to_kexec_type(e820entries[i].type);
+ segregate_lowmem_region(&j, lowmem_limit);
+ }
+
+ *range = crash_memory_range;
+ *ranges = j;
+
+ qsort(*range, *ranges, sizeof(struct memory_range), compare_ranges);
+
+ if (exclude_region(ranges, crash_reserved_mem.start,
+ crash_reserved_mem.end) < 0)
+ goto err;
+
+ ret = 0;
+
+err:
+ munlock(xen_memory_map, sizeof(struct xen_memory_map));
+ munlock(e820entries, sizeof(struct e820entry) * CRASH_MAX_MEMORY_RANGES);
+ free(xen_memory_map);
+ free(e820entries);
+ close(fd);
+
+ return ret;
+}
+#endif /* HAVE_XC_GET_MACHINE_MEMORY_MAP */
+#else
+static int get_crash_memory_ranges_xen(struct memory_range **range,
+ int *ranges, unsigned long lowmem_limit)
+{
+ return 0;
+}
+#endif /* HAVE_LIBXENCTRL */
+
static void segregate_lowmem_region(int *nr_ranges, unsigned long lowmem_limit)
{
unsigned long long end, start;
@@ -724,10 +900,15 @@ int load_crashdump_segments(struct kexec_info *info, char* mod_cmdline,
return -1;
}
- if (get_crash_memory_ranges(&mem_range, &nr_ranges,
- info->kexec_flags,
- elf_info.lowmem_limit) < 0)
- return -1;
+ if (xen_present()) {
+ if (get_crash_memory_ranges_xen(&mem_range, &nr_ranges,
+ elf_info.lowmem_limit) < 0)
+ return -1;
+ } else
+ if (get_crash_memory_ranges(&mem_range, &nr_ranges,
+ info->kexec_flags,
+ elf_info.lowmem_limit) < 0)
+ return -1;
get_backup_area(info, mem_range, nr_ranges);
@@ -784,17 +965,15 @@ int load_crashdump_segments(struct kexec_info *info, char* mod_cmdline,
/* Create elf header segment and store crash image data. */
if (arch_options.core_header_type == CORE_TYPE_ELF64) {
- if (crash_create_elf64_headers(info, &elf_info,
- crash_memory_range, nr_ranges,
- &tmp, &bufsz,
- ELF_CORE_HEADER_ALIGN) < 0)
+ if (crash_create_elf64_headers(info, &elf_info, mem_range,
+ nr_ranges, &tmp, &bufsz,
+ ELF_CORE_HEADER_ALIGN) < 0)
return EFAILED;
}
else {
- if (crash_create_elf32_headers(info, &elf_info,
- crash_memory_range, nr_ranges,
- &tmp, &bufsz,
- ELF_CORE_HEADER_ALIGN) < 0)
+ if (crash_create_elf32_headers(info, &elf_info, mem_range,
+ nr_ranges, &tmp, &bufsz,
+ ELF_CORE_HEADER_ALIGN) < 0)
return EFAILED;
}
/* the size of the elf headers allocated is returned in 'bufsz' */
--
1.5.6.5
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 0/7] kdump: Xen fixes
2012-09-10 11:57 [PATCH 0/7] kdump: Xen fixes Daniel Kiper
[not found] ` <1347278271-5211-1-git-send-email-daniel.kiper-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
@ 2012-09-14 3:30 ` Simon Horman
1 sibling, 0 replies; 11+ messages in thread
From: Simon Horman @ 2012-09-14 3:30 UTC (permalink / raw)
To: Daniel Kiper
Cc: olaf, xen-devel, konrad.wilk, andrew.cooper3, ptesarik, jbeulich,
kexec
On Mon, Sep 10, 2012 at 01:57:44PM +0200, Daniel Kiper wrote:
> Hi,
>
> Here I am sending Xen kdump fixes.
Hi Daniel,
do these relate to the changes that you were discussing
with Petr Tesarik in July?
> Daniel Kiper (7):
> kexec: Define some constants and structures conditionally
> xen: Rename e820_to_kexec_type() to xen_e820_to_kexec_type() and export it
> kexec: Move crash kernel area placement and size detection to is_crashkernel_mem_reserved()
> kexec: Add segregate_lowmem_region()
> kexec: Get backup area start address and size directly from mem_range
> kexec: Move crash memory ranges logging
> xen: Fix Xen kdump support
>
> include/x86/x86-linux.h | 7 +-
> kexec/arch/i386/crashdump-x86.c | 322 +++++++++++++++++++++++++++--------
> kexec/arch/i386/kexec-x86-common.c | 6 +-
> kexec/arch/i386/kexec-x86.h | 2 +
> 4 files changed, 259 insertions(+), 78 deletions(-)
>
> _______________________________________________
> kexec mailing list
> kexec@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/kexec
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 0/7] kdump: Xen fixes
@ 2012-09-14 13:01 Daniel Kiper
2012-09-18 1:15 ` Simon Horman
0 siblings, 1 reply; 11+ messages in thread
From: Daniel Kiper @ 2012-09-14 13:01 UTC (permalink / raw)
To: horms
Cc: olaf, xen-devel, konrad.wilk, andrew.cooper3, kexec, ptesarik,
jbeulich
Hi Simon,
> do these relate to the changes that you were discussing
> with Petr Tesarik in July?
No. They are independent of vmcoreinfo patch.
Daniel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 0/7] kdump: Xen fixes
2012-09-14 13:01 Daniel Kiper
@ 2012-09-18 1:15 ` Simon Horman
0 siblings, 0 replies; 11+ messages in thread
From: Simon Horman @ 2012-09-18 1:15 UTC (permalink / raw)
To: Daniel Kiper
Cc: olaf-QOLJcTWqO2uzQB+pC5nmwQ,
xen-devel-GuqFBffKawuULHF6PoxzQEEOCMrvLtNR,
konrad.wilk-QHcLZuEGTsvQT0dZR+AlfA,
andrew.cooper3-Sxgqhf6Nn4DQT0dZR+AlfA,
kexec-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, ptesarik-AlSwsSmVLrQ,
jbeulich-IBi9RG/b67k
On Fri, Sep 14, 2012 at 06:01:53AM -0700, Daniel Kiper wrote:
> Hi Simon,
>
> > do these relate to the changes that you were discussing
> > with Petr Tesarik in July?
>
> No. They are independent of vmcoreinfo patch.
Thanks, all applied to the kexec-tools tree on kernel.org.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2012-09-18 1:15 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-10 11:57 [PATCH 0/7] kdump: Xen fixes Daniel Kiper
[not found] ` <1347278271-5211-1-git-send-email-daniel.kiper-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2012-09-10 11:57 ` [PATCH 1/7] kexec: Define some constants and structures conditionally Daniel Kiper
[not found] ` <1347278271-5211-2-git-send-email-daniel.kiper-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2012-09-10 11:57 ` [PATCH 2/7] xen: Rename e820_to_kexec_type() to xen_e820_to_kexec_type() and export it Daniel Kiper
[not found] ` <1347278271-5211-3-git-send-email-daniel.kiper-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2012-09-10 11:57 ` [PATCH 3/7] kexec: Move crash kernel area placement and size detection to is_crashkernel_mem_reserved() Daniel Kiper
[not found] ` <1347278271-5211-4-git-send-email-daniel.kiper-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2012-09-10 11:57 ` [PATCH 4/7] kexec: Add segregate_lowmem_region() Daniel Kiper
[not found] ` <1347278271-5211-5-git-send-email-daniel.kiper-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2012-09-10 11:57 ` [PATCH 5/7] kexec: Get backup area start address and size directly from mem_range Daniel Kiper
[not found] ` <1347278271-5211-6-git-send-email-daniel.kiper-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2012-09-10 11:57 ` [PATCH 6/7] kexec: Move crash memory ranges logging Daniel Kiper
[not found] ` <1347278271-5211-7-git-send-email-daniel.kiper-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2012-09-10 11:57 ` [PATCH 7/7] xen: Fix Xen kdump support Daniel Kiper
2012-09-14 3:30 ` [PATCH 0/7] kdump: Xen fixes Simon Horman
-- strict thread matches above, loose matches on Subject: below --
2012-09-14 13:01 Daniel Kiper
2012-09-18 1:15 ` Simon Horman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).