On Wed, 30 Oct 2019 17:32:43 +0100 David Gibson <da...@gibson.dropbear.id.au> wrote:
> We have to set the default model of all machine classes, not just for the > active one. Otherwise, "query-machines" will indicate the wrong CPU model > ("qemu-s390x-cpu" instead of "host-s390x-cpu") as "default-cpu-type". > A PPC cpu model might be better. > s390x already fixed this in de60a92e "s390x/kvm: Set default cpu model for > all machine classes". This patch applies a similar fix for the pseries-* > machine types on ppc64. > > Doing a > {"execute":"query-machines"} > under KVM now results in > { > "hotpluggable-cpus": true, > "name": "pseries-4.2", > "numa-mem-supported": true, > "default-cpu-type": "host-powerpc64-cpu", > "is-default": true, > "cpu-max": 1024, > "deprecated": false, > "alias": "pseries" > }, > { > "hotpluggable-cpus": true, > "name": "pseries-4.1", > "numa-mem-supported": true, > "default-cpu-type": "host-powerpc64-cpu", > "cpu-max": 1024, > "deprecated": false > }, > ... > > Libvirt probes all machines via "-machine none,accel=kvm:tcg" and will > currently see the wrong CPU model under KVM. > > Reported-by: Jiři Denemark <jdene...@redhat.com> > Cc: David Hildenbrand <da...@redhat.com> > Cc: Igor Mammedov <imamm...@redhat.com> Missing S-o-b. With these fixed. Reviewed-by: Greg Kurz <gr...@kaod.org> > --- > target/ppc/kvm.c | 21 +++++++++++++-------- > 1 file changed, 13 insertions(+), 8 deletions(-) > > diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c > index 7d2e8969ac..c77f9848ec 100644 > --- a/target/ppc/kvm.c > +++ b/target/ppc/kvm.c > @@ -100,7 +100,7 @@ static bool kvmppc_is_pr(KVMState *ks) > return kvm_vm_check_extension(ks, KVM_CAP_PPC_GET_PVINFO) != 0; > } > > -static int kvm_ppc_register_host_cpu_type(MachineState *ms); > +static int kvm_ppc_register_host_cpu_type(void); > static void kvmppc_get_cpu_characteristics(KVMState *s); > static int kvmppc_get_dec_bits(void); > > @@ -147,7 +147,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s) > exit(1); > } > > - kvm_ppc_register_host_cpu_type(ms); > + kvm_ppc_register_host_cpu_type(); > > return 0; > } > @@ -2534,13 +2534,19 @@ PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void) > return pvr_pcc; > } > > -static int kvm_ppc_register_host_cpu_type(MachineState *ms) > +static void pseries_machine_class_fixup(ObjectClass *oc, void *opaque) > +{ > + MachineClass *mc = MACHINE_CLASS(oc); > + > + mc->default_cpu_type = TYPE_HOST_POWERPC_CPU; > +} > + > +static int kvm_ppc_register_host_cpu_type(void) > { > TypeInfo type_info = { > .name = TYPE_HOST_POWERPC_CPU, > .class_init = kvmppc_host_cpu_class_init, > }; > - MachineClass *mc = MACHINE_GET_CLASS(ms); > PowerPCCPUClass *pvr_pcc; > ObjectClass *oc; > DeviceClass *dc; > @@ -2552,10 +2558,9 @@ static int kvm_ppc_register_host_cpu_type(MachineState > *ms) > } > type_info.parent = object_class_get_name(OBJECT_CLASS(pvr_pcc)); > type_register(&type_info); > - if (object_dynamic_cast(OBJECT(ms), TYPE_SPAPR_MACHINE)) { > - /* override TCG default cpu type with 'host' cpu model */ > - mc->default_cpu_type = TYPE_HOST_POWERPC_CPU; > - } > + /* override TCG default cpu type with 'host' cpu model */ > + object_class_foreach(pseries_machine_class_fixup, TYPE_SPAPR_MACHINE, > + false, NULL); > > oc = object_class_by_name(type_info.name); > g_assert(oc);