qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: Anthony Liguori <anthony@codemonkey.ws>
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] [RHEL6 qemu-kvm PATCH 03/11] Add kvm emulated x2apic flag to config defined cpu models (v2)
Date: Thu,  2 Jun 2011 16:13:02 -0300	[thread overview]
Message-ID: <1307041990-26194-4-git-send-email-ehabkost@redhat.com> (raw)
In-Reply-To: <1307041990-26194-1-git-send-email-ehabkost@redhat.com>

From: john cooper <john.cooper@redhat.com>

Add kvm emulated x2apic flag to config defined cpu models
and general support for such hypervisor emulated flags.

In addition to checking user request flags against the host
we also selectively check against kvm for emulated flags.

[ehabkost: made Subject line shorter]
[ehabkost: v2: cosmetic: add "x2apic kvm emulated" comments to conf file]

Signed-off-by: john cooper <john.cooper@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/pc.c                              |    2 +-
 sysconfigs/target/target-x86_64.conf |   12 +++---
 target-i386/cpuid.c                  |   61 ++++++++++++++++++++++++---------
 3 files changed, 51 insertions(+), 24 deletions(-)

diff --git a/hw/pc.c b/hw/pc.c
index 8106197..5b94e53 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -927,7 +927,7 @@ static CPUState *pc_new_cpu(const char *cpu_model)
 
     env = cpu_init(cpu_model);
     if (!env) {
-        fprintf(stderr, "Unable to find x86 CPU definition\n");
+        fprintf(stderr, "Unable to support requested x86 CPU definition\n");
         exit(1);
     }
     if ((env->cpuid_features & CPUID_APIC) || smp_cpus > 1) {
diff --git a/sysconfigs/target/target-x86_64.conf b/sysconfigs/target/target-x86_64.conf
index 0613870..a0df33c 100644
--- a/sysconfigs/target/target-x86_64.conf
+++ b/sysconfigs/target/target-x86_64.conf
@@ -8,7 +8,7 @@
    model = "15"
    stepping = "3"
    feature_edx = "sse2 sse fxsr mmx pat cmov pge sep apic cx8 mce pae msr tsc pse de fpu    mtrr clflush mca pse36"
-   feature_ecx = "sse3 ssse3"
+   feature_ecx = "sse3 ssse3 x2apic"
    extfeature_edx = "fxsr mmx pat cmov pge apic cx8 mce pae msr tsc pse de fpu    lm syscall nx"
    extfeature_ecx = "lahf_lm"
    xlevel = "0x8000000A"
@@ -22,7 +22,7 @@
    model = "23"
    stepping = "3"
    feature_edx = "sse2 sse fxsr mmx pat cmov pge sep apic cx8 mce pae msr tsc pse de fpu    mtrr clflush mca pse36"
-   feature_ecx = "sse3 cx16 ssse3 sse4.1"
+   feature_ecx = "sse3 cx16 ssse3 sse4.1 x2apic"
    extfeature_edx = "fxsr mmx pat cmov pge apic cx8 mce pae msr tsc pse de fpu    lm syscall nx"
    extfeature_ecx = "lahf_lm"
    xlevel = "0x8000000A"
@@ -36,7 +36,7 @@
    model = "26"
    stepping = "3"
    feature_edx = "sse2 sse fxsr mmx pat cmov pge sep apic cx8 mce pae msr tsc pse de fpu    mtrr clflush mca pse36"
-   feature_ecx = "sse3 cx16 ssse3 sse4.1 sse4.2 popcnt"
+   feature_ecx = "sse3 cx16 ssse3 sse4.1 sse4.2 popcnt x2apic"
    extfeature_edx = "fxsr mmx pat cmov pge apic cx8 mce pae msr tsc pse de fpu    lm syscall nx"
    extfeature_ecx = "lahf_lm"
    xlevel = "0x8000000A"
@@ -50,7 +50,7 @@
    model = "6"
    stepping = "1"
    feature_edx = "sse2 sse fxsr mmx pat cmov pge sep apic cx8 mce pae msr tsc pse de fpu    mtrr clflush mca pse36"
-   feature_ecx = "sse3"
+   feature_ecx = "sse3 x2apic"	# x2apic kvm emulated
    extfeature_edx = "fxsr mmx pat cmov pge apic cx8 mce pae msr tsc pse de fpu    lm syscall nx"
 #   extfeature_ecx = ""
    xlevel = "0x80000008"
@@ -64,7 +64,7 @@
    model = "6"
    stepping = "1"
    feature_edx = "sse2 sse fxsr mmx pat cmov pge sep apic cx8 mce pae msr tsc pse de fpu    mtrr clflush mca pse36"
-   feature_ecx = "sse3 cx16"
+   feature_ecx = "sse3 cx16 x2apic"	# x2apic kvm emulated
    extfeature_edx = "fxsr mmx pat cmov pge apic cx8 mce pae msr tsc pse de fpu    lm syscall nx rdtscp"
    extfeature_ecx = "svm lahf_lm"
    xlevel = "0x80000008"
@@ -78,7 +78,7 @@
    model = "6"
    stepping = "1"
    feature_edx = "sse2 sse fxsr mmx pat cmov pge sep apic cx8 mce pae msr tsc pse de fpu    mtrr clflush mca pse36"
-   feature_ecx = "sse3 cx16 monitor popcnt"
+   feature_ecx = "sse3 cx16 monitor popcnt x2apic"	# x2apic kvm emulated
    extfeature_edx = "fxsr mmx pat cmov pge apic cx8 mce pae msr tsc pse de fpu    lm syscall nx rdtscp"
    extfeature_ecx = "svm sse4a  abm misalignsse lahf_lm"
    xlevel = "0x80000008"
diff --git a/target-i386/cpuid.c b/target-i386/cpuid.c
index e479a4d..c151f12 100644
--- a/target-i386/cpuid.c
+++ b/target-i386/cpuid.c
@@ -549,15 +549,40 @@ static int unavailable_host_feature(struct model_features_t *f, uint32_t mask)
     return 0;
 }
 
