[PATCH] Add support for 'foreign' page sizes in kdump dumps

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This affects only ppc64 and ia64 since that are the only architectures
that have a page size that is configurable at runtime by the system (which means
at boot by the kernel).

It also only affects dumps of the formats diskdump (which includes kdump
compressed dumps created by makedumpfile) and netdump (which includes kdump
ELF dumps copied from /proc/vmcore without any filtering applied and created
by makedumpfile with the -E option).

The patch reads the page size from the diskdump header or from the VMCOREINFO
in case of netdump (if it's there). For ia64 it also evaluates the page size
of the zero page to *change* the page size. In the past id didn't change the
page size, it only printed an error.

The patch has been tested on ppc64 (4k vs. 64k), ia64 (16k vs. 64k) and x86-64
(always 4k). It has been tested for compilation on i386, x86-64, ia64, PPC,
ppc64, s390 and s390x. Everything on a SLES 11/openSUSE 11.1 code base.


Signed-off-by: Bernhard Walle <bwalle@xxxxxxx>


3 files changed, 117 insertions(+), 11 deletions(-)
diskdump.c |   18 +++++-----
netdump.c  |  108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
netdump.h  |    2 +


This affects only ppc64 and ia64 since that are the only architectures
that have a page size that is configurable at runtime by the system (which means
at boot by the kernel).

It also only affects dumps of the formats diskdump (which includes kdump
compressed dumps created by makedumpfile) and netdump (which includes kdump
ELF dumps copied from /proc/vmcore without any filtering applied and created
by makedumpfile with the -E option).

The patch reads the page size from the diskdump header or from the VMCOREINFO
in case of netdump (if it's there). For ia64 it also evaluates the page size
of the zero page to *change* the page size. In the past id didn't change the
page size, it only printed an error.

The patch has been tested on ppc64 (4k vs. 64k), ia64 (16k vs. 64k) and x86-64
(always 4k). It has been tested for compilation on i386, x86-64, ia64, PPC,
ppc64, s390 and s390x. Everything on a SLES 11/openSUSE 11.1 code base.


Signed-off-by: Bernhard Walle <bwalle@xxxxxxx>

diff --git a/diskdump.c b/diskdump.c
--- a/diskdump.c
+++ b/diskdump.c
@@ -107,7 +107,7 @@
 	struct disk_dump_sub_header *sub_header = NULL;
 	struct kdump_sub_header *sub_header_kdump = NULL;
 	int bitmap_len;
-	const int block_size = (int)sysconf(_SC_PAGESIZE);
+	int block_size = (int)sysconf(_SC_PAGESIZE);
 	off_t offset;
 	const off_t failed = (off_t)-1;
 	ulong pfn;
@@ -116,7 +116,8 @@
 	if (block_size < 0)
 		return FALSE;
 
-	if ((header = malloc(block_size)) == NULL)
+restart:
+	if ((header = realloc(header, block_size)) == NULL)
 		error(FATAL, "diskdump / compressed kdump: cannot malloc block_size buffer\n");
 
 	if (lseek(dd->dfd, 0, SEEK_SET) == failed) {
@@ -166,13 +167,14 @@
 		goto err;
 
 	if (header->block_size != block_size) {
-		error(INFO, "%s: block size in the dump header does not match"
-	            " with system page size\n",
-			DISKDUMP_VALID() ? "diskdump" : "compressed kdump");
-		goto err;
+		block_size = header->block_size;
+		if (CRASHDEBUG(1)) {
+			fprintf(fp, "Retrying with different block size: %d\n", header->block_size);
+		}
+		goto restart;
 	}
-	dd->block_size  = block_size;
-	dd->block_shift = ffs(block_size) - 1;
+	dd->block_size  = header->block_size;
+	dd->block_shift = ffs(header->block_size) - 1;
 
 	if (sizeof(*header) + sizeof(void *) * header->nr_cpus > block_size ||
 	    header->nr_cpus <= 0) {
diff --git a/netdump.c b/netdump.c
--- a/netdump.c
+++ b/netdump.c
@@ -36,7 +36,14 @@
 #define ELFREAD  0
 
 #define MIN_PAGE_SIZE (4096)
-	
+
+/* only PPC64 and IA64 have a configurable page size */
+#if defined(PPC64) || defined(IA64)
+#  define READ_PAGESIZE_FROM_VMCOREINFO 1
+#else
+#  define READ_PAGESIZE_FROM_VMCOREINFO 0
+#endif
+
 /*
  *  Determine whether a file is a netdump/diskdump/kdump creation, 
  *  and if TRUE, initialize the vmcore_data structure.
@@ -1392,6 +1399,93 @@
 }
 
 /*
+ * VMCOREINFO
+ *
+ * This is a ELF note intented for makedumpfile that is exported by the
+ * kernel that crashes and presented as ELF note to the /proc/vmcore
+ * of the panic kernel.
+ */
+
+#define VMCOREINFO_NOTE_NAME        "VMCOREINFO"
+#define VMCOREINFO_NOTE_NAME_BYTES  (sizeof(VMCOREINFO_NOTE_NAME))
+
+/*
+ * Reads a string value from VMCOREINFO.
+ *
+ * Returns a string (that has to be freed by the caller) that contains the
+ * value for key or NULL if the key has not been found.
+ */
+static char *
+vmcoreinfo_read_string(const char *key)
+{
+	int i, j;
+	size_t key_length = strlen(key);
+	char *vmcoreinfo = (char *)nd->vmcoreinfo;
+	char *value = NULL;
+
+	if (!nd->vmcoreinfo) {
+		return NULL;
+	}
+
+	/* the '+ 1' is the equal sign */
+	for (i = 0; i < (nd->size_vmcoreinfo - key_length + 1); i++) {
+		/*
+		 * we must also check if we're at the beginning of VMCOREINFO or
+		 * the separating newline is there ... and of course if we have
+		 * a equal sign after the key
+		 */
+		if (strncmp(vmcoreinfo+i, key, key_length) == 0 &&
+				(i == 0 || vmcoreinfo[i-1] == '\n') &&
+				(vmcoreinfo[i+key_length] == '=') ) {
+
+			int end = -1;
+			size_t value_length;
+
+			/* found  ... search for the next newline */
+			for (j = i + key_length + 1; j < nd->size_vmcoreinfo; j++) {
+				if (vmcoreinfo[j] == '\n') {
+					end = j;
+					break;
+				}
+			}
+
+			/* if we didn't find an end, we assume it's the end of VMCOREINFO */
+			if (end == -1) {
+				/* we point after the end */
+				end = nd->size_vmcoreinfo + 1;
+			}
+
+			value_length = end - (1+ i + key_length);
+			value = malloc(value_length);
+			if (value) {
+				strncpy(value, vmcoreinfo + i + key_length + 1, value_length);
+			}
+			break;
+		}
+	}
+
+	return value;
+}
+
+/*
+ * Reads an integer value from VMCOREINFO.
+ */
+static long
+vmcoreinfo_read_integer(const char *key, long default_value)
+{
+	char *string;
+	long retval = default_value;
+
+	string = vmcoreinfo_read_string(key);
+	if (string) {
+		retval = atol(string);
+		free(string);
+	}
+
+	return retval;
+}
+
+/*
  *  Dump a note section header -- the actual data is defined by netdump
  */
 
@@ -1686,9 +1780,17 @@
 			if (store)
                         	error(WARNING, 
 				    "unknown Xen n_type: %lx\n\n", note->n_type);
-		} else if (vmcoreinfo)
+		} else if (vmcoreinfo) {
                         netdump_print("(unused)\n");
-                else 
+
+			if (READ_PAGESIZE_FROM_VMCOREINFO && store) {
+				nd->vmcoreinfo = (char *)nd->elf64 + offset +
+					(sizeof(Elf64_Nhdr) +
+					((note->n_namesz + 3) & ~3));
+				nd->size_vmcoreinfo = note->n_descsz;
+				nd->page_size = vmcoreinfo_read_integer("PAGESIZE", 0);
+			}
+                } else
                         netdump_print("(?)\n");
                 break;
 
diff --git a/netdump.h b/netdump.h
--- a/netdump.h
+++ b/netdump.h
@@ -66,6 +66,8 @@
 	uint num_prstatus_notes;
 	void *nt_prstatus_percpu[NR_CPUS];
 	struct xen_kdump_data *xen_kdump_data;
+	void *vmcoreinfo;
+	uint size_vmcoreinfo;
 };
 
 /*
--
Crash-utility mailing list
Crash-utility@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/crash-utility

[Index of Archives]     [Fedora Development]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]     [Fedora Tools]

 

Powered by Linux