Skip to contentSkip to conversation

exec.c: ensure all AddressSpaceDispatch updates under RCU

PATCH In review Alex Bennée 2 participants 2 messages Oct 21, 2016 – Oct 24, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 exec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
exec.c +2 -2
index 738e8ba..c5e4073 100644
@@ -459,7 +459,7 @@ address_space_translate_for_iotlb(CPUState *cpu, int asidx, hwaddr addr,
                                   hwaddr *xlat, hwaddr *plen)
 {
     MemoryRegionSection *section;
-    AddressSpaceDispatch *d = cpu->cpu_ases[asidx].memory_dispatch;
+    AddressSpaceDispatch *d = atomic_rcu_read(&cpu->cpu_ases[asidx].memory_dispatch);
 
     section = address_space_translate_internal(d, addr, xlat, plen, false);
 
@@ -2342,7 +2342,7 @@ static void tcg_commit(MemoryListener *listener)
      * may have split the RCU critical section.
      */
     d = atomic_rcu_read(&cpuas->as->dispatch);
-    cpuas->memory_dispatch = d;
+    atomic_rcu_set(&cpuas->memory_dispatch, d);
     tlb_flush(cpuas->cpu, 1);
 }
 
Signature · 1 line
2.9.3
#1 lore raw
Quoted 24 lines · Alex Bennée

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.

---
 exec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
exec.c +1 -1
index 738e8ba..c5e4073 100644
@@ -459,7 +459,7 @@ address_space_translate_for_iotlb(CPUState *cpu, int asidx, hwaddr addr,
                                   hwaddr *xlat, hwaddr *plen)
 {
     MemoryRegionSection *section;
-    AddressSpaceDispatch *d = cpu->cpu_ases[asidx].memory_dispatch;
+    AddressSpaceDispatch *d = atomic_rcu_read(&cpu->cpu_ases[asidx].memory_dispatch);
 
     section = address_space_translate_internal(d, addr, xlat, plen, false);
 

exec.c static void tcg_commit(MemoryListener *listener) · line 2348

Quoted 8 lines
exec.c +1 -1
@@ -2342,7 +2342,7 @@ static void tcg_commit(MemoryListener *listener)
      * may have split the RCU critical section.
      */
     d = atomic_rcu_read(&cpuas->as->dispatch);
-    cpuas->memory_dispatch = d;
+    atomic_rcu_set(&cpuas->memory_dispatch, d);
     tlb_flush(cpuas->cpu, 1);
 }
 

Oops, this missed today's pull request but it's a bug so it can go in later.

Thanks,

Paolo