Split cpu_exec_init() into an init and a realize part
v4 cover Split cpu_exec_init() into an init and a realize part
Since commit 42ecaba ("target-i386: Call cpu_exec_init() on realize"), , commit 6dd0f83 ("target-ppc: Move cpu_exec_init() call to realize function"), and commit c6644fc ("s390x/cpu: Get rid of side effects when creating a vcpu"), cpu_exec_init() has been moved to realize function for some architectures to implement CPU htoplug. This allows any failures from cpu_exec_init() to be handled appropriately.
This series tries to do the same work for all the other CPUs.
But as the ARM Virtual Machine ("virt") needs the "memory" property of the CPU in the machine init function (the "memory" property is created in cpu_exec_init() we want to move to the realize part), split cpu_exec_init() in two parts: a realize part (cpu_exec_realizefn(), adding the CPU in the environment) and an init part (cpu_exec_initfn(), initializing the CPU, like adding the "memory" property). To mirror the realize part, add an unrealize part, and remove the cpu_exec_exit() call from the finalize part.
This also allows to remove all the "cannot_destroy_with_object_finalize_yet" properties from the CPU device class.
v4:
- arm: update mp_affinity in realize only if it s not set by the user
- i386 and ppc: add an parent_unrealize to call the Device unrealize because it is overwritten by the CPU unrealize
- update commit messages
v3:
- reorganize the series in 3 patches:
1- split cpu_exec_init() and call the init part from
cpu_common_initfn()
2- move all the cpu_exec_realize() calls to the
XXX_cpu_realizefn() functions
3- create a cpu_common_unrealizefn() function
and call the cpu_exec_unrealize() function from here, except for ppc64 and i386 that have their own XX_cpu_unrealizefn() functions
- rename cpu_exec_init(), cpu_exec_realize(), cpu_exec_unrealize() to cpu_exec_initfn(), cpu_exec_realizefn() and cpu_exec_unrealizefn(),
- move cpu_exec_unrealizefn() to the device class unrealize and declare it in qom/cpu.h instead of exec/exec-all.h
v2:
- rename cpu_exec_exit() as cpu_exec_unrealize(), as it un-does what cpu_exec_realize() does,
- remove cpu_exec_exit() from ppc_cpu_unrealizefn() as it is called from cpu_common_finalize(),
- add a patch to move all cpu_exec_init() from all XX_cpu_initfn() to cpu_common_initfn(),
- arm: move setting of cpu->mp_affinity to arm_cpu_realizefn() as the cpu_index is now set in cpu_exec_realizefn().
- update some commit messages
Laurent Vivier (3):
exec: split cpu_exec_init()
exec: move cpu_exec_init() calls to realize functions
exec: call cpu_exec_exit() from a CPU unrealize common function
exec.c | 12 +++++++----- include/exec/exec-all.h | 1 - include/qom/cpu.h | 4 +++- qom/cpu.c | 10 +++++++++- target-alpha/cpu.c | 15 +++++++-------- target-arm/cpu.c | 45 ++++++++++++++++++++++----------------------- target-cris/cpu.c | 15 +++++++-------- target-i386/cpu-qom.h | 1 + target-i386/cpu.c | 20 ++++++++++++++------ target-lm32/cpu.c | 15 +++++++-------- target-m68k/cpu.c | 15 +++++++-------- target-microblaze/cpu.c | 14 +++++++------- target-mips/cpu.c | 15 +++++++-------- target-moxie/cpu.c | 15 +++++++-------- target-openrisc/cpu.c | 15 +++++++-------- target-ppc/cpu-qom.h | 1 + target-ppc/translate_init.c | 11 +++++++++-- target-s390x/cpu.c | 8 +------- target-sh4/cpu.c | 15 +++++++-------- target-sparc/cpu.c | 18 +++++++++--------- target-tilegx/cpu.c | 15 +++++++-------- target-tricore/cpu.c | 15 +++++++-------- target-unicore32/cpu.c | 18 +++++++++--------- target-xtensa/cpu.c | 15 +++++++-------- 24 files changed, 169 insertions(+), 159 deletions(-)
Signature · 1 line
2.7.4
PATCH v4 1/3 exec: split cpu_exec_init()
Put in cpu_exec_initfn() what initializes the CPU, and leave in cpu_exec_init() what adds it to the environment.
As cpu_exec_initfn() is called by all XX_cpu_initfn(), call it directly in cpu_common_initfn().cpu_exec_init() is now a realize function, it will be renamed to cpu_exec_realizefn() and moved to the XX_cpu_realizefn() function in a following patch.
--- exec.c | 10 ++++++---- include/qom/cpu.h | 1 + qom/cpu.c | 2 ++ 3 files changed, 9 insertions(+), 4 deletions(-)
exec.c +6 -4
@@ -610,11 +610,8 @@ void cpu_exec_exit(CPUState *cpu) } } -void cpu_exec_init (CPUState *cpu,Error **errp) +void cpu_exec_initfn (CPUState *cpu) { - CPUClass *cc ATTRIBUTE_UNUSED = CPU_GET_CLASS(cpu); - Error *local_err ATTRIBUTE_UNUSED = NULL; - cpu->as =NULL ; cpu->num_ases =0 ;
@@ -635,6 +632,11 @@ void cpu_exec_init(CPUState *cpu, Error **errp) cpu->memory = system_memory;object_ref (OBJECT (cpu->memory));#endif +} + +void cpu_exec_init (CPUState *cpu,Error **errp) +{ + CPUClass *cc ATTRIBUTE_UNUSED = CPU_GET_CLASS(cpu);cpu_list_add (cpu);
include/qom/cpu.h +1 -0
@@ -946,6 +946,7 @@ AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx); void QEMU_NORETURN cpu_abort(CPUState *cpu, const char *fmt, ...) GCC_FMT_ATTR(2, 3); +void cpu_exec_initfn(CPUState *cpu);void cpu_exec_exit (CPUState *cpu);#ifdef CONFIG_SOFTMMU
qom/cpu.c +2 -0
@@ -362,6 +362,8 @@ static void cpu_common_initfn(Object *obj)QTAILQ_INIT (&cpu->watchpoints); cpu->trace_dstate =bitmap_new (trace_get_vcpu_event_count ()); + +cpu_exec_initfn (cpu); }static void cpu_common_finalize (Object *obj)
Signature · 1 line
2.7.4
PATCH v4 2/3 exec: move cpu_exec_init() calls to realize functions
In reply to Laurent VivierModify all CPUs to call it from XXX_cpu_realizefn() function.
Remove all the cannot_destroy_with_object_finalize_yet as unsafe references have been moved to cpu_exec_realizefn(). (tested with QOM command provided by commit 4c315c27)
for arm:
Setting of cpu->mp_affinity is moved from arm_cpu_initfn() to arm_cpu_realizefn() as setting of cpu_index is now done in cpu_exec_realizefn(). To avoid to overwrite an user defined value, we set it to an invalid value by default, and update it in realize function only if the value is still invalid.
--- exec.c | 2 +- include/exec/exec-all.h | 1 - include/qom/cpu.h | 1 + target-alpha/cpu.c | 15 +++++++-------- target-arm/cpu.c | 45 ++++++++++++++++++++++----------------------- target-cris/cpu.c | 15 +++++++-------- target-i386/cpu.c | 11 +++++------ target-lm32/cpu.c | 15 +++++++-------- target-m68k/cpu.c | 15 +++++++-------- target-microblaze/cpu.c | 14 +++++++------- target-mips/cpu.c | 15 +++++++-------- target-moxie/cpu.c | 15 +++++++-------- target-openrisc/cpu.c | 15 +++++++-------- target-ppc/translate_init.c | 2 +- target-s390x/cpu.c | 8 +------- target-sh4/cpu.c | 15 +++++++-------- target-sparc/cpu.c | 18 +++++++++--------- target-tilegx/cpu.c | 15 +++++++-------- target-tricore/cpu.c | 15 +++++++-------- target-unicore32/cpu.c | 18 +++++++++--------- target-xtensa/cpu.c | 15 +++++++-------- 21 files changed, 133 insertions(+), 152 deletions(-)
exec.c +1 -1
@@ -634,7 +634,7 @@ void cpu_exec_initfn(CPUState *cpu)#endif } -void cpu_exec_init (CPUState *cpu,Error **errp) +void cpu_exec_realizefn (CPUState *cpu,Error **errp) { CPUClass *cc ATTRIBUTE_UNUSED = CPU_GET_CLASS(cpu);
include/exec/exec-all.h +0 -1
@@ -57,7 +57,6 @@ TranslationBlock *tb_gen_code(CPUState *cpu,uint32_t flags, int cflags); -void cpu_exec_init (CPUState *cpu,Error **errp); void QEMU_NORETURN cpu_loop_exit(CPUState *cpu); void QEMU_NORETURN cpu_loop_exit_restore(CPUState *cpu, uintptr_t pc);
include/qom/cpu.h +1 -0
@@ -947,6 +947,7 @@ AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx); void QEMU_NORETURN cpu_abort(CPUState *cpu, const char *fmt, ...) GCC_FMT_ATTR(2, 3); void cpu_exec_initfn(CPUState *cpu); +void cpu_exec_realizefn (CPUState *cpu,Error **errp);void cpu_exec_exit (CPUState *cpu);#ifdef CONFIG_SOFTMMU
target-alpha/cpu.c +7 -8
@@ -59,6 +59,13 @@ static void alpha_cpu_realizefn(DeviceState *dev, Error **errp) {CPUState *cs =CPU (dev);AlphaCPUClass *acc =ALPHA_CPU_GET_CLASS (dev); +Error *local_err =NULL ; + +cpu_exec_realizefn (cs, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; + }qemu_init_vcpu (cs);
@@ -266,7 +273,6 @@ static void alpha_cpu_initfn(Object *obj)CPUAlphaState *env = &cpu->env; cs->env_ptr = env; -cpu_exec_init (cs, &error_abort);tlb_flush (cs,1 );alpha_translate_init ();
@@ -309,13 +315,6 @@ static void alpha_cpu_class_init(ObjectClass *oc, void *data) cc->disas_set_info = alpha_cpu_disas_set_info; cc->gdb_num_core_regs =67 ; - -/* -* Reason: alpha_cpu_initfn() calls cpu_exec_init(), which saves -* the object in cpus -> dangling pointer after final -* object_unref(). -*/ - dc->cannot_destroy_with_object_finalize_yet = true; }static const TypeInfo alpha_cpu_type_info = {
target-arm/cpu.c +22 -23
86 lines not on this page · raw message
target-cris/cpu.c +7 -8
@@ -142,6 +142,13 @@ static void cris_cpu_realizefn(DeviceState *dev, Error **errp) {CPUState *cs =CPU (dev);CRISCPUClass *ccc =CRIS_CPU_GET_CLASS (dev); +Error *local_err =NULL ; + +cpu_exec_realizefn (cs, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; + }cpu_reset (cs);qemu_init_vcpu (cs);
@@ -187,7 +194,6 @@ static void cris_cpu_initfn(Object *obj)static bool tcg_initialized; cs->env_ptr = env; -cpu_exec_init (cs, &error_abort); env->pregs[PR_VR ] = ccc->vr;
@@ -326,13 +332,6 @@ static void cris_cpu_class_init(ObjectClass *oc, void *data) cc->gdb_stop_before_watchpoint = true; cc->disas_set_info = cris_disas_set_info; - -/* -* Reason: cris_cpu_initfn() calls cpu_exec_init(), which saves -* the object in cpus -> dangling pointer after final -* object_unref(). -*/ - dc->cannot_destroy_with_object_finalize_yet = true; }static const TypeInfo cris_cpu_type_info = {
target-i386/cpu.c +5 -6
@@ -3158,7 +3158,11 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) cpu->phys_bits =32 ; } } -cpu_exec_init (cs, &error_abort); +cpu_exec_realizefn (cs, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; + }if (tcg_enabled ()) {tcg_x86_init ();
@@ -3537,11 +3541,6 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data) cc->cpu_exec_exit = x86_cpu_exec_exit; dc->cannot_instantiate_with_device_add_yet = false; -/* -* Reason: x86_cpu_initfn() calls cpu_exec_init(), which saves the -* object in cpus -> dangling pointer after final object_unref(). -*/ - dc->cannot_destroy_with_object_finalize_yet = true; }static const TypeInfo x86_cpu_type_info = {
target-lm32/cpu.c +7 -8
@@ -144,6 +144,13 @@ static void lm32_cpu_realizefn(DeviceState *dev, Error **errp) {CPUState *cs =CPU (dev);LM32CPUClass *lcc =LM32_CPU_GET_CLASS (dev); +Error *local_err =NULL ; + +cpu_exec_realizefn (cs, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; + }cpu_reset (cs);
@@ -160,7 +167,6 @@ static void lm32_cpu_initfn(Object *obj)static bool tcg_initialized; cs->env_ptr = env; -cpu_exec_init (cs, &error_abort); env->flags =0 ;
@@ -285,13 +291,6 @@ static void lm32_cpu_class_init(ObjectClass *oc, void *data) cc->gdb_stop_before_watchpoint = true; cc->debug_excp_handler = lm32_debug_excp_handler; cc->disas_set_info = lm32_cpu_disas_set_info; - -/* -* Reason: lm32_cpu_initfn() calls cpu_exec_init(), which saves -* the object in cpus -> dangling pointer after final -* object_unref(). -*/ - dc->cannot_destroy_with_object_finalize_yet = true; }static void lm32_register_cpu_type (const LM32CPUInfo *info)
target-m68k/cpu.c +7 -8
@@ -159,6 +159,13 @@ static void m68k_cpu_realizefn(DeviceState *dev, Error **errp)CPUState *cs =CPU (dev);M68kCPU *cpu =M68K_CPU (dev);M68kCPUClass *mcc =M68K_CPU_GET_CLASS (dev); +Error *local_err =NULL ; + +cpu_exec_realizefn (cs, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; + }m68k_cpu_init_gdb (cpu);
@@ -176,7 +183,6 @@ static void m68k_cpu_initfn(Object *obj)static bool inited; cs->env_ptr = env; -cpu_exec_init (cs, &error_abort);if (tcg_enabled () && !inited) { inited = true;
@@ -222,13 +228,6 @@ static void m68k_cpu_class_init(ObjectClass *c, void *data) cc->gdb_core_xml_file ="cf-core.xml" ; dc->vmsd = &vmstate_m68k_cpu; - -/* -* Reason: m68k_cpu_initfn() calls cpu_exec_init(), which saves -* the object in cpus -> dangling pointer after final -* object_unref(). -*/ - dc->cannot_destroy_with_object_finalize_yet = true; }static void register_cpu_type (const M68kCPUInfo *info)
target-microblaze/cpu.c +7 -7
@@ -138,6 +138,13 @@ static void mb_cpu_realizefn(DeviceState *dev, Error **errp)CPUMBState *env = &cpu->env;uint8_t version_code =0 ;int i =0 ; +Error *local_err =NULL ; + +cpu_exec_realizefn (cs, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; + }qemu_init_vcpu (cs);
@@ -199,7 +206,6 @@ static void mb_cpu_initfn(Object *obj)static bool tcg_initialized; cs->env_ptr = env; -cpu_exec_init (cs, &error_abort);set_float_rounding_mode (float_round_nearest_even, &env->fp_status);
@@ -267,12 +273,6 @@ static void mb_cpu_class_init(ObjectClass *oc, void *data) cc->gdb_num_core_regs =32 +5 ; cc->disas_set_info = mb_disas_set_info; - -/* -* Reason: mb_cpu_initfn() calls cpu_exec_init(), which saves the -* object in cpus -> dangling pointer after final object_unref(). -*/ - dc->cannot_destroy_with_object_finalize_yet = true; }static const TypeInfo mb_cpu_type_info = {
target-mips/cpu.c +7 -8
@@ -124,6 +124,13 @@ static void mips_cpu_realizefn(DeviceState *dev, Error **errp) {CPUState *cs =CPU (dev);MIPSCPUClass *mcc =MIPS_CPU_GET_CLASS (dev); +Error *local_err =NULL ; + +cpu_exec_realizefn (cs, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; + }cpu_reset (cs);qemu_init_vcpu (cs);
@@ -138,7 +145,6 @@ static void mips_cpu_initfn(Object *obj)CPUMIPSState *env = &cpu->env; cs->env_ptr = env; -cpu_exec_init (cs, &error_abort);if (tcg_enabled ()) {mips_tcg_init ();
@@ -177,13 +183,6 @@ static void mips_cpu_class_init(ObjectClass *c, void *data) cc->gdb_num_core_regs =73 ; cc->gdb_stop_before_watchpoint = true; - -/* -* Reason: mips_cpu_initfn() calls cpu_exec_init(), which saves -* the object in cpus -> dangling pointer after final -* object_unref(). -*/ - dc->cannot_destroy_with_object_finalize_yet = true; }static const TypeInfo mips_cpu_type_info = {
target-moxie/cpu.c +7 -8
@@ -61,6 +61,13 @@ static void moxie_cpu_realizefn(DeviceState *dev, Error **errp) {CPUState *cs =CPU (dev);MoxieCPUClass *mcc =MOXIE_CPU_GET_CLASS (dev); +Error *local_err =NULL ; + +cpu_exec_realizefn (cs, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; + }qemu_init_vcpu (cs);cpu_reset (cs);
@@ -75,7 +82,6 @@ static void moxie_cpu_initfn(Object *obj)static int inited; cs->env_ptr = &cpu->env; -cpu_exec_init (cs, &error_abort);if (tcg_enabled () && !inited) { inited =1 ;
@@ -124,13 +130,6 @@ static void moxie_cpu_class_init(ObjectClass *oc, void *data) cc->vmsd = &vmstate_moxie_cpu;#endif cc->disas_set_info = moxie_cpu_disas_set_info; - -/* -* Reason: moxie_cpu_initfn() calls cpu_exec_init(), which saves -* the object in cpus -> dangling pointer after final -* object_unref(). -*/ - dc->cannot_destroy_with_object_finalize_yet = true; }static void moxielite_initfn (Object *obj)
target-openrisc/cpu.c +7 -8
@@ -81,6 +81,13 @@ static void openrisc_cpu_realizefn(DeviceState *dev, Error **errp) {CPUState *cs =CPU (dev);OpenRISCCPUClass *occ =OPENRISC_CPU_GET_CLASS (dev); +Error *local_err =NULL ; + +cpu_exec_realizefn (cs, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; + }qemu_init_vcpu (cs);cpu_reset (cs);
@@ -95,7 +102,6 @@ static void openrisc_cpu_initfn(Object *obj)static int inited; cs->env_ptr = &cpu->env; -cpu_exec_init (cs, &error_abort);#ifndef CONFIG_USER_ONLY cpu_openrisc_mmu_init (cpu);
@@ -180,13 +186,6 @@ static void openrisc_cpu_class_init(ObjectClass *oc, void *data) dc->vmsd = &vmstate_openrisc_cpu;#endif cc->gdb_num_core_regs =32 +3 ; - -/* -* Reason: openrisc_cpu_initfn() calls cpu_exec_init(), which saves -* the object in cpus -> dangling pointer after final -* object_unref(). -*/ - dc->cannot_destroy_with_object_finalize_yet = true; }static void cpu_register (const OpenRISCCPUInfo *info)
target-ppc/translate_init.c +1 -1
@@ -9678,7 +9678,7 @@ static void ppc_cpu_realizefn(DeviceState *dev, Error **errp) }#endif -cpu_exec_init (cs, &local_err); +cpu_exec_realizefn (cs, &local_err);if (local_err !=NULL ) {error_propagate (errp, local_err);return ;
target-s390x/cpu.c +1 -7
@@ -207,7 +207,7 @@ static void s390_cpu_realizefn(DeviceState *dev, Error **errp) goto out; } -cpu_exec_init (cs, &err); +cpu_exec_realizefn (cs, &err);if (err !=NULL ) { goto out; }
@@ -440,12 +440,6 @@ static void s390_cpu_class_init(ObjectClass *oc, void *data) cc->gdb_core_xml_file ="s390x-core64.xml" ; cc->gdb_arch_name = s390_gdb_arch_name; -/* -* Reason: s390_cpu_realizefn() calls cpu_exec_init(), which saves -* the object in cpus -> dangling pointer after final -* object_unref(). -*/ - dc->cannot_destroy_with_object_finalize_yet = true;s390_cpu_model_class_register_props (oc); }
target-sh4/cpu.c +7 -8
@@ -244,6 +244,13 @@ static void superh_cpu_realizefn(DeviceState *dev, Error **errp) {CPUState *cs =CPU (dev);SuperHCPUClass *scc =SUPERH_CPU_GET_CLASS (dev); +Error *local_err =NULL ; + +cpu_exec_realizefn (cs, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; + }cpu_reset (cs);qemu_init_vcpu (cs);
@@ -258,7 +265,6 @@ static void superh_cpu_initfn(Object *obj)CPUSH4State *env = &cpu->env; cs->env_ptr = env; -cpu_exec_init (cs, &error_abort); env->movcal_backup_tail = &(env->movcal_backup);
@@ -303,13 +309,6 @@ static void superh_cpu_class_init(ObjectClass *oc, void *data) cc->gdb_num_core_regs =59 ; dc->vmsd = &vmstate_sh_cpu; - -/* -* Reason: superh_cpu_initfn() calls cpu_exec_init(), which saves -* the object in cpus -> dangling pointer after final -* object_unref(). -*/ - dc->cannot_destroy_with_object_finalize_yet = true; }static const TypeInfo superh_cpu_type_info = {
target-sparc/cpu.c +9 -9
@@ -792,7 +792,9 @@ static bool sparc_cpu_has_work(CPUState *cs)static void sparc_cpu_realizefn (DeviceState *dev,Error **errp) { +CPUState *cs =CPU (dev);SPARCCPUClass *scc =SPARC_CPU_GET_CLASS (dev); +Error *local_err =NULL ;#if defined(CONFIG_USER_ONLY )SPARCCPU *cpu =SPARC_CPU (dev);CPUSPARCState *env = &cpu->env;
@@ -802,7 +804,13 @@ static void sparc_cpu_realizefn(DeviceState *dev, Error **errp) }#endif -qemu_init_vcpu (CPU (dev)); +cpu_exec_realizefn (cs, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; + } + +qemu_init_vcpu (cs); scc->parent_realize (dev, errp); }
@@ -814,7 +822,6 @@ static void sparc_cpu_initfn(Object *obj)CPUSPARCState *env = &cpu->env; cs->env_ptr = env; -cpu_exec_init (cs, &error_abort);if (tcg_enabled ()) {gen_intermediate_code_init (env);
@@ -867,13 +874,6 @@ static void sparc_cpu_class_init(ObjectClass *oc, void *data)#else cc->gdb_num_core_regs =72 ;#endif - -/* -* Reason: sparc_cpu_initfn() calls cpu_exec_init(), which saves -* the object in cpus -> dangling pointer after final -* object_unref(). -*/ - dc->cannot_destroy_with_object_finalize_yet = true; }static const TypeInfo sparc_cpu_type_info = {
target-tilegx/cpu.c +7 -8
@@ -92,6 +92,13 @@ static void tilegx_cpu_realizefn(DeviceState *dev, Error **errp) {CPUState *cs =CPU (dev);TileGXCPUClass *tcc =TILEGX_CPU_GET_CLASS (dev); +Error *local_err =NULL ; + +cpu_exec_realizefn (cs, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; + }cpu_reset (cs);qemu_init_vcpu (cs);
@@ -107,7 +114,6 @@ static void tilegx_cpu_initfn(Object *obj)static bool tcg_initialized; cs->env_ptr = env; -cpu_exec_init (cs, &error_abort);if (tcg_enabled () && !tcg_initialized) { tcg_initialized = true;
@@ -162,13 +168,6 @@ static void tilegx_cpu_class_init(ObjectClass *oc, void *data) cc->set_pc = tilegx_cpu_set_pc; cc->handle_mmu_fault = tilegx_cpu_handle_mmu_fault; cc->gdb_num_core_regs =0 ; - -/* -* Reason: tilegx_cpu_initfn() calls cpu_exec_init(), which saves -* the object in cpus -> dangling pointer after final -* object_unref(). -*/ - dc->cannot_destroy_with_object_finalize_yet = true; }static const TypeInfo tilegx_cpu_type_info = {
target-tricore/cpu.c +7 -8
@@ -69,6 +69,13 @@ static void tricore_cpu_realizefn(DeviceState *dev, Error **errp)TriCoreCPU *cpu =TRICORE_CPU (dev);TriCoreCPUClass *tcc =TRICORE_CPU_GET_CLASS (dev);CPUTriCoreState *env = &cpu->env; +Error *local_err =NULL ; + +cpu_exec_realizefn (cs, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; + }/* Some features automatically imply others */ if (tricore_feature (env,TRICORE_FEATURE_161 )) {
@@ -95,7 +102,6 @@ static void tricore_cpu_initfn(Object *obj)CPUTriCoreState *env = &cpu->env; cs->env_ptr = env; -cpu_exec_init (cs, &error_abort);if (tcg_enabled ()) {tricore_tcg_init ();
@@ -172,13 +178,6 @@ static void tricore_cpu_class_init(ObjectClass *c, void *data) cc->dump_state = tricore_cpu_dump_state; cc->set_pc = tricore_cpu_set_pc; cc->synchronize_from_tb = tricore_cpu_synchronize_from_tb; - -/* -* Reason: tricore_cpu_initfn() calls cpu_exec_init(), which saves -* the object in cpus -> dangling pointer after final -* object_unref(). -*/ - dc->cannot_destroy_with_object_finalize_yet = true; }static void cpu_register (const TriCoreCPUInfo *info)
target-unicore32/cpu.c +9 -9
@@ -101,9 +101,17 @@ static const UniCore32CPUInfo uc32_cpus[] = {static void uc32_cpu_realizefn (DeviceState *dev,Error **errp) { +CPUState *cs =CPU (dev);UniCore32CPUClass *ucc =UNICORE32_CPU_GET_CLASS (dev); +Error *local_err =NULL ; -qemu_init_vcpu (CPU (dev)); +cpu_exec_realizefn (cs, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; + } + +qemu_init_vcpu (cs); ucc->parent_realize (dev, errp); }
@@ -116,7 +124,6 @@ static void uc32_cpu_initfn(Object *obj)static bool inited; cs->env_ptr = env; -cpu_exec_init (cs, &error_abort);#ifdef CONFIG_USER_ONLY env->uncached_asr =ASR_MODE_USER ;
@@ -160,13 +167,6 @@ static void uc32_cpu_class_init(ObjectClass *oc, void *data) cc->get_phys_page_debug = uc32_cpu_get_phys_page_debug;#endif dc->vmsd = &vmstate_uc32_cpu; - -/* -* Reason: uc32_cpu_initfn() calls cpu_exec_init(), which saves -* the object in cpus -> dangling pointer after final -* object_unref(). -*/ - dc->cannot_destroy_with_object_finalize_yet = true; }static void uc32_register_cpu_type (const UniCore32CPUInfo *info)
target-xtensa/cpu.c +7 -8
@@ -99,6 +99,13 @@ static void xtensa_cpu_realizefn(DeviceState *dev, Error **errp) {CPUState *cs =CPU (dev);XtensaCPUClass *xcc =XTENSA_CPU_GET_CLASS (dev); +Error *local_err =NULL ; + +cpu_exec_realizefn (cs, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; + } cs->gdb_num_regs = xcc->config->gdb_regmap.num_regs;
@@ -117,7 +124,6 @@ static void xtensa_cpu_initfn(Object *obj) cs->env_ptr = env; env->config = xcc->config; -cpu_exec_init (cs, &error_abort);if (tcg_enabled () && !tcg_inited) { tcg_inited = true;
@@ -158,13 +164,6 @@ static void xtensa_cpu_class_init(ObjectClass *oc, void *data)#endif cc->debug_excp_handler = xtensa_breakpoint_handler; dc->vmsd = &vmstate_xtensa_cpu; - -/* -* Reason: xtensa_cpu_initfn() calls cpu_exec_init(), which saves -* the object in cpus -> dangling pointer after final -* object_unref(). -*/ - dc->cannot_destroy_with_object_finalize_yet = true; }static const TypeInfo xtensa_cpu_type_info = {
Signature · 1 line
2.7.4
Re: [Qemu-arm] [Qemu-devel] [PATCH v4 2/3] exec: move cpu_exec_init() calls to realize functions
Quoted 18 lines · Laurent Vivier
Modify all CPUs to call it from
XXX_cpu_realizefn()function.Remove all the
cannot_destroy_with_object_finalize_yetas unsafe references have been moved tocpu_exec_realizefn(). (tested with QOM command provided by commit4c315c27)for arm:
Setting of
cpu->mp_affinityis moved fromarm_cpu_initfn()toarm_cpu_realizefn()as setting ofcpu_indexis now done incpu_exec_realizefn(). To avoid to overwrite an user defined value, we set it to an invalid value by default, and update it in realize function only if the value is still invalid.Signed-off-by Laurent Vivier <[email protected]>Reviewed-by David Gibson <[email protected]>Reviewed-by Igor Mammedov <[email protected]>---
[...]
target-arm/cpu.c line 36
Quoted 9 lines
target-arm/cpu.c +1
-0@@ -33,6 +33,8 @@#include "sysemu/kvm.h" #include "kvm_arm.h" +#define MP_AFFINITY_INVALID (~ARM64_AFFINITY_MASK)
I would have defined this next to ARM64_AFFINITY_MASK in target-arm/cpu-qom.h
Quoted 44 lines
target-arm/cpu.c +9
-11+static void arm_cpu_set_pc (CPUState *cs,vaddr value) {ARMCPU *cpu =ARM_CPU (cs);@@ -441,22 +443,11 @@ static void arm_cpu_initfn(Object *obj)CPUState *cs =CPU (obj);ARMCPU *cpu =ARM_CPU (obj);static bool inited; -uint32_t Aff1, Aff0; cs->env_ptr = &cpu->env; -cpu_exec_init (cs, &error_abort); cpu->cp_regs =g_hash_table_new_full (g_int_hash, g_int_equal, g_free, g_free); -/* This cpu-id-to-MPIDR affinity is used only for TCG; KVM will override it. -* We don't support setting cluster ID ([16..23]) (known as Aff2 -* in later ARM ARM versions), or any of the higher affinity level fields, -* so these bits always RAZ. -*/ - Aff1 = cs->cpu_index /ARM_CPUS_PER_CLUSTER ; - Aff0 = cs->cpu_index %ARM_CPUS_PER_CLUSTER ; - cpu->mp_affinity = (Aff1 <<ARM_AFF1_SHIFT ) | Aff0; -#ifndef CONFIG_USER_ONLY /* Our inbound IRQ and FIQ lines */ if (kvm_enabled ()) {@@ -576,6 +567,14 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)ARMCPU *cpu =ARM_CPU (dev);ARMCPUClass *acc =ARM_CPU_GET_CLASS (dev);CPUARMState *env = &cpu->env; +Error *local_err =NULL ; +uint32_t Aff1, Aff0; + +cpu_exec_realizefn (cs, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; + }/* Some features automatically imply others: */ if (arm_feature (env,ARM_FEATURE_V8 )) {@@ -631,6 +630,17 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)set_feature (env,ARM_FEATURE_THUMB_DSP );
target-arm/cpu.c static void arm_cpu_realizefn(DeviceState *dev, Error **errp) · line 640
Quoted 10 lines
target-arm/cpu.c +8
-0} +/* This cpu-id-to-MPIDR affinity is used only for TCG; KVM will override it. +* We don't support setting cluster ID ([16..23]) (known as Aff2 +* in later ARM ARM versions), or any of the higher affinity level fields, +* so these bits always RAZ. +*/ +if (cpu->mp_affinity ==MP_AFFINITY_INVALID ) { + Aff1 = cs->cpu_index /ARM_CPUS_PER_CLUSTER ; + Aff0 = cs->cpu_index %ARM_CPUS_PER_CLUSTER ;
I think ARM_CPUS_PER_CLUSTER should be renamed to ARM_DEFAULT_CPUS_PER_CLUSTER and either moved from where it's currently defined (above arm_cpu_initfn) to just above arm_cpu_realizefn, or to the same place as ARM64_AFFINITY_MASK and MP_AFFINITY_INVALID.
Aff0 and Aff1 could be declared in this scope, as they're only used here.
Quoted 23 lines
target-arm/cpu.c +4
-5+ cpu->mp_affinity = (Aff1 <<ARM_AFF1_SHIFT ) | Aff0; + } +if (cpu->reset_hivecs) { cpu->reset_sctlr |= (1 <<13 ); }@@ -1461,7 +1471,7 @@ static Property arm_cpu_properties[] = {DEFINE_PROP_BOOL ("start-powered-off" ,ARMCPU , start_powered_off, false),DEFINE_PROP_UINT32 ("psci-conduit" ,ARMCPU , psci_conduit,0 ),DEFINE_PROP_UINT32 ("midr" ,ARMCPU , midr,0 ), -DEFINE_PROP_UINT64 ("mp-affinity" ,ARMCPU , mp_affinity,0 ), +DEFINE_PROP_UINT64 ("mp-affinity" ,ARMCPU , mp_affinity,MP_AFFINITY_INVALID ), DEFINE_PROP_END_OF_LIST() };@@ -1533,17 +1543,6 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data) cc->debug_check_watchpoint = arm_debug_check_watchpoint; cc->disas_set_info = arm_disas_set_info; - -/* -* Reason: arm_cpu_initfn() calls cpu_exec_init(), which saves -* the object in cpus -> dangling pointer after final
target-arm/cpu.c static void arm_cpu_class_init(ObjectClass *oc, void *data) · line 1548
Quoted 10 lines
target-arm/cpu.c +0
-7-* object_unref(). -* -* Once this is fixed, the devices that create ARM CPUs should be -* updated not to set cannot_destroy_with_object_finalize_yet, -* unless they still screw up something else. -*/ - dc->cannot_destroy_with_object_finalize_yet = true; }static void cpu_register (const ARMCPUInfo *info)
[...]
Otherwise looks good to me.
Thanks,
drew
Re: [Qemu-arm] [Qemu-devel] [PATCH v4 2/3] exec: move cpu_exec_init() calls to realize functions
Quoted 28 lines · Andrew Jones
Quoted 18 lines · Laurent Vivier
Modify all CPUs to call it from
XXX_cpu_realizefn()function.Remove all the
cannot_destroy_with_object_finalize_yetas unsafe references have been moved tocpu_exec_realizefn(). (tested with QOM command provided by commit4c315c27)for arm:
Setting of
cpu->mp_affinityis moved fromarm_cpu_initfn()toarm_cpu_realizefn()as setting ofcpu_indexis now done incpu_exec_realizefn(). To avoid to overwrite an user defined value, we set it to an invalid value by default, and update it in realize function only if the value is still invalid.Signed-off-by Laurent Vivier <[email protected]>Reviewed-by David Gibson <[email protected]>Reviewed-by Igor Mammedov <[email protected]>---
[...]
Quoted 8 lines
target-arm/cpu.c +0
-0@@ -33,6 +33,8 @@#include "sysemu/kvm.h" #include "kvm_arm.h"
Quoted 4 lines
target-arm/cpu.c line 36
Quoted 1 line
target-arm/cpu.c +1
-0+#define MP_AFFINITY_INVALID (~ARM64_AFFINITY_MASK)I would have defined this next to
ARM64_AFFINITY_MASKintarget-arm/cpu-qom.h
It was my first idea, but all macros in cpu-qom.h start by ARM_ or ARM64_, this one looks like a local macro (the name is too generic), so I put it in cpu.c.
Quoted 61 lines
Quoted 44 lines
target-arm/cpu.c +9
-11+static void arm_cpu_set_pc (CPUState *cs,vaddr value) {ARMCPU *cpu =ARM_CPU (cs);@@ -441,22 +443,11 @@ static void arm_cpu_initfn(Object *obj)CPUState *cs =CPU (obj);ARMCPU *cpu =ARM_CPU (obj);static bool inited; -uint32_t Aff1, Aff0; cs->env_ptr = &cpu->env; -cpu_exec_init (cs, &error_abort); cpu->cp_regs =g_hash_table_new_full (g_int_hash, g_int_equal, g_free, g_free); -/* This cpu-id-to-MPIDR affinity is used only for TCG; KVM will override it. -* We don't support setting cluster ID ([16..23]) (known as Aff2 -* in later ARM ARM versions), or any of the higher affinity level fields, -* so these bits always RAZ. -*/ - Aff1 = cs->cpu_index /ARM_CPUS_PER_CLUSTER ; - Aff0 = cs->cpu_index %ARM_CPUS_PER_CLUSTER ; - cpu->mp_affinity = (Aff1 <<ARM_AFF1_SHIFT ) | Aff0; -#ifndef CONFIG_USER_ONLY /* Our inbound IRQ and FIQ lines */ if (kvm_enabled ()) {@@ -576,6 +567,14 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)ARMCPU *cpu =ARM_CPU (dev);ARMCPUClass *acc =ARM_CPU_GET_CLASS (dev);CPUARMState *env = &cpu->env; +Error *local_err =NULL ; +uint32_t Aff1, Aff0; + +cpu_exec_realizefn (cs, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; + }/* Some features automatically imply others: */ if (arm_feature (env,ARM_FEATURE_V8 )) {@@ -631,6 +630,17 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)set_feature (env,ARM_FEATURE_THUMB_DSP );target-arm/cpu.c static void arm_cpu_realizefn(DeviceState *dev, Error **errp) · line 640
Quoted 10 lines
target-arm/cpu.c +8
-0} +/* This cpu-id-to-MPIDR affinity is used only for TCG; KVM will override it. +* We don't support setting cluster ID ([16..23]) (known as Aff2 +* in later ARM ARM versions), or any of the higher affinity level fields, +* so these bits always RAZ. +*/ +if (cpu->mp_affinity ==MP_AFFINITY_INVALID ) { + Aff1 = cs->cpu_index /ARM_CPUS_PER_CLUSTER ; + Aff0 = cs->cpu_index %ARM_CPUS_PER_CLUSTER ;I think
ARM_CPUS_PER_CLUSTERshould be renamed toARM_DEFAULT_CPUS_PER_CLUSTERand either moved from where it's currently defined (abovearm_cpu_initfn) to just abovearm_cpu_realizefn, or to the same place asARM64_AFFINITY_MASKandMP_AFFINITY_INVALID.
Quoted 2 lines
Aff0 and Aff1 could be declared in this scope, as they're only used here.
The goal was to have as less diff as possible with my previous patch, so I didn't move the declaration. This will not change the generated code.
Quoted 33 lines
Quoted 33 lines
target-arm/cpu.c +4
-12+ cpu->mp_affinity = (Aff1 <<ARM_AFF1_SHIFT ) | Aff0; + } +if (cpu->reset_hivecs) { cpu->reset_sctlr |= (1 <<13 ); }@@ -1461,7 +1471,7 @@ static Property arm_cpu_properties[] = {DEFINE_PROP_BOOL ("start-powered-off" ,ARMCPU , start_powered_off, false),DEFINE_PROP_UINT32 ("psci-conduit" ,ARMCPU , psci_conduit,0 ),DEFINE_PROP_UINT32 ("midr" ,ARMCPU , midr,0 ), -DEFINE_PROP_UINT64 ("mp-affinity" ,ARMCPU , mp_affinity,0 ), +DEFINE_PROP_UINT64 ("mp-affinity" ,ARMCPU , mp_affinity,MP_AFFINITY_INVALID ), DEFINE_PROP_END_OF_LIST() };@@ -1533,17 +1543,6 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data) cc->debug_check_watchpoint = arm_debug_check_watchpoint; cc->disas_set_info = arm_disas_set_info; - -/* -* Reason: arm_cpu_initfn() calls cpu_exec_init(), which saves -* the object in cpus -> dangling pointer after final -* object_unref(). -* -* Once this is fixed, the devices that create ARM CPUs should be -* updated not to set cannot_destroy_with_object_finalize_yet, -* unless they still screw up something else. -*/ - dc->cannot_destroy_with_object_finalize_yet = true; }
Quoted 4 lines
target-arm/cpu.c static void arm_cpu_class_init(ObjectClass *oc, void *data) · line 1548
Quoted 1 line
target-arm/cpu.c +0
-0static void cpu_register (const ARMCPUInfo *info)[...]
Otherwise looks good to me.
Thanks,
Laurent
Re: [Qemu-devel] [PATCH v4 2/3] exec: move cpu_exec_init() calls to realize functions
Quoted 31 lines · Laurent Vivier
Quoted 28 lines · Andrew Jones
Quoted 18 lines · Laurent Vivier
Modify all CPUs to call it from
XXX_cpu_realizefn()function.Remove all the
cannot_destroy_with_object_finalize_yetas unsafe references have been moved tocpu_exec_realizefn(). (tested with QOM command provided by commit4c315c27)for arm:
Setting of
cpu->mp_affinityis moved fromarm_cpu_initfn()toarm_cpu_realizefn()as setting ofcpu_indexis now done incpu_exec_realizefn(). To avoid to overwrite an user defined value, we set it to an invalid value by default, and update it in realize function only if the value is still invalid.Signed-off-by Laurent Vivier <[email protected]>Reviewed-by David Gibson <[email protected]>Reviewed-by Igor Mammedov <[email protected]>---
[...]
Quoted 8 lines
target-arm/cpu.c +0
-0@@ -33,6 +33,8 @@#include "sysemu/kvm.h" #include "kvm_arm.h"
Quoted 8 lines
Quoted 4 lines
target-arm/cpu.c line 36
Quoted 1 line
target-arm/cpu.c +1
-0+#define MP_AFFINITY_INVALID (~ARM64_AFFINITY_MASK)I would have defined this next to
ARM64_AFFINITY_MASKintarget-arm/cpu-qom.hIt was my first idea, but all macros in
cpu-qom.hstart byARM_orARM64_, this one looks like a local macro (the name is too generic), so I put it incpu.c.
Feel free to prefix it with ARM64_ :-) How aboutARM64_AFFINITY_INVALID
Quoted 62 lines
Quoted 62 lines
Quoted 45 lines
target-arm/cpu.c +9
-11+static void arm_cpu_set_pc (CPUState *cs,vaddr value) {ARMCPU *cpu =ARM_CPU (cs);@@ -441,22 +443,11 @@ static void arm_cpu_initfn(Object *obj)CPUState *cs =CPU (obj);ARMCPU *cpu =ARM_CPU (obj);static bool inited; -uint32_t Aff1, Aff0; cs->env_ptr = &cpu->env; -cpu_exec_init (cs, &error_abort); cpu->cp_regs =g_hash_table_new_full (g_int_hash, g_int_equal, g_free, g_free); -/* This cpu-id-to-MPIDR affinity is used only for TCG; KVM will override it. -* We don't support setting cluster ID ([16..23]) (known as Aff2 -* in later ARM ARM versions), or any of the higher affinity level fields, -* so these bits always RAZ. -*/ - Aff1 = cs->cpu_index /ARM_CPUS_PER_CLUSTER ; - Aff0 = cs->cpu_index %ARM_CPUS_PER_CLUSTER ; - cpu->mp_affinity = (Aff1 <<ARM_AFF1_SHIFT ) | Aff0; -#ifndef CONFIG_USER_ONLY /* Our inbound IRQ and FIQ lines */ if (kvm_enabled ()) {@@ -576,6 +567,14 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)ARMCPU *cpu =ARM_CPU (dev);ARMCPUClass *acc =ARM_CPU_GET_CLASS (dev);CPUARMState *env = &cpu->env; +Error *local_err =NULL ; +uint32_t Aff1, Aff0; + +cpu_exec_realizefn (cs, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; + }/* Some features automatically imply others: */ if (arm_feature (env,ARM_FEATURE_V8 )) {@@ -631,6 +630,17 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)set_feature (env,ARM_FEATURE_THUMB_DSP );target-arm/cpu.c static void arm_cpu_realizefn(DeviceState *dev, Error **errp) · line 640
Quoted 10 lines
target-arm/cpu.c +8
-0} +/* This cpu-id-to-MPIDR affinity is used only for TCG; KVM will override it. +* We don't support setting cluster ID ([16..23]) (known as Aff2 +* in later ARM ARM versions), or any of the higher affinity level fields, +* so these bits always RAZ. +*/ +if (cpu->mp_affinity ==MP_AFFINITY_INVALID ) { + Aff1 = cs->cpu_index /ARM_CPUS_PER_CLUSTER ; + Aff0 = cs->cpu_index %ARM_CPUS_PER_CLUSTER ;I think
ARM_CPUS_PER_CLUSTERshould be renamed toARM_DEFAULT_CPUS_PER_CLUSTERand either moved from where it's currently defined (abovearm_cpu_initfn) to just abovearm_cpu_realizefn, or to the same place asARM64_AFFINITY_MASKandMP_AFFINITY_INVALID.
Quoted 5 lines
Quoted 2 lines
Aff0 and Aff1 could be declared in this scope, as they're only used here.
The goal was to have as less diff as possible with my previous patch, so I didn't move the declaration. This will not change the generated code.
I don't care much, but it's not just about generated code. It's also about reviewers being able to dismiss those variables when they get to the end of the scope (avoids too much brain clutter)
Quoted 41 lines
Quoted 33 lines
Quoted 33 lines
target-arm/cpu.c +4
-12+ cpu->mp_affinity = (Aff1 <<ARM_AFF1_SHIFT ) | Aff0; + } +if (cpu->reset_hivecs) { cpu->reset_sctlr |= (1 <<13 ); }@@ -1461,7 +1471,7 @@ static Property arm_cpu_properties[] = {DEFINE_PROP_BOOL ("start-powered-off" ,ARMCPU , start_powered_off, false),DEFINE_PROP_UINT32 ("psci-conduit" ,ARMCPU , psci_conduit,0 ),DEFINE_PROP_UINT32 ("midr" ,ARMCPU , midr,0 ), -DEFINE_PROP_UINT64 ("mp-affinity" ,ARMCPU , mp_affinity,0 ), +DEFINE_PROP_UINT64 ("mp-affinity" ,ARMCPU , mp_affinity,MP_AFFINITY_INVALID ), DEFINE_PROP_END_OF_LIST() };@@ -1533,17 +1543,6 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data) cc->debug_check_watchpoint = arm_debug_check_watchpoint; cc->disas_set_info = arm_disas_set_info; - -/* -* Reason: arm_cpu_initfn() calls cpu_exec_init(), which saves -* the object in cpus -> dangling pointer after final -* object_unref(). -* -* Once this is fixed, the devices that create ARM CPUs should be -* updated not to set cannot_destroy_with_object_finalize_yet, -* unless they still screw up something else. -*/ - dc->cannot_destroy_with_object_finalize_yet = true; }Quoted 4 lines
target-arm/cpu.c static void arm_cpu_class_init(ObjectClass *oc, void *data) · line 1548
Quoted 1 line
target-arm/cpu.c +0
-0static void cpu_register (const ARMCPUInfo *info)[...]
Otherwise looks good to me.
Thanks,
Laurent
Re: [Qemu-arm] [Qemu-devel] [PATCH v4 2/3] exec: move cpu_exec_init() calls to realize functions
Quoted 109 lines · Andrew Jones
Quoted 31 lines · Laurent Vivier
Quoted 28 lines · Andrew Jones
Quoted 18 lines · Laurent Vivier
Modify all CPUs to call it from
XXX_cpu_realizefn()function.Remove all the
cannot_destroy_with_object_finalize_yetas unsafe references have been moved tocpu_exec_realizefn(). (tested with QOM command provided by commit4c315c27)for arm:
Setting of
cpu->mp_affinityis moved fromarm_cpu_initfn()toarm_cpu_realizefn()as setting ofcpu_indexis now done incpu_exec_realizefn(). To avoid to overwrite an user defined value, we set it to an invalid value by default, and update it in realize function only if the value is still invalid.Signed-off-by Laurent Vivier <[email protected]>Reviewed-by David Gibson <[email protected]>Reviewed-by Igor Mammedov <[email protected]>---
[...]
Quoted 8 lines
target-arm/cpu.c +0
-0@@ -33,6 +33,8 @@#include "sysemu/kvm.h" #include "kvm_arm.h" Quoted 8 lines
Quoted 4 lines
target-arm/cpu.c line 36
Quoted 1 line
target-arm/cpu.c +1
-0+#define MP_AFFINITY_INVALID (~ARM64_AFFINITY_MASK)I would have defined this next to
ARM64_AFFINITY_MASKintarget-arm/cpu-qom.hIt was my first idea, but all macros in
cpu-qom.hstart byARM_orARM64_, this one looks like a local macro (the name is too generic), so I put it incpu.c.Feel free to prefix it with
ARM64_:-) How aboutARM64_AFFINITY_INVALIDQuoted 65 lines
Quoted 64 lines
Quoted 45 lines
target-arm/cpu.c +9
-11+static void arm_cpu_set_pc (CPUState *cs,vaddr value) {ARMCPU *cpu =ARM_CPU (cs);@@ -441,22 +443,11 @@ static void arm_cpu_initfn(Object *obj)CPUState *cs =CPU (obj);ARMCPU *cpu =ARM_CPU (obj);static bool inited; -uint32_t Aff1, Aff0; cs->env_ptr = &cpu->env; -cpu_exec_init (cs, &error_abort); cpu->cp_regs =g_hash_table_new_full (g_int_hash, g_int_equal, g_free, g_free); -/* This cpu-id-to-MPIDR affinity is used only for TCG; KVM will override it. -* We don't support setting cluster ID ([16..23]) (known as Aff2 -* in later ARM ARM versions), or any of the higher affinity level fields, -* so these bits always RAZ. -*/ - Aff1 = cs->cpu_index /ARM_CPUS_PER_CLUSTER ; - Aff0 = cs->cpu_index %ARM_CPUS_PER_CLUSTER ; - cpu->mp_affinity = (Aff1 <<ARM_AFF1_SHIFT ) | Aff0; -#ifndef CONFIG_USER_ONLY /* Our inbound IRQ and FIQ lines */ if (kvm_enabled ()) {@@ -576,6 +567,14 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)ARMCPU *cpu =ARM_CPU (dev);ARMCPUClass *acc =ARM_CPU_GET_CLASS (dev);CPUARMState *env = &cpu->env; +Error *local_err =NULL ; +uint32_t Aff1, Aff0; + +cpu_exec_realizefn (cs, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; + }/* Some features automatically imply others: */ if (arm_feature (env,ARM_FEATURE_V8 )) {@@ -631,6 +630,17 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)set_feature (env,ARM_FEATURE_THUMB_DSP );target-arm/cpu.c static void arm_cpu_realizefn(DeviceState *dev, Error **errp) · line 640
Quoted 10 lines
target-arm/cpu.c +8
-0} +/* This cpu-id-to-MPIDR affinity is used only for TCG; KVM will override it. +* We don't support setting cluster ID ([16..23]) (known as Aff2 +* in later ARM ARM versions), or any of the higher affinity level fields, +* so these bits always RAZ. +*/ +if (cpu->mp_affinity ==MP_AFFINITY_INVALID ) { + Aff1 = cs->cpu_index /ARM_CPUS_PER_CLUSTER ; + Aff0 = cs->cpu_index %ARM_CPUS_PER_CLUSTER ;I think
ARM_CPUS_PER_CLUSTERshould be renamed toARM_DEFAULT_CPUS_PER_CLUSTERand either moved from where it's currently defined (abovearm_cpu_initfn) to just abovearm_cpu_realizefn, or to the same place asARM64_AFFINITY_MASKandMP_AFFINITY_INVALID.Aff0 and Aff1 could be declared in this scope, as they're only used here.
Quoted 6 lines
Quoted 2 lines
The goal was to have as less diff as possible with my previous patch, so I didn't move the declaration. This will not change the generated code.
I don't care much, but it's not just about generated code. It's also about reviewers being able to dismiss those variables when they get to the end of the scope (avoids too much brain clutter)
OK, I will modify the patch as you say.
Thanks,
Laurent
PATCH v4 3/3 exec: call cpu_exec_exit() from a CPU unrealize common function
In reply to Laurent VivierAs cpu_exec_exit() mirrors the cpu_exec_realizefn(), rename it as cpu_exec_unrealizefn().
Create and register a cpu_common_unrealizefn() function for the CPU device class and call cpu_exec_unrealizefn() from this function.
Remove cpu_exec_exit() from cpu_common_finalize()
(which mirrors init, not realize), and as x86_cpu_unrealizefn() and ppc_cpu_unrealizefn() overwrite the device class unrealize function, add a call to a parent_unrealize pointer.
--- exec.c | 2 +- include/qom/cpu.h | 2 +- qom/cpu.c | 8 +++++++- target-i386/cpu-qom.h | 1 + target-i386/cpu.c | 9 +++++++++ target-ppc/cpu-qom.h | 1 + target-ppc/translate_init.c | 9 ++++++++- 7 files changed, 28 insertions(+), 4 deletions(-)
exec.c +1 -1
@@ -596,7 +596,7 @@ AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx) }#endif -void cpu_exec_exit (CPUState *cpu) +void cpu_exec_unrealizefn (CPUState *cpu) {CPUClass *cc =CPU_GET_CLASS (cpu);
include/qom/cpu.h +1 -1
@@ -948,7 +948,7 @@ void QEMU_NORETURN cpu_abort(CPUState *cpu, const char *fmt, ...)GCC_FMT_ATTR (2 ,3 );void cpu_exec_initfn (CPUState *cpu);void cpu_exec_realizefn (CPUState *cpu,Error **errp); -void cpu_exec_exit (CPUState *cpu); +void cpu_exec_unrealizefn (CPUState *cpu);#ifdef CONFIG_SOFTMMU extern const struct VMStateDescription vmstate_cpu_common;
qom/cpu.c +7 -1
@@ -345,6 +345,12 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp)trace_init_vcpu (cpu); } +static void cpu_common_unrealizefn (DeviceState *dev,Error **errp) +{ +CPUState *cpu =CPU (dev); +cpu_exec_unrealizefn (cpu); +} +static void cpu_common_initfn (Object *obj) {CPUState *cpu =CPU (obj);
@@ -369,7 +375,6 @@ static void cpu_common_initfn(Object *obj)static void cpu_common_finalize (Object *obj) {CPUState *cpu =CPU (obj); -cpu_exec_exit (cpu);g_free (cpu->trace_dstate); }
@@ -403,6 +408,7 @@ static void cpu_class_init(ObjectClass *klass, void *data) k->cpu_exec_exit = cpu_common_noop; k->cpu_exec_interrupt = cpu_common_exec_interrupt; dc->realize = cpu_common_realizefn; + dc->unrealize = cpu_common_unrealizefn;/* * Reason: CPUs still need special care by board code: wiring up * IRQs, adding reset handlers, halting non-first CPUs, ...
target-i386/cpu-qom.h +1 -0
@@ -64,6 +64,7 @@ typedef struct X86CPUClass {bool kvm_required;DeviceRealize parent_realize; +DeviceUnrealize parent_unrealize;void (*parent_reset)(CPUState *cpu); } X86CPUClass;
target-i386/cpu.c +9 -0
@@ -3243,6 +3243,8 @@ out:static void x86_cpu_unrealizefn (DeviceState *dev,Error **errp) {X86CPU *cpu =X86_CPU (dev); +X86CPUClass *xcc =X86_CPU_GET_CLASS (dev); +Error *local_err =NULL ;#ifndef CONFIG_USER_ONLY cpu_remove_sync (CPU (dev));
@@ -3253,6 +3255,12 @@ static void x86_cpu_unrealizefn(DeviceState *dev, Error **errp)object_unparent (OBJECT (cpu->apic_state)); cpu->apic_state =NULL ; } + + xcc->parent_unrealize (dev, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; + } } typedef struct BitProperty {
@@ -3502,6 +3510,7 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)DeviceClass *dc =DEVICE_CLASS (oc); xcc->parent_realize = dc->realize; + xcc->parent_unrealize = dc->unrealize; dc->realize = x86_cpu_realizefn; dc->unrealize = x86_cpu_unrealizefn; dc->props = x86_cpu_properties;
target-ppc/cpu-qom.h +1 -0
@@ -174,6 +174,7 @@ typedef struct PowerPCCPUClass {/*< public >*/ DeviceRealize parent_realize; +DeviceUnrealize parent_unrealize;void (*parent_reset)(CPUState *cpu);uint32_t pvr;
target-ppc/translate_init.c +8 -1
@@ -9906,11 +9906,17 @@ static void ppc_cpu_realizefn(DeviceState *dev, Error **errp)static void ppc_cpu_unrealizefn (DeviceState *dev,Error **errp) {PowerPCCPU *cpu =POWERPC_CPU (dev); +PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cpu);CPUPPCState *env = &cpu->env; +Error *local_err =NULL ;opc_handler_t **table, **table_2;int i, j, k; -cpu_exec_exit (CPU (dev)); + pcc->parent_unrealize (dev, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; + }for (i =0 ; i <PPC_CPU_OPCODES_LEN ; i++) {if (env->opcodes[i] == &invalid_handler) {
@@ -10521,6 +10527,7 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data)DeviceClass *dc =DEVICE_CLASS (oc); pcc->parent_realize = dc->realize; + pcc->parent_unrealize = dc->unrealize; pcc->pvr_match = ppc_pvr_match_default; pcc->interrupts_big_endian = ppc_cpu_interrupts_big_endian_always; dc->realize = ppc_cpu_realizefn;
Signature · 1 line
2.7.4
Quoted 17 lines · Laurent Vivier
Since commit 42ecaba ("target-i386: Call
cpu_exec_init()on realize"), , commit 6dd0f83 ("target-ppc: Movecpu_exec_init()call to realize function"), and commit c6644fc ("s390x/cpu: Get rid of side effects when creating a vcpu"),cpu_exec_init()has been moved to realize function for some architectures to implement CPU htoplug. This allows any failures fromcpu_exec_init()to be handled appropriately.This series tries to do the same work for all the other CPUs.
But as the ARM Virtual Machine ("virt") needs the "memory" property of the CPU in the machine init function (the "memory" property is created in
cpu_exec_init()we want to move to the realize part), splitcpu_exec_init()in two parts: a realize part (cpu_exec_realizefn(), adding the CPU in the environment) and an init part (cpu_exec_initfn(), initializing the CPU, like adding the "memory" property). To mirror the realize part, add an unrealize part, and remove thecpu_exec_exit()call from the finalize part.
Quoted 8 lines
This also allows to remove all the "
cannot_destroy_with_object_finalize_yet" properties from the CPU device class.v4:
- arm: updatemp_affinityin realize only if it s not set by the user
- i386 and ppc: add anparent_unrealizeto call the Device unrealize because it is overwritten by the CPU unrealize
- update commit messages
Series:
But I will wait for Drew or other ARM people to review the ARM hunks on patch 2/3 before applying.
v3 -> v4 diff, for reference:
diff --git a/target-arm/cpu.c b/target-arm/cpu.c index 364a45d..f0d2074 100644 --- a/target-arm/cpu.c +++ b/target-arm/cpu.c @@ -33,6 +33,8 @@ #include "sysemu/kvm.h" #include "kvm_arm.h"
+#define MP_AFFINITY_INVALID (~ARM64_AFFINITY_MASK) +
static void arm_cpu_set_pc(CPUState *cs, vaddr value)
{
ARMCPU *cpu = ARM_CPU(cs);
@@ -633,9 +635,11 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
* in later ARM ARM versions), or any of the higher affinity level fields,
* so these bits always RAZ.
*/
- Aff1 = cs->cpu_index / ARM_CPUS_PER_CLUSTER;
- Aff0 = cs->cpu_index % ARM_CPUS_PER_CLUSTER;
- cpu->mp_affinity = (Aff1 << ARM_AFF1_SHIFT) | Aff0;
+ if (cpu->mp_affinity == MP_AFFINITY_INVALID) {
+ Aff1 = cs->cpu_index / ARM_CPUS_PER_CLUSTER;
+ Aff0 = cs->cpu_index % ARM_CPUS_PER_CLUSTER;
+ cpu->mp_affinity = (Aff1 << ARM_AFF1_SHIFT) | Aff0;+ }
if (cpu->reset_hivecs) {
cpu->reset_sctlr |= (1 << 13); @@ -1467,7 +1471,7 @@ static Property arm_cpu_properties[] = {
DEFINE_PROP_BOOL("start-powered-off", ARMCPU, start_powered_off, false), DEFINE_PROP_UINT32("psci-conduit", ARMCPU, psci_conduit, 0), DEFINE_PROP_UINT32("midr", ARMCPU, midr, 0),
- DEFINE_PROP_UINT64("mp-affinity", ARMCPU, mp_affinity, 0),
+ DEFINE_PROP_UINT64("mp-affinity", ARMCPU, mp_affinity, MP_AFFINITY_INVALID),
DEFINE_PROP_END_OF_LIST()
};
diff --git a/target-i386/cpu-qom.h b/target-i386/cpu-qom.h
index 5dde658..07030d2 100644
--- a/target-i386/cpu-qom.h
+++ b/target-i386/cpu-qom.h
@@ -64,6 +64,7 @@ typedef struct X86CPUClass {
bool kvm_required; DeviceRealize parent_realize;
+ DeviceUnrealize parent_unrealize;
void (*parent_reset)(CPUState *cpu);} X86CPUClass;
diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 399a3e4..95ce067 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -3243,6 +3243,8 @@ out:
static void x86_cpu_unrealizefn(DeviceState *dev, Error **errp)
{
X86CPU *cpu = X86_CPU(dev); + X86CPUClass *xcc = X86_CPU_GET_CLASS(dev);
+ Error *local_err = NULL;
#ifndef CONFIG_USER_ONLY
cpu_remove_sync(CPU(dev));
@@ -3254,7 +3256,11 @@ static void x86_cpu_unrealizefn(DeviceState *dev, Error **errp)
cpu->apic_state = NULL;
} - cpu_exec_unrealizefn(CPU(dev));
+ xcc->parent_unrealize(dev, &local_err);
+ if (local_err != NULL) { + error_propagate(errp, local_err);
+ return;
+ }
}
typedef struct BitProperty {
@@ -3504,6 +3510,7 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
DeviceClass *dc = DEVICE_CLASS(oc); xcc->parent_realize = dc->realize;
+ xcc->parent_unrealize = dc->unrealize;
dc->realize = x86_cpu_realizefn;
dc->unrealize = x86_cpu_unrealizefn;
dc->props = x86_cpu_properties;
diff --git a/target-ppc/cpu-qom.h b/target-ppc/cpu-qom.h
index 713deef..d46c31a 100644
--- a/target-ppc/cpu-qom.h
+++ b/target-ppc/cpu-qom.h
@@ -174,6 +174,7 @@ typedef struct PowerPCCPUClass {
/*< public >*/
DeviceRealize parent_realize;
+ DeviceUnrealize parent_unrealize;
void (*parent_reset)(CPUState *cpu);
uint32_t pvr;
diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c
index 2de6a06..208fa1e 100644
--- a/target-ppc/translate_init.c
+++ b/target-ppc/translate_init.c
@@ -9906,11 +9906,17 @@ static void ppc_cpu_realizefn(DeviceState *dev, Error **errp)
static void ppc_cpu_unrealizefn(DeviceState *dev, Error **errp)
{
PowerPCCPU *cpu = POWERPC_CPU(dev);
+ PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu);
CPUPPCState *env = &cpu->env;
+ Error *local_err = NULL;
opc_handler_t **table, **table_2;
int i, j, k; - cpu_exec_unrealizefn(CPU(dev));
+ pcc->parent_unrealize(dev, &local_err);
+ if (local_err != NULL) { + error_propagate(errp, local_err);
+ return;
+ }
for (i = 0; i < PPC_CPU_OPCODES_LEN; i++) {
if (env->opcodes[i] == &invalid_handler) {
@@ -10521,6 +10527,7 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data)
DeviceClass *dc = DEVICE_CLASS(oc);
pcc->parent_realize = dc->realize;
+ pcc->parent_unrealize = dc->unrealize;
pcc->pvr_match = ppc_pvr_match_default;
pcc->interrupts_big_endian = ppc_cpu_interrupts_big_endian_always;
dc->realize = ppc_cpu_realizefn;Quoted 62 lines
v3:
- reorganize the series in 3 patches:
1- splitcpu_exec_init()and call the init part from
cpu_common_initfn()
2- move all thecpu_exec_realize()calls to the
XXX_cpu_realizefn()functions
3- create acpu_common_unrealizefn()function
and call thecpu_exec_unrealize()function from here, except for ppc64 and i386 that have their ownXX_cpu_unrealizefn()functions
- renamecpu_exec_init(),cpu_exec_realize(),cpu_exec_unrealize()tocpu_exec_initfn(),cpu_exec_realizefn()andcpu_exec_unrealizefn(),
- movecpu_exec_unrealizefn()to the device class unrealize and declare it inqom/cpu.hinstead ofexec/exec-all.hv2:
- renamecpu_exec_exit()ascpu_exec_unrealize(), as it un-does whatcpu_exec_realize()does,
- removecpu_exec_exit()fromppc_cpu_unrealizefn()as it is called fromcpu_common_finalize(),
- add a patch to move allcpu_exec_init()from allXX_cpu_initfn()tocpu_common_initfn(),
- arm: move setting ofcpu->mp_affinitytoarm_cpu_realizefn()as thecpu_indexis now set incpu_exec_realizefn().
- update some commit messagesLaurent Vivier (3):
exec: splitcpu_exec_init()
exec: movecpu_exec_init()calls to realize functions
exec: callcpu_exec_exit()from a CPU unrealize common functionexec.c | 12 +++++++----- include/exec/exec-all.h | 1 - include/qom/cpu.h | 4 +++- qom/cpu.c | 10 +++++++++- target-alpha/cpu.c | 15 +++++++-------- target-arm/cpu.c | 45 ++++++++++++++++++++++----------------------- target-cris/cpu.c | 15 +++++++-------- target-i386/cpu-qom.h | 1 + target-i386/cpu.c | 20 ++++++++++++++------ target-lm32/cpu.c | 15 +++++++-------- target-m68k/cpu.c | 15 +++++++-------- target-microblaze/cpu.c | 14 +++++++------- target-mips/cpu.c | 15 +++++++-------- target-moxie/cpu.c | 15 +++++++-------- target-openrisc/cpu.c | 15 +++++++-------- target-ppc/cpu-qom.h | 1 + target-ppc/translate_init.c | 11 +++++++++-- target-s390x/cpu.c | 8 +------- target-sh4/cpu.c | 15 +++++++-------- target-sparc/cpu.c | 18 +++++++++--------- target-tilegx/cpu.c | 15 +++++++-------- target-tricore/cpu.c | 15 +++++++-------- target-unicore32/cpu.c | 18 +++++++++--------- target-xtensa/cpu.c | 15 +++++++-------- 24 files changed, 169 insertions(+), 159 deletions(-)Signature · 1 line
2.7.4
Signature · 1 line
Eduardo