From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:53940) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qy6v7-0007Ok-Ru for qemu-devel@nongnu.org; Mon, 29 Aug 2011 14:50:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qy6v5-0000kY-LC for qemu-devel@nongnu.org; Mon, 29 Aug 2011 14:50:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47126) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qy6v5-0000kC-A3 for qemu-devel@nongnu.org; Mon, 29 Aug 2011 14:50:51 -0400 Date: Mon, 29 Aug 2011 15:40:49 -0300 From: Marcelo Tosatti Message-ID: <20110829184049.GA3783@amt.cnet> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Subject: Re: [Qemu-devel] [PATCH 3/5] Migration thread mutex List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Umesh Deshpande Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org On Sat, Aug 27, 2011 at 02:09:46PM -0400, Umesh Deshpande wrote: > This patch implements migrate_ram mutex, which protects the RAMBlock list > traversal in the migration thread during the transfer of a ram from their > addition/removal from the iothread. > > Note: Combination of iothread mutex and migration thread mutex works as a > rw-lock. Both mutexes are acquired while modifying the ram_list members or RAM > block list. > > Signed-off-by: Umesh Deshpande > --- > arch_init.c | 21 +++++++++++++++++++++ > cpu-all.h | 3 +++ > exec.c | 23 +++++++++++++++++++++++ > qemu-common.h | 2 ++ > 4 files changed, 49 insertions(+), 0 deletions(-) > > diff --git a/arch_init.c b/arch_init.c > index 484b39d..9d02270 100644 > --- a/arch_init.c > +++ b/arch_init.c > @@ -109,6 +109,7 @@ static int is_dup_page(uint8_t *page, uint8_t ch) > > static RAMBlock *last_block; > static ram_addr_t last_offset; > +static uint64_t last_version; > > static int ram_save_block(QEMUFile *f) > { > @@ -170,6 +171,7 @@ static int ram_save_block(QEMUFile *f) > > last_block = block; > last_offset = offset; > + last_version = ram_list.version; > > return bytes_sent; > } > @@ -270,6 +272,7 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque) > bytes_transferred = 0; > last_block = NULL; > last_offset = 0; > + last_version = ram_list.version = 0; > sort_ram_list(); > > /* Make sure all dirty bits are set */ > @@ -298,6 +301,17 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque) > bytes_transferred_last = bytes_transferred; > bwidth = qemu_get_clock_ns(rt_clock); > > + if (stage != 3) { > + qemu_mutex_lock_migrate_ram(); > + qemu_mutex_unlock_iothread(); > + } Dropping the iothread lock from within a timer handler is not safe. This change to ram_save_live should be moved to the patch where migration thread is introduced.