public inbox for qemu-devel@nongnu.org
 help / color / mirror / Atom feed
From: Jonah Palmer <jonah.palmer@oracle.com>
To: Eugenio Perez Martin <eperezma@redhat.com>
Cc: qemu-devel@nongnu.org, eduardo@habkost.net,
	marcel.apfelbaum@gmail.com, philmd@linaro.org,
	wangyanan55@huawei.com, zhao1.liu@intel.com, mst@redhat.com,
	sgarzare@redhat.com, jasowang@redhat.com, leiyang@redhat.com,
	si-wei.liu@oracle.com, boris.ostrovsky@oracle.com,
	armbru@redhat.com, Juraj Marcin <jmarcin@redhat.com>
Subject: Re: [RFC v2 04/14] virtio-net: detect VirtIODevice status mid-migration change
Date: Tue, 24 Mar 2026 11:01:32 -0400	[thread overview]
Message-ID: <654f2356-9c78-45df-95ff-de103557948b@oracle.com> (raw)
In-Reply-To: <CAJaqyWfkLCu2RRGaJZdcqG0c3uZH0jWmmTmN23F=Bz-Hfm4KOg@mail.gmail.com>



On 3/24/26 6:45 AM, Eugenio Perez Martin wrote:
> On Fri, Mar 20, 2026 at 3:20 PM Jonah Palmer <jonah.palmer@oracle.com> wrote:
>>
>> This patch introduces the mechanism in which this series will use to
>> detect VirtIODevice & VirtIONet state deltas, starting with the
>> VirtIODevice's 'status' member of a virtio-net device.
>>
>> Before we send the device's state early, we save each piece of its state
>> in a temporary structure via virtio_net_early_pre_save. Later, once the
>> source VM has been paused,
> 
> While I ack this approach should cover 99% of cases—as I think it is
> unlikely the guest changes device properties during a live migration—I
> still believe these changes should be sent when the guest modifies the
> property, before it is paused. That way we shrink the downtime even
> more. This comparison fits naturally: Instead of sending one state and
> then the deltas at the switchover, we send the state and then the
> delta for every change.
> 
> However, I'm happy enough with this approach because it is more
> self-contained within the migration code. It also reduces the state
> sent over the migration channel if the guest changes its device status
> many times.
> 
> CCing Juraj as we discussed this at the virtio-net upstream meeting.
> 

