The PMU feature is only supported by KVM, so move it there. And since
all accelerators other than TCG overwrite the vendor, set it in
max_x86_cpu_initfn only if it has not been initialized by the
superclass. This makes it possible to run max_x86_cpu_initfn
after accelerator init.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
target/i386/cpu.c | 24 ++++++++++++------------
target/i386/kvm/kvm-cpu.c | 2 ++
2 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 69bdffbfe46..46d59229200 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -6204,21 +6204,21 @@ static void max_x86_cpu_class_init(ObjectClass *oc, const void *data)
static void max_x86_cpu_initfn(Object *obj)
{
X86CPU *cpu = X86_CPU(obj);
-
- /* We can't fill the features array here because we don't know yet if
- * "migratable" is true or false.
- */
- object_property_set_bool(OBJECT(cpu), "pmu", true, &error_abort);
+ CPUX86State *env = &cpu->env;
/*
- * these defaults are used for TCG and all other accelerators
- * besides KVM and HVF, which overwrite these values
+ * these defaults are used for TCG, other accelerators overwrite these
+ * values
*/
- object_property_set_str(OBJECT(cpu), "vendor", CPUID_VENDOR_AMD,
- &error_abort);
- object_property_set_str(OBJECT(cpu), "model-id",
- "QEMU TCG CPU version " QEMU_HW_VERSION,
- &error_abort);
+ if (!env->cpuid_vendor1) {
+ object_property_set_str(OBJECT(cpu), "vendor", CPUID_VENDOR_AMD,
+ &error_abort);
+ }
+ if (!env->cpuid_model[0]) {
+ object_property_set_str(OBJECT(cpu), "model-id",
+ "QEMU TCG CPU version " QEMU_HW_VERSION,
+ &error_abort);
+ }
}
static const TypeInfo max_x86_cpu_type_info = {
diff --git a/target/i386/kvm/kvm-cpu.c b/target/i386/kvm/kvm-cpu.c
index 0fb88a239d4..6fed353548e 100644
--- a/target/i386/kvm/kvm-cpu.c
+++ b/target/i386/kvm/kvm-cpu.c
@@ -111,6 +111,8 @@ static void kvm_cpu_max_instance_init(X86CPU *cpu)
host_cpu_max_instance_init(cpu);
+ object_property_set_bool(OBJECT(cpu), "pmu", true, &error_abort);
+
if (lmce_supported()) {
object_property_set_bool(OBJECT(cpu), "lmce", true, &error_abort);
}
--
2.50.0
On Fri, Jul 11, 2025 at 02:06:02AM +0200, Paolo Bonzini wrote: > Date: Fri, 11 Jul 2025 02:06:02 +0200 > From: Paolo Bonzini <pbonzini@redhat.com> > Subject: [PATCH 3/4] target/i386: allow reordering max_x86_cpu_initfn vs > accel CPU init > X-Mailer: git-send-email 2.50.0 > > The PMU feature is only supported by KVM, so move it there. And since > all accelerators other than TCG overwrite the vendor, set it in > max_x86_cpu_initfn only if it has not been initialized by the > superclass. This makes it possible to run max_x86_cpu_initfn > after accelerator init. > > Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> > --- > target/i386/cpu.c | 24 ++++++++++++------------ > target/i386/kvm/kvm-cpu.c | 2 ++ > 2 files changed, 14 insertions(+), 12 deletions(-) Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
On 7/11/2025 8:06 AM, Paolo Bonzini wrote:
> The PMU feature is only supported by KVM, so move it there. And since
> all accelerators other than TCG overwrite the vendor, set it in
> max_x86_cpu_initfn only if it has not been initialized by the
> superclass. This makes it possible to run max_x86_cpu_initfn
> after accelerator init.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
> ---
> target/i386/cpu.c | 24 ++++++++++++------------
> target/i386/kvm/kvm-cpu.c | 2 ++
> 2 files changed, 14 insertions(+), 12 deletions(-)
>
> diff --git a/target/i386/cpu.c b/target/i386/cpu.c
> index 69bdffbfe46..46d59229200 100644
> --- a/target/i386/cpu.c
> +++ b/target/i386/cpu.c
> @@ -6204,21 +6204,21 @@ static void max_x86_cpu_class_init(ObjectClass *oc, const void *data)
> static void max_x86_cpu_initfn(Object *obj)
> {
> X86CPU *cpu = X86_CPU(obj);
> -
> - /* We can't fill the features array here because we don't know yet if
> - * "migratable" is true or false.
> - */
> - object_property_set_bool(OBJECT(cpu), "pmu", true, &error_abort);
> + CPUX86State *env = &cpu->env;
>
> /*
> - * these defaults are used for TCG and all other accelerators
> - * besides KVM and HVF, which overwrite these values
> + * these defaults are used for TCG, other accelerators overwrite these
> + * values
> */
> - object_property_set_str(OBJECT(cpu), "vendor", CPUID_VENDOR_AMD,
> - &error_abort);
> - object_property_set_str(OBJECT(cpu), "model-id",
> - "QEMU TCG CPU version " QEMU_HW_VERSION,
> - &error_abort);
> + if (!env->cpuid_vendor1) {
> + object_property_set_str(OBJECT(cpu), "vendor", CPUID_VENDOR_AMD,
> + &error_abort);
> + }
> + if (!env->cpuid_model[0]) {
> + object_property_set_str(OBJECT(cpu), "model-id",
> + "QEMU TCG CPU version " QEMU_HW_VERSION,
> + &error_abort);
> + }
> }
>
> static const TypeInfo max_x86_cpu_type_info = {
> diff --git a/target/i386/kvm/kvm-cpu.c b/target/i386/kvm/kvm-cpu.c
> index 0fb88a239d4..6fed353548e 100644
> --- a/target/i386/kvm/kvm-cpu.c
> +++ b/target/i386/kvm/kvm-cpu.c
> @@ -111,6 +111,8 @@ static void kvm_cpu_max_instance_init(X86CPU *cpu)
>
> host_cpu_max_instance_init(cpu);
>
> + object_property_set_bool(OBJECT(cpu), "pmu", true, &error_abort);
> +
> if (lmce_supported()) {
> object_property_set_bool(OBJECT(cpu), "lmce", true, &error_abort);
> }
© 2016 - 2025 Red Hat, Inc.