Fill gaps in savevm support
cover Fill gaps in savevm support
This is a series of fairly straightforward patches to fix some fairly obvious gaps in the set of helpers for VMStateDescription buffers. These just extend existing practice to some data types that didn't yet have helper functions, presumably because there were not yet any users.
I have draft savevm support for the pseries machine in the works which need the various extensions here.
PATCH 1/6 savevm: Add VMSTATE_UINT64_EQUAL helpers
The savevm code already includes a number of *_EQUAL helpers which act as sanity checks verifying that the configuration of the saved state matches that of the machine we're loading into to work. Variants already exist for 8 bit 16 bit and 32 bit integers, but not 64 bit integers. This patch fills that hole, adding a UINT64 version.
--- savevm.c | 20 ++++++++++++++++++++ vmstate.h | 7 +++++++ 2 files changed, 27 insertions(+)
savevm.c +20 -0
@@ -1043,6 +1043,26 @@ const VMStateInfo vmstate_info_uint64 = { .put = put_uint64, }; +/* 64 bit unsigned int. See that the received value is the same than the one +in the field */ + +static int get_uint64_equal (QEMUFile *f,void *pv,size_t size) +{ +uint64_t *v = pv; +uint64_t v2; +qemu_get_be64s (f, &v2); + +if (*v == v2) +return 0 ; +return -EINVAL ; +} + +const VMStateInfo vmstate_info_uint64_equal = { + .name ="int64 equal" , + .get = get_uint64_equal, + .put = put_uint64, +}; +/* 8 bit int. See that the received value is the same than the one in the field */
vmstate.h +7 -0
@@ -129,6 +129,7 @@ extern const VMStateInfo vmstate_info_uint8_equal;extern const VMStateInfo vmstate_info_uint16_equal;extern const VMStateInfo vmstate_info_int32_equal;extern const VMStateInfo vmstate_info_uint32_equal; +extern const VMStateInfo vmstate_info_uint64_equal;extern const VMStateInfo vmstate_info_int32_le;extern const VMStateInfo vmstate_info_uint8;
@@ -488,6 +489,12 @@ extern const VMStateInfo vmstate_info_unused_buffer;#define VMSTATE_UINT32_EQUAL (_f, _s) \ VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint32_equal, uint32_t) +#define VMSTATE_UINT64_EQUAL_V (_f, _s, _v) \ + VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64_equal, uint64_t) + +#define VMSTATE_UINT64_EQUAL (_f, _s) \ + VMSTATE_UINT64_EQUAL_V(_f, _s, 0) +#define VMSTATE_INT32_LE (_f, _s) \ VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t)
Signature · 1 line
1.7.10.4
Re: [Qemu-devel] [PATCH 1/6] savevm: Add VMSTATE_UINT64_EQUAL helpers
Quoted 20 lines · David Gibson
The savevm code already includes a number of
*_EQUALhelpers which act as sanity checks verifying that the configuration of the saved state matches that of the machine we're loading into to work. Variants already exist for 8 bit 16 bit and 32 bit integers, but not 64 bit integers. This patch fills that hole, adding a UINT64 version.Signed-off-by David Gibson <[email protected]>--- savevm.c | 20 ++++++++++++++++++++ vmstate.h | 7 +++++++ 2 files changed, 27 insertions(+)savevm.c +0
-0@@ -1043,6 +1043,26 @@ const VMStateInfo vmstate_info_uint64 = { .put = put_uint64, };
savevm.c const VMStateInfo vmstate_info_uint64 = { · line 1055
Quoted 10 lines
savevm.c +10
-0+/* 64 bit unsigned int. See that the received value is the same than the one +in the field */ + +static int get_uint64_equal (QEMUFile *f,void *pv,size_t size) +{ +uint64_t *v = pv; +uint64_t v2; +qemu_get_be64s (f, &v2); + +if (*v == v2)
Braces.
Quoted 42 lines
savevm.c +10
-0+return 0 ; +return -EINVAL ; +} + +const VMStateInfo vmstate_info_uint64_equal = { + .name ="int64 equal" , + .get = get_uint64_equal, + .put = put_uint64, +}; +/* 8 bit int. See that the received value is the same than the one in the field */ vmstate.h +7
-1@@ -129,6 +129,7 @@ extern const VMStateInfo vmstate_info_uint8_equal;extern const VMStateInfo vmstate_info_uint16_equal;extern const VMStateInfo vmstate_info_int32_equal;extern const VMStateInfo vmstate_info_uint32_equal; +extern const VMStateInfo vmstate_info_uint64_equal;extern const VMStateInfo vmstate_info_int32_le;extern const VMStateInfo vmstate_info_uint8;@@ -488,6 +489,12 @@ extern const VMStateInfo vmstate_info_unused_buffer;#define VMSTATE_UINT32_EQUAL (_f, _s) \ VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint32_equal, uint32_t) +#define VMSTATE_UINT64_EQUAL_V (_f, _s, _v) \ + VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64_equal, uint64_t) + +#define VMSTATE_UINT64_EQUAL (_f, _s) \ + VMSTATE_UINT64_EQUAL_V(_f, _s, 0) +#define VMSTATE_INT32_LE (_f, _s) \ VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t) --1.7.10.4
Re: [Qemu-devel] [PATCH 1/6] savevm: Add VMSTATE_UINT64_EQUAL helpers
Quoted 22 lines · Blue Swirl
Quoted 20 lines · David Gibson
The savevm code already includes a number of
*_EQUALhelpers which act as sanity checks verifying that the configuration of the saved state matches that of the machine we're loading into to work. Variants already exist for 8 bit 16 bit and 32 bit integers, but not 64 bit integers. This patch fills that hole, adding a UINT64 version.Signed-off-by David Gibson <[email protected]>--- savevm.c | 20 ++++++++++++++++++++ vmstate.h | 7 +++++++ 2 files changed, 27 insertions(+)savevm.c +0
-0@@ -1043,6 +1043,26 @@ const VMStateInfo vmstate_info_uint64 = { .put = put_uint64, };
Quoted 12 lines
savevm.c const VMStateInfo vmstate_info_uint64 = { · line 1055
Quoted 10 lines
savevm.c +10
-0+/* 64 bit unsigned int. See that the received value is the same than the one +in the field */ + +static int get_uint64_equal (QEMUFile *f,void *pv,size_t size) +{ +uint64_t *v = pv; +uint64_t v2; +qemu_get_be64s (f, &v2); + +if (*v == v2)Braces.
Oops, fixed for the next version.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
PATCH 2/6 savevm: Add VMSTATE_UINTTL_EQUAL helper
In reply to David GibsonThis adds an _EQUAL VMSTATE helper for target_ulongs, defined in terms of VMSTATE_UINT32_EQUAL or VMSTATE_UINT64_EQUAL as appropriate.
--- hw/hw.h | 6 ++++++ vmstate.h | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-)
hw/hw.h +6 -0
@@ -50,16 +50,22 @@ int qemu_boot_set(const char *boot_devices);#if TARGET_LONG_BITS ==64 #define VMSTATE_UINTTL_V (_f, _s, _v) \ VMSTATE_UINT64_V(_f, _s, _v) +#define VMSTATE_UINTTL_EQUAL_V (_f, _s, _v) \ + VMSTATE_UINT64_EQUAL_V(_f, _s, _v)#define VMSTATE_UINTTL_ARRAY_V (_f, _s, _n, _v) \ VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v)#else #define VMSTATE_UINTTL_V (_f, _s, _v) \ VMSTATE_UINT32_V(_f, _s, _v) +#define VMSTATE_UINTTL_EQUAL_V (_f, _s, _v) \ + VMSTATE_UINT32_EQUAL_V(_f, _s, _v)#define VMSTATE_UINTTL_ARRAY_V (_f, _s, _n, _v) \ VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v)#endif #define VMSTATE_UINTTL (_f, _s) \ VMSTATE_UINTTL_V(_f, _s, 0) +#define VMSTATE_UINTTL_EQUAL (_f, _s) \ + VMSTATE_UINTTL_EQUAL_V(_f, _s, 0)#define VMSTATE_UINTTL_ARRAY (_f, _s, _n) \ VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, 0)
vmstate.h +5 -2
@@ -486,8 +486,11 @@ extern const VMStateInfo vmstate_info_unused_buffer;#define VMSTATE_INT32_EQUAL (_f, _s) \ VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_equal, int32_t) -#define VMSTATE_UINT32_EQUAL (_f, _s) \ - VMSTATE_SINGLE(_f, _s, 0, vmstate_info_uint32_equal, uint32_t) +#define VMSTATE_UINT32_EQUAL_V (_f, _s, _v) \ + VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32_equal, uint32_t) + +#define VMSTATE_UINT32_EQUAL (_f, _s) \ + VMSTATE_UINT32_EQUAL_V(_f, _s, 0)#define VMSTATE_UINT64_EQUAL_V (_f, _s, _v) \ VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64_equal, uint64_t)
Signature · 1 line
1.7.10.4
PATCH 3/6 savevm: Add VMSTATE_FLOAT64 helpers
In reply to David GibsonThe current savevm code includes VMSTATE helpers for a number of commonly used data types, but not for the float64 type used by the internal floating point emulation code. This patch fixes the deficiency.
--- savevm.c | 23 +++++++++++++++++++++++ vmstate.h | 15 +++++++++++++++ 2 files changed, 38 insertions(+)
savevm.c +23 -0
@@ -1103,6 +1103,29 @@ const VMStateInfo vmstate_info_uint16_equal = { .put = put_uint16, }; +/* floating point */ + +static int get_float64 (QEMUFile *f,void *pv,size_t size) +{ +float64 *v = pv; + + *v =make_float64 (qemu_get_be64 (f)); +return 0 ; +} + +static void put_float64 (QEMUFile *f,void *pv,size_t size) +{ +uint64_t *v = pv; + +qemu_put_be64 (f,float64_val (*v)); +} + +const VMStateInfo vmstate_info_float64 = { + .name ="float64" , + .get = get_float64, + .put = put_float64, +}; +/* timers */ static int get_timer (QEMUFile *f,void *pv,size_t size)
vmstate.h +15 -0
@@ -137,6 +137,8 @@ extern const VMStateInfo vmstate_info_uint16;extern const VMStateInfo vmstate_info_uint32;extern const VMStateInfo vmstate_info_uint64; +extern const VMStateInfo vmstate_info_float64; +extern const VMStateInfo vmstate_info_timer;extern const VMStateInfo vmstate_info_buffer;extern const VMStateInfo vmstate_info_unused_buffer;
@@ -510,6 +512,13 @@ extern const VMStateInfo vmstate_info_unused_buffer;#define VMSTATE_UINT32_TEST (_f, _s, _t) \ VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint32, uint32_t) + +#define VMSTATE_FLOAT64_V (_f, _s, _v) \ + VMSTATE_SINGLE(_f, _s, _v, vmstate_info_float64, float64) + +#define VMSTATE_FLOAT64 (_f, _s) \ + VMSTATE_FLOAT64_V(_f, _s, 0) +#define VMSTATE_TIMER_TEST (_f, _s, _test) \ VMSTATE_POINTER_TEST(_f, _s, _test, vmstate_info_timer, QEMUTimer *)
@@ -576,6 +585,12 @@ extern const VMStateInfo vmstate_info_unused_buffer;#define VMSTATE_INT64_ARRAY (_f, _s, _n) \ VMSTATE_INT64_ARRAY_V(_f, _s, _n, 0) +#define VMSTATE_FLOAT64_ARRAY_V (_f, _s, _n, _v) \ + VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_float64, float64) + +#define VMSTATE_FLOAT64_ARRAY (_f, _s, _n) \ + VMSTATE_FLOAT64_ARRAY_V(_f, _s, _n, 0) +#define VMSTATE_BUFFER_V (_f, _s, _v) \ VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, 0, sizeof(typeof_field(_s, _f)))
Signature · 1 line
1.7.10.4
PATCH 4/6 savevm: Add VMSTATE_ helpers for target_phys_addr_t
In reply to David GibsonThe savevm code contains VMSTATE_ helpers for a number of commonly used types, but not for target_phys_addr_t. This patch fixes that deficiency implementing VMSTATE_TPA helpers in terms of VMSTATE_UINT32 or VMSTATE_UINT64 helpers as appropriate.
--- targphys.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
targphys.h +19 -0
@@ -21,6 +21,13 @@ typedef uint32_t target_phys_addr_t;#define TARGET_PRIuPHYS PRIu32#define TARGET_PRIxPHYS PRIx32#define TARGET_PRIXPHYS PRIX32 + +#define VMSTATE_TPA_V (_f, _s, _v) \ + VMSTATE_UINT32_V(_f, _s, _v) + +#define VMSTATE_TPA_EQUAL_V (_f, _s, _v) \ + VMSTATE_UINT32_EQUAL_V(_f, _s, _v) +#elif TARGET_PHYS_ADDR_BITS ==64 typedef uint64_t target_phys_addr_t ;#define TARGET_PHYS_ADDR_MAX UINT64_MAX
@@ -31,7 +38,19 @@ typedef uint64_t target_phys_addr_t;#define TARGET_PRIuPHYS PRIu64#define TARGET_PRIxPHYS PRIx64#define TARGET_PRIXPHYS PRIX64 + +#define VMSTATE_TPA_V (_f, _s, _v) \ + VMSTATE_UINT64_V(_f, _s, _v) + +#define VMSTATE_TPA_EQUAL_V (_f, _s, _v) \ + VMSTATE_UINT64_EQUAL_V(_f, _s, _v) +#endif #endif +#define VMSTATE_TPA (_f, _s) \ + VMSTATE_TPA_V(_f, _s, 0) +#define VMSTATE_TPA_EQUAL (_f, _s) \ + VMSTATE_TPA_EQUAL_V(_f, _s, 0) +#endif
Signature · 1 line
1.7.10.4
PATCH 5/6 savevm: Add VMSTATE_STRUCT_VARRAY_POINTER_UINT32
In reply to David GibsonCurrently the savevm code contains a VMSTATE_STRUCT_VARRAY_POINTER_INT32 helper (a variably sized array with the number of elements in an int32_t), but not VMSTATE_STRUCT_VARRAY_POINTER_UINT32 (... with the number of elements in a uint32_t). This patch (trivially) fixes the deficiency.
--- vmstate.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
vmstate.h +10 -0
@@ -322,6 +322,16 @@ extern const VMStateInfo vmstate_info_unused_buffer; .offset = vmstate_offset_pointer(_state, _field, _type), \ } +#define VMSTATE_STRUCT_VARRAY_POINTER_UINT32 (_field, _state, _field_num, _vmsd, _type) { \ + .name = (stringify(_field)), \ + .version_id = 0, \ + .num_offset = vmstate_offset_value(_state, _field_num, uint32_t),\ + .size = sizeof(_type), \ + .vmsd = &(_vmsd), \ + .flags = VMS_POINTER | VMS_VARRAY_INT32 | VMS_STRUCT, \ + .offset = vmstate_offset_pointer(_state, _field, _type), \ +} +#define VMSTATE_STRUCT_VARRAY_POINTER_UINT16 (_field, _state, _field_num, _vmsd, _type) { \ .name = (stringify(_field)), \ .version_id = 0, \
Signature · 1 line
1.7.10.4
PATCH 6/6 savevm: Fix bugs in the VMSTATE_VBUFFER_MULTIPLY definition
In reply to David GibsonThe VMSTATE_BUFFER_MULTIPLY macro is misnamed - it actually specifies a variably sized buffer with VMS_VBUFFER, so should be named VMSTATE_VBUFFER_MULTIPLY. This patch fixes this (the macro had no current users under either name).
In addition, unlike the other VMSTATE_VBUFFER variants, this macro did not specify VMS_POINTER. This patch fixes this bug as well.
--- vmstate.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
vmstate.h +2 -2
@@ -372,14 +372,14 @@ extern const VMStateInfo vmstate_info_unused_buffer; .offset = vmstate_offset_buffer(_state, _field) + _start, \ } -#define VMSTATE_BUFFER_MULTIPLY (_field, _state, _version, _test, _start, _field_size, _multiply) { \ +#define VMSTATE_VBUFFER_MULTIPLY (_field, _state, _version, _test, _start, _field_size, _multiply) { \ .name = (stringify(_field)), \ .version_id = (_version), \ .field_exists = (_test), \ .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\ .size = (_multiply), \ .info = &vmstate_info_buffer, \ - .flags = VMS_VBUFFER|VMS_MULTIPLY, \ + .flags = VMS_VBUFFER|VMS_POINTER|VMS_MULTIPLY, \ .offset = offsetof(_state, _field), \ .start = (_start), \ }
Signature · 1 line
1.7.10.4