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

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