All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [RFC v2 0/6] memory: make dirty_memory[] accesses atomic
@ 2014-12-02 11:23 Stefan Hajnoczi
  2014-12-02 11:23 ` [Qemu-devel] [RFC v2 1/6] bitmap: add atomic set functions Stefan Hajnoczi
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: Stefan Hajnoczi @ 2014-12-02 11:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Dr. David Alan Gilbert, Stefan Hajnoczi,
	Peter Maydell

v2:
 * Make bitmap_set_atomic() and bitmap_test_and_clear_atomic() faster by
   replacing the inner loop with cheaper operations.  I did use smp_wmb() in
   bitmap_set_atomic() so that the function is always a write barrier, no
   matter which code path is taken. [Paolo]

The dirty_memory[] bitmap is used for live migration, TCG self-modifying code
detection, and VGA emulation.  Up until now the bitmap was always accessed
under the QEMU global mutex.  This series makes all dirty_memory[] accesses
atomic to prepare the way for threads writing to guest memory without holding
the global mutex.

In particular, this series converts non-atomic dirty_memory[] accesses to
atomic_or, atomic_xchg, and atomic_fetch_and so that race conditions are
avoided when two threads manipulate the bitmap at the same time.

There are two pieces remaining before the dirty_memory[] bitmap is truly
thread-safe:

1. Convert all cpu_physical_memory_*_dirty() callers to use the API atomically.
   There are TCG callers who things along the lines of:

     if (!cpu_physical_memory_get_dirty(addr)) {
         cpu_physical_memory_set_dirty(addr);  /* not atomic! */
     }

   At first I considered ignoring TCG completely since it is currently not
   multi-threaded, but we might as well tackle this so that
   virtio-blk/virtio-scsi dataplane can be used with TCG eventually (they still
   need ioeventfd/irqfd emulation before they can support TCG).

2. Use array RCU to safely resize dirty_memory[] for memory hotplug.  Currently
   ram_block_add() grows the bitmap in a way that is not thread-safe.

   Paolo has a QEMU userspace RCU implementation which I'd like to bring in for
   this.

Stefan Hajnoczi (6):
  bitmap: add atomic set functions
  bitmap: add atomic test and clear
  memory: use atomic ops for setting dirty memory bits
  migration: move dirty bitmap sync to ram_addr.h
  memory: replace cpu_physical_memory_reset_dirty() with test-and-clear
  memory: make cpu_physical_memory_sync_dirty_bitmap() fully atomic

 arch_init.c             | 46 ++----------------------------
 cputlb.c                |  4 +--
 exec.c                  | 23 +++++++++++----
 include/exec/ram_addr.h | 74 ++++++++++++++++++++++++++++++++++++-------------
 include/qemu/bitmap.h   |  4 +++
 include/qemu/bitops.h   | 14 ++++++++++
 memory.c                | 11 +++-----
 util/bitmap.c           | 73 ++++++++++++++++++++++++++++++++++++++++++++++++
 8 files changed, 170 insertions(+), 79 deletions(-)

-- 
2.1.0

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-12-02 12:28 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-02 11:23 [Qemu-devel] [RFC v2 0/6] memory: make dirty_memory[] accesses atomic Stefan Hajnoczi
2014-12-02 11:23 ` [Qemu-devel] [RFC v2 1/6] bitmap: add atomic set functions Stefan Hajnoczi
2014-12-02 12:28   ` Paolo Bonzini
2014-12-02 11:23 ` [Qemu-devel] [RFC v2 2/6] bitmap: add atomic test and clear Stefan Hajnoczi
2014-12-02 12:16   ` Paolo Bonzini
2014-12-02 11:23 ` [Qemu-devel] [RFC v2 3/6] memory: use atomic ops for setting dirty memory bits Stefan Hajnoczi
2014-12-02 11:23 ` [Qemu-devel] [RFC v2 4/6] migration: move dirty bitmap sync to ram_addr.h Stefan Hajnoczi
2014-12-02 11:23 ` [Qemu-devel] [RFC v2 5/6] memory: replace cpu_physical_memory_reset_dirty() with test-and-clear Stefan Hajnoczi
2014-12-02 11:23 ` [Qemu-devel] [RFC v2 6/6] memory: make cpu_physical_memory_sync_dirty_bitmap() fully atomic Stefan Hajnoczi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.