mm: autopatch: fix 32bit kasan cant boot on T5W [1/1]

PD#SWPL-80202

Problem:
If enabled 32bit kasan on T5W with VMAP, kernel can't boot.
This case can't happen on T5D.

Solution:
Rootcause is bss cleared but real data keeps in cache, not flushed
into DDR, and physical kasan shadow page soon be mapped to shadow
memory while in shadow virtual address we see random data, which
caused kasan check failed in vmap fixup function and crashed. So
just add a dcache flush function call after bss cleared.

Verify:
T5W

Change-Id: If9834d3ebe8457fa4ef06e596ed0e136cf5cdd84
Signed-off-by: Jianxiong Pan <jianxiong.pan@amlogic.com>
This commit is contained in:
Jianxiong Pan
2023-12-22 16:58:05 +08:00
committed by gerrit autosubmit
parent 7923ca6dbd
commit 447b6feeef
@@ -0,0 +1,56 @@
From 09b0ed89a441600394c0503d8edcbf303df05433 Mon Sep 17 00:00:00 2001
From: Jianxiong Pan <jianxiong.pan@amlogic.com>
Date: Fri, 22 Dec 2023 16:03:59 +0800
Subject: [PATCH] mm: fix 32bit kasan can't boot on T5W [1/1]
PD#SWPL-80202
Problem:
If enabled 32bit kasan on T5W with VMAP, kernel can't boot.
This case can't happen on T5D.
Solution:
Rootcause is bss cleared but real data keeps in cache, not flushed
into DDR, and physical kasan shadow page soon be mapped to shadow
memory while in shadow virtual address we see random data, which
caused kasan check failed in vmap fixup funciton and crashed. So
just add a dcache flush function call after bss cleared.
Verify:
T5W
Change-Id: Id72d26046a2155ee8fea35c3bf8c7aa4fe52e7a4
Signed-off-by: Jianxiong Pan <jianxiong.pan@amlogic.com>
---
arch/arm/kernel/head-common.S | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/arch/arm/kernel/head-common.S b/arch/arm/kernel/head-common.S
index ae5f69292a11..f271626c9888 100644
--- a/arch/arm/kernel/head-common.S
+++ b/arch/arm/kernel/head-common.S
@@ -105,6 +105,21 @@ __mmap_switched:
mov r1, #0
bl __memset @ clear .bss
+#if defined (CONFIG_KASAN) && defined (CONFIG_AMLOGIC_VMAP)
+ /* After bss cleard, kasan_early_shadow_page are 0 in cache
+ * But on A55 it's physical memory keeps random data, this
+ * physical page will be mapped to shadow memory very soon(few
+ * lines behind) in function kasan_early_init, this caused kasan
+ * shadow memory check failed and crashed in function
+ * fixup_init_thread_union(). However, this problem don't see on
+ * A35 processor. Rootcause may related with core's cache replace/
+ * clean policy.
+ */
+ push {r0-r12, lr}
+ bl v7_flush_dcache_all
+ pop {r0-r12, lr}
+#endif
+
ldmia r4, {r0, r1, r2, r3}
str r9, [r0] @ Save processor ID
str r7, [r1] @ Save machine type
--
2.42.0