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

893e0b
From: Bhupesh Sharma <bhsharma@redhat.com>
603de6
Date: Wed, 6 Feb 2019 12:31:29 +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
603de6
addresses. It is specially useful for having a 52-bit user-space 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
603de6
determine the maximum virtual physical address supported by 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
603de6
still 48-bit. The increased 'PTRS_PER_PGD' value for such cases can 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
603de6
  #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
603de6
[0].
603de6
http://lists.infradead.org/pipermail/kexec/2019-February/022411.html
893e0b
893e0b
Signed-off-by: Bhupesh Sharma <bhsharma@redhat.com>
7a865b
893e0b
---
603de6
 arch/arm64.c   | 109 ++++++++++++++++++++++++++++++++++++++++++---------------
893e0b
 makedumpfile.c |   2 ++
893e0b
 makedumpfile.h |   1 +
603de6
 3 files changed, 83 insertions(+), 29 deletions(-)
893e0b
f8bec6
diff --git a/makedumpfile-1.6.7/arch/arm64.c b/makedumpfile-1.6.7/arch/arm64.c
7a865b
index 0535193..5fcf59d 100644
f8bec6
--- a/makedumpfile-1.6.7/arch/arm64.c
f8bec6
+++ b/makedumpfile-1.6.7/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))
603de6
@@ -73,6 +74,10 @@ static unsigned long kimage_voffset;
603de6
 #define PTRS_PER_PMD		PTRS_PER_PTE
603de6
 
603de6
 #define PAGE_PRESENT		(1 << 0)
603de6
+
603de6
+/*
603de6
+ * Section address mask and size definitions.
603de6
+ */
603de6
 #define SECTIONS_SIZE_BITS	30
603de6
 /* Highest possible physical address supported */
603de6
 #define PHYS_MASK_SHIFT		48
603de6
@@ -284,14 +289,83 @@ 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
+
603de6
+	DEBUG_MSG("va_bits      : %d\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
 	if (!va_bits)
893e0b
-		get_versiondep_info_arm64();
893e0b
+		if (get_va_bits_from_stext_arm64() == ERROR)
603de6
+			return ERROR;
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");
603de6
@@ -330,34 +404,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)
603de6
+			return ERROR;
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
 }
f8bec6
diff --git a/makedumpfile-1.6.7/makedumpfile.c b/makedumpfile-1.6.7/makedumpfile.c
7a865b
index d76a435..c8906b5 100644
f8bec6
--- a/makedumpfile-1.6.7/makedumpfile.c
f8bec6
+++ b/makedumpfile-1.6.7/makedumpfile.c
7a865b
@@ -2313,6 +2313,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);
7a865b
@@ -2719,6 +2720,7 @@ read_vmcoreinfo(void)
893e0b
 	READ_NUMBER("phys_base", phys_base);
7a865b
 	READ_NUMBER("KERNEL_IMAGE_SIZE", KERNEL_IMAGE_SIZE);
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);
f8bec6
diff --git a/makedumpfile-1.6.7/makedumpfile.h b/makedumpfile-1.6.7/makedumpfile.h
7a865b
index 24b2f69..cccb52a 100644
f8bec6
--- a/makedumpfile-1.6.7/makedumpfile.h
f8bec6
+++ b/makedumpfile-1.6.7/makedumpfile.h
7a865b
@@ -1937,6 +1937,7 @@ struct number_table {
893e0b
 	long	phys_base;
7a865b
 	long	KERNEL_IMAGE_SIZE;
893e0b
 #ifdef __aarch64__
893e0b
+	long 	MAX_USER_VA_BITS;
893e0b
 	long 	VA_BITS;
893e0b
 	unsigned long	PHYS_OFFSET;
893e0b
 	unsigned long	kimage_voffset;
893e0b
-- 
7a865b
2.7.5
893e0b