target-i386: Support check/enforce flags in TCG mode, too
v2 cover target-i386: Support check/enforce flags in TCG mode, too
This removes some duplication in the CPU feature checking and filtering code in cpu.c, and as a nice side-effect, will make the "check" and "enforce" flags work in TCG mode too.
Changes v1 -> v2:
* Rebase to latest qom-cpu (commit 90c5d39c)
Eduardo Habkost (10):
target-i386: Simplify reporting of unavailable features
target-i386: Merge feature filtering/checking functions
target-i386: Pass FeatureWord argument to
report_unavailable_features()
target-i386: Isolate KVM-specific code on CPU feature filtering logic
target-i386: Make TCG feature filtering more readable
target-i386: Filter FEAT_7_0_EBX TCG features too
target-i386: Filter KVM and 0xC0000001 features on TCG
target-i386: Define TCG_*_FEATURES earlier on cpu.c
target-i386: Loop-based feature word filtering in TCG mode
target-i386: Support check/enforce flags in TCG mode, too
target-i386/cpu.c | 216 +++++++++++++++++++++++++++--------------------------- 1 file changed, 108 insertions(+), 108 deletions(-)
Signature · 1 line
1.8.5.3
PATCH v2 1/10 target-i386: Simplify reporting of unavailable features
Instead of checking and calling unavailable_host_feature() once for each bit, simply call the function (now renamed to report_unavailable_features()) once for each feature word.
---
Changes v1 -> v2:
* Rebase to latest qom-cpu (commit 90c5d39c)
--- target-i386/cpu.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
target-i386/cpu.c +7 -9
@@ -1230,11 +1230,11 @@ static const TypeInfo host_x86_cpu_type_info = {#endif -static int unavailable_host_feature (FeatureWordInfo *f,uint32_t mask) +static int report_unavailable_features (FeatureWordInfo *f,uint32_t mask) {int i; -for (i =0 ; i <32 ; ++i) +for (i =0 ; i <32 ; ++i) {if (1 << i & mask) {const char *reg =get_register_name_32 (f->cpuid_reg);assert (reg);
@@ -1243,8 +1243,8 @@ static int unavailable_host_feature(FeatureWordInfo *f, uint32_t mask) f->cpuid_eax, reg, f->feat_names[i] ?"." :"" , f->feat_names[i] ? f->feat_names[i] : "", i); -break ; } + }return 0 ; }
@@ -1268,12 +1268,10 @@ static int kvm_check_features_against_host(KVMState *s, X86CPU *cpu)uint32_t host_feat =kvm_arch_get_supported_cpuid (s, wi->cpuid_eax, wi->cpuid_ecx, wi->cpuid_reg); -uint32_t mask; -for (mask =1 ; mask; mask <<=1 ) { -if (guest_feat & mask && !(host_feat & mask)) { -unavailable_host_feature (wi, mask); - rv =1 ; - } +uint32_t unavailable_features = guest_feat & ~host_feat; +if (unavailable_features) { +report_unavailable_features (wi, unavailable_features); + rv =1 ; } }return rv;
Signature · 1 line
1.8.5.3
PATCH v2 2/10 target-i386: Merge feature filtering/checking functions
In reply to Eduardo HabkostMerge filter_features_for_kvm() and kvm_check_features_against_host().
Both functions made exactly the same calculations, the only difference was that filter_features_for_kvm() changed the bits on cpu->features[], and kvm_check_features_against_host() did error reporting.
--- target-i386/cpu.c | 53 +++++++++++++++++++---------------------------------- 1 file changed, 19 insertions(+), 34 deletions(-)
target-i386/cpu.c +19 -34
@@ -1248,35 +1248,6 @@ static int report_unavailable_features(FeatureWordInfo *f, uint32_t mask)return 0 ; } -/* Check if all requested cpu flags are making their way to the guest -* -* Returns 0 if all flags are supported by the host, non-zero otherwise. -* -* This function may be called only if KVM is enabled. -*/ -static int kvm_check_features_against_host (KVMState *s,X86CPU *cpu) -{ -CPUX86State *env = &cpu->env; -int rv =0 ; -FeatureWord w; - -assert (kvm_enabled ()); - -for (w =0 ; w <FEATURE_WORDS ; w++) { -FeatureWordInfo *wi = &feature_word_info[w]; -uint32_t guest_feat = env->features[w]; -uint32_t host_feat =kvm_arch_get_supported_cpuid (s, wi->cpuid_eax, - wi->cpuid_ecx, - wi->cpuid_reg); -uint32_t unavailable_features = guest_feat & ~host_feat; -if (unavailable_features) { -report_unavailable_features (wi, unavailable_features); - rv =1 ; - } - } -return rv; -} -static void x86_cpuid_version_get_family (Object *obj,Visitor *v,void *opaque,const char *name,Error **errp) {
@@ -1835,11 +1806,20 @@ CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)return cpu_list; } -static void filter_features_for_kvm (X86CPU *cpu) +/* Filters CPU feature words based on host availability of each feature +* +* Returns 0 if all flags are supported by the host, non-zero otherwise. +* +* This function may be called only if KVM is enabled. +*/ +static int filter_features_for_kvm (X86CPU *cpu) {CPUX86State *env = &cpu->env;KVMState *s = kvm_state;FeatureWord w; +int rv =0 ; + +assert (kvm_enabled ());for (w =0 ; w <FEATURE_WORDS ; w++) {FeatureWordInfo *wi = &feature_word_info[w];
@@ -1849,7 +1829,15 @@ static void filter_features_for_kvm(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]) { +if (cpu->check_cpuid || cpu->enforce_cpuid) { +report_unavailable_features (wi, cpu->filtered_features[w]); + } + rv =1 ; + } } + +return rv; }/* Load data from X86CPUDefinition
@@ -2597,14 +2585,11 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) env->features[FEAT_8000_0001_ECX ] &=TCG_EXT3_FEATURES ; env->features[FEAT_SVM ] &=TCG_SVM_FEATURES ; }else { -KVMState *s = kvm_state; -if ((cpu->check_cpuid || cpu->enforce_cpuid) - &&kvm_check_features_against_host (s, cpu) && cpu->enforce_cpuid) { +if (filter_features_for_kvm (cpu) && cpu->enforce_cpuid) {error_setg (&local_err,"Host's CPU doesn't support requested features" ); goto out; } -filter_features_for_kvm (cpu); }#ifndef CONFIG_USER_ONLY
Signature · 1 line
1.8.5.3
PATCH v2 3/10 target-i386: Pass FeatureWord argument to report_unavailable_features()
In reply to Eduardo HabkostThis will help us simplify the code that callsreport_unavailable_features() later.
---
Changes v1 -> v2:
* Rebase to latest qom-cpu (commit 90c5d39c)
--- target-i386/cpu.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
target-i386/cpu.c +3 -2
@@ -1230,8 +1230,9 @@ static const TypeInfo host_x86_cpu_type_info = {#endif -static int report_unavailable_features (FeatureWordInfo *f,uint32_t mask) +static int report_unavailable_features (FeatureWord w,uint32_t mask) { +FeatureWordInfo *f = &feature_word_info[w];int i;for (i =0 ; i <32 ; ++i) {
@@ -1831,7 +1832,7 @@ static int filter_features_for_kvm(X86CPU *cpu) cpu->filtered_features[w] = requested_features & ~env->features[w];if (cpu->filtered_features[w]) {if (cpu->check_cpuid || cpu->enforce_cpuid) { -report_unavailable_features (wi, cpu->filtered_features[w]); +report_unavailable_features (w, cpu->filtered_features[w]); } rv =1 ; }
Signature · 1 line
1.8.5.3
PATCH v2 4/10 target-i386: Isolate KVM-specific code on CPU feature filtering logic
In reply to Eduardo HabkostThis will allow us to re-use the feature filtering logic (and the check/enforce flag logic) for TCG.
--- target-i386/cpu.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)
target-i386/cpu.c +12 -9
@@ -1807,26 +1807,29 @@ CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)return cpu_list; } +static uint32_t x86_cpu_get_supported_feature_word (FeatureWord w) +{ +FeatureWordInfo *wi = &feature_word_info[w]; +assert (kvm_enabled ()); +return kvm_arch_get_supported_cpuid (kvm_state, wi->cpuid_eax, + wi->cpuid_ecx, + wi->cpuid_reg); +} +/* Filters CPU feature words based on host availability of each feature * * Returns 0 if all flags are supported by the host, non-zero otherwise. * * This function may be called only if KVM is enabled. */ -static int filter_features_for_kvm (X86CPU *cpu) +static int x86_cpu_filter_features (X86CPU *cpu) {CPUX86State *env = &cpu->env; -KVMState *s = kvm_state;FeatureWord w;int rv =0 ; -assert (kvm_enabled ()); -for (w =0 ; w <FEATURE_WORDS ; w++) { -FeatureWordInfo *wi = &feature_word_info[w]; -uint32_t host_feat =kvm_arch_get_supported_cpuid (s, wi->cpuid_eax, - wi->cpuid_ecx, - wi->cpuid_reg); +uint32_t host_feat =x86_cpu_get_supported_feature_word (w);uint32_t requested_features = env->features[w]; env->features[w] &= host_feat; cpu->filtered_features[w] = requested_features & ~env->features[w];
@@ -2586,7 +2589,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) env->features[FEAT_8000_0001_ECX ] &=TCG_EXT3_FEATURES ; env->features[FEAT_SVM ] &=TCG_SVM_FEATURES ; }else { -if (filter_features_for_kvm (cpu) && cpu->enforce_cpuid) { +if (x86_cpu_filter_features (cpu) && cpu->enforce_cpuid) {error_setg (&local_err,"Host's CPU doesn't support requested features" ); goto out;
Signature · 1 line
1.8.5.3
PATCH v2 5/10 target-i386: Make TCG feature filtering more readable
In reply to Eduardo HabkostInstead of an #ifdef in the middle of the code, just set TCG_EXT2_FEATURES to a different value depending on TARGET_X86_64.
--- target-i386/cpu.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
target-i386/cpu.c +10 -6
@@ -566,9 +566,17 @@ struct X86CPUDefinition {CPUID_EXT_X2APIC, CPUID_EXT_TSC_DEADLINE_TIMER, CPUID_EXT_XSAVE, CPUID_EXT_OSXSAVE, CPUID_EXT_AVX, CPUID_EXT_F16C, CPUID_EXT_RDRAND */ + +#ifdef TARGET_X86_64 +#define TCG_EXT2_X86_64_FEATURES (CPUID_EXT2_SYSCALL | CPUID_EXT2_LM) +#else +#define TCG_EXT2_X86_64_FEATURES 0 +#endif +#define TCG_EXT2_FEATURES ((TCG_FEATURES & CPUID_EXT2_AMD_ALIASES) | \ CPUID_EXT2_NX | CPUID_EXT2_MMXEXT | CPUID_EXT2_RDTSCP | \ - CPUID_EXT2_3DNOW | CPUID_EXT2_3DNOWEXT) + CPUID_EXT2_3DNOW | CPUID_EXT2_3DNOWEXT | \ + TCG_EXT2_X86_64_FEATURES)/* missing: CPUID_EXT2_PDPE1GB */ #define TCG_EXT3_FEATURES (CPUID_EXT3_LAHF_LM | CPUID_EXT3_SVM | \
@@ -2581,11 +2589,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)if (!kvm_enabled ()) { env->features[FEAT_1_EDX ] &=TCG_FEATURES ; env->features[FEAT_1_ECX ] &=TCG_EXT_FEATURES ; - env->features[FEAT_8000_0001_EDX ] &= (TCG_EXT2_FEATURES -#ifdef TARGET_X86_64 - |CPUID_EXT2_SYSCALL |CPUID_EXT2_LM -#endif - ); + env->features[FEAT_8000_0001_EDX ] &=TCG_EXT2_FEATURES ; env->features[FEAT_8000_0001_ECX ] &=TCG_EXT3_FEATURES ; env->features[FEAT_SVM ] &=TCG_SVM_FEATURES ; }else {
Signature · 1 line
1.8.5.3
PATCH v2 6/10 target-i386: Filter FEAT_7_0_EBX TCG features too
The TCG_7_0_EBX_FEATURES macro was defined but never used (it even had a typo that was never noticed). Make the existing TCG feature filtering code use it.
Change the TCG feature flag filtering code to use it.
--- target-i386/cpu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
target-i386/cpu.c +2 -1
@@ -582,7 +582,7 @@ struct X86CPUDefinition {#define TCG_EXT3_FEATURES (CPUID_EXT3_LAHF_LM | CPUID_EXT3_SVM | \ CPUID_EXT3_CR8LEG | CPUID_EXT3_ABM | CPUID_EXT3_SSE4A)#define TCG_SVM_FEATURES 0 -#define TCG_7_0_EBX_FEATURES (CPUID_7_0_EBX_SMEP | CPUID_7_0_EBX_SMAP \ +#define TCG_7_0_EBX_FEATURES (CPUID_7_0_EBX_SMEP | CPUID_7_0_EBX_SMAP | \ CPUID_7_0_EBX_BMI1 | CPUID_7_0_EBX_BMI2 | CPUID_7_0_EBX_ADX)/* missing: CPUID_7_0_EBX_FSGSBASE, CPUID_7_0_EBX_HLE, CPUID_7_0_EBX_AVX2,
@@ -2589,6 +2589,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)if (!kvm_enabled ()) { env->features[FEAT_1_EDX ] &=TCG_FEATURES ; env->features[FEAT_1_ECX ] &=TCG_EXT_FEATURES ; + env->features[FEAT_7_0_EBX ] &=TCG_7_0_EBX_FEATURES ; env->features[FEAT_8000_0001_EDX ] &=TCG_EXT2_FEATURES ; env->features[FEAT_8000_0001_ECX ] &=TCG_EXT3_FEATURES ; env->features[FEAT_SVM ] &=TCG_SVM_FEATURES ;
Signature · 1 line
1.8.5.3
PATCH v2 7/10 target-i386: Filter KVM and 0xC0000001 features on TCG
In reply to Eduardo HabkostTCG doesn't support any of the feature flags on FEAT_KVM and FEAT_C000_0001_EDX feature words, so clear all bits on those feature words.
--- target-i386/cpu.c | 4 ++++ 1 file changed, 4 insertions(+)
target-i386/cpu.c +4 -0
@@ -581,7 +581,9 @@ struct X86CPUDefinition {CPUID_EXT2_PDPE1GB */ #define TCG_EXT3_FEATURES (CPUID_EXT3_LAHF_LM | CPUID_EXT3_SVM | \ CPUID_EXT3_CR8LEG | CPUID_EXT3_ABM | CPUID_EXT3_SSE4A) +#define TCG_EXT4_FEATURES 0#define TCG_SVM_FEATURES 0 +#define TCG_KVM_FEATURES 0#define TCG_7_0_EBX_FEATURES (CPUID_7_0_EBX_SMEP | CPUID_7_0_EBX_SMAP | \ CPUID_7_0_EBX_BMI1 | CPUID_7_0_EBX_BMI2 | CPUID_7_0_EBX_ADX)/* missing:
@@ -2593,6 +2595,8 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) env->features[FEAT_8000_0001_EDX ] &=TCG_EXT2_FEATURES ; env->features[FEAT_8000_0001_ECX ] &=TCG_EXT3_FEATURES ; env->features[FEAT_SVM ] &=TCG_SVM_FEATURES ; + env->features[FEAT_KVM ] &=TCG_KVM_FEATURES ; + env->features[FEAT_C000_0001_EDX ] &=TCG_EXT4_FEATURES ; }else {if (x86_cpu_filter_features (cpu) && cpu->enforce_cpuid) { error_setg(&local_err,
Signature · 1 line
1.8.5.3
PATCH v2 8/10 target-i386: Define TCG_*_FEATURES earlier on cpu.c
In reply to Eduardo HabkostThose macros will be used in the feature_word_info array data, so need to be defined earlier.
---
Changes v1 -> v2:
* Rebase to latest qom-cpu (commit 90c5d39c)
--- target-i386/cpu.c | 117 +++++++++++++++++++++++++++--------------------------- 1 file changed, 59 insertions(+), 58 deletions(-)
target-i386/cpu.c +59 -58
@@ -262,6 +262,65 @@ static const char *cpuid_7_0_ebx_feature_name[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, }; +#define I486_FEATURES (CPUID_FP87 | CPUID_VME | CPUID_PSE) +#define PENTIUM_FEATURES (I486_FEATURES | CPUID_DE | CPUID_TSC | \ + CPUID_MSR | CPUID_MCE | CPUID_CX8 | CPUID_MMX | CPUID_APIC) +#define PENTIUM2_FEATURES (PENTIUM_FEATURES | CPUID_PAE | CPUID_SEP | \ + CPUID_MTRR | CPUID_PGE | CPUID_MCA | CPUID_CMOV | CPUID_PAT | \ + CPUID_PSE36 | CPUID_FXSR) +#define PENTIUM3_FEATURES (PENTIUM2_FEATURES | CPUID_SSE) +#define PPRO_FEATURES (CPUID_FP87 | CPUID_DE | CPUID_PSE | CPUID_TSC | \ + CPUID_MSR | CPUID_MCE | CPUID_CX8 | CPUID_PGE | CPUID_CMOV | \ + CPUID_PAT | CPUID_FXSR | CPUID_MMX | CPUID_SSE | CPUID_SSE2 | \ + CPUID_PAE | CPUID_SEP | CPUID_APIC) + +#define TCG_FEATURES (CPUID_FP87 | CPUID_PSE | CPUID_TSC | CPUID_MSR | \ + CPUID_PAE | CPUID_MCE | CPUID_CX8 | CPUID_APIC | CPUID_SEP | \ + CPUID_MTRR | CPUID_PGE | CPUID_MCA | CPUID_CMOV | CPUID_PAT | \ + CPUID_PSE36 | CPUID_CLFLUSH | CPUID_ACPI | CPUID_MMX | \ + CPUID_FXSR | CPUID_SSE | CPUID_SSE2 | CPUID_SS) +/* partly implemented: +CPUID_MTRR, CPUID_MCA, CPUID_CLFLUSH (needed for Win64) +CPUID_PSE36 (needed for Solaris) */ +/* missing: +CPUID_VME, CPUID_DTS, CPUID_SS, CPUID_HT, CPUID_TM, CPUID_PBE */ +#define TCG_EXT_FEATURES (CPUID_EXT_SSE3 | CPUID_EXT_PCLMULQDQ | \ + CPUID_EXT_MONITOR | CPUID_EXT_SSSE3 | CPUID_EXT_CX16 | \ + CPUID_EXT_SSE41 | CPUID_EXT_SSE42 | CPUID_EXT_POPCNT | \ + CPUID_EXT_MOVBE | CPUID_EXT_AES | CPUID_EXT_HYPERVISOR) +/* missing: +CPUID_EXT_DTES64, CPUID_EXT_DSCPL, CPUID_EXT_VMX, CPUID_EXT_SMX, +CPUID_EXT_EST, CPUID_EXT_TM2, CPUID_EXT_CID, CPUID_EXT_FMA, +CPUID_EXT_XTPR, CPUID_EXT_PDCM, CPUID_EXT_PCID, CPUID_EXT_DCA, +CPUID_EXT_X2APIC, CPUID_EXT_TSC_DEADLINE_TIMER, CPUID_EXT_XSAVE, +CPUID_EXT_OSXSAVE, CPUID_EXT_AVX, CPUID_EXT_F16C, +CPUID_EXT_RDRAND */ + +#ifdef TARGET_X86_64 +#define TCG_EXT2_X86_64_FEATURES (CPUID_EXT2_SYSCALL | CPUID_EXT2_LM) +#else +#define TCG_EXT2_X86_64_FEATURES 0 +#endif + +#define TCG_EXT2_FEATURES ((TCG_FEATURES & CPUID_EXT2_AMD_ALIASES) | \ + CPUID_EXT2_NX | CPUID_EXT2_MMXEXT | CPUID_EXT2_RDTSCP | \ + CPUID_EXT2_3DNOW | CPUID_EXT2_3DNOWEXT | \ + TCG_EXT2_X86_64_FEATURES) +/* missing: +CPUID_EXT2_PDPE1GB */ +#define TCG_EXT3_FEATURES (CPUID_EXT3_LAHF_LM | CPUID_EXT3_SVM | \ + CPUID_EXT3_CR8LEG | CPUID_EXT3_ABM | CPUID_EXT3_SSE4A) +#define TCG_EXT4_FEATURES 0 +#define TCG_SVM_FEATURES 0 +#define TCG_KVM_FEATURES 0 +#define TCG_7_0_EBX_FEATURES (CPUID_7_0_EBX_SMEP | CPUID_7_0_EBX_SMAP | \ + CPUID_7_0_EBX_BMI1 | CPUID_7_0_EBX_BMI2 | CPUID_7_0_EBX_ADX) +/* missing: +CPUID_7_0_EBX_FSGSBASE, CPUID_7_0_EBX_HLE, CPUID_7_0_EBX_AVX2, +CPUID_7_0_EBX_ERMS, CPUID_7_0_EBX_INVPCID, CPUID_7_0_EBX_RTM, +CPUID_7_0_EBX_RDSEED */ + + typedef struct FeatureWordInfo { const char **feat_names; uint32_t cpuid_eax; /* Input EAX for CPUID */
@@ -533,64 +592,6 @@ struct X86CPUDefinition {bool cache_info_passthrough; }; -#define I486_FEATURES (CPUID_FP87 | CPUID_VME | CPUID_PSE) -#define PENTIUM_FEATURES (I486_FEATURES | CPUID_DE | CPUID_TSC | \ - CPUID_MSR | CPUID_MCE | CPUID_CX8 | CPUID_MMX | CPUID_APIC) -#define PENTIUM2_FEATURES (PENTIUM_FEATURES | CPUID_PAE | CPUID_SEP | \ - CPUID_MTRR | CPUID_PGE | CPUID_MCA | CPUID_CMOV | CPUID_PAT | \ - CPUID_PSE36 | CPUID_FXSR) -#define PENTIUM3_FEATURES (PENTIUM2_FEATURES | CPUID_SSE) -#define PPRO_FEATURES (CPUID_FP87 | CPUID_DE | CPUID_PSE | CPUID_TSC | \ - CPUID_MSR | CPUID_MCE | CPUID_CX8 | CPUID_PGE | CPUID_CMOV | \ - CPUID_PAT | CPUID_FXSR | CPUID_MMX | CPUID_SSE | CPUID_SSE2 | \ - CPUID_PAE | CPUID_SEP | CPUID_APIC) - -#define TCG_FEATURES (CPUID_FP87 | CPUID_PSE | CPUID_TSC | CPUID_MSR | \ - CPUID_PAE | CPUID_MCE | CPUID_CX8 | CPUID_APIC | CPUID_SEP | \ - CPUID_MTRR | CPUID_PGE | CPUID_MCA | CPUID_CMOV | CPUID_PAT | \ - CPUID_PSE36 | CPUID_CLFLUSH | CPUID_ACPI | CPUID_MMX | \ - CPUID_FXSR | CPUID_SSE | CPUID_SSE2 | CPUID_SS) -/* partly implemented: -CPUID_MTRR, CPUID_MCA, CPUID_CLFLUSH (needed for Win64) -CPUID_PSE36 (needed for Solaris) */ -/* missing: -CPUID_VME, CPUID_DTS, CPUID_SS, CPUID_HT, CPUID_TM, CPUID_PBE */ -#define TCG_EXT_FEATURES (CPUID_EXT_SSE3 | CPUID_EXT_PCLMULQDQ | \ - CPUID_EXT_MONITOR | CPUID_EXT_SSSE3 | CPUID_EXT_CX16 | \ - CPUID_EXT_SSE41 | CPUID_EXT_SSE42 | CPUID_EXT_POPCNT | \ - CPUID_EXT_MOVBE | CPUID_EXT_AES | CPUID_EXT_HYPERVISOR) -/* missing: -CPUID_EXT_DTES64, CPUID_EXT_DSCPL, CPUID_EXT_VMX, CPUID_EXT_SMX, -CPUID_EXT_EST, CPUID_EXT_TM2, CPUID_EXT_CID, CPUID_EXT_FMA, -CPUID_EXT_XTPR, CPUID_EXT_PDCM, CPUID_EXT_PCID, CPUID_EXT_DCA, -CPUID_EXT_X2APIC, CPUID_EXT_TSC_DEADLINE_TIMER, CPUID_EXT_XSAVE, -CPUID_EXT_OSXSAVE, CPUID_EXT_AVX, CPUID_EXT_F16C, -CPUID_EXT_RDRAND */ - -#ifdef TARGET_X86_64 -#define TCG_EXT2_X86_64_FEATURES (CPUID_EXT2_SYSCALL | CPUID_EXT2_LM) -#else -#define TCG_EXT2_X86_64_FEATURES 0 -#endif - -#define TCG_EXT2_FEATURES ((TCG_FEATURES & CPUID_EXT2_AMD_ALIASES) | \ - CPUID_EXT2_NX | CPUID_EXT2_MMXEXT | CPUID_EXT2_RDTSCP | \ - CPUID_EXT2_3DNOW | CPUID_EXT2_3DNOWEXT | \ - TCG_EXT2_X86_64_FEATURES) -/* missing: -CPUID_EXT2_PDPE1GB */ -#define TCG_EXT3_FEATURES (CPUID_EXT3_LAHF_LM | CPUID_EXT3_SVM | \ - CPUID_EXT3_CR8LEG | CPUID_EXT3_ABM | CPUID_EXT3_SSE4A) -#define TCG_EXT4_FEATURES 0 -#define TCG_SVM_FEATURES 0 -#define TCG_KVM_FEATURES 0 -#define TCG_7_0_EBX_FEATURES (CPUID_7_0_EBX_SMEP | CPUID_7_0_EBX_SMAP | \ - CPUID_7_0_EBX_BMI1 | CPUID_7_0_EBX_BMI2 | CPUID_7_0_EBX_ADX) -/* missing: -CPUID_7_0_EBX_FSGSBASE, CPUID_7_0_EBX_HLE, CPUID_7_0_EBX_AVX2, -CPUID_7_0_EBX_ERMS, CPUID_7_0_EBX_INVPCID, CPUID_7_0_EBX_RTM, -CPUID_7_0_EBX_RDSEED */ -static X86CPUDefinition builtin_x86_defs[] = { { .name ="qemu64" ,
Signature · 1 line
1.8.5.3
PATCH v2 9/10 target-i386: Loop-based feature word filtering in TCG mode
In reply to Eduardo HabkostInstead of manually filtering each feature word, add a tcg_features field to FeatureWordInfo, and use that field to filter all feature words in TCG mode.
--- target-i386/cpu.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
target-i386/cpu.c +13 -8
@@ -327,42 +327,51 @@ typedef struct FeatureWordInfo {bool cpuid_needs_ecx;/* CPUID instruction uses ECX as input */ uint32_t cpuid_ecx;/* Input ECX value for CPUID */ int cpuid_reg;/* output register (R_* constant) */ +uint32_t tcg_features;/* Feature flags supported by TCG */ } FeatureWordInfo;static FeatureWordInfo feature_word_info[FEATURE_WORDS ] = { [FEAT_1_EDX ] = { .feat_names = feature_name, .cpuid_eax =1 , .cpuid_reg =R_EDX , + .tcg_features =TCG_FEATURES , }, [FEAT_1_ECX ] = { .feat_names = ext_feature_name, .cpuid_eax =1 , .cpuid_reg =R_ECX , + .tcg_features =TCG_EXT_FEATURES , }, [FEAT_8000_0001_EDX ] = { .feat_names = ext2_feature_name, .cpuid_eax =0x80000001 , .cpuid_reg =R_EDX , + .tcg_features =TCG_EXT2_FEATURES , }, [FEAT_8000_0001_ECX ] = { .feat_names = ext3_feature_name, .cpuid_eax =0x80000001 , .cpuid_reg =R_ECX , + .tcg_features =TCG_EXT3_FEATURES , }, [FEAT_C000_0001_EDX ] = { .feat_names = ext4_feature_name, .cpuid_eax =0xC0000001 , .cpuid_reg =R_EDX , + .tcg_features =TCG_EXT4_FEATURES , }, [FEAT_KVM ] = { .feat_names = kvm_feature_name, .cpuid_eax =KVM_CPUID_FEATURES , .cpuid_reg =R_EAX , + .tcg_features =TCG_KVM_FEATURES , }, [FEAT_SVM ] = { .feat_names = svm_feature_name, .cpuid_eax =0x8000000A , .cpuid_reg =R_EDX , + .tcg_features =TCG_SVM_FEATURES , }, [FEAT_7_0_EBX ] = { .feat_names = cpuid_7_0_ebx_feature_name, .cpuid_eax =7 , .cpuid_needs_ecx = true, .cpuid_ecx =0 , .cpuid_reg =R_EBX , + .tcg_features =TCG_7_0_EBX_FEATURES , }, };
@@ -2590,14 +2599,10 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) }if (!kvm_enabled ()) { - env->features[FEAT_1_EDX ] &=TCG_FEATURES ; - env->features[FEAT_1_ECX ] &=TCG_EXT_FEATURES ; - env->features[FEAT_7_0_EBX ] &=TCG_7_0_EBX_FEATURES ; - env->features[FEAT_8000_0001_EDX ] &=TCG_EXT2_FEATURES ; - env->features[FEAT_8000_0001_ECX ] &=TCG_EXT3_FEATURES ; - env->features[FEAT_SVM ] &=TCG_SVM_FEATURES ; - env->features[FEAT_KVM ] &=TCG_KVM_FEATURES ; - env->features[FEAT_C000_0001_EDX ] &=TCG_EXT4_FEATURES ; +FeatureWord w; +for (w =0 ; w <FEATURE_WORDS ; w++) { + env->features[w] &= feature_word_info[w].tcg_features; + } }else {if (x86_cpu_filter_features (cpu) && cpu->enforce_cpuid) { error_setg(&local_err,
Signature · 1 line
1.8.5.3
PATCH v2 10/10 target-i386: Support check/enforce flags in TCG mode, too
In reply to Eduardo HabkostIf enforce/check is specified in TCG mode, QEMU will ensure all CPU features are supported by TCG, so no CPU feature is silently disabled.
--- target-i386/cpu.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-)
target-i386/cpu.c +16 -18
@@ -1259,8 +1259,9 @@ static int report_unavailable_features(FeatureWord w, uint32_t mask)if (1 << i & mask) {const char *reg =get_register_name_32 (f->cpuid_reg);assert (reg); -fprintf (stderr,"warning: host doesn't support requested feature: " +fprintf (stderr,"warning: %s doesn't support requested feature: " "CPUID.%02XH:%s%s%s [bit %d]\n" , +kvm_enabled () ?"host" :"TCG" , f->cpuid_eax, reg, f->feat_names[i] ?"." :"" , f->feat_names[i] ? f->feat_names[i] :"" , i);
@@ -1830,17 +1831,18 @@ CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)static uint32_t x86_cpu_get_supported_feature_word (FeatureWord w) {FeatureWordInfo *wi = &feature_word_info[w]; -assert (kvm_enabled ()); -return kvm_arch_get_supported_cpuid (kvm_state, wi->cpuid_eax, - wi->cpuid_ecx, - wi->cpuid_reg); +if (kvm_enabled ()) { +return kvm_arch_get_supported_cpuid (kvm_state, wi->cpuid_eax, + wi->cpuid_ecx, + wi->cpuid_reg); + }else { +return wi->tcg_features; + } }/* Filters CPU feature words based on host availability of each feature * * Returns 0 if all flags are supported by the host, non-zero otherwise. -* -* This function may be called only if KVM is enabled. */ static int x86_cpu_filter_features (X86CPU *cpu) {
@@ -2598,17 +2600,13 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) & CPUID_EXT2_AMD_ALIASES); } -if (!kvm_enabled ()) { -FeatureWord w; -for (w =0 ; w <FEATURE_WORDS ; w++) { - env->features[w] &= feature_word_info[w].tcg_features; - } - }else { -if (x86_cpu_filter_features (cpu) && cpu->enforce_cpuid) { -error_setg (&local_err, -"Host's CPU doesn't support requested features" ); - goto out; - } + +if (x86_cpu_filter_features (cpu) && cpu->enforce_cpuid) { +error_setg (&local_err, +kvm_enabled () ? +"Host doesn't support requested features" : +"TCG doesn't support requested features" ); + goto out; }#ifndef CONFIG_USER_ONLY
Signature · 1 line
1.8.5.3