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 v6 2/3] target-i386: x86_cpu_load_features() function
Date: Fri, 7 Oct 2016 17:29:01 -0300 [thread overview]
Message-ID: <1475872142-3986-3-git-send-email-ehabkost@redhat.com> (raw)
In-Reply-To: <1475872142-3986-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 v5 -> v6:
* Move x86_cpu_filter_features() outside x86_cpu_load_features(),
as the CPU model querying API won't run
x86_cpu_filter_features() on most cases
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 | 67 +++++++++++++++++++++++++++++++++++--------------------
1 file changed, 43 insertions(+), 24 deletions(-)
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 1e8127b..23cc19b 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -2993,34 +2993,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
@@ -3086,6 +3065,46 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
env->cpuid_xlevel2 = env->cpuid_min_xlevel2;
}
+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;
+ }
+
+ x86_cpu_filter_features(cpu);
+
if (x86_cpu_filter_features(cpu) &&
(cpu->check_cpuid || cpu->enforce_cpuid)) {
x86_cpu_report_filtered_features(cpu);
--
2.7.4
next prev parent reply other threads:[~2016-10-07 20:29 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-07 20:28 [Qemu-devel] [PATCH v6 0/3] Add runnability info to query-cpu-definitions Eduardo Habkost
2016-10-07 20:29 ` [Qemu-devel] [PATCH v6 1/3] target-i386: Move warning code outside x86_cpu_filter_features() Eduardo Habkost
2016-10-10 11:57 ` Igor Mammedov
2016-10-10 17:04 ` Eduardo Habkost
2016-10-07 20:29 ` Eduardo Habkost [this message]
2016-10-10 12:25 ` [Qemu-devel] [PATCH v6 2/3] target-i386: x86_cpu_load_features() function Igor Mammedov
2016-10-10 16:58 ` [Qemu-devel] [PATCH] fixup! " Eduardo Habkost
2016-10-11 11:41 ` Igor Mammedov
2016-10-14 14:59 ` Eduardo Habkost
2016-10-07 20:29 ` [Qemu-devel] [PATCH v6 3/3] target-i386: Return runnability information on query-cpu-definitions Eduardo Habkost
2016-10-10 12:27 ` Igor Mammedov
2016-10-10 17:01 ` Eduardo Habkost
2016-10-11 11:45 ` Igor Mammedov
2016-10-11 11:58 ` Eduardo Habkost
2016-10-11 13:21 ` Igor Mammedov
2016-10-11 13:24 ` Eduardo Habkost
2016-10-11 13:51 ` Igor Mammedov
2016-10-11 14:13 ` Igor Mammedov
2016-10-14 14:59 ` 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=1475872142-3986-3-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 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).