File makedumpfile-Revert-x86_64-translate-all-VA-to-PA-using-pgt.patch of Package makedumpfile.8642

From: Petr Tesarik <ptesarik@suse.com>
Date: Thu, 21 Dec 2017 13:39:37 +0100
Subject: Revert "x86_64: translate all VA to PA using page table values"
References: bsc#1068925, bsc#1099121
Upstream: never, upstream needs newer kernel

This reverts commit c41e33c28bdefb2084ba8758082d315a2bfa6033.
---
 arch/x86_64.c  |   36 ++++++++++++++++++++++++++++++++++--
 makedumpfile.h |    4 ++--
 2 files changed, 36 insertions(+), 4 deletions(-)

--- a/arch/x86_64.c
+++ b/arch/x86_64.c
@@ -224,9 +224,9 @@ vtop4_x86_64(unsigned long vaddr)
 	/*
 	 * Get PGD.
 	 */
-	page_dir = SYMBOL(init_level4_pgt) - __START_KERNEL_map + info->phys_base;
+	page_dir  = SYMBOL(init_level4_pgt);
 	page_dir += pml4_index(vaddr) * sizeof(unsigned long);
-	if (!readmem(PADDR, page_dir, &pml4, sizeof pml4)) {
+	if (!readmem(VADDR, page_dir, &pml4, sizeof pml4)) {
 		ERRMSG("Can't get pml4 (page_dir:%lx).\n", page_dir);
 		return NOT_PADDR;
 	}
@@ -297,6 +297,38 @@ vtop4_x86_64(unsigned long vaddr)
 	return (pte & ENTRY_MASK) + PAGEOFFSET(vaddr);
 }
 
+unsigned long long
+vaddr_to_paddr_x86_64(unsigned long vaddr)
+{
+	unsigned long phys_base;
+	unsigned long long paddr;
+
+	/*
+	 * Check the relocatable kernel.
+	 */
+	if (SYMBOL(phys_base) != NOT_FOUND_SYMBOL)
+		phys_base = info->phys_base;
+	else
+		phys_base = 0;
+
+	if (is_vmalloc_addr_x86_64(vaddr)) {
+		if ((paddr = vtop4_x86_64(vaddr)) == NOT_PADDR) {
+			ERRMSG("Can't convert a virtual address(%lx) to " \
+			    "physical address.\n", vaddr);
+			return NOT_PADDR;
+		}
+	} else if (vaddr >= __START_KERNEL_map) {
+		paddr = vaddr - __START_KERNEL_map + phys_base;
+
+	} else {
+		if (is_xen_memory())
+			paddr = vaddr - PAGE_OFFSET_XEN_DOM0;
+		else
+			paddr = vaddr - PAGE_OFFSET;
+	}
+	return paddr;
+}
+
 /*
  * for Xen extraction
  */
--- a/makedumpfile.h
+++ b/makedumpfile.h
@@ -878,12 +878,12 @@ int is_vmalloc_addr_x86_64(ulong vaddr);
 int get_phys_base_x86_64(void);
 int get_machdep_info_x86_64(void);
 int get_versiondep_info_x86_64(void);
-unsigned long long vtop4_x86_64(unsigned long vaddr);
+unsigned long long vaddr_to_paddr_x86_64(unsigned long vaddr);
 #define find_vmemmap()		find_vmemmap_x86_64()
 #define get_phys_base()		get_phys_base_x86_64()
 #define get_machdep_info()	get_machdep_info_x86_64()
 #define get_versiondep_info()	get_versiondep_info_x86_64()
-#define vaddr_to_paddr(X)	vtop4_x86_64(X)
+#define vaddr_to_paddr(X)	vaddr_to_paddr_x86_64(X)
 #define is_phys_addr(X)		(!is_vmalloc_addr_x86_64(X))
 #endif /* x86_64 */
 
openSUSE Build Service is sponsored by