From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50259) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V3pR9-0001oz-6h for qemu-devel@nongnu.org; Mon, 29 Jul 2013 11:32:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V3pQz-0001Ea-7x for qemu-devel@nongnu.org; Mon, 29 Jul 2013 11:32:39 -0400 Received: from cantor2.suse.de ([195.135.220.15]:44584 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V3pQy-0001EP-Vm for qemu-devel@nongnu.org; Mon, 29 Jul 2013 11:32:29 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Mon, 29 Jul 2013 17:32:19 +0200 Message-Id: <1375111939-19577-4-git-send-email-afaerber@suse.de> In-Reply-To: <1375111939-19577-1-git-send-email-afaerber@suse.de> References: <1375111939-19577-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL for-1.6 3/3] target-i386: Disable PMU CPUID leaf by default List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Eduardo Habkost , =?UTF-8?q?Andreas=20F=C3=A4rber?= From: Eduardo Habkost Bug description: QEMU currently gets all bits from GET_SUPPORTED_CPUID for CPUID leaf 0xA and passes them directly to the guest. This makes the guest ABI depend on host kernel and host CPU capabilities, and breaks live migration if we migrate between hosts with different capabilities (e.g., different number of PMU counters). Add a "pmu" property to X86CPU, and set it to true only on "-cpu host", or on pc-*-1.5 and older machine-types. For now, setting pmu=3Don will enable the current passthrough mode that doesn't have any ABI stability guarantees, but in the future we may implement a mode where the PMU CPUID bits are stable and configurable. Signed-off-by: Eduardo Habkost Cc: Paolo Bonzini Signed-off-by: Andreas F=C3=A4rber --- include/hw/i386/pc.h | 4 ++++ target-i386/cpu-qom.h | 7 +++++++ target-i386/cpu.c | 11 ++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 7fb97b0..09c2dd4 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -235,6 +235,10 @@ int e820_add_entry(uint64_t, uint64_t, uint32_t); .driver =3D "virtio-net-pci",\ .property =3D "any_layout",\ .value =3D "off",\ + },{\ + .driver =3D TYPE_X86_CPU,\ + .property =3D "pmu",\ + .value =3D "on",\ } =20 #define PC_COMPAT_1_4 \ diff --git a/target-i386/cpu-qom.h b/target-i386/cpu-qom.h index 60d2b5d..53b4c34 100644 --- a/target-i386/cpu-qom.h +++ b/target-i386/cpu-qom.h @@ -68,6 +68,13 @@ typedef struct X86CPU { =20 /* Features that were filtered out because of missing host capabilit= ies */ uint32_t filtered_features[FEATURE_WORDS]; + + /* Enable PMU CPUID bits. This can't be enabled by default yet becau= se + * it doesn't have ABI stability guarantees, as it passes all PMU CP= UID + * bits returned by GET_SUPPORTED_CPUID (that depend on host CPU and= kernel + * capabilities) directly to the guest. + */ + bool enable_pmu; } X86CPU; =20 static inline X86CPU *x86_env_get_cpu(CPUX86State *env) diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 80143bf..71ab915 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -1479,6 +1479,7 @@ static int cpu_x86_find_by_name(X86CPU *cpu, x86_de= f_t *x86_cpu_def, const char *name) { x86_def_t *def; + Error *err =3D NULL; int i; =20 if (name =3D=3D NULL) { @@ -1486,6 +1487,8 @@ static int cpu_x86_find_by_name(X86CPU *cpu, x86_de= f_t *x86_cpu_def, } if (kvm_enabled() && strcmp(name, "host") =3D=3D 0) { kvm_cpu_fill_host(x86_cpu_def); + object_property_set_bool(OBJECT(cpu), true, "pmu", &err); + assert_no_error(err); return 0; } =20 @@ -2017,7 +2020,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index= , uint32_t count, break; case 0xA: /* Architectural Performance Monitoring Leaf */ - if (kvm_enabled()) { + if (kvm_enabled() && cpu->enable_pmu) { KVMState *s =3D cs->kvm_state; =20 *eax =3D kvm_arch_get_supported_cpuid(s, 0xA, count, R_EAX); @@ -2523,6 +2526,11 @@ static void x86_cpu_synchronize_from_tb(CPUState *= cs, TranslationBlock *tb) cpu->env.eip =3D tb->pc - tb->cs_base; } =20 +static Property x86_cpu_properties[] =3D { + DEFINE_PROP_BOOL("pmu", X86CPU, enable_pmu, false), + DEFINE_PROP_END_OF_LIST() +}; + static void x86_cpu_common_class_init(ObjectClass *oc, void *data) { X86CPUClass *xcc =3D X86_CPU_CLASS(oc); @@ -2532,6 +2540,7 @@ static void x86_cpu_common_class_init(ObjectClass *= oc, void *data) xcc->parent_realize =3D dc->realize; dc->realize =3D x86_cpu_realizefn; dc->bus_type =3D TYPE_ICC_BUS; + dc->props =3D x86_cpu_properties; =20 xcc->parent_reset =3D cc->reset; cc->reset =3D x86_cpu_reset; --=20 1.8.1.4