Fix VMSTATE_BUFFER_UNSAFE macro usage
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
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
@@ -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
PATCH 2/3 hw/sd.c: fix migration of dynamically allocated buffer "buf"
In reply to Igor MitsyankoVMSTATE_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
@@ -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
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_UNSAFEshould be used for buffers inlined in device state, not for buffers allocated dynamically. Change toVMSTATE_BUFFER_POINTER_UNSAFEmacro, which will do migration right.Signed-off-by Igor Mitsyanko <[email protected]>--- hw/sd.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)hw/sd.c +0
-0
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
PATCH 3/3 hw/onenand.c: fix migration of dynamically allocated buffer "otp"
In reply to Igor MitsyankoVMSTATE_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
@@ -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
Quoted 9 lines · Igor Mitsyanko
hw/sd.candhw/onenand.cwere wrongly usingVMSTATE_BUFFER_UNSAFEfor dynamically allocated buffer migration, this was causing memory corruption.
UseVMSTATE_BUFFER_POINTER_UNSAFE(wich has an additionalVMS_POINTERflag 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]
Quoted 14 lines · Peter Maydell
Quoted 13 lines · Igor Mitsyanko
Quoted 11 lines
hw/sd.candhw/onenand.cwere wrongly usingVMSTATE_BUFFER_UNSAFEfor dynamically
allocated buffer migration, this was causing memory corruption. UseVMSTATE_BUFFER_POINTER_UNSAFE(wich has an additionalVMS_POINTERflag 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.
Quoted 7 lines · Igor Mitsyanko
hw/sd.candhw/onenand.cwere wrongly usingVMSTATE_BUFFER_UNSAFEfor dynamically allocated buffer migration, this was causing memory corruption.
UseVMSTATE_BUFFER_POINTER_UNSAFE(wich has an additionalVMS_POINTERflag 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: introduceVMSTATE_BUFFER_POINTER_UNSAFEmacrohw/sd.c: fix migration of dynamically allocated buffer "buf"hw/onenand.c: fix migration of dynamically allocated buffer "otp"
Whole series:
-- PMM