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

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