qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] hw/isa/piix4: Migrate Reset Control Register
@ 2021-03-24 20:03 Philippe Mathieu-Daudé
  2021-03-25 18:41 ` Dr. David Alan Gilbert
  0 siblings, 1 reply; 2+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-03-24 20:03 UTC (permalink / raw)
  To: qemu-devel
  Cc: Hervé Poussineau, Dr . David Alan Gilbert, Aurelien Jarno,
	Philippe Mathieu-Daudé

When adding the Reset register in commit 5790b757cfb we
forgot to migrate it.

While it is possible a VM using the PIIX4 is migrated just
after requesting a system shutdown, it is very unlikely.
However when restoring a migrated VM, we might have the
RCR bit #4 set on the stack and when the VM resume it
directly shutdowns.

Add a post_load() migration handler and set the default
RCR value to 0 for earlier versions, assuming the VM was
not going to shutdown before migration.

Fixes: 5790b757cfb ("piix4: Add the Reset Control Register")
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
v3: Use VMSTATE_UINT8_V (Dave)
v2: Add piix4_ide_post_load() and describe
---
 hw/isa/piix4.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/hw/isa/piix4.c b/hw/isa/piix4.c
index a50d97834c7..b3b6a4378a3 100644
--- a/hw/isa/piix4.c
+++ b/hw/isa/piix4.c
@@ -93,12 +93,25 @@ static void piix4_isa_reset(DeviceState *dev)
     pci_conf[0xae] = 0x00;
 }
 
+static int piix4_ide_post_load(void *opaque, int version_id)
+{
+    PIIX4State *s = opaque;
+
+    if (version_id == 2) {
+        s->rcr = 0;
+    }
+
+    return 0;
+}
+
 static const VMStateDescription vmstate_piix4 = {
     .name = "PIIX4",
-    .version_id = 2,
+    .version_id = 3,
     .minimum_version_id = 2,
+    .post_load = piix4_ide_post_load,
     .fields = (VMStateField[]) {
         VMSTATE_PCI_DEVICE(dev, PIIX4State),
+        VMSTATE_UINT8_V(rcr, PIIX4State, 3),
         VMSTATE_END_OF_LIST()
     }
 };
-- 
2.26.2



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

* Re: [PATCH v3] hw/isa/piix4: Migrate Reset Control Register
  2021-03-24 20:03 [PATCH v3] hw/isa/piix4: Migrate Reset Control Register Philippe Mathieu-Daudé
@ 2021-03-25 18:41 ` Dr. David Alan Gilbert
  0 siblings, 0 replies; 2+ messages in thread
From: Dr. David Alan Gilbert @ 2021-03-25 18:41 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Hervé Poussineau, qemu-devel, Aurelien Jarno

* Philippe Mathieu-Daudé (f4bug@amsat.org) wrote:
> When adding the Reset register in commit 5790b757cfb we
> forgot to migrate it.
> 
> While it is possible a VM using the PIIX4 is migrated just
> after requesting a system shutdown, it is very unlikely.
> However when restoring a migrated VM, we might have the
> RCR bit #4 set on the stack and when the VM resume it
> directly shutdowns.
> 
> Add a post_load() migration handler and set the default
> RCR value to 0 for earlier versions, assuming the VM was
> not going to shutdown before migration.
> 
> Fixes: 5790b757cfb ("piix4: Add the Reset Control Register")
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

Yep, that's better.

(Note you could also use a pre_load that might be a little simpler,
but not much in it).


Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

> ---
> v3: Use VMSTATE_UINT8_V (Dave)
> v2: Add piix4_ide_post_load() and describe
> ---
>  hw/isa/piix4.c | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/isa/piix4.c b/hw/isa/piix4.c
> index a50d97834c7..b3b6a4378a3 100644
> --- a/hw/isa/piix4.c
> +++ b/hw/isa/piix4.c
> @@ -93,12 +93,25 @@ static void piix4_isa_reset(DeviceState *dev)
>      pci_conf[0xae] = 0x00;
>  }
>  
> +static int piix4_ide_post_load(void *opaque, int version_id)
> +{
> +    PIIX4State *s = opaque;
> +
> +    if (version_id == 2) {
> +        s->rcr = 0;
> +    }
> +
> +    return 0;
> +}
> +
>  static const VMStateDescription vmstate_piix4 = {
>      .name = "PIIX4",
> -    .version_id = 2,
> +    .version_id = 3,
>      .minimum_version_id = 2,
> +    .post_load = piix4_ide_post_load,
>      .fields = (VMStateField[]) {
>          VMSTATE_PCI_DEVICE(dev, PIIX4State),
> +        VMSTATE_UINT8_V(rcr, PIIX4State, 3),
>          VMSTATE_END_OF_LIST()
>      }
>  };
> -- 
> 2.26.2
> 
-- 
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



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

end of thread, other threads:[~2021-03-25 18:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-24 20:03 [PATCH v3] hw/isa/piix4: Migrate Reset Control Register Philippe Mathieu-Daudé
2021-03-25 18:41 ` Dr. David Alan Gilbert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).