Use more cpuid bits from upstream
cover Use more cpuid bits from upstream
This patchset converts kvm_arch_vcpu_init()'s cpuid handling bits to use upstream code.
Avi Kivity (5):
Make get_para_features() similar to upstream Use get_para_features() from upstream Rename kvm_arch_vcpu_init()s cenv argument to env Use skeleton of upstream's kvm_arch_init_vcpu() Use upstream's kvm_arch_init_vcpu()'s cpuid bits
qemu-kvm-x86.c | 148 +++-------------------------------------------------- target-i386/kvm.c | 15 ++++- 2 files changed, 20 insertions(+), 143 deletions(-)
PATCH 1/5 Make get_para_features() similar to upstream
Accept a CPUState parameter instead of a kvm_context_t.
--- qemu-kvm-x86.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
qemu-kvm-x86.c +2 -2
@@ -1132,7 +1132,7 @@ struct kvm_para_features { { -1, -1 } }; -static int get_para_features (kvm_context_t kvm_context) +static int get_para_features (CPUState *env) {int i, features =0 ;
@@ -1184,7 +1184,7 @@ int kvm_arch_init_vcpu(CPUState *cenv) pv_ent = &cpuid_ent[cpuid_nent++];memset (pv_ent,0 ,sizeof (*pv_ent)); pv_ent->function =KVM_CPUID_FEATURES ; - pv_ent->eax =get_para_features (kvm_context); + pv_ent->eax =get_para_features (cenv);#endif kvm_trim_features(&cenv->cpuid_features,
Signature · 1 line
1.7.1
Re: [PATCH 1/5] Make get_para_features() similar to upstream
Quoted 3 lines · Avi Kivity
Accept a CPUState parameter instead of a
kvm_context_t.Signed-off-by Avi Kivity <[email protected]>
PATCH 2/5 Use get_para_features() from upstream
In reply to Avi Kivity--- qemu-kvm-x86.c | 28 ---------------------------- target-i386/kvm.c | 4 ++-- 2 files changed, 2 insertions(+), 30 deletions(-)
qemu-kvm-x86.c +0 -28
@@ -1116,34 +1116,6 @@ static void do_cpuid_ent(struct kvm_cpuid_entry2 *e, uint32_t function, e->edx = env->regs[R_EDX ]; } -struct kvm_para_features { -int cap; -int feature; -} para_features[] = { -#ifdef KVM_CAP_CLOCKSOURCE - {KVM_CAP_CLOCKSOURCE ,KVM_FEATURE_CLOCKSOURCE }, -#endif -#ifdef KVM_CAP_NOP_IO_DELAY - {KVM_CAP_NOP_IO_DELAY ,KVM_FEATURE_NOP_IO_DELAY }, -#endif -#ifdef KVM_CAP_PV_MMU - {KVM_CAP_PV_MMU ,KVM_FEATURE_MMU_OP }, -#endif - {-1 ,-1 } -}; - -static int get_para_features (CPUState *env) -{ -int i, features =0 ; - -for (i =0 ; i <ARRAY_SIZE (para_features)-1 ; i++) { -if (kvm_check_extension (kvm_state, para_features[i].cap)) - features |= (1 << para_features[i].feature); - } - -return features; -} -static void kvm_trim_features (uint32_t *features,uint32_t supported) {int i;
target-i386/kvm.c +2 -2
@@ -133,8 +133,6 @@ uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function, int reg)#endif -#ifdef KVM_UPSTREAM - #ifdef CONFIG_KVM_PARA struct kvm_para_features { int cap;
@@ -165,6 +163,8 @@ static int get_para_features(CPUState *env) }#endif +#ifdef KVM_UPSTREAM +int kvm_arch_init_vcpu (CPUState *env) { struct {
Signature · 1 line
1.7.1
Re: [PATCH 2/5] Use get_para_features() from upstream
Quoted 1 line · Avi Kivity
Signed-off-by Avi Kivity <[email protected]>
PATCH 3/5 Rename kvm_arch_vcpu_init()s cenv argument to env
In reply to Avi KivityBe more similar to upstream.
--- qemu-kvm-x86.c | 42 +++++++++++++++++++++--------------------- 1 files changed, 21 insertions(+), 21 deletions(-)
qemu-kvm-x86.c +21 -21
@@ -1129,7 +1129,7 @@ static void kvm_trim_features(uint32_t *features, uint32_t supported) } } -int kvm_arch_init_vcpu (CPUState *cenv) +int kvm_arch_init_vcpu (CPUState *env) {struct kvm_cpuid_entry2 cpuid_ent[100 ];#ifdef KVM_CPUID_SIGNATURE
@@ -1140,7 +1140,7 @@ int kvm_arch_init_vcpu(CPUState *cenv)CPUState copy;uint32_t i, j, limit; -kvm_arch_reset_vcpu (cenv); +kvm_arch_reset_vcpu (env);#ifdef KVM_CPUID_SIGNATURE /* Paravirtualization CPUIDs */
@@ -1156,24 +1156,24 @@ int kvm_arch_init_vcpu(CPUState *cenv) pv_ent = &cpuid_ent[cpuid_nent++];memset (pv_ent,0 ,sizeof (*pv_ent)); pv_ent->function =KVM_CPUID_FEATURES ; - pv_ent->eax =get_para_features (cenv); + pv_ent->eax =get_para_features (env);#endif -kvm_trim_features (&cenv->cpuid_features, -kvm_arch_get_supported_cpuid (cenv,1 ,R_EDX )); +kvm_trim_features (&env->cpuid_features, +kvm_arch_get_supported_cpuid (env,1 ,R_EDX ));/* prevent the hypervisor bit from being cleared by the kernel */ - i = cenv->cpuid_ext_features &CPUID_EXT_HYPERVISOR ; -kvm_trim_features (&cenv->cpuid_ext_features, -kvm_arch_get_supported_cpuid (cenv,1 ,R_ECX )); - cenv->cpuid_ext_features |= i; + i = env->cpuid_ext_features &CPUID_EXT_HYPERVISOR ; +kvm_trim_features (&env->cpuid_ext_features, +kvm_arch_get_supported_cpuid (env,1 ,R_ECX )); + env->cpuid_ext_features |= i; -kvm_trim_features (&cenv->cpuid_ext2_features, -kvm_arch_get_supported_cpuid (cenv,0x80000001 ,R_EDX )); -kvm_trim_features (&cenv->cpuid_ext3_features, -kvm_arch_get_supported_cpuid (cenv,0x80000001 ,R_ECX )); +kvm_trim_features (&env->cpuid_ext2_features, +kvm_arch_get_supported_cpuid (env,0x80000001 ,R_EDX )); +kvm_trim_features (&env->cpuid_ext3_features, +kvm_arch_get_supported_cpuid (env,0x80000001 ,R_ECX )); - copy = *cenv; + copy = *env; copy.regs[R_EAX ] =0 ;qemu_kvm_cpuid_on_env (©);
@@ -1207,11 +1207,11 @@ int kvm_arch_init_vcpu(CPUState *cenv)for (i =0x80000000 ; i <= limit; ++i)do_cpuid_ent (&cpuid_ent[cpuid_nent++], i,0 , ©); -kvm_setup_cpuid2 (cenv, cpuid_nent, cpuid_ent); +kvm_setup_cpuid2 (env, cpuid_nent, cpuid_ent);#ifdef KVM_CAP_MCE -if (((cenv->cpuid_version >>8 )&0xF ) >=6 - && (cenv->cpuid_features&(CPUID_MCE |CPUID_MCA )) == (CPUID_MCE |CPUID_MCA ) +if (((env->cpuid_version >>8 )&0xF ) >=6 + && (env->cpuid_features&(CPUID_MCE |CPUID_MCA )) == (CPUID_MCE |CPUID_MCA ) &&kvm_check_extension (kvm_state,KVM_CAP_MCE ) >0 ) {uint64_t mcg_cap;int banks;
@@ -1223,18 +1223,18 @@ int kvm_arch_init_vcpu(CPUState *cenv) banks =MCE_BANKS_DEF ; mcg_cap &=MCE_CAP_DEF ; mcg_cap |= banks; -if (kvm_setup_mce (cenv, &mcg_cap)) +if (kvm_setup_mce (env, &mcg_cap))perror ("kvm_setup_mce FAILED" );else - cenv->mcg_cap = mcg_cap; + env->mcg_cap = mcg_cap; } }#endif #ifdef KVM_EXIT_TPR_ACCESS -kvm_enable_tpr_access_reporting (cenv); +kvm_enable_tpr_access_reporting (env);#endif -kvm_reset_mpstate (cenv); +kvm_reset_mpstate (env);return 0 ; }
Signature · 1 line
1.7.1
Re: [PATCH 3/5] Rename kvm_arch_vcpu_init()s cenv argument to env
Quoted 3 lines · Avi Kivity
Be more similar to upstream.
Signed-off-by Avi Kivity <[email protected]>
PATCH 4/5 Use skeleton of upstream's kvm_arch_init_vcpu()
In reply to Avi KivityCurrently all content from qemu-kvm's kvm_arch_init_vcpu().
--- qemu-kvm-x86.c | 2 +- target-i386/kvm.c | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-)
qemu-kvm-x86.c +1 -1
@@ -1129,7 +1129,7 @@ static void kvm_trim_features(uint32_t *features, uint32_t supported) } } -int kvm_arch_init_vcpu (CPUState *env) +static int _kvm_arch_init_vcpu (CPUState *env) {struct kvm_cpuid_entry2 cpuid_ent[100 ];#ifdef KVM_CPUID_SIGNATURE
target-i386/kvm.c +15 -2
@@ -163,10 +163,13 @@ static int get_para_features(CPUState *env) }#endif -#ifdef KVM_UPSTREAM +static int _kvm_arch_init_vcpu (CPUState *env);int kvm_arch_init_vcpu (CPUState *env) { +int r; +#ifdef KVM_UPSTREAM + struct { struct kvm_cpuid2 cpuid; struct kvm_cpuid_entry2 entries[100];
@@ -178,6 +181,15 @@ int kvm_arch_init_vcpu(CPUState *env)uint32_t signature[3 ];#endif +#endif + + r =_kvm_arch_init_vcpu (env); +if (r <0 ) { +return r; + } + +#ifdef KVM_UPSTREAM + env->mp_state =KVM_MP_STATE_RUNNABLE ; env->cpuid_features &=kvm_arch_get_supported_cpuid (env,1 ,R_EDX );
@@ -273,9 +285,10 @@ int kvm_arch_init_vcpu(CPUState *env) cpuid_data.cpuid.nent = cpuid_i;return kvm_vcpu_ioctl (env,KVM_SET_CPUID2 , &cpuid_data); +#endif +return 0 ; } -#endif void kvm_arch_reset_vcpu (CPUState *env) { env->exception_injected =-1 ;
Signature · 1 line
1.7.1
Re: [PATCH 4/5] Use skeleton of upstream's kvm_arch_init_vcpu()
Quoted 3 lines · Avi Kivity
Currently all content from qemu-kvm's
kvm_arch_init_vcpu().Signed-off-by Avi Kivity <[email protected]>
PATCH 5/5 Use upstream's kvm_arch_init_vcpu()'s cpuid bits
In reply to Avi Kivity--- qemu-kvm-x86.c | 104 ----------------------------------------------------- target-i386/kvm.c | 8 +--- 2 files changed, 2 insertions(+), 110 deletions(-)
qemu-kvm-x86.c +0 -104
@@ -1101,114 +1101,10 @@ void kvm_arch_save_regs(CPUState *env)kvm_get_debugregs (env); } -static void do_cpuid_ent (struct kvm_cpuid_entry2 *e,uint32_t function, -uint32_t count,CPUState *env) -{ - env->regs[R_EAX ] = function; - env->regs[R_ECX ] = count; -qemu_kvm_cpuid_on_env (env); - e->function = function; - e->flags =0 ; - e->index =0 ; - e->eax = env->regs[R_EAX ]; - e->ebx = env->regs[R_EBX ]; - e->ecx = env->regs[R_ECX ]; - e->edx = env->regs[R_EDX ]; -} - -static void kvm_trim_features (uint32_t *features,uint32_t supported) -{ -int i; -uint32_t mask; - -for (i =0 ; i <32 ; ++i) { - mask =1U << i; -if ((*features & mask) && !(supported & mask)) { - *features &= ~mask; - } - } -} -static int _kvm_arch_init_vcpu (CPUState *env) { -struct kvm_cpuid_entry2 cpuid_ent[100 ]; -#ifdef KVM_CPUID_SIGNATURE -struct kvm_cpuid_entry2 *pv_ent; -uint32_t signature[3 ]; -#endif -int cpuid_nent =0 ; -CPUState copy; -uint32_t i, j, limit; -kvm_arch_reset_vcpu (env); -#ifdef KVM_CPUID_SIGNATURE -/* Paravirtualization CPUIDs */ -memcpy (signature,"KVMKVMKVM\0\0\0" ,12 ); - pv_ent = &cpuid_ent[cpuid_nent++]; -memset (pv_ent,0 ,sizeof (*pv_ent)); - pv_ent->function =KVM_CPUID_SIGNATURE ; - pv_ent->eax =0 ; - pv_ent->ebx = signature[0 ]; - pv_ent->ecx = signature[1 ]; - pv_ent->edx = signature[2 ]; - - pv_ent = &cpuid_ent[cpuid_nent++]; -memset (pv_ent,0 ,sizeof (*pv_ent)); - pv_ent->function =KVM_CPUID_FEATURES ; - pv_ent->eax =get_para_features (env); -#endif - -kvm_trim_features (&env->cpuid_features, -kvm_arch_get_supported_cpuid (env,1 ,R_EDX )); - -/* prevent the hypervisor bit from being cleared by the kernel */ - i = env->cpuid_ext_features &CPUID_EXT_HYPERVISOR ; -kvm_trim_features (&env->cpuid_ext_features, -kvm_arch_get_supported_cpuid (env,1 ,R_ECX )); - env->cpuid_ext_features |= i; - -kvm_trim_features (&env->cpuid_ext2_features, -kvm_arch_get_supported_cpuid (env,0x80000001 ,R_EDX )); -kvm_trim_features (&env->cpuid_ext3_features, -kvm_arch_get_supported_cpuid (env,0x80000001 ,R_ECX )); - - copy = *env; - - copy.regs[R_EAX ] =0 ; -qemu_kvm_cpuid_on_env (©); - limit = copy.regs[R_EAX ]; - -for (i =0 ; i <= limit; ++i) { -if (i ==4 || i ==0xb || i ==0xd ) { -for (j =0 ; ; ++j) { -do_cpuid_ent (&cpuid_ent[cpuid_nent], i, j, ©); - - cpuid_ent[cpuid_nent].flags =KVM_CPUID_FLAG_SIGNIFCANT_INDEX ; - cpuid_ent[cpuid_nent].index = j; - - cpuid_nent++; - -if (i ==4 && copy.regs[R_EAX ] ==0 ) -break ; -if (i ==0xb && !(copy.regs[R_ECX ] &0xff00 )) -break ; -if (i ==0xd && copy.regs[R_EAX ] ==0 ) -break ; - } - }else -do_cpuid_ent (&cpuid_ent[cpuid_nent++], i,0 , ©); - } - - copy.regs[R_EAX ] =0x80000000 ; -qemu_kvm_cpuid_on_env (©); - limit = copy.regs[R_EAX ]; - -for (i =0x80000000 ; i <= limit; ++i) -do_cpuid_ent (&cpuid_ent[cpuid_nent++], i,0 , ©); - -kvm_setup_cpuid2 (env, cpuid_nent, cpuid_ent); -#ifdef KVM_CAP_MCE if (((env->cpuid_version >>8 )&0xF ) >=6 && (env->cpuid_features&(CPUID_MCE|CPUID_MCA)) == (CPUID_MCE|CPUID_MCA)
target-i386/kvm.c +2 -6
@@ -168,8 +168,6 @@ static int _kvm_arch_init_vcpu(CPUState *env);int kvm_arch_init_vcpu (CPUState *env) {int r; -#ifdef KVM_UPSTREAM -struct {struct kvm_cpuid2 cpuid;struct kvm_cpuid_entry2 entries[100 ];
@@ -181,8 +179,6 @@ int kvm_arch_init_vcpu(CPUState *env)uint32_t signature[3 ];#endif -#endif - r =_kvm_arch_init_vcpu (env);if (r <0 ) {return r;
@@ -192,6 +188,8 @@ int kvm_arch_init_vcpu(CPUState *env) env->mp_state =KVM_MP_STATE_RUNNABLE ; +#endif + env->cpuid_features &=kvm_arch_get_supported_cpuid (env,1 ,R_EDX ); i = env->cpuid_ext_features &CPUID_EXT_HYPERVISOR ;
@@ -285,8 +283,6 @@ int kvm_arch_init_vcpu(CPUState *env) cpuid_data.cpuid.nent = cpuid_i;return kvm_vcpu_ioctl (env,KVM_SET_CPUID2 , &cpuid_data); -#endif -return 0 ; }void kvm_arch_reset_vcpu (CPUState *env)
Signature · 1 line
1.7.1
Re: [PATCH 5/5] Use upstream's kvm_arch_init_vcpu()'s cpuid bits
Quoted 1 line · Avi Kivity
Signed-off-by Avi Kivity <[email protected]>
Marcelo Tosatti
AppliedQuoted 10 lines · Avi Kivity
This patchset converts kvm_arch_vcpu_init()'s cpuid handling bits to use upstream code.
Avi Kivity (5):
Makeget_para_features()similar to upstream Useget_para_features()from upstream Rename kvm_arch_vcpu_init()s cenv argument to env Use skeleton of upstream'skvm_arch_init_vcpu()Use upstream's kvm_arch_init_vcpu()'s cpuid bits
Quoted 3 lines
qemu-kvm-x86.c | 148 +++-------------------------------------------------- target-i386/kvm.c | 15 ++++- 2 files changed, 20 insertions(+), 143 deletions(-)
Applied, thanks.