Commit 6d2edc43731d0e804c1c846db1e07bddfb158ebd

Authored by Andre Przywara
Committed by Anthony Liguori
1 parent 707c0dbc

allow hypervisor CPUID bit to be overriden

KVM defaults to the hypervisor CPUID bit to be set, whereas pure
QEMU clears it. On some occasions one wants to set or clear it the
other way round (for instance to get HyperV running inside a guest).

Move the bit-set to be done before the command line parsing and
enable it by default. One can disable it by using: -cpu qemu64,-hypervisor
Fix some whitespace damage on the way.

Signed-off-by: Andre Przywara <andre.przywara@amd.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Showing 1 changed file with 11 additions and 12 deletions
target-i386/helper.c
... ... @@ -44,7 +44,7 @@ static const char *ext_feature_name[] = {
44 44 "pni" /* Intel,AMD sse3 */, NULL, NULL, "monitor", "ds_cpl", "vmx", NULL /* Linux smx */, "est",
45 45 "tm2", "ssse3", "cid", NULL, NULL, "cx16", "xtpr", NULL,
46 46 NULL, NULL, "dca", NULL, NULL, NULL, NULL, "popcnt",
47   - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  47 + NULL, NULL, NULL, NULL, NULL, NULL, NULL, "hypervisor",
48 48 };
49 49 static const char *ext2_feature_name[] = {
50 50 "fpu", "vme", "de", "pse", "tsc", "msr", "pae", "mce",
... ... @@ -59,30 +59,30 @@ static const char *ext3_feature_name[] = {
59 59 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
60 60 };
61 61  
62   -static void add_flagname_to_bitmaps(char *flagname, uint32_t *features,
63   - uint32_t *ext_features,
64   - uint32_t *ext2_features,
  62 +static void add_flagname_to_bitmaps(const char *flagname, uint32_t *features,
  63 + uint32_t *ext_features,
  64 + uint32_t *ext2_features,
65 65 uint32_t *ext3_features)
66 66 {
67 67 int i;
68 68 int found = 0;
69 69  
70   - for ( i = 0 ; i < 32 ; i++ )
  70 + for ( i = 0 ; i < 32 ; i++ )
71 71 if (feature_name[i] && !strcmp (flagname, feature_name[i])) {
72 72 *features |= 1 << i;
73 73 found = 1;
74 74 }
75   - for ( i = 0 ; i < 32 ; i++ )
  75 + for ( i = 0 ; i < 32 ; i++ )
76 76 if (ext_feature_name[i] && !strcmp (flagname, ext_feature_name[i])) {
77 77 *ext_features |= 1 << i;
78 78 found = 1;
79 79 }
80   - for ( i = 0 ; i < 32 ; i++ )
  80 + for ( i = 0 ; i < 32 ; i++ )
81 81 if (ext2_feature_name[i] && !strcmp (flagname, ext2_feature_name[i])) {
82 82 *ext2_features |= 1 << i;
83 83 found = 1;
84 84 }
85   - for ( i = 0 ; i < 32 ; i++ )
  85 + for ( i = 0 ; i < 32 ; i++ )
86 86 if (ext3_feature_name[i] && !strcmp (flagname, ext3_feature_name[i])) {
87 87 *ext3_features |= 1 << i;
88 88 found = 1;
... ... @@ -330,6 +330,9 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model)
330 330 goto error;
331 331 memcpy(x86_cpu_def, def, sizeof(*def));
332 332  
  333 + add_flagname_to_bitmaps("hypervisor", &plus_features,
  334 + &plus_ext_features, &plus_ext2_features, &plus_ext3_features);
  335 +
333 336 featurestr = strtok(NULL, ",");
334 337  
335 338 while (featurestr) {
... ... @@ -1523,10 +1526,6 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
1523 1526 *ebx = (env->cpuid_apic_id << 24) | 8 << 8; /* CLFLUSH size in quad words, Linux wants it. */
1524 1527 *ecx = env->cpuid_ext_features;
1525 1528 *edx = env->cpuid_features;
1526   -
1527   - /* "Hypervisor present" bit required for Microsoft SVVP */
1528   - if (kvm_enabled())
1529   - *ecx |= (1 << 31);
1530 1529 break;
1531 1530 case 2:
1532 1531 /* cache info: needed for Pentium Pro compatibility */
... ...