All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: qemu-devel@nongnu.org
Cc: dahi@linux.vnet.ibm.com, Paolo Bonzini <pbonzini@redhat.com>,
	Igor Mammedov <imammedo@redhat.com>,
	Jiri Denemark <jdenemar@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	Richard Henderson <rth@twiddle.net>,
	libvir-list@redhat.com
Subject: [Qemu-devel] [PATCH v5 10/12] target-i386: x86_cpu_load_features() function
Date: Fri, 30 Sep 2016 15:49:44 -0300	[thread overview]
Message-ID: <1475261386-20211-11-git-send-email-ehabkost@redhat.com> (raw)
In-Reply-To: <1475261386-20211-1-git-send-email-ehabkost@redhat.com>

When probing for CPU model information, we need to reuse the code
that initializes CPUID fields, but not the remaining side-effects
of x86_cpu_realizefn(). Move that code to a separate function
that can be reused later.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Changes v4 -> v5:
* Fix typo on x86_cpu_load_features() comment
  Reported-by: Paolo Bonzini <pbonzini@redhat.com>

Changes series v3 -> v4:
* New patch added to series
---
 target-i386/cpu.c | 66 +++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 42 insertions(+), 24 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 636e629..e4b45e3 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -2991,34 +2991,13 @@ static void x86_cpu_enable_xsave_components(X86CPU *cpu)
     env->features[FEAT_XSAVE_COMP_HI] = mask >> 32;
 }
 
