Blame SOURCES/0016-arm64-use-TCR_EL1_T1SZ-to-get-the-correct-info-if-va.patch

56ae9b
From 28a41ec7a471474094d8ab39f3a69b44d0f9ebcf Mon Sep 17 00:00:00 2001
56ae9b
From: Huang Shijie <shijie@os.amperecomputing.com>
56ae9b
Date: Mon, 22 Aug 2022 09:29:32 +0000
56ae9b
Subject: [PATCH 16/28] arm64: use TCR_EL1_T1SZ to get the correct info if
56ae9b
 vabits_actual is missing
56ae9b
56ae9b
After kernel commit 0d9b1ffefabe ("arm64: mm: make vabits_actual a build
56ae9b
time constant if possible"), the vabits_actual is not compiled to kernel
56ae9b
symbols when "VA_BITS > 48" is false.
56ae9b
56ae9b
So the crash will not find the vabits_actual symbol, and it will fail
56ae9b
in the end like this:
56ae9b
56ae9b
  # ./crash
56ae9b
  ...
56ae9b
  WARNING: VA_BITS: calculated: 46  vmcoreinfo: 48
56ae9b
  crash: invalid kernel virtual address: ffff88177ffff000  type: "pud page"
56ae9b
56ae9b
This patch introduces the arm64_set_va_bits_by_tcr(), and if crash cannot
56ae9b
find vabits_actual symbol, it will use the TCR_EL1_T1SZ register to get
56ae9b
the correct VA_BITS_ACTUAL/VA_BITS/VA_START.
56ae9b
56ae9b
Tested this patch with:
56ae9b
  1.) the live mode with /proc/kcore
56ae9b
  2.) the kdump file with /proc/vmcore.
56ae9b
56ae9b
Signed-off-by: Huang Shijie <shijie@os.amperecomputing.com>
56ae9b
Signed-off-by: Lianbo Jiang <lijiang@redhat.com>
56ae9b
---
56ae9b
 arm64.c | 51 ++++++++++++++++++++++++++++++++++-----------------
56ae9b
 1 file changed, 34 insertions(+), 17 deletions(-)
56ae9b
56ae9b
diff --git a/arm64.c b/arm64.c
56ae9b
index b6b7aa11f4fe..c3e26a371a61 100644
56ae9b
--- a/arm64.c
56ae9b
+++ b/arm64.c
56ae9b
@@ -4586,6 +4586,36 @@ arm64_IS_VMALLOC_ADDR(ulong vaddr)
56ae9b
                 (vaddr >= ms->modules_vaddr && vaddr <= ms->modules_end));
56ae9b
 }
56ae9b
 
56ae9b
+/* Return TRUE if we succeed, return FALSE on failure. */
56ae9b
+static int
56ae9b
+arm64_set_va_bits_by_tcr(void)
56ae9b
+{
56ae9b
+	ulong value;
56ae9b
+	char *string;
56ae9b
+
56ae9b
+	if ((string = pc->read_vmcoreinfo("NUMBER(TCR_EL1_T1SZ)")) ||
56ae9b
+	    (string = pc->read_vmcoreinfo("NUMBER(tcr_el1_t1sz)"))) {
56ae9b
+		/* See ARMv8 ARM for the description of
56ae9b
+		 * TCR_EL1.T1SZ and how it can be used
56ae9b
+		 * to calculate the vabits_actual
56ae9b
+		 * supported by underlying kernel.
56ae9b
+		 *
56ae9b
+		 * Basically:
56ae9b
+		 * vabits_actual = 64 - T1SZ;
56ae9b
+		 */
56ae9b
+		value = 64 - strtoll(string, NULL, 0);
56ae9b
+		if (CRASHDEBUG(1))
56ae9b
+			fprintf(fp,  "vmcoreinfo : vabits_actual: %ld\n", value);
56ae9b
+		free(string);
56ae9b
+		machdep->machspec->VA_BITS_ACTUAL = value;
56ae9b
+		machdep->machspec->VA_BITS = value;
56ae9b
+		machdep->machspec->VA_START = _VA_START(machdep->machspec->VA_BITS_ACTUAL);
56ae9b
+		return TRUE;
56ae9b
+	}
56ae9b
+
56ae9b
+	return FALSE;
56ae9b
+}
56ae9b
+
56ae9b
 static void 
56ae9b
 arm64_calc_VA_BITS(void)
56ae9b
 {
56ae9b
@@ -4616,23 +4646,8 @@ arm64_calc_VA_BITS(void)
56ae9b
 		} else if (ACTIVE())
56ae9b
 			error(FATAL, "cannot determine VA_BITS_ACTUAL: please use /proc/kcore\n");
56ae9b
 		else {
56ae9b
-			if ((string = pc->read_vmcoreinfo("NUMBER(TCR_EL1_T1SZ)")) ||
56ae9b
-			    (string = pc->read_vmcoreinfo("NUMBER(tcr_el1_t1sz)"))) {
56ae9b
-				/* See ARMv8 ARM for the description of
56ae9b
-				 * TCR_EL1.T1SZ and how it can be used
56ae9b
-				 * to calculate the vabits_actual
56ae9b
-				 * supported by underlying kernel.
56ae9b
-				 *
56ae9b
-				 * Basically:
56ae9b
-				 * vabits_actual = 64 - T1SZ;
56ae9b
-				 */
56ae9b
-				value = 64 - strtoll(string, NULL, 0);
56ae9b
-				if (CRASHDEBUG(1))
56ae9b
-					fprintf(fp,  "vmcoreinfo : vabits_actual: %ld\n", value);
56ae9b
-				free(string);
56ae9b
-				machdep->machspec->VA_BITS_ACTUAL = value;
56ae9b
-				machdep->machspec->VA_BITS = value;
56ae9b
-				machdep->machspec->VA_START = _VA_START(machdep->machspec->VA_BITS_ACTUAL);
56ae9b
+			if (arm64_set_va_bits_by_tcr()) {
56ae9b
+				/* nothing */
56ae9b
 			} else if (machdep->machspec->VA_BITS_ACTUAL) {
56ae9b
 				machdep->machspec->VA_BITS = machdep->machspec->VA_BITS_ACTUAL;
56ae9b
 				machdep->machspec->VA_START = _VA_START(machdep->machspec->VA_BITS_ACTUAL);
56ae9b
@@ -4654,6 +4669,8 @@ arm64_calc_VA_BITS(void)
56ae9b
 		 */
56ae9b
 		machdep->flags |= FLIPPED_VM;
56ae9b
 		return;
56ae9b
+	} else if (arm64_set_va_bits_by_tcr()) {
56ae9b
+		return;
56ae9b
 	}
56ae9b
 
56ae9b
 	if (!(sp = symbol_search("swapper_pg_dir")) &&
56ae9b
-- 
56ae9b
2.37.1
56ae9b