Blame SOURCES/kexec-tools-2.0.17-makedumpfile-arm64-Add-support-for-ARMv8.2-LVA-52-bi.patch

893e0b
From c301996fc5c671ff9313189f87bd3dd2c38ccb52 Mon Sep 17 00:00:00 2001
893e0b
From: Bhupesh Sharma <bhsharma@redhat.com>
893e0b
Date: Thu, 21 Feb 2019 13:48:49 +0530
893e0b
Subject: [PATCH] makedumpfile/arm64: Add support for ARMv8.2-LVA (52-bit
893e0b
 user-space VA support)
893e0b
893e0b
With ARMv8.2-LVA architecture extension availability, arm64 hardware
893e0b
which supports this extension can support upto 52-bit virtual
893e0b
addresses. It is specially useful for having a 52-bit user-space
893e0b
virtual
893e0b
address space while the kernel can still retain 48-bit virtual
893e0b
addresses.
893e0b
893e0b
Since at the moment we enable the support of this extension in the
893e0b
kernel via a CONFIG flag (CONFIG_ARM64_USER_VA_BITS_52), so there are
893e0b
no clear mechanisms in user-space to determine this CONFIG
893e0b
flag value and use it to determine the user-space VA address range
893e0b
values.
893e0b
893e0b
'makedumpfile' can instead use 'MAX_USER_VA_BITS' value to
893e0b
determine the maximum virtual physical address supported by
893e0b
user-space.
893e0b
If 'MAX_USER_VA_BITS' value is greater than 'VA_BITS' than we are
893e0b
running a use-case where user-space is 52-bit and underlying kernel is
893e0b
still 48-bit. The increased 'PTRS_PER_PGD' value for such cases can
893e0b
then
893e0b
be calculated as is done by the underlying kernel (see kernel file
893e0b
'arch/arm64/include/asm/pgtable-hwdef.h' for details):
893e0b
893e0b
    #define PTRS_PER_PGD          (1 << (MAX_USER_VA_BITS - PGDIR_SHIFT))
893e0b
893e0b
I have sent a kernel patch upstream to add 'MAX_USER_VA_BITS' to
893e0b
vmcoreinfo for arm64 (see [0]).
893e0b
893e0b
This patch is in accordance with ARMv8 Architecture Reference Manual
893e0b
version D.a
893e0b
893e0b
[0]. http://lists.infradead.org/pipermail/kexec/2019-February/022411.html
893e0b
893e0b
Signed-off-by: Bhupesh Sharma <bhsharma@redhat.com>
893e0b
---
893e0b
 arch/arm64.c   | 106 +++++++++++++++++++++++++++++++++++++++++----------------
893e0b
 makedumpfile.c |   2 ++
893e0b
 makedumpfile.h |   1 +
893e0b
 3 files changed, 80 insertions(+), 29 deletions(-)
893e0b
893e0b
diff --git a/makedumpfile-1.6.4/arch/arm64.c b/makedumpfile-1.6.4/arch/arm64.c
893e0b
index 053519359cbc..e3bead4bb103 100644
893e0b
--- a/makedumpfile-1.6.4/arch/arm64.c
893e0b
+++ b/makedumpfile-1.6.4/arch/arm64.c
893e0b
@@ -41,6 +41,7 @@ typedef struct {
893e0b
 
893e0b
 static int pgtable_level;
893e0b
 static int va_bits;
893e0b
+static int max_user_va_bits;
893e0b
 static unsigned long kimage_voffset;
893e0b
 
893e0b
 #define SZ_4K			(4 * 1024)
893e0b
@@ -61,7 +62,7 @@ static unsigned long kimage_voffset;
893e0b
 
893e0b
 #define PAGE_MASK		(~(PAGESIZE() - 1))
893e0b
 #define PGDIR_SHIFT		((PAGESHIFT() - 3) * pgtable_level + 3)
893e0b
-#define PTRS_PER_PGD		(1 << (va_bits - PGDIR_SHIFT))
893e0b
+#define PTRS_PER_PGD		(1 << ((max_user_va_bits) - PGDIR_SHIFT))
893e0b
 #define PUD_SHIFT		get_pud_shift_arm64()
893e0b
 #define PUD_SIZE		(1UL << PUD_SHIFT)
893e0b
 #define PUD_MASK		(~(PUD_SIZE - 1))
893e0b
@@ -284,14 +285,84 @@ get_stext_symbol(void)
893e0b
 	return(found ? kallsym : FALSE);
893e0b
 }
893e0b
 
