Blame makedumpfile-1.7.2-0005-sadump-fix-failure-of-reading-memory-when-5-le.patch

2ba6f6
From 58553ad03187f0cf208d6c4a0dc026c6338e5edd Mon Sep 17 00:00:00 2001
2ba6f6
From: "Daisuke Hatayama (Fujitsu)" <d.hatayama@fujitsu.com>
2ba6f6
Date: Wed, 29 Mar 2023 12:44:10 +0000
2ba6f6
Subject: [PATCH 5/7] [PATCH] sadump: fix failure of reading memory when
2ba6f6
 5-level paging is enabled
2ba6f6
2ba6f6
makedumpfile fails as follows for memory dumps collected by sadump
2ba6f6
when 5-level paging is enabled on the corresponding systems:
2ba6f6
2ba6f6
    # makedumpfile -l -d 31 -x ./vmlinux ./dump.sadump dump.sadump-ld31
2ba6f6
    __vtop4_x86_64: Can't get a valid pgd.
2ba6f6
    ...snip...
2ba6f6
    __vtop4_x86_64: Can't get a valid pgd.
2ba6f6
    calc_kaslr_offset: failed to calculate kaslr_offset and phys_base; default to 0
2ba6f6
    __vtop4_x86_64: Can't get a valid pgd.
2ba6f6
    readmem: Can't convert a virtual address(ffffffff82fce960) to physical address.
2ba6f6
    readmem: type_addr: 0, addr:ffffffff82fce960, size:1024
2ba6f6
    cpu_online_mask_init: Can't read cpu_online_mask memory.
2ba6f6
2ba6f6
    makedumpfile Failed.
2ba6f6
2ba6f6
This is because 5-level paging support has not been done yet for
2ba6f6
sadump; the work of the 5-level paging support was done by the commit
2ba6f6
30a3214a7193e94c551c0cebda5918a72a35c589 (PATCH 4/4 arch/x86_64: Add
2ba6f6
5-level paging support) but that was focused on the core part only.
2ba6f6
2ba6f6
Having said that, most of things has already been finished in the
2ba6f6
commit. What needs to be newly added for sadump is just how to check
2ba6f6
if 5-level paging is enabled for a given memory dump.
2ba6f6
2ba6f6
For that purpose, let's refer to CR4.LA57, bit 12 of CR4, representing
2ba6f6
whether 5-level paging is enabled or not. We can do this because
2ba6f6
memory dumps collected by sadump have SMRAM as note information and
2ba6f6
they include CR4 together with the other control registers.
2ba6f6
2ba6f6
Signed-off-by: HATAYAMA Daisuke <d.hatayama@fujitsu.com>
2ba6f6
---
2ba6f6
 sadump_info.c | 4 ++++
2ba6f6
 1 file changed, 4 insertions(+)
2ba6f6
2ba6f6
diff --git a/makedumpfile-1.7.2/sadump_info.c b/makedumpfile-1.7.2/sadump_info.c
2ba6f6
index adfa8dc..2c44068 100644
2ba6f6
--- a/makedumpfile-1.7.2/sadump_info.c
2ba6f6
+++ b/makedumpfile-1.7.2/sadump_info.c
2ba6f6
@@ -1362,6 +1362,7 @@ static int linux_banner_sanity_check(ulong cr3)
2ba6f6
 #define PTI_USER_PGTABLE_BIT		(info->page_shift)
2ba6f6
 #define PTI_USER_PGTABLE_MASK		(1 << PTI_USER_PGTABLE_BIT)
2ba6f6
 #define CR3_PCID_MASK			0xFFFull
2ba6f6
+#define CR4_LA57			(1 << 12)
2ba6f6
 int
2ba6f6
 calc_kaslr_offset(void)
2ba6f6
 {
2ba6f6
@@ -1397,6 +1398,8 @@ calc_kaslr_offset(void)
2ba6f6
 		else
2ba6f6
 			cr3 = smram.Cr3 & ~CR3_PCID_MASK;
2ba6f6
 
2ba6f6
+		NUMBER(pgtable_l5_enabled) = !!(smram.Cr4 & CR4_LA57);
2ba6f6
+
2ba6f6
 		/* Convert virtual address of IDT table to physical address */
2ba6f6
 		idtr_paddr = vtop4_x86_64_pagetable(idtr, cr3);
2ba6f6
 		if (idtr_paddr == NOT_PADDR) {
2ba6f6
@@ -1417,6 +1420,7 @@ calc_kaslr_offset(void)
2ba6f6
 
2ba6f6
 		DEBUG_MSG("sadump: idtr=%" PRIx64 "\n", idtr);
2ba6f6
 		DEBUG_MSG("sadump: cr3=%" PRIx64 "\n", cr3);
2ba6f6
+		DEBUG_MSG("sadump: cr4=%" PRIx32 "\n", smram.Cr4);
2ba6f6
 		DEBUG_MSG("sadump: idtr(phys)=%" PRIx64 "\n", idtr_paddr);
2ba6f6
 		DEBUG_MSG("sadump: devide_error(vmlinux)=%lx\n",
2ba6f6
 			  divide_error_vmlinux);
2ba6f6
-- 
2ba6f6
2.33.1
2ba6f6