]> www.infradead.org Git - users/dwmw2/qemu.git/commitdiff
memory: make cpu_physical_memory_sync_dirty_bitmap() fully atomic
authorStefan Hajnoczi <stefanha@redhat.com>
Tue, 2 Dec 2014 11:23:19 +0000 (11:23 +0000)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 5 Jun 2015 15:10:00 +0000 (17:10 +0200)
The fast path of cpu_physical_memory_sync_dirty_bitmap() directly
manipulates the dirty bitmap.  Use atomic_xchg() to make the
test-and-clear atomic.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-Id: <1417519399-3166-7-git-send-email-stefanha@redhat.com>
[Only do xchg on nonzero words. - Paolo]
Reviewed-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
include/exec/ram_addr.h

index a2beea7925abbe1a1e33efaffe590049033127e6..c113f2114060dade4f563dd2d962852a08a7ff02 100644 (file)
@@ -224,12 +224,12 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(unsigned long *dest,
 
         for (k = page; k < page + nr; k++) {
             if (src[k]) {
+                unsigned long bits = atomic_xchg(&src[k], 0);
                 unsigned long new_dirty;
                 new_dirty = ~dest[k];
-                dest[k] |= src[k];
-                new_dirty &= src[k];
+                dest[k] |= bits;
+                new_dirty &= bits;
                 num_dirty += ctpopl(new_dirty);
-                src[k] = 0;
             }
         }
     } else {