accel: Restrict tcg_exec_[un]realizefn() to TCG
v2 cover accel: Restrict tcg_exec_[un]realizefn() to TCG
Since v1:
- Use 'target'/'common' in function names (Claudio)
- Added Claudio R-b tags
From v1:
- Add missing accel_cpu_common_unrealize()
- Add AccelClass::cpu_common_[un]realize handlers
- Use tcg_exec_[un]realizefn as AccelClass handlers
Philippe Mathieu-Daudé (7):
accel: Rename accel_cpu_realizefn() -> accel_cpu_realize()
accel: Rename AccelCPUClass::cpu_realizefn() -> cpu_target_realize()
accel: Rename accel_cpu_realize() -> accel_cpu_common_realize()
accel: Introduce accel_cpu_common_unrealize() stub
accel: Declare AccelClass::cpu_common_[un]realize() handlers accel/tcg: Have tcg_exec_realizefn() return a boolean accel/tcg: Restrict tcg_exec_[un]realizefn() to TCG
accel/tcg/internal.h | 3 +++ include/exec/cpu-all.h | 2 -- include/hw/core/accel-cpu.h | 2 +- include/qemu/accel.h | 12 ++++++++++-- accel/accel-common.c | 27 ++++++++++++++++++++++++--- accel/tcg/cpu-exec.c | 4 +++- accel/tcg/tcg-all.c | 2 ++ cpu.c | 13 +++---------- target/i386/hvf/hvf-cpu.c | 2 +- target/i386/kvm/kvm-cpu.c | 4 ++-- target/i386/tcg/tcg-cpu.c | 2 +- 11 files changed, 50 insertions(+), 23 deletions(-)
Signature · 1 line
2.41.0
PATCH v2 1/7 accel: Rename accel_cpu_realizefn() -> accel_cpu_realize()
We use the '*fn' suffix for handlers, this is a public method. Drop the suffix.
--- include/qemu/accel.h | 4 ++-- accel/accel-common.c | 2 +- cpu.c | 2 +- target/i386/kvm/kvm-cpu.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-)
include/qemu/accel.h +2 -2
@@ -90,11 +90,11 @@ void accel_setup_post(MachineState *ms);void accel_cpu_instance_init (CPUState *cpu);/** -* accel_cpu_realizefn: +* accel_cpu_realize: * @cpu: The CPU that needs to call accel-specific cpu realization. * @errp: currently unused. */ -bool accel_cpu_realizefn (CPUState *cpu,Error **errp); +bool accel_cpu_realize (CPUState *cpu,Error **errp);/** * accel_supported_gdbstub_sstep_flags:
accel/accel-common.c +1 -1
@@ -119,7 +119,7 @@ void accel_cpu_instance_init(CPUState *cpu) } } -bool accel_cpu_realizefn (CPUState *cpu,Error **errp) +bool accel_cpu_realize (CPUState *cpu,Error **errp) {CPUClass *cc =CPU_GET_CLASS (cpu);
cpu.c +1 -1
@@ -136,7 +136,7 @@ void cpu_exec_realizefn(CPUState *cpu, Error **errp)/* cache the cpu class for the hotpath */ cpu->cc =CPU_GET_CLASS (cpu); -if (!accel_cpu_realizefn (cpu, errp)) { +if (!accel_cpu_realize (cpu, errp)) {return ; }
target/i386/kvm/kvm-cpu.c +1 -1
@@ -35,7 +35,7 @@ static bool kvm_cpu_realizefn(CPUState *cs, Error **errp)* x86_cpu_realize(): * -> x86_cpu_expand_features() * -> cpu_exec_realizefn(): -* -> accel_cpu_realizefn() +* -> accel_cpu_realize() * kvm_cpu_realizefn() -> host_cpu_realizefn() * -> check/update ucode_rev, phys_bits, mwait */
Signature · 1 line
2.41.0
PATCH v2 2/7 accel: Rename AccelCPUClass::cpu_realizefn() -> cpu_target_realize()
In reply to Philippe Mathieu-DaudéThe AccelCPUClass::cpu_realizefn handler is meant for target specific code, rename it using '_target_' to emphasis it.
--- include/hw/core/accel-cpu.h | 2 +- accel/accel-common.c | 4 ++-- target/i386/hvf/hvf-cpu.c | 2 +- target/i386/kvm/kvm-cpu.c | 2 +- target/i386/tcg/tcg-cpu.c | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-)
include/hw/core/accel-cpu.h +1 -1
@@ -32,7 +32,7 @@ typedef struct AccelCPUClass {void (*cpu_class_init)(CPUClass *cc);void (*cpu_instance_init)(CPUState *cpu); - bool (*cpu_realizefn)(CPUState *cpu, Error **errp); + bool (*cpu_target_realize)(CPUState *cpu, Error **errp); } AccelCPUClass;#endif /* ACCEL_CPU_H */
accel/accel-common.c +2 -2
@@ -123,8 +123,8 @@ bool accel_cpu_realize(CPUState *cpu, Error **errp) {CPUClass *cc =CPU_GET_CLASS (cpu); -if (cc->accel_cpu && cc->accel_cpu->cpu_realizefn) { -return cc->accel_cpu->cpu_realizefn (cpu, errp); +if (cc->accel_cpu && cc->accel_cpu->cpu_target_realize) { +return cc->accel_cpu->cpu_target_realize (cpu, errp); }return true; }
target/i386/hvf/hvf-cpu.c +1 -1
@@ -77,7 +77,7 @@ static void hvf_cpu_accel_class_init(ObjectClass *oc, void *data) {AccelCPUClass *acc =ACCEL_CPU_CLASS (oc); - acc->cpu_realizefn = host_cpu_realizefn; + acc->cpu_target_realize = host_cpu_realizefn; acc->cpu_instance_init = hvf_cpu_instance_init; }
target/i386/kvm/kvm-cpu.c +1 -1
@@ -190,7 +190,7 @@ static void kvm_cpu_accel_class_init(ObjectClass *oc, void *data) {AccelCPUClass *acc =ACCEL_CPU_CLASS (oc); - acc->cpu_realizefn = kvm_cpu_realizefn; + acc->cpu_target_realize = kvm_cpu_realizefn; acc->cpu_instance_init = kvm_cpu_instance_init; }static const TypeInfo kvm_cpu_accel_type_info = {
target/i386/tcg/tcg-cpu.c +1 -1
@@ -163,7 +163,7 @@ static void tcg_cpu_accel_class_init(ObjectClass *oc, void *data)AccelCPUClass *acc =ACCEL_CPU_CLASS (oc);#ifndef CONFIG_USER_ONLY - acc->cpu_realizefn = tcg_cpu_realizefn; + acc->cpu_target_realize = tcg_cpu_realizefn;#endif /* CONFIG_USER_ONLY */ acc->cpu_class_init = tcg_cpu_class_init;
Signature · 1 line
2.41.0
PATCH v2 3/7 accel: Rename accel_cpu_realize() -> accel_cpu_common_realize()
In reply to Philippe Mathieu-Daudéaccel_cpu_realize() is a generic function working with CPUs from any target. Rename it using '_common_' to emphasis it is not target specific.
--- include/qemu/accel.h | 4 ++-- accel/accel-common.c | 2 +- cpu.c | 2 +- target/i386/kvm/kvm-cpu.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-)
include/qemu/accel.h +2 -2
@@ -90,11 +90,11 @@ void accel_setup_post(MachineState *ms);void accel_cpu_instance_init (CPUState *cpu);/** -* accel_cpu_realize: +* accel_cpu_common_realize: * @cpu: The CPU that needs to call accel-specific cpu realization. * @errp: currently unused. */ -bool accel_cpu_realize (CPUState *cpu,Error **errp); +bool accel_cpu_common_realize (CPUState *cpu,Error **errp);/** * accel_supported_gdbstub_sstep_flags:
accel/accel-common.c +1 -1
@@ -119,7 +119,7 @@ void accel_cpu_instance_init(CPUState *cpu) } } -bool accel_cpu_realize (CPUState *cpu,Error **errp) +bool accel_cpu_common_realize (CPUState *cpu,Error **errp) {CPUClass *cc =CPU_GET_CLASS (cpu);
cpu.c +1 -1
@@ -136,7 +136,7 @@ void cpu_exec_realizefn(CPUState *cpu, Error **errp)/* cache the cpu class for the hotpath */ cpu->cc =CPU_GET_CLASS (cpu); -if (!accel_cpu_realize (cpu, errp)) { +if (!accel_cpu_common_realize (cpu, errp)) {return ; }
target/i386/kvm/kvm-cpu.c +1 -1
@@ -35,7 +35,7 @@ static bool kvm_cpu_realizefn(CPUState *cs, Error **errp)* x86_cpu_realize(): * -> x86_cpu_expand_features() * -> cpu_exec_realizefn(): -* -> accel_cpu_realize() +* -> accel_cpu_common_realize() * kvm_cpu_realizefn() -> host_cpu_realizefn() * -> check/update ucode_rev, phys_bits, mwait */
Signature · 1 line
2.41.0
PATCH v2 4/7 accel: Introduce accel_cpu_common_unrealize() stub
In reply to Philippe Mathieu-DaudéPrepare the stub for parity with accel_cpu_common_realize().
--- include/qemu/accel.h | 6 ++++++ accel/accel-common.c | 4 ++++ cpu.c | 4 +++- 3 files changed, 13 insertions(+), 1 deletion(-)
include/qemu/accel.h +6 -0
@@ -96,6 +96,12 @@ void accel_cpu_instance_init(CPUState *cpu);*/ bool accel_cpu_common_realize (CPUState *cpu,Error **errp); +/** +* accel_cpu_common_unrealize: +* @cpu: The CPU that needs to call accel-specific cpu unrealization. +*/ +void accel_cpu_common_unrealize (CPUState *cpu); +/** * accel_supported_gdbstub_sstep_flags: *
accel/accel-common.c +4 -0
@@ -129,6 +129,10 @@ bool accel_cpu_common_realize(CPUState *cpu, Error **errp)return true; } +void accel_cpu_common_unrealize (CPUState *cpu) +{ +} +int accel_supported_gdbstub_sstep_flags (void ) {AccelState *accel =current_accel ();
cpu.c +3 -1
@@ -187,8 +187,10 @@ void cpu_exec_unrealizefn(CPUState *cpu)cpu_list_remove (cpu);/* * Now that the vCPU has been removed from the RCU list, we can call -* tcg_exec_unrealizefn, which may free fields using call_rcu. +* tcg_exec_unrealizefn and +* accel_cpu_common_unrealize, which may free fields using call_rcu. */ +accel_cpu_common_unrealize (cpu);if (tcg_enabled ()) {tcg_exec_unrealizefn (cpu); }
Signature · 1 line
2.41.0
PATCH v2 5/7 accel: Declare AccelClass::cpu_common_[un]realize() handlers
In reply to Philippe Mathieu-DaudéCurrently accel_cpu_realize() only performs target-specific realization. Introduce the cpu_common_[un]realize fields in the base AccelClass to be able to perform target-agnostic [un]realization of vCPUs.
--- include/qemu/accel.h | 2 ++ accel/accel-common.c | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-)
include/qemu/accel.h +2 -0
@@ -43,6 +43,8 @@ typedef struct AccelClass {bool (*has_memory)(MachineState *ms,AddressSpace *as,hwaddr start_addr,hwaddr size);#endif +bool (*cpu_common_realize)(CPUState *cpu,Error **errp); +void (*cpu_common_unrealize)(CPUState *cpu);/* gdbstub related hooks */ int (*gdbstub_supported_sstep_flags)(void );
accel/accel-common.c +19 -2
@@ -122,15 +122,32 @@ void accel_cpu_instance_init(CPUState *cpu)bool accel_cpu_common_realize (CPUState *cpu,Error **errp) {CPUClass *cc =CPU_GET_CLASS (cpu); +AccelState *accel =current_accel (); +AccelClass *acc =ACCEL_GET_CLASS (accel); -if (cc->accel_cpu && cc->accel_cpu->cpu_target_realize) { -return cc->accel_cpu->cpu_target_realize (cpu, errp); +/* target specific realization */ +if (cc->accel_cpu && cc->accel_cpu->cpu_target_realize + && !cc->accel_cpu->cpu_target_realize (cpu, errp)) { +return false; } + +/* generic realization */ +if (acc->cpu_common_realize && !acc->cpu_common_realize (cpu, errp)) { +return false; + } +return true; }void accel_cpu_common_unrealize (CPUState *cpu) { +AccelState *accel =current_accel (); +AccelClass *acc =ACCEL_GET_CLASS (accel); + +/* generic unrealization */ +if (acc->cpu_common_unrealize) { + acc->cpu_common_unrealize (cpu); + } }int accel_supported_gdbstub_sstep_flags (void )
Signature · 1 line
2.41.0
PATCH v2 6/7 accel/tcg: Have tcg_exec_realizefn() return a boolean
In reply to Philippe Mathieu-DaudéFollowing the example documented since commit e3fe3988d7 ("error:
Document Error API usage rules"), have tcg_exec_realizefn() return a boolean indicating whether an error is set or not.
--- include/exec/cpu-all.h | 2 +- accel/tcg/cpu-exec.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-)
include/exec/cpu-all.h +1 -1
@@ -422,7 +422,7 @@ void dump_exec_info(GString *buf);/* accel/tcg/cpu-exec.c */ int cpu_exec (CPUState *cpu); -void tcg_exec_realizefn (CPUState *cpu,Error **errp); +bool tcg_exec_realizefn (CPUState *cpu,Error **errp);void tcg_exec_unrealizefn (CPUState *cpu);/**
accel/tcg/cpu-exec.c +3 -1
@@ -1088,7 +1088,7 @@ int cpu_exec(CPUState *cpu)return ret; } -void tcg_exec_realizefn (CPUState *cpu,Error **errp) +bool tcg_exec_realizefn (CPUState *cpu,Error **errp) {static bool tcg_target_initialized;CPUClass *cc =CPU_GET_CLASS (cpu);
@@ -1104,6 +1104,8 @@ void tcg_exec_realizefn(CPUState *cpu, Error **errp)tcg_iommu_init_notifier_list (cpu);#endif /* !CONFIG_USER_ONLY */ /* qemu_plugin_vcpu_init_hook delayed until cpu_index assigned. */ + +return true; }/* undo the initializations in reverse order */
Signature · 1 line
2.41.0
PATCH v2 7/7 accel/tcg: Restrict tcg_exec_[un]realizefn() to TCG
In reply to Philippe Mathieu-DaudéWe don't need to expose these TCG-specific methods to the whole code base. Register them as AccelClass handlers, they will be called by the generic accel_cpu_[un]realize() methods.
--- accel/tcg/internal.h | 3 +++ include/exec/cpu-all.h | 2 -- accel/tcg/tcg-all.c | 2 ++ cpu.c | 9 --------- 4 files changed, 5 insertions(+), 11 deletions(-)
accel/tcg/internal.h +3 -0
@@ -80,6 +80,9 @@ bool tb_invalidate_phys_page_unwind(tb_page_addr_t addr, uintptr_t pc);void cpu_restore_state_from_tb (CPUState *cpu,TranslationBlock *tb,uintptr_t host_pc); +bool tcg_exec_realizefn (CPUState *cpu,Error **errp); +void tcg_exec_unrealizefn (CPUState *cpu); +/* Return the current PC from CPU, which may be cached in TB. */ static inline vaddr log_pc (CPUState *cpu,const TranslationBlock *tb) {
include/exec/cpu-all.h +0 -2
@@ -422,8 +422,6 @@ void dump_exec_info(GString *buf);/* accel/tcg/cpu-exec.c */ int cpu_exec (CPUState *cpu); -bool tcg_exec_realizefn (CPUState *cpu,Error **errp); -void tcg_exec_unrealizefn (CPUState *cpu);/** * cpu_set_cpustate_pointers(cpu)
accel/tcg/tcg-all.c +2 -0
@@ -227,6 +227,8 @@ static void tcg_accel_class_init(ObjectClass *oc, void *data)AccelClass *ac =ACCEL_CLASS (oc); ac->name ="tcg" ; ac->init_machine = tcg_init_machine; + ac->cpu_common_realize = tcg_exec_realizefn; + ac->cpu_common_unrealize = tcg_exec_unrealizefn; ac->allowed = &tcg_allowed; ac->gdbstub_supported_sstep_flags = tcg_gdbstub_supported_sstep_flags;
cpu.c +0 -9
@@ -140,11 +140,6 @@ void cpu_exec_realizefn(CPUState *cpu, Error **errp)return ; } -/* NB: errp parameter is unused currently */ -if (tcg_enabled ()) { -tcg_exec_realizefn (cpu, errp); - } -/* Wait until cpu initialization complete before exposing cpu. */ cpu_list_add (cpu);
@@ -187,13 +182,9 @@ void cpu_exec_unrealizefn(CPUState *cpu)cpu_list_remove (cpu);/* * Now that the vCPU has been removed from the RCU list, we can call -* tcg_exec_unrealizefn and * accel_cpu_common_unrealize, which may free fields using call_rcu. */ accel_cpu_common_unrealize (cpu); -if (tcg_enabled ()) { -tcg_exec_unrealizefn (cpu); - } }/*
Signature · 1 line
2.41.0
Nice. I build-tested and make checked this as well,
Quoted 31 lines · Philippe Mathieu-Daudé
Since v1:
- Use 'target'/'common' in function names (Claudio)
- Added Claudio R-b tagsFrom v1:
- Add missingaccel_cpu_common_unrealize()
- Add AccelClass::cpu_common_[un]realize handlers
- Use tcg_exec_[un]realizefn as AccelClass handlersPhilippe Mathieu-Daudé (7):
accel: Renameaccel_cpu_realizefn()->accel_cpu_realize()
accel: RenameAccelCPUClass::cpu_realizefn()->cpu_target_realize()
accel: Renameaccel_cpu_realize()->accel_cpu_common_realize()
accel: Introduceaccel_cpu_common_unrealize()stub
accel: Declare AccelClass::cpu_common_[un]realize() handlers accel/tcg: Havetcg_exec_realizefn()return a boolean accel/tcg: Restrict tcg_exec_[un]realizefn() to TCGaccel/tcg/internal.h | 3 +++ include/exec/cpu-all.h | 2 -- include/hw/core/accel-cpu.h | 2 +- include/qemu/accel.h | 12 ++++++++++-- accel/accel-common.c | 27 ++++++++++++++++++++++++--- accel/tcg/cpu-exec.c | 4 +++- accel/tcg/tcg-all.c | 2 ++ cpu.c | 13 +++---------- target/i386/hvf/hvf-cpu.c | 2 +- target/i386/kvm/kvm-cpu.c | 4 ++-- target/i386/tcg/tcg-cpu.c | 2 +- 11 files changed, 50 insertions(+), 23 deletions(-)
Quoted 8 lines · Philippe Mathieu-Daudé
Since v1:
- Use 'target'/'common' in function names (Claudio)
- Added Claudio R-b tagsFrom v1:
- Add missingaccel_cpu_common_unrealize()
- Add AccelClass::cpu_common_[un]realize handlers
- Use tcg_exec_[un]realizefn as AccelClass handlers
Thanks, queued to tcg-next, replacing v1 that I queued before my holiday. :-)
r~