Fix string input visitor and "info memdev" regression
cover Fix string input visitor and "info memdev" regression
Markus Armbruster (2):
qapi: Fix string input visitor regression for empty lists Revert "hostmem: fix QEMU crash by 'info memdev'"
backends/hostmem.c | 22 ++++++++-------------- qapi/string-input-visitor.c | 4 ++++ tests/test-string-input-visitor.c | 11 ++++++++--- 3 files changed, 20 insertions(+), 17 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/2 qapi: Fix string input visitor regression for empty lists
Visiting a list when input is the empty string should result in an empty list, not an error. Noticed when commit 3d089ce belatedly added tests, but simply accepted as weird then. It's actually a regression:
broken in commit 74f24cb, v2.7.0. Fix it, and throw in another test case for empty string.
--- qapi/string-input-visitor.c | 4 ++++ tests/test-string-input-visitor.c | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-)
qapi/string-input-visitor.c +4 -0
@@ -54,6 +54,10 @@ static int parse_str(StringInputVisitor *siv, const char *name, Error **errp)return 0 ; } +if (!*str) { +return 0 ; + } + do { errno = 0; start = strtoll(str, &endptr, 0);
tests/test-string-input-visitor.c +8 -3
@@ -63,6 +63,11 @@ static void test_visitor_in_int(TestInputVisitorData *data,visit_type_int (v,NULL , &res, &err);error_free_or_abort (&err); + + v =visitor_input_test_init (data,"" ); + +visit_type_int (v,NULL , &res, &err); +error_free_or_abort (&err); }static void check_ilist (Visitor *v,int64_t *expected,size_t n)
@@ -140,11 +145,11 @@ static void test_visitor_in_intList(TestInputVisitorData *data, v =visitor_input_test_init (data,"18446744073709551615" );check_ulist (v, expect4,ARRAY_SIZE (expect4)); -/* Empty list is invalid (weird) */ +/* Empty list */ v =visitor_input_test_init (data,"" ); -visit_type_int64List (v,NULL , &res, &err); -error_free_or_abort (&err); +visit_type_int64List (v,NULL , &res, &error_abort); +g_assert (!res);/* Not a list */
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH for-2.9 1/2] qapi: Fix string input visitor regression for empty lists
Quoting Markus Armbruster (2017-03-20 11:13:43)
Quoted 7 lines
Visiting a list when input is the empty string should result in an empty list, not an error. Noticed when commit 3d089ce belatedly added tests, but simply accepted as weird then. It's actually a regression:
broken in commit 74f24cb, v2.7.0. Fix it, and throw in another test case for empty string.Signed-off-by Markus Armbruster <[email protected]>
Quoted 54 lines
--- qapi/string-input-visitor.c | 4 ++++ tests/test-string-input-visitor.c | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-)qapi/string-input-visitor.c +4
-0@@ -54,6 +54,10 @@ static int parse_str(StringInputVisitor *siv, const char *name, Error **errp)return 0 ; } +if (!*str) { +return 0 ; + } + do { errno = 0; start = strtoll(str, &endptr, 0);tests/test-string-input-visitor.c +8
-3@@ -63,6 +63,11 @@ static void test_visitor_in_int(TestInputVisitorData *data,visit_type_int (v,NULL , &res, &err);error_free_or_abort (&err); + + v =visitor_input_test_init (data,"" ); + +visit_type_int (v,NULL , &res, &err); +error_free_or_abort (&err); }static void check_ilist (Visitor *v,int64_t *expected,size_t n)@@ -140,11 +145,11 @@ static void test_visitor_in_intList(TestInputVisitorData *data, v =visitor_input_test_init (data,"18446744073709551615" );check_ulist (v, expect4,ARRAY_SIZE (expect4)); -/* Empty list is invalid (weird) */ +/* Empty list */ v =visitor_input_test_init (data,"" ); -visit_type_int64List (v,NULL , &res, &err); -error_free_or_abort (&err); +visit_type_int64List (v,NULL , &res, &error_abort); +g_assert (!res);/* Not a list */ Signature · 1 line
2.7.4
PATCH 2/2 Revert "hostmem: fix QEMU crash by 'info memdev'"
In reply to Markus ArmbrusterThis reverts commit 1454d33f0507cb54d62ed80f494884157c9e7130.
The string input visitor regression fixed in the previous commit made visit_type_uint16List() fail on empty input. query_memdev() calls it via object_property_get_uint16List(). Because it doesn't expect it to fail, it passes &error_abort, and duly crashes.
Commit 1454d33 "fixes" this crash by making host_memory_backend_get_host_nodes() return a list containing just MAX_NODES instead of the empty list. Papers over the regression, and leads to bogus "info memdev" output, as shown below; revert.
I suspect that if we had bisected the crash back then, we would have found and fixed the actual bug instead of papering over it.
To reproduce, run HMP command "info memdev" with
$ qemu-system-x86_64 --nodefaults -S -display none -monitor stdio -object memory-backend-ram,id=mem1,size=4k
With this commit, "info memdev" prints
memory backend: mem1
size: 4096
merge: true
dump: true
prealloc: false
policy: default
host nodes:
exactly like before commit 74f24cb.
Between commit 1454d33 and this commit, it prints
memory backend: mem1
size: 4096
merge: true
dump: true
prealloc: false
policy: default
host nodes: 128The last line is bogus.
Between commit 74f24cb and 1454d33, it crashes like this:
Unexpected error in parse_str() at /work/armbru/tmp/qemu/qapi/string-input-visitor.c:126:
Parameter 'null' expects an int64 value or range
Aborted (core dumped)
--- backends/hostmem.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-)
backends/hostmem.c +8 -14
@@ -64,14 +64,6 @@ out:error_propagate (errp, local_err); } -static uint16List **host_memory_append_node (uint16List **node, -unsigned long value) -{ - *node =g_malloc0 (sizeof (**node)); - (*node)->value = value; -return &(*node)->next; -} -static void host_memory_backend_get_host_nodes (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp)
@@ -82,23 +74,25 @@ host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name,unsigned long value; value =find_first_bit (backend->host_nodes,MAX_NODES ); - - node =host_memory_append_node (node, value); -if (value ==MAX_NODES ) { - goto out; +return ; } + *node =g_malloc0 (sizeof (**node)); + (*node)->value = value; + node = &(*node)->next; +do { value =find_next_bit (backend->host_nodes,MAX_NODES , value +1 );if (value ==MAX_NODES ) {break ; } - node =host_memory_append_node (node, value); + *node =g_malloc0 (sizeof (**node)); + (*node)->value = value; + node = &(*node)->next; }while (true); -out:visit_type_uint16List (v, name, &host_nodes, errp); }
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH for-2.9 2/2] Revert "hostmem: fix QEMU crash by 'info memdev'"
Quoting Markus Armbruster (2017-03-20 11:13:44)
Quoted 45 lines
This reverts commit
1454d33f0507cb54d62ed80f494884157c9e7130.The string input visitor regression fixed in the previous commit made
visit_type_uint16List()fail on empty input.query_memdev()calls it viaobject_property_get_uint16List(). Because it doesn't expect it to fail, it passes&error_abort, and duly crashes.Commit 1454d33 "fixes" this crash by making
host_memory_backend_get_host_nodes()return a list containing justMAX_NODESinstead of the empty list. Papers over the regression, and leads to bogus "info memdev" output, as shown below; revert.I suspect that if we had bisected the crash back then, we would have found and fixed the actual bug instead of papering over it.
To reproduce, run HMP command "info memdev" with
$ qemu-system-x86_64 --nodefaults -S -display none -monitor stdio -object memory-backend-ram,id=mem1,size=4kWith this commit, "info memdev" prints
memory backend: mem1
size: 4096
merge: true
dump: true
prealloc: false
policy: default
host nodes:exactly like before commit 74f24cb.
Between commit 1454d33 and this commit, it prints
memory backend: mem1 size: 4096 merge: true dump: true prealloc: false policy: default host nodes: 128The last line is bogus.
Between commit 74f24cb and 1454d33, it crashes like this:
Quoted 7 lines
Unexpected error in
parse_str()at /work/armbru/tmp/qemu/qapi/string-input-visitor.c:126:
Parameter 'null' expects an int64 value or range
Aborted (core dumped)Cc Xiao Guangrong <[email protected]>Cc Paolo Bonzini <[email protected]>Signed-off-by Markus Armbruster <[email protected]>
Quoted 58 lines
--- backends/hostmem.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-)backends/hostmem.c +8
-14@@ -64,14 +64,6 @@ out:error_propagate (errp, local_err); } -static uint16List **host_memory_append_node (uint16List **node, -unsigned long value) -{ - *node =g_malloc0 (sizeof (**node)); - (*node)->value = value; -return &(*node)->next; -} -static void host_memory_backend_get_host_nodes (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp)@@ -82,23 +74,25 @@ host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name,unsigned long value; value =find_first_bit (backend->host_nodes,MAX_NODES ); - - node =host_memory_append_node (node, value); -if (value ==MAX_NODES ) { - goto out; +return ; } + *node =g_malloc0 (sizeof (**node)); + (*node)->value = value; + node = &(*node)->next; +do { value =find_next_bit (backend->host_nodes,MAX_NODES , value +1 );if (value ==MAX_NODES ) {break ; } - node =host_memory_append_node (node, value); + *node =g_malloc0 (sizeof (**node)); + (*node)->value = value; + node = &(*node)->next; }while (true); -out:visit_type_uint16List (v, name, &host_nodes, errp); }Signature · 1 line
2.7.4
Quoted 3 lines · Markus Armbruster
Markus Armbruster (2):
qapi: Fix string input visitor regression for empty lists Revert "hostmem: fix QEMU crash by 'info memdev'"
Quoted 6 lines
backends/hostmem.c | 22 ++++++++-------------- qapi/string-input-visitor.c | 4 ++++ tests/test-string-input-visitor.c | 11 ++++++++--- 3 files changed, 20 insertions(+), 17 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org