migration: Add canary to VMSTATE_END_OF_LIST
PATCH 1/1 migration: Add canary to VMSTATE_END_OF_LIST
From: "Dr. David Alan Gilbert" <[email protected]>
We fairly regularly forget VMSTATE_END_OF_LIST markers off descriptions; given that the current check is only for ->name being NULL, sometimes we get unlucky and the code apparently works and no one spots the error.
Explicitly add a flag, VMS_END that should be set, and assert it is set during the traversal.
Note: This can't go in until we update the copy of vmstate.h in slirp.
--- include/migration/vmstate.h | 7 ++++++- migration/vmstate.c | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-)
include/migration/vmstate.h +6 -1
@@ -147,6 +147,9 @@ enum VMStateFlags {* VMStateField.struct_version_id to tell which version of the * structure we are referencing to use. */ VMS_VSTRUCT =0x8000 , + +/* Marker for end of list */ +VMS_END =0x10000 }; typedef enum {
@@ -1163,7 +1166,9 @@ extern const VMStateInfo vmstate_info_qlist; VMSTATE_UNUSED_BUFFER(_test, 0, _size)#define VMSTATE_END_OF_LIST () \ - {} + { \ + .flags = VMS_END, \ + }int vmstate_load_state (QEMUFile *f,const VMStateDescription *vmsd,void *opaque,int version_id);
migration/vmstate.c +2 -0
@@ -160,6 +160,7 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, } field++; } +assert (field->flags ==VMS_END ); ret =vmstate_subsection_load (f, vmsd, opaque);if (ret !=0 ) {return ret;
@@ -413,6 +414,7 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd, } field++; } +assert (field->flags ==VMS_END );if (vmdesc) {json_writer_end_array (vmdesc);
Signature · 1 line
2.34.1
Quoted 9 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
We fairly regularly forget
VMSTATE_END_OF_LISTmarkers off descriptions; given that the current check is only for ->name being NULL, sometimes we get unlucky and the code apparently works and no one spots the error.Explicitly add a flag,
VMS_ENDthat should be set, and assert it is set during the traversal.
Does 'make check' definitely do the traversal for all vmstate structs, or do we need to add a "sanity check them all on startup" bit of test code ?
thanks
-- PMM
Quoted 9 lines · * Peter Maydell ([email protected]) wrote:
Quoted 7 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
We fairly regularly forget
VMSTATE_END_OF_LISTmarkers off descriptions; given that the current check is only for ->name being NULL, sometimes we get unlucky and the code apparently works and no one spots the error.
Quoted 6 lines
Quoted 2 lines
Explicitly add a flag,
VMS_ENDthat should be set, and assert it is set during the traversal.Does 'make check' definitely do the traversal for all vmstate structs, or do we need to add a "sanity check them all on startup" bit of test code ?
Oh I doubt it does; some vmsd's are conditional on guest state, many are only on particular machine types.
I think the closest we have to being able to walk the tree, is --dump-vmstate - although you need to call that for each machine type. (I forgot to add the canary check in the dump-vmstate code, I'll fix that).
Dave
Quoted 3 lines
thanks
-- PMM
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Quoted 6 lines · Dr. David Alan Gilbert
Quoted 3 lines · * Peter Maydell ([email protected]) wrote:
Does 'make check' definitely do the traversal for all vmstate structs, or do we need to add a "sanity check them all on startup" bit of test code ?
Quoted 7 lines
Oh I doubt it does; some vmsd's are conditional on guest state, many are only on particular machine types.
I think the closest we have to being able to walk the tree, is --dump-vmstate - although you need to call that for each machine type. (I forgot to add the canary check in the dump-vmstate code, I'll fix that).
We could have vmstate_register_with_alias_id() iterate through and assert presence of the right terminator (probably only if qtest enabled, or some other suitable condition). Then the existing tests that do the basic "check we can instantiate every device and initialize every board model" would run that code and catch most missing terminator cases, I think.
-- PMM
Quoted 6 lines · Peter Maydell
We could have
vmstate_register_with_alias_id()iterate through and assert presence of the right terminator (probably only if qtest enabled, or some other suitable condition). Then the existing tests that do the basic "check we can instantiate every device and initialize every board model" would run that code and catch most missing terminator cases, I think.
Agreed. How about assert it even without qtest? We do tons of assertion for programming errors anyway in QEMU.
Thanks,
Signature · 1 line
Peter Xu
Quoted 11 lines · Peter Xu
Quoted 6 lines · Peter Maydell
We could have
vmstate_register_with_alias_id()iterate through and assert presence of the right terminator (probably only if qtest enabled, or some other suitable condition). Then the existing tests that do the basic "check we can instantiate every device and initialize every board model" would run that code and catch most missing terminator cases, I think.Agreed. How about assert it even without qtest? We do tons of assertion for programming errors anyway in QEMU.
I don't inherently object, but in this case to do the assertion we'd need to do a scan over the fields arrays which we wouldn't otherwise need to, so the cost of the assert is not simply the compare-and-branch but also the loop over the array. If that's not significant in terms of start-up time costs we can just go ahead and do it (which would be nicer for debugging and making it really obvious to people writing new devices) but my remark above was a gesture towards "maybe we need to not do it for normal startup"..
-- PMM
Quoted 13 lines · Peter Maydell
Quoted 11 lines · Peter Xu
Quoted 6 lines · Peter Maydell
We could have
vmstate_register_with_alias_id()iterate through and assert presence of the right terminator (probably only if qtest enabled, or some other suitable condition). Then the existing tests that do the basic "check we can instantiate every device and initialize every board model" would run that code and catch most missing terminator cases, I think.Agreed. How about assert it even without qtest? We do tons of assertion for programming errors anyway in QEMU.
Quoted 9 lines
I don't inherently object, but in this case to do the assertion we'd need to do a scan over the fields arrays which we wouldn't otherwise need to, so the cost of the assert is not simply the compare-and-branch but also the loop over the array. If that's not significant in terms of start-up time costs we can just go ahead and do it (which would be nicer for debugging and making it really obvious to people writing new devices) but my remark above was a gesture towards "maybe we need to not do it for normal startup"..
Hmm.. Then how about put it into a "#ifdef CONFIG_DEBUG"?
We may need some extra lines in configure, though:
if test "$debug" = "yes"; then
echo "CONFIG_DEBUG=y" >> $config_host_mak
fi
PS: I'm a bit surprised we don't have CONFIG_DEBUG already..
Thanks,
Signature · 1 line
Peter Xu