Skip to contentSkip to conversation

Fix VMSTATE_BUFFER_UNSAFE macro usage

PATCH In review Igor Mitsyanko 3 participants 8 messages Mar 10, 2013 – Mar 18, 2013 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

cover Fix VMSTATE_BUFFER_UNSAFE macro usage

hw/sd.c and hw/onenand.c were wrongly using VMSTATE_BUFFER_UNSAFE for dynamically allocated buffer migration, this was causing memory corruption.
Use VMSTATE_BUFFER_POINTER_UNSAFE (wich has an additional VMS_POINTER flag set) instead.

Not sure what to do with vmstate version for his devices, should I bump it? Migration was never working for them anyway.

Only tested hw/sd.c, by saving/loading a snapshot of VM while it was playing videofile from SD card.

Igor Mitsyanko (3):
vmstate.h: introduce VMSTATE_BUFFER_POINTER_UNSAFE macro hw/sd.c: fix migration of dynamically allocated buffer "buf" hw/onenand.c: fix migration of dynamically allocated buffer "otp"

 hw/onenand.c                |    3 ++-
 hw/sd.c                     |    2 +-
 include/migration/vmstate.h |    9 +++++++++
 3 files changed, 12 insertions(+), 2 deletions(-)
Signature · 1 line
1.7.5.4
#1 lore raw

PATCH 1/3 vmstate.h: introduce VMSTATE_BUFFER_POINTER_UNSAFE macro

Macro could be used to migrate a dynamically allocated buffer of known size.

---
 include/migration/vmstate.h |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
include/migration/vmstate.h +9 -0
index f27276c..e127ed8 100644
@@ -404,6 +404,15 @@ extern const VMStateInfo vmstate_info_bitmap;
     .offset     = offsetof(_state, _field),                          \
 }
 
+#define VMSTATE_BUFFER_POINTER_UNSAFE(_field, _state, _version, _size) { \
+    .name       = (stringify(_field)),                               \
+    .version_id = (_version),                                        \
+    .size       = (_size),                                           \
+    .info       = &vmstate_info_buffer,                              \
+    .flags      = VMS_BUFFER|VMS_POINTER,                            \
+    .offset     = offsetof(_state, _field),                          \
+}
+
 #define VMSTATE_UNUSED_BUFFER(_test, _version, _size) {              \
     .name         = "unused",                                        \
     .field_exists = (_test),                                         \
Signature · 1 line
1.7.5.4
#2 lore raw

PATCH 2/3 hw/sd.c: fix migration of dynamically allocated buffer "buf"

In reply to Igor Mitsyanko

VMSTATE_BUFFER_UNSAFE should be used for buffers inlined in device state, not for buffers allocated dynamically. Change to VMSTATE_BUFFER_POINTER_UNSAFE macro, which will do migration right.

---
 hw/sd.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/sd.c +1 -1
index 428bd78..88eaaf8 100644
@@ -478,7 +478,7 @@ static const VMStateDescription sd_vmstate = {
         VMSTATE_UINT64(data_start, SDState),
         VMSTATE_UINT32(data_offset, SDState),
         VMSTATE_UINT8_ARRAY(data, SDState, 512),
-        VMSTATE_BUFFER_UNSAFE(buf, SDState, 1, 512),
+        VMSTATE_BUFFER_POINTER_UNSAFE(buf, SDState, 1, 512),
         VMSTATE_BOOL(enable, SDState),
         VMSTATE_END_OF_LIST()
     }
Signature · 1 line
1.7.5.4
Tested-by on v1 2/3
#3 lore raw

Re: [Qemu-devel] [PATCH 2/3] hw/sd.c: fix migration of dynamically allocated buffer "buf"

Am Sonntag 10 März 2013, 14:47:57 schrieb Igor Mitsyanko:

Quoted 14 lines

VMSTATE_BUFFER_UNSAFE should be used for buffers inlined in device state, not for buffers allocated dynamically. Change to VMSTATE_BUFFER_POINTER_UNSAFE macro, which will do migration right.

---
 hw/sd.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/sd.c +0 -0
index 428bd78..88eaaf8 100644

