hostmem: Fix qemu_opt_get_bool() crash in host_memory_backend_init()
PATCH 1/1 hostmem: Fix qemu_opt_get_bool() crash in host_memory_backend_init()
This fixes the following crash, introduced by commit 49d2e648e8087d154d8bf8b91f27c8e05e79d5a6:
$ gdb --args qemu-system-x86_64 -machine pc,mem-merge=off -object memory-backend-ram,id=ram-node0,size=1024 [...] Program received signal SIGABRT, Aborted. (gdb) bt #0 0x00007ffff253b8c7 in raise () at /lib64/libc.so.6 #1 0x00007ffff253d52a in abort () at /lib64/libc.so.6 #2 0x00007ffff253446d in __assert_fail_base () at /lib64/libc.so.6 #3 0x00007ffff2534522 in () at /lib64/libc.so.6 #4 0x00005555558bb80a in qemu_opt_get_bool_helper (opts=0x55555621b650, name=name@entry=0x5555558ec922 "mem-merge", defval=defval@entry=true, del=del@entry=false) at qemu/util/qemu-option.c:388 #5 0x00005555558bbb5a in qemu_opt_get_bool (opts=<optimized out>, name=name@entry=0x5555558ec922 "mem-merge", defval=defval@entry=true) at qemu/util/qemu-option.c:398 #6 0x0000555555720a24 in host_memory_backend_init (obj=0x5555562ac970) at qemu/backends/hostmem.c:226
Instead of using qemu_opt_get_bool(), that didn't work with qemu_machine_opts for a long time, we can use the machine QOM properties directly.
--- backends/hostmem.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
backends/hostmem.c +5 -4
@@ -10,6 +10,7 @@* See the COPYING file in the top-level directory. */ #include "sysemu/hostmem.h" +#include "hw/boards.h" #include "qapi/visitor.h" #include "qapi-types.h" #include "qapi-visit.h"
@@ -223,10 +224,10 @@ static void host_memory_backend_init(Object *obj) {HostMemoryBackend *backend =MEMORY_BACKEND (obj); - backend->merge =qemu_opt_get_bool (qemu_get_machine_opts (), -"mem-merge" , true); - backend->dump =qemu_opt_get_bool (qemu_get_machine_opts (), -"dump-guest-core" , true); + backend->merge =object_property_get_bool (OBJECT (current_machine), +"mem-merge" , &error_abort); + backend->dump =object_property_get_bool (OBJECT (current_machine), +"dump-guest-core" , &error_abort); backend->prealloc = mem_prealloc; object_property_add_bool(obj, "merge",
Signature · 1 line
2.1.0
Quoted 43 lines · On Thu, 16 Jul 2015 17:39:17 -0300 Eduardo Habkost <[email protected]> wrote:
This fixes the following crash, introduced by commit
49d2e648e8087d154d8bf8b91f27c8e05e79d5a6:$ gdb --args qemu-system-x86_64 -machine pc,mem-merge=off -object memory-backend-ram,id=ram-node0,size=1024 [...] Program received signal SIGABRT, Aborted. (gdb) bt #0 0x00007ffff253b8c7 in raise () at /lib64/libc.so.6 #1 0x00007ffff253d52a in abort () at /lib64/libc.so.6 #2 0x00007ffff253446d in __assert_fail_base () at /lib64/libc.so.6 #3 0x00007ffff2534522 in () at /lib64/libc.so.6 #4 0x00005555558bb80a in qemu_opt_get_bool_helper (opts=0x55555621b650, name=name@entry=0x5555558ec922 "mem-merge", defval=defval@entry=true, del=del@entry=false) at qemu/util/qemu-option.c:388 #5 0x00005555558bbb5a in qemu_opt_get_bool (opts=<optimized out>, name=name@entry=0x5555558ec922 "mem-merge", defval=defval@entry=true) at qemu/util/qemu-option.c:398 #6 0x0000555555720a24 in host_memory_backend_init (obj=0x5555562ac970) at qemu/backends/hostmem.c:226Instead of using
qemu_opt_get_bool(), that didn't work withqemu_machine_optsfor a long time, we can use the machine QOM properties directly.Signed-off-by Eduardo Habkost <[email protected]>--- backends/hostmem.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)backends/hostmem.c +1
-0@@ -10,6 +10,7 @@* See the COPYING file in the top-level directory. */ #include "sysemu/hostmem.h" +#include "hw/boards.h" #include "qapi/visitor.h" #include "qapi-types.h" #include "qapi-visit.h"
backends/hostmem.c static void host_memory_backend_init(Object · line 228
Quoted 9 lines
backends/hostmem.c +1
-4@@ -223,10 +224,10 @@ static void host_memory_backend_init(Object *obj) {HostMemoryBackend *backend =MEMORY_BACKEND (obj); - backend->merge =qemu_opt_get_bool (qemu_get_machine_opts (), -"mem-merge" , true); - backend->dump =qemu_opt_get_bool (qemu_get_machine_opts (), -"dump-guest-core" , true); + backend->merge = object_property_get_bool(OBJECT(current_machine),
maybe use qdev_get_machine() instead of OBJECT(current_machine)
Quoted 7 lines
backends/hostmem.c +3
-0+"mem-merge" , &error_abort); + backend->dump =object_property_get_bool (OBJECT (current_machine), +"dump-guest-core" , &error_abort); backend->prealloc = mem_prealloc;object_property_add_bool(obj, "merge",
Quoted 15 lines · Eduardo Habkost
This fixes the following crash, introduced by commit
49d2e648e8087d154d8bf8b91f27c8e05e79d5a6:$ gdb --args qemu-system-x86_64 -machine pc,mem-merge=off -object memory-backend-ram,id=ram-node0,size=1024 [...] Program received signal SIGABRT, Aborted. (gdb) bt #0 0x00007ffff253b8c7 in raise () at /lib64/libc.so.6 #1 0x00007ffff253d52a in abort () at /lib64/libc.so.6 #2 0x00007ffff253446d in __assert_fail_base () at /lib64/libc.so.6 #3 0x00007ffff2534522 in () at /lib64/libc.so.6 #4 0x00005555558bb80a in qemu_opt_get_bool_helper (opts=0x55555621b650, name=name@entry=0x5555558ec922 "mem-merge", defval=defval@entry=true, del=del@entry=false) at qemu/util/qemu-option.c:388 #5 0x00005555558bbb5a in qemu_opt_get_bool (opts=<optimized out>, name=name@entry=0x5555558ec922 "mem-merge", defval=defval@entry=true) at qemu/util/qemu-option.c:398 #6 0x0000555555720a24 in host_memory_backend_init (obj=0x5555562ac970) at qemu/backends/hostmem.c:226
Quoted 3 lines
Instead of using
qemu_opt_get_bool(), that didn't work withqemu_machine_optsfor a long time, we can use the machine QOM properties directly.
This was the intent.
Quoted 24 lines
Signed-off-by Eduardo Habkost <[email protected]>--- backends/hostmem.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)backends/hostmem.c +1
-1@@ -10,6 +10,7 @@* See the COPYING file in the top-level directory. */ #include "sysemu/hostmem.h" +#include "hw/boards.h" #include "qapi/visitor.h" #include "qapi-types.h" #include "qapi-visit.h" @@ -223,10 +224,10 @@ static void host_memory_backend_init(Object *obj) {HostMemoryBackend *backend =MEMORY_BACKEND (obj); - backend->merge = qemu_opt_get_bool(qemu_get_machine_opts(),
backends/hostmem.c static void host_memory_backend_init(Object *obj) · line 233
Quoted 10 lines
backends/hostmem.c +4
-3- "mem-merge", true); - backend->dump =qemu_opt_get_bool (qemu_get_machine_opts (), -"dump-guest-core" , true); + backend->merge =object_property_get_bool (OBJECT (current_machine), +"mem-merge" , &error_abort); + backend->dump =object_property_get_bool (OBJECT (current_machine), +"dump-guest-core" , &error_abort); backend->prealloc = mem_prealloc; object_property_add_bool(obj, "merge",
Thank you for fixing this,
Quoted 49 lines · Igor Mammedov
Quoted 46 lines · On Thu, 16 Jul 2015 17:39:17 -0300 Eduardo Habkost <[email protected]> wrote:
This fixes the following crash, introduced by commit
49d2e648e8087d154d8bf8b91f27c8e05e79d5a6:$ gdb --args qemu-system-x86_64 -machine pc,mem-merge=off -object memory-backend-ram,id=ram-node0,size=1024 [...] Program received signal SIGABRT, Aborted. (gdb) bt #0 0x00007ffff253b8c7 in raise () at /lib64/libc.so.6 #1 0x00007ffff253d52a in abort () at /lib64/libc.so.6 #2 0x00007ffff253446d in __assert_fail_base () at /lib64/libc.so.6 #3 0x00007ffff2534522 in () at /lib64/libc.so.6 #4 0x00005555558bb80a in qemu_opt_get_bool_helper (opts=0x55555621b650, name=name@entry=0x5555558ec922 "mem-merge", defval=defval@entry=true, del=del@entry=false) at qemu/util/qemu-option.c:388 #5 0x00005555558bbb5a in qemu_opt_get_bool (opts=<optimized out>, name=name@entry=0x5555558ec922 "mem-merge", defval=defval@entry=true) at qemu/util/qemu-option.c:398 #6 0x0000555555720a24 in host_memory_backend_init (obj=0x5555562ac970) at qemu/backends/hostmem.c:226Instead of using
qemu_opt_get_bool(), that didn't work withqemu_machine_optsfor a long time, we can use the machine QOM properties directly.Signed-off-by Eduardo Habkost <[email protected]>--- backends/hostmem.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)backends/hostmem.c +1
-0@@ -10,6 +10,7 @@* See the COPYING file in the top-level directory. */ #include "sysemu/hostmem.h" +#include "hw/boards.h" #include "qapi/visitor.h" #include "qapi-types.h" #include "qapi-visit.h" @@ -223,10 +224,10 @@ static void host_memory_backend_init(Object *obj) {HostMemoryBackend *backend =MEMORY_BACKEND (obj);
Quoted 7 lines
backends/hostmem.c static void host_memory_backend_init(Object *obj)
Quoted 6 lines
backends/hostmem.c +1
-4- backend->merge =qemu_opt_get_bool (qemu_get_machine_opts (), -"mem-merge" , true); - backend->dump =qemu_opt_get_bool (qemu_get_machine_opts (), -"dump-guest-core" , true); + backend->merge = object_property_get_bool(OBJECT(current_machine),maybe use
qdev_get_machine()instead ofOBJECT(current_machine)
What are the advantages you see in the extra layers of indirection of qdev_get_machine()? (I am not against your proposal, but I would like to understand the point of qdev_get_machine() yet.)
I'd prefer to use something that is guaranteed to be MachineState*, qdev_get_machine() returns Object*. I am even considering using current_machine->mem_merge and current_machine->dump_guest_core directly instead of object_property_get_bool(). That would mean extra compile-time checks, instead of runtime ones.
Signature · 1 line
Eduardo
Quoted 58 lines · On Fri, 17 Jul 2015 17:33:55 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 49 lines · Igor Mammedov
Quoted 46 lines · On Thu, 16 Jul 2015 17:39:17 -0300 Eduardo Habkost <[email protected]> wrote:
This fixes the following crash, introduced by commit
49d2e648e8087d154d8bf8b91f27c8e05e79d5a6:$ gdb --args qemu-system-x86_64 -machine pc,mem-merge=off -object memory-backend-ram,id=ram-node0,size=1024 [...] Program received signal SIGABRT, Aborted. (gdb) bt #0 0x00007ffff253b8c7 in raise () at /lib64/libc.so.6 #1 0x00007ffff253d52a in abort () at /lib64/libc.so.6 #2 0x00007ffff253446d in __assert_fail_base () at /lib64/libc.so.6 #3 0x00007ffff2534522 in () at /lib64/libc.so.6 #4 0x00005555558bb80a in qemu_opt_get_bool_helper (opts=0x55555621b650, name=name@entry=0x5555558ec922 "mem-merge", defval=defval@entry=true, del=del@entry=false) at qemu/util/qemu-option.c:388 #5 0x00005555558bbb5a in qemu_opt_get_bool (opts=<optimized out>, name=name@entry=0x5555558ec922 "mem-merge", defval=defval@entry=true) at qemu/util/qemu-option.c:398 #6 0x0000555555720a24 in host_memory_backend_init (obj=0x5555562ac970) at qemu/backends/hostmem.c:226Instead of using
qemu_opt_get_bool(), that didn't work withqemu_machine_optsfor a long time, we can use the machine QOM properties directly.Signed-off-by Eduardo Habkost <[email protected]>--- backends/hostmem.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)backends/hostmem.c +1
-0@@ -10,6 +10,7 @@* See the COPYING file in the top-level directory. */ #include "sysemu/hostmem.h" +#include "hw/boards.h" #include "qapi/visitor.h" #include "qapi-types.h" #include "qapi-visit.h" @@ -223,10 +224,10 @@ static void host_memory_backend_init(Object *obj) {HostMemoryBackend *backend =MEMORY_BACKEND (obj);Quoted 7 lines
backends/hostmem.c static void host_memory_backend_init(Object *obj)
Quoted 6 lines
backends/hostmem.c +1
-4- backend->merge =qemu_opt_get_bool (qemu_get_machine_opts (), -"mem-merge" , true); - backend->dump =qemu_opt_get_bool (qemu_get_machine_opts (), -"dump-guest-core" , true); + backend->merge = object_property_get_bool(OBJECT(current_machine),maybe use
qdev_get_machine()instead ofOBJECT(current_machine)
Quoted 3 lines
What are the advantages you see in the extra layers of indirection of
qdev_get_machine()? (I am not against your proposal, but I would like to understand the point ofqdev_get_machine()yet.)
current_machine might be NULL where as qdev_get_machine() always returns /machine object.
Quoted 6 lines
I'd prefer to use something that is guaranteed to be MachineState*,
qdev_get_machine()returns Object*. I am even considering usingcurrent_machine->mem_mergeandcurrent_machine->dump_guest_coredirectly instead ofobject_property_get_bool(). That would mean extra compile-time checks, instead of runtime ones.
Check difference 'git grep qdev_get_machine' vs 'git grep current_machine'. I was under impression that policy was trying no to use globals unless one has to, and not introduce new usage in presence of other means to get object.
Quoted 61 lines · Igor Mammedov
Quoted 58 lines · On Fri, 17 Jul 2015 17:33:55 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 56 lines · Igor Mammedov
Quoted 43 lines · On Thu, 16 Jul 2015 17:39:17 -0300 Eduardo Habkost <[email protected]> wrote:
This fixes the following crash, introduced by commit
49d2e648e8087d154d8bf8b91f27c8e05e79d5a6:$ gdb --args qemu-system-x86_64 -machine pc,mem-merge=off -object memory-backend-ram,id=ram-node0,size=1024 [...] Program received signal SIGABRT, Aborted. (gdb) bt #0 0x00007ffff253b8c7 in raise () at /lib64/libc.so.6 #1 0x00007ffff253d52a in abort () at /lib64/libc.so.6 #2 0x00007ffff253446d in __assert_fail_base () at /lib64/libc.so.6 #3 0x00007ffff2534522 in () at /lib64/libc.so.6 #4 0x00005555558bb80a in qemu_opt_get_bool_helper (opts=0x55555621b650, name=name@entry=0x5555558ec922 "mem-merge", defval=defval@entry=true, del=del@entry=false) at qemu/util/qemu-option.c:388 #5 0x00005555558bbb5a in qemu_opt_get_bool (opts=<optimized out>, name=name@entry=0x5555558ec922 "mem-merge", defval=defval@entry=true) at qemu/util/qemu-option.c:398 #6 0x0000555555720a24 in host_memory_backend_init (obj=0x5555562ac970) at qemu/backends/hostmem.c:226Instead of using
qemu_opt_get_bool(), that didn't work withqemu_machine_optsfor a long time, we can use the machine QOM properties directly.Signed-off-by Eduardo Habkost <[email protected]>--- backends/hostmem.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)backends/hostmem.c +1
-0@@ -10,6 +10,7 @@* See the COPYING file in the top-level directory. */ #include "sysemu/hostmem.h" +#include "hw/boards.h" #include "qapi/visitor.h" #include "qapi-types.h" #include "qapi-visit.h" backends/hostmem.c static void host_memory_backend_init(Object · line 228
Quoted 9 lines
backends/hostmem.c +1
-4@@ -223,10 +224,10 @@ static void host_memory_backend_init(Object *obj) {HostMemoryBackend *backend =MEMORY_BACKEND (obj); - backend->merge =qemu_opt_get_bool (qemu_get_machine_opts (), -"mem-merge" , true); - backend->dump =qemu_opt_get_bool (qemu_get_machine_opts (), -"dump-guest-core" , true); + backend->merge = object_property_get_bool(OBJECT(current_machine),maybe use
qdev_get_machine()instead ofOBJECT(current_machine)
Quoted 5 lines
Quoted 3 lines
What are the advantages you see in the extra layers of indirection of
qdev_get_machine()? (I am not against your proposal, but I would like to understand the point ofqdev_get_machine()yet.)
current_machinemight be NULL where asqdev_get_machine()always returns /machine object.
In this case, I don't want "/machine" to be created as a generic container object by accident because it must be a MachineState object. If /machine is not initialized yet, that code should abort instead of trying to continue.
But that can be solved by simply ensuring qdev_get_machine() is a TYPE_MACHINE object (see below).
Quoted 11 lines
Quoted 7 lines
I'd prefer to use something that is guaranteed to be MachineState*,
qdev_get_machine()returns Object*. I am even considering usingcurrent_machine->mem_mergeandcurrent_machine->dump_guest_coredirectly instead ofobject_property_get_bool(). That would mean extra compile-time checks, instead of runtime ones.Check difference 'git grep
qdev_get_machine' vs 'git grepcurrent_machine'. I was under impression that policy was trying no to use globals unless one has to, and not introduce new usage in presence of other means to get object.
I will send a new version using:
MachineState *machine = MACHINE(qdev_get_machine()); backend->merge = machine_mem_merge(machine); backend->dump = machine_dump_guest_core(machine);
Then we have no global variable, type safety, and no direct access to struct fields.
Signature · 1 line
Eduardo
Quoted 88 lines · Eduardo Habkost
Quoted 61 lines · Igor Mammedov
Quoted 58 lines · On Fri, 17 Jul 2015 17:33:55 -0300 Eduardo Habkost <[email protected]> wrote:
Quoted 56 lines · Igor Mammedov
Quoted 43 lines · On Thu, 16 Jul 2015 17:39:17 -0300 Eduardo Habkost <[email protected]> wrote:
This fixes the following crash, introduced by commit
49d2e648e8087d154d8bf8b91f27c8e05e79d5a6:$ gdb --args qemu-system-x86_64 -machine pc,mem-merge=off -object memory-backend-ram,id=ram-node0,size=1024 [...] Program received signal SIGABRT, Aborted. (gdb) bt #0 0x00007ffff253b8c7 in raise () at /lib64/libc.so.6 #1 0x00007ffff253d52a in abort () at /lib64/libc.so.6 #2 0x00007ffff253446d in __assert_fail_base () at /lib64/libc.so.6 #3 0x00007ffff2534522 in () at /lib64/libc.so.6 #4 0x00005555558bb80a in qemu_opt_get_bool_helper (opts=0x55555621b650, name=name@entry=0x5555558ec922 "mem-merge", defval=defval@entry=true, del=del@entry=false) at qemu/util/qemu-option.c:388 #5 0x00005555558bbb5a in qemu_opt_get_bool (opts=<optimized out>, name=name@entry=0x5555558ec922 "mem-merge", defval=defval@entry=true) at qemu/util/qemu-option.c:398 #6 0x0000555555720a24 in host_memory_backend_init (obj=0x5555562ac970) at qemu/backends/hostmem.c:226Instead of using
qemu_opt_get_bool(), that didn't work withqemu_machine_optsfor a long time, we can use the machine QOM properties directly.Signed-off-by Eduardo Habkost <[email protected]>--- backends/hostmem.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)backends/hostmem.c +1
-0@@ -10,6 +10,7 @@* See the COPYING file in the top-level directory. */ #include "sysemu/hostmem.h" +#include "hw/boards.h" #include "qapi/visitor.h" #include "qapi-types.h" #include "qapi-visit.h" backends/hostmem.c static void host_memory_backend_init(Object · line 228
Quoted 9 lines
backends/hostmem.c +1
-4@@ -223,10 +224,10 @@ static void host_memory_backend_init(Object *obj) {HostMemoryBackend *backend =MEMORY_BACKEND (obj); - backend->merge =qemu_opt_get_bool (qemu_get_machine_opts (), -"mem-merge" , true); - backend->dump =qemu_opt_get_bool (qemu_get_machine_opts (), -"dump-guest-core" , true); + backend->merge = object_property_get_bool(OBJECT(current_machine),maybe use
qdev_get_machine()instead ofOBJECT(current_machine)Quoted 5 lines
Quoted 3 lines
What are the advantages you see in the extra layers of indirection of
qdev_get_machine()? (I am not against your proposal, but I would like to understand the point ofqdev_get_machine()yet.)
current_machinemight be NULL where asqdev_get_machine()always returns /machine object.In this case, I don't want "/machine" to be created as a generic container object by accident because it must be a MachineState object. If /machine is not initialized yet, that code should abort instead of trying to continue.
But that can be solved by simply ensuring
qdev_get_machine()is aTYPE_MACHINEobject (see below).Quoted 11 lines
Quoted 7 lines
I'd prefer to use something that is guaranteed to be MachineState*,
qdev_get_machine()returns Object*. I am even considering usingcurrent_machine->mem_mergeandcurrent_machine->dump_guest_coredirectly instead ofobject_property_get_bool(). That would mean extra compile-time checks, instead of runtime ones.Check difference 'git grep
qdev_get_machine' vs 'git grepcurrent_machine'. I was under impression that policy was trying no to use globals unless one has to, and not introduce new usage in presence of other means to get object.
Quoted 8 lines
I will send a new version using:
MachineState *machine = MACHINE(qdev_get_machine()); backend->merge = machine_mem_merge(machine); backend->dump = machine_dump_guest_core(machine);Then we have no global variable, type safety, and no direct access to struct fields.
+1
I am considering retiring curent_machine global variable for 2.5.
Thanks,
Marcel