diff mbox series

[v2] hw/isa/piix4: Migrate Reset Control Register

Message ID 20210324192731.717142-1-f4bug@amsat.org (mailing list archive)
State New, archived
Headers show
Series [v2] hw/isa/piix4: Migrate Reset Control Register | expand

Commit Message

Philippe Mathieu-Daudé March 24, 2021, 7:27 p.m. UTC
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>
---
v2: Add piix4_ide_post_load() and describe
---
 hw/isa/piix4.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

Comments

Dr. David Alan Gilbert March 24, 2021, 7:40 p.m. UTC | #1
* 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>
> ---
> 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..e7bce0e590c 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(rcr, PIIX4State),

I don't think that looks right any more; you'd need to make that a 
   VMSTATE_UINT8_V(rcr, PIIX4State, 3),

I think, otherwise when you loaded a v2 it would still try
and read the rcr byte.

Dave

>          VMSTATE_END_OF_LIST()
>      }
>  };
> -- 
> 2.26.2
>
Philippe Mathieu-Daudé March 24, 2021, 8 p.m. UTC | #2
On 3/24/21 8:40 PM, Dr. David Alan Gilbert wrote:
> * 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>
>> ---
>> 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..e7bce0e590c 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(rcr, PIIX4State),
> 
> I don't think that looks right any more; you'd need to make that a 
>    VMSTATE_UINT8_V(rcr, PIIX4State, 3),
> 
> I think, otherwise when you loaded a v2 it would still try
> and read the rcr byte.

Ah now I guess I understood.

Thanks!
diff mbox series

Patch

diff --git a/hw/isa/piix4.c b/hw/isa/piix4.c
index a50d97834c7..e7bce0e590c 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(rcr, PIIX4State),
         VMSTATE_END_OF_LIST()
     }
 };