[PATCH 03/18] sparc32,leon: publish instruction updates across CPUs
From: Magnus Lindholm
Date: Thu Nov 26 2026 - 04:31:36 EST
flush_icache_range() is a no-op on sparc32, so another LEON CPU can
execute old instructions after code is rewritten at an existing mapping.
The LEON4 data cache snoops bus writes (GRIP 104.3.8); publishing code
also requires invalidating the other CPU's instruction cache.
Flush locally and through a synchronous cross-call with preemption
disabled. Keep empty ranges and non-LEON systems as runtime no-ops;
generic SPARC32 kernels can detect LEON without CONFIG_SPARC_LEON.
This covers in-place code updates. The module loader already flushes
caches when creating mappings for module text.
Signed-off-by: Magnus Lindholm <linmag7@xxxxxxxxx>
---
arch/sparc/include/asm/cacheflush_32.h | 2 +-
arch/sparc/mm/srmmu.c | 14 ++++++++++++++
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/arch/sparc/include/asm/cacheflush_32.h b/arch/sparc/include/asm/cacheflush_32.h
index 9fee0ccfccb8..4249663efacc 100644
--- a/arch/sparc/include/asm/cacheflush_32.h
+++ b/arch/sparc/include/asm/cacheflush_32.h
@@ -15,7 +15,7 @@
sparc32_cachetlb_ops->cache_range(vma, start, end)
#define flush_cache_page(vma,addr,pfn) \
sparc32_cachetlb_ops->cache_page(vma, addr)
-#define flush_icache_range(start, end) do { } while (0)
+void flush_icache_range(unsigned long start, unsigned long end);
#define copy_to_user_page(vma, page, vaddr, dst, src, len) \
do { \
diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
index fb95865d7ddd..d2963fab829c 100644
--- a/arch/sparc/mm/srmmu.c
+++ b/arch/sparc/mm/srmmu.c
@@ -1736,6 +1736,20 @@ static struct sparc32_cachetlb_ops smp_cachetlb_ops __ro_after_init = {
};
#endif
+void flush_icache_range(unsigned long start, unsigned long end)
+{
+ if (start >= end || sparc_cpu_model != sparc_leon)
+ return;
+
+ preempt_disable();
+ leon_flush_cache_all();
+#ifdef CONFIG_SMP
+ xc0(leon_flush_cache_all);
+#endif
+ preempt_enable();
+}
+EXPORT_SYMBOL(flush_icache_range);
+
/* Load up routines and constants for sun4m and sun4d mmu */
void __init load_mmu(void)
{
--
2.43.0