Blame SOURCES/0001-Fix-pvops-Xen-detection-for-arm-machine.patch

52efa0
From 7eba220e1a7d443cad6716dd83d4953ffd62d566 Mon Sep 17 00:00:00 2001
52efa0
From: Qi Zheng <zhengqi.arch@bytedance.com>
52efa0
Date: Tue, 21 Dec 2021 15:40:31 +0800
52efa0
Subject: [PATCH 1/2] Fix pvops Xen detection for arm machine
52efa0
52efa0
Since the xen_start_info on the arm/arm64 platform points to a static
52efa0
variable '_xen_start_info'(see its definition as below), which makes
52efa0
that the address of xen_start_info will never be null.
52efa0
52efa0
arch/arm/xen/enlighten.c:40:static struct start_info _xen_start_info;
52efa0
arch/arm/xen/enlighten.c:41:struct start_info *xen_start_info = &_xen_start_info;
52efa0
arch/arm/xen/enlighten.c:42:EXPORT_SYMBOL(xen_start_info);
52efa0
52efa0
As a result, the is_pvops_xen() in commit 4badc6229c69 ("Fix pvops
52efa0
Xen detection for kernels >= v4.20") always returns TRUE because it
52efa0
can always read out the non-null address of xen_start_info, finally
52efa0
the following error will be reported on arm/arm64 platform(non-Xen
52efa0
environment) because p2m_mid_missing and xen_p2m_addr are not defined:
52efa0
52efa0
        crash: cannot resolve "p2m_top"
52efa0
52efa0
For the arm/arm64 platform, fix it by using xen_vcpu_info instead of
52efa0
xen_start_info to detect Xen dumps.
52efa0
52efa0
In addition, also explicitly narrow the scope of the xen_start_info
52efa0
check to x86 with the machine_type(), there is no need to check it on
52efa0
other architectures.
52efa0
52efa0
Fixes: 4badc6229c69 ("Fix pvops Xen detection for kernels >= v4.20")
52efa0
Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com>
52efa0
Acked-by: Kazuhito Hagio <k-hagio-ab@nec.com>
52efa0
---
52efa0
 kernel.c | 20 +++++++++++++++-----
52efa0
 1 file changed, 15 insertions(+), 5 deletions(-)
52efa0
52efa0
diff --git a/kernel.c b/kernel.c
52efa0
index f4598ea217a3..37b7af74ed2e 100644
52efa0
--- a/kernel.c
52efa0
+++ b/kernel.c
52efa0
@@ -10757,11 +10757,21 @@ is_pvops_xen(void)
52efa0
 	     STREQ(sym, "paravirt_patch_default")))
52efa0
 		return TRUE;
52efa0
 
52efa0
-	if (symbol_exists("xen_start_info") &&
52efa0
-	    readmem(symbol_value("xen_start_info"), KVADDR, &addr,
52efa0
-	    sizeof(void *), "xen_start_info", RETURN_ON_ERROR) &&
52efa0
-	    addr != 0)
52efa0
-		return TRUE;
52efa0
+	if (machine_type("X86") || machine_type("X86_64")) {
52efa0
+		if (symbol_exists("xen_start_info") &&
52efa0
+		    readmem(symbol_value("xen_start_info"), KVADDR, &addr,
52efa0
+		    sizeof(void *), "xen_start_info", RETURN_ON_ERROR) &&
52efa0
+		    addr != 0)
52efa0
+			return TRUE;
52efa0
+	}
52efa0
+
52efa0
+	if (machine_type("ARM") || machine_type("ARM64")) {
52efa0
+		if (symbol_exists("xen_vcpu_info") &&
52efa0
+		    readmem(symbol_value("xen_vcpu_info"), KVADDR, &addr,
52efa0
+		    sizeof(void *), "xen_vcpu_info", RETURN_ON_ERROR) &&
52efa0
+		    addr != 0)
52efa0
+			return TRUE;
52efa0
+	}
52efa0
 
52efa0
 	return FALSE;
52efa0
 }
52efa0
-- 
52efa0
2.20.1
52efa0