|
@@ -890,6 +890,9 @@ static uint64_t virtio_mem_get_features(VirtIODevice *vdev, uint64_t features,
|
|
|
if (vmem->unplugged_inaccessible == ON_OFF_AUTO_ON) {
|
|
|
virtio_add_feature(&features, VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE);
|
|
|
}
|
|
|
+ if (qemu_wakeup_suspend_enabled()) {
|
|
|
+ virtio_add_feature(&features, VIRTIO_MEM_F_PERSISTENT_SUSPEND);
|
|
|
+ }
|
|
|
return features;
|
|
|
}
|
|
|
|
|
@@ -902,18 +905,6 @@ static int virtio_mem_validate_features(VirtIODevice *vdev)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static void virtio_mem_system_reset(void *opaque)
|
|
|
-{
|
|
|
- VirtIOMEM *vmem = VIRTIO_MEM(opaque);
|
|
|
-
|
|
|
- /*
|
|
|
- * During usual resets, we will unplug all memory and shrink the usable
|
|
|
- * region size. This is, however, not possible in all scenarios. Then,
|
|
|
- * the guest has to deal with this manually (VIRTIO_MEM_REQ_UNPLUG_ALL).
|
|
|
- */
|
|
|
- virtio_mem_unplug_all(vmem);
|
|
|
-}
|
|
|
-
|
|
|
static void virtio_mem_prepare_mr(VirtIOMEM *vmem)
|
|
|
{
|
|
|
const uint64_t region_size = memory_region_size(&vmem->memdev->mr);
|
|
@@ -1130,7 +1121,7 @@ static void virtio_mem_device_realize(DeviceState *dev, Error **errp)
|
|
|
vmstate_register_any(VMSTATE_IF(vmem),
|
|
|
&vmstate_virtio_mem_device_early, vmem);
|
|
|
}
|
|
|
- qemu_register_reset(virtio_mem_system_reset, vmem);
|
|
|
+ qemu_register_resettable(OBJECT(vmem));
|
|
|
|
|
|
/*
|
|
|
* Set ourselves as RamDiscardManager before the plug handler maps the
|
|
@@ -1150,7 +1141,7 @@ static void virtio_mem_device_unrealize(DeviceState *dev)
|
|
|
* found via an address space anymore. Unset ourselves.
|
|
|
*/
|
|
|
memory_region_set_ram_discard_manager(&vmem->memdev->mr, NULL);
|
|
|
- qemu_unregister_reset(virtio_mem_system_reset, vmem);
|
|
|
+ qemu_unregister_resettable(OBJECT(vmem));
|
|
|
if (vmem->early_migration) {
|
|
|
vmstate_unregister(VMSTATE_IF(vmem), &vmstate_virtio_mem_device_early,
|
|
|
vmem);
|
|
@@ -1850,12 +1841,38 @@ static void virtio_mem_unplug_request_check(VirtIOMEM *vmem, Error **errp)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+static ResettableState *virtio_mem_get_reset_state(Object *obj)
|
|
|
+{
|
|
|
+ VirtIOMEM *vmem = VIRTIO_MEM(obj);
|
|
|
+ return &vmem->reset_state;
|
|
|
+}
|
|
|
+
|
|
|
+static void virtio_mem_system_reset_hold(Object *obj, ResetType type)
|
|
|
+{
|
|
|
+ VirtIOMEM *vmem = VIRTIO_MEM(obj);
|
|
|
+
|
|
|
+ /*
|
|
|
+ * When waking up from standby/suspend-to-ram, do not unplug any memory.
|
|
|
+ */
|
|
|
+ if (type == RESET_TYPE_WAKEUP) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * During usual resets, we will unplug all memory and shrink the usable
|
|
|
+ * region size. This is, however, not possible in all scenarios. Then,
|
|
|
+ * the guest has to deal with this manually (VIRTIO_MEM_REQ_UNPLUG_ALL).
|
|
|
+ */
|
|
|
+ virtio_mem_unplug_all(vmem);
|
|
|
+}
|
|
|
+
|
|
|
static void virtio_mem_class_init(ObjectClass *klass, void *data)
|
|
|
{
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
|
|
|
VirtIOMEMClass *vmc = VIRTIO_MEM_CLASS(klass);
|
|
|
RamDiscardManagerClass *rdmc = RAM_DISCARD_MANAGER_CLASS(klass);
|
|
|
+ ResettableClass *rc = RESETTABLE_CLASS(klass);
|
|
|
|
|
|
device_class_set_props(dc, virtio_mem_properties);
|
|
|
dc->vmsd = &vmstate_virtio_mem;
|
|
@@ -1882,6 +1899,9 @@ static void virtio_mem_class_init(ObjectClass *klass, void *data)
|
|
|
rdmc->replay_discarded = virtio_mem_rdm_replay_discarded;
|
|
|
rdmc->register_listener = virtio_mem_rdm_register_listener;
|
|
|
rdmc->unregister_listener = virtio_mem_rdm_unregister_listener;
|
|
|
+
|
|
|
+ rc->get_state = virtio_mem_get_reset_state;
|
|
|
+ rc->phases.hold = virtio_mem_system_reset_hold;
|
|
|
}
|
|
|
|
|
|
static const TypeInfo virtio_mem_info = {
|