address_space_map: address_space_to_flatview needs RCU lock
authorPaolo Bonzini <pbonzini@redhat.com>
Sun, 4 Mar 2018 23:23:26 +0000 (00:23 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 6 Mar 2018 13:01:28 +0000 (14:01 +0100)
address_space_map is calling address_space_to_flatview but it can
be called outside the RCU lock.  The function itself is calling
rcu_read_lock/rcu_read_unlock, just in the wrong place, so the
fix is easy.

Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
exec.c

diff --git a/exec.c b/exec.c
index 62ed49ddd5e494111d97bf5b096f7c1e85ea91ed..bffb959a1ffb118118bd0e011277351db066fedd 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -3468,7 +3468,7 @@ void *address_space_map(AddressSpace *as,
     hwaddr l, xlat;
     MemoryRegion *mr;
     void *ptr;
-    FlatView *fv = address_space_to_flatview(as);
+    FlatView *fv;
 
     if (len == 0) {
         return NULL;
@@ -3476,6 +3476,7 @@ void *address_space_map(AddressSpace *as,
 
     l = len;
     rcu_read_lock();
+    fv = address_space_to_flatview(as);
     mr = flatview_translate(fv, addr, &xlat, &l, is_write);
 
     if (!memory_access_is_direct(mr, is_write)) {