[PATCH] ARM: mm: fix stack corruption when CONFIG_ARM_PV_FIXUP=y

From: Zhizhou Zhang
Date: Thu Sep 07 2023 - 13:54:42 EST


From: Zhizhou Zhang <zhizhouzhang@xxxxxxxxxxxx>

flush_cache_all() save registers to stack at function entry.
If it's called after cache disabled, the data is written to
memory directly. So the following clean cache operation corrupted
registers saved by flush_cache_all(), including lr register.
calling flush_cache_all() before turn off cache fixed the problem.

Signed-off-by: Zhizhou Zhang <zhizhouzhang@xxxxxxxxxxxx>
---
arch/arm/mm/mmu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
index 674ed71573a8..03fb0fe926f3 100644
--- a/arch/arm/mm/mmu.c
+++ b/arch/arm/mm/mmu.c
@@ -1675,6 +1675,7 @@ static void __init early_paging_init(const struct machine_desc *mdesc)
/* Run the patch stub to update the constants */
fixup_pv_table(&__pv_table_begin,
(&__pv_table_end - &__pv_table_begin) << 2);
+ flush_cache_all();

/*
* We changing not only the virtual to physical mapping, but also
@@ -1690,7 +1691,6 @@ static void __init early_paging_init(const struct machine_desc *mdesc)
asm("mrc p15, 0, %0, c2, c0, 2" : "=r" (ttbcr));
asm volatile("mcr p15, 0, %0, c2, c0, 2"
: : "r" (ttbcr & ~(3 << 8 | 3 << 10)));
- flush_cache_all();

/*
* Fixup the page tables - this must be in the idmap region as
--
2.34.1