exec.c: ensure all AddressSpaceDispatch updates under RCU

The memory_dispatch field is meant to be protected by RCU so we should
use the correct primitives when accessing it. This race was flagged up
by the ThreadSanitizer.

Backports commit f35e44e7645edbb08e35b111c10c2fc57e2905c7 from qemu
This commit is contained in:
Alex Bennée 2018-03-01 08:44:12 -05:00 committed by Lioncash
parent 7ff441826c
commit 1e4154af83
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7

View file

@ -432,7 +432,8 @@ address_space_translate_for_iotlb(CPUState *cpu, int asidx, hwaddr addr,
hwaddr *xlat, hwaddr *plen) hwaddr *xlat, hwaddr *plen)
{ {
MemoryRegionSection *section; MemoryRegionSection *section;
AddressSpaceDispatch *d = cpu->cpu_ases[asidx].memory_dispatch; // Unicorn: atomic_read used instead of atomic_rcu_read
AddressSpaceDispatch *d = atomic_read(&cpu->cpu_ases[asidx].memory_dispatch);
section = address_space_translate_internal(d, addr, xlat, plen, false); section = address_space_translate_internal(d, addr, xlat, plen, false);
@ -1809,7 +1810,8 @@ static void tcg_commit(MemoryListener *listener)
*/ */
// Unicorn: uses atomic_read instead of atomic_rcu_read // Unicorn: uses atomic_read instead of atomic_rcu_read
d = atomic_read(&cpuas->as->dispatch); d = atomic_read(&cpuas->as->dispatch);
cpuas->memory_dispatch = d; // Unicorn: atomic_set used instead of atomic_rcu_set
atomic_set(&cpuas->memory_dispatch, d);
tlb_flush(cpuas->cpu, 1); tlb_flush(cpuas->cpu, 1);
} }