[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 3/3] i386: Sanity check CPU model feature sets
From: |
Eduardo Habkost |
Subject: |
[PATCH 3/3] i386: Sanity check CPU model feature sets |
Date: |
Mon, 1 Feb 2021 17:54:04 -0500 |
All CPU models must refer only to features that have their names
defined in feature_word_info[].feat_names, otherwise error
reporting and query-cpu-model-expansion will break.
Validate CPU feature flags in x86_cpudef_validate(), we can catch
mistakes more easily.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
target/i386/cpu.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 6285fb00eb8..3c066738e82 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -5435,12 +5435,27 @@ static void x86_register_cpu_model_type(const char
*name, X86CPUModel *model)
static void x86_cpudef_validate(X86CPUDefinition *def)
{
#ifndef NDEBUG
+ FeatureWord w;
+ int bitnr;
+
/* AMD aliases are handled at runtime based on CPUID vendor, so
* they shouldn't be set on the CPU model table.
*/
assert(!(def->features[FEAT_8000_0001_EDX] & CPUID_EXT2_AMD_ALIASES));
/* catch mistakes instead of silently truncating model_id when too long */
assert(def->model_id && strlen(def->model_id) <= 48);
+
+ /*
+ * CPU models must enable only features with valid names, otherwise
+ * error reporting and query-cpu-model-expansion can't work correctly.
+ */
+ for (w = 0; w < FEATURE_WORDS; w++) {
+ for (bitnr = 0; bitnr < 64; bitnr++) {
+ uint64_t mask = (1ULL << bitnr);
+ assert(!(def->features[w] & mask) ||
+ feature_word_info[w].feat_names[bitnr]);
+ }
+ }
#endif
}
--
2.28.0
- [PATCH 0/3] i386: Ensure feature names are always defined, Eduardo Habkost, 2021/02/01
- [PATCH 1/3] i386: Add missing "vmx-ept-wb" feature name, Eduardo Habkost, 2021/02/01
- Re: [PATCH 1/3] i386: Add missing "vmx-ept-wb" feature name, Paolo Bonzini, 2021/02/01
- Re: [PATCH 1/3] i386: Add missing "vmx-ept-wb" feature name, Eduardo Habkost, 2021/02/01
- Re: [PATCH 1/3] i386: Add missing "vmx-ept-wb" feature name, Paolo Bonzini, 2021/02/01
- Re: [PATCH 1/3] i386: Add missing "vmx-ept-wb" feature name, Eduardo Habkost, 2021/02/01
- Re: [PATCH 1/3] i386: Add missing "vmx-ept-wb" feature name, Paolo Bonzini, 2021/02/02
- Re: [PATCH 1/3] i386: Add missing "vmx-ept-wb" feature name, Eduardo Habkost, 2021/02/02
[PATCH 2/3] i386: Move asserts to separate x86_cpudef_validate() function, Eduardo Habkost, 2021/02/01
[PATCH 3/3] i386: Sanity check CPU model feature sets,
Eduardo Habkost <=