hw/sd.c static const VMStateDescription sd_vmstate = { · line 484

Quoted 8 lines
hw/sd.c +1 -1
@@ -478,7 +478,7 @@ static const VMStateDescription sd_vmstate = {
         VMSTATE_UINT64(data_start, SDState),
         VMSTATE_UINT32(data_offset, SDState),
         VMSTATE_UINT8_ARRAY(data, SDState, 512),
-        VMSTATE_BUFFER_UNSAFE(buf, SDState, 1, 512),
+        VMSTATE_BUFFER_POINTER_UNSAFE(buf, SDState, 1, 512),
         VMSTATE_BOOL(enable, SDState),
         VMSTATE_END_OF_LIST()
     }
Signature · 1 line
michael
#4 lore raw

PATCH 3/3 hw/onenand.c: fix migration of dynamically allocated buffer "otp"

In reply to Igor Mitsyanko

VMSTATE_BUFFER_UNSAFE should be used for buffers inlined in device state, not for buffers allocated dynamically. Change to VMSTATE_BUFFER_POINTER_UNSAFE macro, which will do migration right.

---
 hw/onenand.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
hw/onenand.c +2 -1
index 00a8738..12ccb67f 100644
@@ -185,7 +185,8 @@ static const VMStateDescription vmstate_onenand = {
         VMSTATE_UINT8(ecc.cp, OneNANDState),
         VMSTATE_UINT16_ARRAY(ecc.lp, OneNANDState, 2),
         VMSTATE_UINT16(ecc.count, OneNANDState),
-        VMSTATE_BUFFER_UNSAFE(otp, OneNANDState, 0, ((64 + 2) << PAGE_SHIFT)),
+        VMSTATE_BUFFER_POINTER_UNSAFE(otp, OneNANDState, 0,
+            ((64 + 2) << PAGE_SHIFT)),
         VMSTATE_END_OF_LIST()
     }
 };
Signature · 1 line
1.7.5.4
#5 lore raw
In reply to Igor Mitsyanko
Quoted 9 lines · Igor Mitsyanko

hw/sd.c and hw/onenand.c were wrongly using VMSTATE_BUFFER_UNSAFE for dynamically allocated buffer migration, this was causing memory corruption.
Use VMSTATE_BUFFER_POINTER_UNSAFE (wich has an additional VMS_POINTER flag set) instead.

Not sure what to do with vmstate version for his devices, should I bump it? Migration was never working for them anyway.

Only tested hw/sd.c, by saving/loading a snapshot of VM while it was playing videofile from SD card.

Cc'ing Juan in case he wants to comment on the vmstate changes.

-- PMM

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw
Quoted 14 lines · Peter Maydell
Quoted 13 lines · Igor Mitsyanko
Quoted 11 lines

hw/sd.c and hw/onenand.c were wrongly using VMSTATE_BUFFER_UNSAFE for dynamically
allocated buffer migration, this was causing memory corruption. Use VMSTATE_BUFFER_POINTER_UNSAFE (wich has an additional VMS_POINTER flag set) instead.

Not sure what to do with vmstate version for his devices, should I bump it? Migration
was never working for them anyway.

Quoted 9 lines
Quoted 8 lines
Quoted 4 lines

Only tested hw/sd.c, by saving/loading a snapshot of VM while it was playing videofile
from SD card.

Cc'ing Juan in case he wants to comment on the vmstate changes.

-- PMM

Thanks, Peter. Also cc'ing Andrzej Zaborowski using a (correct) address from MAINTAINERS, because the one in hw/onenand.c is not working.

Reviewed-by on the v1 series
#8 lore raw
In reply to Igor Mitsyanko
Quoted 7 lines · Igor Mitsyanko

hw/sd.c and hw/onenand.c were wrongly using VMSTATE_BUFFER_UNSAFE for dynamically allocated buffer migration, this was causing memory corruption.
Use VMSTATE_BUFFER_POINTER_UNSAFE (wich has an additional VMS_POINTER flag set) instead.

Not sure what to do with vmstate version for his devices, should I bump it? Migration was never working for them anyway.

Quoted 7 lines

Only tested hw/sd.c, by saving/loading a snapshot of VM while it was playing videofile from SD card.

Igor Mitsyanko (3):
vmstate.h: introduce VMSTATE_BUFFER_POINTER_UNSAFE macro hw/sd.c: fix migration of dynamically allocated buffer "buf" hw/onenand.c: fix migration of dynamically allocated buffer "otp"

Whole series:

-- PMM