From nobody Tue Oct 7 05:42:07 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1611241502; cv=none; d=zohomail.com; s=zohoarc; b=c+nzrA4akXyUf5ricQ4pmaHMtVJJ9a5tGuY5MTEOj4yYJcEFAFZrFSK+saojmP2z9Bx6DlQ2oYBFujiXVp6EPBmLj7eyS/Fj+yWUg/dUqq2feU4v3hG4XZClvjSywoXoHgHtphhsorGZxJ+ma7tlbNBthol3DCqm3jQZuVHTn4g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611241502; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=29a+qrzMYDAGWfC8vtg1gZNVvTzVRi7Ihl/vSrn6pmo=; b=b46tuJaz26iIv/RCITfjQQDi4aX+JyaoVe3lCkrlnFuSJNTMdNkKI6zBEd9bfZWKZVUt97yZW16OLVd1em85MHeHrdVrTpFJjVAfZ/vcg/J1AY9mpckj0PYCOS8sl15F8i9uSaveOd/VUdI6k6mKonIPDPyFZ4wPZEXjccm65t8= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1611241502512933.4765024214706; Thu, 21 Jan 2021 07:05:02 -0800 (PST) Received: from localhost ([::1]:36300 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l2bW8-0001g5-UW for importer@patchew.org; Thu, 21 Jan 2021 10:05:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45854) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l2bUL-0008Ur-Hx for qemu-devel@nongnu.org; Thu, 21 Jan 2021 10:03:09 -0500 Received: from relay.sw.ru ([185.231.240.75]:43326) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l2bUD-0003fy-7v for qemu-devel@nongnu.org; Thu, 21 Jan 2021 10:03:09 -0500 Received: from [192.168.15.91] (helo=andrey-MS-7B54.sw.ru) by relay.sw.ru with esmtp (Exim 4.94) (envelope-from ) id 1l2bTx-0004cV-T2; Thu, 21 Jan 2021 18:02:45 +0300 To: qemu-devel@nongnu.org Subject: [PATCH v12 1/5] migration: introduce 'background-snapshot' migration capability Date: Thu, 21 Jan 2021 18:02:30 +0300 Message-Id: <20210121150234.192543-2-andrey.gruzdev@virtuozzo.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210121150234.192543-1-andrey.gruzdev@virtuozzo.com> References: <20210121150234.192543-1-andrey.gruzdev@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=185.231.240.75; envelope-from=andrey.gruzdev@virtuozzo.com; helo=relay.sw.ru X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Juan Quintela , "Dr . David Alan Gilbert" , Peter Xu , Markus Armbruster , Paolo Bonzini , Den Lunev , Andrey Gruzdev Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Reply-to: Andrey Gruzdev From: andrey.gruzdev--- via Content-Type: text/plain; charset="utf-8" Add new capability to 'qapi/migration.json' schema. Update migrate_caps_check() to validate enabled capability set against introduced one. Perform checks for required kernel features and compatibility with guest memory backends. Signed-off-by: Andrey Gruzdev Reviewed-by: Peter Xu Acked-by: Markus Armbruster --- migration/migration.c | 110 ++++++++++++++++++++++++++++++++++++++++++ migration/migration.h | 1 + migration/ram.c | 21 ++++++++ migration/ram.h | 4 ++ qapi/migration.json | 7 ++- 5 files changed, 142 insertions(+), 1 deletion(-) diff --git a/migration/migration.c b/migration/migration.c index d5136419bf..f018337fbc 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -58,6 +58,7 @@ #include "qemu/queue.h" #include "multifd.h" #include "qemu/yank.h" +#include "sysemu/cpus.h" =20 #ifdef CONFIG_VFIO #include "hw/vfio/vfio-common.h" @@ -134,6 +135,38 @@ enum mig_rp_message_type { MIG_RP_MSG_MAX }; =20 +/* Migration capabilities set */ +struct MigrateCapsSet { + int size; /* Capability set size */ + MigrationCapability caps[]; /* Variadic array of capabilities */ +}; +typedef struct MigrateCapsSet MigrateCapsSet; + +/* Define and initialize MigrateCapsSet */ +#define INITIALIZE_MIGRATE_CAPS_SET(_name, ...) \ + MigrateCapsSet _name =3D { \ + .size =3D sizeof((int []) { __VA_ARGS__ }) / sizeof(int), \ + .caps =3D { __VA_ARGS__ } \ + } + +/* Background-snapshot compatibility check list */ +static const +INITIALIZE_MIGRATE_CAPS_SET(check_caps_background_snapshot, + MIGRATION_CAPABILITY_POSTCOPY_RAM, + MIGRATION_CAPABILITY_DIRTY_BITMAPS, + MIGRATION_CAPABILITY_POSTCOPY_BLOCKTIME, + MIGRATION_CAPABILITY_LATE_BLOCK_ACTIVATE, + MIGRATION_CAPABILITY_RETURN_PATH, + MIGRATION_CAPABILITY_MULTIFD, + MIGRATION_CAPABILITY_PAUSE_BEFORE_SWITCHOVER, + MIGRATION_CAPABILITY_AUTO_CONVERGE, + MIGRATION_CAPABILITY_RELEASE_RAM, + MIGRATION_CAPABILITY_RDMA_PIN_ALL, + MIGRATION_CAPABILITY_COMPRESS, + MIGRATION_CAPABILITY_XBZRLE, + MIGRATION_CAPABILITY_X_COLO, + MIGRATION_CAPABILITY_VALIDATE_UUID); + /* When we add fault tolerance, we could have several migrations at once. For now we don't need to add dynamic creation of migration */ @@ -1097,6 +1130,33 @@ static void fill_source_migration_info(MigrationInfo= *info) info->status =3D s->state; } =20 +#ifdef CONFIG_LINUX +typedef enum WriteTrackingSupport { + WT_SUPPORT_UNKNOWN =3D 0, + WT_SUPPORT_ABSENT, + WT_SUPPORT_AVAILABLE, + WT_SUPPORT_COMPATIBLE +} WriteTrackingSupport; + +static +WriteTrackingSupport migrate_query_write_tracking(void) +{ + /* Check if kernel supports required UFFD features */ + if (!ram_write_tracking_available()) { + return WT_SUPPORT_ABSENT; + } + /* + * Check if current memory configuration is + * compatible with required UFFD features. + */ + if (!ram_write_tracking_compatible()) { + return WT_SUPPORT_AVAILABLE; + } + + return WT_SUPPORT_COMPATIBLE; +} +#endif /* CONFIG_LINUX */ + /** * @migration_caps_check - check capability validity * @@ -1158,6 +1218,45 @@ static bool migrate_caps_check(bool *cap_list, } } =20 + if (cap_list[MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT]) { +#ifdef CONFIG_LINUX + WriteTrackingSupport wt_support; + int idx; + /* + * Check if 'background-snapshot' capability is supported by + * host kernel and compatible with guest memory configuration. + */ + wt_support =3D migrate_query_write_tracking(); + if (wt_support < WT_SUPPORT_AVAILABLE) { + error_setg(errp, "Background-snapshot is not supported by host= kernel"); + return false; + } + if (wt_support < WT_SUPPORT_COMPATIBLE) { + error_setg(errp, "Background-snapshot is not compatible " + "with guest memory configuration"); + return false; + } + + /* + * Check if there are any migration capabilities + * incompatible with 'background-snapshot'. + */ + for (idx =3D 0; idx < check_caps_background_snapshot.size; idx++) { + int incomp_cap =3D check_caps_background_snapshot.caps[idx]; + if (cap_list[incomp_cap]) { + error_setg(errp, + "Background-snapshot is not compatible with %s", + MigrationCapability_str(incomp_cap)); + return false; + } + } +#else + error_setg(errp, + "Background-snapshot is not supported on non-Linux hosts"); + return false; +#endif + } + return true; } =20 @@ -2499,6 +2598,15 @@ bool migrate_use_block_incremental(void) return s->parameters.block_incremental; } =20 +bool migrate_background_snapshot(void) +{ + MigrationState *s; + + s =3D migrate_get_current(); + + return s->enabled_capabilities[MIGRATION_CAPABILITY_BACKGROUND_SNAPSHO= T]; +} + /* migration thread support */ /* * Something bad happened to the RP stream, mark an error @@ -3792,6 +3900,8 @@ static Property migration_properties[] =3D { DEFINE_PROP_MIG_CAP("x-block", MIGRATION_CAPABILITY_BLOCK), DEFINE_PROP_MIG_CAP("x-return-path", MIGRATION_CAPABILITY_RETURN_PATH), DEFINE_PROP_MIG_CAP("x-multifd", MIGRATION_CAPABILITY_MULTIFD), + DEFINE_PROP_MIG_CAP("x-background-snapshot", + MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT), =20 DEFINE_PROP_END_OF_LIST(), }; diff --git a/migration/migration.h b/migration/migration.h index d096b77f74..f40338cfbf 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -341,6 +341,7 @@ int migrate_compress_wait_thread(void); int migrate_decompress_threads(void); bool migrate_use_events(void); bool migrate_postcopy_blocktime(void); +bool migrate_background_snapshot(void); =20 /* Sending on the return path - generic and then for each message type */ void migrate_send_rp_shut(MigrationIncomingState *mis, diff --git a/migration/ram.c b/migration/ram.c index 7811cde643..ae8de17153 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3788,6 +3788,27 @@ static int ram_resume_prepare(MigrationState *s, voi= d *opaque) return 0; } =20 +/* ram_write_tracking_available: check if kernel supports required UFFD fe= atures + * + * Returns true if supports, false otherwise + */ +bool ram_write_tracking_available(void) +{ + /* TODO: implement */ + return false; +} + +/* ram_write_tracking_compatible: check if guest configuration is + * compatible with 'write-tracking' + * + * Returns true if compatible, false otherwise + */ +bool ram_write_tracking_compatible(void) +{ + /* TODO: implement */ + return false; +} + static SaveVMHandlers savevm_ram_handlers =3D { .save_setup =3D ram_save_setup, .save_live_iterate =3D ram_save_iterate, diff --git a/migration/ram.h b/migration/ram.h index 011e85414e..1a9ff90304 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -79,4 +79,8 @@ void colo_flush_ram_cache(void); void colo_release_ram_cache(void); void colo_incoming_start_dirty_log(void); =20 +/* Background snapshot */ +bool ram_write_tracking_available(void); +bool ram_write_tracking_compatible(void); + #endif diff --git a/qapi/migration.json b/qapi/migration.json index d1d9632c2a..6c12b368aa 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -442,6 +442,11 @@ # @validate-uuid: Send the UUID of the source to allow the destination # to ensure it is the same. (since 4.2) # +# @background-snapshot: If enabled, the migration stream will be a snapshot +# of the VM exactly at the point when the migration +# procedure starts. The VM RAM is saved with running= VM. +# (since 6.0) +# # Since: 1.2 ## { 'enum': 'MigrationCapability', @@ -449,7 +454,7 @@ 'compress', 'events', 'postcopy-ram', 'x-colo', 'release-ram', 'block', 'return-path', 'pause-before-switchover', 'multifd', 'dirty-bitmaps', 'postcopy-blocktime', 'late-block-activate', - 'x-ignore-shared', 'validate-uuid' ] } + 'x-ignore-shared', 'validate-uuid', 'background-snapshot'] } =20 ## # @MigrationCapabilityStatus: --=20 2.25.1