Message ID | 20190107122304.22997-2-marcandre.lureau@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [PULL,v2,01/28] hw: apply accel compat properties without touching globals | expand |
On Mon, 7 Jan 2019 at 12:23, Marc-André Lureau <marcandre.lureau@redhat.com> wrote: > > Instead of registering compat properties as globals, let's keep them > in their own array, to avoid mixing with user globals. > > Introduce object_apply_global_props() function, to apply compatibility > properties from a GPtrArray. > diff --git a/hw/core/qdev.c b/hw/core/qdev.c > index 6b3cc55b27..53b507164f 100644 > --- a/hw/core/qdev.c > +++ b/hw/core/qdev.c > @@ -972,6 +972,15 @@ static void device_initfn(Object *obj) > > static void device_post_init(Object *obj) > { > + if (object_dynamic_cast(qdev_get_machine(), TYPE_MACHINE)) { > + MachineState *m = MACHINE(qdev_get_machine()); > + AccelClass *ac = ACCEL_GET_CLASS(m->accelerator); > + > + if (ac->compat_props) { > + object_apply_global_props(obj, ac->compat_props, &error_abort); > + } > + } > + > qdev_prop_set_globals(DEVICE(obj)); > } Hi; I've just noticed that this commit seems to break "-device whatever,help" : $ gdb --args ./build/x86/arm-softmmu/qemu-system-arm -device iotkit,help -M virt GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1 [...] (gdb) r Starting program: /home/petmay01/linaro/qemu-from-laptop/qemu/build/x86/arm-softmmu/qemu-system-arm -device iotkit,help -M virt [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". [New Thread 0x7fffce6c1700 (LWP 23277)] Thread 1 "qemu-system-arm" received signal SIGSEGV, Segmentation fault. 0x0000555555d985d1 in object_get_class (obj=0x0) at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:857 857 return obj->class; (gdb) bt #0 0x0000555555d985d1 in object_get_class (obj=0x0) at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:857 #1 0x0000555555b5675d in object_apply_compat_props (obj=0x555556b42600) at /home/petmay01/linaro/qemu-from-laptop/qemu/hw/core/qdev.c:978 #2 0x0000555555b567f0 in device_post_init (obj=0x555556b42600) at /home/petmay01/linaro/qemu-from-laptop/qemu/hw/core/qdev.c:989 #3 0x0000555555d97294 in object_post_init_with_type (obj=0x555556b42600, ti=0x5555569f7840) at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:365 #4 0x0000555555d972c2 in object_post_init_with_type (obj=0x555556b42600, ti=0x5555569f8640) at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:369 #5 0x0000555555d972c2 in object_post_init_with_type (obj=0x555556b42600, ti=0x555556a12c60) at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:369 #6 0x0000555555d97572 in object_initialize_with_type (data=0x555556b42600, size=1056, type=0x555556a12c60) at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:425 #7 0x0000555555d975b0 in object_initialize (data=0x555556b42600, size=1056, typename=0x555555ff3ee1 "armv7m_systick") at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:432 #8 0x0000555555d976fd in object_initialize_childv (parentobj=0x555556b40fa0, propname=0x555555ff3f36 "systick-reg-ns", childobj=0x555556b42600, size=1056, type=0x555555ff3ee1 "armv7m_systick", errp=0x5555569775f8 <error_abort>, vargs=0x7fffffffd7c0) at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:455 #9 0x0000555555d97689 in object_initialize_child (parentobj=0x555556b40fa0, propname=0x555555ff3f36 "systick-reg-ns", childobj=0x555556b42600, size=1056, type=0x555555ff3ee1 "armv7m_systick", errp=0x5555569775f8 <error_abort>) at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:442 #10 0x0000555555b5d049 in sysbus_init_child_obj (parent=0x555556b40fa0, childname=0x555555ff3f36 "systick-reg-ns", child=0x555556b42600, childsize=1056, childtype=0x555555ff3ee1 "armv7m_systick") at /home/petmay01/linaro/qemu-from-laptop/qemu/hw/core/sysbus.c:376 #11 0x00005555559231b0 in armv7m_nvic_instance_init (obj=0x555556b40fa0) at /home/petmay01/linaro/qemu-from-laptop/qemu/hw/intc/armv7m_nvic.c:2393 #12 0x0000555555d97263 in object_init_with_type (obj=0x555556b40fa0, ti=0x5555569cbce0) at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:358 #13 0x0000555555d9755f in object_initialize_with_type (data=0x555556b40fa0, size=7840, type=0x5555569cbce0) at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:424 #14 0x0000555555d975b0 in object_initialize (data=0x555556b40fa0, size=7840, typename=0x555556019af8 "armv7m_nvic") at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:432 #15 0x0000555555d976fd in object_initialize_childv (parentobj=0x555556b40c90, propname=0x555556019b04 "nvnic", childobj=0x555556b40fa0, size=7840, type=0x555556019af8 "armv7m_nvic", errp=0x5555569775f8 <error_abort>, vargs=0x7fffffffda90) at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:455 #16 0x0000555555d97689 in object_initialize_child (parentobj=0x555556b40c90, propname=0x555556019b04 "nvnic", childobj=0x555556b40fa0, size=7840, type=0x555556019af8 "armv7m_nvic", errp=0x5555569775f8 <error_abort>) at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:442 #17 0x0000555555b5d049 in sysbus_init_child_obj (parent=0x555556b40c90, childname=0x555556019b04 "nvnic", child=0x555556b40fa0, childsize=7840, childtype=0x555556019af8 "armv7m_nvic") at /home/petmay01/linaro/qemu-from-laptop/qemu/hw/core/sysbus.c:376 #18 0x00005555559c63ba in armv7m_instance_init (obj=0x555556b40c90) at /home/petmay01/linaro/qemu-from-laptop/qemu/hw/arm/armv7m.c:137 #19 0x0000555555d97263 in object_init_with_type (obj=0x555556b40c90, ti=0x5555569db4c0) at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:358 #20 0x0000555555d9755f in object_initialize_with_type (data=0x555556b40c90, size=11152, type=0x5555569db4c0) at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:424 #21 0x0000555555d975b0 in object_initialize (data=0x555556b40c90, size=11152, typename=0x555556022fd1 "armv7m") at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:432 #22 0x0000555555d976fd in object_initialize_childv (parentobj=0x555556b40980, propname=0x555556022fd1 "armv7m", childobj=0x555556b40c90, size=11152, type=0x555556022fd1 "armv7m", errp=0x5555569775f8 <error_abort>, vargs=0x7fffffffdd50) at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:455 #23 0x0000555555d97689 in object_initialize_child (parentobj=0x555556b40980, propname=0x555556022fd1 "armv7m", childobj=0x555556b40c90, size=11152, type=0x555556022fd1 "armv7m", errp=0x5555569775f8 <error_abort>) at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:442 #24 0x0000555555b5d049 in sysbus_init_child_obj (parent=0x555556b40980, childname=0x555556022fd1 "armv7m", child=0x555556b40c90, childsize=11152, childtype=0x555556022fd1 "armv7m") at /home/petmay01/linaro/qemu-from-laptop/qemu/hw/core/sysbus.c:376 #25 0x00005555559f3fdc in iotkit_init (obj=0x555556b40980) at /home/petmay01/linaro/qemu-from-laptop/qemu/hw/arm/iotkit.c:115 #26 0x0000555555d97263 in object_init_with_type (obj=0x555556b40980, ti=0x5555569df840) at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:358 #27 0x0000555555d9755f in object_initialize_with_type (data=0x555556b40980, size=50080, type=0x5555569df840) at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:424 #28 0x0000555555d97bb9 in object_new_with_type (type=0x5555569df840) at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:588 #29 0x0000555555d97bf6 in object_new (typename=0x555556a2b230 "iotkit") at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:598 #30 0x0000555555aafe8c in qmp_device_list_properties (typename=0x555556a2b230 "iotkit", errp=0x7fffffffe050) at /home/petmay01/linaro/qemu-from-laptop/qemu/qmp.c:519 #31 0x0000555555a8607a in qdev_device_help (opts=0x555556a2b1c0) at /home/petmay01/linaro/qemu-from-laptop/qemu/qdev-monitor.c:283 #32 0x0000555555a8f77e in device_help_func (opaque=0x0, opts=0x555556a2b1c0, errp=0x0) at /home/petmay01/linaro/qemu-from-laptop/qemu/vl.c:2299 #33 0x0000555555ef5b21 in qemu_opts_foreach (list=0x555556787040 <qemu_device_opts>, func=0x555555a8f75e <device_help_func>, opaque=0x0, errp=0x0) at /home/petmay01/linaro/qemu-from-laptop/qemu/util/qemu-option.c:1171 #34 0x0000555555a94310 in main (argc=5, argv=0x7fffffffe408, envp=0x7fffffffe438) at /home/petmay01/linaro/qemu-from-laptop/qemu/vl.c:4323 Looking at the backtrace, this seems to happen because in device_post_init we look at m->accelerator, but m->accelerator is only set when vl.c calls configure_accelerator(), so if this function gets called before then, it will cause an assert. In particular, the handling of -device foo,help happens before the accelerator is configured. (Possibly other things may cause device init before then too?) thanks -- PMM
Hi Peter On Mon, Jan 14, 2019 at 7:50 PM Peter Maydell <peter.maydell@linaro.org> wrote: > > On Mon, 7 Jan 2019 at 12:23, Marc-André Lureau > <marcandre.lureau@redhat.com> wrote: > > > > Instead of registering compat properties as globals, let's keep them > > in their own array, to avoid mixing with user globals. > > > > Introduce object_apply_global_props() function, to apply compatibility > > properties from a GPtrArray. > > > diff --git a/hw/core/qdev.c b/hw/core/qdev.c > > index 6b3cc55b27..53b507164f 100644 > > --- a/hw/core/qdev.c > > +++ b/hw/core/qdev.c > > @@ -972,6 +972,15 @@ static void device_initfn(Object *obj) > > > > static void device_post_init(Object *obj) > > { > > + if (object_dynamic_cast(qdev_get_machine(), TYPE_MACHINE)) { > > + MachineState *m = MACHINE(qdev_get_machine()); > > + AccelClass *ac = ACCEL_GET_CLASS(m->accelerator); > > + > > + if (ac->compat_props) { > > + object_apply_global_props(obj, ac->compat_props, &error_abort); > > + } > > + } > > + > > qdev_prop_set_globals(DEVICE(obj)); > > } > > > Hi; I've just noticed that this commit seems to break > "-device whatever,help" : [Qemu-devel] [PATCH] qdev: fix -device scsi-hd,help regression This should now be queued, afaik. > > $ gdb --args ./build/x86/arm-softmmu/qemu-system-arm -device iotkit,help -M virt > GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1 > [...] > (gdb) r > Starting program: > /home/petmay01/linaro/qemu-from-laptop/qemu/build/x86/arm-softmmu/qemu-system-arm > -device iotkit,help -M virt > [Thread debugging using libthread_db enabled] > Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". > [New Thread 0x7fffce6c1700 (LWP 23277)] > > Thread 1 "qemu-system-arm" received signal SIGSEGV, Segmentation fault. > 0x0000555555d985d1 in object_get_class (obj=0x0) > at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:857 > 857 return obj->class; > (gdb) bt > #0 0x0000555555d985d1 in object_get_class (obj=0x0) > at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:857 > #1 0x0000555555b5675d in object_apply_compat_props (obj=0x555556b42600) > at /home/petmay01/linaro/qemu-from-laptop/qemu/hw/core/qdev.c:978 > #2 0x0000555555b567f0 in device_post_init (obj=0x555556b42600) > at /home/petmay01/linaro/qemu-from-laptop/qemu/hw/core/qdev.c:989 > #3 0x0000555555d97294 in object_post_init_with_type > (obj=0x555556b42600, ti=0x5555569f7840) > at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:365 > #4 0x0000555555d972c2 in object_post_init_with_type > (obj=0x555556b42600, ti=0x5555569f8640) > at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:369 > #5 0x0000555555d972c2 in object_post_init_with_type > (obj=0x555556b42600, ti=0x555556a12c60) > at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:369 > #6 0x0000555555d97572 in object_initialize_with_type > (data=0x555556b42600, size=1056, type=0x555556a12c60) at > /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:425 > #7 0x0000555555d975b0 in object_initialize (data=0x555556b42600, > size=1056, typename=0x555555ff3ee1 "armv7m_systick") at > /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:432 > #8 0x0000555555d976fd in object_initialize_childv > (parentobj=0x555556b40fa0, propname=0x555555ff3f36 "systick-reg-ns", > childobj=0x555556b42600, size=1056, type=0x555555ff3ee1 > "armv7m_systick", errp=0x5555569775f8 <error_abort>, > vargs=0x7fffffffd7c0) > at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:455 > #9 0x0000555555d97689 in object_initialize_child > (parentobj=0x555556b40fa0, propname=0x555555ff3f36 "systick-reg-ns", > childobj=0x555556b42600, size=1056, type=0x555555ff3ee1 > "armv7m_systick", errp=0x5555569775f8 <error_abort>) at > /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:442 > #10 0x0000555555b5d049 in sysbus_init_child_obj > (parent=0x555556b40fa0, childname=0x555555ff3f36 "systick-reg-ns", > child=0x555556b42600, childsize=1056, childtype=0x555555ff3ee1 > "armv7m_systick") > at /home/petmay01/linaro/qemu-from-laptop/qemu/hw/core/sysbus.c:376 > #11 0x00005555559231b0 in armv7m_nvic_instance_init (obj=0x555556b40fa0) > at /home/petmay01/linaro/qemu-from-laptop/qemu/hw/intc/armv7m_nvic.c:2393 > #12 0x0000555555d97263 in object_init_with_type (obj=0x555556b40fa0, > ti=0x5555569cbce0) > at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:358 > #13 0x0000555555d9755f in object_initialize_with_type > (data=0x555556b40fa0, size=7840, type=0x5555569cbce0) at > /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:424 > #14 0x0000555555d975b0 in object_initialize (data=0x555556b40fa0, > size=7840, typename=0x555556019af8 "armv7m_nvic") at > /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:432 > #15 0x0000555555d976fd in object_initialize_childv > (parentobj=0x555556b40c90, propname=0x555556019b04 "nvnic", > childobj=0x555556b40fa0, size=7840, type=0x555556019af8 "armv7m_nvic", > errp=0x5555569775f8 <error_abort>, vargs=0x7fffffffda90) > at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:455 > #16 0x0000555555d97689 in object_initialize_child > (parentobj=0x555556b40c90, propname=0x555556019b04 "nvnic", > childobj=0x555556b40fa0, size=7840, type=0x555556019af8 "armv7m_nvic", > errp=0x5555569775f8 <error_abort>) at > /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:442 > #17 0x0000555555b5d049 in sysbus_init_child_obj > (parent=0x555556b40c90, childname=0x555556019b04 "nvnic", > child=0x555556b40fa0, childsize=7840, childtype=0x555556019af8 > "armv7m_nvic") > at /home/petmay01/linaro/qemu-from-laptop/qemu/hw/core/sysbus.c:376 > #18 0x00005555559c63ba in armv7m_instance_init (obj=0x555556b40c90) > at /home/petmay01/linaro/qemu-from-laptop/qemu/hw/arm/armv7m.c:137 > #19 0x0000555555d97263 in object_init_with_type (obj=0x555556b40c90, > ti=0x5555569db4c0) > at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:358 > #20 0x0000555555d9755f in object_initialize_with_type > (data=0x555556b40c90, size=11152, type=0x5555569db4c0) at > /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:424 > #21 0x0000555555d975b0 in object_initialize (data=0x555556b40c90, > size=11152, typename=0x555556022fd1 "armv7m") at > /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:432 > #22 0x0000555555d976fd in object_initialize_childv > (parentobj=0x555556b40980, propname=0x555556022fd1 "armv7m", > childobj=0x555556b40c90, size=11152, type=0x555556022fd1 "armv7m", > errp=0x5555569775f8 <error_abort>, vargs=0x7fffffffdd50) > at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:455 > #23 0x0000555555d97689 in object_initialize_child > (parentobj=0x555556b40980, propname=0x555556022fd1 "armv7m", > childobj=0x555556b40c90, size=11152, type=0x555556022fd1 "armv7m", > errp=0x5555569775f8 <error_abort>) at > /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:442 > #24 0x0000555555b5d049 in sysbus_init_child_obj > (parent=0x555556b40980, childname=0x555556022fd1 "armv7m", > child=0x555556b40c90, childsize=11152, childtype=0x555556022fd1 > "armv7m") > at /home/petmay01/linaro/qemu-from-laptop/qemu/hw/core/sysbus.c:376 > #25 0x00005555559f3fdc in iotkit_init (obj=0x555556b40980) > at /home/petmay01/linaro/qemu-from-laptop/qemu/hw/arm/iotkit.c:115 > #26 0x0000555555d97263 in object_init_with_type (obj=0x555556b40980, > ti=0x5555569df840) > at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:358 > #27 0x0000555555d9755f in object_initialize_with_type > (data=0x555556b40980, size=50080, type=0x5555569df840) at > /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:424 > #28 0x0000555555d97bb9 in object_new_with_type (type=0x5555569df840) > at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:588 > #29 0x0000555555d97bf6 in object_new (typename=0x555556a2b230 "iotkit") > at /home/petmay01/linaro/qemu-from-laptop/qemu/qom/object.c:598 > #30 0x0000555555aafe8c in qmp_device_list_properties > (typename=0x555556a2b230 "iotkit", errp=0x7fffffffe050) at > /home/petmay01/linaro/qemu-from-laptop/qemu/qmp.c:519 > #31 0x0000555555a8607a in qdev_device_help (opts=0x555556a2b1c0) > at /home/petmay01/linaro/qemu-from-laptop/qemu/qdev-monitor.c:283 > #32 0x0000555555a8f77e in device_help_func (opaque=0x0, > opts=0x555556a2b1c0, errp=0x0) > at /home/petmay01/linaro/qemu-from-laptop/qemu/vl.c:2299 > #33 0x0000555555ef5b21 in qemu_opts_foreach (list=0x555556787040 > <qemu_device_opts>, func=0x555555a8f75e <device_help_func>, > opaque=0x0, errp=0x0) > at /home/petmay01/linaro/qemu-from-laptop/qemu/util/qemu-option.c:1171 > #34 0x0000555555a94310 in main (argc=5, argv=0x7fffffffe408, > envp=0x7fffffffe438) > at /home/petmay01/linaro/qemu-from-laptop/qemu/vl.c:4323 > > Looking at the backtrace, this seems to happen because in > device_post_init we look at m->accelerator, but m->accelerator > is only set when vl.c calls configure_accelerator(), so if > this function gets called before then, it will cause an assert. > In particular, the handling of -device foo,help happens before the > accelerator is configured. (Possibly other things may cause > device init before then too?) > > thanks > -- PMM
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 92851e55df..84e612f473 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -267,6 +267,16 @@ typedef struct GlobalProperty { Error **errp; } GlobalProperty; +static inline void +compat_props_add(GPtrArray *arr, + GlobalProperty props[], size_t nelem) +{ + int i; + for (i = 0; i < nelem; i++) { + g_ptr_array_add(arr, (void *)&props[i]); + } +} + /*** Board API. This should go away once we have a machine config file. ***/ DeviceState *qdev_create(BusState *bus, const char *name); diff --git a/include/qom/object.h b/include/qom/object.h index bcae3f4951..e0262962b5 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -675,6 +675,9 @@ Object *object_new_with_propv(const char *typename, Error **errp, va_list vargs); +void object_apply_global_props(Object *obj, const GPtrArray *props, + Error **errp); + /** * object_set_props: * @obj: the object instance to set properties on diff --git a/include/sysemu/accel.h b/include/sysemu/accel.h index 637358f430..f331d128e9 100644 --- a/include/sysemu/accel.h +++ b/include/sysemu/accel.h @@ -49,7 +49,7 @@ typedef struct AccelClass { * global properties may be overridden by machine-type * compat_props or user-provided global properties. */ - GlobalProperty *global_props; + GPtrArray *compat_props; } AccelClass; #define TYPE_ACCEL "accel" @@ -67,8 +67,6 @@ typedef struct AccelClass { extern unsigned long tcg_tb_size; void configure_accelerator(MachineState *ms); -/* Register accelerator specific global properties */ -void accel_register_compat_props(AccelState *accel); /* Called just before os_setup_post (ie just before drop OS privs) */ void accel_setup_post(MachineState *ms); diff --git a/accel/accel.c b/accel/accel.c index 3da26eb90f..6db5d8f4df 100644 --- a/accel/accel.c +++ b/accel/accel.c @@ -119,18 +119,6 @@ void configure_accelerator(MachineState *ms) } } -void accel_register_compat_props(AccelState *accel) -{ - AccelClass *class = ACCEL_GET_CLASS(accel); - GlobalProperty *prop = class->global_props; - - for (; prop && prop->driver; prop++) { - /* Any compat_props must never cause error */ - prop->errp = &error_abort; - qdev_prop_register_global(prop); - } -} - void accel_setup_post(MachineState *ms) { AccelState *accel = ms->accelerator; diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 6b3cc55b27..53b507164f 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -972,6 +972,15 @@ static void device_initfn(Object *obj) static void device_post_init(Object *obj) { + if (object_dynamic_cast(qdev_get_machine(), TYPE_MACHINE)) { + MachineState *m = MACHINE(qdev_get_machine()); + AccelClass *ac = ACCEL_GET_CLASS(m->accelerator); + + if (ac->compat_props) { + object_apply_global_props(obj, ac->compat_props, &error_abort); + } + } + qdev_prop_set_globals(DEVICE(obj)); } diff --git a/hw/xen/xen-common.c b/hw/xen/xen-common.c index 6ec14c73ca..4532aa8632 100644 --- a/hw/xen/xen-common.c +++ b/hw/xen/xen-common.c @@ -174,18 +174,21 @@ static GlobalProperty xen_compat_props[] = { .driver = "migration", .property = "send-section-footer", .value = "off", - }, - { /* end of list */ }, + } }; static void xen_accel_class_init(ObjectClass *oc, void *data) { AccelClass *ac = ACCEL_CLASS(oc); + ac->name = "Xen"; ac->init_machine = xen_init; ac->setup_post = xen_setup_post; ac->allowed = &xen_allowed; - ac->global_props = xen_compat_props; + ac->compat_props = g_ptr_array_new(); + + compat_props_add(ac->compat_props, + xen_compat_props, G_N_ELEMENTS(xen_compat_props)); } #define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen") diff --git a/qom/object.c b/qom/object.c index 17921c0a71..dbdab0aead 100644 --- a/qom/object.c +++ b/qom/object.c @@ -370,6 +370,31 @@ static void object_post_init_with_type(Object *obj, TypeImpl *ti) } } +void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp) +{ + Error *err = NULL; + int i; + + if (!props) { + return; + } + + for (i = 0; i < props->len; i++) { + GlobalProperty *p = g_ptr_array_index(props, i); + + if (object_dynamic_cast(obj, p->driver) == NULL) { + continue; + } + p->used = true; + object_property_parse(obj, p->value, p->property, &err); + if (err != NULL) { + error_prepend(&err, "can't apply global %s.%s=%s: ", + p->driver, p->property, p->value); + error_propagate(errp, err); + } + } +} + static void object_initialize_with_type(void *data, size_t size, TypeImpl *type) { Object *obj = data; diff --git a/vl.c b/vl.c index 0db5ad0246..936d0c2587 100644 --- a/vl.c +++ b/vl.c @@ -2996,7 +2996,6 @@ static void user_register_global_props(void) */ static void register_global_properties(MachineState *ms) { - accel_register_compat_props(ms->accelerator); machine_register_compat_props(ms); user_register_global_props(); }