From: Peter Xu <peterx@redhat.com>
To: "Cédric Le Goater" <clg@redhat.com>
Cc: Avihai Horon <avihaih@nvidia.com>,
qemu-devel@nongnu.org, Alex Williamson <alex@shazbot.org>,
Eric Blake <eblake@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
Fabiano Rosas <farosas@suse.de>
Subject: Re: [PATCH] vfio/migration: Send migration event before device state transition
Date: Wed, 28 Jan 2026 09:49:38 -0500 [thread overview]
Message-ID: <aXoiAsGCWRv1nwW-@x1.local> (raw)
In-Reply-To: <36062a37-0af5-49fc-ac06-212096fb2c30@redhat.com>
On Wed, Jan 28, 2026 at 12:03:46PM +0100, Cédric Le Goater wrote:
> +Peter, + Fabiano
Thanks, looks benign to me from migration POV. I have one question though,
and not sure if I'm the only one wondering..
>
> On 1/28/26 11:51, Avihai Horon wrote:
> > Currently, VFIO device migration event is sent after the device state
> > transition has been completed. However, it may be useful to additionally
> > send a "prepare" event before the state transition, to notify users that
> > it's about to happen.
> >
> > For example, in some cases with heavy resource utilization, stopping the
> > VFIO device may take a long time. In time-sensitive scenarios, the
> > management application that consumes the event may be notified about the
> > state transition too late.
Could there be more elaborations on the problem? For example:
(1) What would the mgmt do when receiving the notification? What would go
wrong if the state notification will be very late?
(2) Why would a prepare message help this situation?
(3) Doc below says, the prepare message does not imply the event will be
guaranteed to happen. Would it confuse the mgmt?
Thanks,
> >
> > To overcome this issue, send an additional "prepare" migration event
> > before the device state transition.
> >
> > Signed-off-by: Avihai Horon <avihaih@nvidia.com>
> > ---
> > qapi/vfio.json | 33 +++++++++++++++++++++++++++++++++
> > hw/vfio/migration.c | 18 +++++++++++++-----
> > 2 files changed, 46 insertions(+), 5 deletions(-)
> >
> > diff --git a/qapi/vfio.json b/qapi/vfio.json
> > index a1a9c5b673..de41211f1d 100644
> > --- a/qapi/vfio.json
> > +++ b/qapi/vfio.json
> > @@ -66,3 +66,36 @@
> > 'qom-path': 'str',
> > 'device-state': 'QapiVfioMigrationState'
> > } }
> > +
> > +##
> > +# @VFIO_MIGRATION_PREPARE:
> > +#
> > +# This event is emitted when a VFIO device migration state is about to
> > +# be changed. Note that even if this event is received for state X,
> > +# the VFIO device may transition to a different state if the original
> > +# state transition to X failed.
> > +#
> > +# @device-id: The device's id, if it has one.
> > +#
> > +# @qom-path: The device's QOM path.
> > +#
> > +# @device-state: The new device migration state that is about to be
> > +# changed.
> > +#
> > +# Since: 11.0
> > +#
> > +# .. qmp-example::
> > +#
> > +# <- { "timestamp": { "seconds": 1713771323, "microseconds": 212268 },
> > +# "event": "VFIO_MIGRATION_PREPARE",
> > +# "data": {
> > +# "device-id": "vfio_dev1",
> > +# "qom-path": "/machine/peripheral/vfio_dev1",
> > +# "device-state": "stop" } }
> > +##
> > +{ 'event': 'VFIO_MIGRATION_PREPARE',
> > + 'data': {
> > + 'device-id': 'str',
> > + 'qom-path': 'str',
> > + 'device-state': 'QapiVfioMigrationState'
> > + } }
> > diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
> > index b4695030c7..9f887c148f 100644
> > --- a/hw/vfio/migration.c
> > +++ b/hw/vfio/migration.c
> > @@ -90,9 +90,11 @@ mig_state_to_qapi_state(enum vfio_device_mig_state state)
> > }
> > }
> > -static void vfio_migration_send_event(VFIODevice *vbasedev)
> > +static void vfio_migration_send_event(VFIODevice *vbasedev,
> > + enum vfio_device_mig_state state,
> > + bool prep)
> > {
> > - VFIOMigration *migration = vbasedev->migration;
> > + QapiVfioMigrationState qapi_state;
> > DeviceState *dev = vbasedev->dev;
> > g_autofree char *qom_path = NULL;
> > Object *obj;
> > @@ -105,9 +107,13 @@ static void vfio_migration_send_event(VFIODevice *vbasedev)
> > obj = vbasedev->ops->vfio_get_object(vbasedev);
> > g_assert(obj);
> > qom_path = object_get_canonical_path(obj);
> > + qapi_state = mig_state_to_qapi_state(state);
> > - qapi_event_send_vfio_migration(
> > - dev->id, qom_path, mig_state_to_qapi_state(migration->device_state));
> > + if (prep) {
> > + qapi_event_send_vfio_migration_prepare(dev->id, qom_path, qapi_state);
> > + } else {
> > + qapi_event_send_vfio_migration(dev->id, qom_path, qapi_state);
> > + }
> > }
> > static void vfio_migration_set_device_state(VFIODevice *vbasedev,
> > @@ -119,7 +125,7 @@ static void vfio_migration_set_device_state(VFIODevice *vbasedev,
> > mig_state_to_str(state));
> > migration->device_state = state;
> > - vfio_migration_send_event(vbasedev);
> > + vfio_migration_send_event(vbasedev, state, false);
> > }
> > int vfio_migration_set_state(VFIODevice *vbasedev,
> > @@ -146,6 +152,8 @@ int vfio_migration_set_state(VFIODevice *vbasedev,
> > return 0;
> > }
> > + vfio_migration_send_event(vbasedev, new_state, true);
> > +
> > feature->argsz = sizeof(buf);
> > feature->flags =
> > VFIO_DEVICE_FEATURE_SET | VFIO_DEVICE_FEATURE_MIG_DEVICE_STATE;
>
--
Peter Xu
next prev parent reply other threads:[~2026-01-28 14:50 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-28 10:51 [PATCH] vfio/migration: Send migration event before device state transition Avihai Horon
2026-01-28 11:03 ` Cédric Le Goater
2026-01-28 14:49 ` Peter Xu [this message]
2026-01-28 15:32 ` Avihai Horon
2026-01-28 16:21 ` Peter Xu
2026-01-28 17:13 ` Avihai Horon
2026-01-28 17:38 ` Peter Xu
2026-01-29 5:11 ` Avihai Horon
2026-01-29 14:31 ` Cédric Le Goater
2026-01-29 21:18 ` Avihai Horon
2026-01-30 13:34 ` Cédric Le Goater
2026-02-04 13:03 ` Markus Armbruster
2026-02-04 13:12 ` Avihai Horon
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=aXoiAsGCWRv1nwW-@x1.local \
--to=peterx@redhat.com \
--cc=alex@shazbot.org \
--cc=armbru@redhat.com \
--cc=avihaih@nvidia.com \
--cc=clg@redhat.com \
--cc=eblake@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.