@@ -89,6 +89,14 @@ static int __patch_insn_set(void *addr, u8 c, size_t len)
89
89
90
90
memset (waddr , c , len );
91
91
92
+ /*
93
+ * We could have just patched a function that is about to be
94
+ * called so make sure we don't execute partially patched
95
+ * instructions by flushing the icache as soon as possible.
96
+ */
97
+ local_flush_icache_range ((unsigned long )waddr ,
98
+ (unsigned long )waddr + len );
99
+
92
100
patch_unmap (FIX_TEXT_POKE0 );
93
101
94
102
if (across_pages )
@@ -135,6 +143,14 @@ static int __patch_insn_write(void *addr, const void *insn, size_t len)
135
143
136
144
ret = copy_to_kernel_nofault (waddr , insn , len );
137
145
146
+ /*
147
+ * We could have just patched a function that is about to be
148
+ * called so make sure we don't execute partially patched
149
+ * instructions by flushing the icache as soon as possible.
150
+ */
151
+ local_flush_icache_range ((unsigned long )waddr ,
152
+ (unsigned long )waddr + len );
153
+
138
154
patch_unmap (FIX_TEXT_POKE0 );
139
155
140
156
if (across_pages )
@@ -189,9 +205,6 @@ int patch_text_set_nosync(void *addr, u8 c, size_t len)
189
205
190
206
ret = patch_insn_set (tp , c , len );
191
207
192
- if (!ret )
193
- flush_icache_range ((uintptr_t )tp , (uintptr_t )tp + len );
194
-
195
208
return ret ;
196
209
}
197
210
NOKPROBE_SYMBOL (patch_text_set_nosync );
@@ -224,9 +237,6 @@ int patch_text_nosync(void *addr, const void *insns, size_t len)
224
237
225
238
ret = patch_insn_write (tp , insns , len );
226
239
227
- if (!ret )
228
- flush_icache_range ((uintptr_t ) tp , (uintptr_t ) tp + len );
229
-
230
240
return ret ;
231
241
}
232
242
NOKPROBE_SYMBOL (patch_text_nosync );
@@ -253,9 +263,9 @@ static int patch_text_cb(void *data)
253
263
} else {
254
264
while (atomic_read (& patch -> cpu_count ) <= num_online_cpus ())
255
265
cpu_relax ();
256
- }
257
266
258
- local_flush_icache_all ();
267
+ local_flush_icache_all ();
268
+ }
259
269
260
270
return ret ;
261
271
}
0 commit comments