All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] g364fb: fix migration (or: fix migration for MIPS magnum machines)
@ 2021-06-25 16:35 Mark Cave-Ayland
  2021-06-25 16:35 ` [PATCH v2 1/2] g364fb: use RAM memory region for framebuffer Mark Cave-Ayland
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Mark Cave-Ayland @ 2021-06-25 16:35 UTC (permalink / raw)
  To: qemu-devel, f4bug, aurelien, jiaxun.yang, aleksandar.rikalo,
	hpoussin, fthain

I noticed whilst testing the previous dp8393x patchset that I would always
get a segfault whilst attempting to migrate the MIPS magnum machine.

A bit of detective work shows that the problem is an incorrect VMStateDescription
in the g364fb device which expects a G364State but instead receives a
G364SysBusState.

Looking back through the git history suggests that migration for this device
(and also the MIPS magnum machines) has been broken for several years, so patch
1 takes the opportunity to improve the migration stream for the framebuffer
first whilst patch 2 contains the actual fix.

Note that I don't use the MIPS magnum machines on a regular basis but the
patchset fixes the migration error and survives some light testing here.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>


v2:
- Bump migration version to 2 as suggested by Phil (note: I've done this in
  both patch 1 and patch 2 to keep the versions identical)
- Remove unused vram pointer from G364State in patch 1
- Added R-B tag from Phil


Mark Cave-Ayland (2):
  g364fb: use RAM memory region for framebuffer
  g364fb: add VMStateDescription for G364SysBusState

 hw/display/g364fb.c | 32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)

-- 
2.20.1



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/2] g364fb: use RAM memory region for framebuffer
  2021-06-25 16:35 [PATCH v2 0/2] g364fb: fix migration (or: fix migration for MIPS magnum machines) Mark Cave-Ayland
@ 2021-06-25 16:35 ` Mark Cave-Ayland
  2021-06-25 16:35 ` [PATCH v2 2/2] g364fb: add VMStateDescription for G364SysBusState Mark Cave-Ayland
  2021-07-02 13:30 ` [PATCH v2 0/2] g364fb: fix migration (or: fix migration for MIPS magnum machines) Philippe Mathieu-Daudé
  2 siblings, 0 replies; 5+ messages in thread
From: Mark Cave-Ayland @ 2021-06-25 16:35 UTC (permalink / raw)
  To: qemu-devel, f4bug, aurelien, jiaxun.yang, aleksandar.rikalo,
	hpoussin, fthain

Since the migration stream is already broken, we can use this opportunity to
change the framebuffer so that it is migrated as a RAM memory region rather
than as an array of bytes.

In particular this helps the output of the analyze-migration.py tool which
no longer contains a huge array representing the framebuffer contents.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/display/g364fb.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/hw/display/g364fb.c b/hw/display/g364fb.c
index 8f1725432c..87effbf2b0 100644
--- a/hw/display/g364fb.c
+++ b/hw/display/g364fb.c
@@ -22,6 +22,7 @@
 #include "hw/hw.h"
 #include "hw/irq.h"
 #include "hw/qdev-properties.h"
+#include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "qemu/module.h"
 #include "ui/console.h"
@@ -33,7 +34,6 @@
 
 typedef struct G364State {
     /* hardware */
-    uint8_t *vram;
     uint32_t vram_size;
     qemu_irq irq;
     MemoryRegion mem_vram;
@@ -125,7 +125,7 @@ static void g364fb_draw_graphic8(G364State *s)
         xcursor = ycursor = -65;
     }
 
