From patchwork Fri Oct 28 16:59:52 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 122443 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 36365B6F67 for ; Sat, 29 Oct 2011 04:00:10 +1100 (EST) Received: from localhost ([::1]:59866 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RJpmp-0001BN-4d for incoming@patchwork.ozlabs.org; Fri, 28 Oct 2011 13:00:07 -0400 Received: from eggs.gnu.org ([140.186.70.92]:35440) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RJpmi-0001B1-2r for qemu-devel@nongnu.org; Fri, 28 Oct 2011 13:00:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RJpmh-0001R6-5d for qemu-devel@nongnu.org; Fri, 28 Oct 2011 13:00:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:30242) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RJpmg-0001R1-RV for qemu-devel@nongnu.org; Fri, 28 Oct 2011 12:59:59 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p9SGxtQE015387 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 28 Oct 2011 12:59:55 -0400 Received: from doriath ([10.3.113.4]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p9SGxqY9010097; Fri, 28 Oct 2011 12:59:53 -0400 Date: Fri, 28 Oct 2011 14:59:52 -0200 From: Luiz Capitulino To: qemu-devel Message-ID: <20111028145952.4bb63294@doriath> Organization: Red Hat Mime-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 209.132.183.28 Cc: Paolo Bonzini , Eduardo Habkost , Juan Jose Quintela Carreira Subject: [Qemu-devel] [PATCH v2] Fix segfault on migration completion 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 A simple migration reproduces it: 1. Start the source VM with: # qemu [...] -S 2. Start the destination VM with: # qemu -incoming tcp:0:4444 3. In the source VM: (qemu) migrate -d tcp:0:4444 4. The source VM will segfault as soon as migration completes (might not happen in the first try) What is happening here is that qemu_file_put_notify() can end up closing 's->file' (in which case it's also set to NULL). The call stack is rather complex, but Eduardo helped tracking it to: select loop -> migrate_fd_put_notify() -> qemu_file_put_notify() -> buffered_put_buffer() -> migrate_fd_put_ready() -> migrate_fd_completed() -> migrate_fd_cleanup(). To be honest, it's not completely clear to me in which cases 's->file' is not closed (on error maybe)? But I doubt this fix will make anything worse. Reviewed-by: Paolo Bonzini Acked-by: Eduardo Habkost Signed-off-by: Luiz Capitulino Acked-by: Juan Quintela --- V2: better commit log migration.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/migration.c b/migration.c index bdca72e..f6e6208 100644 --- a/migration.c +++ b/migration.c @@ -252,7 +252,7 @@ static void migrate_fd_put_notify(void *opaque) qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL); qemu_file_put_notify(s->file); - if (qemu_file_get_error(s->file)) { + if (s->file && qemu_file_get_error(s->file)) { migrate_fd_error(s); } }