On 5/29/2026 11:32 AM, Pierrick Bouvier wrote:
> On 5/29/2026 7:24 AM, Philippe Mathieu-Daudé wrote:
>> accel_cpu_common_realize() first calls accel_cpu->cpu_target_realize
>> then ops->cpu_realize.
>>
>> Rather than having one handler for each host architecture, use a
>> single host-specific method (prefixed with kvm_arch_* like other
>> similar KVM methods). Register it once as AccelOpsClass
>> cpu_target_realize handler.
>>
>> PPC's ACCEL_CPU_NAME("kvm") TypeInfo is now empty, remove it.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
>> ---
>> include/system/kvm.h | 2 ++
>> accel/kvm/kvm-accel-ops.c | 1 +
>> target/i386/kvm/kvm-cpu.c | 3 +--
>> target/ppc/kvm.c | 23 +----------------------
>> target/riscv/kvm/kvm-cpu.c | 10 +---------
>> 5 files changed, 6 insertions(+), 33 deletions(-)
>>
>> diff --git a/include/system/kvm.h b/include/system/kvm.h
>> index 5fa33eddda3..fd7175ea9f5 100644
>> --- a/include/system/kvm.h
>> +++ b/include/system/kvm.h
>> @@ -364,6 +364,8 @@ int kvm_arch_pre_create_vcpu(CPUState *cpu, Error
>> **errp);
>> int kvm_arch_init_vcpu(CPUState *cpu);
>> int kvm_arch_destroy_vcpu(CPUState *cpu);
>>
>> +bool kvm_arch_cpu_realize(CPUState *cpu, Error **errp);
>> +
>> #ifdef TARGET_KVM_HAVE_RESET_PARKED_VCPU
>> void kvm_arch_reset_parked_vcpu(unsigned long vcpu_id, int kvm_fd);
>> #else
>> diff --git a/accel/kvm/kvm-accel-ops.c b/accel/kvm/kvm-accel-ops.c
>> index 6d9140e549f..4294c7a9514 100644
>> --- a/accel/kvm/kvm-accel-ops.c
>> +++ b/accel/kvm/kvm-accel-ops.c
>> @@ -97,6 +97,7 @@ static void kvm_accel_ops_class_init(ObjectClass *oc,
>> const void *data)
>> AccelOpsClass *ops = ACCEL_OPS_CLASS(oc);
>>
>> ops->create_vcpu_thread = kvm_start_vcpu_thread;
>> + ops->cpu_target_realize = kvm_arch_cpu_realize;
>
> cpu_realize
Ignore, I was wrong, confused that with AccelCPUClass.
>
>> ops->cpu_thread_is_idle = kvm_vcpu_thread_is_idle;
>> ops->cpus_are_resettable = kvm_cpus_are_resettable;
>> ops->synchronize_post_reset = kvm_cpu_synchronize_post_reset;
>> diff --git a/target/i386/kvm/kvm-cpu.c b/target/i386/kvm/kvm-cpu.c
>> index c34d9f15c7e..36634ec8929 100644
>> --- a/target/i386/kvm/kvm-cpu.c
>> +++ b/target/i386/kvm/kvm-cpu.c
>> @@ -39,7 +39,7 @@ static void kvm_set_guest_phys_bits(CPUState *cs)
>> }
>> }
>>
>> -static bool kvm_cpu_realizefn(CPUState *cs, Error **errp)
>> +bool kvm_arch_cpu_realize(CPUState *cs, Error **errp)
>> {
>> X86CPU *cpu = X86_CPU(cs);
>> X86CPUClass *xcc = X86_CPU_GET_CLASS(cpu);
>> @@ -237,7 +237,6 @@ static void kvm_cpu_accel_class_init(ObjectClass *oc,
>> const void *data)
>> {
>> AccelCPUClass *acc = ACCEL_CPU_CLASS(oc);
>>
>> - acc->cpu_target_realize = kvm_cpu_realizefn;
>> acc->cpu_instance_init = kvm_cpu_instance_init;
>> }
>> static const TypeInfo kvm_cpu_accel_type_info = {
>> diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
>> index b94c2997a07..013f5e852e1 100644
>> --- a/target/ppc/kvm.c
>> +++ b/target/ppc/kvm.c
>> @@ -49,7 +49,6 @@
>> #include "elf.h"
>> #include "system/kvm_int.h"
>> #include "system/kvm.h"
>> -#include "accel/accel-cpu-target.h"
>>
>> #include CONFIG_DEVICES
>>
>> @@ -2353,7 +2352,7 @@ static void alter_insns(uint64_t *word, uint64_t
>> flags, bool on)
>> }
>> }
>>
>> -static bool kvmppc_cpu_realize(CPUState *cs, Error **errp)
>> +bool kvm_arch_cpu_realize(CPUState *cs, Error **errp)
>> {
>> int ret;
>> const char *vcpu_str = (cs->parent_obj.hotplugged == true) ?
>> @@ -2995,23 +2994,3 @@ void kvmppc_set_reg_tb_offset(PowerPCCPU *cpu,
>> int64_t tb_offset)
>> void kvm_arch_accel_class_init(ObjectClass *oc)
>> {
>> }
>> -
>> -static void kvm_cpu_accel_class_init(ObjectClass *oc, const void *data)
>> -{
>> - AccelCPUClass *acc = ACCEL_CPU_CLASS(oc);
>> -
>> - acc->cpu_target_realize = kvmppc_cpu_realize;
>> -}
>> -
>> -static const TypeInfo kvm_cpu_accel_type_info = {
>> - .name = ACCEL_CPU_NAME("kvm"),
>> -
>> - .parent = TYPE_ACCEL_CPU,
>> - .class_init = kvm_cpu_accel_class_init,
>> - .abstract = true,
>> -};
>> -static void kvm_cpu_accel_register_types(void)
>> -{
>> - type_register_static(&kvm_cpu_accel_type_info);
>> -}
>> -type_init(kvm_cpu_accel_register_types);
>> diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
>> index 17ba38403a3..7c4440d0025 100644
>> --- a/target/riscv/kvm/kvm-cpu.c
>> +++ b/target/riscv/kvm/kvm-cpu.c
>> @@ -1990,14 +1990,7 @@ static void kvm_cpu_instance_init(CPUState *cs)
>> kvm_riscv_add_cpu_user_properties(obj);
>> }
>>
>> -/*
>> - * We'll get here via the following path:
>> - *
>> - * riscv_cpu_realize()
>> - * -> cpu_exec_realizefn()
>> - * -> kvm_cpu_realize() (via accel_cpu_common_realize())
>> - */
>> -static bool kvm_cpu_realize(CPUState *cs, Error **errp)
>> +bool kvm_arch_cpu_realize(CPUState *cs, Error **errp)
>> {
>> RISCVCPU *cpu = RISCV_CPU(cs);
>> int ret;
>> @@ -2120,7 +2113,6 @@ static void kvm_cpu_accel_class_init(ObjectClass *oc,
>> const void *data)
>> AccelCPUClass *acc = ACCEL_CPU_CLASS(oc);
>>
>> acc->cpu_instance_init = kvm_cpu_instance_init;
>> - acc->cpu_target_realize = kvm_cpu_realize;
>> }
>>
>> static const TypeInfo kvm_cpu_accel_type_info = {
>
>
> Reviewed-by: Pierrick Bouvier <[email protected]>
>
> Regards,
> Pierrick