From: Peter Xu <peterx@redhat.com>
To: Fabiano Rosas <farosas@suse.de>
Cc: qemu-devel@nongnu.org,
"Marco Cavenati" <Marco.Cavenati@eurecom.fr>,
"Daniel P. Berrangé" <berrange@redhat.com>
Subject: Re: [RESEND] migration/savevm: Add a compatibility check for capabilities
Date: Tue, 7 Oct 2025 15:14:07 -0400 [thread overview]
Message-ID: <aOVmfzJFa1C7aaF1@x1.local> (raw)
In-Reply-To: <20251007184213.5990-1-farosas@suse.de>
queued.
+Dan
On Tue, Oct 07, 2025 at 03:42:13PM -0300, Fabiano Rosas wrote:
> It has always been possible to enable arbitrary migration capabilities
> and attempt to take a snapshot of the VM with the savevm/loadvm
> commands as well as their QMP counterparts
> snapshot-save/snapshot-load.
>
> Most migration capabilities are not meant to be used with snapshots
> and there's a risk of crashing QEMU or producing incorrect
> behavior. Ideally, every migration capability would either be
> implemented for savevm or explicitly rejected.
>
> Add a compatibility check routine and reject the snapshot command if
> an incompatible capability is enabled. For now only act on the the two
> that actually cause a crash: multifd and mapped-ram.
>
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2881
> Signed-off-by: Fabiano Rosas <farosas@suse.de>
> ---
> migration/options.c | 27 +++++++++++++++++++++++++++
> migration/options.h | 1 +
> migration/savevm.c | 8 ++++++++
> 3 files changed, 36 insertions(+)
>
> diff --git a/migration/options.c b/migration/options.c
> index 5183112775..d9227809d7 100644
> --- a/migration/options.c
> +++ b/migration/options.c
> @@ -445,11 +445,38 @@ INITIALIZE_MIGRATE_CAPS_SET(check_caps_background_snapshot,
> MIGRATION_CAPABILITY_VALIDATE_UUID,
> MIGRATION_CAPABILITY_ZERO_COPY_SEND);
>
> +/* Snapshot compatibility check list */
> +static const
> +INITIALIZE_MIGRATE_CAPS_SET(check_caps_savevm,
> + MIGRATION_CAPABILITY_MULTIFD,
> + MIGRATION_CAPABILITY_MAPPED_RAM,
> +);
> +
> static bool migrate_incoming_started(void)
> {
> return !!migration_incoming_get_current()->transport_data;
> }
>
> +bool migrate_can_snapshot(Error **errp)
> +{
> + MigrationState *s = migrate_get_current();
> + int i;
> +
> + for (i = 0; i < check_caps_savevm.size; i++) {
> + int incomp_cap = check_caps_savevm.caps[i];
> +
> + if (s->capabilities[incomp_cap]) {
> + error_setg(errp,
> + "Snapshots are not compatible with %s",
> + MigrationCapability_str(incomp_cap));
> + return false;
> + }
> + }
> +
> + return true;
> +}
> +
> +
> bool migrate_rdma_caps_check(bool *caps, Error **errp)
> {
> if (caps[MIGRATION_CAPABILITY_XBZRLE]) {
> diff --git a/migration/options.h b/migration/options.h
> index 82d839709e..a7b3262d1e 100644
> --- a/migration/options.h
> +++ b/migration/options.h
> @@ -59,6 +59,7 @@ bool migrate_tls(void);
>
> bool migrate_rdma_caps_check(bool *caps, Error **errp);
> bool migrate_caps_check(bool *old_caps, bool *new_caps, Error **errp);
> +bool migrate_can_snapshot(Error **errp);
>
> /* parameters */
>
> diff --git a/migration/savevm.c b/migration/savevm.c
> index 7b35ec4dd0..aafa40d779 100644
> --- a/migration/savevm.c
> +++ b/migration/savevm.c
> @@ -3322,6 +3322,10 @@ bool save_snapshot(const char *name, bool overwrite, const char *vmstate,
>
> GLOBAL_STATE_CODE();
>
> + if (!migrate_can_snapshot(errp)) {
> + return false;
> + }
> +
> if (migration_is_blocked(errp)) {
> return false;
> }
> @@ -3507,6 +3511,10 @@ bool load_snapshot(const char *name, const char *vmstate,
> int ret;
> MigrationIncomingState *mis = migration_incoming_get_current();
>
> + if (!migrate_can_snapshot(errp)) {
> + return false;
> + }
> +
> if (!bdrv_all_can_snapshot(has_devices, devices, errp)) {
> return false;
> }
> --
> 2.35.3
>
--
Peter Xu
prev parent reply other threads:[~2025-10-07 19:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-07 18:42 [RESEND] migration/savevm: Add a compatibility check for capabilities Fabiano Rosas
2025-10-07 19:14 ` Peter Xu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aOVmfzJFa1C7aaF1@x1.local \
--to=peterx@redhat.com \
--cc=Marco.Cavenati@eurecom.fr \
--cc=berrange@redhat.com \
--cc=farosas@suse.de \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).