[PATCH] ramfb: implement migration support

marcandre.lureau@redhat.com posted 1 patch 7 months, 2 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20230920082651.3349712-1-marcandre.lureau@redhat.com
Maintainers: Gerd Hoffmann <kraxel@redhat.com>
hw/display/ramfb.c | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
[PATCH] ramfb: implement migration support
Posted by marcandre.lureau@redhat.com 7 months, 2 weeks ago
From: Marc-André Lureau <marcandre.lureau@redhat.com>

Implementing RAMFB migration seems quite straightforward. Unfortunately,
current QEMU didn't block migration when RAMFB was used.

Having an extra "ramfb" VMState doesn't seem to "break" migration
forward compatibility. Surprisingly, missing sections are being ignored?

Backward compatiblity however will have this extra error:
qemu: Unknown savevm section or instance 'ramfb' 0. Make sure that your current VM setup matches your saved VM setup, including any hotplugged devices.

Fixes:
https://bugzilla.redhat.com/show_bug.cgi?id=1859424

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 hw/display/ramfb.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/hw/display/ramfb.c b/hw/display/ramfb.c
index 1fe6a817cd..116d674348 100644
--- a/hw/display/ramfb.c
+++ b/hw/display/ramfb.c
@@ -12,6 +12,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "migration/vmstate.h"
 #include "qapi/error.h"
 #include "hw/loader.h"
 #include "hw/display/ramfb.h"
@@ -28,6 +29,8 @@ struct QEMU_PACKED RAMFBCfg {
     uint32_t stride;
 };
 
+typedef struct RAMFBCfg RAMFBCfg;
+
 struct RAMFBState {
     DisplaySurface *ds;
     uint32_t width, height;
@@ -116,6 +119,38 @@ void ramfb_display_update(QemuConsole *con, RAMFBState *s)
     dpy_gfx_update_full(con);
 }
 
+static int ramfb_post_load(void *opaque, int version_id)
+{
+    ramfb_fw_cfg_write(opaque, 0, 0);
+    return 0;
+}
+
+static const VMStateDescription vmstate_ramfb_cfg = {
+    .name = "ramfb-cfg",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .fields = (VMStateField[]) {
+        VMSTATE_UINT64(addr, RAMFBCfg),
+        VMSTATE_UINT32(fourcc, RAMFBCfg),
+        VMSTATE_UINT32(flags, RAMFBCfg),
+        VMSTATE_UINT32(width, RAMFBCfg),
+        VMSTATE_UINT32(height, RAMFBCfg),
+        VMSTATE_UINT32(stride, RAMFBCfg),
+        VMSTATE_END_OF_LIST()
+    },
+};
+
+static const VMStateDescription vmstate_ramfb = {
+    .name = "ramfb",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .post_load = ramfb_post_load,
+    .fields = (VMStateField[]) {
+        VMSTATE_STRUCT(cfg, RAMFBState, 0, vmstate_ramfb_cfg, RAMFBCfg),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 RAMFBState *ramfb_setup(Error **errp)
 {
     FWCfgState *fw_cfg = fw_cfg_find();
@@ -128,6 +163,7 @@ RAMFBState *ramfb_setup(Error **errp)
 
     s = g_new0(RAMFBState, 1);
 
+    vmstate_register(NULL, 0, &vmstate_ramfb, s);
     rom_add_vga("vgabios-ramfb.bin");
     fw_cfg_add_file_callback(fw_cfg, "etc/ramfb",
                              NULL, ramfb_fw_cfg_write, s,
-- 
2.41.0


Re: [PATCH] ramfb: implement migration support
Posted by Gerd Hoffmann 7 months ago
On Wed, Sep 20, 2023 at 12:26:51PM +0400, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> Implementing RAMFB migration seems quite straightforward. Unfortunately,
> current QEMU didn't block migration when RAMFB was used.
> 
> Having an extra "ramfb" VMState doesn't seem to "break" migration
> forward compatibility. Surprisingly, missing sections are being ignored?
> 
> Backward compatiblity however will have this extra error:
> qemu: Unknown savevm section or instance 'ramfb' 0. Make sure that your current VM setup matches your saved VM setup, including any hotplugged devices.

I guess that is only fixable by making old machine types bug-compatible,
i.e. register the ramfb vmstate only for qemu 8.2+ machine types.

Otherwise looks fine to me.

take care,
  Gerd