Blame SOURCES/github_a6cd8408_mach-m.patch

474a44
commit a6cd8408d1d214a67ed0c4b09343fec77a8e2ae7
474a44
Author: Dave Anderson <anderson@redhat.com>
474a44
Date:   Thu May 31 11:43:14 2018 -0400
474a44
474a44
    Fix for the x86 and x86_64 "mach -m" option on Linux 4.12 and later
474a44
    kernels to account for the structure name changes "e820map" to
474a44
    "e820_table", and "e820entry" to "e820_entry", and for the symbol
474a44
    name change from "e820" to "e820_table".  Also updated the display
474a44
    output to properly translate E820_PRAM and E820_RESERVED_KERN entries.
474a44
    Without the patch on all kernels, E820_PRAM and E820_RESERVED_KERN
474a44
    entries show "type 12" and "type 128" respectively.  Without the
474a44
    patch on Linux 4.12 and later kernels, the command fails with the
474a44
    error message "mach: cannot resolve e820".
474a44
    (anderson@redhat.com)
474a44
474a44
diff --git a/x86.c b/x86.c
474a44
index 47767b6..88562b6 100644
474a44
--- a/x86.c
474a44
+++ b/x86.c
474a44
@@ -1,8 +1,8 @@
474a44
 /* x86.c - core analysis suite
474a44
  *
474a44
  * Portions Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc.
474a44
- * Copyright (C) 2002-2014,2017 David Anderson
474a44
- * Copyright (C) 2002-2014,2017 Red Hat, Inc. All rights reserved.
474a44
+ * Copyright (C) 2002-2014,2017-2018 David Anderson
474a44
+ * Copyright (C) 2002-2014,2017-2018 Red Hat, Inc. All rights reserved.
474a44
  *
474a44
  * This program is free software; you can redistribute it and/or modify
474a44
  * it under the terms of the GNU General Public License as published by
474a44
@@ -1967,15 +1967,27 @@ x86_init(int when)
474a44
 		}
474a44
 		MEMBER_OFFSET_INIT(thread_struct_cr3, "thread_struct", "cr3");
474a44
 		STRUCT_SIZE_INIT(cpuinfo_x86, "cpuinfo_x86");
474a44
-		STRUCT_SIZE_INIT(e820map, "e820map");
474a44
-		STRUCT_SIZE_INIT(e820entry, "e820entry");
474a44
 		STRUCT_SIZE_INIT(irq_ctx, "irq_ctx");
474a44
+		if (STRUCT_EXISTS("e820map")) {
474a44
+			STRUCT_SIZE_INIT(e820map, "e820map");
474a44
+			MEMBER_OFFSET_INIT(e820map_nr_map, "e820map", "nr_map");
474a44
+		} else {
474a44
+			STRUCT_SIZE_INIT(e820map, "e820_table");
474a44
+			MEMBER_OFFSET_INIT(e820map_nr_map, "e820_table", "nr_entries");
474a44
+		}
474a44
+		if (STRUCT_EXISTS("e820entry")) {
474a44
+			STRUCT_SIZE_INIT(e820entry, "e820entry");
474a44
+			MEMBER_OFFSET_INIT(e820entry_addr, "e820entry", "addr");
474a44
+			MEMBER_OFFSET_INIT(e820entry_size, "e820entry", "size");
474a44
+			MEMBER_OFFSET_INIT(e820entry_type, "e820entry", "type");
474a44
+		} else {
474a44
+			STRUCT_SIZE_INIT(e820entry, "e820_entry");
474a44
+			MEMBER_OFFSET_INIT(e820entry_addr, "e820_entry", "addr");
474a44
+			MEMBER_OFFSET_INIT(e820entry_size, "e820_entry", "size");
474a44
+			MEMBER_OFFSET_INIT(e820entry_type, "e820_entry", "type");
474a44
+		}
474a44
 		if (!VALID_STRUCT(irq_ctx))
474a44
 			STRUCT_SIZE_INIT(irq_ctx, "irq_stack");
474a44
-		MEMBER_OFFSET_INIT(e820map_nr_map, "e820map", "nr_map");
474a44
-		MEMBER_OFFSET_INIT(e820entry_addr, "e820entry", "addr");
474a44
-		MEMBER_OFFSET_INIT(e820entry_size, "e820entry", "size");
474a44
-		MEMBER_OFFSET_INIT(e820entry_type, "e820entry", "type");
474a44
 		if (KVMDUMP_DUMPFILE())
474a44
 			set_kvm_iohole(NULL);
474a44
 		if (symbol_exists("irq_desc"))
474a44
@@ -4415,33 +4427,54 @@ static char *e820type[] = {
474a44
 static void
474a44
 x86_display_memmap(void)
474a44
 {
474a44
-	ulong e820;
474a44
-	int nr_map, i;
474a44
-	char *buf, *e820entry_ptr;
474a44
-	ulonglong addr, size;
474a44
-	ulong type;
474a44
+        ulong e820;
474a44
+        int nr_map, i;
474a44
+        char *buf, *e820entry_ptr;
474a44
+        ulonglong addr, size;
474a44
+        uint type;
474a44
+
474a44
+	if (kernel_symbol_exists("e820")) {
474a44
+		if (get_symbol_type("e820", NULL, NULL) == TYPE_CODE_PTR)
474a44
+			get_symbol_data("e820", sizeof(void *), &e820);
474a44
+		else
474a44
+			e820 = symbol_value("e820");
474a44
+
474a44
+	} else if (kernel_symbol_exists("e820_table"))
474a44
+		get_symbol_data("e820_table", sizeof(void *), &e820);
474a44
+	else
474a44
+		error(FATAL, "neither e820 or e820_table symbols exist\n");
474a44
 
474a44
-	e820 = symbol_value("e820");
474a44
-	buf = (char *)GETBUF(SIZE(e820map));
474a44
+	if (CRASHDEBUG(1)) {
474a44
+		if (STRUCT_EXISTS("e820map"))
474a44
+			dump_struct("e820map", e820, RADIX(16));
474a44
+		else if (STRUCT_EXISTS("e820_table"))
474a44
+			dump_struct("e820_table", e820, RADIX(16));
474a44
+	}
474a44
+        buf = (char *)GETBUF(SIZE(e820map));
474a44
 
474a44
-        readmem(e820, KVADDR, &buf[0], SIZE(e820map), 
474a44
-		"e820map", FAULT_ON_ERROR);
474a44
+        readmem(e820, KVADDR, &buf[0], SIZE(e820map),
474a44
+                "e820map", FAULT_ON_ERROR);
474a44
 
474a44
-	nr_map = INT(buf + OFFSET(e820map_nr_map));
474a44
+        nr_map = INT(buf + OFFSET(e820map_nr_map));
474a44
 
474a44
-	fprintf(fp, "      PHYSICAL ADDRESS RANGE         TYPE\n");
474a44
+        fprintf(fp, "      PHYSICAL ADDRESS RANGE         TYPE\n");
474a44
 
474a44
-	for (i = 0; i < nr_map; i++) {
474a44
-		e820entry_ptr = buf + sizeof(int) + (SIZE(e820entry) * i);
474a44
-		addr = ULONGLONG(e820entry_ptr + OFFSET(e820entry_addr));
474a44
-		size = ULONGLONG(e820entry_ptr + OFFSET(e820entry_size));
474a44
-		type = ULONG(e820entry_ptr + OFFSET(e820entry_type));
474a44
+        for (i = 0; i < nr_map; i++) {
474a44
+                e820entry_ptr = buf + sizeof(int) + (SIZE(e820entry) * i);
474a44
+                addr = ULONGLONG(e820entry_ptr + OFFSET(e820entry_addr));
474a44
+                size = ULONGLONG(e820entry_ptr + OFFSET(e820entry_size));
474a44
+                type = UINT(e820entry_ptr + OFFSET(e820entry_type));
474a44
 		fprintf(fp, "%016llx - %016llx  ", addr, addr+size);
474a44
-		if (type >= (sizeof(e820type)/sizeof(char *)))
474a44
-			fprintf(fp, "type %ld\n", type);
474a44
-		else
474a44
+		if (type >= (sizeof(e820type)/sizeof(char *))) {
474a44
+			if (type == 12)
474a44
+				fprintf(fp, "E820_PRAM\n");
474a44
+			else if (type == 128)
474a44
+				fprintf(fp, "E820_RESERVED_KERN\n");
474a44
+			else
474a44
+				fprintf(fp, "type %d\n", type);
474a44
+		} else
474a44
 			fprintf(fp, "%s\n", e820type[type]);
474a44
-	}
474a44
+        }
474a44
 }
474a44
 
474a44
 /*
474a44
diff --git a/x86_64.c b/x86_64.c
474a44
index 921552b..1d5e155 100644
474a44
--- a/x86_64.c
474a44
+++ b/x86_64.c
474a44
@@ -415,12 +415,26 @@ x86_64_init(int when)
474a44
 			STRUCT_SIZE_INIT(gate_struct, "gate_desc");
474a44
 		else
474a44
 			STRUCT_SIZE_INIT(gate_struct, "gate_struct");
474a44
-                STRUCT_SIZE_INIT(e820map, "e820map");
474a44
-                STRUCT_SIZE_INIT(e820entry, "e820entry");
474a44
-                MEMBER_OFFSET_INIT(e820map_nr_map, "e820map", "nr_map");
474a44
-                MEMBER_OFFSET_INIT(e820entry_addr, "e820entry", "addr");
474a44
-                MEMBER_OFFSET_INIT(e820entry_size, "e820entry", "size");
474a44
-                MEMBER_OFFSET_INIT(e820entry_type, "e820entry", "type");
474a44
+
474a44
+		if (STRUCT_EXISTS("e820map")) {
474a44
+			STRUCT_SIZE_INIT(e820map, "e820map");
474a44
+			MEMBER_OFFSET_INIT(e820map_nr_map, "e820map", "nr_map");
474a44
+		} else {
474a44
+			STRUCT_SIZE_INIT(e820map, "e820_table");
474a44
+			MEMBER_OFFSET_INIT(e820map_nr_map, "e820_table", "nr_entries");
474a44
+		}
474a44
+		if (STRUCT_EXISTS("e820entry")) {
474a44
+			STRUCT_SIZE_INIT(e820entry, "e820entry");
474a44
+			MEMBER_OFFSET_INIT(e820entry_addr, "e820entry", "addr");
474a44
+			MEMBER_OFFSET_INIT(e820entry_size, "e820entry", "size");
474a44
+			MEMBER_OFFSET_INIT(e820entry_type, "e820entry", "type");
474a44
+		} else {
474a44
+			STRUCT_SIZE_INIT(e820entry, "e820_entry");
474a44
+			MEMBER_OFFSET_INIT(e820entry_addr, "e820_entry", "addr");
474a44
+			MEMBER_OFFSET_INIT(e820entry_size, "e820_entry", "size");
474a44
+			MEMBER_OFFSET_INIT(e820entry_type, "e820_entry", "type");
474a44
+		}
474a44
+
474a44
 		if (KVMDUMP_DUMPFILE())
474a44
 			set_kvm_iohole(NULL);
474a44
 		MEMBER_OFFSET_INIT(thread_struct_rip, "thread_struct", "rip");
474a44
@@ -5643,12 +5657,23 @@ x86_64_display_memmap(void)
474a44
         ulonglong addr, size;
474a44
         uint type;
474a44
 
474a44
-	if (get_symbol_type("e820", NULL, NULL) == TYPE_CODE_PTR)
474a44
-		get_symbol_data("e820", sizeof(void *), &e820);
474a44
+	if (kernel_symbol_exists("e820")) {
474a44
+		if (get_symbol_type("e820", NULL, NULL) == TYPE_CODE_PTR)
474a44
+			get_symbol_data("e820", sizeof(void *), &e820);
474a44
+		else
474a44
+			e820 = symbol_value("e820");
474a44
+
474a44
+	} else if (kernel_symbol_exists("e820_table"))
474a44
+		get_symbol_data("e820_table", sizeof(void *), &e820);
474a44
 	else
474a44
-		e820 = symbol_value("e820");
474a44
-	if (CRASHDEBUG(1))
474a44
-		dump_struct("e820map", e820, RADIX(16));
474a44
+		error(FATAL, "neither e820 or e820_table symbols exist\n");
474a44
+
474a44
+	if (CRASHDEBUG(1)) {
474a44
+		if (STRUCT_EXISTS("e820map"))
474a44
+			dump_struct("e820map", e820, RADIX(16));
474a44
+		else if (STRUCT_EXISTS("e820_table"))
474a44
+			dump_struct("e820_table", e820, RADIX(16));
474a44
+	}
474a44
         buf = (char *)GETBUF(SIZE(e820map));
474a44
 
474a44
         readmem(e820, KVADDR, &buf[0], SIZE(e820map),
474a44
@@ -5664,9 +5689,14 @@ x86_64_display_memmap(void)
474a44
                 size = ULONGLONG(e820entry_ptr + OFFSET(e820entry_size));
474a44
                 type = UINT(e820entry_ptr + OFFSET(e820entry_type));
474a44
 		fprintf(fp, "%016llx - %016llx  ", addr, addr+size);
474a44
-		if (type >= (sizeof(e820type)/sizeof(char *)))
474a44
-			fprintf(fp, "type %d\n", type);
474a44
-		else
474a44
+		if (type >= (sizeof(e820type)/sizeof(char *))) {
474a44
+			if (type == 12)
474a44
+				fprintf(fp, "E820_PRAM\n");
474a44
+			else if (type == 128)
474a44
+				fprintf(fp, "E820_RESERVED_KERN\n");
474a44
+			else
474a44
+				fprintf(fp, "type %d\n", type);
474a44
+		} else
474a44
 			fprintf(fp, "%s\n", e820type[type]);
474a44
         }
474a44
 }