Skip to contentSkip to conversation

sh: Account for cache aliases in flush_icache_range()

PATCH In review Matt Fleming 2 participants 3 messages Nov 5, 2009 – Nov 9, 2009 SuperH

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sh: Account for cache aliases in flush_icache_range()

The icache may also contain aliases so we must account for them just like we do when manipulating the dcache. We usually get away with aliases in the icache because the instructions that are read from memory are read-only, i.e. they never change. However, the place where this bites us is when the code has been modified.

---
 arch/sh/mm/cache-sh4.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
arch/sh/mm/cache-sh4.c +4 -1
index b5abe94..6bfd08d 100644
@@ -65,6 +65,7 @@ static void __uses_jump_to_uncached sh4_flush_icache_range(void *args)
 
 	for (v = start; v < end; v += L1_CACHE_BYTES) {
 		unsigned long icacheaddr;
+		int j, n;
 
 		__ocbwb(v);
 
@@ -72,8 +73,10 @@ static void __uses_jump_to_uncached sh4_flush_icache_range(void *args)
 				cpu_data->icache.entry_mask);
 
 		/* Clear i-cache line valid-bit */
+		n = boot_cpu_data.icache.n_aliases;
 		for (i = 0; i < cpu_data->icache.ways; i++) {
-			__raw_writel(0, icacheaddr);
+			for (j = 0; j < n; j++)
+				__raw_writel(0, icacheaddr + (j * PAGE_SIZE));
 			icacheaddr += cpu_data->icache.way_incr;
 		}
 	}
Signature · 1 line
1.6.2.5
#1 lore raw
Quoted 6 lines · Matt Fleming

The icache may also contain aliases so we must account for them just like we do when manipulating the dcache. We usually get away with aliases in the icache because the instructions that are read from memory are read-only, i.e. they never change. However, the place where this bites us is when the code has been modified.

Just to be clear, I haven't actually seen any errors because of this code. But the fix looks correct to me unless we're never in a state where we have aliases in the icache (even though in theory we could)?

#2 lore raw
In reply to Matt Fleming
Quoted 7 lines · Matt Fleming

The icache may also contain aliases so we must account for them just like we do when manipulating the dcache. We usually get away with aliases in the icache because the instructions that are read from memory are read-only, i.e. they never change. However, the place where this bites us is when the code has been modified.

Looks reasonable to me, I've applied it.