This series extends query-cpu-definitions to include an extra
field: "unavailable-features". The new field can be used to find
out reasons that prevent the CPU model from running in the
current host.
This will return information based on the current machine and
accelerator only. In the future we may extend these mechanisms to
allow querying other machines and other accelerators without
restarting QEMU, but it will require some reorganization of
QEMU's main code.
To be able to implement this more cleanly, the series rework some
of the feature/property name code.
This series can be seen in the git branch at:
https://github.com/ehabkost/qemu-hacks.git work/query-cpu-definitions-runnable-info
The series is based on my x86-next branch:
https://github.com/ehabkost/qemu.git x86-next
Changes v5 -> v6:
* Rebased to x86-next, that already has 8 of the previous patches
from v5 applied
* Removed x86_cpu_filter_features() from x86_cpu_load_features(),
because some of the commands in the CPU model query API need
info about CPU models before filtering
* Recovered v3 of
"target-i386: Move warning code outside x86_cpu_filter_features()"
because now we can keep the simpler logic that checked
the return value of x86_cpu_filter_features()
Diff v5 -> v6:
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index d53e711..63330ce 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -2052,6 +2052,7 @@ static void x86_cpu_parse_featurestr(const char *typename, char
*features,
}
static void x86_cpu_load_features(X86CPU *cpu, Error **errp);
+static int x86_cpu_filter_features(X86CPU *cpu);
/* Check for missing features that may prevent the CPU class from
* running using the current machine and accelerator.
@@ -2085,6 +2086,8 @@ static void x86_cpu_class_check_missing_features(X86CPUClass
*xcc,
next = &new->next;
}
+ x86_cpu_filter_features(xc);
+
for (w = 0; w < FEATURE_WORDS; w++) {
uint32_t filtered = xc->filtered_features[w];
int i;
@@ -2234,11 +2237,14 @@ static uint32_t x86_cpu_get_supported_feature_word(FeatureWord
w,
/*
* Filters CPU feature words based on host availability of each feature.
+ *
+ * Returns: 0 if all flags are supported by the host, non-zero otherwise.
*/
-static void x86_cpu_filter_features(X86CPU *cpu)
+static int x86_cpu_filter_features(X86CPU *cpu)
{
CPUX86State *env = &cpu->env;
FeatureWord w;
+ int rv = 0;
for (w = 0; w < FEATURE_WORDS; w++) {
uint32_t host_feat =
@@ -2246,22 +2252,21 @@ static void x86_cpu_filter_features(X86CPU *cpu)
uint32_t requested_features = env->features[w];
env->features[w] &= host_feat;
cpu->filtered_features[w] = requested_features & ~env->features[w];
+ if (cpu->filtered_features[w]) {
+ rv = 1;
+ }
}
+
+ return rv;
}
-/* Report list of filtered features to stderr.
- * Returns true if some features were found to be filtered, false otherwise
- */
-static bool x86_cpu_report_filtered_features(X86CPU *cpu)
+static void x86_cpu_report_filtered_features(X86CPU *cpu)
{
FeatureWord w;
- uint32_t filtered = 0;
for (w = 0; w < FEATURE_WORDS; w++) {
- filtered |= cpu->filtered_features[w];
report_unavailable_features(w, cpu->filtered_features[w]);
}
- return filtered;
}
static void x86_cpu_apply_props(X86CPU *cpu, PropValue *props)
@@ -3136,8 +3141,6 @@ static void x86_cpu_load_features(X86CPU *cpu, Error **errp)
env->cpuid_xlevel2 = env->cpuid_min_xlevel2;
}
- x86_cpu_filter_features(cpu);
-
out:
if (local_err != NULL) {
error_propagate(errp, local_err);
@@ -3176,8 +3179,12 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
goto out;
}
- if (cpu->check_cpuid || cpu->enforce_cpuid) {
- if (x86_cpu_report_filtered_features(cpu) && cpu->enforce_cpuid) {
+ x86_cpu_filter_features(cpu);
+
+ if (x86_cpu_filter_features(cpu) &&
+ (cpu->check_cpuid || cpu->enforce_cpuid)) {
+ x86_cpu_report_filtered_features(cpu);
+ if (cpu->enforce_cpuid) {
error_setg(&local_err,
kvm_enabled() ?
"Host doesn't support requested features" :
Changes v4 -> v5:
* New patch: "target-i386: Register aliases for feature names with underscores"
* On patch: "tests: Add test case for x86 feature parsing compatibility":
* Fix typo on commit message
Reported-by: Jonathan Neuschäfer <j.neuschaefer(a)gmx.net>
* Add comment noting that the "[+-]feature" compatibility mode
will be removed soon
* On patch: "target-i386: Make plus_features/minus_features QOM-based":
* Removed feat2prop() call on , as we now have property aliases
for the old names containing underscores
* On patch: "target-i386: Remove underscores from feat_names arrays":
* Remove the feat2prop() call from the alias registration
loop, too
* Commit message update to enumerate all code that uses
feat_names
* On patch: "target-i386: x86_cpu_load_features() function":
* Fix typo on x86_cpu_load_features() comment
Reported-by: Paolo Bonzini <pbonzini(a)redhat.com>
Diff v4 ->v5:
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 4dd3aee..620889f 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -2002,12 +2002,10 @@ static void x86_cpu_parse_featurestr(const char *typename, char
*features,
/* Compatibility syntax: */
if (featurestr[0] == '+') {
- feat2prop(featurestr + 1);
plus_features = g_list_append(plus_features,
g_strdup(featurestr + 1));
continue;
} else if (featurestr[0] == '-') {
- feat2prop(featurestr + 1);
minus_features = g_list_append(minus_features,
g_strdup(featurestr + 1));
continue;
@@ -3066,8 +3064,7 @@ static void x86_cpu_enable_xsave_components(X86CPU *cpu)
env->features[FEAT_XSAVE_COMP_HI] = mask >> 32;
}
-/* Load CPUID data based on configureured features
- */
+/* Load CPUID data based on configured features */
static void x86_cpu_load_features(X86CPU *cpu, Error **errp)
{
CPUX86State *env = &cpu->env;
@@ -3443,7 +3440,10 @@ static void x86_cpu_register_feature_bit_props(X86CPU *cpu,
return;
}
- /* Property names should use "-" instead of "_" */
+ /* Property names should use "-" instead of "_".
+ * Old names containing underscores are registered as aliases
+ * using object_property_add_alias()
+ */
assert(!strchr(name, '_'));
/* aliases don't use "|" delimiters anymore, they are registered
* manually using object_property_add_alias() */
@@ -3496,7 +3496,6 @@ static void x86_cpu_initfn(Object *obj)
}
}
- /* Alias for feature properties: */
object_property_add_alias(obj, "sse3", obj, "pni",
&error_abort);
object_property_add_alias(obj, "pclmuldq", obj, "pclmulqdq",
&error_abort);
object_property_add_alias(obj, "sse4-1", obj, "sse4.1",
&error_abort);
@@ -3505,6 +3504,28 @@ static void x86_cpu_initfn(Object *obj)
object_property_add_alias(obj, "ffxsr", obj, "fxsr-opt",
&error_abort);
object_property_add_alias(obj, "i64", obj, "lm",
&error_abort);
+ object_property_add_alias(obj, "ds_cpl", obj, "ds-cpl",
&error_abort);
+ object_property_add_alias(obj, "tsc_adjust", obj, "tsc-adjust",
&error_abort);
+ object_property_add_alias(obj, "fxsr_opt", obj, "fxsr-opt",
&error_abort);
+ object_property_add_alias(obj, "lahf_lm", obj, "lahf-lm",
&error_abort);
+ object_property_add_alias(obj, "cmp_legacy", obj, "cmp-legacy",
&error_abort);
+ object_property_add_alias(obj, "nodeid_msr", obj, "nodeid-msr",
&error_abort);
+ object_property_add_alias(obj, "perfctr_core", obj,
"perfctr-core", &error_abort);
+ object_property_add_alias(obj, "perfctr_nb", obj, "perfctr-nb",
&error_abort);
+ object_property_add_alias(obj, "kvm_nopiodelay", obj,
"kvm-nopiodelay", &error_abort);
+ object_property_add_alias(obj, "kvm_mmu", obj, "kvm-mmu",
&error_abort);
+ object_property_add_alias(obj, "kvm_asyncpf", obj,
"kvm-asyncpf", &error_abort);
+ object_property_add_alias(obj, "kvm_steal_time", obj,
"kvm-steal-time", &error_abort);
+ object_property_add_alias(obj, "kvm_pv_eoi", obj, "kvm-pv-eoi",
&error_abort);
+ object_property_add_alias(obj, "kvm_pv_unhalt", obj,
"kvm-pv-unhalt", &error_abort);
+ object_property_add_alias(obj, "svm_lock", obj, "svm-lock",
&error_abort);
+ object_property_add_alias(obj, "nrip_save", obj, "nrip-save",
&error_abort);
+ object_property_add_alias(obj, "tsc_scale", obj, "tsc-scale",
&error_abort);
+ object_property_add_alias(obj, "vmcb_clean", obj, "vmcb-clean",
&error_abort);
+ object_property_add_alias(obj, "pause_filter", obj,
"pause-filter", &error_abort);
+ object_property_add_alias(obj, "sse4_1", obj, "sse4.1",
&error_abort);
+ object_property_add_alias(obj, "sse4_2", obj, "sse4.2",
&error_abort);
+
x86_cpu_load_def(cpu, xcc->cpu_def, &error_abort);
}
diff --git a/tests/test-x86-cpuid-compat.c b/tests/test-x86-cpuid-compat.c
index 7cff2b5..260dd27 100644
--- a/tests/test-x86-cpuid-compat.c
+++ b/tests/test-x86-cpuid-compat.c
@@ -81,9 +81,14 @@ static void test_plus_minus(void)
char *path;
/* Rules:
- * "-foo" overrides "+foo"
- * "[+-]foo" overrides "foo=..."
- * "foo_bar" should be translated to "foo-bar"
+ * 1)"-foo" overrides "+foo"
+ * 2) "[+-]foo" overrides "foo=..."
+ * 3) Old feature names with underscores (e.g. "sse4_2")
+ * should keep working
+ *
+ * Note: rules 1 and 2 are planned to be removed soon, but we
+ * need to keep compatibility for a while until we start
+ * warning users about it.
*/
qtest_start("-cpu
pentium,-fpu,+fpu,-mce,mce=on,+cx8,cx8=off,+sse4_1,sse4_2=on");
path = get_cpu0_qom_path();
Changes v3 -> v4:
* Removed patch "Define CPUID filtering functions before x86_cpu_list"
* New patch: "tests: Add test case for x86 feature parsing compatibility"
* New patch: "target-i386: Disable VME by default with TCG"
* Disable VME by default on TCG to avoid returning bogus
results for all CPU models in TCG mode
* New patch: "target-i386: Make plus_features/minus_features QOM-based"
* New patch: "target-i386: Remove underscores from property names"
* New patch: "target-i386: Register properties for feature aliases manually"
* New patch: "target-i386: xsave: Add FP and SSE bits to x86_ext_save_areas"
* New patch: "target-i386: x86_cpu_load_features() function"
* On patch: "target-i386: Return runnability information on
query-cpu-definitions"
* Added code to handle unsupported XSAVE components cleanly
* Use x86_cpu_load_features() function
Changes v2 -> v3:
* Small documentation reword
* Suggested-by: Markus Armbruster <armbru(a)redhat.com>
* Create a x86_cpu_feature_name() function, to
isolate the code that returns the property name
Changes v1 -> v2:
* Fixed documentation to say "(since 2.7)"
* Removed @runnable field, improved documentation
Example command output:
{ "return": [
{
"unavailable-features": [],
"static": false,
"name": "host"
},
{
"unavailable-features": [],
"static": false,
"name": "qemu64"
},
{
"unavailable-features": [],
"static": false,
"name": "qemu32"
},
{
"unavailable-features": ["npt", "sse4a",
"3dnow", "3dnowext", "fxsr-opt", "mmxext"],
"static": false,
"name": "phenom"
},
{
"unavailable-features": [],
"static": false,
"name": "pentium3"
},
{
"unavailable-features": [],
"static": false,
"name": "pentium2"
},
{
"unavailable-features": [],
"static": false,
"name": "pentium"
},
{
"unavailable-features": [],
"static": false,
"name": "n270"
},
{
"unavailable-features": [],
"static": false,
"name": "kvm64"
},
{
"unavailable-features": [],
"static": false,
"name": "kvm32"
},
{
"unavailable-features": [],
"static": false,
"name": "coreduo"
},
{
"unavailable-features": [],
"static": false,
"name": "core2duo"
},
{
"unavailable-features": ["3dnow", "3dnowext",
"mmxext"],
"static": false,
"name": "athlon"
},
{
"unavailable-features": [],
"static": false,
"name": "Westmere"
},
{
"unavailable-features": ["xgetbv1", "xsavec",
"3dnowprefetch", "smap", "adx", "rdseed",
"mpx", "rtm", "hle"],
"static": false,
"name": "Skylake-Client"
},
{
"unavailable-features": [],
"static": false,
"name": "SandyBridge"
},
{
"unavailable-features": [],
"static": false,
"name": "Penryn"
},
{
"unavailable-features": ["tbm", "fma4",
"xop", "3dnowprefetch", "misalignsse", "sse4a"],
"static": false,
"name": "Opteron_G5"
},
{
"unavailable-features": ["fma4", "xop",
"3dnowprefetch", "misalignsse", "sse4a"],
"static": false,
"name": "Opteron_G4"
},
{
"unavailable-features": ["misalignsse",
"sse4a"],
"static": false,
"name": "Opteron_G3"
},
{
"unavailable-features": [],
"static": false,
"name": "Opteron_G2"
},
{
"unavailable-features": [],
"static": false,
"name": "Opteron_G1"
},
{
"unavailable-features": [],
"static": false,
"name": "Nehalem"
},
{
"unavailable-features": [],
"static": false,
"name": "IvyBridge"
},
{
"unavailable-features": ["rtm", "hle"],
"static": false,
"name": "Haswell"
},
{
"unavailable-features": [],
"static": false,
"name": "Haswell-noTSX"
},
{
"unavailable-features": [],
"static": false,
"name": "Conroe"
},
{
"unavailable-features": ["3dnowprefetch",
"smap", "adx", "rdseed", "rtm", "hle"],
"static": false,
"name": "Broadwell"
},
{
"unavailable-features": ["3dnowprefetch",
"smap", "adx", "rdseed"],
"static": false,
"name": "Broadwell-noTSX"
},
{
"unavailable-features": [],
"static": false,
"name": "486"
}
]}
Cc: David Hildenbrand <dahi(a)linux.vnet.ibm.com>
Cc: Michael Mueller <mimu(a)linux.vnet.ibm.com>
Cc: Christian Borntraeger <borntraeger(a)de.ibm.com>
Cc: Cornelia Huck <cornelia.huck(a)de.ibm.com>
Cc: Jiri Denemark <jdenemar(a)redhat.com>
Cc: libvir-list(a)redhat.com
Eduardo Habkost (3):
target-i386: Move warning code outside x86_cpu_filter_features()
target-i386: x86_cpu_load_features() function
target-i386: Return runnability information on query-cpu-definitions
target-i386/cpu.c | 169 +++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 137 insertions(+), 32 deletions(-)
--
2.7.4