Skip to contentSkip to conversation

migration/vl: new -incoming config:* for early migration parameters

PATCH In review Peter Xu 1 participant 4 messages May 28

lore
Share & tools
lore

Peter Xu

author
#0 lore raw

v2 cover migration/vl: new -incoming config:* for early migration parameters

CI: https://gitlab.com/peterx/qemu/-/pipelines/2560168907

This series introduces a generic way to specify migration parameters that can be used even during the early boot phase of QEMU.

One example use case that already existed is CPR-transfer / CPR-exec. currently QEMU has a temporary global variable (incoming_mode) to achieve this, but it's hard to understand and this hack bleeded into quite a few places that we could have avoided. The lines in patch 2 touched may provide some idea.

With a generic approach of setting migration parameters with cmdlines, we can remove this hack meanwhile QEMU should be able to keep the CPR behavior as before. To CPR maintainers and reviewers: please have a closer look, even better if it can be smoke tested, to see if this works for Oracle's environment, TIA.

The 1st patch implemented that new semantics. It is straightforward: now we can setup any migration parameter using an extra line of:

-incoming config:key1=value1,key2=value2,...

So far only one such instance is allowed for simplicity, but it should be enough. We still allow multiple -incoming for specifying channels, used together with one "-incoming config:*".

Then parameters set this way will be visible almost anytime for QEMU, for example, during initialization of device backends (which is before migration object created).

I posted this series majorly because I want to see if this will make a possible new user for the new "local" migration parameter proposed in Vladimir's series:

https://lore.kernel.org/r/[email protected]

Especially, there're some context on this idea too in this email:

https://lore.kernel.org/all/[email protected]/

With this series, we should be able to drop "incoming-fds" TAP property from the other series, instead relying on the existing "local" parameters both in migration core and in TAP's property should suffice.

One thing to mention is I didn't further make only-migratable into a migration parameter. Logically it will also work now with only-migratable, but it then also means I'll need to convert it to a parameter, which will be mutable even after VM started. It will change how only-migratable used to work, hence I skipped.

After this, we also almost have no reason to use -global for migration parameters. Capabilities are still not supported in -incoming cmdline, though.

Thanks,

Peter Xu (2):
migration/vl: Allow set parameters with -incoming config:* migration/cpr: Opt-in "mode" parameter for early boot access

 include/migration/cpr.h  |  3 --
 include/migration/misc.h |  5 +++
 migration/migration.h    |  3 ++
 migration/cpr.c          | 18 ++++----
 migration/migration.c    | 91 +++++++++++++++++++++++++++++++++++++++-
 migration/options.c      | 10 ++---
 system/vl.c              |  7 ++++
 qemu-options.hx          | 18 +++++++-
 8 files changed, 133 insertions(+), 22 deletions(-)
Signature · 1 line
2.53.0
author
#1 lore raw

PATCH v2 1/2 migration/vl: Allow set parameters with -incoming config:*

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/[email protected]

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=value1,key2=value2,...

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.

---
 include/migration/misc.h |  5 ++++
 migration/migration.c    | 54 ++++++++++++++++++++++++++++++++++++++++
 system/vl.c              |  7 ++++++
 qemu-options.hx          | 18 ++++++++++++--
 4 files changed, 82 insertions(+), 2 deletions(-)
include/migration/misc.h +5 -0
index 3159a5e53c..aff79b1380 100644
@@ -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=value1,..." to initialize
+ * migration parameters.
+ */
+bool migration_parameters_boot_parse(const char *config_str, Error **errp);
 
 /* migration/multifd-device-state.c */
 typedef struct SaveCompletePrecopyThreadData {
migration/migration.c +54 -0

78 lines not on this page · raw message

system/vl.c +7 -0
index da36b2c6e1..49f5fa0c7b 100644
@@ -1838,6 +1838,13 @@ static void incoming_option_parse(const char *str)
 
     if (!strcmp(str, "defer")) {
         channel = 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 {
qemu-options.hx +16 -2
index 96ae41f787..1fc92a409a 100644
@@ -5366,11 +5366,15 @@ DEF("incoming", HAS_ARG, QEMU_OPTION_incoming, \
     "-incoming <channel>\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=value1,key2=value2,...\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 <channel>,
 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 one 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=value1[,key2=value2,...]``
+
+    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
 
 DEF("only-migratable", 0, QEMU_OPTION_only_migratable, \
Signature · 1 line
2.53.0
author
#2 lore raw

PATCH v2 2/2 migration/cpr: Opt-in "mode" parameter for early boot access

In reply to Peter Xu

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.

---
 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(-)
include/migration/cpr.h +0 -3
index 56fb67e6b4..27061ad629 100644
@@ -12,8 +12,6 @@
 #include "io/channel.h"
 #include "qemu/queue.h"
 
-#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);
 
-MigMode cpr_get_incoming_mode(void);
 void cpr_set_incoming_mode(MigMode mode);
 bool cpr_is_incoming(void);
 
migration/migration.h +3 -0
index 841f49b215..9fa97f6d9a 100644
@@ -609,4 +609,7 @@ void migration_bitmap_sync_precopy(bool last_stage);
 void dirty_bitmap_mig_init(void);
 bool should_send_vmdesc(void);
 
+void migration_parameters_boot_set_mode(MigMode mode);
+MigrationParameters *migration_get_parameters(void);
+
 #endif
migration/cpr.c +9 -9
index bca43e9bf3..1f49afe109 100644
@@ -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);
 }
 
-static MigMode incoming_mode = MIG_MODE_NONE;
-
-MigMode cpr_get_incoming_mode(void)
-{
-    return incoming_mode;
-}
-
 void cpr_set_incoming_mode(MigMode mode)
 {
-    incoming_mode = mode;
+    migration_parameters_boot_set_mode(mode);
 }
 
 bool cpr_is_incoming(void)
 {
-    return incoming_mode != MIG_MODE_NONE;
+    MigMode mode = migrate_mode();
+
+    if (!runstate_check(RUN_STATE_INMIGRATE)) {
+        return false;
+    }
+
+    return mode == MIG_MODE_CPR_EXEC || mode == MIG_MODE_CPR_TRANSFER;
 }
 
 bool cpr_state_save(MigrationChannel *channel, Error **errp)
migration/migration.c +36 -1
index d918be7a44..d7591571ed 100644
@@ -145,6 +145,42 @@ static void migration_parameters_boot_apply(void)
     }
 }
 
+static void migration_parameters_boot_init(void)
+{
+    if (!mig_boot_params) {
+        mig_boot_params = 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=cpr-* 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 = true;
+    mig_boot_params->mode = 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 ?
+        &current_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 = NULL;
     }
 
-    cpr_set_incoming_mode(MIG_MODE_NONE);
     yank_unregister_instance(MIGRATION_YANK_INSTANCE);
 }
 
migration/options.c +3 -7
index 5cbfd29099..c1209cbec3 100644
@@ -886,16 +886,12 @@ uint64_t migrate_max_postcopy_bandwidth(void)
     return s->parameters.max_postcopy_bandwidth;
 }
 
+/* Opt-in "mode" parameter to be available even during boot */
 MigMode migrate_mode(void)
 {
-    MigMode mode = cpr_get_incoming_mode();
+    MigrationParameters *params = migration_get_parameters();
 
-    if (mode == MIG_MODE_NONE) {
-        mode = migrate_get_current()->parameters.mode;
-    }
-
-    assert(mode >= 0 && mode < MIG_MODE__MAX);
-    return mode;
+    return params ? params->mode : MIG_MODE_NORMAL;
 }
 
 int migrate_multifd_channels(void)
Signature · 1 line
2.53.0