kdump: Xen fixes
Subsystems (2)
cover kdump: Xen fixes
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(-)
PATCH 1/7 kexec: Define some constants and structures conditionally
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.
--- include/x86/x86-linux.h | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
include/x86/x86-linux.h +6 -1
@@ -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 {
Signature · 1 line
1.5.6.5
PATCH 2/7 xen: Rename e820_to_kexec_type() to xen_e820_to_kexec_type() and export it
Rename e820_to_kexec_type() to xen_e820_to_kexec_type() and export it.
--- kexec/arch/i386/kexec-x86-common.c | 6 +++--- kexec/arch/i386/kexec-x86.h | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-)
kexec/arch/i386/kexec-x86-common.c +3 -3
@@ -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);
kexec/arch/i386/kexec-x86.h +2 -0
@@ -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 */
Signature · 1 line
1.5.6.5
PATCH 3/7 kexec: Move crash kernel area placement and size detection to is_crashkernel_mem_reserved()
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.
--- kexec/arch/i386/crashdump-x86.c | 17 ++++++++--------- 1 files changed, 8 insertions(+), 9 deletions(-)
kexec/arch/i386/crashdump-x86.c +8 -9
@@ -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 ; }
Signature · 1 line
1.5.6.5
PATCH 4/7 kexec: Add segregate_lowmem_region()
Extract code segregating lowmem region and move it to new segregate_lowmem_region(). This function will be used by fixed Xen kdump support, too.
--- kexec/arch/i386/crashdump-x86.c | 38 +++++++++++++++++++++++++++----------- 1 files changed, 27 insertions(+), 11 deletions(-)
kexec/arch/i386/crashdump-x86.c +27 -11
@@ -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 */
Signature · 1 line
1.5.6.5
PATCH 5/7 kexec: Get backup area start address and size directly from mem_range
Get backup area start address and size directly from mem_range. Under Xen /proc/iomem contains invalid values.
--- kexec/arch/i386/crashdump-x86.c | 55 +++++++++++++------------------------- 1 files changed, 19 insertions(+), 36 deletions(-)
kexec/arch/i386/crashdump-x86.c +19 -36
@@ -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
Signature · 1 line
1.5.6.5
PATCH 6/7 kexec: Move crash memory ranges logging
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.
--- kexec/arch/i386/crashdump-x86.c | 13 +++++-------- 1 files changed, 5 insertions(+), 8 deletions(-)
kexec/arch/i386/crashdump-x86.c +5 -8
@@ -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
Signature · 1 line
1.5.6.5
PATCH 7/7 xen: Fix Xen kdump support
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.
--- kexec/arch/i386/crashdump-x86.c | 203 ++++++++++++++++++++++++++++++++++++--- 1 files changed, 191 insertions(+), 12 deletions(-)
kexec/arch/i386/crashdump-x86.c +191 -12
@@ -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' */
Signature · 1 line
1.5.6.5
Quoted 3 lines · Daniel Kiper
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?
Quoted 20 lines
Daniel Kiper (7):
kexec: Define some constants and structures conditionally
xen: Renamee820_to_kexec_type()toxen_e820_to_kexec_type()and export it
kexec: Move crash kernel area placement and size detection tois_crashkernel_mem_reserved()
kexec: Addsegregate_lowmem_region()
kexec: Get backup area start address and size directly frommem_range
kexec: Move crash memory ranges logging
xen: Fix Xen kdump supportinclude/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
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec