[Crash-utility] [PATCH v2 3/6] x86_64: Unify the page table parsing for 4-level mode

Dou Liyang douly.fnst at cn.fujitsu.com
Fri Jan 12 10:12:53 UTC 2018


Repace the PML4 and UPML with the common PGD to make page table uniform
for supporting 5 level mode.

Signed-off-by: Dou Liyang <douly.fnst at cn.fujitsu.com>
---
 defs.h   |  55 ++++++---------
 sadump.c |   9 +--
 x86_64.c | 230 +++++++++++++++++++++++++++------------------------------------
 3 files changed, 123 insertions(+), 171 deletions(-)

diff --git a/defs.h b/defs.h
index 8082d6c..c055e48 100644
--- a/defs.h
+++ b/defs.h
@@ -3330,56 +3330,44 @@ struct arm64_stackframe {
 #define VTOP(X)               x86_64_VTOP((ulong)(X))
 #define IS_VMALLOC_ADDR(X)    x86_64_IS_VMALLOC_ADDR((ulong)(X))
 
-#define PML4_SHIFT      39
-#define PTRS_PER_PML4   512
+/* origin level page */
 #define PGDIR_SHIFT     30
 #define PTRS_PER_PGD    512
 #define PMD_SHIFT       21
 #define PTRS_PER_PMD    512
 #define PTRS_PER_PTE    512
 
+/* 4 level page */
+#define PGDIR_SHIFT_4LEVEL    39
+#define PTRS_PER_PGD_4LEVEL  512
+#define PUD_SHIFT       30
+#define PTRS_PER_PUD    512
+
+/* 5 level page */
 #define PGDIR_SHIFT_5LEVEL    48
 #define PTRS_PER_PGD_5LEVEL  512
 #define P4D_SHIFT             39
 #define PTRS_PER_P4D         512
 
 #define __PGDIR_SHIFT  (machdep->machspec->pgdir_shift)
+#define __PTRS_PER_PGD  (machdep->machspec->ptrs_per_pgd)
 
-#define pml4_index(address) (((address) >> PML4_SHIFT) & (PTRS_PER_PML4-1))
+#define pgd_index(address)  (((address) >> __PGDIR_SHIFT) & (__PTRS_PER_PGD-1))
 #define p4d_index(address)  (((address) >> P4D_SHIFT) & (PTRS_PER_P4D - 1))
-#define pgd_index(address)  (((address) >> __PGDIR_SHIFT) & (PTRS_PER_PGD-1))
+#define pud_index(address)  (((address) >> PUD_SHIFT) & (PTRS_PER_PUD - 1))
 #define pmd_index(address)  (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1))
 #define pte_index(address)  (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
 
-#define IS_LAST_PML4_READ(pml4) ((ulong)(pml4) == machdep->machspec->last_pml4_read)
-
-#define FILL_PML4() 									\
-	if (!(pc->flags & RUNTIME) || ACTIVE()) { 					\
-		if (!IS_LAST_PML4_READ(vt->kernel_pgd[0])) { 				\
-			readmem(vt->kernel_pgd[0], KVADDR, machdep->machspec->pml4, 	\
-					PAGESIZE(), "init_level4_pgt", FAULT_ON_ERROR); \
-			machdep->machspec->last_pml4_read = (ulong)(vt->kernel_pgd[0]); \
-		} 									\
+#define FILL_TOP_PGD() 							\
+	if (!(pc->flags & RUNTIME) || ACTIVE()) { 				\
+		FILL_PGD(vt->kernel_pgd[0], KVADDR, PAGESIZE());		\
 	}
 
-#define FILL_PML4_HYPER() 								\
-	if (!machdep->machspec->last_pml4_read) { 					\
-		unsigned long idle_pg_table = symbol_exists("idle_pg_table_4") ? 	\
-						symbol_value("idle_pg_table_4") : 	\
-						symbol_value("idle_pg_table"); 	\
-		readmem(idle_pg_table, KVADDR, machdep->machspec->pml4, PAGESIZE(), 	\
-				"idle_pg_table", FAULT_ON_ERROR); 			\
-		machdep->machspec->last_pml4_read = idle_pg_table; 			\
-	}
-
-#define IS_LAST_UPML_READ(pml) ((ulong)(pml) == machdep->machspec->last_upml_read)
-
-#define FILL_UPML(PML, TYPE, SIZE) 					      \
-    if (!IS_LAST_UPML_READ(PML)) {                                             \
-            readmem((ulonglong)((ulong)(PML)), TYPE, machdep->machspec->upml, \
-                    SIZE, "pml page", FAULT_ON_ERROR);                        \
-            machdep->machspec->last_upml_read = (ulong)(PML);                 \
-    }								            
+#define FILL_TOP_PGD_HYPER() 							\
+	unsigned long idle_pg_table = symbol_exists("idle_pg_table_4") ? 	\
+					symbol_value("idle_pg_table_4") : 	\
+					symbol_value("idle_pg_table");		\
+	FILL_PGD(idle_pg_table, KVADDR, PAGESIZE());
 
 #define IS_LAST_P4D_READ(p4d) ((ulong)(p4d) == machdep->machspec->last_p4d_read)
 
@@ -5747,10 +5735,6 @@ struct machine_specific {
 	ulong modules_vaddr;
 	ulong modules_end;
 	ulong phys_base;
-        char *pml4;
-	char *upml;
-	ulong last_upml_read;
-	ulong last_pml4_read;
 	char *irqstack;
 	ulong irq_eframe_link;
 	struct x86_64_pt_regs_offsets pto;
@@ -5765,6 +5749,7 @@ struct machine_specific {
 	ulong kernel_image_size;
 	ulong physical_mask_shift;
 	ulong pgdir_shift;
+	ulong ptrs_per_pgd;
         char *p4d;
 	ulong last_p4d_read;
 	struct ORC_data orc;
diff --git a/sadump.c b/sadump.c
index 6b912d4..a189c2d 100644
--- a/sadump.c
+++ b/sadump.c
@@ -2051,10 +2051,11 @@ sadump_calc_kaslr_offset(ulong *kaslr_offset)
 	 * TODO: XEN and 5-level is not supported
 	 */
 	vt->kernel_pgd[0] = cr3;
-	machdep->machspec->last_pml4_read = vt->kernel_pgd[0];
+	machdep->last_pgd_read = vt->kernel_pgd[0];
 	machdep->machspec->physical_mask_shift = __PHYSICAL_MASK_SHIFT_2_6;
-	machdep->machspec->pgdir_shift = PGDIR_SHIFT;
-	if (!readmem(cr3, PHYSADDR, machdep->machspec->pml4, PAGESIZE(),
+	machdep->machspec->pgdir_shift = PGDIR_SHIFT_4LEVEL;
+	machdep->machspec->ptrs_per_pgd = PTRS_PER_PGD_4LEVEL;
+	if (!readmem(cr3, PHYSADDR, machdep->pgd, PAGESIZE(),
 			"cr3", RETURN_ON_ERROR))
 		goto quit;
 
@@ -2099,7 +2100,7 @@ sadump_calc_kaslr_offset(ulong *kaslr_offset)
 	ret = TRUE;
 quit:
 	vt->kernel_pgd[0] = 0;
-	machdep->machspec->last_pml4_read = 0;
+	machdep->last_pgd_read = 0;
 	return ret;
 }
 #else
diff --git a/x86_64.c b/x86_64.c
index 7134b4b..0f2e24a 100644
--- a/x86_64.c
+++ b/x86_64.c
@@ -166,20 +166,17 @@ x86_64_init(int when)
                 machdep->pageoffset = machdep->pagesize - 1;
                 machdep->pagemask = ~((ulonglong)machdep->pageoffset);
 		machdep->stacksize = machdep->pagesize * 2;
-                if ((machdep->machspec->upml = (char *)malloc(PAGESIZE())) == NULL)
-                        error(FATAL, "cannot malloc upml space.");
-                if ((machdep->pgd = (char *)malloc(PAGESIZE())) == NULL)
+		if ((machdep->pgd = (char *)malloc(PAGESIZE())) == NULL)
                         error(FATAL, "cannot malloc pgd space.");
+                if ((machdep->pud = (char *)malloc(PAGESIZE())) == NULL)
+                        error(FATAL, "cannot malloc pud space.");
                 if ((machdep->pmd = (char *)malloc(PAGESIZE())) == NULL)
                         error(FATAL, "cannot malloc pmd space.");
                 if ((machdep->ptbl = (char *)malloc(PAGESIZE())) == NULL)
                         error(FATAL, "cannot malloc ptbl space.");
-		if ((machdep->machspec->pml4 = 
-			(char *)malloc(PAGESIZE()*2)) == NULL)
-                        error(FATAL, "cannot malloc pml4 space.");
-                machdep->machspec->last_upml_read = 0;
-                machdep->machspec->last_pml4_read = 0;
+
                 machdep->last_pgd_read = 0;
+		machdep->last_pud_read = 0;
                 machdep->last_pmd_read = 0;
                 machdep->last_ptbl_read = 0;
 		machdep->verify_paddr = x86_64_verify_paddr;
@@ -233,12 +230,10 @@ x86_64_init(int when)
                         machdep->machspec->modules_vaddr = MODULES_VADDR_ORIG;
                         machdep->machspec->modules_end = MODULES_END_ORIG;
 
-			free(machdep->machspec->upml);
-			machdep->machspec->upml = NULL;
-
 			machdep->uvtop = x86_64_uvtop;
 			machdep->machspec->physical_mask_shift = __PHYSICAL_MASK_SHIFT_2_6;
 			machdep->machspec->pgdir_shift = PGDIR_SHIFT;
+			machdep->machspec->ptrs_per_pgd = PTRS_PER_PGD;
 			break;
 		
 		case VM_2_6_11:
@@ -264,7 +259,8 @@ x86_64_init(int when)
 
 			machdep->uvtop = x86_64_uvtop_level4;
 			machdep->machspec->physical_mask_shift = __PHYSICAL_MASK_SHIFT_2_6;
-			machdep->machspec->pgdir_shift = PGDIR_SHIFT;
+			machdep->machspec->pgdir_shift = PGDIR_SHIFT_4LEVEL;
+			machdep->machspec->ptrs_per_pgd = PTRS_PER_PGD_4LEVEL;
 			break;
 
                 case VM_XEN:
@@ -276,7 +272,6 @@ x86_64_init(int when)
                         machdep->machspec->modules_vaddr = MODULES_VADDR_XEN;
                         machdep->machspec->modules_end = MODULES_END_XEN;
 			machdep->machspec->physical_mask_shift = __PHYSICAL_MASK_SHIFT_XEN;
-			machdep->machspec->pgdir_shift = PGDIR_SHIFT;
                         break;
 
 		case VM_XEN_RHEL4:
@@ -288,7 +283,6 @@ x86_64_init(int when)
                         machdep->machspec->modules_vaddr = MODULES_VADDR_XEN_RHEL4;
                         machdep->machspec->modules_end = MODULES_END_XEN_RHEL4;
 			machdep->machspec->physical_mask_shift = __PHYSICAL_MASK_SHIFT_XEN;
-			machdep->machspec->pgdir_shift = PGDIR_SHIFT;
 			break;
 
 		case VM_5LEVEL:
@@ -302,6 +296,7 @@ x86_64_init(int when)
 			machdep->machspec->vmemmap_end = VMEMMAP_END_5LEVEL;
 			machdep->machspec->physical_mask_shift = __PHYSICAL_MASK_SHIFT_5LEVEL;
 			machdep->machspec->pgdir_shift = PGDIR_SHIFT_5LEVEL;
+			machdep->machspec->ptrs_per_pgd = PTRS_PER_PGD_5LEVEL;
 			if ((machdep->machspec->p4d = (char *)malloc(PAGESIZE())) == NULL)
 				error(FATAL, "cannot malloc p4d space.");
 			machdep->machspec->last_p4d_read = 0;
@@ -629,14 +624,21 @@ x86_64_init(int when)
 				case VM_XEN: 
 				case VM_2_6_11:
                         		machdep->uvtop = x86_64_uvtop_level4_xen_wpt;
+					machdep->machspec->pgdir_shift = PGDIR_SHIFT_4LEVEL;
+					machdep->machspec->ptrs_per_pgd = PTRS_PER_PGD_4LEVEL;
 					break;
 				case VM_XEN_RHEL4:
                         		machdep->uvtop = x86_64_uvtop_level4_rhel4_xen_wpt;
+					machdep->machspec->pgdir_shift = PGDIR_SHIFT;
+					machdep->machspec->ptrs_per_pgd = PTRS_PER_PGD;
 					break;
 				}
 				machdep->machspec->physical_mask_shift = __PHYSICAL_MASK_SHIFT_XEN;
-			} else
-                        	machdep->uvtop = x86_64_uvtop_level4;
+			} else {
+				machdep->uvtop = x86_64_uvtop_level4;
+				machdep->machspec->pgdir_shift = PGDIR_SHIFT_4LEVEL;
+				machdep->machspec->ptrs_per_pgd = PTRS_PER_PGD_4LEVEL;
+			}
                         MEMBER_OFFSET_INIT(vcpu_guest_context_user_regs,
                                 "vcpu_guest_context", "user_regs");
 			ASSIGN_OFFSET(cpu_user_regs_rsp) = 
@@ -811,9 +813,11 @@ x86_64_dump_machdep_table(ulong arg)
         fprintf(fp, "    value_to_symbol: x86_64_value_to_symbol()\n");
         fprintf(fp, " in_alternate_stack: x86_64_in_alternate_stack()\n");
         fprintf(fp, "      last_pgd_read: %lx\n", machdep->last_pgd_read);
+	fprintf(fp, "      last_pud_read: %lx\n", machdep->last_pud_read);
         fprintf(fp, "      last_pmd_read: %lx\n", machdep->last_pmd_read);
         fprintf(fp, "     last_ptbl_read: %lx\n", machdep->last_ptbl_read);
         fprintf(fp, "                pgd: %lx\n", (ulong)machdep->pgd);
+	fprintf(fp, "                pud: %lx\n", (ulong)machdep->pud);
         fprintf(fp, "                pmd: %lx\n", (ulong)machdep->pmd);
         fprintf(fp, "               ptbl: %lx\n", (ulong)machdep->ptbl);
 	fprintf(fp, "       ptrs_per_pgd: %d\n", machdep->ptrs_per_pgd);
@@ -848,15 +852,7 @@ x86_64_dump_machdep_table(ulong arg)
 	fprintf(fp, "              pgdir_shift: %ld\n", ms->pgdir_shift);
 	fprintf(fp, "               GART_start: %lx\n", ms->GART_start);
 	fprintf(fp, "                 GART_end: %lx\n", ms->GART_end);
-	fprintf(fp, "                     pml4: %lx\n", (ulong)ms->pml4);
-	fprintf(fp, "           last_pml4_read: %lx\n", (ulong)ms->last_pml4_read);
-	if (ms->upml) {
-		fprintf(fp, "                     upml: %lx\n", (ulong)ms->upml);
-		fprintf(fp, "           last_upml_read: %lx\n", (ulong)ms->last_upml_read);
-	} else {
-		fprintf(fp, "                     upml: (unused)\n");
-		fprintf(fp, "           last_upml_read: (unused)\n");
-	}
+
 	if (ms->p4d) {
 		fprintf(fp, "                      p4d: %lx\n", (ulong)ms->p4d);
 		fprintf(fp, "            last_p4d_read: %lx\n", (ulong)ms->last_p4d_read);
@@ -1511,7 +1507,7 @@ x86_64_init_kernel_pgd(void)
 	for (i = 0; i < NR_CPUS; i++) 
 		vt->kernel_pgd[i] = kernel_pgt;
 
-	FILL_PML4();
+	FILL_TOP_PGD();
 }
 
 /*
@@ -1571,8 +1567,8 @@ x86_64_kpgd_offset(ulong kvaddr, int verbose , int IS_XEN)
 {
 	ulong *pgd;
 
-	FILL_PML4();
-	pgd = ((ulong *)machdep->machspec->pml4) + pml4_index(kvaddr);
+	FILL_TOP_PGD();
+	pgd = ((ulong *)machdep->pgd) + pgd_index(kvaddr);
 	if (verbose) {
 		fprintf(fp, "PGD DIRECTORY: %lx\n", vt->kernel_pgd[0]);
 		if(IS_XEN)
@@ -1602,9 +1598,9 @@ x86_64_upgd_offset(struct task_context *tc, ulong uvaddr, int verbose , int IS_X
                         sizeof(long), "mm_struct pgd", FAULT_ON_ERROR);
 
         pgd_paddr = x86_64_VTOP((ulong)pgd);
-        FILL_UPML(pgd_paddr, PHYSADDR, PAGESIZE());
-	pgd = ((ulong *)pgd_paddr) + pml4_index(uvaddr);
-	pgd_pte = ULONG(machdep->machspec->pml4 + PAGEOFFSET(pgd));
+        FILL_PGD(pgd_paddr, PHYSADDR, PAGESIZE());
+	pgd = ((ulong *)pgd_paddr) + pgd_index(uvaddr);
+	pgd_pte = ULONG(machdep->pgd + PAGEOFFSET(pgd));
         if (verbose) {
 		if(IS_XEN)
 			fprintf(fp, "   PGD: %lx => %lx [machine]\n", (ulong)pgd, pgd_pte);
@@ -1635,7 +1631,7 @@ x86_64_pud_offset(ulong pgd_pte, ulong vaddr, int verbose , int IS_XEN)
 	}
 
 	FILL_PUD(pud_paddr, PHYSADDR, PAGESIZE());
-	pud = ((ulong *)pud_paddr) + pgd_index(vaddr);
+	pud = ((ulong *)pud_paddr) + pud_index(vaddr);
 	pud_pte = ULONG(machdep->pud + PAGEOFFSET(pud));
 	if (verbose) {
 		if(IS_XEN)
@@ -1917,9 +1913,6 @@ no_upage:
 static int
 x86_64_uvtop_level4_rhel4_xen_wpt(struct task_context *tc, ulong uvaddr, physaddr_t *paddr, int verbose)
 {
-	ulong mm;
-	ulong *pgd;
-	ulong pgd_paddr;
 	ulong pgd_pte;
 	ulong pmd_pte;
 	ulong pseudo_pmd_pte;
@@ -1936,18 +1929,7 @@ x86_64_uvtop_level4_rhel4_xen_wpt(struct task_context *tc, ulong uvaddr, physadd
 	if (IS_KVADDR(uvaddr))
 		return x86_64_kvtop(tc, uvaddr, paddr, verbose);
 
-	if ((mm = task_mm(tc->task, TRUE)))
-		pgd = ULONG_PTR(tt->mm_struct + OFFSET(mm_struct_pgd));
-	else
-		readmem(tc->mm_struct + OFFSET(mm_struct_pgd), KVADDR, &pgd,
-			sizeof(long), "mm_struct pgd", FAULT_ON_ERROR);
-
-	pgd_paddr = x86_64_VTOP((ulong)pgd);
-	FILL_PGD(pgd_paddr, PHYSADDR, PAGESIZE());
-	pgd = ((ulong *)pgd_paddr) + pgd_index(uvaddr); 
-	pgd_pte = ULONG(machdep->pgd + PAGEOFFSET(pgd));
-	if (verbose) 
-                fprintf(fp, "   PGD: %lx => %lx [machine]\n", (ulong)pgd, pgd_pte);
+	pgd_pte = x86_64_upgd_offset(tc, uvaddr, verbose, TRUE);
 	if (!(pgd_pte & _PAGE_PRESENT))
 		goto no_upage;
 
@@ -2028,9 +2010,6 @@ no_upage:
 static int
 x86_64_uvtop(struct task_context *tc, ulong uvaddr, physaddr_t *paddr, int verbose)
 {
-       	ulong mm;
-        ulong *pgd;
-	ulong pgd_paddr;
 	ulong pgd_pte;
 	ulong pmd_pte;
         ulong pte;
@@ -2047,18 +2026,7 @@ x86_64_uvtop(struct task_context *tc, ulong uvaddr, physaddr_t *paddr, int verbo
         /*
          *  pgd = pgd_offset(mm, address);
          */
-        if ((mm = task_mm(tc->task, TRUE)))
-                pgd = ULONG_PTR(tt->mm_struct + OFFSET(mm_struct_pgd));
-        else
-                readmem(tc->mm_struct + OFFSET(mm_struct_pgd), KVADDR, &pgd,
-                        sizeof(long), "mm_struct pgd", FAULT_ON_ERROR);
-
-        pgd_paddr = x86_64_VTOP((ulong)pgd);
-        FILL_PGD(pgd_paddr, PHYSADDR, PAGESIZE());
-	pgd = ((ulong *)pgd_paddr) + pgd_index(uvaddr); 
-	pgd_pte = ULONG(machdep->pgd + PAGEOFFSET(pgd));
-        if (verbose) 
-                fprintf(fp, "   PGD: %lx => %lx\n", (ulong)pgd, pgd_pte);
+        pgd_pte = x86_64_upgd_offset(tc, uvaddr, verbose, FALSE);
 	if (!(pgd_pte & _PAGE_PRESENT))
 		goto no_upage;
 
@@ -2119,7 +2087,7 @@ no_upage:
 static int
 x86_64_kvtop(struct task_context *tc, ulong kvaddr, physaddr_t *paddr, int verbose)
 {
-	ulong *pml4;
+	ulong *pgd;
 	ulong pud_pte;
 	ulong pmd_pte;
 	ulong pte;
@@ -2148,11 +2116,11 @@ x86_64_kvtop(struct task_context *tc, ulong kvaddr, physaddr_t *paddr, int verbo
 			*paddr = kvaddr - DIRECTMAP_VIRT_START;
 			return TRUE;
 		}
-		FILL_PML4_HYPER();
-		pml4 = ((ulong *)machdep->machspec->pml4) + pml4_index(kvaddr);  
+		FILL_TOP_PGD_HYPER();
+		pgd = ((ulong *)machdep->pgd) + pgd_index(kvaddr);
         	if (verbose) {
-			fprintf(fp, "PML4 DIRECTORY: %lx\n", vt->kernel_pgd[0]);
-               		fprintf(fp, "PAGE DIRECTORY: %lx\n", *pml4);
+			fprintf(fp, "PGD DIRECTORY: %lx\n", vt->kernel_pgd[0]);
+			fprintf(fp, "PAGE DIRECTORY: %lx\n", *pgd);
 		}
 	} else {
         	if (!vt->vmalloc_start) {
@@ -2179,10 +2147,10 @@ x86_64_kvtop(struct task_context *tc, ulong kvaddr, physaddr_t *paddr, int verbo
 	}
 
 start_vtop_with_pagetable:
-	if (!(*pml4 & _PAGE_PRESENT))
+	if (!(*pgd & _PAGE_PRESENT))
 		goto no_kpage;
 
-	pud_pte = x86_64_pud_offset(*pml4, kvaddr, verbose, FALSE);
+	pud_pte = x86_64_pud_offset(*pgd, kvaddr, verbose, FALSE);
 	if (!(pud_pte & _PAGE_PRESENT))
 		goto no_kpage;
 
@@ -2242,7 +2210,7 @@ x86_64_kvtop_5level(struct task_context *tc, ulong kvaddr, physaddr_t *paddr, in
 static int
 x86_64_kvtop_xen_wpt(struct task_context *tc, ulong kvaddr, physaddr_t *paddr, int verbose)
 {
-	ulong *pml4;
+        ulong *pgd;
 	ulong pud_pte;
 	ulong pmd_pte;
 	ulong pseudo_pmd_pte;
@@ -2254,11 +2222,11 @@ x86_64_kvtop_xen_wpt(struct task_context *tc, ulong kvaddr, physaddr_t *paddr, i
  	/*	
 	 *  pgd = pgd_offset_k(addr);
 	 */
-	pml4 = x86_64_kpgd_offset(kvaddr, verbose, TRUE);
-	if (!(*pml4 & _PAGE_PRESENT))
+	pgd = x86_64_kpgd_offset(kvaddr, verbose, TRUE);
+	if (!(*pgd & _PAGE_PRESENT))
 		goto no_kpage;
 
-	pud_pte = x86_64_pud_offset(*pml4, kvaddr, verbose, TRUE);
+	pud_pte = x86_64_pud_offset(*pgd, kvaddr, verbose, TRUE);
 	if (!(pud_pte & _PAGE_PRESENT))
 		goto no_kpage;
 
@@ -5827,7 +5795,8 @@ parse_cmdline_args(void)
 void
 x86_64_clear_machdep_cache(void)
 {
-	machdep->machspec->last_upml_read = 0;
+	if (machdep->last_pgd_read != vt->kernel_pgd[0])
+		machdep->last_pgd_read = 0;
 }
 
 #define PUSH_RBP_MOV_RSP_RBP 0xe5894855
@@ -6206,12 +6175,12 @@ use_cr3:
         if (CRASHDEBUG(1))
                 fprintf(fp, "x86_64_xen_kdump_p2m_create: cr3: %lx\n", xkd->cr3);
 
-        if (!readmem(PTOB(xkd->cr3), PHYSADDR, machdep->machspec->pml4, 
+        if (!readmem(PTOB(xkd->cr3), PHYSADDR, machdep->pgd,
 	    PAGESIZE(), "xen kdump cr3 page", RETURN_ON_ERROR))
                 error(FATAL, "cannot read xen kdump cr3 page\n");
 
         if (CRASHDEBUG(7))
-                x86_64_debug_dump_page(fp, machdep->machspec->pml4,
+                x86_64_debug_dump_page(fp, machdep->pgd,
                         "contents of PML4 page:");
 
 	/*
@@ -6246,7 +6215,7 @@ use_cr3:
         if (CRASHDEBUG(1))
                 fprintf(fp, "phys_to_machine_mapping: %lx\n", kvaddr);
 
-        machdep->last_pgd_read = BADADDR;
+        machdep->last_pud_read = BADADDR;
         machdep->last_pmd_read = BADADDR;
         machdep->last_ptbl_read = BADADDR;
 
@@ -6261,7 +6230,7 @@ use_cr3:
                 fprintf(fp, "\n");
         }
 
-	machdep->last_pgd_read = 0;
+	machdep->last_pud_read = 0;
         machdep->last_ptbl_read = 0;
         machdep->last_pmd_read = 0;
 	pc->curcmd_flags &= ~XEN_MACHINE_ADDR;
@@ -6275,33 +6244,33 @@ static char *
 x86_64_xen_kdump_load_page(ulong kvaddr, char *pgbuf)
 {
 	ulong mfn;
-	ulong *pml4, *pgd, *pmd, *ptep;
+	ulong *pgd, *pud, *pmd, *ptep;
 
-        pml4 = ((ulong *)machdep->machspec->pml4) + pml4_index(kvaddr);
-	mfn = ((*pml4) & PHYSICAL_PAGE_MASK) >> PAGESHIFT();
+        pgd = ((ulong *)machdep->pgd) + pgd_index(kvaddr);
+	mfn = ((*pgd) & PHYSICAL_PAGE_MASK) >> PAGESHIFT();
 
 	if (CRASHDEBUG(3))
 		fprintf(fp, 
-		    "[%lx] pml4: %lx  mfn: %lx  pml4_index: %lx\n", 
-			kvaddr, *pml4, mfn, pml4_index(kvaddr));
+		    "[%lx] pgd: %lx  mfn: %lx  pgd_index: %lx\n",
+			kvaddr, *pgd, mfn, pgd_index(kvaddr));
 
-        if (!readmem(PTOB(mfn), PHYSADDR, machdep->pgd, PAGESIZE(),
+        if (!readmem(PTOB(mfn), PHYSADDR, machdep->pud, PAGESIZE(),
             "xen kdump pud page", RETURN_ON_ERROR))
 		error(FATAL, "cannot read/find pud page\n");
 
-	machdep->last_pgd_read = mfn;
+	machdep->last_pud_read = mfn;
         
         if (CRASHDEBUG(7))
-		x86_64_debug_dump_page(fp, machdep->pgd, 
+		x86_64_debug_dump_page(fp, machdep->pud,
                 	"contents of page upper directory page:");
 
-        pgd = ((ulong *)machdep->pgd) + pgd_index(kvaddr);
-	mfn = ((*pgd) & PHYSICAL_PAGE_MASK) >> PAGESHIFT();
+        pud = ((ulong *)machdep->pud) + pud_index(kvaddr);
+	mfn = ((*pud) & PHYSICAL_PAGE_MASK) >> PAGESHIFT();
 
 	if (CRASHDEBUG(3))
 		fprintf(fp, 
-		    "[%lx] pgd: %lx  mfn: %lx  pgd_index: %lx\n", 
-			kvaddr, *pgd, mfn, pgd_index(kvaddr));
+		    "[%lx] pud: %lx  mfn: %lx  pud_index: %lx\n",
+			kvaddr, *pgd, mfn, pud_index(kvaddr));
 
 	if (!readmem(PTOB(mfn), PHYSADDR, machdep->pmd, PAGESIZE(),
             "xen kdump pmd page", RETURN_ON_ERROR))
@@ -6354,21 +6323,21 @@ static ulong
 x86_64_xen_kdump_page_mfn(ulong kvaddr)
 {
 	ulong mfn;
-	ulong *pml4, *pgd, *pmd, *ptep;
+	ulong *pgd, *pud, *pmd, *ptep;
 
-        pml4 = ((ulong *)machdep->machspec->pml4) + pml4_index(kvaddr);
-	mfn = ((*pml4) & PHYSICAL_PAGE_MASK) >> PAGESHIFT();
+        pgd = ((ulong *)machdep->pgd) + pgd_index(kvaddr);
+	mfn = ((*pgd) & PHYSICAL_PAGE_MASK) >> PAGESHIFT();
 
-        if ((mfn != machdep->last_pgd_read) && 
-	    !readmem(PTOB(mfn), PHYSADDR, machdep->pgd, PAGESIZE(),
+        if ((mfn != machdep->last_pud_read) && 
+	    !readmem(PTOB(mfn), PHYSADDR, machdep->pud, PAGESIZE(),
             "xen kdump pud entry", RETURN_ON_ERROR))
 		error(FATAL, "cannot read/find pud page\n");
-        machdep->last_pgd_read = mfn;
+        machdep->last_pud_read = mfn;
 
-        pgd = ((ulong *)machdep->pgd) + pgd_index(kvaddr);
-	mfn = ((*pgd) & PHYSICAL_PAGE_MASK) >> PAGESHIFT();
+        pud = ((ulong *)machdep->pud) + pud_index(kvaddr);
+	mfn = ((*pud) & PHYSICAL_PAGE_MASK) >> PAGESHIFT();
 
-        if ((mfn != machdep->last_pmd_read) && 
+        if ((mfn != machdep->last_pmd_read) &&
             !readmem(PTOB(mfn), PHYSADDR, machdep->pmd, PAGESIZE(),
             "xen kdump pmd entry", RETURN_ON_ERROR))
                 error(FATAL, "cannot read/find pmd page\n");
@@ -6723,12 +6692,12 @@ x86_64_xendump_p2m_create(struct xendump_data *xd)
 
 	mfn = ctrlreg[3] >> PAGESHIFT();
 
-	if (!xc_core_mfn_to_page(mfn, machdep->machspec->pml4))
+	if (!xc_core_mfn_to_page(mfn, machdep->pgd))
 		error(FATAL, "cannot read/find cr3 page\n");
 
 	if (CRASHDEBUG(7)) 
-		x86_64_debug_dump_page(xd->ofp, machdep->machspec->pml4, 
-                	"contents of PML4 page:");
+		x86_64_debug_dump_page(xd->ofp, machdep->pgd, 
+                	"contents of PGD page:");
 
 	/*
 	 * kernel version <  2.6.27 => end_pfn
@@ -6809,12 +6778,12 @@ x86_64_pvops_xendump_p2m_create(struct xendump_data *xd)
 
 	mfn = ctrlreg[3] >> PAGESHIFT();
 
-	if (!xc_core_mfn_to_page(mfn, machdep->machspec->pml4))
+	if (!xc_core_mfn_to_page(mfn, machdep->pgd))
 		error(FATAL, "cannot read/find cr3 page\n");
 
 	if (CRASHDEBUG(7)) 
-		x86_64_debug_dump_page(xd->ofp, machdep->machspec->pml4, 
-                	"contents of PML4 page:");
+		x86_64_debug_dump_page(xd->ofp, machdep->pgd,
+			"contents of PGD page:");
 
 	/*
 	 * kernel version <  2.6.27 => end_pfn
@@ -6990,32 +6959,32 @@ static char *
 x86_64_xendump_load_page(ulong kvaddr, struct xendump_data *xd)
 {
 	ulong mfn;
-	ulong *pml4, *pgd, *pmd, *ptep;
+	ulong *pgd, *pud, *pmd, *ptep;
 
-        pml4 = ((ulong *)machdep->machspec->pml4) + pml4_index(kvaddr);
-	mfn = ((*pml4) & PHYSICAL_PAGE_MASK) >> PAGESHIFT();
+        pgd = ((ulong *)machdep->pgd) + pgd_index(kvaddr);
+	mfn = ((*pgd) & PHYSICAL_PAGE_MASK) >> PAGESHIFT();
 
 	if (CRASHDEBUG(3))
 		fprintf(xd->ofp, 
-		    "[%lx] pml4: %lx  mfn: %lx  pml4_index: %lx\n", 
-			kvaddr, *pml4, mfn, pml4_index(kvaddr));
+		    "[%lx] pgd: %lx  mfn: %lx  pgd_index: %lx\n",
+			kvaddr, *pgd, mfn, pgd_index(kvaddr));
 
-	if (!xc_core_mfn_to_page(mfn, machdep->pgd))
+	if (!xc_core_mfn_to_page(mfn, machdep->pud))
 		error(FATAL, "cannot read/find pud page\n");
 
-	machdep->last_pgd_read = mfn;
+	machdep->last_pud_read = mfn;
 
         if (CRASHDEBUG(7))
-		x86_64_debug_dump_page(xd->ofp, machdep->pgd, 
+		x86_64_debug_dump_page(xd->ofp, machdep->pud, 
                 	"contents of page upper directory page:");
 
-        pgd = ((ulong *)machdep->pgd) + pgd_index(kvaddr);
-	mfn = ((*pgd) & PHYSICAL_PAGE_MASK) >> PAGESHIFT();
+        pud = ((ulong *)machdep->pud) + pud_index(kvaddr);
+	mfn = ((*pud) & PHYSICAL_PAGE_MASK) >> PAGESHIFT();
 
 	if (CRASHDEBUG(3))
 		fprintf(xd->ofp, 
-		    "[%lx] pgd: %lx  mfn: %lx  pgd_index: %lx\n", 
-			kvaddr, *pgd, mfn, pgd_index(kvaddr));
+		    "[%lx] pud: %lx  mfn: %lx  pud_index: %lx\n",
+			kvaddr, *pud, mfn, pud_index(kvaddr));
 
         if (!xc_core_mfn_to_page(mfn, machdep->pmd))
                 error(FATAL, "cannot read/find pmd page\n");
@@ -7069,18 +7038,18 @@ x86_64_xendump_page_index(ulong kvaddr, struct xendump_data *xd)
 {
         int idx;
 	ulong mfn;
-	ulong *pml4, *pgd, *pmd, *ptep;
+	ulong *pgd, *pud, *pmd, *ptep;
 
-        pml4 = ((ulong *)machdep->machspec->pml4) + pml4_index(kvaddr);
-	mfn = ((*pml4) & PHYSICAL_PAGE_MASK) >> PAGESHIFT();
+        pgd = ((ulong *)machdep->pgd) + pgd_index(kvaddr);
+	mfn = ((*pgd) & PHYSICAL_PAGE_MASK) >> PAGESHIFT();
 
-        if ((mfn != machdep->last_pgd_read) && 
-	    !xc_core_mfn_to_page(mfn, machdep->pgd))
+        if ((mfn != machdep->last_pud_read) && 
+	    !xc_core_mfn_to_page(mfn, machdep->pud))
 		error(FATAL, "cannot read/find pud page\n");
-        machdep->last_pgd_read = mfn;
+        machdep->last_pud_read = mfn;
 
-        pgd = ((ulong *)machdep->pgd) + pgd_index(kvaddr);
-	mfn = ((*pgd) & PHYSICAL_PAGE_MASK) >> PAGESHIFT();
+        pud = ((ulong *)machdep->pud) + pud_index(kvaddr);
+	mfn = ((*pud) & PHYSICAL_PAGE_MASK) >> PAGESHIFT();
 
         if ((mfn != machdep->last_pmd_read) && 
             !xc_core_mfn_to_page(mfn, machdep->pmd))
@@ -7571,20 +7540,17 @@ x86_64_init_hyper(int when)
                 machdep->pageoffset = machdep->pagesize - 1;
                 machdep->pagemask = ~((ulonglong)machdep->pageoffset);
 		machdep->stacksize = machdep->pagesize * 2;
-                if ((machdep->machspec->upml = (char *)malloc(PAGESIZE())) == NULL)
-                        error(FATAL, "cannot malloc upml space.");
                 if ((machdep->pgd = (char *)malloc(PAGESIZE())) == NULL)
                         error(FATAL, "cannot malloc pgd space.");
+		if ((machdep->pud = (char *)malloc(PAGESIZE())) == NULL)
+                        error(FATAL, "cannot malloc pud space.");
                 if ((machdep->pmd = (char *)malloc(PAGESIZE())) == NULL)
                         error(FATAL, "cannot malloc pmd space.");
                 if ((machdep->ptbl = (char *)malloc(PAGESIZE())) == NULL)
                         error(FATAL, "cannot malloc ptbl space.");
-		if ((machdep->machspec->pml4 = 
-			(char *)malloc(PAGESIZE()*2)) == NULL)
-                        error(FATAL, "cannot malloc pml4 space.");
-                machdep->machspec->last_upml_read = 0;
-                machdep->machspec->last_pml4_read = 0;
+
                 machdep->last_pgd_read = 0;
+		machdep->last_pud_read = 0;
                 machdep->last_pmd_read = 0;
                 machdep->last_ptbl_read = 0;
 		machdep->verify_paddr = generic_verify_paddr;
-- 
2.14.3






More information about the Crash-utility mailing list