From 90eaa10550ca74f67589eebd647fe8791e4e24ee Mon Sep 17 00:00:00 2001
From: Patrick Daly <pdaly@codeaurora.org>
Date: Thu, 23 Mar 2017 14:14:22 -0700
Subject: [PATCH] lrdp-v2: Fixe vmemmap offset when kaslr is enabled for arm64

KASLR randomizes the address of the linear kernel mapping, which
causes the starting address of vmemmap to be similarly randomized.
Use the value of memstart_addr in calculations instead of phys_offset.

Change-Id: I905c0f50e011f85871ca2406b9a5d78afe4f0dc6
---
 linux-ramdump-parser-v2/mm.py | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/linux-ramdump-parser-v2/mm.py b/linux-ramdump-parser-v2/mm.py
index ec55f5d..4ac9c68 100644
--- a/linux-ramdump-parser-v2/mm.py
+++ b/linux-ramdump-parser-v2/mm.py
@@ -152,22 +152,27 @@ def get_vmemmap(ramdump):
     spsize = ramdump.sizeof('struct page')
     vmemmap_size = bitops.align((1 << (va_bits - page_shift)) * spsize,
                                 pud_size)
-    pfn_offset = (ramdump.phys_offset >> page_shift)
-    offset = pfn_offset * spsize
+
+    memstart_addr = ramdump.read_s64('memstart_addr')
+    page_section_mask = ~((1 << 18) - 1)
+    memstart_offset = (memstart_addr >> page_shift) & page_section_mask
+    memstart_offset *= spsize
+
     if (ramdump.kernel_version < (3, 18, 31)):
-        vmalloc_end = ramdump.page_offset - pud_size - vmemmap_size
         # vmalloc_end = 0xFFFFFFBC00000000
+        vmemmap = ramdump.page_offset - pud_size - vmemmap_size
     elif (ramdump.kernel_version < (4, 9, 0)):
         # for version >= 3.18.31,
         # vmemmap is shifted to base addr (0x80000000) pfn.
-        vmalloc_end = ramdump.page_offset - pud_size - vmemmap_size - offset
+        vmemmap = (ramdump.page_offset - pud_size - vmemmap_size -
+                   memstart_offset)
     else:
         # for version >= 4.9.0,
+        # vmemmap_size = ( 1 << (39 - 12 - 1 + 6))
         struct_page_max_shift = 6
-        #vmemmap_size = ( 1 << (39 - 12 - 1 + 6))
         vmemmap_size = ( 1 << (va_bits - page_shift - 1 + struct_page_max_shift))
-        vmalloc_end = ramdump.page_offset - vmemmap_size - offset
-    return vmalloc_end
+        vmemmap = ramdump.page_offset - vmemmap_size - memstart_offset
+    return vmemmap
 
 
 def page_to_pfn_vmemmap(ramdump, page):
-- 
GitLab