replace cpuid_*features fields with a featue word array (v6)
cover replace cpuid_*features fields with a featue word array (v6)
Changes v6:
- Rebase on top of Andreas' qom-cpu tree (commit 9260944307077b93a66bf861a467107af986fe47)
- Break lines on kvm_check_features_against_host()
- Break the lines on builtin_x86_defs just after the "=". This way the feature lists stay on separate lines, this patch gets easier to review, and future patches that touches the code around builtin_x86_defs will be even easier to review (as they won't need to touch the lines containing the fature lists again)
Eduardo Habkost (2):
target-i386/cpu.c: Coding style fixes
target-i386: Replace cpuid_*features fields with a feature word array
bsd-user/elfload.c | 2 +- bsd-user/main.c | 4 +- hw/kvm/clock.c | 2 +- linux-user/elfload.c | 2 +- linux-user/main.c | 4 +- target-i386/cpu.c | 412 ++++++++++++++++++++++++++++------------------ target-i386/cpu.h | 15 +- target-i386/helper.c | 4 +- target-i386/kvm.c | 5 +- target-i386/misc_helper.c | 14 +- target-i386/translate.c | 10 +- 11 files changed, 274 insertions(+), 200 deletions(-)
Signature · 1 line
1.8.1.4
PATCH 1/2 target-i386/cpu.c: Coding style fixes
* Add braces to 'if' statements;
* Remove last TAB character from the source.
--- target-i386/cpu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
target-i386/cpu.c +4 -3
@@ -1870,12 +1870,13 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,if (env->cpuid_ext2_features &CPUID_EXT2_LM ) {/* 64 bit processor */ /* XXX: The physical address space is limited to 42 bits in exec.c. */ - *eax =0x00003028 ;/* 48 bits virtual, 40 bits physical */ + *eax =0x00003028 ;/* 48 bits virtual, 40 bits physical */ }else { -if (env->cpuid_features &CPUID_PSE36 ) +if (env->cpuid_features &CPUID_PSE36 ) { *eax =0x00000024 ;/* 36 bits physical */ -else + }else { *eax =0x00000020 ;/* 32 bits physical */ + } } *ebx =0 ; *ecx =0 ;
Signature · 1 line
1.8.1.4
PATCH 2/2 target-i386: Replace cpuid_*features fields with a feature word array
In reply to Eduardo HabkostThis replaces the feature-bit fields on both X86CPU and x86_def_t structs with an array.
With this, we will be able to simplify code that simply does the same operation on all feature words (e.g. kvm_check_features_against_host(), filter_features_for_kvm(), add_flagname_to_bitmaps(), CPU feature-bit property lookup/registration, and the proposed "feature-words" property)
This should also help avoid bugs like the ones introduced when we added cpuid_7_0_ebx_features. Today, adding a new feature word to the code requires chaning 5 or 6 different places in the code, and it's very easy to miss a problem when we forget to update one of those parts. See, for example:
* The bug solved by commit ffa8c11f0bbf47e1b7a3a62f97bc1da591c6734a; (CPUID 7 leaf was not being filtered based on host capabilities)
* The bug solved by commit 07ca59450c9a0c5df65665ce46aa8487af59a1dd (check/enforce flags were not checking all feature flags)
---
This patch was created solely using a sed script and no manual changes, to try to avoid mistakes while converting the code, and make it easier to rebase if necessary. The sed script can be seen at:
https://gist.github.com/4271991
Changes v6:
- Rebase on top of Andreas' qom-cpu tree (commit 9260944307077b93a66bf861a467107af986fe47)
- Break lines on kvm_check_features_against_host()
- Break the lines on builtin_x86_defs just after the "=". This way the feature lists stay on separate lines, this patch gets easier to review, and future patches that touches the code around builtin_x86_defs will be even easier to review (as they won't need to touch the lines containing the fature lists again)
--- bsd-user/elfload.c | 2 +- bsd-user/main.c | 4 +- hw/kvm/clock.c | 2 +- linux-user/elfload.c | 2 +- linux-user/main.c | 4 +- target-i386/cpu.c | 407 ++++++++++++++++++++++++++++------------------ target-i386/cpu.h | 15 +- target-i386/helper.c | 4 +- target-i386/kvm.c | 5 +- target-i386/misc_helper.c | 14 +- target-i386/translate.c | 10 +- 11 files changed, 271 insertions(+), 198 deletions(-)
bsd-user/elfload.c +1 -1
@@ -110,7 +110,7 @@ static const char *get_elf_platform(void)static uint32_t get_elf_hwcap (void ) { -return thread_env->cpuid_features; +return thread_env->features[FEAT_1_EDX ]; }#ifdef TARGET_X86_64
bsd-user/main.c +2 -2
@@ -1004,13 +1004,13 @@ int main(int argc, char **argv) env->cr[0 ] =CR0_PG_MASK |CR0_WP_MASK |CR0_PE_MASK ; env->hflags |=HF_PE_MASK ; -if (env->cpuid_features &CPUID_SSE ) { +if (env->features[FEAT_1_EDX ] &CPUID_SSE ) { env->cr[4 ] |=CR4_OSFXSR_MASK ; env->hflags |=HF_OSFXSR_MASK ; }#ifndef TARGET_ABI32 /* enable 64 bit mode if possible */ -if (!(env->cpuid_ext2_features &CPUID_EXT2_LM )) { +if (!(env->features[FEAT_8000_0001_EDX ] &CPUID_EXT2_LM )) {fprintf (stderr,"The selected x86 CPU does not support 64 bit mode\n" );exit (1 ); }
hw/kvm/clock.c +1 -1
@@ -129,7 +129,7 @@ static const TypeInfo kvmclock_info = {void kvmclock_create (void ) {if (kvm_enabled () && - first_cpu->cpuid_kvm_features & ((1ULL <<KVM_FEATURE_CLOCKSOURCE ) | + first_cpu->features[FEAT_KVM ] & ((1ULL <<KVM_FEATURE_CLOCKSOURCE ) | (1ULL <<KVM_FEATURE_CLOCKSOURCE2 ))) {sysbus_create_simple ("kvmclock" ,-1 ,NULL ); }
linux-user/elfload.c +1 -1
@@ -130,7 +130,7 @@ static const char *get_elf_platform(void)static uint32_t get_elf_hwcap (void ) { -return thread_env->cpuid_features; +return thread_env->features[FEAT_1_EDX ]; }#ifdef TARGET_X86_64
linux-user/main.c +2 -2
@@ -3764,13 +3764,13 @@ int main(int argc, char **argv, char **envp) env->cr[0 ] =CR0_PG_MASK |CR0_WP_MASK |CR0_PE_MASK ; env->hflags |=HF_PE_MASK ; -if (env->cpuid_features &CPUID_SSE ) { +if (env->features[FEAT_1_EDX ] &CPUID_SSE ) { env->cr[4 ] |=CR4_OSFXSR_MASK ; env->hflags |=HF_OSFXSR_MASK ; }#ifndef TARGET_ABI32 /* enable 64 bit mode if possible */ -if (!(env->cpuid_ext2_features &CPUID_EXT2_LM )) { +if (!(env->features[FEAT_8000_0001_EDX ] &CPUID_EXT2_LM )) {fprintf (stderr,"The selected x86 CPU does not support 64 bit mode\n" );exit (1 ); }
target-i386/cpu.c +245 -162
849 lines not on this page · raw message
target-i386/cpu.h +2 -13
@@ -834,23 +834,14 @@ typedef struct CPUX86State {uint64_t pat;/* processor features (e.g. for CPUID insn) */ -uint32_t cpuid_level; +uint32_t cpuid_level, cpuid_xlevel, cpuid_xlevel2; +FeatureWordArray features;uint32_t cpuid_vendor1;uint32_t cpuid_vendor2;uint32_t cpuid_vendor3;uint32_t cpuid_version; -uint32_t cpuid_features; -uint32_t cpuid_ext_features; -uint32_t cpuid_xlevel;uint32_t cpuid_model[12 ]; -uint32_t cpuid_ext2_features; -uint32_t cpuid_ext3_features;uint32_t cpuid_apic_id; -/* Store the results of Centaur's CPUID instructions */ -uint32_t cpuid_xlevel2; -uint32_t cpuid_ext4_features; -/* Flags from CPUID[EAX=7,ECX=0].EBX */ -uint32_t cpuid_7_0_ebx_features;/* MTRRs */ uint64_t mtrr_fixed[11 ];
@@ -864,8 +855,6 @@ typedef struct CPUX86State {uint8_t soft_interrupt;uint8_t has_error_code;uint32_t sipi_vector; -uint32_t cpuid_kvm_features; -uint32_t cpuid_svm_features;bool tsc_valid;int tsc_khz;void *kvm_xsave_buf;
target-i386/helper.c +2 -2
@@ -463,7 +463,7 @@ void cpu_x86_update_cr4(CPUX86State *env, uint32_t new_cr4)tlb_flush (env,1 ); }/* SSE handling */ -if (!(env->cpuid_features &CPUID_SSE )) { +if (!(env->features[FEAT_1_EDX ] &CPUID_SSE )) { new_cr4 &= ~CR4_OSFXSR_MASK ; } env->hflags &= ~HF_OSFXSR_MASK ;
@@ -471,7 +471,7 @@ void cpu_x86_update_cr4(CPUX86State *env, uint32_t new_cr4) env->hflags |=HF_OSFXSR_MASK ; } -if (!(env->cpuid_7_0_ebx_features &CPUID_7_0_EBX_SMAP )) { +if (!(env->features[FEAT_7_0_EBX ] &CPUID_7_0_EBX_SMAP )) { new_cr4 &= ~CR4_SMAP_MASK ; } env->hflags &= ~HF_SMAP_MASK ;
target-i386/kvm.c +3 -2
@@ -453,7 +453,7 @@ int kvm_arch_init_vcpu(CPUState *cs) c = &cpuid_data.entries[cpuid_i++];memset (c,0 ,sizeof (*c)); c->function =KVM_CPUID_FEATURES ; - c->eax = env->cpuid_kvm_features; + c->eax = env->features[FEAT_KVM ];if (hyperv_enabled ()) {memcpy (signature,"Hv#1\0\0\0\0\0\0\0\0" ,12 );
@@ -610,7 +610,8 @@ int kvm_arch_init_vcpu(CPUState *cs) cpuid_data.cpuid.nent = cpuid_i;if (((env->cpuid_version >>8 )&0xF ) >=6 - && (env->cpuid_features&(CPUID_MCE |CPUID_MCA )) == (CPUID_MCE |CPUID_MCA ) + && (env->features[FEAT_1_EDX ] & (CPUID_MCE |CPUID_MCA )) == + (CPUID_MCE |CPUID_MCA ) &&kvm_check_extension (cs->kvm_state,KVM_CAP_MCE ) >0 ) {uint64_t mcg_cap;int banks;
target-i386/misc_helper.c +7 -7
@@ -291,22 +291,22 @@ void helper_wrmsr(CPUX86State *env)uint64_t update_mask; update_mask =0 ; -if (env->cpuid_ext2_features &CPUID_EXT2_SYSCALL ) { +if (env->features[FEAT_8000_0001_EDX ] &CPUID_EXT2_SYSCALL ) { update_mask |=MSR_EFER_SCE ; } -if (env->cpuid_ext2_features &CPUID_EXT2_LM ) { +if (env->features[FEAT_8000_0001_EDX ] &CPUID_EXT2_LM ) { update_mask |=MSR_EFER_LME ; } -if (env->cpuid_ext2_features &CPUID_EXT2_FFXSR ) { +if (env->features[FEAT_8000_0001_EDX ] &CPUID_EXT2_FFXSR ) { update_mask |=MSR_EFER_FFXSR ; } -if (env->cpuid_ext2_features &CPUID_EXT2_NX ) { +if (env->features[FEAT_8000_0001_EDX ] &CPUID_EXT2_NX ) { update_mask |=MSR_EFER_NXE ; } -if (env->cpuid_ext3_features &CPUID_EXT3_SVM ) { +if (env->features[FEAT_8000_0001_ECX ] &CPUID_EXT3_SVM ) { update_mask |=MSR_EFER_SVME ; } -if (env->cpuid_ext2_features &CPUID_EXT2_FFXSR ) { +if (env->features[FEAT_8000_0001_EDX ] &CPUID_EXT2_FFXSR ) { update_mask |=MSR_EFER_FFXSR ; } cpu_load_efer(env, (env->efer & ~update_mask) |
@@ -513,7 +513,7 @@ void helper_rdmsr(CPUX86State *env) val = env->mtrr_deftype;break ;case MSR_MTRRcap: -if (env->cpuid_features &CPUID_MTRR ) { +if (env->features[FEAT_1_EDX ] &CPUID_MTRR ) { val = MSR_MTRRcap_VCNT | MSR_MTRRcap_FIXRANGE_SUPPORT | MSR_MTRRcap_WC_SUPPORTED; }else {
target-i386/translate.c +5 -5
@@ -8279,11 +8279,11 @@ static inline void gen_intermediate_code_internal(CPUX86State *env,if (flags &HF_SOFTMMU_MASK ) { dc->mem_index = (cpu_mmu_index (env) +1 ) <<2 ; } - dc->cpuid_features = env->cpuid_features; - dc->cpuid_ext_features = env->cpuid_ext_features; - dc->cpuid_ext2_features = env->cpuid_ext2_features; - dc->cpuid_ext3_features = env->cpuid_ext3_features; - dc->cpuid_7_0_ebx_features = env->cpuid_7_0_ebx_features; + dc->cpuid_features = env->features[FEAT_1_EDX ]; + dc->cpuid_ext_features = env->features[FEAT_1_ECX ]; + dc->cpuid_ext2_features = env->features[FEAT_8000_0001_EDX ]; + dc->cpuid_ext3_features = env->features[FEAT_8000_0001_ECX ]; + dc->cpuid_7_0_ebx_features = env->features[FEAT_7_0_EBX ];#ifdef TARGET_X86_64 dc->lma = (flags >>HF_LMA_SHIFT ) &1 ; dc->code64 = (flags >>HF_CS64_SHIFT ) &1 ;
Signature · 1 line
1.8.1.4
It looks like I will need to rebase and resubmit this again.
Is there any hope we can get it included before soft freeze?
Quoted 32 lines · Eduardo Habkost
Changes v6:
- Rebase on top of Andreas' qom-cpu tree (commit9260944307077b93a66bf861a467107af986fe47)
- Break lines onkvm_check_features_against_host()
- Break the lines onbuiltin_x86_defsjust after the "=". This way the feature lists stay on separate lines, this patch gets easier to review, and future patches that touches the code aroundbuiltin_x86_defswill be even easier to review (as they won't need to touch the lines containing the fature lists again)Eduardo Habkost (2):
target-i386/cpu.c: Coding style fixes
target-i386: Replace cpuid_*features fields with a feature word arraybsd-user/elfload.c | 2 +- bsd-user/main.c | 4 +- hw/kvm/clock.c | 2 +- linux-user/elfload.c | 2 +- linux-user/main.c | 4 +- target-i386/cpu.c | 412 ++++++++++++++++++++++++++++------------------ target-i386/cpu.h | 15 +- target-i386/helper.c | 4 +- target-i386/kvm.c | 5 +- target-i386/misc_helper.c | 14 +- target-i386/translate.c | 10 +- 11 files changed, 274 insertions(+), 200 deletions(-)Signature · 1 line
1.8.1.4
Signature · 1 line
Eduardo