893e0b
+static int
893e0b
+get_va_bits_from_stext_arm64(void)
893e0b
+{
893e0b
+	ulong _stext;
893e0b
+
893e0b
+	_stext = get_stext_symbol();
893e0b
+	if (!_stext) {
893e0b
+		ERRMSG("Can't get the symbol of _stext.\n");
893e0b
+		return FALSE;
893e0b
+	}
893e0b
+
893e0b
+	/* Derive va_bits as per arch/arm64/Kconfig */
893e0b
+	if ((_stext & PAGE_OFFSET_36) == PAGE_OFFSET_36) {
893e0b
+		va_bits = 36;
893e0b
+	} else if ((_stext & PAGE_OFFSET_39) == PAGE_OFFSET_39) {
893e0b
+		va_bits = 39;
893e0b
+	} else if ((_stext & PAGE_OFFSET_42) == PAGE_OFFSET_42) {
893e0b
+		va_bits = 42;
893e0b
+	} else if ((_stext & PAGE_OFFSET_47) == PAGE_OFFSET_47) {
893e0b
+		va_bits = 47;
893e0b
+	} else if ((_stext & PAGE_OFFSET_48) == PAGE_OFFSET_48) {
893e0b
+		va_bits = 48;
893e0b
+	} else {
893e0b
+		ERRMSG("Cannot find a proper _stext for calculating VA_BITS\n");
893e0b
+		return FALSE;
893e0b
+	}
893e0b
+
893e0b
+	DEBUG_MSG("va_bits      : %d(_stext)\n", va_bits);
893e0b
+
893e0b
+	return TRUE;
893e0b
+}
893e0b
+
893e0b
+static void
893e0b
+get_page_offset_arm64(void)
893e0b
+{
893e0b
+	info->page_offset = (0xffffffffffffffffUL) << (va_bits - 1);
893e0b
+
893e0b
+	DEBUG_MSG("page_offset  : %lx\n", info->page_offset);
893e0b
+}
893e0b
+
893e0b
 int
893e0b
 get_machdep_info_arm64(void)
