diff --git a/include/hw/acpi/vmgenid.h b/include/hw/acpi/vmgenid.h index db7fa0e63303..a2ae450b1f56 100644 --- a/include/hw/acpi/vmgenid.h +++ b/include/hw/acpi/vmgenid.h @@ -4,6 +4,7 @@ #include "hw/acpi/bios-linker-loader.h" #include "hw/qdev.h" #include "qemu/uuid.h" +#include "sysemu/sysemu.h" #define VMGENID_DEVICE "vmgenid" #define VMGENID_GUID "guid" @@ -21,6 +22,7 @@ typedef struct VmGenIdState { DeviceClass parent_obj; QemuUUID guid; /* The 128-bit GUID seen by the guest */ uint8_t vmgenid_addr_le[8]; /* Address of the GUID (little-endian) */ + VMChangeStateEntry *vmstate; } VmGenIdState; static inline Object *find_vmgenid_dev(void) diff --git a/hw/acpi/vmgenid.c b/hw/acpi/vmgenid.c index 9f97b722761b..0ae1d56ff297 100644 --- a/hw/acpi/vmgenid.c +++ b/hw/acpi/vmgenid.c @@ -177,10 +177,20 @@ static void vmgenid_set_guid(Object *obj, const char *value, Error **errp) /* After restoring an image, we need to update the guest memory and notify * it of a potential change to VM Generation ID */ +static void postload_update_guest_cb(void *opaque, int running, RunState state) +{ + VmGenIdState *vms = opaque; + + qemu_del_vm_change_state_handler(vms->vmstate); + vms->vmstate = NULL; + vmgenid_update_guest(vms); +} + static int vmgenid_post_load(void *opaque, int version_id) { VmGenIdState *vms = opaque; - vmgenid_update_guest(vms); + vms->vmstate = qemu_add_vm_change_state_handler(postload_update_guest_cb, + vms); return 0; }