Skip to contentSkip to conversation

exec.c: Use atomic_rcu_read() to access dispatch in memory_region_section_get_iotlb()

PATCH In review Peter Maydell 2 participants 2 messages Jul 20, 2015 – Jul 21, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 exec.c: Use atomic_rcu_read() to access dispatch in memory_region_section_get_iotlb()

When accessing the dispatch pointer in an AddressSpace within an RCU critical section we should always use atomic_rcu_read(). Fix an access within memory_region_section_get_iotlb() which was incorrectly doing a direct pointer access.

---
I discussed this on IRC with Paolo a while back, and IIRC he said that although this is a bug it's not one that can currently have any ill effects, though I forget why (probably because this code path is TCG only and TCG is single-threaded right now).

 exec.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
exec.c +4 -1
index 7d60e15..0a4a0c5 100644
@@ -954,7 +954,10 @@ hwaddr memory_region_section_get_iotlb(CPUState *cpu,
             iotlb |= PHYS_SECTION_ROM;
         }
     } else {
-        iotlb = section - section->address_space->dispatch->map.sections;
+        AddressSpaceDispatch *d;
+
+        d = atomic_rcu_read(&section->address_space->dispatch);
+        iotlb = section - d->map.sections;
         iotlb += xlat;
     }
 
Signature · 1 line
1.9.1
#1 lore raw
Quoted 21 lines · Peter Maydell

When accessing the dispatch pointer in an AddressSpace within an RCU critical section we should always use atomic_rcu_read(). Fix an access within memory_region_section_get_iotlb() which was incorrectly doing a direct pointer access.

---
I discussed this on IRC with Paolo a while back, and IIRC he said that although this is a bug it's not one that can currently have any ill effects, though I forget why (probably because this code path is TCG only and TCG is single-threaded right now).

 exec.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
exec.c +0 -0
index 7d60e15..0a4a0c5 100644
@@ -954,7 +954,10 @@ hwaddr memory_region_section_get_iotlb(CPUState *cpu,
             iotlb |= PHYS_SECTION_ROM;

exec.c hwaddr memory_region_section_get_iotlb(CPUState *cpu, · line 963

Quoted 10 lines
exec.c +4 -1
         }
     } else {
-        iotlb = section - section->address_space->dispatch->map.sections;
+        AddressSpaceDispatch *d;
+
+        d = atomic_rcu_read(&section->address_space->dispatch);
+        iotlb = section - d->map.sections;
         iotlb += xlat;
     }
 

Thanks, queued for next 2.4 pull request.

Paolo