Right. I agree it would be optimal that, for every change made during 
live migration, the destination is updated with this change and it's not 
left to be handled once the source has been paused, which would impact 
guest-visible downtime (especially if it's an expensive change).

However, the only way to handle mid-migration changes like this is via 
the SaveVMHandlers framework. I did give a stab at this approach in my 
v1 RFC series: 
https://lore.kernel.org/qemu-devel/20250722124127.2497406-1-jonah.palmer@oracle.com/

However, Peter believed that this early-migration work would be better 
suited using the VMStateDescription framework instead. And the VMSD 
framework does not support handling these mid-migration changes before 
the stop-and-copy phase.

>> we compare the current values of those pieces
>> to what we saved earlier. If any mismatch is found, virtio-net's VMSD
>> (vmstate_virtio_net) is enabled and resends all state and device prep
>> work (as it's normally done today when live migrating a virtio-net
>> device).
>>
>> Once all relevant delta checks are in place, a no-delta case will skip
>> vmstate_virtio_net and only resend updated VQ indices.
>>
>> For this patch, keep a temporary always-true fallback in
>> virtio_net_has_delta/virtio_net_needed until follow-up patches cover the
>> remaining VirtIONet & VirtIODevice deltas.
>>
>> Signed-off-by: Jonah Palmer <jonah.palmer@oracle.com>
>> ---
>>   hw/net/virtio-net.c        | 40 ++++++++++++++++++++++++++++++++++++++
>>   include/hw/virtio/virtio.h |  2 ++
>>   2 files changed, 42 insertions(+)
>>
>> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
>> index 5d71ad235e..2733e0130c 100644
>> --- a/hw/net/virtio-net.c
>> +++ b/hw/net/virtio-net.c
>> @@ -3864,6 +3864,16 @@ static bool failover_hide_primary_device(DeviceListener *listener,
>>       return qatomic_read(&n->failover_primary_hidden);
>>   }
>>
>> +static int virtio_net_early_pre_save(void *opaque)
>> +{
>> +    VirtIONet *n = opaque;
>> +    VirtIODevice *vdev = VIRTIO_DEVICE(n);
>> +    VirtIODevMigration *vdev_mig = vdev->migration;
>> +
>> +    vdev_mig->status_early = vdev->status;
>> +    return 0;
>> +}
>> +
>>   static int virtio_net_early_pre_load(void *opaque)
>>   {
>>       VirtIONet *n = opaque;
>> @@ -3887,6 +3897,7 @@ static const VMStateDescription vmstate_virtio_net_early = {
>>       .minimum_version_id = VIRTIO_NET_VM_VERSION,
>>       .version_id = VIRTIO_NET_VM_VERSION,
>>       .early_setup = true,
>> +    .pre_save = virtio_net_early_pre_save,
>>       .pre_load = virtio_net_early_pre_load,
>>       .post_load = virtio_net_early_post_load,
>>       .fields = (const VMStateField[]) {
>> @@ -4231,10 +4242,39 @@ static bool dev_unplug_pending(void *opaque)
>>       return vdc->primary_unplug_pending(dev);
>>   }
>>
>> +static bool virtio_net_has_delta(VirtIONet *n, VirtIODevice *vdev)
>> +{
>> +    VirtIODevMigration *vdev_mig = vdev->migration;
>> +
>> +    /* Has the VirtIODevice's status changed? */
>> +    if (vdev->status != vdev_mig->status_early) {
>> +        return true;
>> +    }
> 
> To clarify my point, I think we should add something like this:
> 
> if (vdev->status != status) {
>    // process it.
>    virtio_send_status_update_to_destination()
> }
> 
> At virtio_net_set_status, or similar.
> 

See comment above.

>> +
>> +    /*
>> +     * Always return true for now until we're able to detect all possible
>> +     * changes to a VirtIONet device.
>> +     */
>> +    return true;
>> +}
>> +
>> +static bool virtio_net_needed(void *opaque)
>> +{
>> +    VirtIONet *n = opaque;
>> +    VirtIODevice *vdev = VIRTIO_DEVICE(n);
>> +
>> +    if (!n->early_mig) {
>> +        return true;
>> +    }
>> +
>> +    return virtio_net_has_delta(n, vdev);
>> +}
>> +
>>   static const VMStateDescription vmstate_virtio_net = {
>>       .name = "virtio-net",
>>       .minimum_version_id = VIRTIO_NET_VM_VERSION,
>>       .version_id = VIRTIO_NET_VM_VERSION,
>> +    .needed = virtio_net_needed,
>>       .fields = (const VMStateField[]) {
>>           VMSTATE_VIRTIO_DEVICE,
>>           VMSTATE_END_OF_LIST()
>> diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
>> index 74fed8c324..752c46ce53 100644
>> --- a/include/hw/virtio/virtio.h
>> +++ b/include/hw/virtio/virtio.h
>> @@ -102,9 +102,11 @@ enum virtio_device_endian {
>>   /**
>>    * struct VirtIODevMigration - Common VirtIODevice migration structure
>>    * @early_load: Flag to indicate an early virtio_load for the device.
>> + * @status_early: Device status at the time it was sent early.
>>    */
>>   typedef struct VirtIODevMigration {
>>       bool early_load;
>> +    uint8_t status_early;
>>   } VirtIODevMigration;
>>
>>   /**
>> --
>> 2.51.0
>>
> 



  reply	other threads:[~2026-03-24 15:02 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-20 14:20 [RFC v2 00/14] virtio-net: early VMStateDescription live migration support Jonah Palmer
2026-03-20 14:20 ` [RFC v2 01/14] machine,virtio-net: add early-mig property Jonah Palmer
2026-03-23 10:25   ` Eugenio Perez Martin
2026-03-24 14:07     ` Jonah Palmer
2026-03-26  8:02       ` Eugenio Perez Martin
2026-03-20 14:20 ` [RFC v2 02/14] virtio, virtio-net: add initial early VMSD for setup-phase migration Jonah Palmer via qemu development
2026-03-24  9:27   ` [RFC v2 02/14] virtio,virtio-net: " Eugenio Perez Martin
2026-03-24 14:28     ` Jonah Palmer
2026-03-24 14:38       ` Eugenio Perez Martin
2026-03-24 17:16         ` Jonah Palmer
2026-03-20 14:20 ` [RFC v2 03/14] virtio,virtio-net: virtio-delta VMSD - VQ state Jonah Palmer
2026-03-20 14:20 ` [RFC v2 04/14] virtio-net: detect VirtIODevice status mid-migration change Jonah Palmer
2026-03-24 10:45   ` Eugenio Perez Martin
2026-03-24 15:01     ` Jonah Palmer [this message]
2026-03-26 10:08       ` Eugenio Perez Martin
2026-03-20 14:20 ` [RFC v2 05/14] virtio-net: detect VirtIODevice config buffer " Jonah Palmer
2026-03-24 10:48   ` Eugenio Perez Martin
2026-03-24 15:25     ` Jonah Palmer
2026-03-20 14:20 ` [RFC v2 06/14] virtio-net: detect VirtIONet MAC addr " Jonah Palmer
2026-03-20 14:20 ` [RFC v2 07/14] virtio-net: detect VirtIONet MAC table mid-migration changes Jonah Palmer
2026-03-20 14:20 ` [RFC v2 08/14] virtio-net: detect VirtIONet status mid-migration change Jonah Palmer
2026-03-24 11:26   ` Eugenio Perez Martin
2026-03-24 16:23     ` Jonah Palmer
2026-03-26 10:20       ` Eugenio Perez Martin
2026-03-20 14:20 ` [RFC v2 09/14] virtio-net: detect VirtIONet Rx filter mid-migration changes Jonah Palmer
2026-03-20 14:20 ` [RFC v2 10/14] virtio-net: detect VirtIONet VLAN filter table changes Jonah Palmer
2026-03-20 14:20 ` [RFC v2 11/14] virtio-net: detect VirtIONet guest offload & MQ mid-migration changes Jonah Palmer
2026-03-20 14:20 ` [RFC v2 12/14] virtio-net: detect RSS state " Jonah Palmer
2026-03-20 14:20 ` [RFC v2 13/14] virtio-net: detect pending Tx work for VQs " Jonah Palmer
2026-03-24 11:35   ` Eugenio Perez Martin
2026-03-24 16:47     ` Jonah Palmer
2026-03-26 10:30       ` Eugenio Perez Martin
2026-03-20 14:20 ` [RFC v2 14/14] virtio-net, vhost-net: early migration support for vhost-net Jonah Palmer via qemu development

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=654f2356-9c78-45df-95ff-de103557948b@oracle.com \
    --to=jonah.palmer@oracle.com \
    --cc=armbru@redhat.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=eduardo@habkost.net \
    --cc=eperezma@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=jmarcin@redhat.com \
    --cc=leiyang@redhat.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=mst@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=sgarzare@redhat.com \
    --cc=si-wei.liu@oracle.com \
    --cc=wangyanan55@huawei.com \
    --cc=zhao1.liu@intel.com \
    /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