From nobody Thu Apr 3 10:02:39 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1742306988; cv=none; d=zohomail.com; s=zohoarc; b=mXSjXxn3WJF0wJP2h9v2DfvensB7u6KPEUiN7b3o/O0qoRIrgoBhlKoRY2l7A8ZXCcQJVq34mE9fAsc5EEeJh3L9S+JtchtQcdULo7dqz/i+Y0aRmWWPQdGfd5ncGMiAAz7XE/RH3qvu0IyoPYyKMtfvZnurOWZXYF5sfAzbR74= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1742306988; h=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=lbfxP3jjC8UrxJyTZ+GaVBR0Y8K+IXepORN0PpIWmOo=; b=BukgzdvGTUIuuwx7RbWmSELEjSZ5E/Sxs5QpHBRochJ9/03O2L0KKrTrKPcEGYC5QGcIdTzoCXWHIC71IlpMqc9hRYTVF/f8y6q2XSHy5Sm74te+8vkCaY6sjzC9avUtPTnNtSTu+5ixvn/3rptFto1gGqVXRg5nl7GPwt0PSXE= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1742306988198734.129811926249; Tue, 18 Mar 2025 07:09:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tuWER-0002ha-TW; Tue, 18 Mar 2025 08:39:43 -0400 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 1tuWDx-0002Pg-JQ for qemu-devel@nongnu.org; Tue, 18 Mar 2025 08:39:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tuWDu-0007Eg-6v for qemu-devel@nongnu.org; Tue, 18 Mar 2025 08:39:12 -0400 Received: from mx-prod-mc-05.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-441-YkgTfX2iNBCIDj5vucJW1g-1; Tue, 18 Mar 2025 08:39:05 -0400 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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DCFC919560AF; Tue, 18 Mar 2025 12:39:03 +0000 (UTC) Received: from kaapi.redhat.com (unknown [10.74.16.234]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 40F001801764; Tue, 18 Mar 2025 12:38:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1742301549; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lbfxP3jjC8UrxJyTZ+GaVBR0Y8K+IXepORN0PpIWmOo=; b=acv93UHf4cV+oQqvghrZ/70aDLP4YGega6z1eSbQy4iQiLXeEbEfz4a9Ihg44HtTJKJBWn xZ8o2YKS0sIJN35+SCP5p8TKyGOkaANy6U8Lnp4nnwi94lCyIn9VD9UCOYtIMwBLq/OMMu YCKzxRynfncTiUbkxNvWDteGFKoxDFU= X-MC-Unique: YkgTfX2iNBCIDj5vucJW1g-1 X-Mimecast-MFC-AGG-ID: YkgTfX2iNBCIDj5vucJW1g_1742301544 From: Prasad Pandit To: qemu-devel@nongnu.org Cc: peterx@redhat.com, farosas@suse.de, berrange@redhat.com, Prasad Pandit Subject: [PATCH v8 1/7] migration/multifd: move macros to multifd header Date: Tue, 18 Mar 2025 18:08:40 +0530 Message-ID: <20250318123846.1370312-2-ppandit@redhat.com> In-Reply-To: <20250318123846.1370312-1-ppandit@redhat.com> References: <20250318123846.1370312-1-ppandit@redhat.com> MIME-Version: 1.0 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.129.124; envelope-from=ppandit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.332, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1742306990849019100 Content-Type: text/plain; charset="utf-8" From: Prasad Pandit Move MULTIFD_ macros to the header file so that they are accessible from other source files. Reviewed-by: Fabiano Rosas Signed-off-by: Prasad Pandit --- migration/multifd.c | 5 ----- migration/multifd.h | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) v7: no change - https://lore.kernel.org/qemu-devel/20250228121749.553184-1-ppandit@redhat= .com/T/#t diff --git a/migration/multifd.c b/migration/multifd.c index dfb5189f0e..6139cabe44 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -36,11 +36,6 @@ #include "io/channel-socket.h" #include "yank_functions.h" =20 -/* Multiple fd's */ - -#define MULTIFD_MAGIC 0x11223344U -#define MULTIFD_VERSION 1 - typedef struct { uint32_t magic; uint32_t version; diff --git a/migration/multifd.h b/migration/multifd.h index 2d337e7b3b..9b6d81e7ed 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -49,6 +49,11 @@ bool multifd_queue_page(RAMBlock *block, ram_addr_t offs= et); bool multifd_recv(void); MultiFDRecvData *multifd_get_recv_data(void); =20 +/* Multiple fd's */ + +#define MULTIFD_MAGIC 0x11223344U +#define MULTIFD_VERSION 1 + /* Multifd Compression flags */ #define MULTIFD_FLAG_SYNC (1 << 0) =20 --=20 2.48.1 From nobody Thu Apr 3 10:02:39 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1742304935; cv=none; d=zohomail.com; s=zohoarc; b=maM66Td4OBWolgp7U08MO+IdyOcrHmZUzNhd1NMP8wfJE9unvshPcuG6OZnHzw0D0BkaaKrc6hbeUYNNO+BnWEhdojX1B3R1ne+nrKYak+J9ZbaEWIUvumlvS7/9IN0AtxYrauxihojpG4c/SJ/bM6Y4/fyYvQErhNITgGHEBKU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1742304935; h=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=sMSs1AHIZSRqdKg/kg4Cc10x0NxpoPBnKMn3+G8D0aw=; b=eDbacsN4V+D+J68Fv47ZgOC8SNHfWASWR68MPeqy1+beAHIKd5T3FEkzXXkyzk+SjSguXePf3Ghl5TaAEYIHRdtHZm4RJtKh+nq2095N3Ne6x/fxuJoGS0VyCCKvLgbW3PhswIPBKBwBWZpTLDasj3mho/koR2WhrgRA8BuSv3o= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1742304935101486.3292894455052; Tue, 18 Mar 2025 06:35:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tuWEX-00038T-Kk; Tue, 18 Mar 2025 08:39:49 -0400 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 1tuWE1-0002QR-Cd for qemu-devel@nongnu.org; Tue, 18 Mar 2025 08:39:22 -0400 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 1tuWDx-0007Kr-CD for qemu-devel@nongnu.org; Tue, 18 Mar 2025 08:39:16 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-182-pWcMo-mINCCNnCBXS9fXWQ-1; Tue, 18 Mar 2025 08:39:09 -0400 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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C5FDD180034D; Tue, 18 Mar 2025 12:39:08 +0000 (UTC) Received: from kaapi.redhat.com (unknown [10.74.16.234]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E0BC3180094A; Tue, 18 Mar 2025 12:39:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1742301552; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sMSs1AHIZSRqdKg/kg4Cc10x0NxpoPBnKMn3+G8D0aw=; b=e4cSL3WQ1AOyVrO5fefDheooT5fmj10d/uMp+bNXhUln49e1lWHHjJhPq1gbKA3fe8iIef YSKq3nY2QmjQUfyGT1WgT4b2jaKafMQqtuk/w3nt0hb2VMuDmarjPUhNhHdc3pA94peJ6b pHBhvQZSTvtvcF3wjzQ126eAQ0eQ5EE= X-MC-Unique: pWcMo-mINCCNnCBXS9fXWQ-1 X-Mimecast-MFC-AGG-ID: pWcMo-mINCCNnCBXS9fXWQ_1742301548 From: Prasad Pandit To: qemu-devel@nongnu.org Cc: peterx@redhat.com, farosas@suse.de, berrange@redhat.com, Prasad Pandit Subject: [PATCH v8 2/7] migration: Refactor channel discovery mechanism Date: Tue, 18 Mar 2025 18:08:41 +0530 Message-ID: <20250318123846.1370312-3-ppandit@redhat.com> In-Reply-To: <20250318123846.1370312-1-ppandit@redhat.com> References: <20250318123846.1370312-1-ppandit@redhat.com> MIME-Version: 1.0 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=ppandit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.332, 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1742304935865019000 Content-Type: text/plain; charset="utf-8" From: Prasad Pandit The various logical migration channels don't have a standardized way of advertising themselves and their connections may be seen out of order by the migration destination. When a new connection arrives, the incoming migration currently make use of heuristics to determine which channel it belongs to. The next few patches will need to change how the multifd and postcopy capabilities interact and that affects the channel discovery heuristic. Refactor the channel discovery heuristic to make it less opaque and simplify the subsequent patches. Signed-off-by: Prasad Pandit --- migration/migration.c | 124 +++++++++++++++++++++++------------------- 1 file changed, 69 insertions(+), 55 deletions(-) v8: - Separate this patch out from earlier patch-2 v7: - https://lore.kernel.org/qemu-devel/20250228121749.553184-1-ppandit@redhat= .com/T/#t diff --git a/migration/migration.c b/migration/migration.c index d46e776e24..f97bb2777f 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -95,6 +95,9 @@ enum mig_rp_message_type { MIG_RP_MSG_MAX }; =20 +/* Migration channel types */ +enum { CH_MAIN, CH_MULTIFD, CH_POSTCOPY }; + /* When we add fault tolerance, we could have several migrations at once. For now we don't need to add dynamic creation of migration */ @@ -985,28 +988,19 @@ void migration_fd_process_incoming(QEMUFile *f) migration_incoming_process(); } =20 -/* - * Returns true when we want to start a new incoming migration process, - * false otherwise. - */ -static bool migration_should_start_incoming(bool main_channel) +static bool migration_has_main_and_multifd_channels(void) { - /* Multifd doesn't start unless all channels are established */ - if (migrate_multifd()) { - return migration_has_all_channels(); + MigrationIncomingState *mis =3D migration_incoming_get_current(); + if (!mis->from_src_file) { + /* main channel not established */ + return false; } =20 - /* Preempt channel only starts when the main channel is created */ - if (migrate_postcopy_preempt()) { - return main_channel; + if (migrate_multifd() && !multifd_recv_all_channels_created()) { + return false; } =20 - /* - * For all the rest types of migration, we should only reach here when - * it's the main channel that's being created, and we should always - * proceed with this channel. - */ - assert(main_channel); + /* main and all multifd channels are established */ return true; } =20 @@ -1015,59 +1009,84 @@ void migration_ioc_process_incoming(QIOChannel *ioc= , Error **errp) MigrationIncomingState *mis =3D migration_incoming_get_current(); Error *local_err =3D NULL; QEMUFile *f; - bool default_channel =3D true; + uint8_t channel; uint32_t channel_magic =3D 0; int ret =3D 0; =20 - if (migrate_multifd() && !migrate_mapped_ram() && - !migrate_postcopy_ram() && - qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_READ_MSG_PEEK)) { - /* - * With multiple channels, it is possible that we receive channels - * out of order on destination side, causing incorrect mapping of - * source channels on destination side. Check channel MAGIC to - * decide type of channel. Please note this is best effort, postco= py - * preempt channel does not send any magic number so avoid it for - * postcopy live migration. Also tls live migration already does - * tls handshake while initializing main channel so with tls this - * issue is not possible. - */ - ret =3D migration_channel_read_peek(ioc, (void *)&channel_magic, - sizeof(channel_magic), errp); + if (!migration_has_main_and_multifd_channels()) { + if (qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_READ_MSG_PEEK= )) { + /* + * With multiple channels, it is possible that we receive chan= nels + * out of order on destination side, causing incorrect mapping= of + * source channels on destination side. Check channel MAGIC to + * decide type of channel. Please note this is best effort, + * postcopy preempt channel does not send any magic number so + * avoid it for postcopy live migration. Also tls live migrati= on + * already does tls handshake while initializing main channel = so + * with tls this issue is not possible. + */ + ret =3D migration_channel_read_peek(ioc, (void *)&channel_magi= c, + sizeof(channel_magic), errp); + if (ret !=3D 0) { + return; + } =20 - if (ret !=3D 0) { + channel_magic =3D be32_to_cpu(channel_magic); + if (channel_magic =3D=3D QEMU_VM_FILE_MAGIC) { + channel =3D CH_MAIN; + } else if (channel_magic =3D=3D MULTIFD_MAGIC) { + channel =3D CH_MULTIFD; + } else if (!mis->from_src_file && + mis->state =3D=3D MIGRATION_STATUS_POSTCOPY_PAUSED= ) { + /* reconnect main channel for postcopy recovery */ + channel =3D CH_MAIN; + } else { + error_setg(errp, "unknown channel magic: %u", channel_magi= c); + return; + } + } else if (mis->from_src_file && migrate_multifd()) { + /* + * Non-peekable channels like tls/file are processed as + * multifd channels when multifd is enabled. + */ + channel =3D CH_MULTIFD; + } else if (!mis->from_src_file) { + channel =3D CH_MAIN; + } else { + error_setg(errp, "non-peekable channel used without multifd"); return; } - - default_channel =3D (channel_magic =3D=3D cpu_to_be32(QEMU_VM_FILE= _MAGIC)); + } else if (mis->from_src_file) { + channel =3D CH_POSTCOPY; } else { - default_channel =3D !mis->from_src_file; + channel =3D CH_MAIN; } =20 if (multifd_recv_setup(errp) !=3D 0) { return; } =20 - if (default_channel) { + if (channel =3D=3D CH_MAIN) { f =3D qemu_file_new_input(ioc); migration_incoming_setup(f); - } else { + } else if (channel =3D=3D CH_MULTIFD) { /* Multiple connections */ - assert(migration_needs_multiple_sockets()); if (migrate_multifd()) { multifd_recv_new_channel(ioc, &local_err); - } else { - assert(migrate_postcopy_preempt()); - f =3D qemu_file_new_input(ioc); - postcopy_preempt_new_channel(mis, f); } if (local_err) { error_propagate(errp, local_err); return; } + } else if (channel =3D=3D CH_POSTCOPY) { + assert(migrate_postcopy_preempt()); + assert(!mis->postcopy_qemufile_dst); + f =3D qemu_file_new_input(ioc); + postcopy_preempt_new_channel(mis, f); + return; } =20 - if (migration_should_start_incoming(default_channel)) { + if (migration_has_main_and_multifd_channels()) { /* If it's a recovery, we're done */ if (postcopy_try_recover()) { return; @@ -1084,20 +1103,15 @@ void migration_ioc_process_incoming(QIOChannel *ioc= , Error **errp) */ bool migration_has_all_channels(void) { + if (!migration_has_main_and_multifd_channels()) { + return false; + } + MigrationIncomingState *mis =3D migration_incoming_get_current(); - - if (!mis->from_src_file) { + if (migrate_postcopy_preempt() && !mis->postcopy_qemufile_dst) { return false; } =20 - if (migrate_multifd()) { - return multifd_recv_all_channels_created(); - } - - if (migrate_postcopy_preempt()) { - return mis->postcopy_qemufile_dst !=3D NULL; - } - return true; } =20 --=20 2.48.1 From nobody Thu Apr 3 10:02:39 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1742302668; cv=none; d=zohomail.com; s=zohoarc; b=Ve2Ck+rNF8ErblPeQrFyr9o5IXXCCqoSQzV8FE7EAisEGLaqmC2Oyw5kg7nvS7P5wX9FXDD7lWEcTzeiuPlmRMP0kbz1UMfOUkOq5c/jK5eOcNFYg2hqaG9hYPG6MGyKl+Ks455B36M+oqpsPWmVjPH+yLmHsqfm7ZtTcNBU0CI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1742302668; h=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=ErArQjU6eRsmzNZuSCyF39RPNl6ZM8cjudxvqH6TEE4=; b=kF4cF9jRAVh6Vxuh1jjQfxAipXAriBDjRPGPa8mFH7WBPxoMTk2wXKdtYYGlGa+zoOZgkhpWNL41rQFt8IpORaQOYdSgPjUBs8Cw3ePm6wNuLd2WCPTsvnEfMEz9E33TeBNDx5NV+Bs0Bg41f/xTUKtPu5eds+zneEGOWoqhoyg= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1742302668710465.45382084722655; Tue, 18 Mar 2025 05:57:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tuWEV-0002xb-3s; Tue, 18 Mar 2025 08:39:47 -0400 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 1tuWEB-0002Vo-Ie for qemu-devel@nongnu.org; Tue, 18 Mar 2025 08:39:32 -0400 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 1tuWE3-0007RS-Vg for qemu-devel@nongnu.org; Tue, 18 Mar 2025 08:39:26 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-250-0TZhBk8UPM28C2zlyioUbg-1; Tue, 18 Mar 2025 08:39:14 -0400 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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6DC7918009B1; Tue, 18 Mar 2025 12:39:13 +0000 (UTC) Received: from kaapi.redhat.com (unknown [10.74.16.234]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C6E9E1800946; Tue, 18 Mar 2025 12:39:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1742301558; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ErArQjU6eRsmzNZuSCyF39RPNl6ZM8cjudxvqH6TEE4=; b=R0seA4QG/aw29pQwwVvYVzeYQmQMDRL6zRQgd3W4ycmWkm08rKiJjtyRGM0DKd+w/gfvs/ N/dRVEKknUZJ6Wh4aCZN+OevkDA+JuixLXsSkXpjTaw8Sfi7CpaoB78Ouz5zLVFfyM698d 1M8Vf6giMhKp6hIw8bmspSRM0FCWM6E= X-MC-Unique: 0TZhBk8UPM28C2zlyioUbg-1 X-Mimecast-MFC-AGG-ID: 0TZhBk8UPM28C2zlyioUbg_1742301553 From: Prasad Pandit To: qemu-devel@nongnu.org Cc: peterx@redhat.com, farosas@suse.de, berrange@redhat.com, Prasad Pandit Subject: [PATCH v8 3/7] migration: enable multifd and postcopy together Date: Tue, 18 Mar 2025 18:08:42 +0530 Message-ID: <20250318123846.1370312-4-ppandit@redhat.com> In-Reply-To: <20250318123846.1370312-1-ppandit@redhat.com> References: <20250318123846.1370312-1-ppandit@redhat.com> MIME-Version: 1.0 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=ppandit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.332, 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1742302672313019100 Content-Type: text/plain; charset="utf-8" From: Prasad Pandit Enable Multifd and Postcopy migration together. The migration_ioc_process_incoming() routine checks magic value sent on each channel and helps to properly setup multifd and postcopy channels. The Precopy and Multifd threads work during the initial guest RAM transfer. When migration moves to the Postcopy phase, the multifd threads cease to send data on multifd channels and Postcopy threads on the destination request/pull data from the source side. Signed-off-by: Prasad Pandit --- migration/multifd-nocomp.c | 3 ++- migration/multifd.c | 7 +++++++ migration/options.c | 5 ----- migration/ram.c | 7 +++---- 4 files changed, 12 insertions(+), 10 deletions(-) v8: - Separate this patch out from earlier patch-2. v7: - https://lore.kernel.org/qemu-devel/20250228121749.553184-1-ppandit@redhat= .com/T/#t diff --git a/migration/multifd-nocomp.c b/migration/multifd-nocomp.c index ffe75256c9..02f8bf8ce8 100644 --- a/migration/multifd-nocomp.c +++ b/migration/multifd-nocomp.c @@ -17,6 +17,7 @@ #include "migration-stats.h" #include "multifd.h" #include "options.h" +#include "migration.h" #include "qapi/error.h" #include "qemu/cutils.h" #include "qemu/error-report.h" @@ -399,7 +400,7 @@ int multifd_ram_flush_and_sync(QEMUFile *f) MultiFDSyncReq req; int ret; =20 - if (!migrate_multifd()) { + if (!migrate_multifd() || migration_in_postcopy()) { return 0; } =20 diff --git a/migration/multifd.c b/migration/multifd.c index 6139cabe44..074d16d07d 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -1379,6 +1379,13 @@ static void *multifd_recv_thread(void *opaque) } =20 if (has_data) { + /* + * multifd thread should not be active and receive data + * when migration is in the Postcopy phase. Two threads + * writing the same memory area could easily corrupt + * the guest state. + */ + assert(!migration_in_postcopy()); if (is_device_state) { assert(use_packets); ret =3D multifd_device_state_recv(p, &local_err); diff --git a/migration/options.c b/migration/options.c index b0ac2ea408..48aa6076de 100644 --- a/migration/options.c +++ b/migration/options.c @@ -491,11 +491,6 @@ bool migrate_caps_check(bool *old_caps, bool *new_caps= , Error **errp) error_setg(errp, "Postcopy is not compatible with ignore-share= d"); return false; } - - if (new_caps[MIGRATION_CAPABILITY_MULTIFD]) { - error_setg(errp, "Postcopy is not yet compatible with multifd"= ); - return false; - } } =20 if (new_caps[MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT]) { diff --git a/migration/ram.c b/migration/ram.c index 424df6d9f1..6fd88cbf2a 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1297,7 +1297,7 @@ static int find_dirty_block(RAMState *rs, PageSearchS= tatus *pss) pss->page =3D 0; pss->block =3D QLIST_NEXT_RCU(pss->block, next); if (!pss->block) { - if (multifd_ram_sync_per_round()) { + if (multifd_ram_sync_per_round() && !migration_in_postcopy()) { QEMUFile *f =3D rs->pss[RAM_CHANNEL_PRECOPY].pss_channel; int ret =3D multifd_ram_flush_and_sync(f); if (ret < 0) { @@ -1976,9 +1976,8 @@ static int ram_save_target_page(RAMState *rs, PageSea= rchStatus *pss) } } =20 - if (migrate_multifd()) { - RAMBlock *block =3D pss->block; - return ram_save_multifd_page(block, offset); + if (migrate_multifd() && !migration_in_postcopy()) { + return ram_save_multifd_page(pss->block, offset); } =20 return ram_save_page(rs, pss); --=20 2.48.1 From nobody Thu Apr 3 10:02:39 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1742306998; cv=none; d=zohomail.com; s=zohoarc; b=ALbk4PcTt9FXqKGeSOXvoarl/iNfGX6tXNv2UV6Ckmyj5hxUcGaorPcyvba7kWh1fHjosj0SyTwHb45RV9wYoFznppIGeM7m/BD1RdZ9gxEOCUAZ56FliQGYXKa4SHRBfm3Csq+Ho4XN26dSYwfWi0wuoorqviF15qP0Tu0nZoM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1742306998; h=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=IoCKmLMli6EcsfATHqtRzIu6Ct1rloZ10Coavs76lNg=; b=Jew4GHn+z+LhrNemw4/4u43LtlvpV2cbKh/aZjkbq/PcIn0uHBg6pLVbob03YYkKPNACqxpPUqRSAPNN2YAbOs8MIzwkQ5mIt3drvEuZCap/CtqqV5HXhrYblpjCpc9h880yTGm9gV0OFDfvuPejVmy98FRiVjGzP5lkwL1/81k= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1742306998551329.42783611187815; Tue, 18 Mar 2025 07:09:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tuWET-0002ru-LX; Tue, 18 Mar 2025 08:39:45 -0400 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 1tuWEC-0002W0-Qc for qemu-devel@nongnu.org; Tue, 18 Mar 2025 08:39:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tuWE9-0007aK-KZ for qemu-devel@nongnu.org; Tue, 18 Mar 2025 08:39:28 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-297-YtTTLXNIPm-5nfWIHjHsCg-1; Tue, 18 Mar 2025 08:39:19 -0400 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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 52A9D1801A1A; Tue, 18 Mar 2025 12:39:18 +0000 (UTC) Received: from kaapi.redhat.com (unknown [10.74.16.234]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 670C51800946; Tue, 18 Mar 2025 12:39:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1742301563; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IoCKmLMli6EcsfATHqtRzIu6Ct1rloZ10Coavs76lNg=; b=ZVp8F3Z5qcK39lulJuYMwbyFuICD40zyXcc18cs/NJyBD+A+7HZBpS9Ji6xgjRjZSc+KTP BNscs0WGQAROre/1pnaDlLmyTHDo33Eo/7fls99AQHaSmTjDCW+By+s0CY11HulmAsJMMj h4O3Bbh+aR8FyvNxSTvXOl898uNbI8Y= X-MC-Unique: YtTTLXNIPm-5nfWIHjHsCg-1 X-Mimecast-MFC-AGG-ID: YtTTLXNIPm-5nfWIHjHsCg_1742301558 From: Prasad Pandit To: qemu-devel@nongnu.org Cc: peterx@redhat.com, farosas@suse.de, berrange@redhat.com, Prasad Pandit Subject: [PATCH v8 4/7] tests/qtest/migration: consolidate set capabilities Date: Tue, 18 Mar 2025 18:08:43 +0530 Message-ID: <20250318123846.1370312-5-ppandit@redhat.com> In-Reply-To: <20250318123846.1370312-1-ppandit@redhat.com> References: <20250318123846.1370312-1-ppandit@redhat.com> MIME-Version: 1.0 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.129.124; envelope-from=ppandit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.332, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1742307001068019100 Content-Type: text/plain; charset="utf-8" From: Prasad Pandit Migration capabilities are set in multiple '.start_hook' functions for various tests. Instead, consolidate setting capabilities in 'migrate_start_set_capabilities()' function which is called from the 'migrate_start()' function. While simplifying the capabilities setting, it helps to declutter the qtest sources. Suggested-by: Fabiano Rosas Signed-off-by: Prasad Pandit --- tests/qtest/migration/compression-tests.c | 22 +++++-- tests/qtest/migration/cpr-tests.c | 6 +- tests/qtest/migration/file-tests.c | 58 ++++++++--------- tests/qtest/migration/framework.c | 76 ++++++++++++++++------- tests/qtest/migration/framework.h | 9 ++- tests/qtest/migration/misc-tests.c | 4 +- tests/qtest/migration/postcopy-tests.c | 8 ++- tests/qtest/migration/precopy-tests.c | 29 +++++---- tests/qtest/migration/tls-tests.c | 23 ++++++- 9 files changed, 151 insertions(+), 84 deletions(-) v7: no change - https://lore.kernel.org/qemu-devel/20250228121749.553184-1-ppandit@redhat= .com/T/#t diff --git a/tests/qtest/migration/compression-tests.c b/tests/qtest/migrat= ion/compression-tests.c index 8b58401b84..41e79f031b 100644 --- a/tests/qtest/migration/compression-tests.c +++ b/tests/qtest/migration/compression-tests.c @@ -35,6 +35,9 @@ static void test_multifd_tcp_zstd(void) { MigrateCommon args =3D { .listen_uri =3D "defer", + .start =3D { + .caps[MIGRATION_CAPABILITY_MULTIFD] =3D true, + }, .start_hook =3D migrate_hook_start_precopy_tcp_multifd_zstd, }; test_precopy_common(&args); @@ -56,6 +59,9 @@ static void test_multifd_tcp_qatzip(void) { MigrateCommon args =3D { .listen_uri =3D "defer", + .start =3D { + .caps[MIGRATION_CAPABILITY_MULTIFD] =3D true, + }, .start_hook =3D migrate_hook_start_precopy_tcp_multifd_qatzip, }; test_precopy_common(&args); @@ -74,6 +80,9 @@ static void test_multifd_tcp_qpl(void) { MigrateCommon args =3D { .listen_uri =3D "defer", + .start =3D { + .caps[MIGRATION_CAPABILITY_MULTIFD] =3D true, + }, .start_hook =3D migrate_hook_start_precopy_tcp_multifd_qpl, }; test_precopy_common(&args); @@ -92,6 +101,9 @@ static void test_multifd_tcp_uadk(void) { MigrateCommon args =3D { .listen_uri =3D "defer", + .start =3D { + .caps[MIGRATION_CAPABILITY_MULTIFD] =3D true, + }, .start_hook =3D migrate_hook_start_precopy_tcp_multifd_uadk, }; test_precopy_common(&args); @@ -103,10 +115,6 @@ migrate_hook_start_xbzrle(QTestState *from, QTestState *to) { migrate_set_parameter_int(from, "xbzrle-cache-size", 33554432); - - migrate_set_capability(from, "xbzrle", true); - migrate_set_capability(to, "xbzrle", true); - return NULL; } =20 @@ -118,6 +126,9 @@ static void test_precopy_unix_xbzrle(void) .listen_uri =3D uri, .start_hook =3D migrate_hook_start_xbzrle, .iterations =3D 2, + .start =3D { + .caps[MIGRATION_CAPABILITY_XBZRLE] =3D true, + }, /* * XBZRLE needs pages to be modified when doing the 2nd+ round * iteration to have real data pushed to the stream. @@ -146,6 +157,9 @@ static void test_multifd_tcp_zlib(void) { MigrateCommon args =3D { .listen_uri =3D "defer", + .start =3D { + .caps[MIGRATION_CAPABILITY_MULTIFD] =3D true, + }, .start_hook =3D migrate_hook_start_precopy_tcp_multifd_zlib, }; test_precopy_common(&args); diff --git a/tests/qtest/migration/cpr-tests.c b/tests/qtest/migration/cpr-= tests.c index 4758841824..5536e14610 100644 --- a/tests/qtest/migration/cpr-tests.c +++ b/tests/qtest/migration/cpr-tests.c @@ -24,9 +24,6 @@ static void *migrate_hook_start_mode_reboot(QTestState *f= rom, QTestState *to) migrate_set_parameter_str(from, "mode", "cpr-reboot"); migrate_set_parameter_str(to, "mode", "cpr-reboot"); =20 - migrate_set_capability(from, "x-ignore-shared", true); - migrate_set_capability(to, "x-ignore-shared", true); - return NULL; } =20 @@ -39,6 +36,9 @@ static void test_mode_reboot(void) .connect_uri =3D uri, .listen_uri =3D "defer", .start_hook =3D migrate_hook_start_mode_reboot, + .start =3D { + .caps[MIGRATION_CAPABILITY_X_IGNORE_SHARED] =3D true, + }, }; =20 test_file_common(&args, true); diff --git a/tests/qtest/migration/file-tests.c b/tests/qtest/migration/fil= e-tests.c index f260e2871d..4d78ce0855 100644 --- a/tests/qtest/migration/file-tests.c +++ b/tests/qtest/migration/file-tests.c @@ -107,15 +107,6 @@ static void test_precopy_file_offset_bad(void) test_file_common(&args, false); } =20 -static void *migrate_hook_start_mapped_ram(QTestState *from, - QTestState *to) -{ - migrate_set_capability(from, "mapped-ram", true); - migrate_set_capability(to, "mapped-ram", true); - - return NULL; -} - static void test_precopy_file_mapped_ram_live(void) { g_autofree char *uri =3D g_strdup_printf("file:%s/%s", tmpfs, @@ -123,7 +114,9 @@ static void test_precopy_file_mapped_ram_live(void) MigrateCommon args =3D { .connect_uri =3D uri, .listen_uri =3D "defer", - .start_hook =3D migrate_hook_start_mapped_ram, + .start =3D { + .caps[MIGRATION_CAPABILITY_MAPPED_RAM] =3D true, + }, }; =20 test_file_common(&args, false); @@ -136,26 +129,14 @@ static void test_precopy_file_mapped_ram(void) MigrateCommon args =3D { .connect_uri =3D uri, .listen_uri =3D "defer", - .start_hook =3D migrate_hook_start_mapped_ram, + .start =3D { + .caps[MIGRATION_CAPABILITY_MAPPED_RAM] =3D true, + }, }; =20 test_file_common(&args, true); } =20 -static void *migrate_hook_start_multifd_mapped_ram(QTestState *from, - QTestState *to) -{ - migrate_hook_start_mapped_ram(from, to); - - migrate_set_parameter_int(from, "multifd-channels", 4); - migrate_set_parameter_int(to, "multifd-channels", 4); - - migrate_set_capability(from, "multifd", true); - migrate_set_capability(to, "multifd", true); - - return NULL; -} - static void test_multifd_file_mapped_ram_live(void) { g_autofree char *uri =3D g_strdup_printf("file:%s/%s", tmpfs, @@ -163,7 +144,10 @@ static void test_multifd_file_mapped_ram_live(void) MigrateCommon args =3D { .connect_uri =3D uri, .listen_uri =3D "defer", - .start_hook =3D migrate_hook_start_multifd_mapped_ram, + .start =3D { + .caps[MIGRATION_CAPABILITY_MULTIFD] =3D true, + .caps[MIGRATION_CAPABILITY_MAPPED_RAM] =3D true, + }, }; =20 test_file_common(&args, false); @@ -176,7 +160,10 @@ static void test_multifd_file_mapped_ram(void) MigrateCommon args =3D { .connect_uri =3D uri, .listen_uri =3D "defer", - .start_hook =3D migrate_hook_start_multifd_mapped_ram, + .start =3D { + .caps[MIGRATION_CAPABILITY_MULTIFD] =3D true, + .caps[MIGRATION_CAPABILITY_MAPPED_RAM] =3D true, + }, }; =20 test_file_common(&args, true); @@ -185,8 +172,6 @@ static void test_multifd_file_mapped_ram(void) static void *migrate_hook_start_multifd_mapped_ram_dio(QTestState *from, QTestState *to) { - migrate_hook_start_multifd_mapped_ram(from, to); - migrate_set_parameter_bool(from, "direct-io", true); migrate_set_parameter_bool(to, "direct-io", true); =20 @@ -201,6 +186,10 @@ static void test_multifd_file_mapped_ram_dio(void) .connect_uri =3D uri, .listen_uri =3D "defer", .start_hook =3D migrate_hook_start_multifd_mapped_ram_dio, + .start =3D { + .caps[MIGRATION_CAPABILITY_MAPPED_RAM] =3D true, + .caps[MIGRATION_CAPABILITY_MULTIFD] =3D true, + }, }; =20 if (!probe_o_direct_support(tmpfs)) { @@ -246,7 +235,6 @@ static void *migrate_hook_start_multifd_mapped_ram_fdse= t_dio(QTestState *from, fdset_add_fds(from, file, O_WRONLY, 2, true); fdset_add_fds(to, file, O_RDONLY, 2, true); =20 - migrate_hook_start_multifd_mapped_ram(from, to); migrate_set_parameter_bool(from, "direct-io", true); migrate_set_parameter_bool(to, "direct-io", true); =20 @@ -261,8 +249,6 @@ static void *migrate_hook_start_multifd_mapped_ram_fdse= t(QTestState *from, fdset_add_fds(from, file, O_WRONLY, 2, false); fdset_add_fds(to, file, O_RDONLY, 2, false); =20 - migrate_hook_start_multifd_mapped_ram(from, to); - return NULL; } =20 @@ -275,6 +261,10 @@ static void test_multifd_file_mapped_ram_fdset(void) .listen_uri =3D "defer", .start_hook =3D migrate_hook_start_multifd_mapped_ram_fdset, .end_hook =3D migrate_hook_end_multifd_mapped_ram_fdset, + .start =3D { + .caps[MIGRATION_CAPABILITY_MAPPED_RAM] =3D true, + .caps[MIGRATION_CAPABILITY_MULTIFD] =3D true, + }, }; =20 test_file_common(&args, true); @@ -289,6 +279,10 @@ static void test_multifd_file_mapped_ram_fdset_dio(voi= d) .listen_uri =3D "defer", .start_hook =3D migrate_hook_start_multifd_mapped_ram_fdset_dio, .end_hook =3D migrate_hook_end_multifd_mapped_ram_fdset, + .start =3D { + .caps[MIGRATION_CAPABILITY_MAPPED_RAM] =3D true, + .caps[MIGRATION_CAPABILITY_MULTIFD] =3D true, + }, }; =20 if (!probe_o_direct_support(tmpfs)) { diff --git a/tests/qtest/migration/framework.c b/tests/qtest/migration/fram= ework.c index 10e1d04b58..be6c245843 100644 --- a/tests/qtest/migration/framework.c +++ b/tests/qtest/migration/framework.c @@ -30,6 +30,7 @@ #define QEMU_VM_FILE_MAGIC 0x5145564d #define QEMU_ENV_SRC "QTEST_QEMU_BINARY_SRC" #define QEMU_ENV_DST "QTEST_QEMU_BINARY_DST" +#define MULTIFD_TEST_CHANNELS 4 =20 unsigned start_address; unsigned end_address; @@ -207,6 +208,52 @@ static QList *migrate_start_get_qmp_capabilities(const= MigrateStart *args) return capabilities; } =20 +static void migrate_start_set_capabilities(QTestState *from, QTestState *t= o, + MigrateStart *args) +{ + /* + * MigrationCapability_lookup and MIGRATION_CAPABILITY_ constants + * are from qapi-types-migration.h. + */ + for (uint8_t i =3D 0; i < MIGRATION_CAPABILITY__MAX; i++) + { + if (!args->caps[i]) { + continue; + } + if (from) { + migrate_set_capability(from, + MigrationCapability_lookup.array[i], true); + } + if (to) { + migrate_set_capability(to, + MigrationCapability_lookup.array[i], true); + } + } + + /* + * Always enable migration events. Libvirt always uses it, let's try + * to mimic as closer as that. + */ + migrate_set_capability(from, "events", true); + if (!args->defer_target_connect) { + migrate_set_capability(to, "events", true); + } + + /* + * Default number of channels should be fine for most + * tests. Individual tests can override by calling + * migrate_set_parameter() directly. + */ + if (args->caps[MIGRATION_CAPABILITY_MULTIFD]) { + migrate_set_parameter_int(from, "multifd-channels", + MULTIFD_TEST_CHANNELS); + migrate_set_parameter_int(to, "multifd-channels", + MULTIFD_TEST_CHANNELS); + } + + return; +} + int migrate_start(QTestState **from, QTestState **to, const char *uri, MigrateStart *args) { @@ -379,14 +426,7 @@ int migrate_start(QTestState **from, QTestState **to, = const char *uri, unlink(shmem_path); } =20 - /* - * Always enable migration events. Libvirt always uses it, let's try - * to mimic as closer as that. - */ - migrate_set_capability(*from, "events", true); - if (!args->defer_target_connect) { - migrate_set_capability(*to, "events", true); - } + migrate_start_set_capabilities(*from, *to, args); =20 return 0; } @@ -432,6 +472,10 @@ static int migrate_postcopy_prepare(QTestState **from_= ptr, { QTestState *from, *to; =20 + /* set postcopy capabilities */ + args->start.caps[MIGRATION_CAPABILITY_POSTCOPY_BLOCKTIME] =3D true; + args->start.caps[MIGRATION_CAPABILITY_POSTCOPY_RAM] =3D true; + if (migrate_start(&from, &to, "defer", &args->start)) { return -1; } @@ -440,17 +484,7 @@ static int migrate_postcopy_prepare(QTestState **from_= ptr, args->postcopy_data =3D args->start_hook(from, to); } =20 - migrate_set_capability(from, "postcopy-ram", true); - migrate_set_capability(to, "postcopy-ram", true); - migrate_set_capability(to, "postcopy-blocktime", true); - - if (args->postcopy_preempt) { - migrate_set_capability(from, "postcopy-preempt", true); - migrate_set_capability(to, "postcopy-preempt", true); - } - migrate_ensure_non_converge(from); - migrate_prepare_for_dirty_mem(from); qtest_qmp_assert_success(to, "{ 'execute': 'migrate-incoming'," " 'arguments': { " @@ -948,15 +982,9 @@ void *migrate_hook_start_precopy_tcp_multifd_common(QT= estState *from, QTestState *to, const char *method) { - migrate_set_parameter_int(from, "multifd-channels", 16); - migrate_set_parameter_int(to, "multifd-channels", 16); - migrate_set_parameter_str(from, "multifd-compression", method); migrate_set_parameter_str(to, "multifd-compression", method); =20 - migrate_set_capability(from, "multifd", true); - migrate_set_capability(to, "multifd", true); - /* Start incoming migration from the 1st socket */ migrate_incoming_qmp(to, "tcp:127.0.0.1:0", NULL, "{}"); =20 diff --git a/tests/qtest/migration/framework.h b/tests/qtest/migration/fram= ework.h index e4a11870f6..01e425e64e 100644 --- a/tests/qtest/migration/framework.h +++ b/tests/qtest/migration/framework.h @@ -12,6 +12,7 @@ #define TEST_FRAMEWORK_H =20 #include "libqtest.h" +#include =20 #define FILE_TEST_FILENAME "migfile" #define FILE_TEST_OFFSET 0x1000 @@ -120,6 +121,13 @@ typedef struct { =20 /* Do not connect to target monitor and qtest sockets in qtest_init */ bool defer_target_connect; + + /* + * Migration capabilities to be set in both source and + * destination. For unilateral capabilities, use + * migration_set_capabilities(). + */ + bool caps[MIGRATION_CAPABILITY__MAX]; } MigrateStart; =20 typedef enum PostcopyRecoveryFailStage { @@ -207,7 +215,6 @@ typedef struct { =20 /* Postcopy specific fields */ void *postcopy_data; - bool postcopy_preempt; PostcopyRecoveryFailStage postcopy_recovery_fail_stage; } MigrateCommon; =20 diff --git a/tests/qtest/migration/misc-tests.c b/tests/qtest/migration/mis= c-tests.c index 2e612d9e38..54995256d8 100644 --- a/tests/qtest/migration/misc-tests.c +++ b/tests/qtest/migration/misc-tests.c @@ -98,6 +98,7 @@ static void test_ignore_shared(void) QTestState *from, *to; MigrateStart args =3D { .use_shmem =3D true, + .caps[MIGRATION_CAPABILITY_X_IGNORE_SHARED] =3D true, }; =20 if (migrate_start(&from, &to, uri, &args)) { @@ -107,9 +108,6 @@ static void test_ignore_shared(void) migrate_ensure_non_converge(from); migrate_prepare_for_dirty_mem(from); =20 - migrate_set_capability(from, "x-ignore-shared", true); - migrate_set_capability(to, "x-ignore-shared", true); - /* Wait for the first serial output from the source */ wait_for_serial("src_serial"); =20 diff --git a/tests/qtest/migration/postcopy-tests.c b/tests/qtest/migration= /postcopy-tests.c index 982457bed1..483e3ff99f 100644 --- a/tests/qtest/migration/postcopy-tests.c +++ b/tests/qtest/migration/postcopy-tests.c @@ -39,7 +39,9 @@ static void test_postcopy_suspend(void) static void test_postcopy_preempt(void) { MigrateCommon args =3D { - .postcopy_preempt =3D true, + .start =3D { + .caps[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT] =3D true, + }, }; =20 test_postcopy_common(&args); @@ -73,7 +75,9 @@ static void test_postcopy_recovery_fail_reconnect(void) static void test_postcopy_preempt_recovery(void) { MigrateCommon args =3D { - .postcopy_preempt =3D true, + .start =3D { + .caps[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT] =3D true, + }, }; =20 test_postcopy_recovery_common(&args); diff --git a/tests/qtest/migration/precopy-tests.c b/tests/qtest/migration/= precopy-tests.c index ba273d10b9..f8404793b8 100644 --- a/tests/qtest/migration/precopy-tests.c +++ b/tests/qtest/migration/precopy-tests.c @@ -108,23 +108,14 @@ static void test_precopy_tcp_plain(void) test_precopy_common(&args); } =20 -static void *migrate_hook_start_switchover_ack(QTestState *from, QTestStat= e *to) -{ - - migrate_set_capability(from, "return-path", true); - migrate_set_capability(to, "return-path", true); - - migrate_set_capability(from, "switchover-ack", true); - migrate_set_capability(to, "switchover-ack", true); - - return NULL; -} - static void test_precopy_tcp_switchover_ack(void) { MigrateCommon args =3D { .listen_uri =3D "tcp:127.0.0.1:0", - .start_hook =3D migrate_hook_start_switchover_ack, + .start =3D { + .caps[MIGRATION_CAPABILITY_RETURN_PATH] =3D true, + .caps[MIGRATION_CAPABILITY_SWITCHOVER_ACK] =3D true, + }, /* * Source VM must be running in order to consider the switchover A= CK * when deciding to do switchover or not. @@ -393,6 +384,9 @@ static void test_multifd_tcp_uri_none(void) MigrateCommon args =3D { .listen_uri =3D "defer", .start_hook =3D migrate_hook_start_precopy_tcp_multifd, + .start =3D { + .caps[MIGRATION_CAPABILITY_MULTIFD] =3D true, + }, /* * Multifd is more complicated than most of the features, it * directly takes guest page buffers when sending, make sure @@ -408,6 +402,9 @@ static void test_multifd_tcp_zero_page_legacy(void) MigrateCommon args =3D { .listen_uri =3D "defer", .start_hook =3D migrate_hook_start_precopy_tcp_multifd_zero_page_l= egacy, + .start =3D { + .caps[MIGRATION_CAPABILITY_MULTIFD] =3D true, + }, /* * Multifd is more complicated than most of the features, it * directly takes guest page buffers when sending, make sure @@ -423,6 +420,9 @@ static void test_multifd_tcp_no_zero_page(void) MigrateCommon args =3D { .listen_uri =3D "defer", .start_hook =3D migrate_hook_start_precopy_tcp_multifd_no_zero_pag= e, + .start =3D { + .caps[MIGRATION_CAPABILITY_MULTIFD] =3D true, + }, /* * Multifd is more complicated than most of the features, it * directly takes guest page buffers when sending, make sure @@ -439,6 +439,9 @@ static void test_multifd_tcp_channels_none(void) .listen_uri =3D "defer", .start_hook =3D migrate_hook_start_precopy_tcp_multifd, .live =3D true, + .start =3D { + .caps[MIGRATION_CAPABILITY_MULTIFD] =3D true, + }, .connect_channels =3D ("[ { 'channel-type': 'main'," " 'addr': { 'transport': 'socket'," " 'type': 'inet'," diff --git a/tests/qtest/migration/tls-tests.c b/tests/qtest/migration/tls-= tests.c index 2cb4a44bcd..72f44defbb 100644 --- a/tests/qtest/migration/tls-tests.c +++ b/tests/qtest/migration/tls-tests.c @@ -375,9 +375,11 @@ static void test_postcopy_tls_psk(void) static void test_postcopy_preempt_tls_psk(void) { MigrateCommon args =3D { - .postcopy_preempt =3D true, .start_hook =3D migrate_hook_start_tls_psk_match, .end_hook =3D migrate_hook_end_tls_psk, + .start =3D { + .caps[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT] =3D true, + }, }; =20 test_postcopy_common(&args); @@ -397,9 +399,11 @@ static void test_postcopy_recovery_tls_psk(void) static void test_postcopy_preempt_all(void) { MigrateCommon args =3D { - .postcopy_preempt =3D true, .start_hook =3D migrate_hook_start_tls_psk_match, .end_hook =3D migrate_hook_end_tls_psk, + .start =3D { + .caps[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT] =3D true, + }, }; =20 test_postcopy_recovery_common(&args); @@ -631,6 +635,9 @@ static void test_multifd_tcp_tls_psk_match(void) .listen_uri =3D "defer", .start_hook =3D migrate_hook_start_multifd_tcp_tls_psk_match, .end_hook =3D migrate_hook_end_tls_psk, + .start =3D { + .caps[MIGRATION_CAPABILITY_MULTIFD] =3D true, + }, }; test_precopy_common(&args); } @@ -640,6 +647,7 @@ static void test_multifd_tcp_tls_psk_mismatch(void) MigrateCommon args =3D { .start =3D { .hide_stderr =3D true, + .caps[MIGRATION_CAPABILITY_MULTIFD] =3D true, }, .listen_uri =3D "defer", .start_hook =3D migrate_hook_start_multifd_tcp_tls_psk_mismatch, @@ -656,6 +664,9 @@ static void test_multifd_tcp_tls_x509_default_host(void) .listen_uri =3D "defer", .start_hook =3D migrate_hook_start_multifd_tls_x509_default_host, .end_hook =3D migrate_hook_end_tls_x509, + .start =3D { + .caps[MIGRATION_CAPABILITY_MULTIFD] =3D true, + }, }; test_precopy_common(&args); } @@ -666,6 +677,9 @@ static void test_multifd_tcp_tls_x509_override_host(voi= d) .listen_uri =3D "defer", .start_hook =3D migrate_hook_start_multifd_tls_x509_override_host, .end_hook =3D migrate_hook_end_tls_x509, + .start =3D { + .caps[MIGRATION_CAPABILITY_MULTIFD] =3D true, + }, }; test_precopy_common(&args); } @@ -688,6 +702,7 @@ static void test_multifd_tcp_tls_x509_mismatch_host(voi= d) MigrateCommon args =3D { .start =3D { .hide_stderr =3D true, + .caps[MIGRATION_CAPABILITY_MULTIFD] =3D true, }, .listen_uri =3D "defer", .start_hook =3D migrate_hook_start_multifd_tls_x509_mismatch_host, @@ -703,6 +718,9 @@ static void test_multifd_tcp_tls_x509_allow_anon_client= (void) .listen_uri =3D "defer", .start_hook =3D migrate_hook_start_multifd_tls_x509_allow_anon_cli= ent, .end_hook =3D migrate_hook_end_tls_x509, + .start =3D { + .caps[MIGRATION_CAPABILITY_MULTIFD] =3D true, + }, }; test_precopy_common(&args); } @@ -712,6 +730,7 @@ static void test_multifd_tcp_tls_x509_reject_anon_clien= t(void) MigrateCommon args =3D { .start =3D { .hide_stderr =3D true, + .caps[MIGRATION_CAPABILITY_MULTIFD] =3D true, }, .listen_uri =3D "defer", .start_hook =3D migrate_hook_start_multifd_tls_x509_reject_anon_cl= ient, --=20 2.48.1 From nobody Thu Apr 3 10:02:40 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1742302603; cv=none; d=zohomail.com; s=zohoarc; b=l2b11LZqhcImcaOHEc3AVvcWX2ICrsXWRUlahytD8wpVpDSHcp09pje/L/jpleBSflbus52gTscuFHx1QgbuCE1v+4kqlqKhkAfGF6MsmuRcCJvd5ZdqCFux/umvIC12E1er5Oo3vc81LasDNjKJiOrew+oKSHpbEY8jHaOqa04= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1742302603; h=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=nDd40a80ltKRkFwfz3XZyIIt27+rRcG5t9F/EmCszvg=; b=IAY6XmDhUwLrdS7QLRmBGaAgyhjmd12Xi4DCR3TU+ilkZlU33chXwNfbQgB9pbTgDz7PlB3AOGAv207BbgWcontIGG5tNnM2ZYIn4zr/s+XWMNvDqAAbzxylTQ/VuoTy++0cVs9YTi/zO+ZloFQ2mbMmJUUn1IxygQELCAjRMxc= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1742302603487712.4852022011984; Tue, 18 Mar 2025 05:56:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tuWEW-00031r-Co; Tue, 18 Mar 2025 08:39:48 -0400 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 1tuWEL-0002ep-IP for qemu-devel@nongnu.org; Tue, 18 Mar 2025 08:39:39 -0400 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 1tuWEH-0007c6-QU for qemu-devel@nongnu.org; Tue, 18 Mar 2025 08:39:36 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-150-Izy-KG_DM7qGKmiqWynbew-1; Tue, 18 Mar 2025 08:39:24 -0400 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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9D18A180AF59; Tue, 18 Mar 2025 12:39:22 +0000 (UTC) Received: from kaapi.redhat.com (unknown [10.74.16.234]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3A8BA180094A; Tue, 18 Mar 2025 12:39:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1742301570; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nDd40a80ltKRkFwfz3XZyIIt27+rRcG5t9F/EmCszvg=; b=Upto2wB0nEc4aDzBC6yhZtQzUvblAiTog5lpUCG2Fa+s5PjodnSvNi4rLGVlbYidrftr94 UQA00zAodSl06p09vAu+QR7upnxwtNgHphpDVx44J4CQNaF11wxxyH13NjlHegX+bJzU4m fsu4FSBHVgx36gdjHewIFGKDtCySOgw= X-MC-Unique: Izy-KG_DM7qGKmiqWynbew-1 X-Mimecast-MFC-AGG-ID: Izy-KG_DM7qGKmiqWynbew_1742301562 From: Prasad Pandit To: qemu-devel@nongnu.org Cc: peterx@redhat.com, farosas@suse.de, berrange@redhat.com, Prasad Pandit Subject: [PATCH v8 5/7] tests/qtest/migration: add postcopy tests with multifd Date: Tue, 18 Mar 2025 18:08:44 +0530 Message-ID: <20250318123846.1370312-6-ppandit@redhat.com> In-Reply-To: <20250318123846.1370312-1-ppandit@redhat.com> References: <20250318123846.1370312-1-ppandit@redhat.com> MIME-Version: 1.0 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=ppandit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.332, 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1742302605490019000 Content-Type: text/plain; charset="utf-8" From: Prasad Pandit Add new qtests to run postcopy migration with multifd channels enabled. Signed-off-by: Prasad Pandit --- tests/qtest/migration/compression-tests.c | 16 ++++++++ tests/qtest/migration/postcopy-tests.c | 27 +++++++++++++ tests/qtest/migration/precopy-tests.c | 19 +++++++++ tests/qtest/migration/tls-tests.c | 47 +++++++++++++++++++++++ 4 files changed, 109 insertions(+) v8: - Set missing 'postcopy-ram' and 'multifd' capabilities for couple tests. v7: - https://lore.kernel.org/qemu-devel/20250228121749.553184-1-ppandit@redhat= .com/T/#t diff --git a/tests/qtest/migration/compression-tests.c b/tests/qtest/migrat= ion/compression-tests.c index 41e79f031b..a788a8d4a7 100644 --- a/tests/qtest/migration/compression-tests.c +++ b/tests/qtest/migration/compression-tests.c @@ -42,6 +42,20 @@ static void test_multifd_tcp_zstd(void) }; test_precopy_common(&args); } + +static void test_multifd_postcopy_tcp_zstd(void) +{ + MigrateCommon args =3D { + .listen_uri =3D "defer", + .start =3D { + .caps[MIGRATION_CAPABILITY_MULTIFD] =3D true, + .caps[MIGRATION_CAPABILITY_POSTCOPY_RAM] =3D true, + }, + .start_hook =3D migrate_hook_start_precopy_tcp_multifd_zstd, + }; + + test_precopy_common(&args); +} #endif /* CONFIG_ZSTD */ =20 #ifdef CONFIG_QATZIP @@ -184,6 +198,8 @@ void migration_test_add_compression(MigrationTestEnv *e= nv) #ifdef CONFIG_ZSTD migration_test_add("/migration/multifd/tcp/plain/zstd", test_multifd_tcp_zstd); + migration_test_add("/migration/multifd+postcopy/tcp/plain/zstd", + test_multifd_postcopy_tcp_zstd); #endif =20 #ifdef CONFIG_QATZIP diff --git a/tests/qtest/migration/postcopy-tests.c b/tests/qtest/migration= /postcopy-tests.c index 483e3ff99f..eb637f94f7 100644 --- a/tests/qtest/migration/postcopy-tests.c +++ b/tests/qtest/migration/postcopy-tests.c @@ -94,6 +94,29 @@ static void migration_test_add_postcopy_smoke(MigrationT= estEnv *env) } } =20 +static void test_multifd_postcopy(void) +{ + MigrateCommon args =3D { + .start =3D { + .caps[MIGRATION_CAPABILITY_MULTIFD] =3D true, + }, + }; + + test_postcopy_common(&args); +} + +static void test_multifd_postcopy_preempt(void) +{ + MigrateCommon args =3D { + .start =3D { + .caps[MIGRATION_CAPABILITY_MULTIFD] =3D true, + .caps[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT] =3D true, + }, + }; + + test_postcopy_common(&args); +} + void migration_test_add_postcopy(MigrationTestEnv *env) { migration_test_add_postcopy_smoke(env); @@ -114,6 +137,10 @@ void migration_test_add_postcopy(MigrationTestEnv *env) "/migration/postcopy/recovery/double-failures/reconnect", test_postcopy_recovery_fail_reconnect); =20 + migration_test_add("/migration/postcopy/multifd/plain", + test_multifd_postcopy); + migration_test_add("/migration/postcopy/multifd/preempt/plain", + test_multifd_postcopy_preempt); if (env->is_x86) { migration_test_add("/migration/postcopy/suspend", test_postcopy_suspend); diff --git a/tests/qtest/migration/precopy-tests.c b/tests/qtest/migration/= precopy-tests.c index f8404793b8..b2b0db8076 100644 --- a/tests/qtest/migration/precopy-tests.c +++ b/tests/qtest/migration/precopy-tests.c @@ -34,6 +34,7 @@ #define DIRTYLIMIT_TOLERANCE_RANGE 25 /* MB/s */ =20 static char *tmpfs; +static bool postcopy_ram =3D false; =20 static void test_precopy_unix_plain(void) { @@ -476,6 +477,11 @@ static void test_multifd_tcp_cancel(void) migrate_ensure_non_converge(from); migrate_prepare_for_dirty_mem(from); =20 + if (postcopy_ram) { + migrate_set_capability(from, "postcopy-ram", true); + migrate_set_capability(to, "postcopy-ram", true); + } + migrate_set_parameter_int(from, "multifd-channels", 16); migrate_set_parameter_int(to, "multifd-channels", 16); =20 @@ -517,6 +523,10 @@ static void test_multifd_tcp_cancel(void) return; } =20 + if (postcopy_ram) { + migrate_set_capability(to2, "postcopy-ram", true); + } + migrate_set_parameter_int(to2, "multifd-channels", 16); =20 migrate_set_capability(to2, "multifd", true); @@ -540,6 +550,13 @@ static void test_multifd_tcp_cancel(void) migrate_end(from, to2, true); } =20 +static void test_multifd_postcopy_tcp_cancel(void) +{ + postcopy_ram =3D true; + test_multifd_tcp_cancel(); + postcopy_ram =3D false; +} + static void test_cancel_src_after_failed(QTestState *from, QTestState *to, const char *uri, const char *phas= e) { @@ -1127,6 +1144,8 @@ static void migration_test_add_precopy_smoke(Migratio= nTestEnv *env) test_multifd_tcp_uri_none); migration_test_add("/migration/multifd/tcp/plain/cancel", test_multifd_tcp_cancel); + migration_test_add("/migration/multifd+postcopy/tcp/plain/cancel", + test_multifd_postcopy_tcp_cancel); } =20 void migration_test_add_precopy(MigrationTestEnv *env) diff --git a/tests/qtest/migration/tls-tests.c b/tests/qtest/migration/tls-= tests.c index 72f44defbb..54581e182f 100644 --- a/tests/qtest/migration/tls-tests.c +++ b/tests/qtest/migration/tls-tests.c @@ -395,6 +395,19 @@ static void test_postcopy_recovery_tls_psk(void) test_postcopy_recovery_common(&args); } =20 +static void test_multifd_postcopy_recovery_tls_psk(void) +{ + MigrateCommon args =3D { + .start_hook =3D migrate_hook_start_tls_psk_match, + .end_hook =3D migrate_hook_end_tls_psk, + .start =3D { + .caps[MIGRATION_CAPABILITY_MULTIFD] =3D true, + }, + }; + + test_postcopy_recovery_common(&args); +} + /* This contains preempt+recovery+tls test altogether */ static void test_postcopy_preempt_all(void) { @@ -409,6 +422,19 @@ static void test_postcopy_preempt_all(void) test_postcopy_recovery_common(&args); } =20 +static void test_multifd_postcopy_preempt_recovery_tls_psk(void) +{ + MigrateCommon args =3D { + .start_hook =3D migrate_hook_start_tls_psk_match, + .end_hook =3D migrate_hook_end_tls_psk, + .start =3D { + .caps[MIGRATION_CAPABILITY_MULTIFD] =3D true, + }, + }; + + test_postcopy_recovery_common(&args); +} + static void test_precopy_unix_tls_psk(void) { g_autofree char *uri =3D g_strdup_printf("unix:%s/migsocket", tmpfs); @@ -657,6 +683,21 @@ static void test_multifd_tcp_tls_psk_mismatch(void) test_precopy_common(&args); } =20 +static void test_multifd_postcopy_tcp_tls_psk_match(void) +{ + MigrateCommon args =3D { + .start =3D { + .caps[MIGRATION_CAPABILITY_MULTIFD] =3D true, + .caps[MIGRATION_CAPABILITY_POSTCOPY_RAM] =3D true, + }, + .listen_uri =3D "defer", + .start_hook =3D migrate_hook_start_multifd_tcp_tls_psk_match, + .end_hook =3D migrate_hook_end_tls_psk, + }; + + test_precopy_common(&args); +} + #ifdef CONFIG_TASN1 static void test_multifd_tcp_tls_x509_default_host(void) { @@ -774,6 +815,10 @@ void migration_test_add_tls(MigrationTestEnv *env) test_postcopy_preempt_tls_psk); migration_test_add("/migration/postcopy/preempt/recovery/tls/psk", test_postcopy_preempt_all); + migration_test_add("/migration/postcopy/multifd/recovery/tls/psk", + test_multifd_postcopy_recovery_tls_psk); + migration_test_add("/migration/postcopy/multifd/preempt/recovery/t= ls/psk", + test_multifd_postcopy_preempt_recovery_tls_psk); } #ifdef CONFIG_TASN1 migration_test_add("/migration/precopy/unix/tls/x509/default-host", @@ -805,6 +850,8 @@ void migration_test_add_tls(MigrationTestEnv *env) test_multifd_tcp_tls_psk_match); migration_test_add("/migration/multifd/tcp/tls/psk/mismatch", test_multifd_tcp_tls_psk_mismatch); + migration_test_add("/migration/multifd+postcopy/tcp/tls/psk/match", + test_multifd_postcopy_tcp_tls_psk_match); #ifdef CONFIG_TASN1 migration_test_add("/migration/multifd/tcp/tls/x509/default-host", test_multifd_tcp_tls_x509_default_host); --=20 2.48.1 From nobody Thu Apr 3 10:02:40 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1742311665; cv=none; d=zohomail.com; s=zohoarc; b=g1AM2gT+/IM8bK/nlr5G2N+RY50gi6cJZ7ad2xD4jhSqcnoPmS2O1k/Z42OU6CM2UUvLXoBs07GTt/Elxql+XKQiGoFwGihLgYGO3DG2qMfvnyCdez7uyfXKH9KXT2xZYODKivQN7jMCxa9N51y08KhDHp0BChZHVdxrvgs2zIA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1742311665; h=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=kPof6sTt4ptR9GIy4E4urQ6PAt+v+dGETnww+PA+Q7c=; b=IfNO6BAyavM4ScdTDRRNYbyy0wZ6WdB1mr2tGhmPHra51vW2RPhwrQ9PyQYtddkSY9ggFDY9bGP45qyLWO7jW1JN19fg3Ye8Xuzu1Q8FNsH1OvB4GcmiYdedD2ZtP+gEr0etmmtg6Nx8J8GSrB0VCq+9OAtYOO9p4ryYlhTZ1kI= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1742311665683585.657336808502; Tue, 18 Mar 2025 08:27:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tuWET-0002qp-ET; Tue, 18 Mar 2025 08:39:45 -0400 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 1tuWEN-0002gE-Fo for qemu-devel@nongnu.org; Tue, 18 Mar 2025 08:39:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tuWEG-0007c8-K2 for qemu-devel@nongnu.org; Tue, 18 Mar 2025 08:39:38 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-607-BgsRubG-Op6rw14R4nlqdg-1; Tue, 18 Mar 2025 08:39:27 -0400 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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 827D61801A00; Tue, 18 Mar 2025 12:39:26 +0000 (UTC) Received: from kaapi.redhat.com (unknown [10.74.16.234]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8C215180094A; Tue, 18 Mar 2025 12:39:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1742301570; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kPof6sTt4ptR9GIy4E4urQ6PAt+v+dGETnww+PA+Q7c=; b=bjkCginmn0dttlrcxmXS56NJ7AvzBBBIXcdcStg8UDWGSGZzLA7+LTjPRQSVBeFE+hLrn8 DlT57wqRyzQRaUyBTPMemr63x4KH9ieLvEv7prdESzZ22/eg/Wezc3qI9fp6mrpbft73Nr LSQ8nPVcT5B4evaeEy766oaK079h8Fg= X-MC-Unique: BgsRubG-Op6rw14R4nlqdg-1 X-Mimecast-MFC-AGG-ID: BgsRubG-Op6rw14R4nlqdg_1742301566 From: Prasad Pandit To: qemu-devel@nongnu.org Cc: peterx@redhat.com, farosas@suse.de, berrange@redhat.com Subject: [PATCH v8 6/7] migration: Add save_postcopy_prepare() savevm handler Date: Tue, 18 Mar 2025 18:08:45 +0530 Message-ID: <20250318123846.1370312-7-ppandit@redhat.com> In-Reply-To: <20250318123846.1370312-1-ppandit@redhat.com> References: <20250318123846.1370312-1-ppandit@redhat.com> MIME-Version: 1.0 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.129.124; envelope-from=ppandit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.332, 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_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1742311667531019100 Content-Type: text/plain; charset="utf-8" From: Peter Xu Add a savevm handler for a module to opt-in sending extra sections right before postcopy starts, and before VM is stopped. RAM will start to use this new savevm handler in the next patch to do flush and sync for multifd pages. Note that we choose to do it before VM stopped because the current only potential user is not sensitive to VM status, so doing it before VM is stopped is preferred to enlarge any postcopy downtime. It is still a bit unfortunate that we need to introduce such a new savevm handler just for the only use case, however it's so far the cleanest. Signed-off-by: Peter Xu Signed-off-by: Prasad Pandit --- include/migration/register.h | 15 +++++++++++++++ migration/migration.c | 4 ++++ migration/savevm.c | 33 +++++++++++++++++++++++++++++++++ migration/savevm.h | 1 + 4 files changed, 53 insertions(+) v8: - New patch v7: - https://lore.kernel.org/qemu-devel/20250228121749.553184-1-ppandit@redhat= .com/T/#t diff --git a/include/migration/register.h b/include/migration/register.h index c041ce32f2..b79dc81b8d 100644 --- a/include/migration/register.h +++ b/include/migration/register.h @@ -189,6 +189,21 @@ typedef struct SaveVMHandlers { =20 /* This runs outside the BQL! */ =20 + /** + * @save_postcopy_prepare + * + * This hook will be invoked on the source side right before switching + * to postcopy (before VM stopped). + * + * @f: QEMUFile where to send the data + * @opaque: Data pointer passed to register_savevm_live() + * @errp: Error** used to report error message + * + * Returns: true if succeeded, false if error occured. When false is + * returned, @errp must be set. + */ + bool (*save_postcopy_prepare)(QEMUFile *f, void *opaque, Error **errp); + /** * @state_pending_estimate * diff --git a/migration/migration.c b/migration/migration.c index f97bb2777f..afb4dda19e 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2721,6 +2721,10 @@ static int postcopy_start(MigrationState *ms, Error = **errp) } } =20 + if (!qemu_savevm_state_postcopy_prepare(ms->to_dst_file, errp)) { + return -1; + } + trace_postcopy_start(); bql_lock(); trace_postcopy_start_set_run(); diff --git a/migration/savevm.c b/migration/savevm.c index ce158c3512..23ef4c7dc9 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1523,6 +1523,39 @@ void qemu_savevm_state_complete_postcopy(QEMUFile *f) qemu_fflush(f); } =20 +bool qemu_savevm_state_postcopy_prepare(QEMUFile *f, Error **errp) +{ + SaveStateEntry *se; + bool ret; + + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + if (!se->ops || !se->ops->save_postcopy_prepare) { + continue; + } + + if (se->ops->is_active) { + if (!se->ops->is_active(se->opaque)) { + continue; + } + } + + trace_savevm_section_start(se->idstr, se->section_id); + + save_section_header(f, se, QEMU_VM_SECTION_PART); + ret =3D se->ops->save_postcopy_prepare(f, se->opaque, errp); + save_section_footer(f, se); + + trace_savevm_section_end(se->idstr, se->section_id, ret); + + if (!ret) { + assert(*errp); + return false; + } + } + + return true; +} + int qemu_savevm_state_complete_precopy_iterable(QEMUFile *f, bool in_postc= opy) { int64_t start_ts_each, end_ts_each; diff --git a/migration/savevm.h b/migration/savevm.h index 138c39a7f9..2d5e9c7166 100644 --- a/migration/savevm.h +++ b/migration/savevm.h @@ -45,6 +45,7 @@ void qemu_savevm_state_pending_exact(uint64_t *must_preco= py, void qemu_savevm_state_pending_estimate(uint64_t *must_precopy, uint64_t *can_postcopy); int qemu_savevm_state_complete_precopy_iterable(QEMUFile *f, bool in_postc= opy); +bool qemu_savevm_state_postcopy_prepare(QEMUFile *f, Error **errp); void qemu_savevm_send_ping(QEMUFile *f, uint32_t value); void qemu_savevm_send_open_return_path(QEMUFile *f); int qemu_savevm_send_packaged(QEMUFile *f, const uint8_t *buf, size_t len); --=20 2.48.1 From nobody Thu Apr 3 10:02:40 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1742306982; cv=none; d=zohomail.com; s=zohoarc; b=USLTlZBpNQiH8bbl74+Q8TS7tRSwb2qt3USI1G1iLT0f4ew+1VYQhtu6/e1ImkNSlaQDU6AkX9k8LpXtQZkLpf3JgPGiRi5f0/dZUBm78nxkUT1tHa5asHPCJCSyk32+DffuMTlEXqExkuVzwZlgR9+6u+XoNJWKwDeB5A8l7Ts= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1742306982; h=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=06iM+9P55Mj7StAkwOGZYdkiRCeTKmpFEP5kkBTrn2A=; b=XrTvH+6jgOM8Lv94Ke0/yU2Mmbm1BvoCvgFklxZkKgKlQEnQm2Md+Y/zZ9h6qKza1tRC17AZI82URb86yHIR+feqlVQ2wCH+H1EWHGnCG3YkOzWB9JO3hC5eDucb/O5hrNChGjv3dkzxMsgFBlp3CM9vAGvE6XRBl/eY5AnUgJQ= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1742306982545409.7960886932235; Tue, 18 Mar 2025 07:09:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tuWEZ-0003Cz-HJ; Tue, 18 Mar 2025 08:39:51 -0400 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 1tuWEN-0002gG-Hu for qemu-devel@nongnu.org; Tue, 18 Mar 2025 08:39:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tuWEJ-0007gm-LF for qemu-devel@nongnu.org; Tue, 18 Mar 2025 08:39:38 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-39-LcobzCDHNPClf9YLS81t8A-1; Tue, 18 Mar 2025 08:39:31 -0400 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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 82F621801A07; Tue, 18 Mar 2025 12:39:30 +0000 (UTC) Received: from kaapi.redhat.com (unknown [10.74.16.234]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 82A481800946; Tue, 18 Mar 2025 12:39:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1742301574; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=06iM+9P55Mj7StAkwOGZYdkiRCeTKmpFEP5kkBTrn2A=; b=Z5vwlpNeeVa7xxnFPsmR/gvU3huLAjjK3eTBxpTJtqZvNMS1tc4UnFlpofSZcumgzNyqF0 WYqrSRNMIVGrzY5XO0ZBzsSYjf3//6oKx4+34uPi+XNakShhVxxk6S/DSKM2UjvamP3nSk gmqMOgInk/PiIGn7Iyyy0m/e/1zSwrM= X-MC-Unique: LcobzCDHNPClf9YLS81t8A-1 X-Mimecast-MFC-AGG-ID: LcobzCDHNPClf9YLS81t8A_1742301570 From: Prasad Pandit To: qemu-devel@nongnu.org Cc: peterx@redhat.com, farosas@suse.de, berrange@redhat.com Subject: [PATCH v8 7/7] migration/ram: Implement save_postcopy_prepare() Date: Tue, 18 Mar 2025 18:08:46 +0530 Message-ID: <20250318123846.1370312-8-ppandit@redhat.com> In-Reply-To: <20250318123846.1370312-1-ppandit@redhat.com> References: <20250318123846.1370312-1-ppandit@redhat.com> MIME-Version: 1.0 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.129.124; envelope-from=ppandit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.332, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1742306984313019000 Content-Type: text/plain; charset="utf-8" From: Peter Xu Implement save_postcopy_prepare(), preparing for the enablement of both multifd and postcopy. Please see the rich comment for the rationals. Signed-off-by: Peter Xu Signed-off-by: Prasad Pandit --- migration/ram.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) v8: - New patch v7: - https://lore.kernel.org/qemu-devel/20250228121749.553184-1-ppandit@redhat= .com/T/#t diff --git a/migration/ram.c b/migration/ram.c index 6fd88cbf2a..04fde7ba6b 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -4419,6 +4419,42 @@ static int ram_resume_prepare(MigrationState *s, voi= d *opaque) return 0; } =20 +static bool ram_save_postcopy_prepare(QEMUFile *f, void *opaque, Error **e= rrp) +{ + int ret; + + if (migrate_multifd()) { + /* + * When multifd is enabled, source QEMU needs to make sure all the + * pages queued before postcopy starts to be flushed. + * + * Meanwhile, the load of these pages must happen before switching + * to postcopy. It's because loading of guest pages (so far) in + * multifd recv threads is still non-atomic, so the load cannot + * happen with vCPUs running on destination side. + * + * This flush and sync will guarantee those pages loaded _before_ + * postcopy starts on destination. The rational is, this happens + * before VM stops (and before source QEMU sends all the rest of + * the postcopy messages). So when the destination QEMU received + * the postcopy messages, it must have received the sync message on + * the main channel (either RAM_SAVE_FLAG_MULTIFD_FLUSH, or + * RAM_SAVE_FLAG_EOS), and such message should have guaranteed all + * previous guest pages queued in the multifd channels to be + * completely loaded. + */ + ret =3D multifd_ram_flush_and_sync(f); + if (ret < 0) { + error_setg(errp, "%s: multifd flush and sync failed", __func__= ); + return false; + } + } + + qemu_put_be64(f, RAM_SAVE_FLAG_EOS); + + return true; +} + void postcopy_preempt_shutdown_file(MigrationState *s) { qemu_put_be64(s->postcopy_qemufile_src, RAM_SAVE_FLAG_EOS); @@ -4438,6 +4474,7 @@ static SaveVMHandlers savevm_ram_handlers =3D { .load_setup =3D ram_load_setup, .load_cleanup =3D ram_load_cleanup, .resume_prepare =3D ram_resume_prepare, + .save_postcopy_prepare =3D ram_save_postcopy_prepare, }; =20 static void ram_mig_ram_block_resized(RAMBlockNotifier *n, void *host, --=20 2.48.1