[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 13/19] target-i386: Add "migratable" property to "hos
From: |
Andreas Färber |
Subject: |
[Qemu-devel] [PULL 13/19] target-i386: Add "migratable" property to "host" CPU model |
Date: |
Thu, 26 Jun 2014 00:12:13 +0200 |
From: Eduardo Habkost <address@hidden>
This flag will allow the user to choose between two modes:
* All flags that can be enabled on the host, even if unmigratable
(migratable=no);
* All flags that can be enabled on the host, are known to QEMU
and migratable (migratable=yes).
The default is still migratable=false, to keep current behavior, but
this will be changed to migratable=true by another patch.
My plan was to support the "migratable" flag on all CPU classes, but
have the default to "false" on all CPU models except "host". However,
DeviceClass has no mechanism to allow a child class to have a different
property default from the parent class yet, so by now only the "host"
CPU model will support the "migratable" flag.
Signed-off-by: Eduardo Habkost <address@hidden>
Signed-off-by: Andreas Färber <address@hidden>
---
target-i386/cpu-qom.h | 4 ++++
target-i386/cpu.c | 60 +++++++++++++++++++++++++++++++++++++++++++--------
2 files changed, 55 insertions(+), 9 deletions(-)
diff --git a/target-i386/cpu-qom.h b/target-i386/cpu-qom.h
index 0808cfc..ff3a5de 100644
--- a/target-i386/cpu-qom.h
+++ b/target-i386/cpu-qom.h
@@ -71,6 +71,9 @@ typedef struct X86CPUClass {
/**
* X86CPU:
* @env: #CPUX86State
+ * @migratable: If set, only migratable flags will be accepted when "enforce"
+ * mode is used, and only migratable flags will be included in the "host"
+ * CPU model.
*
* An x86 CPU.
*/
@@ -88,6 +91,7 @@ typedef struct X86CPU {
bool check_cpuid;
bool enforce_cpuid;
bool expose_kvm;
+ bool migratable;
/* if true the CPUID code directly forward host cache leaves to the guest
*/
bool cache_info_passthrough;
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index d789cba..7d8f9e7 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -326,6 +326,7 @@ typedef struct FeatureWordInfo {
uint32_t cpuid_ecx; /* Input ECX value for CPUID */
int cpuid_reg; /* output register (R_* constant) */
uint32_t tcg_features; /* Feature flags supported by TCG */
+ uint32_t unmigratable_flags; /* Feature flags known to be unmigratable */
} FeatureWordInfo;
static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
@@ -449,6 +450,31 @@ void x86_cpu_compat_disable_kvm_features(FeatureWord w,
uint32_t features)
kvm_default_features[w] &= ~features;
}
+/*
+ * Returns the set of feature flags that are supported and migratable by
+ * QEMU, for a given FeatureWord.
+ */
+static uint32_t x86_cpu_get_migratable_flags(FeatureWord w)
+{
+ FeatureWordInfo *wi = &feature_word_info[w];
+ uint32_t r = 0;
+ int i;
+
+ for (i = 0; i < 32; i++) {
+ uint32_t f = 1U << i;
+ /* If the feature name is unknown, it is not supported by QEMU yet */
+ if (!wi->feat_names[i]) {
+ continue;
+ }
+ /* Skip features known to QEMU, but explicitly marked as unmigratable
*/
+ if (wi->unmigratable_flags & f) {
+ continue;
+ }
+ r |= f;
+ }
+ return r;
+}
+
void host_cpuid(uint32_t function, uint32_t count,
uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
{
@@ -1194,12 +1220,18 @@ static int cpu_x86_fill_model_id(char *str)
static X86CPUDefinition host_cpudef;
+static Property host_x86_cpu_properties[] = {
+ DEFINE_PROP_BOOL("migratable", X86CPU, migratable, false),
+ DEFINE_PROP_END_OF_LIST()
+};
+
/* class_init for the "host" CPU model
*
* This function may be called before KVM is initialized.
*/
static void host_x86_cpu_class_init(ObjectClass *oc, void *data)
{
+ DeviceClass *dc = DEVICE_CLASS(oc);
X86CPUClass *xcc = X86_CPU_CLASS(oc);
uint32_t eax = 0, ebx = 0, ecx = 0, edx = 0;
@@ -1221,8 +1253,13 @@ static void host_x86_cpu_class_init(ObjectClass *oc,
void *data)
/* level, xlevel, xlevel2, and the feature words are initialized on
* instance_init, because they require KVM to be initialized.
*/
+
+ dc->props = host_x86_cpu_properties;
}
+static uint32_t x86_cpu_get_supported_feature_word(FeatureWord w,
+ bool migratable_only);
+
static void host_x86_cpu_initfn(Object *obj)
{
X86CPU *cpu = X86_CPU(obj);
@@ -1237,10 +1274,8 @@ static void host_x86_cpu_initfn(Object *obj)
env->cpuid_xlevel2 = kvm_arch_get_supported_cpuid(s, 0xC0000000, 0, R_EAX);
for (w = 0; w < FEATURE_WORDS; w++) {
- FeatureWordInfo *wi = &feature_word_info[w];
env->features[w] =
- kvm_arch_get_supported_cpuid(s, wi->cpuid_eax, wi->cpuid_ecx,
- wi->cpuid_reg);
+ x86_cpu_get_supported_feature_word(w, cpu->migratable);
}
object_property_set_bool(OBJECT(cpu), true, "pmu", &error_abort);
}
@@ -1826,19 +1861,25 @@ CpuDefinitionInfoList *arch_query_cpu_definitions(Error
**errp)
return cpu_list;
}
-static uint32_t x86_cpu_get_supported_feature_word(FeatureWord w)
+static uint32_t x86_cpu_get_supported_feature_word(FeatureWord w,
+ bool migratable_only)
{
FeatureWordInfo *wi = &feature_word_info[w];
+ uint32_t r;
if (kvm_enabled()) {
- return kvm_arch_get_supported_cpuid(kvm_state, wi->cpuid_eax,
- wi->cpuid_ecx,
- wi->cpuid_reg);
+ r = kvm_arch_get_supported_cpuid(kvm_state, wi->cpuid_eax,
+ wi->cpuid_ecx,
+ wi->cpuid_reg);
} else if (tcg_enabled()) {
- return wi->tcg_features;
+ r = wi->tcg_features;
} else {
return ~0;
}
+ if (migratable_only) {
+ r &= x86_cpu_get_migratable_flags(w);
+ }
+ return r;
}
/*
@@ -1853,7 +1894,8 @@ static int x86_cpu_filter_features(X86CPU *cpu)
int rv = 0;
for (w = 0; w < FEATURE_WORDS; w++) {
- uint32_t host_feat = x86_cpu_get_supported_feature_word(w);
+ uint32_t host_feat =
+ x86_cpu_get_supported_feature_word(w, cpu->migratable);
uint32_t requested_features = env->features[w];
env->features[w] &= host_feat;
cpu->filtered_features[w] = requested_features & ~env->features[w];
--
1.8.4.5
- [Qemu-devel] [PULL 01/19] target-i386: kvm: Don't enable MONITOR by default on any CPU model, (continued)
- [Qemu-devel] [PULL 01/19] target-i386: kvm: Don't enable MONITOR by default on any CPU model, Andreas Färber, 2014/06/25
- [Qemu-devel] [PULL 12/19] target-i386: Support check/enforce flags in TCG mode, too, Andreas Färber, 2014/06/25
- [Qemu-devel] [PULL 03/19] target-i386: Merge feature filtering/checking functions, Andreas Färber, 2014/06/25
- [Qemu-devel] [PULL 02/19] target-i386: Simplify reporting of unavailable features, Andreas Färber, 2014/06/25
- [Qemu-devel] [PULL 06/19] target-i386: Make TCG feature filtering more readable, Andreas Färber, 2014/06/25
- [Qemu-devel] [PULL 07/19] target-i386: Filter FEAT_7_0_EBX TCG features too, Andreas Färber, 2014/06/25
- [Qemu-devel] [PULL 09/19] target-i386: Define TCG_*_FEATURES earlier in cpu.c, Andreas Färber, 2014/06/25
- [Qemu-devel] [PULL 05/19] target-i386: Isolate KVM-specific code on CPU feature filtering logic, Andreas Färber, 2014/06/25
- [Qemu-devel] [PULL 10/19] target-i386: Loop-based copying and setting/unsetting of feature words, Andreas Färber, 2014/06/25
- [Qemu-devel] [PULL 04/19] target-i386: Pass FeatureWord argument to report_unavailable_features(), Andreas Färber, 2014/06/25
- [Qemu-devel] [PULL 13/19] target-i386: Add "migratable" property to "host" CPU model,
Andreas Färber <=
- [Qemu-devel] [PULL 11/19] target-i386: Loop-based feature word filtering in TCG mode, Andreas Färber, 2014/06/25
- [Qemu-devel] [PULL 08/19] target-i386: Filter KVM and 0xC0000001 features on TCG, Andreas Färber, 2014/06/25
- [Qemu-devel] [PULL 16/19] target-i386: block migration and savevm if invariant tsc is exposed, Andreas Färber, 2014/06/25
- [Qemu-devel] [PULL 14/19] target-i386: Set migratable=yes by default on "host" CPU mooel, Andreas Färber, 2014/06/25
- [Qemu-devel] [PULL 17/19] target-i386: Support "invariant tsc" flag, Andreas Färber, 2014/06/25
- [Qemu-devel] [PULL 19/19] target-i386: Broadwell CPU model, Andreas Färber, 2014/06/25
- [Qemu-devel] [PULL 15/19] savevm: check vmsd for migratability status, Andreas Färber, 2014/06/25
- [Qemu-devel] [PULL 18/19] target-i386: Fix indentation of CPU model definitions, Andreas Färber, 2014/06/25
- Re: [Qemu-devel] [PULL 00/19] QOM CPUState patch queue 2014-06-26, Peter Maydell, 2014/06/26