Skip to content

Commit 82d80e1

Browse files
ehabkostmdroth
authored andcommitted
target-i386: Support migratable=no properly
When the "migratable" property was implemented, the behavior was tested by changing the default on the code, but actually using the option on the command-line (e.g. "-cpu host,migratable=false") doesn't work as expected. This is a regression for a common use case of "-cpu host", which is to enable features that are supported by the host CPU + kernel before feature-specific code is added to QEMU. Fix this by initializing the feature words for "-cpu host" on x86_cpu_parse_featurestr(), right after parsing the CPU options. Signed-off-by: Eduardo Habkost <[email protected]> Reviewed-by: Michael Roth <[email protected]> Cc: [email protected] Signed-off-by: Andreas Färber <[email protected]> (cherry picked from commit 4d1b279) Signed-off-by: Michael Roth <[email protected]>
1 parent 5dd076a commit 82d80e1

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

target-i386/cpu-qom.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ typedef struct X86CPU {
9292
bool enforce_cpuid;
9393
bool expose_kvm;
9494
bool migratable;
95+
bool host_features;
9596

9697
/* if true the CPUID code directly forward host cache leaves to the guest */
9798
bool cache_info_passthrough;

target-i386/cpu.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,9 @@ void x86_cpu_compat_set_features(const char *cpu_model, FeatureWord w,
12541254
}
12551255
}
12561256

1257+
static uint32_t x86_cpu_get_supported_feature_word(FeatureWord w,
1258+
bool migratable_only);
1259+
12571260
#ifdef CONFIG_KVM
12581261

12591262
static int cpu_x86_fill_model_id(char *str)
@@ -1310,26 +1313,23 @@ static void host_x86_cpu_class_init(ObjectClass *oc, void *data)
13101313
dc->props = host_x86_cpu_properties;
13111314
}
13121315

1313-
static uint32_t x86_cpu_get_supported_feature_word(FeatureWord w,
1314-
bool migratable_only);
1315-
13161316
static void host_x86_cpu_initfn(Object *obj)
13171317
{
13181318
X86CPU *cpu = X86_CPU(obj);
13191319
CPUX86State *env = &cpu->env;
13201320
KVMState *s = kvm_state;
1321-
FeatureWord w;
13221321

13231322
assert(kvm_enabled());
13241323

1324+
/* We can't fill the features array here because we don't know yet if
1325+
* "migratable" is true or false.
1326+
*/
1327+
cpu->host_features = true;
1328+
13251329
env->cpuid_level = kvm_arch_get_supported_cpuid(s, 0x0, 0, R_EAX);
13261330
env->cpuid_xlevel = kvm_arch_get_supported_cpuid(s, 0x80000000, 0, R_EAX);
13271331
env->cpuid_xlevel2 = kvm_arch_get_supported_cpuid(s, 0xC0000000, 0, R_EAX);
13281332

1329-
for (w = 0; w < FEATURE_WORDS; w++) {
1330-
env->features[w] =
1331-
x86_cpu_get_supported_feature_word(w, cpu->migratable);
1332-
}
13331333
object_property_set_bool(OBJECT(cpu), true, "pmu", &error_abort);
13341334
}
13351335

@@ -1828,6 +1828,13 @@ static void x86_cpu_parse_featurestr(CPUState *cs, char *features,
18281828
featurestr = strtok(NULL, ",");
18291829
}
18301830

1831+
if (cpu->host_features) {
1832+
for (w = 0; w < FEATURE_WORDS; w++) {
1833+
env->features[w] =
1834+
x86_cpu_get_supported_feature_word(w, cpu->migratable);
1835+
}
1836+
}
1837+
18311838
for (w = 0; w < FEATURE_WORDS; w++) {
18321839
env->features[w] |= plus_features[w];
18331840
env->features[w] &= ~minus_features[w];

0 commit comments

Comments
 (0)