qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Paolo Bonzini <pbonzini@redhat.com>,
	rth@redhat.com, Stefan Hajnoczi <stefanha@redhat.com>,
	Juan Quintela <quintela@redhat.com>
Subject: [Qemu-devel] [RFC 0/6] memory: make dirty_memory[] accesses atomic
Date: Thu, 27 Nov 2014 12:29:20 +0000	[thread overview]
Message-ID: <1417091366-4469-1-git-send-email-stefanha@redhat.com> (raw)

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.

I am posting this RFC to get feedback because this is my first foray into the
memory bitmap code.  Comments appreciated!

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           | 47 +++++++++++++++++++++++++++++++
 8 files changed, 144 insertions(+), 79 deletions(-)

-- 
2.1.0

             reply	other threads:[~2014-11-27 12:29 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-27 12:29 Stefan Hajnoczi [this message]
2014-11-27 12:29 ` [Qemu-devel] [RFC 1/6] bitmap: add atomic set functions Stefan Hajnoczi
2014-11-27 16:42   ` Paolo Bonzini
2014-12-01 13:52     ` Stefan Hajnoczi
2014-11-27 12:29 ` [Qemu-devel] [RFC 2/6] bitmap: add atomic test and clear Stefan Hajnoczi
2014-11-27 16:43   ` Paolo Bonzini
2014-12-01 13:53     ` Stefan Hajnoczi
2014-11-27 12:29 ` [Qemu-devel] [RFC 3/6] memory: use atomic ops for setting dirty memory bits Stefan Hajnoczi
2014-11-27 12:29 ` [Qemu-devel] [RFC 4/6] migration: move dirty bitmap sync to ram_addr.h Stefan Hajnoczi
2014-11-27 16:29   ` Dr. David Alan Gilbert
2014-12-01 14:01     ` Stefan Hajnoczi
2014-12-01 14:49       ` Dr. David Alan Gilbert
2014-11-27 12:29 ` [Qemu-devel] [RFC 5/6] memory: replace cpu_physical_memory_reset_dirty() with test-and-clear Stefan Hajnoczi
2014-11-27 12:29 ` [Qemu-devel] [RFC 6/6] memory: make cpu_physical_memory_sync_dirty_bitmap() fully atomic Stefan Hajnoczi
2014-11-27 13:21 ` [Qemu-devel] [RFC 0/6] memory: make dirty_memory[] accesses atomic Peter Maydell
2014-11-28 12:44   ` Stefan Hajnoczi
2015-03-23 11:09     ` Paolo Bonzini
2015-03-24 16:48       ` Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1417091366-4469-1-git-send-email-stefanha@redhat.com \
    --to=stefanha@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=rth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).