From nobody Thu Apr 3 11:57:22 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1741270931; cv=none; d=zohomail.com; s=zohoarc; b=fzqcUwShJtV0b4zOQ3DrmJf+oFNGT68GToERakBK7MlM27UOS3wUB0ulbdi8OAXth4kc136U/8BMTIb8Q2FcnOeRh3epyW1GcijH9qtXy2QUYFvrD3gq2sIEDrsDec673fTVZ9QzdYWf5ASo1FrB/g7RG/IbFrgwFCegvLkVCQc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1741270931; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=nx4bd6ERtY3K+2G5g7ASy2iRMEjQ7poAzNL7XntscSA=; b=jfHOpVM7ON+0MNf81zmI5axQAZT6GxWUBvO0vzJjciPJ6Y9PuqB67mM2+7Pkrkmytu0hDOxogK63VYx0h7+lgAFLR7dYxsbEtzLJBT/TIRQL+nV7Brf+pEEY8ADE+IjQIjN8+3rW98GIncfy1/fUTx16bB+VuHqLoDn1yu57STI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1741270931692501.35785734960984; Thu, 6 Mar 2025 06:22:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tqC0y-0007xf-9a; Thu, 06 Mar 2025 09:15:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tqC0d-0007NF-Ll for qemu-devel@nongnu.org; Thu, 06 Mar 2025 09:15:36 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tqC0a-0001on-JQ for qemu-devel@nongnu.org; Thu, 06 Mar 2025 09:15:34 -0500 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-542-3Gt8Rl0cNVirCFxRBrHizg-1; Thu, 06 Mar 2025 09:15:13 -0500 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8EC2F19560BB; Thu, 6 Mar 2025 14:15:12 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.33.141]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 64CB318009BC; Thu, 6 Mar 2025 14:15:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741270531; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nx4bd6ERtY3K+2G5g7ASy2iRMEjQ7poAzNL7XntscSA=; b=ANt60jDmJJi4dLps7AgkYviRx1lTaDcAuLpeSwXgdHJpM325rE1gYjSDuq9BHLaugXCbjS 6FHBl4RP2Wt2zQUsX9K+ex0Srlo5JCv4T6z4CFdGrPhPgZX4un9H/gf6hl3SIh1iMpro8V ImlpXQchFnjUd3fGBVOSpJMSITaMQNc= X-MC-Unique: 3Gt8Rl0cNVirCFxRBrHizg-1 X-Mimecast-MFC-AGG-ID: 3Gt8Rl0cNVirCFxRBrHizg_1741270512 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , "Maciej S. Szmigiero" , Fabiano Rosas , Zhang Chen , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 14/42] migration: Add MIG_CMD_SWITCHOVER_START and its load handler Date: Thu, 6 Mar 2025 15:13:50 +0100 Message-ID: <20250306141419.2015340-15-clg@redhat.com> In-Reply-To: <20250306141419.2015340-1-clg@redhat.com> References: <20250306141419.2015340-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1741270933718019100 From: "Maciej S. Szmigiero" This QEMU_VM_COMMAND sub-command and its switchover_start SaveVMHandler is used to mark the switchover point in main migration stream. It can be used to inform the destination that all pre-switchover main migration stream data has been sent/received so it can start to process post-switchover data that it might have received via other migration channels like the multifd ones. Add also the relevant MigrationState bit stream compatibility property and its hw_compat entry. Reviewed-by: Fabiano Rosas Reviewed-by: Zhang Chen # for the COLO part Signed-off-by: Maciej S. Szmigiero Link: https://lore.kernel.org/qemu-devel/311be6da85fc7e49a7598684d80aa63177= 8dcbce.1741124640.git.maciej.szmigiero@oracle.com Signed-off-by: C=C3=A9dric Le Goater --- include/migration/client-options.h | 4 +++ include/migration/register.h | 12 +++++++++ migration/migration.h | 2 ++ migration/savevm.h | 1 + hw/core/machine.c | 1 + migration/colo.c | 3 +++ migration/migration-hmp-cmds.c | 2 ++ migration/migration.c | 2 ++ migration/options.c | 9 +++++++ migration/savevm.c | 39 ++++++++++++++++++++++++++++++ migration/trace-events | 1 + scripts/analyze-migration.py | 11 +++++++++ 12 files changed, 87 insertions(+) diff --git a/include/migration/client-options.h b/include/migration/client-= options.h index 59f4b55cf4f744f222c161ab0b5b9828b53198be..289c9d776221ce3cf35d86f91ce= 3313fd79427d3 100644 --- a/include/migration/client-options.h +++ b/include/migration/client-options.h @@ -10,6 +10,10 @@ #ifndef QEMU_MIGRATION_CLIENT_OPTIONS_H #define QEMU_MIGRATION_CLIENT_OPTIONS_H =20 + +/* properties */ +bool migrate_send_switchover_start(void); + /* capabilities */ =20 bool migrate_background_snapshot(void); diff --git a/include/migration/register.h b/include/migration/register.h index 0b02927383208d1457f21da7ad4900ba53e93638..ff0faf5f68c8e9ac0fd1144ad91= b3fab731d8a2f 100644 --- a/include/migration/register.h +++ b/include/migration/register.h @@ -279,6 +279,18 @@ typedef struct SaveVMHandlers { * otherwise */ bool (*switchover_ack_needed)(void *opaque); + + /** + * @switchover_start + * + * Notifies that the switchover has started. Called only on + * the destination. + * + * @opaque: data pointer passed to register_savevm_live() + * + * Returns zero to indicate success and negative for error + */ + int (*switchover_start)(void *opaque); } SaveVMHandlers; =20 /** diff --git a/migration/migration.h b/migration/migration.h index 4639e2a7e42f6b25c1fe45ff1a9c13695306480a..7b4278e2a32b2044fad4cf7f7a5= defd4435333ea 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -400,6 +400,8 @@ struct MigrationState { bool send_configuration; /* Whether we send section footer during migration */ bool send_section_footer; + /* Whether we send switchover start notification during migration */ + bool send_switchover_start; =20 /* Needed by postcopy-pause state */ QemuSemaphore postcopy_pause_sem; diff --git a/migration/savevm.h b/migration/savevm.h index 7957460062cad0de7129e5f03b9f8d51ba5dc1f9..58f871a7ed9ce8498a16f76ab66= b08ef665aee73 100644 --- a/migration/savevm.h +++ b/migration/savevm.h @@ -53,6 +53,7 @@ void qemu_savevm_send_postcopy_listen(QEMUFile *f); void qemu_savevm_send_postcopy_run(QEMUFile *f); void qemu_savevm_send_postcopy_resume(QEMUFile *f); void qemu_savevm_send_recv_bitmap(QEMUFile *f, char *block_name); +void qemu_savevm_maybe_send_switchover_start(QEMUFile *f); =20 void qemu_savevm_send_postcopy_ram_discard(QEMUFile *f, const char *name, uint16_t len, diff --git a/hw/core/machine.c b/hw/core/machine.c index b68b8b94a3c43865ec89d9a957289e42d1b26da1..d1ddc3a3db595bd746e8f39b006= a8bf9cd9a52d6 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -44,6 +44,7 @@ GlobalProperty hw_compat_9_2[] =3D { { "virtio-balloon-pci-non-transitional", "vectors", "0" }, { "virtio-mem-pci", "vectors", "0" }, { "migration", "multifd-clean-tls-termination", "false" }, + { "migration", "send-switchover-start", "off"}, }; const size_t hw_compat_9_2_len =3D G_N_ELEMENTS(hw_compat_9_2); =20 diff --git a/migration/colo.c b/migration/colo.c index 9a8e5fbe9b94e9fa56b3c59d3ae4271c1368d7f8..c976b3ff344d7ddf8f850c5a601= b3fe42a503610 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -452,6 +452,9 @@ static int colo_do_checkpoint_transaction(MigrationStat= e *s, bql_unlock(); goto out; } + + qemu_savevm_maybe_send_switchover_start(s->to_dst_file); + /* Note: device state is saved into buffer */ ret =3D qemu_save_device_state(fb); =20 diff --git a/migration/migration-hmp-cmds.c b/migration/migration-hmp-cmds.c index 3347e34c489136106e29baf077bb93fb2f95ef1d..49c26daed359fbc04474be212cf= 7b5c8748043d5 100644 --- a/migration/migration-hmp-cmds.c +++ b/migration/migration-hmp-cmds.c @@ -46,6 +46,8 @@ static void migration_global_dump(Monitor *mon) ms->send_configuration ? "on" : "off"); monitor_printf(mon, "send-section-footer: %s\n", ms->send_section_footer ? "on" : "off"); + monitor_printf(mon, "send-switchover-start: %s\n", + ms->send_switchover_start ? "on" : "off"); monitor_printf(mon, "clear-bitmap-shift: %u\n", ms->clear_bitmap_shift); } diff --git a/migration/migration.c b/migration/migration.c index c597aa707e5718bfd15ba6f175b4efbd870ee96f..9e9db26667f1adbeaae428be9b9= 7750755c1c144 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2891,6 +2891,8 @@ static bool migration_switchover_start(MigrationState= *s, Error **errp) =20 precopy_notify_complete(); =20 + qemu_savevm_maybe_send_switchover_start(s->to_dst_file); + return true; } =20 diff --git a/migration/options.c b/migration/options.c index bb259d192a932d7af1ada20254a020cf3b2178a2..b0ac2ea4083ffbdf20788e0f508= ab9f02a955f99 100644 --- a/migration/options.c +++ b/migration/options.c @@ -93,6 +93,8 @@ const Property migration_properties[] =3D { send_configuration, true), DEFINE_PROP_BOOL("send-section-footer", MigrationState, send_section_footer, true), + DEFINE_PROP_BOOL("send-switchover-start", MigrationState, + send_switchover_start, true), DEFINE_PROP_BOOL("multifd-flush-after-each-section", MigrationState, multifd_flush_after_each_section, false), DEFINE_PROP_UINT8("x-clear-bitmap-shift", MigrationState, @@ -209,6 +211,13 @@ bool migrate_auto_converge(void) return s->capabilities[MIGRATION_CAPABILITY_AUTO_CONVERGE]; } =20 +bool migrate_send_switchover_start(void) +{ + MigrationState *s =3D migrate_get_current(); + + return s->send_switchover_start; +} + bool migrate_background_snapshot(void) { MigrationState *s =3D migrate_get_current(); diff --git a/migration/savevm.c b/migration/savevm.c index 4046faf0091e8ec48c47d4265f325236596a8cc5..faebf47ef51f2c5e6c49df831e1= efe585c1a38a9 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -90,6 +90,7 @@ enum qemu_vm_cmd { MIG_CMD_ENABLE_COLO, /* Enable COLO */ MIG_CMD_POSTCOPY_RESUME, /* resume postcopy on dest */ MIG_CMD_RECV_BITMAP, /* Request for recved bitmap on dst */ + MIG_CMD_SWITCHOVER_START, /* Switchover start notification */ MIG_CMD_MAX }; =20 @@ -109,6 +110,7 @@ static struct mig_cmd_args { [MIG_CMD_POSTCOPY_RESUME] =3D { .len =3D 0, .name =3D "POSTCOPY_RESU= ME" }, [MIG_CMD_PACKAGED] =3D { .len =3D 4, .name =3D "PACKAGED" }, [MIG_CMD_RECV_BITMAP] =3D { .len =3D -1, .name =3D "RECV_BITMAP" = }, + [MIG_CMD_SWITCHOVER_START] =3D { .len =3D 0, .name =3D "SWITCHOVER_ST= ART" }, [MIG_CMD_MAX] =3D { .len =3D -1, .name =3D "MAX" }, }; =20 @@ -1201,6 +1203,19 @@ void qemu_savevm_send_recv_bitmap(QEMUFile *f, char = *block_name) qemu_savevm_command_send(f, MIG_CMD_RECV_BITMAP, len + 1, (uint8_t *)b= uf); } =20 +static void qemu_savevm_send_switchover_start(QEMUFile *f) +{ + trace_savevm_send_switchover_start(); + qemu_savevm_command_send(f, MIG_CMD_SWITCHOVER_START, 0, NULL); +} + +void qemu_savevm_maybe_send_switchover_start(QEMUFile *f) +{ + if (migrate_send_switchover_start()) { + qemu_savevm_send_switchover_start(f); + } +} + bool qemu_savevm_state_blocked(Error **errp) { SaveStateEntry *se; @@ -1687,6 +1702,7 @@ static int qemu_savevm_state(QEMUFile *f, Error **err= p) =20 ret =3D qemu_file_get_error(f); if (ret =3D=3D 0) { + qemu_savevm_maybe_send_switchover_start(f); qemu_savevm_state_complete_precopy(f, false); ret =3D qemu_file_get_error(f); } @@ -2383,6 +2399,26 @@ static int loadvm_process_enable_colo(MigrationIncom= ingState *mis) return ret; } =20 +static int loadvm_postcopy_handle_switchover_start(void) +{ + SaveStateEntry *se; + + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + int ret; + + if (!se->ops || !se->ops->switchover_start) { + continue; + } + + ret =3D se->ops->switchover_start(se->opaque); + if (ret < 0) { + return ret; + } + } + + return 0; +} + /* * Process an incoming 'QEMU_VM_COMMAND' * 0 just a normal return @@ -2481,6 +2517,9 @@ static int loadvm_process_command(QEMUFile *f) =20 case MIG_CMD_ENABLE_COLO: return loadvm_process_enable_colo(mis); + + case MIG_CMD_SWITCHOVER_START: + return loadvm_postcopy_handle_switchover_start(); } =20 return 0; diff --git a/migration/trace-events b/migration/trace-events index 58c0f07f5b2dc3c7550239eab0c410561a21d645..c506e11a2e1d37a4aa22035248b= cce47ac5956b1 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -39,6 +39,7 @@ savevm_send_postcopy_run(void) "" savevm_send_postcopy_resume(void) "" savevm_send_colo_enable(void) "" savevm_send_recv_bitmap(char *name) "%s" +savevm_send_switchover_start(void) "" savevm_state_setup(void) "" savevm_state_resume_prepare(void) "" savevm_state_header(void) "" diff --git a/scripts/analyze-migration.py b/scripts/analyze-migration.py index 8e1fbf4c9d9f13151535f95bfbee4f32ce8d7500..67631ac43e9f4807b16d3ae62b4= eff2d0e340943 100755 --- a/scripts/analyze-migration.py +++ b/scripts/analyze-migration.py @@ -620,7 +620,9 @@ class MigrationDump(object): QEMU_VM_SUBSECTION =3D 0x05 QEMU_VM_VMDESCRIPTION =3D 0x06 QEMU_VM_CONFIGURATION =3D 0x07 + QEMU_VM_COMMAND =3D 0x08 QEMU_VM_SECTION_FOOTER=3D 0x7e + QEMU_MIG_CMD_SWITCHOVER_START =3D 0x0b =20 def __init__(self, filename): self.section_classes =3D { @@ -685,6 +687,15 @@ def read(self, desc_only =3D False, dump_memory =3D Fa= lse, elif section_type =3D=3D self.QEMU_VM_SECTION_PART or section_= type =3D=3D self.QEMU_VM_SECTION_END: section_id =3D file.read32() self.sections[section_id].read() + elif section_type =3D=3D self.QEMU_VM_COMMAND: + command_type =3D file.read16() + command_data_len =3D file.read16() + if command_type !=3D self.QEMU_MIG_CMD_SWITCHOVER_START: + raise Exception("Unknown QEMU_VM_COMMAND: %x" % + (command_type)) + if command_data_len !=3D 0: + raise Exception("Invalid SWITCHOVER_START length: %x" % + (command_data_len)) elif section_type =3D=3D self.QEMU_VM_SECTION_FOOTER: read_section_id =3D file.read32() if read_section_id !=3D section_id: --=20 2.48.1