Skip to contentSkip to conversation

arm64: alternative:flush cache with unpatched code

PATCH New Rohit Khanna 2 participants 2 messages Jun 6, 2018 – Jun 7, 2018 arm64

lore
Share & tools
lore
#0 lore raw

PATCH v6 1/1 arm64: alternative:flush cache with unpatched code

In the current implementation, __apply_alternatives patches flush_icache_range and then executes it without invalidating the icache. Thus, icache can contain some of the old instructions for flush_icache_range. This can cause unpredictable behavior as during execution we can get a mix of old and new instructions for flush_icache_range.

This patch modifies __apply_alternatives so that it uses non hot-patched __flush_icache_all after applying all the alternatives.

---
 arch/arm64/kernel/alternative.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
arch/arm64/kernel/alternative.c +1 -3
index 5c4bce4ac381..047139f570ac 100644
@@ -154,10 +154,8 @@ static void __apply_alternatives(void *alt_region, bool use_linear_alias)
 			alt_cb  = ALT_REPL_PTR(alt);
 
 		alt_cb(alt, origptr, updptr, nr_inst);
-
-		flush_icache_range((uintptr_t)origptr,
-				   (uintptr_t)(origptr + nr_inst));
 	}
+	__flush_icache_all();
 }
 
 /*
Signature · 1 line
2.1.4
#1 lore raw

PATCH v6 1/1 arm64: alternative:flush cache with unpatched code

Quoted 9 lines · Rohit Khanna

In the current implementation, __apply_alternatives patches flush_icache_range and then executes it without invalidating the icache. Thus, icache can contain some of the old instructions for flush_icache_range. This can cause unpredictable behavior as during execution we can get a mix of old and new instructions for flush_icache_range.

This patch modifies __apply_alternatives so that it uses non hot-patched __flush_icache_all after applying all the alternatives.

Please can you try the diff I posted the other day? [1]

Will

--->8

[1] http://lists.infradead.org/pipermail/linux-arm-kernel/2018-June/582861.html