-/* best effort attempt to inform user requested cpu flags aren't making
- * their way to the guest.  Note: ft[].check_feat ideally should be
- * specified via a guest_def field to suppress report of extraneous flags.
+/* determine the effective set of cpuid features visible to a guest.
+ * in the case kvm is enabled, we also selectively include features
+ * emulated by the hypervisor
  */
-static int check_features_against_host(x86_def_t *guest_def)
+static void summary_cpuid_features(CPUX86State *env, x86_def_t *hd)
+{
+    struct {
+        uint32_t *pfeat, cmd, reg, mask;
+        } fmap[] = {
+            {&hd->features, 0x00000001, R_EDX, 0},
+            {&hd->ext_features, 0x00000001, R_ECX, CPUID_EXT_X2APIC},
+            {&hd->ext2_features, 0x80000001, R_EDX, 0},
+            {&hd->ext3_features, 0x80000001, R_ECX, 0},
+            {NULL} }, *p;
+
+    cpu_x86_fill_host(hd);
+    if (kvm_enabled()) {
+        for (p = fmap; p->pfeat; ++p) {
+            if (p->mask) {
+                *p->pfeat |= p->mask &
+                    kvm_arch_get_supported_cpuid(env, p->cmd, 0, p->reg);
+            }
+        }
+    }
+}
+
+/* inform the user of any requested cpu features (both explicitly requested
+ * flags and implicit cpu model flags) not making their way to the guest
+ */
+static int check_features_against_host(CPUX86State *env, x86_def_t *guest_def)
 {
     x86_def_t host_def;
     uint32_t mask;
-    int rv, i;
+    int rv;
     struct model_features_t ft[] = {
         {&guest_def->features, &host_def.features,
             ~0, feature_name, 0x00000000},
@@ -566,16 +591,16 @@ static int check_features_against_host(x86_def_t *guest_def)
         {&guest_def->ext2_features, &host_def.ext2_features,
             ~PPRO_FEATURES, ext2_feature_name, 0x80000000},
         {&guest_def->ext3_features, &host_def.ext3_features,
-            ~CPUID_EXT3_SVM, ext3_feature_name, 0x80000001}};
+            ~CPUID_EXT3_SVM, ext3_feature_name, 0x80000001},
+        {NULL} }, *p;
 
-    cpu_x86_fill_host(&host_def);
-    for (rv = 0, i = 0; i < ARRAY_SIZE(ft); ++i)
+    summary_cpuid_features(env, &host_def);
+    for (rv = 0, p = ft; p->guest_feat; ++p)
         for (mask = 1; mask; mask <<= 1)
