linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ARM: mm: fix stack corruption when CONFIG_ARM_PV_FIXUP=y
@ 2023-09-07 14:33 Zhizhou Zhang
  2023-09-08 12:58 ` Linus Walleij
  0 siblings, 1 reply; 7+ messages in thread
From: Zhizhou Zhang @ 2023-09-07 14:33 UTC (permalink / raw)
  To: linux, rmk+kernel, rppt, linus.walleij, akpm, vishal.moola, arnd,
	wangkefeng.wang, willy
  Cc: linux-arm-kernel, linux-kernel, Zhizhou Zhang

From: Zhizhou Zhang <zhizhouzhang@asrmicro.com>

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@asrmicro.com>
---
 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


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-10-02 14:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-07 14:33 [PATCH] ARM: mm: fix stack corruption when CONFIG_ARM_PV_FIXUP=y Zhizhou Zhang
2023-09-08 12:58 ` Linus Walleij
2023-09-08 13:50   ` Russell King (Oracle)
2023-09-08 21:00     ` Linus Walleij
2023-09-09  8:23       ` Zhi-zhou Zhang
2023-10-02 14:17         ` Andrew Davis
2023-09-11 13:04       ` Nishanth Menon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).