-    vram = s->vram + s->top_of_screen;
+    vram = memory_region_get_ram_ptr(&s->mem_vram) + s->top_of_screen;
     /* XXX: out of range in vram? */
     data_display = dd = surface_data(surface);
     snap = memory_region_snapshot_and_clear_dirty(&s->mem_vram, 0, s->vram_size,
@@ -274,6 +274,8 @@ static inline void g364fb_invalidate_display(void *opaque)
 
 static void g364fb_reset(G364State *s)
 {
+    uint8_t *vram = memory_region_get_ram_ptr(&s->mem_vram);
+
     qemu_irq_lower(s->irq);
 
     memset(s->color_palette, 0, sizeof(s->color_palette));
@@ -283,7 +285,7 @@ static void g364fb_reset(G364State *s)
     s->ctla = 0;
     s->top_of_screen = 0;
     s->width = s->height = 0;
-    memset(s->vram, 0, s->vram_size);
+    memset(vram, 0, s->vram_size);
     g364fb_invalidate_display(s);
 }
 
@@ -450,11 +452,10 @@ static int g364fb_post_load(void *opaque, int version_id)
 
 static const VMStateDescription vmstate_g364fb = {
     .name = "g364fb",
-    .version_id = 1,
-    .minimum_version_id = 1,
+    .version_id = 2,
+    .minimum_version_id = 2,
     .post_load = g364fb_post_load,
     .fields = (VMStateField[]) {
-        VMSTATE_VBUFFER_UINT32(vram, G364State, 1, NULL, vram_size),
         VMSTATE_BUFFER_UNSAFE(color_palette, G364State, 0, 256 * 3),
         VMSTATE_BUFFER_UNSAFE(cursor_palette, G364State, 0, 9),
         VMSTATE_UINT16_ARRAY(cursor, G364State, 512),
@@ -474,15 +475,12 @@ static const GraphicHwOps g364fb_ops = {
 
 static void g364fb_init(DeviceState *dev, G364State *s)
 {
-    s->vram = g_malloc0(s->vram_size);
-
     s->con = graphic_console_init(dev, 0, &g364fb_ops, s);
 
     memory_region_init_io(&s->mem_ctrl, OBJECT(dev), &g364fb_ctrl_ops, s,
                           "ctrl", 0x180000);
-    memory_region_init_ram_ptr(&s->mem_vram, NULL, "vram",
-                               s->vram_size, s->vram);
-    vmstate_register_ram(&s->mem_vram, dev);
+    memory_region_init_ram(&s->mem_vram, NULL, "g364fb.vram", s->vram_size,
+                           &error_fatal);
     memory_region_set_log(&s->mem_vram, true, DIRTY_MEMORY_VGA);
 }
 
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/2] g364fb: add VMStateDescription for G364SysBusState
  2021-06-25 16:35 [PATCH v2 0/2] g364fb: fix migration (or: fix migration for MIPS magnum machines) Mark Cave-Ayland
  2021-06-25 16:35 ` [PATCH v2 1/2] g364fb: use RAM memory region for framebuffer Mark Cave-Ayland
@ 2021-06-25 16:35 ` Mark Cave-Ayland
  2021-06-25 17:04   ` Philippe Mathieu-Daudé
  2021-07-02 13:30 ` [PATCH v2 0/2] g364fb: fix migration (or: fix migration for MIPS magnum machines) Philippe Mathieu-Daudé
  2 siblings, 1 reply; 5+ messages in thread
From: Mark Cave-Ayland @ 2021-06-25 16:35 UTC (permalink / raw)
  To: qemu-devel, f4bug, aurelien, jiaxun.yang, aleksandar.rikalo,
	hpoussin, fthain

Currently when QEMU attempts to migrate the MIPS magnum machine it crashes due
to a mistake in the g364fb VMStateDescription configuration which expects a
G364SysBusState and not a G364State.

Resolve the issue by adding a new VMStateDescription for G364SysBusState and
embedding the existing vmstate_g364fb VMStateDescription inside it using
VMSTATE_STRUCT.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Fixes: 97a3f6ffbba ("g364fb: convert to qdev")
---
 hw/display/g364fb.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/hw/display/g364fb.c b/hw/display/g364fb.c
index 87effbf2b0..caca86d773 100644
--- a/hw/display/g364fb.c
+++ b/hw/display/g364fb.c
@@ -517,6 +517,16 @@ static Property g364fb_sysbus_properties[] = {
     DEFINE_PROP_END_OF_LIST(),
 };
 
+static const VMStateDescription vmstate_g364fb_sysbus = {
+    .name = "g364fb-sysbus",
+    .version_id = 2,
+    .minimum_version_id = 2,
+    .fields = (VMStateField[]) {
+        VMSTATE_STRUCT(g364, G364SysBusState, 2, vmstate_g364fb, G364State),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 static void g364fb_sysbus_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -525,7 +535,7 @@ static void g364fb_sysbus_class_init(ObjectClass *klass, void *data)
     set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
     dc->desc = "G364 framebuffer";
     dc->reset = g364fb_sysbus_reset;
-    dc->vmsd = &vmstate_g364fb;
+    dc->vmsd = &vmstate_g364fb_sysbus;
     device_class_set_props(dc, g364fb_sysbus_properties);
 }
 
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 2/2] g364fb: add VMStateDescription for G364SysBusState
  2021-06-25 16:35 ` [PATCH v2 2/2] g364fb: add VMStateDescription for G364SysBusState Mark Cave-Ayland
@ 2021-06-25 17:04   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-06-25 17:04 UTC (permalink / raw)
  To: Mark Cave-Ayland, qemu-devel, aurelien, jiaxun.yang,
	aleksandar.rikalo, hpoussin, fthain

On 6/25/21 6:35 PM, Mark Cave-Ayland wrote:
> Currently when QEMU attempts to migrate the MIPS magnum machine it crashes due
> to a mistake in the g364fb VMStateDescription configuration which expects a
> G364SysBusState and not a G364State.
> 
> Resolve the issue by adding a new VMStateDescription for G364SysBusState and
> embedding the existing vmstate_g364fb VMStateDescription inside it using
> VMSTATE_STRUCT.
> 
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> Fixes: 97a3f6ffbba ("g364fb: convert to qdev")
> ---
>  hw/display/g364fb.c | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 0/2] g364fb: fix migration (or: fix migration for MIPS magnum machines)
  2021-06-25 16:35 [PATCH v2 0/2] g364fb: fix migration (or: fix migration for MIPS magnum machines) Mark Cave-Ayland
  2021-06-25 16:35 ` [PATCH v2 1/2] g364fb: use RAM memory region for framebuffer Mark Cave-Ayland
  2021-06-25 16:35 ` [PATCH v2 2/2] g364fb: add VMStateDescription for G364SysBusState Mark Cave-Ayland
@ 2021-07-02 13:30 ` Philippe Mathieu-Daudé
  2 siblings, 0 replies; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-07-02 13:30 UTC (permalink / raw)
  To: Mark Cave-Ayland, qemu-devel, aurelien, jiaxun.yang,
	aleksandar.rikalo, hpoussin, fthain

On 6/25/21 6:35 PM, Mark Cave-Ayland wrote:
> I noticed whilst testing the previous dp8393x patchset that I would always
> get a segfault whilst attempting to migrate the MIPS magnum machine.
> 
> A bit of detective work shows that the problem is an incorrect VMStateDescription
> in the g364fb device which expects a G364State but instead receives a
> G364SysBusState.
> 
> Looking back through the git history suggests that migration for this device
> (and also the MIPS magnum machines) has been broken for several years, so patch
> 1 takes the opportunity to improve the migration stream for the framebuffer
> first whilst patch 2 contains the actual fix.
> 
> Note that I don't use the MIPS magnum machines on a regular basis but the
> patchset fixes the migration error and survives some light testing here.

> Mark Cave-Ayland (2):
>   g364fb: use RAM memory region for framebuffer
>   g364fb: add VMStateDescription for G364SysBusState
> 
>  hw/display/g364fb.c | 32 ++++++++++++++++++++------------
>  1 file changed, 20 insertions(+), 12 deletions(-)

Thanks, queued to mips-next.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-07-02 13:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-25 16:35 [PATCH v2 0/2] g364fb: fix migration (or: fix migration for MIPS magnum machines) Mark Cave-Ayland
2021-06-25 16:35 ` [PATCH v2 1/2] g364fb: use RAM memory region for framebuffer Mark Cave-Ayland
2021-06-25 16:35 ` [PATCH v2 2/2] g364fb: add VMStateDescription for G364SysBusState Mark Cave-Ayland
2021-06-25 17:04   ` Philippe Mathieu-Daudé
2021-07-02 13:30 ` [PATCH v2 0/2] g364fb: fix migration (or: fix migration for MIPS magnum machines) Philippe Mathieu-Daudé

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.