From nobody Thu Nov 6 03:29:15 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539315898915115.92711414274493; Thu, 11 Oct 2018 20:44:58 -0700 (PDT) Received: from localhost ([::1]:38106 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gAoNl-0000uP-Lh for importer@patchew.org; Thu, 11 Oct 2018 23:44:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36090) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gAoMs-0000bT-Hy for qemu-devel@nongnu.org; Thu, 11 Oct 2018 23:44:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gAoMn-0004Jz-JR for qemu-devel@nongnu.org; Thu, 11 Oct 2018 23:44:02 -0400 Received: from [220.181.50.185] (port=59356 helo=baidu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gAoMn-0004Fj-5O for qemu-devel@nongnu.org; Thu, 11 Oct 2018 23:43:57 -0400 Received: from M1-MAIL-EX12.internal.baidu.com (unknown [10.44.89.52]) by Forcepoint Email with ESMTPS id 9011C25654BFC; Fri, 12 Oct 2018 10:57:31 +0800 (CST) Received: from BC-Mail-EX05.internal.baidu.com (172.31.40.45) by M1-MAIL-EX12.internal.baidu.com (10.44.89.52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1531.3; Fri, 12 Oct 2018 10:57:32 +0800 Received: from 9B900DC7A53C154.internal.baidu.com (10.44.111.8) by BC-Mail-Ex05.internal.baidu.com (172.31.40.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1531.3; Fri, 12 Oct 2018 10:57:31 +0800 From: jialina01 To: , , , Date: Fri, 12 Oct 2018 10:56:23 +0800 Message-ID: <20181012025623.38792-1-jialina01@baidu.com> X-Mailer: git-send-email 2.13.2.windows.1 MIME-Version: 1.0 X-Originating-IP: [10.44.111.8] X-ClientProxiedBy: BC-Mail-EX07.internal.baidu.com (172.31.40.47) To BC-Mail-Ex05.internal.baidu.com (172.31.40.45) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 220.181.50.185 Subject: [Qemu-devel] [PATCH] migration: avoid segmentfault when take a snapshot of a VM which being migrated X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: zhangyu , chaiwen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" During an active background migraion, snapshot will trigger a segmentfault. As snapshot clears the "current_migration" struct and updates "to_dst_file" before it finds out that there is a migration task, Migration accesses the null pointer in "current_migration" struct and qemu crashes eventually. Signed-off-by: jialina01 Signed-off-by: chaiwen Signed-off-by: zhangyu --- migration/savevm.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/migration/savevm.c b/migration/savevm.c index 2d10e45582..9cb97ca343 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1319,21 +1319,18 @@ static int qemu_savevm_state(QEMUFile *f, Error **e= rrp) MigrationState *ms =3D migrate_get_current(); MigrationStatus status; =20 - migrate_init(ms); - - ms->to_dst_file =3D f; - if (migration_is_blocked(errp)) { - ret =3D -EINVAL; - goto done; + return -EINVAL; } =20 if (migrate_use_block()) { error_setg(errp, "Block migration and snapshots are incompatible"); - ret =3D -EINVAL; - goto done; + return -EINVAL; } =20 + migrate_init(ms); + ms->to_dst_file =3D f; + qemu_mutex_unlock_iothread(); qemu_savevm_state_header(f); qemu_savevm_state_setup(f); @@ -1355,7 +1352,6 @@ static int qemu_savevm_state(QEMUFile *f, Error **err= p) error_setg_errno(errp, -ret, "Error while writing VM state"); } =20 -done: if (ret !=3D 0) { status =3D MIGRATION_STATUS_FAILED; } else { --=20 2.13.2.windows.1