From nobody Sun Apr 28 11:08:19 2024 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.zoho.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 1488051232549387.3669637765737; Sat, 25 Feb 2017 11:33:52 -0800 (PST) Received: from localhost ([::1]:43972 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chi6J-0001tx-A4 for importer@patchew.org; Sat, 25 Feb 2017 14:33:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33997) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chi4c-0000X2-0U for qemu-devel@nongnu.org; Sat, 25 Feb 2017 14:32:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1chi4Z-0007oa-Bt for qemu-devel@nongnu.org; Sat, 25 Feb 2017 14:32:05 -0500 Received: from mailhub.sw.ru ([195.214.232.25]:48585 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1chi4Y-0007o1-WC; Sat, 25 Feb 2017 14:32:03 -0500 Received: from kvm.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v1PJVtVZ000370; Sat, 25 Feb 2017 22:31:55 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Sat, 25 Feb 2017 22:31:52 +0300 Message-Id: <20170225193155.447462-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170225193155.447462-1-vsementsov@virtuozzo.com> References: <20170225193155.447462-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x [fuzzy] X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH 1/4] iotests: add migration corner cases test 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: kwolf@redhat.com, peter.maydell@linaro.org, vsementsov@virtuozzo.com, famz@redhat.com, lirans@il.ibm.com, quintela@redhat.com, jsnow@redhat.com, armbru@redhat.com, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, amit.shah@redhat.com, pbonzini@redhat.com, dgilbert@redhat.com 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 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/175 | 71 ++++++++++++++++++++++++++++++++++++++++++= ++++ tests/qemu-iotests/175.out | 5 ++++ tests/qemu-iotests/group | 1 + 3 files changed, 77 insertions(+) create mode 100644 tests/qemu-iotests/175 create mode 100644 tests/qemu-iotests/175.out diff --git a/tests/qemu-iotests/175 b/tests/qemu-iotests/175 new file mode 100644 index 0000000000..ef86c70db5 --- /dev/null +++ b/tests/qemu-iotests/175 @@ -0,0 +1,71 @@ +#!/usr/bin/env python +# +# Test migration corner-cases +# +# Copyright (C) Vladimir Sementsov-Ogievskiy 2017 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import os +import iotests +import time +from iotests import qemu_img + +disk =3D os.path.join(iotests.test_dir, 'disk') + +class TestMigrationCornerCases(iotests.QMPTestCase): + def setUp(self): + qemu_img('create', '-f', iotests.imgfmt, disk, '10M') + self.vm =3D iotests.VM().add_drive(disk) + self.vm.launch() + + def tearDown(self): + self.vm.shutdown() + os.remove(disk) + + def test_migrate_reset_cont_write(self): + result =3D self.vm.qmp('migrate', uri=3D'exec:cat>/dev/null') + self.assert_qmp(result, 'return', {}) + time.sleep(4) + + result =3D self.vm.qmp('human-monitor-command', + command_line=3D'system_reset') + self.assert_qmp(result, 'return', '') + + result =3D self.vm.qmp('cont') + self.assert_qmp(result, 'return', {}) + + result =3D self.vm.qmp('human-monitor-command', + command_line=3D'qemu-io drive0 "write 0 512"') + self.assert_qmp(result, 'return', '') + + def test_migrate_savevm(self): + result =3D self.vm.qmp('migrate', uri=3D'exec:cat>/dev/null') + self.assert_qmp(result, 'return', {}) + time.sleep(4) + + result =3D self.vm.qmp('human-monitor-command', command_line=3D'sa= vevm') + self.assert_qmp(result, 'return', '') + + def test_savevm_set_speed_savevm(self): + for i in range(10): + result =3D self.vm.qmp('human-monitor-command', command_line= =3D'savevm') + self.assert_qmp(result, 'return', '') + + result =3D self.vm.qmp('migrate_set_speed', value=3D9223372036= 853727232) + self.assert_qmp(result, 'return', {}) + +if __name__ =3D=3D '__main__': + iotests.main() diff --git a/tests/qemu-iotests/175.out b/tests/qemu-iotests/175.out new file mode 100644 index 0000000000..8d7e996700 --- /dev/null +++ b/tests/qemu-iotests/175.out @@ -0,0 +1,5 @@ +... +---------------------------------------------------------------------- +Ran 3 tests + +OK diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 985b9a6a36..1f4bf03185 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -167,3 +167,4 @@ 172 auto 173 rw auto 174 auto +175 auto quick --=20 2.11.1 From nobody Sun Apr 28 11:08:19 2024 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.zoho.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 1488051229967616.0487023430577; Sat, 25 Feb 2017 11:33:49 -0800 (PST) Received: from localhost ([::1]:43970 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chi6F-0001rD-Lx for importer@patchew.org; Sat, 25 Feb 2017 14:33:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34000) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chi4c-0000X8-12 for qemu-devel@nongnu.org; Sat, 25 Feb 2017 14:32:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1chi4Z-0007oR-B5 for qemu-devel@nongnu.org; Sat, 25 Feb 2017 14:32:06 -0500 Received: from mailhub.sw.ru ([195.214.232.25]:28749 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1chi4Y-0007o0-WA; Sat, 25 Feb 2017 14:32:03 -0500 Received: from kvm.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v1PJVtVa000370; Sat, 25 Feb 2017 22:31:55 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Sat, 25 Feb 2017 22:31:53 +0300 Message-Id: <20170225193155.447462-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170225193155.447462-1-vsementsov@virtuozzo.com> References: <20170225193155.447462-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x [fuzzy] X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH 2/4] qmp-cont: invalidate on RUN_STATE_PRELAUNCH 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: kwolf@redhat.com, peter.maydell@linaro.org, vsementsov@virtuozzo.com, famz@redhat.com, lirans@il.ibm.com, quintela@redhat.com, jsnow@redhat.com, armbru@redhat.com, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, amit.shah@redhat.com, pbonzini@redhat.com, dgilbert@redhat.com 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 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We must invalidate on RUN_STATE_PRELAUNCH too, as it is available through qmp_system_reset from RUN_STATE_POSTMIGRATE. Otherwise, we will come to qemu-kvm: block/io.c:1406: bdrv_co_do_pwritev: Assertion `!(bs->open_flags & 0x0800)' failed. on the first write after vm start. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Fam Zheng --- qmp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qmp.c b/qmp.c index dfaabac1a6..e61795d033 100644 --- a/qmp.c +++ b/qmp.c @@ -198,7 +198,8 @@ void qmp_cont(Error **errp) /* Continuing after completed migration. Images have been inactivated = to * allow the destination to take control. Need to get control back now= . */ if (runstate_check(RUN_STATE_FINISH_MIGRATE) || - runstate_check(RUN_STATE_POSTMIGRATE)) + runstate_check(RUN_STATE_POSTMIGRATE) || + runstate_check(RUN_STATE_PRELAUNCH)) { bdrv_invalidate_cache_all(&local_err); if (local_err) { --=20 2.11.1 From nobody Sun Apr 28 11:08:19 2024 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.zoho.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 148805160380446.368085966473814; Sat, 25 Feb 2017 11:40:03 -0800 (PST) Received: from localhost ([::1]:44006 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chiCG-0007Q8-Hh for importer@patchew.org; Sat, 25 Feb 2017 14:40:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33994) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chi4b-0000Wv-WA for qemu-devel@nongnu.org; Sat, 25 Feb 2017 14:32:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1chi4Z-0007og-Bz for qemu-devel@nongnu.org; Sat, 25 Feb 2017 14:32:05 -0500 Received: from mailhub.sw.ru ([195.214.232.25]:27389 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1chi4Y-0007o3-WD; Sat, 25 Feb 2017 14:32:03 -0500 Received: from kvm.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v1PJVtVb000370; Sat, 25 Feb 2017 22:31:56 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Sat, 25 Feb 2017 22:31:54 +0300 Message-Id: <20170225193155.447462-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170225193155.447462-1-vsementsov@virtuozzo.com> References: <20170225193155.447462-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x [fuzzy] X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH 3/4] savevm: fix savevm after migration 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: kwolf@redhat.com, peter.maydell@linaro.org, vsementsov@virtuozzo.com, famz@redhat.com, lirans@il.ibm.com, quintela@redhat.com, jsnow@redhat.com, armbru@redhat.com, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, amit.shah@redhat.com, pbonzini@redhat.com, dgilbert@redhat.com 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 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" After migration all drives are inactive and savevm will fail with qemu-kvm: block/io.c:1406: bdrv_co_do_pwritev: Assertion `!(bs->open_flags & 0x0800)' failed. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/snapshot.c | 3 ++- migration/savevm.c | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/block/snapshot.c b/block/snapshot.c index bf5c2ca5e1..256d06ac9f 100644 --- a/block/snapshot.c +++ b/block/snapshot.c @@ -145,7 +145,8 @@ bool bdrv_snapshot_find_by_id_and_name(BlockDriverState= *bs, int bdrv_can_snapshot(BlockDriverState *bs) { BlockDriver *drv =3D bs->drv; - if (!drv || !bdrv_is_inserted(bs) || bdrv_is_read_only(bs)) { + if (!drv || !bdrv_is_inserted(bs) || bdrv_is_read_only(bs) || + (bs->open_flags & BDRV_O_INACTIVE)) { return 0; } =20 diff --git a/migration/savevm.c b/migration/savevm.c index 5ecd264134..75e56d2d07 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2068,6 +2068,17 @@ int save_vmstate(Monitor *mon, const char *name) Error *local_err =3D NULL; AioContext *aio_context; =20 + if (runstate_check(RUN_STATE_FINISH_MIGRATE) || + runstate_check(RUN_STATE_POSTMIGRATE) || + runstate_check(RUN_STATE_PRELAUNCH)) + { + bdrv_invalidate_cache_all(&local_err); + if (local_err) { + error_report_err(local_err); + return -EINVAL; + } + } + if (!bdrv_all_can_snapshot(&bs)) { monitor_printf(mon, "Device '%s' is writable but does not " "support snapshots.\n", bdrv_get_device_name(bs)); --=20 2.11.1 From nobody Sun Apr 28 11:08:19 2024 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.zoho.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 1488051445592788.8180370252411; Sat, 25 Feb 2017 11:37:25 -0800 (PST) Received: from localhost ([::1]:43991 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chi9j-0004tx-Jo for importer@patchew.org; Sat, 25 Feb 2017 14:37:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33995) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chi4b-0000Wy-W9 for qemu-devel@nongnu.org; Sat, 25 Feb 2017 14:32:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1chi4Z-0007oW-BX for qemu-devel@nongnu.org; Sat, 25 Feb 2017 14:32:05 -0500 Received: from mailhub.sw.ru ([195.214.232.25]:44088 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1chi4Y-0007o2-WE; Sat, 25 Feb 2017 14:32:03 -0500 Received: from kvm.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v1PJVtVc000370; Sat, 25 Feb 2017 22:31:56 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Sat, 25 Feb 2017 22:31:55 +0300 Message-Id: <20170225193155.447462-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170225193155.447462-1-vsementsov@virtuozzo.com> References: <20170225193155.447462-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x [fuzzy] X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH 4/4] migration: fix use-after-free of to_dst_file 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: kwolf@redhat.com, peter.maydell@linaro.org, vsementsov@virtuozzo.com, famz@redhat.com, lirans@il.ibm.com, quintela@redhat.com, jsnow@redhat.com, armbru@redhat.com, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, amit.shah@redhat.com, pbonzini@redhat.com, dgilbert@redhat.com 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 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" hmp_savevm calls qemu_savevm_state(f), which sets to_dst_file=3Df in global migration state. Then hmp_savevm closes f (g_free called). Next access to to_dst_file in migration state (for example, qmp_migrate_set_speed) will use it after it was freed. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Dr. David Alan Gilbert --- migration/savevm.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/migration/savevm.c b/migration/savevm.c index 75e56d2d07..fcb8fd8acd 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1276,6 +1276,11 @@ done: status =3D MIGRATION_STATUS_COMPLETED; } migrate_set_state(&ms->state, MIGRATION_STATUS_SETUP, status); + + /* f is outer parameter, it should not stay in global migration state = after + * this function finished */ + ms->to_dst_file =3D NULL; + return ret; } =20 --=20 2.11.1