893e0b
 {
893e0b
 	/* Check if va_bits is still not initialized. If still 0, call
893e0b
 	 * get_versiondep_info() to initialize the same.
893e0b
 	 */
893e0b
+	if (NUMBER(VA_BITS) != NOT_FOUND_NUMBER) {
893e0b
+		va_bits = NUMBER(VA_BITS);
893e0b
+		DEBUG_MSG("va_bits    : %d (vmcoreinfo)\n",
893e0b
+				va_bits);
893e0b
+	}
893e0b
+
893e0b
+	/* Check if va_bits is still not initialized. If still 0, call
893e0b
+	 * get_versiondep_info() to initialize the same from _stext
893e0b
+	 * symbol.
893e0b
+	 */
893e0b
+
893e0b
 	if (!va_bits)
893e0b
-		get_versiondep_info_arm64();
893e0b
+		if (get_va_bits_from_stext_arm64() == ERROR)
893e0b
+			return FALSE;
893e0b
+
893e0b
+	get_page_offset_arm64();
893e0b
+
893e0b
+	if (NUMBER(MAX_USER_VA_BITS) != NOT_FOUND_NUMBER) {
893e0b
+		max_user_va_bits = NUMBER(MAX_USER_VA_BITS);
893e0b
+		DEBUG_MSG("max_user_va_bits : %d (vmcoreinfo)\n",
893e0b
+				max_user_va_bits);
893e0b
+	}
893e0b
+
893e0b
+	/* Check if max_user_va_bits is still not initialized.
893e0b
+	 * If still 0, its not available in vmcoreinfo and its
893e0b
+	 * safe to initialize it with va_bits.
893e0b
+	 */
893e0b
+	if (!max_user_va_bits) {
893e0b
+		max_user_va_bits = va_bits;
893e0b
+		DEBUG_MSG("max_user_va_bits : %d (default = va_bits)\n",
893e0b
+				max_user_va_bits);
893e0b
+	}
893e0b
 
893e0b
 	if (!calculate_plat_config()) {
893e0b
 		ERRMSG("Can't determine platform config values\n");
893e0b
@@ -330,34 +401,11 @@ get_xen_info_arm64(void)
893e0b
 int
893e0b
 get_versiondep_info_arm64(void)
893e0b
 {
893e0b
-	ulong _stext;
893e0b
-
893e0b
-	_stext = get_stext_symbol();
893e0b
-	if (!_stext) {
893e0b
-		ERRMSG("Can't get the symbol of _stext.\n");
893e0b
-		return FALSE;
893e0b
-	}
893e0b
-
893e0b
-	/* Derive va_bits as per arch/arm64/Kconfig */
893e0b
-	if ((_stext & PAGE_OFFSET_36) == PAGE_OFFSET_36) {
893e0b
-		va_bits = 36;
893e0b
-	} else if ((_stext & PAGE_OFFSET_39) == PAGE_OFFSET_39) {
893e0b
-		va_bits = 39;
893e0b
-	} else if ((_stext & PAGE_OFFSET_42) == PAGE_OFFSET_42) {
893e0b
-		va_bits = 42;
893e0b
-	} else if ((_stext & PAGE_OFFSET_47) == PAGE_OFFSET_47) {
893e0b
-		va_bits = 47;
893e0b
-	} else if ((_stext & PAGE_OFFSET_48) == PAGE_OFFSET_48) {
893e0b
-		va_bits = 48;
893e0b
-	} else {
893e0b
-		ERRMSG("Cannot find a proper _stext for calculating VA_BITS\n");
893e0b
-		return FALSE;
893e0b
-	}
893e0b
-
893e0b
-	info->page_offset = (0xffffffffffffffffUL) << (va_bits - 1);
893e0b
+	if (!va_bits)
893e0b
+		if (get_va_bits_from_stext_arm64() == ERROR)
893e0b
+			return FALSE;
893e0b
 
893e0b
-	DEBUG_MSG("va_bits      : %d\n", va_bits);
893e0b
-	DEBUG_MSG("page_offset  : %lx\n", info->page_offset);
893e0b
+	get_page_offset_arm64();
893e0b
 
893e0b
 	return TRUE;
893e0b
 }
893e0b
diff --git a/makedumpfile-1.6.4/makedumpfile.c b/makedumpfile-1.6.4/makedumpfile.c
893e0b
index b7c1c01251bf..ccf7eb4408ba 100644
893e0b
--- a/makedumpfile-1.6.4/makedumpfile.c
893e0b
+++ b/makedumpfile-1.6.4/makedumpfile.c
893e0b
@@ -2291,6 +2291,7 @@ write_vmcoreinfo_data(void)
893e0b
 
893e0b
 	WRITE_NUMBER("HUGETLB_PAGE_DTOR", HUGETLB_PAGE_DTOR);
893e0b
 #ifdef __aarch64__
893e0b
+	WRITE_NUMBER("MAX_USER_VA_BITS", MAX_USER_VA_BITS);
893e0b
 	WRITE_NUMBER("VA_BITS", VA_BITS);
893e0b
 	WRITE_NUMBER_UNSIGNED("PHYS_OFFSET", PHYS_OFFSET);
893e0b
 	WRITE_NUMBER_UNSIGNED("kimage_voffset", kimage_voffset);
893e0b
@@ -2694,6 +2695,7 @@ read_vmcoreinfo(void)
893e0b
 	READ_NUMBER("PAGE_BUDDY_MAPCOUNT_VALUE", PAGE_BUDDY_MAPCOUNT_VALUE);
893e0b
 	READ_NUMBER("phys_base", phys_base);
893e0b
 #ifdef __aarch64__
893e0b
+	READ_NUMBER("MAX_USER_VA_BITS", MAX_USER_VA_BITS);
893e0b
 	READ_NUMBER("VA_BITS", VA_BITS);
893e0b
 	READ_NUMBER_UNSIGNED("PHYS_OFFSET", PHYS_OFFSET);
893e0b
 	READ_NUMBER_UNSIGNED("kimage_voffset", kimage_voffset);
893e0b
diff --git a/makedumpfile-1.6.4/makedumpfile.h b/makedumpfile-1.6.4/makedumpfile.h
893e0b
index d49f1f1fc1a9..3fa810e0bb40 100644
893e0b
--- a/makedumpfile-1.6.4/makedumpfile.h
893e0b
+++ b/makedumpfile-1.6.4/makedumpfile.h
893e0b
@@ -1933,6 +1933,7 @@ struct number_table {
893e0b
 	long    HUGETLB_PAGE_DTOR;
893e0b
 	long	phys_base;
893e0b
 #ifdef __aarch64__
893e0b
+	long 	MAX_USER_VA_BITS;
893e0b
 	long 	VA_BITS;
893e0b
 	unsigned long	PHYS_OFFSET;
893e0b
 	unsigned long	kimage_voffset;
893e0b
-- 
893e0b
2.7.4
893e0b