From nobody Sat May 30 17:43:31 2026 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=1780003823; cv=none; d=zohomail.com; s=zohoarc; b=hqf+aNurUO0h+kWGkAPnGp6BjE4N+zBOlNwGYh+UdqFq4OTwqqFk6kFfH3Msw5naPhdbCYwgG2mlp+Nk88duv5zy58wFay8f5jT9j6aHveA8n4BZZOTubbfK3MF7b0tcRIhpyrP5OVs4bVlaoo8PKbx9CQrP1K4Olo5IYJPysfI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780003823; 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=FIDQ2kvQqYtnxLEwqYnl1da/aYo+rT6/BzRSOHGERy0=; b=RtzXxkdI2BwhsJaVgsZd7JqZagddbMMegTtlfozp0jucX4sCUI+pu/c+K+VB/BP6gGkSknFJBSqyvagE1p8xEDtO2RAoSUppY9E/WBA+uBwacqdDXVrRmjzHVembY91B80bWVpBeNbBo0zcDcZqlrscJVMdgkTkERHiyuOtIKA0= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1780003823884490.58937061517565; Thu, 28 May 2026 14:30:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wSiIC-0005AE-EV; Thu, 28 May 2026 17:29:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wSiI9-00059M-AY for qemu-devel@nongnu.org; Thu, 28 May 2026 17:29:25 -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 1wSiI6-00033R-AR for qemu-devel@nongnu.org; Thu, 28 May 2026 17:29:25 -0400 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-515-2TPtvBQXO9Cxse-zPbo4SA-1; Thu, 28 May 2026 17:29:19 -0400 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-914b56ea791so38265585a.2 for ; Thu, 28 May 2026 14:29:19 -0700 (PDT) Received: from x1.com ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id af79cd13be357-9152fd10282sm5770085a.7.2026.05.28.14.29.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 May 2026 14:29:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780003760; 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=FIDQ2kvQqYtnxLEwqYnl1da/aYo+rT6/BzRSOHGERy0=; b=McwVsD+L0OuqEXCXGsvw8ilqLBS1fStn1a9Up4mlaCPoVCJdIJ/6wrhJl+gpYbs5c/yJsg n3RHedFAU4ZPMG+/8UHZK5LJTANj6h4gnPOGbCxtqQdKHXjS1N2gJNPdbdRo35qsTvqcj2 jqD55Kbimt78v//MPmPNmwNt2EWoY5s= X-MC-Unique: 2TPtvBQXO9Cxse-zPbo4SA-1 X-Mimecast-MFC-AGG-ID: 2TPtvBQXO9Cxse-zPbo4SA_1780003759 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1780003759; x=1780608559; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FIDQ2kvQqYtnxLEwqYnl1da/aYo+rT6/BzRSOHGERy0=; b=UCyZds0zagyX9N9M70MpXOAklfFmGpNPq0GQoBCi5F/+dCL9s+9GQhtRh3bBO2ogec xnNzbUEYBJcfOHjFJ23N1MgKDf/aEY5z+clQu+Zkv9gUkjL8ryzoAY8msTs2qaCi+OaU +Go9HpMo2YONhWB6BjL7nrNjlKdlfXGqbCyLwn6cnp16v2VtK7SrWoSFCtbcyBMVQL9I X+V0DRj7eG5aOwAdBjppNoHgJqnwiCfRQHtxLmJy2bH1YttQ55JL9awNkS1zYHaLgI1v IfSrNB+DXH0UkMkGZgTyIj4OfRQ2libTt/N5/r9sVRfY2kdWeELJjOpCudOQ+JBZ7uOC J8bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780003759; x=1780608559; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=FIDQ2kvQqYtnxLEwqYnl1da/aYo+rT6/BzRSOHGERy0=; b=P21jSDY+9fK2stYTdzbe2aES3Y0NfAi42HjQujfAEpdFKRa2bccOrkJGV9Y1xsjSyR ZuA+N+cYZYXCYrapW9uUf+7YXGsHiWAiRX/KNYSpnc3ylJ+edMRGU9MWHHLRgx030Qyz /TNe+IoKns9NBWAwWlqGXPb/b74FNsXLDMCd3Uwa0C4rZjdkA1murHWQNS+LjZ0srRGz KMgsLUnOYUgTMBN5KPUyIP52BD5sJksKQ7sH9dV+qKIxi2Y0qpS1I556I4sbQQoHF/2S H6E2jeq105kTG65k5p+cY99Od4ZDHb3S2qyWX/jR+QPphWP0toMLGGJtEfUi5hSvGoY9 P/LQ== X-Gm-Message-State: AOJu0YznUiJmIGCu/KAMWdEHThTpvHviukWGsahKKGdr+3hJAdcktAjd F1frZJnIWS29ctalLqQ3Kim5n+PL9ykuMWBXe0Cf4qCD0ZD6iBueTf/fvb7/WjnMz3o6oZVyP++ p4N1OgE+iyxk/sJMKub67XJN8q25AHOggwKM0UMno5bD5p6v3G1/w3y5R8j3ZjtiyXDpkvYoIbO uQEb+Fxpjrm/QBPutdxu8ckBkkINlsxD+ymJTJLA== X-Gm-Gg: Acq92OFeO/0oJa6aml/7cPwuUrIyPEmp5g5HV7XmtSG8QfBi08GpZLDlWNr23Y3DR4o dJKQ0WTkHTurblQANBqJeWfL+PQRgw0AHnq41oNQ9nP3kLKZSTEwhnC0ke+uAIuaq31wlPKQtXa 8VxrphbLUpVuIgBy7M27LZBDVrdf2eoFrxIIufGt8oRimUjGsA/u5kS0BhBWWwwOhjR9MiGmXLN 5t5jF6IN+zewGE+ZzpGIBlnLHXBdVFH8z+6mjJ+Dycni7tPSFfMp9vfjLjTmltL04hrMQb6sVVe iSntl2sYpfDmE4AXHjdjytISjb7fBZLWj9LqlneFZMR7sWU03u/tDCVE8iiiQO8ys2w27W6j/bW mg50KBWBp28JO+W2m22cJ9AJmTX7BZtgUXY3U3fc/3yQYB4fYruNE944= X-Received: by 2002:a05:620a:29c9:b0:914:babf:9f40 with SMTP id af79cd13be357-9152fdea256mr7863085a.28.1780003758693; Thu, 28 May 2026 14:29:18 -0700 (PDT) X-Received: by 2002:a05:620a:29c9:b0:914:babf:9f40 with SMTP id af79cd13be357-9152fdea256mr7856285a.28.1780003758066; Thu, 28 May 2026 14:29:18 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Maciej S. Szmigiero" , Mark Kanda , peterx@redhat.com, Vladimir Sementsov-Ogievskiy , Fabiano Rosas , Eric Blake , Markus Armbruster , Paolo Bonzini , "Michael S . Tsirkin" , Jason Wang , Ben Chaney Subject: [PATCH v2 1/2] migration/vl: Allow set parameters with -incoming config:* Date: Thu, 28 May 2026 17:29:11 -0400 Message-ID: <20260528212912.367967-2-peterx@redhat.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260528212912.367967-1-peterx@redhat.com> References: <20260528212912.367967-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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: qemu development 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: 1780003826685158500 Content-Type: text/plain; charset="utf-8" QEMU doesn't yet have a good way to specify migration parameters so that they can be available even during early stage of QEMU boots. It is because the migration object (who owns the migration parameters) will only be created after PHASE_LATE_BACKENDS_CREATED. It means anything before it reading migration parameters is illegal. However, QEMU does have special use cases for such, namely only-migratable flag, and cpr-transfer. Recently, we have one more possible user to read a to-be-introduced new migration parameters during backend initialization phase. We can introduce yet another global variable (or per-device parameter) to bypass this limitation, but we can also seek for a generic solution that we can setup migration parameters very early, even during backend initializations. See this discussion for more details on the context of the problem: https://lore.kernel.org/r/ahdI7Vl5KraK566D@x1.local This patch wants to take the latter approach. As a start, introduce a new way to specify migration parameters in QEMU boot commandline, as proposed in the above discussion: -incoming config:key1=3Dvalue1,key2=3Dvalue2,... When specified, QEMU will parse a string formatted MigrationParameters and keep it. When migration object is created, it will apply all the settings as initial value. Since the application of boot parameters will be after object_new() completes, it means it happens after all machine compat properties or -global settings (which should be done during instance_post_init()). So far, it's still only a way to specify parameters. All parameters are not visible before migration object created, like before. Any parameter that needs to be visible during boot will need to opt-in this feature. Follow up patches will switch the current users to use this model. Signed-off-by: Peter Xu --- include/migration/misc.h | 5 ++++ migration/migration.c | 54 ++++++++++++++++++++++++++++++++++++++++ system/vl.c | 7 ++++++ qemu-options.hx | 18 ++++++++++++-- 4 files changed, 82 insertions(+), 2 deletions(-) diff --git a/include/migration/misc.h b/include/migration/misc.h index 3159a5e53c..aff79b1380 100644 --- a/include/migration/misc.h +++ b/include/migration/misc.h @@ -133,6 +133,11 @@ bool migrate_is_uri(const char *uri); /* Parse @uri and return @channel, returning true on success */ bool migrate_uri_parse(const char *uri, MigrationChannel **channel, Error **errp); +/* + * Parse @config_str in form of "config:key1=3Dvalue1,..." to initialize + * migration parameters. + */ +bool migration_parameters_boot_parse(const char *config_str, Error **errp); =20 /* migration/multifd-device-state.c */ typedef struct SaveCompletePrecopyThreadData { diff --git a/migration/migration.c b/migration/migration.c index 074d3f2c69..d918be7a44 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -41,6 +41,7 @@ #include "qapi/qapi-commands-migration.h" #include "qapi/qapi-events-migration.h" #include "qapi/qmp/qerror.h" +#include "qapi/qobject-input-visitor.h" #include "qobject/qnull.h" #include "qemu/rcu.h" #include "postcopy-ram.h" @@ -94,6 +95,9 @@ enum mig_rp_message_type { static MigrationState *current_migration; static MigrationIncomingState *current_incoming; =20 +/* Only used during boot, destroyed after migration object initialized */ +static MigrationParameters *mig_boot_params; + static GSList *migration_blockers[MIG_MODE__MAX]; =20 static bool migration_object_check(MigrationState *ms, Error **errp); @@ -102,6 +106,45 @@ static bool stop_return_path_thread_on_source(Migratio= nState *s); static void migration_release_dst_files(MigrationState *ms); static void migration_completion_end(MigrationState *s); =20 +bool migration_parameters_boot_parse(const char *config_str, Error **errp) +{ + Visitor *v; + + if (mig_boot_params) { + error_setg(errp, "Only one -incoming config:* is allowed."); + return false; + } + + v =3D qobject_input_visitor_new_str(config_str, NULL, errp); + if (!v) { + goto fail; + } + + if (!visit_type_MigrationParameters(v, NULL, &mig_boot_params, errp)) { + goto fail; + } + + visit_free(v); + return true; + +fail: + visit_free(v); + return false; +} + +static void migration_parameters_boot_apply(void) +{ + if (mig_boot_params) { + /* + * This can fail, because qobject visitor doesn't do sanity check + * on values while parsing. It's not too late; we're still in boot + * phase. + */ + qmp_migrate_set_parameters(mig_boot_params, &error_abort); + g_clear_pointer(&mig_boot_params, qapi_free_MigrationParameters); + } +} + static void migration_downtime_start(MigrationState *s) { trace_vmstate_downtime_checkpoint("src-downtime-start"); @@ -322,6 +365,17 @@ void migration_object_init(void) =20 current_incoming->exit_on_error =3D INMIGRATE_DEFAULT_EXIT_ON_ERROR; =20 + /* + * Apply boot migration parameters in case the user specified some via + * command line "-incoming config:*". NOTE: this will overwrite machine + * type compat properties and -global settings! + */ + migration_parameters_boot_apply(); + + /* + * The boot parameters should have been verified already, but leave it + * after applying boot parameters to do one check for everything. + */ migration_object_check(current_migration, &error_fatal); =20 ram_mig_init(); diff --git a/system/vl.c b/system/vl.c index da36b2c6e1..49f5fa0c7b 100644 --- a/system/vl.c +++ b/system/vl.c @@ -1838,6 +1838,13 @@ static void incoming_option_parse(const char *str) =20 if (!strcmp(str, "defer")) { channel =3D NULL; + } else if (!strncmp(str, "config:", 7)) { + /* + * This is not a channel setup, but configuration to incoming + * migration parameters to make them available during early boot. + */ + migration_parameters_boot_parse(str + 7, &error_fatal); + return; } else if (migrate_is_uri(str)) { migrate_uri_parse(str, &channel, &error_fatal); } else { diff --git a/qemu-options.hx b/qemu-options.hx index 96ae41f787..1fc92a409a 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -5366,11 +5366,15 @@ DEF("incoming", HAS_ARG, QEMU_OPTION_incoming, \ "-incoming \n" \ " accept incoming migration on the migration channel\n"= \ "-incoming defer\n" \ - " wait for the URI to be specified via migrate_incoming= \n", + " wait for the URI to be specified via migrate_incoming= \n" + "-incoming config:key1=3Dvalue1,key2=3Dvalue2,...\n" \ + " specify migration parameters valid even during boot\n= ", QEMU_ARCH_ALL) SRST + The -incoming option specifies the migration channel for an incoming -migration. It may be used multiple times to specify multiple +migration, or can also be used to setup migration parameters for the +incoming migration. It may be used multiple times to specify multiple migration channel types. The channel type is specified in , or is 'main' for all other forms of -incoming. If multiple -incoming options are specified for a channel type, the last one takes precedence. @@ -5411,6 +5415,16 @@ options are specified for a channel type, the last o= ne takes precedence. Wait for the URI to be specified via migrate\_incoming. The monitor can be used to change settings (such as migration parameters) prior to issuing the migrate\_incoming to allow the migration to begin. + +``-incoming config:key1=3Dvalue1[,key2=3Dvalue2,...]`` + + Specify migration parameters in QEMU commandlines, so that these + parameters will be available even during very early boot of QEMU. + They will be applied properly after QEMU boots and when the migration + core is initialized. From that POV, it has similar effect as setting + these parameters using QMP command ``migrate-set-parameters`` or HMP + command ``migrate_set_parameter``. + ERST =20 DEF("only-migratable", 0, QEMU_OPTION_only_migratable, \ --=20 2.53.0 From nobody Sat May 30 17:43:31 2026 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=1780003839; cv=none; d=zohomail.com; s=zohoarc; b=cJax8/erQrgsg1mlWFeec35g5Pjxv30LRRmcTgZrpmeexoL1uHC2plq2gedziJ5Y109v+G5Q4JjKqPuqB3VoPgvHtUKBSIUM69UF+fffmcccDxfxRqSXhAydnAYz+8SdLBUdAbz+FcKowZVeXY/3pp4dIv5PKMqLaKva2OoToJw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780003839; 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=iK2oU4S+42s+otGAIzHzbA0pHikpDmtjFXz49vQJAUM=; b=M6Mg/hV5hAulQim+9GgwYvT+l9/zJ4UDzxyJpH2xc0+N1dokf9Y1XGvl6Dsmqjz159MY1Kog8WO4AydiwzSK6Ll7f8S2SjcTCKyxAHxOdlgTB8U/c9Sx+9sSnNGVJHaSNaV+rmJPyQF+BV0KWH0g1fqgAAaGJF28HnudHgCTOEs= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1780003839495401.0557482110215; Thu, 28 May 2026 14:30:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wSiIE-0005AQ-4d; Thu, 28 May 2026 17:29:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wSiIA-00059o-Gg for qemu-devel@nongnu.org; Thu, 28 May 2026 17:29:26 -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 1wSiI8-00033r-Kl for qemu-devel@nongnu.org; Thu, 28 May 2026 17:29:26 -0400 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-230-gj92fnUzNACVn8VMWqD45A-1; Thu, 28 May 2026 17:29:22 -0400 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-8ccd51bc2f5so23844036d6.2 for ; Thu, 28 May 2026 14:29:22 -0700 (PDT) Received: from x1.com ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id af79cd13be357-9152fd10282sm5770085a.7.2026.05.28.14.29.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 May 2026 14:29:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780003764; 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=iK2oU4S+42s+otGAIzHzbA0pHikpDmtjFXz49vQJAUM=; b=Je6RUg4bZO9RAVUSHcDuQHaMmZtYZAhnnro1JoUAjPtMQY9jc+EGDZW2UpYutAUI97e95+ /tDRkyQZsUqJU/otLNNtwDNEZZ8W5YMMiBdFfSjNB/JMeEwHppu3S8ZZl/jqXCVipXg3PU 3ouD31p7Bu7XLR0VraK/HM6ARy4goeg= X-MC-Unique: gj92fnUzNACVn8VMWqD45A-1 X-Mimecast-MFC-AGG-ID: gj92fnUzNACVn8VMWqD45A_1780003762 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1780003762; x=1780608562; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iK2oU4S+42s+otGAIzHzbA0pHikpDmtjFXz49vQJAUM=; b=h01dgfecNiic1Ca4SGOTsMF/MkOjT01djeOVbbpW4ZOfzdH+N4Gwh6vfDaPbBKXuEA l85TmtbrouD5mNpLJJmnMYjnnAdcBT8w6T9yPHB7qX/d3wW6o8ytfv/AsmlKLHt3PGHq 9HqVFk6yvHno4TSWTmxcALCr73NikqpIC58aQz1+rT4/TvTDUdHKWBTYSxZvo9VHsgCw Q+b26FIHsef/FxmCI0FRFuzGG7j3mYSV7Dzy3sBWEWFPf75+CtV5/1M/CVEEGUmWmu97 VohPLvZJMlBjeGyV35UXPrB3oke7K45U9ua4urwx1rbWmkHcyual9DgfD5zJioDrW0Jh uq8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780003762; x=1780608562; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=iK2oU4S+42s+otGAIzHzbA0pHikpDmtjFXz49vQJAUM=; b=kIqQw0XOB1ga0GE6Gh3imlIl3Rq2k77pKNEBwd6YtvnmW5yrrJscvfgKLRNcGetKqp tdL2YZyIS6HdaXmFY2jvReYJ31OvkdPxm1pMgbgUfUjAHZvc+Ju4KSH8rifSS9XYEQ29 EDkV1fDzAr/DOlZTzmu0s5333EqLjv4p34w/VqnPPzCN1THcO4Qz9iyUetQHf2rWrpZR 0cdFNfCQOruWFy4x9B2J5b55wf/TWnXfuAVet27sDc3pY1pu3RlpFvfmJHqm7Iea9fzc oiKdTrW6DyJYUS42r0eOKpPuGofKqpiUZ3gRu8MZGFL0jYBeO83xLrspjmRukIHHT16I q0vw== X-Gm-Message-State: AOJu0YzuGRmZGNW8lkahmAswfhYF87ooppx+BC2QSETfo5Tr+pg/juQC Y0BGUuGJf+YhOuP2pBb157BZX6/GYAKni6oLfi9K5gDAe8CbWbtnHgUjAT84BQoR+NwbuqlmesT 5+aAobddyuFDUFmLOkwaiiufK4mENSy3S+TYL9fE9F5pVSFbSQEr1g66VzcQU0NJXDENEXcqXWa ju4Ykesk4FjILYPZfLh2+ILX3i/IZZR976i3UbmQ== X-Gm-Gg: Acq92OFQERNIo1+X9gUAb5zX43wONyS1vrulk6vFNO7QO8/dNPZMLZk9GLrjpm8IZ0k GGVezea4bGNIF1Mm0MywEQqRxkhUDt+tdT6mS6me6fCI6VwIXslQzypOhsvY/F8HUeNddyTnnOk nG3fsHI9sIbMMBRyDPJ+EJb6c632Gzvls1TQCLB4tD9l25twrkeqxKSwW91pfEP/JcWeqsFvYhv OeZY1rQuDMfPoW0SOYeDQSQIXwjyP2HiSZUtBjFpOLBrZ9C98lF82myCeXrKm2JOB6nCAO+up0G Q5jszmkKHltmafzqAXI+pY97fqNHuB8aGtCQkIF4PF2XYqX33gzdl9ebyR++KJLdRbGlCylHSDp k8IWNPGMrJF4SAFU9GDl0d1g9JZSVU9h0Ll3MgivCSXrWI9YafqEnOTk= X-Received: by 2002:a05:620a:450f:b0:8cd:a3ab:352d with SMTP id af79cd13be357-9152ff65e2dmr5352585a.61.1780003761592; Thu, 28 May 2026 14:29:21 -0700 (PDT) X-Received: by 2002:a05:620a:450f:b0:8cd:a3ab:352d with SMTP id af79cd13be357-9152ff65e2dmr5346685a.61.1780003761009; Thu, 28 May 2026 14:29:21 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Maciej S. Szmigiero" , Mark Kanda , peterx@redhat.com, Vladimir Sementsov-Ogievskiy , Fabiano Rosas , Eric Blake , Markus Armbruster , Paolo Bonzini , "Michael S . Tsirkin" , Jason Wang , Ben Chaney Subject: [PATCH v2 2/2] migration/cpr: Opt-in "mode" parameter for early boot access Date: Thu, 28 May 2026 17:29:12 -0400 Message-ID: <20260528212912.367967-3-peterx@redhat.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260528212912.367967-1-peterx@redhat.com> References: <20260528212912.367967-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, 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, SPF_HELO_PASS=-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: qemu development 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: 1780003842750154100 Content-Type: text/plain; charset="utf-8" Make "mode" to be the first parameter to opt-in for early boot access. CPR will start to consume this early boot parameter. With this, we can remove the special "incoming_mode" variable together with cpr_get_incoming_mode(). One thing to mention is, to make cpr_is_incoming() work like before, we need to do extra check on INMIGRATE runstate to make sure it only returns true while during the incoming migration. It used to be achieved by a pretty hackish "cpr_set_incoming_mode(MIG_MODE_NONE)" when incoming migration destroys. Now we can remove it. Another good side effect is, we can finally drop MIG_MODE_NONE: it was never a valid value, only used by the temp global variable. Signed-off-by: Peter Xu --- include/migration/cpr.h | 3 --- migration/migration.h | 3 +++ migration/cpr.c | 18 +++++++++--------- migration/migration.c | 37 ++++++++++++++++++++++++++++++++++++- migration/options.c | 10 +++------- 5 files changed, 51 insertions(+), 20 deletions(-) diff --git a/include/migration/cpr.h b/include/migration/cpr.h index 56fb67e6b4..27061ad629 100644 --- a/include/migration/cpr.h +++ b/include/migration/cpr.h @@ -12,8 +12,6 @@ #include "io/channel.h" #include "qemu/queue.h" =20 -#define MIG_MODE_NONE -1 - #define QEMU_CPR_FILE_MAGIC 0x51435052 #define QEMU_CPR_FILE_VERSION 0x00000001 #define CPR_STATE "CprState" @@ -38,7 +36,6 @@ int cpr_open_fd(const char *path, int flags, const char *= name, int id, typedef bool (*cpr_walk_fd_cb)(int fd); bool cpr_walk_fd(cpr_walk_fd_cb cb); =20 -MigMode cpr_get_incoming_mode(void); void cpr_set_incoming_mode(MigMode mode); bool cpr_is_incoming(void); =20 diff --git a/migration/migration.h b/migration/migration.h index 841f49b215..9fa97f6d9a 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -609,4 +609,7 @@ void migration_bitmap_sync_precopy(bool last_stage); void dirty_bitmap_mig_init(void); bool should_send_vmdesc(void); =20 +void migration_parameters_boot_set_mode(MigMode mode); +MigrationParameters *migration_get_parameters(void); + #endif diff --git a/migration/cpr.c b/migration/cpr.c index bca43e9bf3..1f49afe109 100644 --- a/migration/cpr.c +++ b/migration/cpr.c @@ -16,6 +16,7 @@ #include "migration/qemu-file.h" #include "migration/savevm.h" #include "migration/vmstate.h" +#include "migration/migration.h" #include "monitor/monitor.h" #include "system/runstate.h" #include "trace.h" @@ -239,21 +240,20 @@ QIOChannel *cpr_state_ioc(void) return qemu_file_get_ioc(cpr_state_file); } =20 -static MigMode incoming_mode =3D MIG_MODE_NONE; - -MigMode cpr_get_incoming_mode(void) -{ - return incoming_mode; -} - void cpr_set_incoming_mode(MigMode mode) { - incoming_mode =3D mode; + migration_parameters_boot_set_mode(mode); } =20 bool cpr_is_incoming(void) { - return incoming_mode !=3D MIG_MODE_NONE; + MigMode mode =3D migrate_mode(); + + if (!runstate_check(RUN_STATE_INMIGRATE)) { + return false; + } + + return mode =3D=3D MIG_MODE_CPR_EXEC || mode =3D=3D MIG_MODE_CPR_TRANS= FER; } =20 bool cpr_state_save(MigrationChannel *channel, Error **errp) diff --git a/migration/migration.c b/migration/migration.c index d918be7a44..d7591571ed 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -145,6 +145,42 @@ static void migration_parameters_boot_apply(void) } } =20 +static void migration_parameters_boot_init(void) +{ + if (!mig_boot_params) { + mig_boot_params =3D g_new0(MigrationParameters, 1); + } +} + +/* + * This should only be used during boot by CPR. NOTE: This is only needed + * to be compatible with old CPR use case, if we decide to have users + * switch to -incoming config:mode=3Dcpr-* then this can be removed. + */ +void migration_parameters_boot_set_mode(MigMode mode) +{ + assert(!current_migration); + migration_parameters_boot_init(); + mig_boot_params->has_mode =3D true; + mig_boot_params->mode =3D mode; +} + +/* + * Get the effective migration parameter object. + * + * Three possibilities: + * - Migration object has been initialized, always use it, or, + * - Migration boot parameters are initialized, then use it, or, + * - return NULL + * + * Callers should always check non-NULL pointer first before use. + */ +MigrationParameters *migration_get_parameters(void) +{ + return current_migration ? + ¤t_migration->parameters : mig_boot_params; +} + static void migration_downtime_start(MigrationState *s) { trace_vmstate_downtime_checkpoint("src-downtime-start"); @@ -546,7 +582,6 @@ void migration_incoming_state_destroy(void) mis->postcopy_qemufile_dst =3D NULL; } =20 - cpr_set_incoming_mode(MIG_MODE_NONE); yank_unregister_instance(MIGRATION_YANK_INSTANCE); } =20 diff --git a/migration/options.c b/migration/options.c index 5cbfd29099..c1209cbec3 100644 --- a/migration/options.c +++ b/migration/options.c @@ -886,16 +886,12 @@ uint64_t migrate_max_postcopy_bandwidth(void) return s->parameters.max_postcopy_bandwidth; } =20 +/* Opt-in "mode" parameter to be available even during boot */ MigMode migrate_mode(void) { - MigMode mode =3D cpr_get_incoming_mode(); + MigrationParameters *params =3D migration_get_parameters(); =20 - if (mode =3D=3D MIG_MODE_NONE) { - mode =3D migrate_get_current()->parameters.mode; - } - - assert(mode >=3D 0 && mode < MIG_MODE__MAX); - return mode; + return params ? params->mode : MIG_MODE_NORMAL; } =20 int migrate_multifd_channels(void) --=20 2.53.0