-#define IS_INTEL_CPU(env) ((env)->cpuid_vendor1 == CPUID_VENDOR_INTEL_1 && \
-                           (env)->cpuid_vendor2 == CPUID_VENDOR_INTEL_2 && \
-                           (env)->cpuid_vendor3 == CPUID_VENDOR_INTEL_3)
-#define IS_AMD_CPU(env) ((env)->cpuid_vendor1 == CPUID_VENDOR_AMD_1 && \
-                         (env)->cpuid_vendor2 == CPUID_VENDOR_AMD_2 && \
-                         (env)->cpuid_vendor3 == CPUID_VENDOR_AMD_3)
-static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
+/* Load CPUID data based on configured features */
+static void x86_cpu_load_features(X86CPU *cpu, Error **errp)
 {
-    CPUState *cs = CPU(dev);
-    X86CPU *cpu = X86_CPU(dev);
-    X86CPUClass *xcc = X86_CPU_GET_CLASS(dev);
     CPUX86State *env = &cpu->env;
-    Error *local_err = NULL;
-    static bool ht_warned;
     FeatureWord w;
     GList *l;
-
-    if (xcc->kvm_required && !kvm_enabled()) {
-        char *name = x86_cpu_class_get_model_name(xcc);
-        error_setg(&local_err, "CPU model '%s' requires KVM", name);
-        g_free(name);
-        goto out;
-    }
-
-    if (cpu->apic_id == UNASSIGNED_APIC_ID) {
-        error_setg(errp, "apic-id property was not initialized properly");
-        return;
-    }
+    Error *local_err = NULL;
 
     /*TODO: cpu->host_features incorrectly overwrites features
      * set using "feat=on|off". Once we fix this, we can convert
@@ -3085,6 +3064,45 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
     }
 
     x86_cpu_filter_features(cpu);
+
+out:
+    if (local_err != NULL) {
+        error_propagate(errp, local_err);
+    }
+}
+
+#define IS_INTEL_CPU(env) ((env)->cpuid_vendor1 == CPUID_VENDOR_INTEL_1 && \
+                           (env)->cpuid_vendor2 == CPUID_VENDOR_INTEL_2 && \
+                           (env)->cpuid_vendor3 == CPUID_VENDOR_INTEL_3)
+#define IS_AMD_CPU(env) ((env)->cpuid_vendor1 == CPUID_VENDOR_AMD_1 && \
+                         (env)->cpuid_vendor2 == CPUID_VENDOR_AMD_2 && \
+                         (env)->cpuid_vendor3 == CPUID_VENDOR_AMD_3)
+static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
+{
+    CPUState *cs = CPU(dev);
+    X86CPU *cpu = X86_CPU(dev);
+    X86CPUClass *xcc = X86_CPU_GET_CLASS(dev);
+    CPUX86State *env = &cpu->env;
+    Error *local_err = NULL;
+    static bool ht_warned;
+
+    if (xcc->kvm_required && !kvm_enabled()) {
+        char *name = x86_cpu_class_get_model_name(xcc);
+        error_setg(&local_err, "CPU model '%s' requires KVM", name);
+        g_free(name);
+        goto out;
+    }
+
+    if (cpu->apic_id == UNASSIGNED_APIC_ID) {
+        error_setg(errp, "apic-id property was not initialized properly");
+        return;
+    }
+
+    x86_cpu_load_features(cpu, &local_err);
+    if (local_err) {
+        goto out;
+    }
+
     if (cpu->check_cpuid || cpu->enforce_cpuid) {
         if (x86_cpu_report_filtered_features(cpu) && cpu->enforce_cpuid) {
             error_setg(&local_err,
-- 
2.7.4

  parent reply	other threads:[~2016-09-30 18:50 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-30 18:49 [Qemu-devel] [PATCH v5 00/12] Add runnability info to query-cpu-definitions Eduardo Habkost
2016-09-30 18:49 ` [Qemu-devel] [PATCH v5 01/12] tests: Add test case for x86 feature parsing compatibility Eduardo Habkost
2016-09-30 18:49 ` [Qemu-devel] [PATCH v5 02/12] target-i386: List CPU models using subclass list Eduardo Habkost
2016-09-30 18:49 ` [Qemu-devel] [PATCH v5 03/12] target-i386: Disable VME by default with TCG Eduardo Habkost
2016-09-30 18:49 ` [Qemu-devel] [PATCH v5 04/12] target-i386: Register aliases for feature names with underscores Eduardo Habkost
2016-09-30 19:56   ` [Qemu-devel] [libvirt] " Eric Blake
2016-09-30 20:59     ` Eduardo Habkost
2016-09-30 18:49 ` [Qemu-devel] [PATCH v5 05/12] target-i386: Make plus_features/minus_features QOM-based Eduardo Habkost
2016-11-25 14:51   ` Markus Armbruster
2016-09-30 18:49 ` [Qemu-devel] [PATCH v5 06/12] target-i386: Remove underscores from feat_names arrays Eduardo Habkost
2016-09-30 18:49 ` [Qemu-devel] [PATCH v5 07/12] target-i386: Register properties for feature aliases manually Eduardo Habkost
2016-09-30 18:49 ` [Qemu-devel] [PATCH v5 08/12] target-i386: xsave: Add FP and SSE bits to x86_ext_save_areas Eduardo Habkost
2016-09-30 18:49 ` [Qemu-devel] [PATCH v5 09/12] target-i386: Move warning code outside x86_cpu_filter_features() Eduardo Habkost
2016-09-30 18:49 ` Eduardo Habkost [this message]
2016-09-30 18:49 ` [Qemu-devel] [PATCH v5 11/12] qmp: Add runnability information to query-cpu-definitions Eduardo Habkost
2016-10-07 20:25   ` Eduardo Habkost
2016-09-30 18:49 ` [Qemu-devel] [PATCH v5 12/12] target-i386: Return runnability information on query-cpu-definitions Eduardo Habkost
2016-10-07 18:54 ` [Qemu-devel] [PATCH v5 00/12] Add runnability info to query-cpu-definitions Eduardo Habkost

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=1475261386-20211-11-git-send-email-ehabkost@redhat.com \
    --to=ehabkost@redhat.com \
    --cc=armbru@redhat.com \
    --cc=dahi@linux.vnet.ibm.com \
    --cc=imammedo@redhat.com \
    --cc=jdenemar@redhat.com \
    --cc=libvir-list@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.