From patchwork Thu Sep 24 12:53:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev" X-Patchwork-Id: 522299 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4E17014029C for ; Thu, 24 Sep 2015 22:54:15 +1000 (AEST) Received: from localhost ([::1]:33551 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zf62P-0001JP-Gv for incoming@patchwork.ozlabs.org; Thu, 24 Sep 2015 08:54:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57214) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zf627-0000z8-DG for qemu-devel@nongnu.org; Thu, 24 Sep 2015 08:53:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zf621-0001U2-Li for qemu-devel@nongnu.org; Thu, 24 Sep 2015 08:53:55 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:47668 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zf621-0001QW-AS for qemu-devel@nongnu.org; Thu, 24 Sep 2015 08:53:49 -0400 Received: from irbis.sw.ru ([10.30.2.139]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id t8OCrcn2022538; Thu, 24 Sep 2015 15:53:39 +0300 (MSK) From: "Denis V. Lunev" To: Date: Thu, 24 Sep 2015 15:53:38 +0300 Message-Id: <1443099218-14857-1-git-send-email-den@openvz.org> X-Mailer: git-send-email 2.1.4 X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x X-Received-From: 195.214.232.25 Cc: Amit Shah , Igor Redko , Juan Quintela , qemu-devel@nongnu.org, "Denis V. Lunev" Subject: [Qemu-devel] [PATCH 1/1] migration: fix deadlock X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Igor Redko Release qemu global mutex before call synchronize_rcu(). synchronize_rcu() waiting for all readers to finish their critical sections. There is at least one critical section in which we try to get QGM (critical section is in address_space_rw() and prepare_mmio_access() is trying to aquire QGM). Both functions (migration_end() and migration_bitmap_extend()) are called from main thread which is holding QGM. Thus there is a race condition that ends up with deadlock: main thread working thread Lock QGA | | Call KVM_EXIT_IO handler | | | Open rcu reader's critical section Migration cleanup bh | | | synchronize_rcu() is | waiting for readers | | prepare_mmio_access() is waiting for QGM \ / deadlock The patch just releases QGM before calling synchronize_rcu(). Signed-off-by: Igor Redko Reviewed-by: Anna Melekhova Signed-off-by: Denis V. Lunev CC: Juan Quintela CC: Amit Shah Signed-off-by: Denis V. Lunev --- migration/ram.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/migration/ram.c b/migration/ram.c index 7f007e6..d01febc 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1028,12 +1028,16 @@ static void migration_end(void) { /* caller have hold iothread lock or is in a bh, so there is * no writing race against this migration_bitmap + * but rcu used not only for migration_bitmap, so we should + * release QGM or we get in deadlock. */ unsigned long *bitmap = migration_bitmap; atomic_rcu_set(&migration_bitmap, NULL); if (bitmap) { memory_global_dirty_log_stop(); + qemu_mutex_unlock_iothread(); synchronize_rcu(); + qemu_mutex_lock_iothread(); g_free(bitmap); } @@ -1085,7 +1089,9 @@ void migration_bitmap_extend(ram_addr_t old, ram_addr_t new) atomic_rcu_set(&migration_bitmap, bitmap); qemu_mutex_unlock(&migration_bitmap_mutex); migration_dirty_pages += new - old; + qemu_mutex_unlock_iothread(); synchronize_rcu(); + qemu_mutex_lock_iothread(); g_free(old_bitmap); } }