-            if (ft[i].check_feat & mask && *ft[i].guest_feat & mask &&
-                !(*ft[i].host_feat & mask)) {
-                    unavailable_host_feature(&ft[i], mask);
-                    rv = 1;
-                }
+            if (mask & p->check_feat & *p->guest_feat & ~*p->host_feat) {
+                unavailable_host_feature(p, mask);
+                rv = 1;
+            }
     return rv;
 }
 
@@ -602,6 +627,7 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model)
     if (kvm_enabled() && strcmp(name, "host") == 0) {
         cpu_x86_fill_host(x86_cpu_def);
     } else if (!def) {
+        fprintf(stderr, "Unknown cpu model: %s\n", name);
         goto error;
     } else {
         memcpy(x86_cpu_def, def, sizeof(*def));
@@ -715,10 +741,6 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model)
     x86_cpu_def->ext3_features &= ~minus_ext3_features;
     x86_cpu_def->kvm_features &= ~minus_kvm_features;
     x86_cpu_def->svm_features &= ~minus_svm_features;
-    if (check_cpuid) {
-        if (check_features_against_host(x86_cpu_def) && enforce_cpuid)
-            goto error;
-    }
     free(s);
     return 0;
 
@@ -880,6 +902,11 @@ int cpu_x86_register (CPUX86State *env, const char *cpu_model)
             env->cpuid_model[i >> 2] |= c << (8 * (i & 3));
         }
     }
+    if (check_cpuid) {
+        if (check_features_against_host(env, def) && enforce_cpuid) {
+            return -1;
+        }
+    }
     return 0;
 }
 
-- 
1.7.3.2

  parent reply	other threads:[~2011-06-02 19:13 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-02 19:12 [Qemu-devel] [RHEL6 qemu-kvm PATCH 00/11] cpu model bug fixes and definition corrections (v2) Eduardo Habkost
2011-06-02 19:13 ` [Qemu-devel] [RHEL6 qemu-kvm PATCH 01/11] correct archaic CPU model "model" field for Intel CPUs Eduardo Habkost
2011-06-02 19:13 ` [Qemu-devel] [RHEL6 qemu-kvm PATCH 02/11] Allow an optional qemu_early_init_vcpu() Eduardo Habkost
2011-06-02 19:13 ` Eduardo Habkost [this message]
2011-06-02 19:13 ` [Qemu-devel] [RHEL6 qemu-kvm PATCH 04/11] Support -readconfig "?" to debug config file loading Eduardo Habkost
2011-06-02 19:13 ` [Qemu-devel] [RHEL6 qemu-kvm PATCH 05/11] cpu defs: use Intel flag names for Intel models Eduardo Habkost
2011-06-02 19:13 ` [Qemu-devel] [RHEL6 qemu-kvm PATCH 06/11] cpu defs: remove replicated flags from Intel Eduardo Habkost
2011-06-02 19:13 ` [Qemu-devel] [RHEL6 qemu-kvm PATCH 07/11] cpu defs: uncomment empty extfeatures_ecx definition for Opteron_G1 Eduardo Habkost
2011-06-02 19:13 ` [Qemu-devel] [RHEL6 qemu-kvm PATCH 08/11] reorder cpuid feature bits on target-x86_64.conf Eduardo Habkost
2011-06-02 19:13 ` [Qemu-devel] [RHEL6 qemu-kvm PATCH 09/11] cpu defs: add pse36, mca, mtrr to AMD CPU definitions Eduardo Habkost
2011-06-02 19:13 ` [Qemu-devel] [RHEL6 qemu-kvm PATCH 10/11] add Westmere as a qemu cpu model Eduardo Habkost
2011-06-02 19:13 ` [Qemu-devel] [RHEL6 qemu-kvm PATCH 11/11] add "default" pseudo CPU model name Eduardo Habkost
2011-06-02 19:34 ` [Qemu-devel] [PATCH 00/11] cpu model bug fixes and definition corrections (v2) Eduardo Habkost
2011-06-02 22:51   ` Jan Kiszka
2011-06-03 14:38     ` Eduardo Habkost
2011-06-03 14:51       ` Jan Kiszka
2011-06-09  6:43         ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1307041990-26194-4-git-send-email-ehabkost@redhat.com \
    --to=ehabkost@redhat.com \
    --cc=anthony@codemonkey.ws \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).