Blame SOURCES/kexec-tools-2.0.15-makedumpfile-sadump-Fix-a-problem-of-PTI-enabled-kernel.patch

06c2a2
From: Takao Indoh <indou.takao@jp.fujitsu.com>
06c2a2
To: ats-kumagai@wm.jp.nec.com, d.hatayama@jp.fujitsu.com
06c2a2
Subject: [makedumpfile PATCH] sadump: Fix a problem of PTI enabled kernel
06c2a2
Date: Fri, 26 Jan 2018 09:22:26 +0900
06c2a2
Cc: kexec@lists.infradead.org
06c2a2
MIME-Version: 1.0
06c2a2
Content-Transfer-Encoding: 8bit
06c2a2
Content-Type: text/plain; charset=utf-8
06c2a2
06c2a2
This patch fixes a problme that a dumpfile of sadump cannot be handled by
06c2a2
makedumpfile when Page Table Isolation(PTI) is enabled.
06c2a2
06c2a2
When PTI is enabled, bit 12 of CR3 register is used to split user space and
06c2a2
kernel space. Also bit 11:0 is used for Process Context IDentifiers(PCID).  To
06c2a2
open a dump file of sadump, a value of CR3 is used to calculate KASLR offset and
06c2a2
phys_base, therefore this patch fixes to mask CR3 register value collectly for
06c2a2
PTI enabled kernel.
06c2a2
06c2a2
Signed-off-by: Takao Indoh <indou.takao@jp.fujitsu.com>
06c2a2
---
06c2a2
 makedumpfile.c | 2 ++
06c2a2
 makedumpfile.h | 2 ++
06c2a2
 sadump_info.c  | 9 ++++++++-
06c2a2
 3 files changed, 12 insertions(+), 1 deletion(-)
06c2a2
06c2a2
diff --git a/makedumpfile-1.6.2/makedumpfile.c b/makedumpfile-1.6.2/makedumpfile.c
06c2a2
index 64b404a..247a056 100644
06c2a2
--- a/makedumpfile-1.6.2/makedumpfile.c
06c2a2
+++ b/makedumpfile-1.6.2/makedumpfile.c
06c2a2
@@ -1557,6 +1557,8 @@ get_symbol_info(void)
06c2a2
 	SYMBOL_INIT(divide_error, "divide_error");
06c2a2
 	SYMBOL_INIT(idt_table, "idt_table");
06c2a2
 	SYMBOL_INIT(saved_command_line, "saved_command_line");
06c2a2
+	SYMBOL_INIT(pti_init, "pti_init");
06c2a2
+	SYMBOL_INIT(kaiser_init, "kaiser_init");
06c2a2
 
06c2a2
 	return TRUE;
06c2a2
 }
06c2a2
diff --git a/makedumpfile-1.6.2/makedumpfile.h b/makedumpfile-1.6.2/makedumpfile.h
06c2a2
index 57cf4d9..8ee4d29 100644
06c2a2
--- a/makedumpfile-1.6.2/makedumpfile.h
06c2a2
+++ b/makedumpfile-1.6.2/makedumpfile.h
06c2a2
@@ -1608,6 +1608,8 @@ struct symbol_table {
06c2a2
 	unsigned long long	divide_error;
06c2a2
 	unsigned long long	idt_table;
06c2a2
 	unsigned long long	saved_command_line;
06c2a2
+	unsigned long long	pti_init;
06c2a2
+	unsigned long long	kaiser_init;
06c2a2
 
06c2a2
 	/*
06c2a2
 	 * symbols on ppc64 arch
06c2a2
diff --git a/makedumpfile-1.6.2/sadump_info.c b/makedumpfile-1.6.2/sadump_info.c
06c2a2
index 148d4ba..dd50d48 100644
06c2a2
--- a/makedumpfile-1.6.2/sadump_info.c
06c2a2
+++ b/makedumpfile-1.6.2/sadump_info.c
06c2a2
@@ -1362,6 +1362,9 @@ finish:
06c2a2
  *    kernel. Retrieve vmcoreinfo from address of "elfcorehdr=" and
06c2a2
  *    get kaslr_offset and phys_base from vmcoreinfo.
06c2a2
  */
06c2a2
+#define PTI_USER_PGTABLE_BIT		(info->page_shift)
06c2a2
+#define PTI_USER_PGTABLE_MASK		(1 << PTI_USER_PGTABLE_BIT)
06c2a2
+#define CR3_PCID_MASK			0xFFFull
06c2a2
 int
06c2a2
 calc_kaslr_offset(void)
06c2a2
 {
06c2a2
@@ -1389,7 +1392,11 @@ calc_kaslr_offset(void)
06c2a2
 	}
06c2a2
 
06c2a2
 	idtr = ((uint64_t)smram.IdtUpper)<<32 | (uint64_t)smram.IdtLower;
06c2a2
-	cr3 = smram.Cr3;
06c2a2
+	if ((SYMBOL(pti_init) != NOT_FOUND_SYMBOL) ||
06c2a2
+	    (SYMBOL(kaiser_init) != NOT_FOUND_SYMBOL))
06c2a2
+		cr3 = smram.Cr3 & ~(CR3_PCID_MASK|PTI_USER_PGTABLE_MASK);
06c2a2
+	else
06c2a2
+		cr3 = smram.Cr3 & ~CR3_PCID_MASK;
06c2a2
 
06c2a2
 	/* Convert virtual address of IDT table to physical address */
06c2a2
 	if ((idtr_paddr = vtop4_x86_64_pagetable(idtr, cr3)) == NOT_PADDR)
06c2a2
-- 
06c2a2
1.8.3.1
06c2a2
06c2a2
06c2a2
06c2a2
_______________________________________________
06c2a2
kexec mailing list
06c2a2
kexec@lists.infradead.org
06c2a2
http://lists.infradead.org/mailman/listinfo/kexec