提交 9337e3b6 编写于 作者: E Eduardo Habkost 提交者: Andreas Färber

target-i386: Disable PMU CPUID leaf by default

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=on 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: NEduardo Habkost <ehabkost@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: NAndreas Färber <afaerber@suse.de>
上级 c1399112
...@@ -235,6 +235,10 @@ int e820_add_entry(uint64_t, uint64_t, uint32_t); ...@@ -235,6 +235,10 @@ int e820_add_entry(uint64_t, uint64_t, uint32_t);
.driver = "virtio-net-pci",\ .driver = "virtio-net-pci",\
.property = "any_layout",\ .property = "any_layout",\
.value = "off",\ .value = "off",\
},{\
.driver = TYPE_X86_CPU,\
.property = "pmu",\
.value = "on",\
} }
#define PC_COMPAT_1_4 \ #define PC_COMPAT_1_4 \
......
...@@ -68,6 +68,13 @@ typedef struct X86CPU { ...@@ -68,6 +68,13 @@ typedef struct X86CPU {
/* Features that were filtered out because of missing host capabilities */ /* Features that were filtered out because of missing host capabilities */
uint32_t filtered_features[FEATURE_WORDS]; uint32_t filtered_features[FEATURE_WORDS];
/* Enable PMU CPUID bits. This can't be enabled by default yet because
* it doesn't have ABI stability guarantees, as it passes all PMU CPUID
* bits returned by GET_SUPPORTED_CPUID (that depend on host CPU and kernel
* capabilities) directly to the guest.
*/
bool enable_pmu;
} X86CPU; } X86CPU;
static inline X86CPU *x86_env_get_cpu(CPUX86State *env) static inline X86CPU *x86_env_get_cpu(CPUX86State *env)
......
...@@ -1479,6 +1479,7 @@ static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def, ...@@ -1479,6 +1479,7 @@ static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def,
const char *name) const char *name)
{ {
x86_def_t *def; x86_def_t *def;
Error *err = NULL;
int i; int i;
if (name == NULL) { if (name == NULL) {
...@@ -1486,6 +1487,8 @@ static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def, ...@@ -1486,6 +1487,8 @@ static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def,
} }
if (kvm_enabled() && strcmp(name, "host") == 0) { if (kvm_enabled() && strcmp(name, "host") == 0) {
kvm_cpu_fill_host(x86_cpu_def); kvm_cpu_fill_host(x86_cpu_def);
object_property_set_bool(OBJECT(cpu), true, "pmu", &err);
assert_no_error(err);
return 0; return 0;
} }
...@@ -2017,7 +2020,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, ...@@ -2017,7 +2020,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
break; break;
case 0xA: case 0xA:
/* Architectural Performance Monitoring Leaf */ /* Architectural Performance Monitoring Leaf */
if (kvm_enabled()) { if (kvm_enabled() && cpu->enable_pmu) {
KVMState *s = cs->kvm_state; KVMState *s = cs->kvm_state;
*eax = kvm_arch_get_supported_cpuid(s, 0xA, count, R_EAX); *eax = 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) ...@@ -2523,6 +2526,11 @@ static void x86_cpu_synchronize_from_tb(CPUState *cs, TranslationBlock *tb)
cpu->env.eip = tb->pc - tb->cs_base; cpu->env.eip = tb->pc - tb->cs_base;
} }
static Property x86_cpu_properties[] = {
DEFINE_PROP_BOOL("pmu", X86CPU, enable_pmu, false),
DEFINE_PROP_END_OF_LIST()
};
static void x86_cpu_common_class_init(ObjectClass *oc, void *data) static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
{ {
X86CPUClass *xcc = X86_CPU_CLASS(oc); X86CPUClass *xcc = X86_CPU_CLASS(oc);
...@@ -2532,6 +2540,7 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data) ...@@ -2532,6 +2540,7 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
xcc->parent_realize = dc->realize; xcc->parent_realize = dc->realize;
dc->realize = x86_cpu_realizefn; dc->realize = x86_cpu_realizefn;
dc->bus_type = TYPE_ICC_BUS; dc->bus_type = TYPE_ICC_BUS;
dc->props = x86_cpu_properties;
xcc->parent_reset = cc->reset; xcc->parent_reset = cc->reset;
cc->reset = x86_cpu_reset; cc->reset = x86_cpu_reset;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册