@@ -292,6 +292,11 @@ static TranslationBlock *tb_find_slow(CPUState *cpu,
{
TranslationBlock *tb;
+ /* Ensure that we won't find a TB in the shared hash table
+ * if it is being invalidated by some other thread.
+ * Otherwise we'd put it back to CPU's local cache.
+ * Pairs with smp_wmb() in tb_phys_invalidate(). */
+ smp_rmb();
tb = tb_find_physical(cpu, pc, cs_base, flags);
if (tb) {
goto found;
@@ -336,7 +341,7 @@ static inline TranslationBlock *tb_find_fast(CPUState *cpu,
is executed. */
cpu_get_tb_cpu_state(env, &pc, &cs_base, &flags);
tb_lock();
- tb = cpu->tb_jmp_cache[tb_jmp_cache_hash_func(pc)];
+ tb = atomic_read(&cpu->tb_jmp_cache[tb_jmp_cache_hash_func(pc)]);
if (unlikely(!tb || tb->pc != pc || tb->cs_base != cs_base ||
tb->flags != flags)) {
tb = tb_find_slow(cpu, pc, cs_base, flags);
@@ -1071,11 +1071,16 @@ void tb_phys_invalidate(TranslationBlock *tb, tb_page_addr_t page_addr)
invalidate_page_bitmap(p);
}
+ /* Ensure that we won't find the TB in the shared hash table
+ * if we con't see it in CPU's local cache.
+ * Pairs with smp_rmb() in tb_find_slow(). */
+ smp_wmb();
+
/* remove the TB from the hash list */
h = tb_jmp_cache_hash_func(tb->pc);
CPU_FOREACH(cpu) {
if (cpu->tb_jmp_cache[h] == tb) {
- cpu->tb_jmp_cache[h] = NULL;
+ atomic_set(&cpu->tb_jmp_cache[h], NULL);
}
}