From nobody Wed Apr 24 16:09:26 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 1487012246072926.8314808703675; Mon, 13 Feb 2017 10:57:26 -0800 (PST) Received: from localhost ([::1]:58951 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdLoS-0007pg-Nj for importer@patchew.org; Mon, 13 Feb 2017 13:57:24 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39001) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdKls-0003RB-P5 for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cdKlq-0005tP-PS for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36528) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cdKlq-0005sx-Db for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:38 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 708473A7696; Mon, 13 Feb 2017 17:50:38 +0000 (UTC) Received: from dgilbert-t530.redhat.com (ovpn-117-140.ams2.redhat.com [10.36.117.140]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1DHoYkA007824; Mon, 13 Feb 2017 12:50:36 -0500 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org Date: Mon, 13 Feb 2017 17:50:20 +0000 Message-Id: <20170213175033.7314-2-dgilbert@redhat.com> In-Reply-To: <20170213175033.7314-1-dgilbert@redhat.com> References: <20170213175033.7314-1-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 13 Feb 2017 17:50:38 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 01/14] migration: remove myself as maintainer 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: pbutsykin@virtuozzo.com, amit@kernel.org, zhang.zhanghailiang@huawei.com, ashijeetacharya@gmail.com, quintela@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" From: Amit Shah I'm switching jobs, and I'm not sure I can continue maintaining migration. Signed-off-by: Amit Shah Message-Id: <1486120416-11566-1-git-send-email-amit.shah@redhat.com> Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert --- MAINTAINERS | 1 - 1 file changed, 1 deletion(-) diff --git a/MAINTAINERS b/MAINTAINERS index 7afbada..d8ea161 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1431,7 +1431,6 @@ F: scripts/checkpatch.pl =20 Migration M: Juan Quintela -M: Amit Shah M: Dr. David Alan Gilbert S: Maintained F: include/migration/ --=20 2.9.3 From nobody Wed Apr 24 16:09:26 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 1487009887418168.34290460330544; Mon, 13 Feb 2017 10:18:07 -0800 (PST) Received: from localhost ([::1]:58695 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdLCQ-0003u4-30 for importer@patchew.org; Mon, 13 Feb 2017 13:18:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39008) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdKlt-0003Rk-Cw for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cdKls-0005tz-8a for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53780) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cdKls-0005tg-2A for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:40 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 17E74C057FA6; Mon, 13 Feb 2017 17:50:40 +0000 (UTC) Received: from dgilbert-t530.redhat.com (ovpn-117-140.ams2.redhat.com [10.36.117.140]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1DHoYkB007824; Mon, 13 Feb 2017 12:50:38 -0500 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org Date: Mon, 13 Feb 2017 17:50:21 +0000 Message-Id: <20170213175033.7314-3-dgilbert@redhat.com> In-Reply-To: <20170213175033.7314-1-dgilbert@redhat.com> References: <20170213175033.7314-1-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 13 Feb 2017 17:50:40 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 02/14] MAINTAINERS: update my email address 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: pbutsykin@virtuozzo.com, amit@kernel.org, zhang.zhanghailiang@huawei.com, ashijeetacharya@gmail.com, quintela@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" From: Amit Shah I'm leaving my job at Red Hat, this email address will stop working next we= ek. Update it to one that I will have access to later. Signed-off-by: Amit Shah Message-Id: <1486120433-11628-1-git-send-email-amit.shah@redhat.com> Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert --- MAINTAINERS | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index d8ea161..fb57d8e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1034,7 +1034,7 @@ F: hw/input/virtio-input*.c F: include/hw/virtio/virtio-input.h =20 virtio-serial -M: Amit Shah +M: Amit Shah S: Supported F: hw/char/virtio-serial-bus.c F: hw/char/virtio-console.c @@ -1043,7 +1043,7 @@ F: tests/virtio-console-test.c F: tests/virtio-serial-test.c =20 virtio-rng -M: Amit Shah +M: Amit Shah S: Supported F: hw/virtio/virtio-rng.c F: include/hw/virtio/virtio-rng.h --=20 2.9.3 From nobody Wed Apr 24 16:09:26 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 1487012453313266.1490994329557; Mon, 13 Feb 2017 11:00:53 -0800 (PST) Received: from localhost ([::1]:58976 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdLrn-0002NO-MZ for importer@patchew.org; Mon, 13 Feb 2017 14:00:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39025) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdKlv-0003Te-Cq for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cdKlu-0005ua-2l for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:43 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38568) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cdKlt-0005uJ-KI for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:41 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A7BFFC04BD47; Mon, 13 Feb 2017 17:50:41 +0000 (UTC) Received: from dgilbert-t530.redhat.com (ovpn-117-140.ams2.redhat.com [10.36.117.140]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1DHoYkC007824; Mon, 13 Feb 2017 12:50:40 -0500 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org Date: Mon, 13 Feb 2017 17:50:22 +0000 Message-Id: <20170213175033.7314-4-dgilbert@redhat.com> In-Reply-To: <20170213175033.7314-1-dgilbert@redhat.com> References: <20170213175033.7314-1-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 13 Feb 2017 17:50:41 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 03/14] migration: add MigrationState arg for ram_save_/compressed_/page() 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: pbutsykin@virtuozzo.com, amit@kernel.org, zhang.zhanghailiang@huawei.com, ashijeetacharya@gmail.com, quintela@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" From: Pavel Butsykin Cosmetic patch. The use of ms variable instead of migrate_get_current() looks nicer, especially when there reuse. Signed-off-by: Pavel Butsykin Message-Id: <20170203152321.19739-2-pbutsykin@virtuozzo.com> Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Dr. David Alan Gilbert --- migration/ram.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index ef8fadf..91443b3 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -713,13 +713,14 @@ static int save_zero_page(QEMUFile *f, RAMBlock *bloc= k, ram_addr_t offset, * >=3D0 - Number of pages written - this might legally be 0 * if xbzrle noticed the page was the same. * + * @ms: The current migration state. * @f: QEMUFile where to send the data * @block: block that contains the page we want to send * @offset: offset inside the block for the page * @last_stage: if we are at the completion stage * @bytes_transferred: increase it with the number of transferred bytes */ -static int ram_save_page(QEMUFile *f, PageSearchStatus *pss, +static int ram_save_page(MigrationState *ms, QEMUFile *f, PageSearchStatus= *pss, bool last_stage, uint64_t *bytes_transferred) { int pages =3D -1; @@ -765,8 +766,7 @@ static int ram_save_page(QEMUFile *f, PageSearchStatus = *pss, */ xbzrle_cache_zero_page(current_addr); } else if (!ram_bulk_stage && - !migration_in_postcopy(migrate_get_current()) && - migrate_use_xbzrle()) { + !migration_in_postcopy(ms) && migrate_use_xbzrle()) { pages =3D save_xbzrle_page(f, &p, current_addr, block, offset, last_stage, bytes_transferred= ); if (!last_stage) { @@ -893,14 +893,15 @@ static int compress_page_with_multi_thread(QEMUFile *= f, RAMBlock *block, * * Returns: Number of pages written. * + * @ms: The current migration state. * @f: QEMUFile where to send the data * @block: block that contains the page we want to send * @offset: offset inside the block for the page * @last_stage: if we are at the completion stage * @bytes_transferred: increase it with the number of transferred bytes */ -static int ram_save_compressed_page(QEMUFile *f, PageSearchStatus *pss, - bool last_stage, +static int ram_save_compressed_page(MigrationState *ms, QEMUFile *f, + PageSearchStatus *pss, bool last_stage, uint64_t *bytes_transferred) { int pages =3D -1; @@ -1231,11 +1232,11 @@ static int ram_save_target_page(MigrationState *ms,= QEMUFile *f, if (migration_bitmap_clear_dirty(dirty_ram_abs)) { unsigned long *unsentmap; if (compression_switch && migrate_use_compression()) { - res =3D ram_save_compressed_page(f, pss, + res =3D ram_save_compressed_page(ms, f, pss, last_stage, bytes_transferred); } else { - res =3D ram_save_page(f, pss, last_stage, + res =3D ram_save_page(ms, f, pss, last_stage, bytes_transferred); } =20 --=20 2.9.3 From nobody Wed Apr 24 16:09:26 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 148701016905994.48205448976535; Mon, 13 Feb 2017 10:22:49 -0800 (PST) Received: from localhost ([::1]:58726 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdLGv-0008R7-Sv for importer@patchew.org; Mon, 13 Feb 2017 13:22:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39072) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdKm0-0003Xt-DG for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cdKlv-0005v0-Hs for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:48 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52584) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cdKlv-0005uh-8V for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:43 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 51FA54E028; Mon, 13 Feb 2017 17:50:43 +0000 (UTC) Received: from dgilbert-t530.redhat.com (ovpn-117-140.ams2.redhat.com [10.36.117.140]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1DHoYkD007824; Mon, 13 Feb 2017 12:50:41 -0500 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org Date: Mon, 13 Feb 2017 17:50:23 +0000 Message-Id: <20170213175033.7314-5-dgilbert@redhat.com> In-Reply-To: <20170213175033.7314-1-dgilbert@redhat.com> References: <20170213175033.7314-1-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 13 Feb 2017 17:50:43 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 04/14] add 'release-ram' migrate capability 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: pbutsykin@virtuozzo.com, amit@kernel.org, zhang.zhanghailiang@huawei.com, ashijeetacharya@gmail.com, quintela@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" From: Pavel Butsykin This feature frees the migrated memory on the source during postcopy-ram migration. In the second step of postcopy-ram migration when the source vm is put on pause we can free unnecessary memory. It will allow, in particula= r, to start relaxing the memory stress on the source host in a load-balancing scenario. Signed-off-by: Pavel Butsykin Message-Id: <20170203152321.19739-3-pbutsykin@virtuozzo.com> Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Dr. David Alan Gilbert Manually merged in Pavel's 'migration: madvise error_report fixup!' --- include/migration/migration.h | 1 + include/migration/qemu-file.h | 3 ++- migration/migration.c | 9 +++++++ migration/qemu-file.c | 59 ++++++++++++++++++++++++++++++++++++++-= ---- migration/ram.c | 22 +++++++++++++++- qapi-schema.json | 5 +++- 6 files changed, 89 insertions(+), 10 deletions(-) diff --git a/include/migration/migration.h b/include/migration/migration.h index 7528cc2..b9b706a 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -304,6 +304,7 @@ int migrate_add_blocker(Error *reason, Error **errp); */ void migrate_del_blocker(Error *reason); =20 +bool migrate_release_ram(void); bool migrate_postcopy_ram(void); bool migrate_zero_blocks(void); =20 diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h index abedd46..0cd648a 100644 --- a/include/migration/qemu-file.h +++ b/include/migration/qemu-file.h @@ -132,7 +132,8 @@ void qemu_put_byte(QEMUFile *f, int v); * put_buffer without copying the buffer. * The buffer should be available till it is sent asynchronously. */ -void qemu_put_buffer_async(QEMUFile *f, const uint8_t *buf, size_t size); +void qemu_put_buffer_async(QEMUFile *f, const uint8_t *buf, size_t size, + bool may_free); bool qemu_file_mode_is_not_valid(const char *mode); bool qemu_file_is_writable(QEMUFile *f); =20 diff --git a/migration/migration.c b/migration/migration.c index 2b179c6..68afc07 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1297,6 +1297,15 @@ void qmp_migrate_set_downtime(double value, Error **= errp) qmp_migrate_set_parameters(&p, errp); } =20 +bool migrate_release_ram(void) +{ + MigrationState *s; + + s =3D migrate_get_current(); + + return s->enabled_capabilities[MIGRATION_CAPABILITY_RELEASE_RAM]; +} + bool migrate_postcopy_ram(void) { MigrationState *s; diff --git a/migration/qemu-file.c b/migration/qemu-file.c index e9fae31..195fa94 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -49,6 +49,7 @@ struct QEMUFile { int buf_size; /* 0 when writing */ uint8_t buf[IO_BUF_SIZE]; =20 + DECLARE_BITMAP(may_free, MAX_IOV_SIZE); struct iovec iov[MAX_IOV_SIZE]; unsigned int iovcnt; =20 @@ -132,6 +133,41 @@ bool qemu_file_is_writable(QEMUFile *f) return f->ops->writev_buffer; } =20 +static void qemu_iovec_release_ram(QEMUFile *f) +{ + struct iovec iov; + unsigned long idx; + + /* Find and release all the contiguous memory ranges marked as may_fre= e. */ + idx =3D find_next_bit(f->may_free, f->iovcnt, 0); + if (idx >=3D f->iovcnt) { + return; + } + iov =3D f->iov[idx]; + + /* The madvise() in the loop is called for iov within a continuous ran= ge and + * then reinitialize the iov. And in the end, madvise() is called for = the + * last iov. + */ + while ((idx =3D find_next_bit(f->may_free, f->iovcnt, idx + 1)) < f->i= ovcnt) { + /* check for adjacent buffer and coalesce them */ + if (iov.iov_base + iov.iov_len =3D=3D f->iov[idx].iov_base) { + iov.iov_len +=3D f->iov[idx].iov_len; + continue; + } + if (qemu_madvise(iov.iov_base, iov.iov_len, QEMU_MADV_DONTNEED) < = 0) { + error_report("migrate: madvise DONTNEED failed %p %zd: %s", + iov.iov_base, iov.iov_len, strerror(errno)); + } + iov =3D f->iov[idx]; + } + if (qemu_madvise(iov.iov_base, iov.iov_len, QEMU_MADV_DONTNEED) < 0) { + error_report("migrate: madvise DONTNEED failed %p %zd: %s", + iov.iov_base, iov.iov_len, strerror(errno)); + } + memset(f->may_free, 0, sizeof(f->may_free)); +} + /** * Flushes QEMUFile buffer * @@ -151,6 +187,8 @@ void qemu_fflush(QEMUFile *f) if (f->iovcnt > 0) { expect =3D iov_size(f->iov, f->iovcnt); ret =3D f->ops->writev_buffer(f->opaque, f->iov, f->iovcnt, f->pos= ); + + qemu_iovec_release_ram(f); } =20 if (ret >=3D 0) { @@ -304,13 +342,19 @@ int qemu_fclose(QEMUFile *f) return ret; } =20 -static void add_to_iovec(QEMUFile *f, const uint8_t *buf, size_t size) +static void add_to_iovec(QEMUFile *f, const uint8_t *buf, size_t size, + bool may_free) { /* check for adjacent buffer and coalesce them */ if (f->iovcnt > 0 && buf =3D=3D f->iov[f->iovcnt - 1].iov_base + - f->iov[f->iovcnt - 1].iov_len) { + f->iov[f->iovcnt - 1].iov_len && + may_free =3D=3D test_bit(f->iovcnt - 1, f->may_free)) + { f->iov[f->iovcnt - 1].iov_len +=3D size; } else { + if (may_free) { + set_bit(f->iovcnt, f->may_free); + } f->iov[f->iovcnt].iov_base =3D (uint8_t *)buf; f->iov[f->iovcnt++].iov_len =3D size; } @@ -320,14 +364,15 @@ static void add_to_iovec(QEMUFile *f, const uint8_t *= buf, size_t size) } } =20 -void qemu_put_buffer_async(QEMUFile *f, const uint8_t *buf, size_t size) +void qemu_put_buffer_async(QEMUFile *f, const uint8_t *buf, size_t size, + bool may_free) { if (f->last_error) { return; } =20 f->bytes_xfer +=3D size; - add_to_iovec(f, buf, size); + add_to_iovec(f, buf, size, may_free); } =20 void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, size_t size) @@ -345,7 +390,7 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, s= ize_t size) } memcpy(f->buf + f->buf_index, buf, l); f->bytes_xfer +=3D l; - add_to_iovec(f, f->buf + f->buf_index, l); + add_to_iovec(f, f->buf + f->buf_index, l, false); f->buf_index +=3D l; if (f->buf_index =3D=3D IO_BUF_SIZE) { qemu_fflush(f); @@ -366,7 +411,7 @@ void qemu_put_byte(QEMUFile *f, int v) =20 f->buf[f->buf_index] =3D v; f->bytes_xfer++; - add_to_iovec(f, f->buf + f->buf_index, 1); + add_to_iovec(f, f->buf + f->buf_index, 1, false); f->buf_index++; if (f->buf_index =3D=3D IO_BUF_SIZE) { qemu_fflush(f); @@ -647,7 +692,7 @@ ssize_t qemu_put_compression_data(QEMUFile *f, const ui= nt8_t *p, size_t size, } qemu_put_be32(f, blen); if (f->ops->writev_buffer) { - add_to_iovec(f, f->buf + f->buf_index, blen); + add_to_iovec(f, f->buf + f->buf_index, blen, false); } f->buf_index +=3D blen; if (f->buf_index =3D=3D IO_BUF_SIZE) { diff --git a/migration/ram.c b/migration/ram.c index 91443b3..c22209d 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -705,6 +705,16 @@ static int save_zero_page(QEMUFile *f, RAMBlock *block= , ram_addr_t offset, return pages; } =20 +static void ram_release_pages(MigrationState *ms, const char *block_name, + uint64_t offset, int pages) +{ + if (!migrate_release_ram() || !migration_in_postcopy(ms)) { + return; + } + + ram_discard_range(NULL, block_name, offset, pages << TARGET_PAGE_BITS); +} + /** * ram_save_page: Send the given page to the stream * @@ -765,6 +775,7 @@ static int ram_save_page(MigrationState *ms, QEMUFile *= f, PageSearchStatus *pss, * page would be stale */ xbzrle_cache_zero_page(current_addr); + ram_release_pages(ms, block->idstr, pss->offset, pages); } else if (!ram_bulk_stage && !migration_in_postcopy(ms) && migrate_use_xbzrle()) { pages =3D save_xbzrle_page(f, &p, current_addr, block, @@ -783,7 +794,9 @@ static int ram_save_page(MigrationState *ms, QEMUFile *= f, PageSearchStatus *pss, *bytes_transferred +=3D save_page_header(f, block, offset | RAM_SAVE_FLAG_PAGE= ); if (send_async) { - qemu_put_buffer_async(f, p, TARGET_PAGE_SIZE); + qemu_put_buffer_async(f, p, TARGET_PAGE_SIZE, + migrate_release_ram() & + migration_in_postcopy(ms)); } else { qemu_put_buffer(f, p, TARGET_PAGE_SIZE); } @@ -813,6 +826,8 @@ static int do_compress_ram_page(QEMUFile *f, RAMBlock *= block, error_report("compressed data failed!"); } else { bytes_sent +=3D blen; + ram_release_pages(migrate_get_current(), block->idstr, + offset & TARGET_PAGE_MASK, 1); } =20 return bytes_sent; @@ -952,12 +967,17 @@ static int ram_save_compressed_page(MigrationState *m= s, QEMUFile *f, error_report("compressed data failed!"); } } + if (pages > 0) { + ram_release_pages(ms, block->idstr, pss->offset, pages); + } } else { offset |=3D RAM_SAVE_FLAG_CONTINUE; pages =3D save_zero_page(f, block, offset, p, bytes_transferre= d); if (pages =3D=3D -1) { pages =3D compress_page_with_multi_thread(f, block, offset, bytes_transferred); + } else { + ram_release_pages(ms, block->idstr, pss->offset, pages); } } } diff --git a/qapi-schema.json b/qapi-schema.json index 61151f3..9330541 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -865,11 +865,14 @@ # side, this process is called COarse-Grain LOck Stepping (COLO) for # Non-stop Service. (since 2.8) # +# @release-ram: if enabled, qemu will free the migrated ram pages on the s= ource +# during postcopy-ram migration. (since 2.9) +# # Since: 1.2 ## { 'enum': 'MigrationCapability', 'data': ['xbzrle', 'rdma-pin-all', 'auto-converge', 'zero-blocks', - 'compress', 'events', 'postcopy-ram', 'x-colo'] } + 'compress', 'events', 'postcopy-ram', 'x-colo', 'release-ram'] } =20 ## # @MigrationCapabilityStatus: --=20 2.9.3 From nobody Wed Apr 24 16:09:26 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 148701009307119.188834645867246; Mon, 13 Feb 2017 10:21:33 -0800 (PST) Received: from localhost ([::1]:58717 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdLFh-00071l-MQ for importer@patchew.org; Mon, 13 Feb 2017 13:21:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39073) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdKm0-0003Xu-DK for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cdKlx-0005vk-EO for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:48 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52610) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cdKlw-0005v8-UZ for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:45 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 043E74DD58; Mon, 13 Feb 2017 17:50:45 +0000 (UTC) Received: from dgilbert-t530.redhat.com (ovpn-117-140.ams2.redhat.com [10.36.117.140]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1DHoYkE007824; Mon, 13 Feb 2017 12:50:43 -0500 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org Date: Mon, 13 Feb 2017 17:50:24 +0000 Message-Id: <20170213175033.7314-6-dgilbert@redhat.com> In-Reply-To: <20170213175033.7314-1-dgilbert@redhat.com> References: <20170213175033.7314-1-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 13 Feb 2017 17:50:45 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 05/14] migration: discard non-dirty ram pages after the start of postcopy 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: pbutsykin@virtuozzo.com, amit@kernel.org, zhang.zhanghailiang@huawei.com, ashijeetacharya@gmail.com, quintela@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" From: Pavel Butsykin After the start of postcopy migration there are some non-dirty pages which = have already been migrated. These pages are no longer needed on the source vm so= that we can free them and it doen't hurt to complete the migration. Signed-off-by: Pavel Butsykin Message-Id: <20170203152321.19739-4-pbutsykin@virtuozzo.com> Signed-off-by: Dr. David Alan Gilbert --- include/migration/migration.h | 1 + migration/migration.c | 4 ++++ migration/ram.c | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/include/migration/migration.h b/include/migration/migration.h index b9b706a..71ce190 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -285,6 +285,7 @@ int ram_postcopy_send_discard_bitmap(MigrationState *ms= ); int ram_discard_range(MigrationIncomingState *mis, const char *block_name, uint64_t start, size_t length); int ram_postcopy_incoming_init(MigrationIncomingState *mis); +void ram_postcopy_migrated_memory_release(MigrationState *ms); =20 /** * @migrate_add_blocker - prevent migration from proceeding diff --git a/migration/migration.c b/migration/migration.c index 68afc07..2a26a20 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1722,6 +1722,10 @@ static int postcopy_start(MigrationState *ms, bool *= old_vm_running) */ qemu_savevm_send_ping(ms->to_dst_file, 4); =20 + if (migrate_release_ram()) { + ram_postcopy_migrated_memory_release(ms); + } + ret =3D qemu_file_get_error(ms->to_dst_file); if (ret) { error_report("postcopy_start: Migration stream errored"); diff --git a/migration/ram.c b/migration/ram.c index c22209d..67f2efb 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1537,6 +1537,25 @@ void ram_debug_dump_bitmap(unsigned long *todump, bo= ol expected) =20 /* **** functions for postcopy ***** */ =20 +void ram_postcopy_migrated_memory_release(MigrationState *ms) +{ + struct RAMBlock *block; + unsigned long *bitmap =3D atomic_rcu_read(&migration_bitmap_rcu)->bmap; + + QLIST_FOREACH_RCU(block, &ram_list.blocks, next) { + unsigned long first =3D block->offset >> TARGET_PAGE_BITS; + unsigned long range =3D first + (block->used_length >> TARGET_PAGE= _BITS); + unsigned long run_start =3D find_next_zero_bit(bitmap, range, firs= t); + + while (run_start < range) { + unsigned long run_end =3D find_next_bit(bitmap, range, run_sta= rt + 1); + ram_discard_range(NULL, block->idstr, run_start << TARGET_PAGE= _BITS, + (run_end - run_start) << TARGET_PAGE_BITS); + run_start =3D find_next_zero_bit(bitmap, range, run_end + 1); + } + } +} + /* * Callback from postcopy_each_ram_send_discard for each RAMBlock * Note: At this point the 'unsentmap' is the processed bitmap combined --=20 2.9.3 From nobody Wed Apr 24 16:09:26 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 1487012718697417.2589217911607; Mon, 13 Feb 2017 11:05:18 -0800 (PST) Received: from localhost ([::1]:59009 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdLw3-00070m-4z for importer@patchew.org; Mon, 13 Feb 2017 14:05:15 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39071) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdKm0-0003Xs-DD for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cdKly-0005wG-Tr for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:48 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36636) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cdKly-0005vv-Mh for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:46 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A9FC53E9; Mon, 13 Feb 2017 17:50:46 +0000 (UTC) Received: from dgilbert-t530.redhat.com (ovpn-117-140.ams2.redhat.com [10.36.117.140]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1DHoYkF007824; Mon, 13 Feb 2017 12:50:45 -0500 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org Date: Mon, 13 Feb 2017 17:50:25 +0000 Message-Id: <20170213175033.7314-7-dgilbert@redhat.com> In-Reply-To: <20170213175033.7314-1-dgilbert@redhat.com> References: <20170213175033.7314-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 13 Feb 2017 17:50:46 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 06/14] migrate: Introduce zero RAM checks to skip RAM 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: pbutsykin@virtuozzo.com, amit@kernel.org, zhang.zhanghailiang@huawei.com, ashijeetacharya@gmail.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Ashijeet Acharya Migration of a "none" machine with no RAM crashes abruptly as bitmap_new() fails and thus aborts. Instead place zero RAM checks at appropriate places to skip migration of RAM in this case and complete migration successfully for devices only. Signed-off-by: Ashijeet Acharya Message-Id: <1486564125-31366-1-git-send-email-ashijeetacharya@gmail.com> Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Dr. David Alan Gilbert --- migration/ram.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 67f2efb..f289fcd 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1346,6 +1346,11 @@ static int ram_find_and_save_block(QEMUFile *f, bool= last_stage, ram_addr_t dirty_ram_abs; /* Address of the start of the dirty page in ram_addr_t space */ =20 + /* No dirty page as there is zero RAM */ + if (!ram_bytes_total()) { + return pages; + } + pss.block =3D last_seen_block; pss.offset =3D last_offset; pss.complete_round =3D false; @@ -1952,14 +1957,17 @@ static int ram_save_init_globals(void) bytes_transferred =3D 0; reset_ram_globals(); =20 - ram_bitmap_pages =3D last_ram_offset() >> TARGET_PAGE_BITS; migration_bitmap_rcu =3D g_new0(struct BitmapRcu, 1); - migration_bitmap_rcu->bmap =3D bitmap_new(ram_bitmap_pages); - bitmap_set(migration_bitmap_rcu->bmap, 0, ram_bitmap_pages); - - if (migrate_postcopy_ram()) { - migration_bitmap_rcu->unsentmap =3D bitmap_new(ram_bitmap_pages); - bitmap_set(migration_bitmap_rcu->unsentmap, 0, ram_bitmap_pages); + /* Skip setting bitmap if there is no RAM */ + if (ram_bytes_total()) { + ram_bitmap_pages =3D last_ram_offset() >> TARGET_PAGE_BITS; + migration_bitmap_rcu->bmap =3D bitmap_new(ram_bitmap_pages); + bitmap_set(migration_bitmap_rcu->bmap, 0, ram_bitmap_pages); + + if (migrate_postcopy_ram()) { + migration_bitmap_rcu->unsentmap =3D bitmap_new(ram_bitmap_page= s); + bitmap_set(migration_bitmap_rcu->unsentmap, 0, ram_bitmap_page= s); + } } =20 /* --=20 2.9.3 From nobody Wed Apr 24 16:09:26 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 1487012941031583.123334196915; Mon, 13 Feb 2017 11:09:01 -0800 (PST) Received: from localhost ([::1]:59039 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdLzd-0002IF-9l for importer@patchew.org; Mon, 13 Feb 2017 14:08:57 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39103) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdKm3-0003Zl-90 for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cdKm0-0005ws-TX for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38626) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cdKm0-0005wQ-Jy for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:48 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A07B2C04BD3C; Mon, 13 Feb 2017 17:50:48 +0000 (UTC) Received: from dgilbert-t530.redhat.com (ovpn-117-140.ams2.redhat.com [10.36.117.140]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1DHoYkG007824; Mon, 13 Feb 2017 12:50:46 -0500 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org Date: Mon, 13 Feb 2017 17:50:26 +0000 Message-Id: <20170213175033.7314-8-dgilbert@redhat.com> In-Reply-To: <20170213175033.7314-1-dgilbert@redhat.com> References: <20170213175033.7314-1-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 13 Feb 2017 17:50:48 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 07/14] migration: consolidate VMStateField.start 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: pbutsykin@virtuozzo.com, amit@kernel.org, zhang.zhanghailiang@huawei.com, ashijeetacharya@gmail.com, quintela@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" From: Halil Pasic The member VMStateField.start is used for two things, partial data migration for VBUFFER data (basically provide migration for a sub-buffer) and for locating next in QTAILQ. The implementation of the VBUFFER feature is broken when VMSTATE_ALLOC is used. This however goes unnoticed because actually partial migration for VBUFFER is not used at all. Let's consolidate the usage of VMStateField.start by removing support for partial migration for VBUFFER. Signed-off-by: Halil Pasic Message-Id: <20170203175217.45562-1-pasic@linux.vnet.ibm.com> Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Dr. David Alan Gilbert --- hw/char/exynos4210_uart.c | 2 +- hw/display/g364fb.c | 2 +- hw/dma/pl330.c | 8 ++++---- hw/intc/exynos4210_gic.c | 2 +- hw/ipmi/isa_ipmi_bt.c | 6 ++---- hw/net/vmxnet3.c | 2 +- hw/nvram/mac_nvram.c | 2 +- hw/nvram/spapr_nvram.c | 2 +- hw/sd/sdhci.c | 2 +- hw/timer/m48t59.c | 2 +- include/migration/vmstate.h | 21 ++++++++------------- migration/savevm.c | 2 +- migration/vmstate.c | 4 ++-- target/s390x/machine.c | 2 +- util/fifo8.c | 2 +- 15 files changed, 27 insertions(+), 34 deletions(-) diff --git a/hw/char/exynos4210_uart.c b/hw/char/exynos4210_uart.c index 7c16e89..b75f28d 100644 --- a/hw/char/exynos4210_uart.c +++ b/hw/char/exynos4210_uart.c @@ -561,7 +561,7 @@ static const VMStateDescription vmstate_exynos4210_uart= _fifo =3D { .fields =3D (VMStateField[]) { VMSTATE_UINT32(sp, Exynos4210UartFIFO), VMSTATE_UINT32(rp, Exynos4210UartFIFO), - VMSTATE_VBUFFER_UINT32(data, Exynos4210UartFIFO, 1, NULL, 0, size), + VMSTATE_VBUFFER_UINT32(data, Exynos4210UartFIFO, 1, NULL, size), VMSTATE_END_OF_LIST() } }; diff --git a/hw/display/g364fb.c b/hw/display/g364fb.c index 70ef2c7..8cdc205 100644 --- a/hw/display/g364fb.c +++ b/hw/display/g364fb.c @@ -464,7 +464,7 @@ static const VMStateDescription vmstate_g364fb =3D { .minimum_version_id =3D 1, .post_load =3D g364fb_post_load, .fields =3D (VMStateField[]) { - VMSTATE_VBUFFER_UINT32(vram, G364State, 1, NULL, 0, vram_size), + VMSTATE_VBUFFER_UINT32(vram, G364State, 1, NULL, vram_size), VMSTATE_BUFFER_UNSAFE(color_palette, G364State, 0, 256 * 3), VMSTATE_BUFFER_UNSAFE(cursor_palette, G364State, 0, 9), VMSTATE_UINT16_ARRAY(cursor, G364State, 512), diff --git a/hw/dma/pl330.c b/hw/dma/pl330.c index c0bd9fe..32cf839 100644 --- a/hw/dma/pl330.c +++ b/hw/dma/pl330.c @@ -173,8 +173,8 @@ static const VMStateDescription vmstate_pl330_fifo =3D { .version_id =3D 1, .minimum_version_id =3D 1, .fields =3D (VMStateField[]) { - VMSTATE_VBUFFER_UINT32(buf, PL330Fifo, 1, NULL, 0, buf_size), - VMSTATE_VBUFFER_UINT32(tag, PL330Fifo, 1, NULL, 0, buf_size), + VMSTATE_VBUFFER_UINT32(buf, PL330Fifo, 1, NULL, buf_size), + VMSTATE_VBUFFER_UINT32(tag, PL330Fifo, 1, NULL, buf_size), VMSTATE_UINT32(head, PL330Fifo), VMSTATE_UINT32(num, PL330Fifo), VMSTATE_UINT32(buf_size, PL330Fifo), @@ -282,8 +282,8 @@ static const VMStateDescription vmstate_pl330 =3D { VMSTATE_STRUCT(manager, PL330State, 0, vmstate_pl330_chan, PL330Ch= an), VMSTATE_STRUCT_VARRAY_UINT32(chan, PL330State, num_chnls, 0, vmstate_pl330_chan, PL330Chan), - VMSTATE_VBUFFER_UINT32(lo_seqn, PL330State, 1, NULL, 0, num_chnls), - VMSTATE_VBUFFER_UINT32(hi_seqn, PL330State, 1, NULL, 0, num_chnls), + VMSTATE_VBUFFER_UINT32(lo_seqn, PL330State, 1, NULL, num_chnls), + VMSTATE_VBUFFER_UINT32(hi_seqn, PL330State, 1, NULL, num_chnls), VMSTATE_STRUCT(fifo, PL330State, 0, vmstate_pl330_fifo, PL330Fifo), VMSTATE_STRUCT(read_queue, PL330State, 0, vmstate_pl330_queue, PL330Queue), diff --git a/hw/intc/exynos4210_gic.c b/hw/intc/exynos4210_gic.c index fd7a8f3..2a55817 100644 --- a/hw/intc/exynos4210_gic.c +++ b/hw/intc/exynos4210_gic.c @@ -393,7 +393,7 @@ static const VMStateDescription vmstate_exynos4210_irq_= gate =3D { .version_id =3D 2, .minimum_version_id =3D 2, .fields =3D (VMStateField[]) { - VMSTATE_VBUFFER_UINT32(level, Exynos4210IRQGateState, 1, NULL, 0, = n_in), + VMSTATE_VBUFFER_UINT32(level, Exynos4210IRQGateState, 1, NULL, n_i= n), VMSTATE_END_OF_LIST() } }; diff --git a/hw/ipmi/isa_ipmi_bt.c b/hw/ipmi/isa_ipmi_bt.c index f036617..1c69cb3 100644 --- a/hw/ipmi/isa_ipmi_bt.c +++ b/hw/ipmi/isa_ipmi_bt.c @@ -471,10 +471,8 @@ static const VMStateDescription vmstate_ISAIPMIBTDevic= e =3D { VMSTATE_BOOL(bt.use_irq, ISAIPMIBTDevice), VMSTATE_BOOL(bt.irqs_enabled, ISAIPMIBTDevice), VMSTATE_UINT32(bt.outpos, ISAIPMIBTDevice), - VMSTATE_VBUFFER_UINT32(bt.outmsg, ISAIPMIBTDevice, 1, NULL, 0, - bt.outlen), - VMSTATE_VBUFFER_UINT32(bt.inmsg, ISAIPMIBTDevice, 1, NULL, 0, - bt.inlen), + VMSTATE_VBUFFER_UINT32(bt.outmsg, ISAIPMIBTDevice, 1, NULL, bt.out= len), + VMSTATE_VBUFFER_UINT32(bt.inmsg, ISAIPMIBTDevice, 1, NULL, bt.inle= n), VMSTATE_UINT8(bt.control_reg, ISAIPMIBTDevice), VMSTATE_UINT8(bt.mask_reg, ISAIPMIBTDevice), VMSTATE_UINT8(bt.waiting_rsp, ISAIPMIBTDevice), diff --git a/hw/net/vmxnet3.c b/hw/net/vmxnet3.c index 7dd4565..e13a798 100644 --- a/hw/net/vmxnet3.c +++ b/hw/net/vmxnet3.c @@ -2397,7 +2397,7 @@ static const VMStateDescription vmxstate_vmxnet3_mcas= t_list =3D { .pre_load =3D vmxnet3_mcast_list_pre_load, .needed =3D vmxnet3_mc_list_needed, .fields =3D (VMStateField[]) { - VMSTATE_VBUFFER_UINT32(mcast_list, VMXNET3State, 0, NULL, 0, + VMSTATE_VBUFFER_UINT32(mcast_list, VMXNET3State, 0, NULL, mcast_list_buff_size), VMSTATE_END_OF_LIST() } diff --git a/hw/nvram/mac_nvram.c b/hw/nvram/mac_nvram.c index 63f9ed1..aef80e6 100644 --- a/hw/nvram/mac_nvram.c +++ b/hw/nvram/mac_nvram.c @@ -82,7 +82,7 @@ static const VMStateDescription vmstate_macio_nvram =3D { .version_id =3D 1, .minimum_version_id =3D 1, .fields =3D (VMStateField[]) { - VMSTATE_VBUFFER_UINT32(data, MacIONVRAMState, 0, NULL, 0, size), + VMSTATE_VBUFFER_UINT32(data, MacIONVRAMState, 0, NULL, size), VMSTATE_END_OF_LIST() } }; diff --git a/hw/nvram/spapr_nvram.c b/hw/nvram/spapr_nvram.c index eb42ea3..65ba188 100644 --- a/hw/nvram/spapr_nvram.c +++ b/hw/nvram/spapr_nvram.c @@ -224,7 +224,7 @@ static const VMStateDescription vmstate_spapr_nvram =3D= { .post_load =3D spapr_nvram_post_load, .fields =3D (VMStateField[]) { VMSTATE_UINT32(size, sPAPRNVRAM), - VMSTATE_VBUFFER_ALLOC_UINT32(buf, sPAPRNVRAM, 1, NULL, 0, size), + VMSTATE_VBUFFER_ALLOC_UINT32(buf, sPAPRNVRAM, 1, NULL, size), VMSTATE_END_OF_LIST() }, }; diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c index 5bd5ab6..da32b5f 100644 --- a/hw/sd/sdhci.c +++ b/hw/sd/sdhci.c @@ -1253,7 +1253,7 @@ const VMStateDescription sdhci_vmstate =3D { VMSTATE_UINT16(data_count, SDHCIState), VMSTATE_UINT64(admasysaddr, SDHCIState), VMSTATE_UINT8(stopped_state, SDHCIState), - VMSTATE_VBUFFER_UINT32(fifo_buffer, SDHCIState, 1, NULL, 0, buf_ma= xsz), + VMSTATE_VBUFFER_UINT32(fifo_buffer, SDHCIState, 1, NULL, buf_maxsz= ), VMSTATE_TIMER_PTR(insert_timer, SDHCIState), VMSTATE_TIMER_PTR(transfer_timer, SDHCIState), VMSTATE_END_OF_LIST() diff --git a/hw/timer/m48t59.c b/hw/timer/m48t59.c index 0157977..474981a 100644 --- a/hw/timer/m48t59.c +++ b/hw/timer/m48t59.c @@ -563,7 +563,7 @@ static const VMStateDescription vmstate_m48t59 =3D { .fields =3D (VMStateField[]) { VMSTATE_UINT8(lock, M48t59State), VMSTATE_UINT16(addr, M48t59State), - VMSTATE_VBUFFER_UINT32(buffer, M48t59State, 0, NULL, 0, size), + VMSTATE_VBUFFER_UINT32(buffer, M48t59State, 0, NULL, size), VMSTATE_END_OF_LIST() } }; diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 6233fe2..39db47e 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -587,7 +587,8 @@ extern const VMStateInfo vmstate_info_qtailq; .offset =3D vmstate_offset_buffer(_state, _field) + _start, \ } =20 -#define VMSTATE_VBUFFER_MULTIPLY(_field, _state, _version, _test, _start, = _field_size, _multiply) { \ +#define VMSTATE_VBUFFER_MULTIPLY(_field, _state, _version, _test, \ + _field_size, _multiply) { \ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ .field_exists =3D (_test), \ @@ -596,10 +597,9 @@ extern const VMStateInfo vmstate_info_qtailq; .info =3D &vmstate_info_buffer, \ .flags =3D VMS_VBUFFER|VMS_POINTER|VMS_MULTIPLY, \ .offset =3D offsetof(_state, _field), \ - .start =3D (_start), \ } =20 -#define VMSTATE_VBUFFER(_field, _state, _version, _test, _start, _field_si= ze) { \ +#define VMSTATE_VBUFFER(_field, _state, _version, _test, _field_size) { \ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ .field_exists =3D (_test), \ @@ -607,10 +607,9 @@ extern const VMStateInfo vmstate_info_qtailq; .info =3D &vmstate_info_buffer, \ .flags =3D VMS_VBUFFER|VMS_POINTER, \ .offset =3D offsetof(_state, _field), \ - .start =3D (_start), \ } =20 -#define VMSTATE_VBUFFER_UINT32(_field, _state, _version, _test, _start, _f= ield_size) { \ +#define VMSTATE_VBUFFER_UINT32(_field, _state, _version, _test, _field_siz= e) { \ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ .field_exists =3D (_test), \ @@ -618,10 +617,10 @@ extern const VMStateInfo vmstate_info_qtailq; .info =3D &vmstate_info_buffer, \ .flags =3D VMS_VBUFFER|VMS_POINTER, \ .offset =3D offsetof(_state, _field), \ - .start =3D (_start), \ } =20 -#define VMSTATE_VBUFFER_ALLOC_UINT32(_field, _state, _version, _test, _sta= rt, _field_size) { \ +#define VMSTATE_VBUFFER_ALLOC_UINT32(_field, _state, _version, \ + _test, _field_size) { \ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ .field_exists =3D (_test), \ @@ -629,7 +628,6 @@ extern const VMStateInfo vmstate_info_qtailq; .info =3D &vmstate_info_buffer, \ .flags =3D VMS_VBUFFER|VMS_POINTER|VMS_ALLOC, \ .offset =3D offsetof(_state, _field), \ - .start =3D (_start), \ } =20 #define VMSTATE_BUFFER_UNSAFE_INFO_TEST(_field, _state, _test, _version, _= info, _size) { \ @@ -948,13 +946,10 @@ extern const VMStateInfo vmstate_info_qtailq; VMSTATE_BUFFER_START_MIDDLE_V(_f, _s, _start, 0) =20 #define VMSTATE_PARTIAL_VBUFFER(_f, _s, _size) \ - VMSTATE_VBUFFER(_f, _s, 0, NULL, 0, _size) + VMSTATE_VBUFFER(_f, _s, 0, NULL, _size) =20 #define VMSTATE_PARTIAL_VBUFFER_UINT32(_f, _s, _size) = \ - VMSTATE_VBUFFER_UINT32(_f, _s, 0, NULL, 0, _size) - -#define VMSTATE_SUB_VBUFFER(_f, _s, _start, _size) \ - VMSTATE_VBUFFER(_f, _s, 0, NULL, _start, _size) + VMSTATE_VBUFFER_UINT32(_f, _s, 0, NULL, _size) =20 #define VMSTATE_BUFFER_TEST(_f, _s, _test) \ VMSTATE_STATIC_BUFFER(_f, _s, 0, _test, 0, sizeof(typeof_field(_s, _f)= )) diff --git a/migration/savevm.c b/migration/savevm.c index 0199768..5ecd264 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -356,7 +356,7 @@ static const VMStateDescription vmstate_configuration = =3D { .pre_save =3D configuration_pre_save, .fields =3D (VMStateField[]) { VMSTATE_UINT32(len, SaveState), - VMSTATE_VBUFFER_ALLOC_UINT32(name, SaveState, 0, NULL, 0, len), + VMSTATE_VBUFFER_ALLOC_UINT32(name, SaveState, 0, NULL, len), VMSTATE_END_OF_LIST() }, .subsections =3D (const VMStateDescription*[]) { diff --git a/migration/vmstate.c b/migration/vmstate.c index 2b2b3a5..520341a 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -68,10 +68,10 @@ static void *vmstate_base_addr(void *opaque, VMStateFie= ld *field, bool alloc) } } if (size) { - *((void **)base_addr + field->start) =3D g_malloc(size); + *(void **)base_addr =3D g_malloc(size); } } - base_addr =3D *(void **)base_addr + field->start; + base_addr =3D *(void **)base_addr; } =20 return base_addr; diff --git a/target/s390x/machine.c b/target/s390x/machine.c index edc3a47..8503fa1 100644 --- a/target/s390x/machine.c +++ b/target/s390x/machine.c @@ -180,7 +180,7 @@ const VMStateDescription vmstate_s390_cpu =3D { VMSTATE_UINT8(env.cpu_state, S390CPU), VMSTATE_UINT8(env.sigp_order, S390CPU), VMSTATE_UINT32_V(irqstate_saved_size, S390CPU, 4), - VMSTATE_VBUFFER_UINT32(irqstate, S390CPU, 4, NULL, 0, + VMSTATE_VBUFFER_UINT32(irqstate, S390CPU, 4, NULL, irqstate_saved_size), VMSTATE_END_OF_LIST() }, diff --git a/util/fifo8.c b/util/fifo8.c index 5c64101..d38b3bd 100644 --- a/util/fifo8.c +++ b/util/fifo8.c @@ -118,7 +118,7 @@ const VMStateDescription vmstate_fifo8 =3D { .version_id =3D 1, .minimum_version_id =3D 1, .fields =3D (VMStateField[]) { - VMSTATE_VBUFFER_UINT32(data, Fifo8, 1, NULL, 0, capacity), + VMSTATE_VBUFFER_UINT32(data, Fifo8, 1, NULL, capacity), VMSTATE_UINT32(head, Fifo8), VMSTATE_UINT32(num, Fifo8), VMSTATE_END_OF_LIST() --=20 2.9.3 From nobody Wed Apr 24 16:09:26 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 1487010426380189.21669940788536; Mon, 13 Feb 2017 10:27:06 -0800 (PST) Received: from localhost ([::1]:58756 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdLL6-00041b-Pw for importer@patchew.org; Mon, 13 Feb 2017 13:27:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39112) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdKm4-0003aV-3N for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cdKm2-0005xH-Il for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36974) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cdKm2-0005x3-9k for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:50 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 553CE7E9F1; Mon, 13 Feb 2017 17:50:50 +0000 (UTC) Received: from dgilbert-t530.redhat.com (ovpn-117-140.ams2.redhat.com [10.36.117.140]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1DHoYkH007824; Mon, 13 Feb 2017 12:50:48 -0500 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org Date: Mon, 13 Feb 2017 17:50:27 +0000 Message-Id: <20170213175033.7314-9-dgilbert@redhat.com> In-Reply-To: <20170213175033.7314-1-dgilbert@redhat.com> References: <20170213175033.7314-1-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 13 Feb 2017 17:50:50 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 08/14] COLO: fix setting checkpoint-delay not working properly 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: pbutsykin@virtuozzo.com, amit@kernel.org, zhang.zhanghailiang@huawei.com, ashijeetacharya@gmail.com, quintela@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" From: zhanghailiang If we set checkpoint-delay through command 'migrate-set-parameters', It will not take effect until we finish last sleep chekpoint-delay, That's will be offensive espeically when we want to change its value from an extreme big one to a proper value. Fix it by using timer to realize checkpoint-delay. Signed-off-by: zhanghailiang Message-Id: <1484657864-21708-2-git-send-email-zhang.zhanghailiang@huawei.c= om> Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Dr. David Alan Gilbert --- include/migration/colo.h | 2 ++ include/migration/migration.h | 5 +++++ migration/colo.c | 33 +++++++++++++++++++++++---------- migration/migration.c | 3 +++ 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/include/migration/colo.h b/include/migration/colo.h index e32eef4..2bbff9e 100644 --- a/include/migration/colo.h +++ b/include/migration/colo.h @@ -35,4 +35,6 @@ COLOMode get_colo_mode(void); =20 /* failover */ void colo_do_failover(MigrationState *s); + +void colo_checkpoint_notify(void *opaque); #endif diff --git a/include/migration/migration.h b/include/migration/migration.h index 71ce190..cb83f16 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -188,6 +188,11 @@ struct MigrationState /* The RAMBlock used in the last src_page_request */ RAMBlock *last_req_rb; =20 + /* The semaphore is used to notify COLO thread to do checkpoint */ + QemuSemaphore colo_checkpoint_sem; + int64_t colo_checkpoint_time; + QEMUTimer *colo_delay_timer; + /* The last error that occurred */ Error *error; }; diff --git a/migration/colo.c b/migration/colo.c index 93c85c5..08b2e46 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -302,7 +302,7 @@ static void colo_process_checkpoint(MigrationState *s) { QIOChannelBuffer *bioc; QEMUFile *fb =3D NULL; - int64_t current_time, checkpoint_time =3D qemu_clock_get_ms(QEMU_CLOCK= _HOST); + int64_t current_time =3D qemu_clock_get_ms(QEMU_CLOCK_HOST); Error *local_err =3D NULL; int ret; =20 @@ -332,26 +332,21 @@ static void colo_process_checkpoint(MigrationState *s) qemu_mutex_unlock_iothread(); trace_colo_vm_state_change("stop", "run"); =20 + timer_mod(s->colo_delay_timer, + current_time + s->parameters.x_checkpoint_delay); + while (s->state =3D=3D MIGRATION_STATUS_COLO) { if (failover_get_state() !=3D FAILOVER_STATUS_NONE) { error_report("failover request"); goto out; } =20 - current_time =3D qemu_clock_get_ms(QEMU_CLOCK_HOST); - if (current_time - checkpoint_time < - s->parameters.x_checkpoint_delay) { - int64_t delay_ms; + qemu_sem_wait(&s->colo_checkpoint_sem); =20 - delay_ms =3D s->parameters.x_checkpoint_delay - - (current_time - checkpoint_time); - g_usleep(delay_ms * 1000); - } ret =3D colo_do_checkpoint_transaction(s, bioc, fb); if (ret < 0) { goto out; } - checkpoint_time =3D qemu_clock_get_ms(QEMU_CLOCK_HOST); } =20 out: @@ -364,14 +359,32 @@ out: qemu_fclose(fb); } =20 + timer_del(s->colo_delay_timer); + if (s->rp_state.from_dst_file) { qemu_fclose(s->rp_state.from_dst_file); } } =20 +void colo_checkpoint_notify(void *opaque) +{ + MigrationState *s =3D opaque; + int64_t next_notify_time; + + qemu_sem_post(&s->colo_checkpoint_sem); + s->colo_checkpoint_time =3D qemu_clock_get_ms(QEMU_CLOCK_HOST); + next_notify_time =3D s->colo_checkpoint_time + + s->parameters.x_checkpoint_delay; + timer_mod(s->colo_delay_timer, next_notify_time); +} + void migrate_start_colo_process(MigrationState *s) { qemu_mutex_unlock_iothread(); + qemu_sem_init(&s->colo_checkpoint_sem, 0); + s->colo_delay_timer =3D timer_new_ms(QEMU_CLOCK_HOST, + colo_checkpoint_notify, s); + migrate_set_state(&s->state, MIGRATION_STATUS_ACTIVE, MIGRATION_STATUS_COLO); colo_process_checkpoint(s); diff --git a/migration/migration.c b/migration/migration.c index 2a26a20..c6ae69d 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -891,6 +891,9 @@ void qmp_migrate_set_parameters(MigrationParameters *pa= rams, Error **errp) =20 if (params->has_x_checkpoint_delay) { s->parameters.x_checkpoint_delay =3D params->x_checkpoint_delay; + if (migration_in_colo_state()) { + colo_checkpoint_notify(s); + } } } =20 --=20 2.9.3 From nobody Wed Apr 24 16:09:26 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 1487010688365617.6482609583375; Mon, 13 Feb 2017 10:31:28 -0800 (PST) Received: from localhost ([::1]:58778 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdLPH-0008S8-N0 for importer@patchew.org; Mon, 13 Feb 2017 13:31:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39133) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdKm5-0003bF-M0 for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cdKm4-0005xs-6S for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53912) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cdKm3-0005xX-U8 for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:52 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 00F08C057FA6; Mon, 13 Feb 2017 17:50:52 +0000 (UTC) Received: from dgilbert-t530.redhat.com (ovpn-117-140.ams2.redhat.com [10.36.117.140]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1DHoYkI007824; Mon, 13 Feb 2017 12:50:50 -0500 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org Date: Mon, 13 Feb 2017 17:50:28 +0000 Message-Id: <20170213175033.7314-10-dgilbert@redhat.com> In-Reply-To: <20170213175033.7314-1-dgilbert@redhat.com> References: <20170213175033.7314-1-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 13 Feb 2017 17:50:52 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 09/14] COLO: Shutdown related socket fd while do failover 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: pbutsykin@virtuozzo.com, amit@kernel.org, zhang.zhanghailiang@huawei.com, ashijeetacharya@gmail.com, quintela@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" From: zhanghailiang If the net connection between primary host and secondary host breaks while COLO/COLO incoming threads are doing read() or write(). It will block until connection is timeout, and the failover process will be blocked because of it. So it is necessary to shutdown all the socket fds used by COLO to avoid this situation. Besides, we should close the corresponding file descriptors after failvoer BH shutdown them, Or there will be an error. Signed-off-by: zhanghailiang Signed-off-by: Li Zhijian Reviewed-by: Dr. David Alan Gilbert Cc: Dr. David Alan Gilbert Message-Id: <1484657864-21708-3-git-send-email-zhang.zhanghailiang@huawei.c= om> Signed-off-by: Dr. David Alan Gilbert --- include/migration/migration.h | 3 +++ migration/colo.c | 43 +++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 46 insertions(+) diff --git a/include/migration/migration.h b/include/migration/migration.h index cb83f16..1735d66 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -116,6 +116,7 @@ struct MigrationIncomingState { QemuThread colo_incoming_thread; /* The coroutine we should enter (back) after failover */ Coroutine *migration_incoming_co; + QemuSemaphore colo_incoming_sem; =20 /* See savevm.c */ LoadStateEntry_Head loadvm_handlers; @@ -187,6 +188,8 @@ struct MigrationState QSIMPLEQ_HEAD(src_page_requests, MigrationSrcPageRequest) src_page_req= uests; /* The RAMBlock used in the last src_page_request */ RAMBlock *last_req_rb; + /* The semaphore is used to notify COLO thread that failover is finish= ed */ + QemuSemaphore colo_exit_sem; =20 /* The semaphore is used to notify COLO thread to do checkpoint */ QemuSemaphore colo_checkpoint_sem; diff --git a/migration/colo.c b/migration/colo.c index 08b2e46..3222812 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -59,6 +59,18 @@ static void secondary_vm_do_failover(void) /* recover runstate to normal migration finish state */ autostart =3D true; } + /* + * Make sure COLO incoming thread not block in recv or send, + * If mis->from_src_file and mis->to_src_file use the same fd, + * The second shutdown() will return -1, we ignore this value, + * It is harmless. + */ + if (mis->from_src_file) { + qemu_file_shutdown(mis->from_src_file); + } + if (mis->to_src_file) { + qemu_file_shutdown(mis->to_src_file); + } =20 old_state =3D failover_set_state(FAILOVER_STATUS_ACTIVE, FAILOVER_STATUS_COMPLETED); @@ -67,6 +79,8 @@ static void secondary_vm_do_failover(void) "secondary VM", FailoverStatus_lookup[old_state]); return; } + /* Notify COLO incoming thread that failover work is finished */ + qemu_sem_post(&mis->colo_incoming_sem); /* For Secondary VM, jump to incoming co */ if (mis->migration_incoming_co) { qemu_coroutine_enter(mis->migration_incoming_co); @@ -81,6 +95,18 @@ static void primary_vm_do_failover(void) migrate_set_state(&s->state, MIGRATION_STATUS_COLO, MIGRATION_STATUS_COMPLETED); =20 + /* + * Wake up COLO thread which may blocked in recv() or send(), + * The s->rp_state.from_dst_file and s->to_dst_file may use the + * same fd, but we still shutdown the fd for twice, it is harmless. + */ + if (s->to_dst_file) { + qemu_file_shutdown(s->to_dst_file); + } + if (s->rp_state.from_dst_file) { + qemu_file_shutdown(s->rp_state.from_dst_file); + } + old_state =3D failover_set_state(FAILOVER_STATUS_ACTIVE, FAILOVER_STATUS_COMPLETED); if (old_state !=3D FAILOVER_STATUS_ACTIVE) { @@ -88,6 +114,8 @@ static void primary_vm_do_failover(void) FailoverStatus_lookup[old_state]); return; } + /* Notify COLO thread that failover work is finished */ + qemu_sem_post(&s->colo_exit_sem); } =20 void colo_do_failover(MigrationState *s) @@ -361,6 +389,14 @@ out: =20 timer_del(s->colo_delay_timer); =20 + /* Hope this not to be too long to wait here */ + qemu_sem_wait(&s->colo_exit_sem); + qemu_sem_destroy(&s->colo_exit_sem); + /* + * Must be called after failover BH is completed, + * Or the failover BH may shutdown the wrong fd that + * re-used by other threads after we release here. + */ if (s->rp_state.from_dst_file) { qemu_fclose(s->rp_state.from_dst_file); } @@ -385,6 +421,7 @@ void migrate_start_colo_process(MigrationState *s) s->colo_delay_timer =3D timer_new_ms(QEMU_CLOCK_HOST, colo_checkpoint_notify, s); =20 + qemu_sem_init(&s->colo_exit_sem, 0); migrate_set_state(&s->state, MIGRATION_STATUS_ACTIVE, MIGRATION_STATUS_COLO); colo_process_checkpoint(s); @@ -423,6 +460,8 @@ void *colo_process_incoming_thread(void *opaque) uint64_t value; Error *local_err =3D NULL; =20 + qemu_sem_init(&mis->colo_incoming_sem, 0); + migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE, MIGRATION_STATUS_COLO); =20 @@ -533,6 +572,10 @@ out: qemu_fclose(fb); } =20 + /* Hope this not to be too long to loop here */ + qemu_sem_wait(&mis->colo_incoming_sem); + qemu_sem_destroy(&mis->colo_incoming_sem); + /* Must be called after failover BH is completed */ if (mis->to_src_file) { qemu_fclose(mis->to_src_file); } --=20 2.9.3 From nobody Wed Apr 24 16:09:26 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 1487011616860917.3331194522956; Mon, 13 Feb 2017 10:46:56 -0800 (PST) Received: from localhost ([::1]:58875 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdLeJ-0006Z8-H2 for importer@patchew.org; Mon, 13 Feb 2017 13:46:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39162) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdKmA-0003fb-4U for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cdKm6-0005yb-0A for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49454) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cdKm5-0005yF-O8 for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:53 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B13DD80472; Mon, 13 Feb 2017 17:50:53 +0000 (UTC) Received: from dgilbert-t530.redhat.com (ovpn-117-140.ams2.redhat.com [10.36.117.140]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1DHoYkJ007824; Mon, 13 Feb 2017 12:50:52 -0500 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org Date: Mon, 13 Feb 2017 17:50:29 +0000 Message-Id: <20170213175033.7314-11-dgilbert@redhat.com> In-Reply-To: <20170213175033.7314-1-dgilbert@redhat.com> References: <20170213175033.7314-1-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 13 Feb 2017 17:50:53 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 10/14] COLO: Don't process failover request while loading VM's state 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: pbutsykin@virtuozzo.com, amit@kernel.org, zhang.zhanghailiang@huawei.com, ashijeetacharya@gmail.com, quintela@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" From: zhanghailiang We should not do failover work while the main thread is loading VM's state. Otherwise the consistent of VM's memory and device state will be broken. We will restart the loading process after jump over the stage, The new failover status 'RELAUNCH' will help to record if we need to restart the process. Cc: Eric Blake Signed-off-by: zhanghailiang Signed-off-by: Li Zhijian Reviewed-by: Dr. David Alan Gilbert Message-Id: <1484657864-21708-4-git-send-email-zhang.zhanghailiang@huawei.c= om> Signed-off-by: Dr. David Alan Gilbert Added a missing '(Since 2.9)' --- migration/colo.c | 26 ++++++++++++++++++++++++++ qapi-schema.json | 4 +++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/migration/colo.c b/migration/colo.c index 3222812..712308e 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -20,6 +20,8 @@ #include "qapi/error.h" #include "migration/failover.h" =20 +static bool vmstate_loading; + #define COLO_BUFFER_BASE_SIZE (4 * 1024 * 1024) =20 bool colo_supported(void) @@ -51,6 +53,19 @@ static void secondary_vm_do_failover(void) int old_state; MigrationIncomingState *mis =3D migration_incoming_get_current(); =20 + /* Can not do failover during the process of VM's loading VMstate, Or + * it will break the secondary VM. + */ + if (vmstate_loading) { + old_state =3D failover_set_state(FAILOVER_STATUS_ACTIVE, + FAILOVER_STATUS_RELAUNCH); + if (old_state !=3D FAILOVER_STATUS_ACTIVE) { + error_report("Unknown error while do failover for secondary VM= ," + "old_state: %s", FailoverStatus_lookup[old_state]= ); + } + return; + } + migrate_set_state(&mis->state, MIGRATION_STATUS_COLO, MIGRATION_STATUS_COMPLETED); =20 @@ -548,13 +563,23 @@ void *colo_process_incoming_thread(void *opaque) =20 qemu_mutex_lock_iothread(); qemu_system_reset(VMRESET_SILENT); + vmstate_loading =3D true; if (qemu_loadvm_state(fb) < 0) { error_report("COLO: loadvm failed"); qemu_mutex_unlock_iothread(); goto out; } + + vmstate_loading =3D false; qemu_mutex_unlock_iothread(); =20 + if (failover_get_state() =3D=3D FAILOVER_STATUS_RELAUNCH) { + failover_set_state(FAILOVER_STATUS_RELAUNCH, + FAILOVER_STATUS_NONE); + failover_request_active(NULL); + goto out; + } + colo_send_message(mis->to_src_file, COLO_MESSAGE_VMSTATE_LOADED, &local_err); if (local_err) { @@ -563,6 +588,7 @@ void *colo_process_incoming_thread(void *opaque) } =20 out: + vmstate_loading =3D false; /* Throw the unreported error message after exited from loop */ if (local_err) { error_report_err(local_err); diff --git a/qapi-schema.json b/qapi-schema.json index 9330541..5edb08d 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -1193,10 +1193,12 @@ # # @completed: finish the process of failover # +# @relaunch: restart the failover process, from 'none' -> 'completed' (Sin= ce 2.9) +# # Since: 2.8 ## { 'enum': 'FailoverStatus', - 'data': [ 'none', 'require', 'active', 'completed'] } + 'data': [ 'none', 'require', 'active', 'completed', 'relaunch' ] } =20 ## # @x-colo-lost-heartbeat: --=20 2.9.3 From nobody Wed Apr 24 16:09:26 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 1487010346609437.5523159315105; Mon, 13 Feb 2017 10:25:46 -0800 (PST) Received: from localhost ([::1]:58748 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdLJo-0002qu-UF for importer@patchew.org; Mon, 13 Feb 2017 13:25:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39170) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdKmA-0003gX-T4 for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:51:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cdKm7-0005yl-D2 for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42714) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cdKm7-0005yf-7L for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:55 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 48CBC61B85; Mon, 13 Feb 2017 17:50:55 +0000 (UTC) Received: from dgilbert-t530.redhat.com (ovpn-117-140.ams2.redhat.com [10.36.117.140]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1DHoYkK007824; Mon, 13 Feb 2017 12:50:53 -0500 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org Date: Mon, 13 Feb 2017 17:50:30 +0000 Message-Id: <20170213175033.7314-12-dgilbert@redhat.com> In-Reply-To: <20170213175033.7314-1-dgilbert@redhat.com> References: <20170213175033.7314-1-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 13 Feb 2017 17:50:55 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 11/14] migration: Add VMSTATE_UNUSED_VARRAY_UINT32 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: pbutsykin@virtuozzo.com, amit@kernel.org, zhang.zhanghailiang@huawei.com, ashijeetacharya@gmail.com, quintela@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" From: "Dr. David Alan Gilbert" VMSTATE_UNUSED_VARRAY_UINT32 is used to skip a chunk of the stream that's an n-element array; note the array size and the dynamic value read never get multiplied so there's no overflow risk. Signed-off-by: Dr. David Alan Gilbert Message-Id: <20170203160651.19917-2-dgilbert@redhat.com> Reviewed-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert --- include/migration/vmstate.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 39db47e..7339594 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -658,6 +658,17 @@ extern const VMStateInfo vmstate_info_qtailq; .flags =3D VMS_BUFFER, \ } =20 +/* Discard size * field_num bytes, where field_num is a uint32 member */ +#define VMSTATE_UNUSED_VARRAY_UINT32(_state, _test, _version, _field_num, = _size) {\ + .name =3D "unused", \ + .field_exists =3D (_test), \ + .num_offset =3D vmstate_offset_value(_state, _field_num, uint32_t),\ + .version_id =3D (_version), \ + .size =3D (_size), \ + .info =3D &vmstate_info_unused_buffer, \ + .flags =3D VMS_VARRAY_UINT32 | VMS_BUFFER, \ +} + /* _field_size should be a int32_t field in the _state struct giving the * size of the bitmap _field in bits. */ --=20 2.9.3 From nobody Wed Apr 24 16:09:26 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 1487010600000874.1441248714245; Mon, 13 Feb 2017 10:30:00 -0800 (PST) Received: from localhost ([::1]:58766 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdLNu-0007Ea-Dr for importer@patchew.org; Mon, 13 Feb 2017 13:29:58 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39172) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdKmA-0003ga-VX for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:51:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cdKm9-0005zD-B1 for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:59 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49486) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cdKm9-0005z2-1T for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:57 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 12E7680478; Mon, 13 Feb 2017 17:50:57 +0000 (UTC) Received: from dgilbert-t530.redhat.com (ovpn-117-140.ams2.redhat.com [10.36.117.140]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1DHoYkL007824; Mon, 13 Feb 2017 12:50:55 -0500 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org Date: Mon, 13 Feb 2017 17:50:31 +0000 Message-Id: <20170213175033.7314-13-dgilbert@redhat.com> In-Reply-To: <20170213175033.7314-1-dgilbert@redhat.com> References: <20170213175033.7314-1-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 13 Feb 2017 17:50:57 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 12/14] migration: Add VMSTATE_WITH_TMP 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: pbutsykin@virtuozzo.com, amit@kernel.org, zhang.zhanghailiang@huawei.com, ashijeetacharya@gmail.com, quintela@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" From: "Dr. David Alan Gilbert" VMSTATE_WITH_TMP is for handling structures where some calculation or rearrangement of the data needs to be performed before the data hits the wire. For example, where the value on the wire is an offset from a non-migrated base, but the data in the structure is the actual pointer. To use it, a temporary type is created and a vmsd used on that type. The first element of the type must be 'parent' a pointer back to the type of the main structure. VMSTATE_WITH_TMP takes care of allocating and freeing the temporary before running the child vmsd. The post_load/pre_save on the child vmsd can copy things from the parent to the temporary using the parent pointer and do any other calculations needed; it can then use normal VMSD entries to do the actual data storage without having to fiddle around with qemu_get_*/qemu_put_* Signed-off-by: Dr. David Alan Gilbert Reviewed-by: David Gibson Reviewed-by: Juan Quintela Message-Id: <20170203160651.19917-3-dgilbert@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- include/migration/vmstate.h | 19 +++++++++++++++++++ migration/vmstate.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 7339594..63e7b02 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -259,6 +259,7 @@ extern const VMStateInfo vmstate_info_cpudouble; extern const VMStateInfo vmstate_info_timer; extern const VMStateInfo vmstate_info_buffer; extern const VMStateInfo vmstate_info_unused_buffer; +extern const VMStateInfo vmstate_info_tmp; extern const VMStateInfo vmstate_info_bitmap; extern const VMStateInfo vmstate_info_qtailq; =20 @@ -649,6 +650,24 @@ extern const VMStateInfo vmstate_info_qtailq; .offset =3D offsetof(_state, _field), \ } =20 +/* Allocate a temporary of type 'tmp_type', set tmp->parent to _state + * and execute the vmsd on the temporary. Note that we're working with + * the whole of _state here, not a field within it. + * We compile time check that: + * That _tmp_type contains a 'parent' member that's a pointer to the + * '_state' type + * That the pointer is right at the start of _tmp_type. + */ +#define VMSTATE_WITH_TMP(_state, _tmp_type, _vmsd) { \ + .name =3D "tmp", \ + .size =3D sizeof(_tmp_type) + \ + QEMU_BUILD_BUG_ON_ZERO(offsetof(_tmp_type, parent) != =3D 0) + \ + type_check_pointer(_state, \ + typeof_field(_tmp_type, parent)), \ + .vmsd =3D &(_vmsd), \ + .info =3D &vmstate_info_tmp, \ +} + #define VMSTATE_UNUSED_BUFFER(_test, _version, _size) { \ .name =3D "unused", \ .field_exists =3D (_test), \ diff --git a/migration/vmstate.c b/migration/vmstate.c index 520341a..b4d8ae9 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -935,6 +935,46 @@ const VMStateInfo vmstate_info_unused_buffer =3D { .put =3D put_unused_buffer, }; =20 +/* vmstate_info_tmp, see VMSTATE_WITH_TMP, the idea is that we allocate + * a temporary buffer and the pre_load/pre_save methods in the child vmsd + * copy stuff from the parent into the child and do calculations to fill + * in fields that don't really exist in the parent but need to be in the + * stream. + */ +static int get_tmp(QEMUFile *f, void *pv, size_t size, VMStateField *field) +{ + int ret; + const VMStateDescription *vmsd =3D field->vmsd; + int version_id =3D field->version_id; + void *tmp =3D g_malloc(size); + + /* Writes the parent field which is at the start of the tmp */ + *(void **)tmp =3D pv; + ret =3D vmstate_load_state(f, vmsd, tmp, version_id); + g_free(tmp); + return ret; +} + +static int put_tmp(QEMUFile *f, void *pv, size_t size, VMStateField *field, + QJSON *vmdesc) +{ + const VMStateDescription *vmsd =3D field->vmsd; + void *tmp =3D g_malloc(size); + + /* Writes the parent field which is at the start of the tmp */ + *(void **)tmp =3D pv; + vmstate_save_state(f, vmsd, tmp, vmdesc); + g_free(tmp); + + return 0; +} + +const VMStateInfo vmstate_info_tmp =3D { + .name =3D "tmp", + .get =3D get_tmp, + .put =3D put_tmp, +}; + /* bitmaps (as defined by bitmap.h). Note that size here is the size * of the bitmap in bits. The on-the-wire format of a bitmap is 64 * bit words with the bits in big endian order. The in-memory format --=20 2.9.3 From nobody Wed Apr 24 16:09:26 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 1487010880574859.6422928742546; Mon, 13 Feb 2017 10:34:40 -0800 (PST) Received: from localhost ([::1]:58788 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdLSR-00039n-A7 for importer@patchew.org; Mon, 13 Feb 2017 13:34:39 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39190) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdKmC-0003hm-76 for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:51:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cdKmA-0005zY-Q4 for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:51:00 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38722) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cdKmA-0005zK-Hh for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:50:58 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9E710C04BD3C; Mon, 13 Feb 2017 17:50:58 +0000 (UTC) Received: from dgilbert-t530.redhat.com (ovpn-117-140.ams2.redhat.com [10.36.117.140]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1DHoYkM007824; Mon, 13 Feb 2017 12:50:57 -0500 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org Date: Mon, 13 Feb 2017 17:50:32 +0000 Message-Id: <20170213175033.7314-14-dgilbert@redhat.com> In-Reply-To: <20170213175033.7314-1-dgilbert@redhat.com> References: <20170213175033.7314-1-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 13 Feb 2017 17:50:58 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 13/14] tests/migration: Add test for VMSTATE_WITH_TMP 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: pbutsykin@virtuozzo.com, amit@kernel.org, zhang.zhanghailiang@huawei.com, ashijeetacharya@gmail.com, quintela@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" From: "Dr. David Alan Gilbert" Add a test for VMSTATE_WITH_TMP to tests/test-vmstate.c Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Juan Quintela Message-Id: <20170203160651.19917-4-dgilbert@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- tests/test-vmstate.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++= ---- 1 file changed, 92 insertions(+), 6 deletions(-) diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c index 9d87faf..d0dd390 100644 --- a/tests/test-vmstate.c +++ b/tests/test-vmstate.c @@ -90,7 +90,7 @@ static void save_buffer(const uint8_t *buf, size_t buf_si= ze) qemu_fclose(fsave); } =20 -static void compare_vmstate(uint8_t *wire, size_t size) +static void compare_vmstate(const uint8_t *wire, size_t size) { QEMUFile *f =3D open_test_file(false); uint8_t result[size]; @@ -113,7 +113,7 @@ static void compare_vmstate(uint8_t *wire, size_t size) } =20 static int load_vmstate_one(const VMStateDescription *desc, void *obj, - int version, uint8_t *wire, size_t size) + int version, const uint8_t *wire, size_t size) { QEMUFile *f; int ret; @@ -137,7 +137,7 @@ static int load_vmstate_one(const VMStateDescription *d= esc, void *obj, static int load_vmstate(const VMStateDescription *desc, void *obj, void *obj_clone, void (*obj_copy)(void *, void*), - int version, uint8_t *wire, size_t size) + int version, const uint8_t *wire, size_t size) { /* We test with zero size */ obj_copy(obj_clone, obj); @@ -289,7 +289,6 @@ static void test_simple_primitive(void) FIELD_EQUAL(i64_1); FIELD_EQUAL(i64_2); } -#undef FIELD_EQUAL =20 typedef struct TestStruct { uint32_t a, b, c, e; @@ -474,7 +473,6 @@ static void test_load_skip(void) qemu_fclose(loading); } =20 - typedef struct { int32_t i; } TestStructTriv; @@ -688,6 +686,94 @@ static void test_load_q(void) qemu_fclose(fload); } =20 +typedef struct TmpTestStruct { + TestStruct *parent; + int64_t diff; +} TmpTestStruct; + +static void tmp_child_pre_save(void *opaque) +{ + struct TmpTestStruct *tts =3D opaque; + + tts->diff =3D tts->parent->b - tts->parent->a; +} + +static int tmp_child_post_load(void *opaque, int version_id) +{ + struct TmpTestStruct *tts =3D opaque; + + tts->parent->b =3D tts->parent->a + tts->diff; + + return 0; +} + +static const VMStateDescription vmstate_tmp_back_to_parent =3D { + .name =3D "test/tmp_child_parent", + .fields =3D (VMStateField[]) { + VMSTATE_UINT64(f, TestStruct), + VMSTATE_END_OF_LIST() + } +}; + +static const VMStateDescription vmstate_tmp_child =3D { + .name =3D "test/tmp_child", + .pre_save =3D tmp_child_pre_save, + .post_load =3D tmp_child_post_load, + .fields =3D (VMStateField[]) { + VMSTATE_INT64(diff, TmpTestStruct), + VMSTATE_STRUCT_POINTER(parent, TmpTestStruct, + vmstate_tmp_back_to_parent, TestStruct), + VMSTATE_END_OF_LIST() + } +}; + +static const VMStateDescription vmstate_with_tmp =3D { + .name =3D "test/with_tmp", + .version_id =3D 1, + .fields =3D (VMStateField[]) { + VMSTATE_UINT32(a, TestStruct), + VMSTATE_UINT64(d, TestStruct), + VMSTATE_WITH_TMP(TestStruct, TmpTestStruct, vmstate_tmp_child), + VMSTATE_END_OF_LIST() + } +}; + +static void obj_tmp_copy(void *target, void *source) +{ + memcpy(target, source, sizeof(TestStruct)); +} + +static void test_tmp_struct(void) +{ + TestStruct obj, obj_clone; + + uint8_t const wire_with_tmp[] =3D { + /* u32 a */ 0x00, 0x00, 0x00, 0x02, + /* u64 d */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + /* diff */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, + /* u64 f */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, + QEMU_VM_EOF, /* just to ensure we won't get EOF reported premature= ly */ + }; + + memset(&obj, 0, sizeof(obj)); + obj.a =3D 2; + obj.b =3D 4; + obj.d =3D 1; + obj.f =3D 8; + save_vmstate(&vmstate_with_tmp, &obj); + + compare_vmstate(wire_with_tmp, sizeof(wire_with_tmp)); + + memset(&obj, 0, sizeof(obj)); + SUCCESS(load_vmstate(&vmstate_with_tmp, &obj, &obj_clone, + obj_tmp_copy, 1, wire_with_tmp, + sizeof(wire_with_tmp))); + g_assert_cmpint(obj.a, =3D=3D, 2); /* From top level vmsd */ + g_assert_cmpint(obj.b, =3D=3D, 4); /* from the post_load */ + g_assert_cmpint(obj.d, =3D=3D, 1); /* From top level vmsd */ + g_assert_cmpint(obj.f, =3D=3D, 8); /* From the child->parent */ +} + int main(int argc, char **argv) { temp_fd =3D mkstemp(temp_file); @@ -708,7 +794,7 @@ int main(int argc, char **argv) test_arr_ptr_str_no0_load); g_test_add_func("/vmstate/qtailq/save/saveq", test_save_q); g_test_add_func("/vmstate/qtailq/load/loadq", test_load_q); - + g_test_add_func("/vmstate/tmp_struct", test_tmp_struct); g_test_run(); =20 close(temp_fd); --=20 2.9.3 From nobody Wed Apr 24 16:09:26 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 1487013086081989.708180497534; Mon, 13 Feb 2017 11:11:26 -0800 (PST) Received: from localhost ([::1]:59064 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdM20-0004Fc-HZ for importer@patchew.org; Mon, 13 Feb 2017 14:11:24 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39202) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdKmE-0003kl-Tj for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:51:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cdKmC-0005zx-Gq for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:51:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36788) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cdKmC-0005zl-7M for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:51:00 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4E966A89D; Mon, 13 Feb 2017 17:51:00 +0000 (UTC) Received: from dgilbert-t530.redhat.com (ovpn-117-140.ams2.redhat.com [10.36.117.140]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1DHoYkN007824; Mon, 13 Feb 2017 12:50:58 -0500 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org Date: Mon, 13 Feb 2017 17:50:33 +0000 Message-Id: <20170213175033.7314-15-dgilbert@redhat.com> In-Reply-To: <20170213175033.7314-1-dgilbert@redhat.com> References: <20170213175033.7314-1-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 13 Feb 2017 17:51:00 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 14/14] virtio/migration: Migrate virtio-net to VMState 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: pbutsykin@virtuozzo.com, amit@kernel.org, zhang.zhanghailiang@huawei.com, ashijeetacharya@gmail.com, quintela@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" From: "Dr. David Alan Gilbert" Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Michael S. Tsirkin Message-Id: <20170203160651.19917-5-dgilbert@redhat.com> Signed-off-by: Dr. David Alan Gilbert Merge fix against Halil's removal of the '_start' field in VMSTATE_VBUFFER_MULTIPLY --- hw/net/virtio-net.c | 316 +++++++++++++++++++++++++++----------= ---- include/hw/virtio/virtio-net.h | 4 +- 2 files changed, 213 insertions(+), 107 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 7b3ad4a..354a19e 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1557,119 +1557,22 @@ static void virtio_net_set_multiqueue(VirtIONet *n= , int multiqueue) virtio_net_set_queues(n); } =20 -static void virtio_net_save_device(VirtIODevice *vdev, QEMUFile *f) +static int virtio_net_post_load_device(void *opaque, int version_id) { - VirtIONet *n =3D VIRTIO_NET(vdev); - int i; - - qemu_put_buffer(f, n->mac, ETH_ALEN); - qemu_put_be32(f, n->vqs[0].tx_waiting); - qemu_put_be32(f, n->mergeable_rx_bufs); - qemu_put_be16(f, n->status); - qemu_put_byte(f, n->promisc); - qemu_put_byte(f, n->allmulti); - qemu_put_be32(f, n->mac_table.in_use); - qemu_put_buffer(f, n->mac_table.macs, n->mac_table.in_use * ETH_ALEN); - qemu_put_buffer(f, (uint8_t *)n->vlans, MAX_VLAN >> 3); - qemu_put_be32(f, n->has_vnet_hdr); - qemu_put_byte(f, n->mac_table.multi_overflow); - qemu_put_byte(f, n->mac_table.uni_overflow); - qemu_put_byte(f, n->alluni); - qemu_put_byte(f, n->nomulti); - qemu_put_byte(f, n->nouni); - qemu_put_byte(f, n->nobcast); - qemu_put_byte(f, n->has_ufo); - if (n->max_queues > 1) { - qemu_put_be16(f, n->max_queues); - qemu_put_be16(f, n->curr_queues); - for (i =3D 1; i < n->curr_queues; i++) { - qemu_put_be32(f, n->vqs[i].tx_waiting); - } - } - - if (virtio_vdev_has_feature(vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS)) { - qemu_put_be64(f, n->curr_guest_offloads); - } -} - -static int virtio_net_load_device(VirtIODevice *vdev, QEMUFile *f, - int version_id) -{ - VirtIONet *n =3D VIRTIO_NET(vdev); + VirtIONet *n =3D opaque; + VirtIODevice *vdev =3D VIRTIO_DEVICE(n); int i, link_down; =20 - qemu_get_buffer(f, n->mac, ETH_ALEN); - n->vqs[0].tx_waiting =3D qemu_get_be32(f); - - virtio_net_set_mrg_rx_bufs(n, qemu_get_be32(f), + virtio_net_set_mrg_rx_bufs(n, n->mergeable_rx_bufs, virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)= ); =20 - n->status =3D qemu_get_be16(f); - - n->promisc =3D qemu_get_byte(f); - n->allmulti =3D qemu_get_byte(f); - - n->mac_table.in_use =3D qemu_get_be32(f); /* MAC_TABLE_ENTRIES may be different from the saved image */ - if (n->mac_table.in_use <=3D MAC_TABLE_ENTRIES) { - qemu_get_buffer(f, n->mac_table.macs, - n->mac_table.in_use * ETH_ALEN); - } else { - int64_t i; - - /* Overflow detected - can happen if source has a larger MAC table. - * We simply set overflow flag so there's no need to maintain the - * table of addresses, discard them all. - * Note: 64 bit math to avoid integer overflow. - */ - for (i =3D 0; i < (int64_t)n->mac_table.in_use * ETH_ALEN; ++i) { - qemu_get_byte(f); - } - n->mac_table.multi_overflow =3D n->mac_table.uni_overflow =3D 1; + if (n->mac_table.in_use > MAC_TABLE_ENTRIES) { n->mac_table.in_use =3D 0; } -=20 - qemu_get_buffer(f, (uint8_t *)n->vlans, MAX_VLAN >> 3); - - if (qemu_get_be32(f) && !peer_has_vnet_hdr(n)) { - error_report("virtio-net: saved image requires vnet_hdr=3Don"); - return -1; - } - - n->mac_table.multi_overflow =3D qemu_get_byte(f); - n->mac_table.uni_overflow =3D qemu_get_byte(f); - - n->alluni =3D qemu_get_byte(f); - n->nomulti =3D qemu_get_byte(f); - n->nouni =3D qemu_get_byte(f); - n->nobcast =3D qemu_get_byte(f); - - if (qemu_get_byte(f) && !peer_has_ufo(n)) { - error_report("virtio-net: saved image requires TUN_F_UFO support"); - return -1; - } =20 - if (n->max_queues > 1) { - if (n->max_queues !=3D qemu_get_be16(f)) { - error_report("virtio-net: different max_queues "); - return -1; - } - - n->curr_queues =3D qemu_get_be16(f); - if (n->curr_queues > n->max_queues) { - error_report("virtio-net: curr_queues %x > max_queues %x", - n->curr_queues, n->max_queues); - return -1; - } - for (i =3D 1; i < n->curr_queues; i++) { - n->vqs[i].tx_waiting =3D qemu_get_be32(f); - } - } - - if (virtio_vdev_has_feature(vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS)) { - n->curr_guest_offloads =3D qemu_get_be64(f); - } else { + if (!virtio_vdev_has_feature(vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS)) { n->curr_guest_offloads =3D virtio_net_supported_guest_offloads(n); } =20 @@ -1703,6 +1606,210 @@ static int virtio_net_load_device(VirtIODevice *vde= v, QEMUFile *f, return 0; } =20 +/* tx_waiting field of a VirtIONetQueue */ +static const VMStateDescription vmstate_virtio_net_queue_tx_waiting =3D { + .name =3D "virtio-net-queue-tx_waiting", + .fields =3D (VMStateField[]) { + VMSTATE_UINT32(tx_waiting, VirtIONetQueue), + VMSTATE_END_OF_LIST() + }, +}; + +static bool max_queues_gt_1(void *opaque, int version_id) +{ + return VIRTIO_NET(opaque)->max_queues > 1; +} + +static bool has_ctrl_guest_offloads(void *opaque, int version_id) +{ + return virtio_vdev_has_feature(VIRTIO_DEVICE(opaque), + VIRTIO_NET_F_CTRL_GUEST_OFFLOADS); +} + +static bool mac_table_fits(void *opaque, int version_id) +{ + return VIRTIO_NET(opaque)->mac_table.in_use <=3D MAC_TABLE_ENTRIES; +} + +static bool mac_table_doesnt_fit(void *opaque, int version_id) +{ + return !mac_table_fits(opaque, version_id); +} + +/* This temporary type is shared by all the WITH_TMP methods + * although only some fields are used by each. + */ +struct VirtIONetMigTmp { + VirtIONet *parent; + VirtIONetQueue *vqs_1; + uint16_t curr_queues_1; + uint8_t has_ufo; + uint32_t has_vnet_hdr; +}; + +/* The 2nd and subsequent tx_waiting flags are loaded later than + * the 1st entry in the queues and only if there's more than one + * entry. We use the tmp mechanism to calculate a temporary + * pointer and count and also validate the count. + */ + +static void virtio_net_tx_waiting_pre_save(void *opaque) +{ + struct VirtIONetMigTmp *tmp =3D opaque; + + tmp->vqs_1 =3D tmp->parent->vqs + 1; + tmp->curr_queues_1 =3D tmp->parent->curr_queues - 1; + if (tmp->parent->curr_queues =3D=3D 0) { + tmp->curr_queues_1 =3D 0; + } +} + +static int virtio_net_tx_waiting_pre_load(void *opaque) +{ + struct VirtIONetMigTmp *tmp =3D opaque; + + /* Reuse the pointer setup from save */ + virtio_net_tx_waiting_pre_save(opaque); + + if (tmp->parent->curr_queues > tmp->parent->max_queues) { + error_report("virtio-net: curr_queues %x > max_queues %x", + tmp->parent->curr_queues, tmp->parent->max_queues); + + return -EINVAL; + } + + return 0; /* all good */ +} + +static const VMStateDescription vmstate_virtio_net_tx_waiting =3D { + .name =3D "virtio-net-tx_waiting", + .pre_load =3D virtio_net_tx_waiting_pre_load, + .pre_save =3D virtio_net_tx_waiting_pre_save, + .fields =3D (VMStateField[]) { + VMSTATE_STRUCT_VARRAY_POINTER_UINT16(vqs_1, struct VirtIONetMigTmp, + curr_queues_1, + vmstate_virtio_net_queue_tx_waiting, + struct VirtIONetQueue), + VMSTATE_END_OF_LIST() + }, +}; + +/* the 'has_ufo' flag is just tested; if the incoming stream has the + * flag set we need to check that we have it + */ +static int virtio_net_ufo_post_load(void *opaque, int version_id) +{ + struct VirtIONetMigTmp *tmp =3D opaque; + + if (tmp->has_ufo && !peer_has_ufo(tmp->parent)) { + error_report("virtio-net: saved image requires TUN_F_UFO support"); + return -EINVAL; + } + + return 0; +} + +static void virtio_net_ufo_pre_save(void *opaque) +{ + struct VirtIONetMigTmp *tmp =3D opaque; + + tmp->has_ufo =3D tmp->parent->has_ufo; +} + +static const VMStateDescription vmstate_virtio_net_has_ufo =3D { + .name =3D "virtio-net-ufo", + .post_load =3D virtio_net_ufo_post_load, + .pre_save =3D virtio_net_ufo_pre_save, + .fields =3D (VMStateField[]) { + VMSTATE_UINT8(has_ufo, struct VirtIONetMigTmp), + VMSTATE_END_OF_LIST() + }, +}; + +/* the 'has_vnet_hdr' flag is just tested; if the incoming stream has the + * flag set we need to check that we have it + */ +static int virtio_net_vnet_post_load(void *opaque, int version_id) +{ + struct VirtIONetMigTmp *tmp =3D opaque; + + if (tmp->has_vnet_hdr && !peer_has_vnet_hdr(tmp->parent)) { + error_report("virtio-net: saved image requires vnet_hdr=3Don"); + return -EINVAL; + } + + return 0; +} + +static void virtio_net_vnet_pre_save(void *opaque) +{ + struct VirtIONetMigTmp *tmp =3D opaque; + + tmp->has_vnet_hdr =3D tmp->parent->has_vnet_hdr; +} + +static const VMStateDescription vmstate_virtio_net_has_vnet =3D { + .name =3D "virtio-net-vnet", + .post_load =3D virtio_net_vnet_post_load, + .pre_save =3D virtio_net_vnet_pre_save, + .fields =3D (VMStateField[]) { + VMSTATE_UINT32(has_vnet_hdr, struct VirtIONetMigTmp), + VMSTATE_END_OF_LIST() + }, +}; + +static const VMStateDescription vmstate_virtio_net_device =3D { + .name =3D "virtio-net-device", + .version_id =3D VIRTIO_NET_VM_VERSION, + .minimum_version_id =3D VIRTIO_NET_VM_VERSION, + .post_load =3D virtio_net_post_load_device, + .fields =3D (VMStateField[]) { + VMSTATE_UINT8_ARRAY(mac, VirtIONet, ETH_ALEN), + VMSTATE_STRUCT_POINTER(vqs, VirtIONet, + vmstate_virtio_net_queue_tx_waiting, + VirtIONetQueue), + VMSTATE_UINT32(mergeable_rx_bufs, VirtIONet), + VMSTATE_UINT16(status, VirtIONet), + VMSTATE_UINT8(promisc, VirtIONet), + VMSTATE_UINT8(allmulti, VirtIONet), + VMSTATE_UINT32(mac_table.in_use, VirtIONet), + + /* Guarded pair: If it fits we load it, else we throw it away + * - can happen if source has a larger MAC table.; post-load + * sets flags in this case. + */ + VMSTATE_VBUFFER_MULTIPLY(mac_table.macs, VirtIONet, + 0, mac_table_fits, mac_table.in_use, + ETH_ALEN), + VMSTATE_UNUSED_VARRAY_UINT32(VirtIONet, mac_table_doesnt_fit, 0, + mac_table.in_use, ETH_ALEN), + + /* Note: This is an array of uint32's that's always been saved as a + * buffer; hold onto your endiannesses; it's actually used as a bi= tmap + * but based on the uint. + */ + VMSTATE_BUFFER_POINTER_UNSAFE(vlans, VirtIONet, 0, MAX_VLAN >> 3), + VMSTATE_WITH_TMP(VirtIONet, struct VirtIONetMigTmp, + vmstate_virtio_net_has_vnet), + VMSTATE_UINT8(mac_table.multi_overflow, VirtIONet), + VMSTATE_UINT8(mac_table.uni_overflow, VirtIONet), + VMSTATE_UINT8(alluni, VirtIONet), + VMSTATE_UINT8(nomulti, VirtIONet), + VMSTATE_UINT8(nouni, VirtIONet), + VMSTATE_UINT8(nobcast, VirtIONet), + VMSTATE_WITH_TMP(VirtIONet, struct VirtIONetMigTmp, + vmstate_virtio_net_has_ufo), + VMSTATE_SINGLE_TEST(max_queues, VirtIONet, max_queues_gt_1, 0, + vmstate_info_uint16_equal, uint16_t), + VMSTATE_UINT16_TEST(curr_queues, VirtIONet, max_queues_gt_1), + VMSTATE_WITH_TMP(VirtIONet, struct VirtIONetMigTmp, + vmstate_virtio_net_tx_waiting), + VMSTATE_UINT64_TEST(curr_guest_offloads, VirtIONet, + has_ctrl_guest_offloads), + VMSTATE_END_OF_LIST() + }, +}; + static NetClientInfo net_virtio_info =3D { .type =3D NET_CLIENT_DRIVER_NIC, .size =3D sizeof(NICState), @@ -1989,9 +2096,8 @@ static void virtio_net_class_init(ObjectClass *klass,= void *data) vdc->set_status =3D virtio_net_set_status; vdc->guest_notifier_mask =3D virtio_net_guest_notifier_mask; vdc->guest_notifier_pending =3D virtio_net_guest_notifier_pending; - vdc->load =3D virtio_net_load_device; - vdc->save =3D virtio_net_save_device; vdc->legacy_features |=3D (0x1 << VIRTIO_NET_F_GSO); + vdc->vmsd =3D &vmstate_virtio_net_device; } =20 static const TypeInfo virtio_net_info =3D { diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index 8ea56a8..1eec9a2 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -47,7 +47,7 @@ typedef struct VirtIONetQueue { VirtQueue *tx_vq; QEMUTimer *tx_timer; QEMUBH *tx_bh; - int tx_waiting; + uint32_t tx_waiting; struct { VirtQueueElement *elem; } async_tx; @@ -68,7 +68,7 @@ typedef struct VirtIONet { size_t guest_hdr_len; uint32_t host_features; uint8_t has_ufo; - int mergeable_rx_bufs; + uint32_t mergeable_rx_bufs; uint8_t promisc; uint8_t allmulti; uint8_t alluni; --=20 2.9.3