target-i386: Eliminate unnecessary has_msr_* global variables
cover target-i386: Eliminate unnecessary has_msr_* global variables
Some of the has_msr_* global variables are set depending on X86PCU fields and are unnecessary because we can look at the X86CPU object directly. This series eliminates some of them.
Eduardo Habkost (5):
target-i386: Remove has_msr_mtrr global variable
target-i386: Remove has_msr_hv_apic global variable
target-i386: Remove has_msr_hv_tsc global variable
target-i386: Clear KVM CPUID features if KVM is disabled
target-i386: Remove has_msr_* global vars for KVM features
target-i386/cpu.c | 4 ++++ target-i386/kvm.c | 51 +++++++++++++++++++-------------------------------- 2 files changed, 23 insertions(+), 32 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/5 target-i386: Remove has_msr_mtrr global variable
The global variable is not necessary because we can check the CPU feature flags directly.
--- target-i386/kvm.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
target-i386/kvm.c +2 -6
@@ -99,7 +99,6 @@ static bool has_msr_hv_vpindex;static bool has_msr_hv_runtime;static bool has_msr_hv_synic;static bool has_msr_hv_stimer; -static bool has_msr_mtrr;static bool has_msr_xss;static bool has_msr_architectural_pmu;
@@ -975,9 +974,6 @@ int kvm_arch_init_vcpu(CPUState *cs) } cpu->kvm_msr_buf =g_malloc0 (MSR_BUF_SIZE ); -if (env->features[FEAT_1_EDX ] &CPUID_MTRR ) { - has_msr_mtrr = true; - }if (!(env->features[FEAT_8000_0001_EDX ] &CPUID_EXT2_RDTSCP )) { has_msr_tsc_aux = false; }
@@ -1735,7 +1731,7 @@ static int kvm_put_msrs(X86CPU *cpu, int level) env->msr_hv_stimer_count[j]); } } -if (has_msr_mtrr) { +if (env->features[FEAT_1_EDX ] &CPUID_MTRR ) {uint64_t phys_mask =MAKE_64BIT_MASK (0 , cpu->phys_bits);kvm_msr_entry_add (cpu, MSR_MTRRdefType, env->mtrr_deftype);
@@ -2125,7 +2121,7 @@ static int kvm_get_msrs(X86CPU *cpu)kvm_msr_entry_add (cpu, msr,0 ); } } -if (has_msr_mtrr) { +if (env->features[FEAT_1_EDX ] &CPUID_MTRR ) {kvm_msr_entry_add (cpu, MSR_MTRRdefType,0 );kvm_msr_entry_add (cpu, MSR_MTRRfix64K_00000,0 );kvm_msr_entry_add (cpu, MSR_MTRRfix16K_80000,0 );
Signature · 1 line
2.7.4
PATCH 2/5 target-i386: Remove has_msr_hv_apic global variable
In reply to Eduardo HabkostThe global variable is not necessary because we can check cpu->hyperv_vapic directly.
--- target-i386/kvm.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
target-i386/kvm.c +3 -5
@@ -91,7 +91,6 @@ static bool has_msr_bndcfgs;static bool has_msr_kvm_steal_time;static int lm_capable_kernel;static bool has_msr_hv_hypercall; -static bool has_msr_hv_vapic;static bool has_msr_hv_tsc;static bool has_msr_hv_crash;static bool has_msr_hv_reset;
@@ -609,7 +608,6 @@ static int hyperv_handle_properties(CPUState *cs)if (cpu->hyperv_vapic) { env->features[FEAT_HYPERV_EAX ] |=HV_X64_MSR_HYPERCALL_AVAILABLE ; env->features[FEAT_HYPERV_EAX ] |=HV_X64_MSR_APIC_ACCESS_AVAILABLE ; - has_msr_hv_vapic = true; }if (cpu->hyperv_time &&kvm_check_extension (cs->kvm_state,KVM_CAP_HYPERV_TIME ) >0 ) {
@@ -728,7 +726,7 @@ int kvm_arch_init_vcpu(CPUState *cs)if (cpu->hyperv_relaxed_timing) { c->eax |=HV_X64_RELAXED_TIMING_RECOMMENDED ; } -if (has_msr_hv_vapic) { +if (cpu->hyperv_vapic) { c->eax |=HV_X64_APIC_ACCESS_RECOMMENDED ; } c->ebx = cpu->hyperv_spinlock_attempts;
@@ -1681,7 +1679,7 @@ static int kvm_put_msrs(X86CPU *cpu, int level)kvm_msr_entry_add (cpu,HV_X64_MSR_HYPERCALL , env->msr_hv_hypercall); } -if (has_msr_hv_vapic) { +if (cpu->hyperv_vapic) {kvm_msr_entry_add (cpu,HV_X64_MSR_APIC_ASSIST_PAGE , env->msr_hv_vapic); }
@@ -2086,7 +2084,7 @@ static int kvm_get_msrs(X86CPU *cpu)kvm_msr_entry_add (cpu,HV_X64_MSR_HYPERCALL ,0 );kvm_msr_entry_add (cpu,HV_X64_MSR_GUEST_OS_ID ,0 ); } -if (has_msr_hv_vapic) { +if (cpu->hyperv_vapic) {kvm_msr_entry_add (cpu,HV_X64_MSR_APIC_ASSIST_PAGE ,0 ); }if (has_msr_hv_tsc) {
Signature · 1 line
2.7.4
PATCH 3/5 target-i386: Remove has_msr_hv_tsc global variable
In reply to Eduardo HabkostThe global variable is not necessary because we can check cpu->hyperv_time directly.
We just need to ensure cpu->hyperv_time will be cleared if the feature is not really being exposed to the guest due to missing KVM_CAP_HYPERV_TIME capability.
--- target-i386/kvm.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
target-i386/kvm.c +8 -6
@@ -91,7 +91,6 @@ static bool has_msr_bndcfgs;static bool has_msr_kvm_steal_time;static int lm_capable_kernel;static bool has_msr_hv_hypercall; -static bool has_msr_hv_tsc;static bool has_msr_hv_crash;static bool has_msr_hv_reset;static bool has_msr_hv_vpindex;
@@ -602,6 +601,11 @@ static int hyperv_handle_properties(CPUState *cs)X86CPU *cpu =X86_CPU (cs);CPUX86State *env = &cpu->env; +if (cpu->hyperv_time && +kvm_check_extension (cs->kvm_state,KVM_CAP_HYPERV_TIME ) <=0 ) { + cpu->hyperv_time = false; + } +if (cpu->hyperv_relaxed_timing) { env->features[FEAT_HYPERV_EAX ] |=HV_X64_MSR_HYPERCALL_AVAILABLE ; }
@@ -609,12 +613,10 @@ static int hyperv_handle_properties(CPUState *cs) env->features[FEAT_HYPERV_EAX ] |=HV_X64_MSR_HYPERCALL_AVAILABLE ; env->features[FEAT_HYPERV_EAX ] |=HV_X64_MSR_APIC_ACCESS_AVAILABLE ; } -if (cpu->hyperv_time && -kvm_check_extension (cs->kvm_state,KVM_CAP_HYPERV_TIME ) >0 ) { +if (cpu->hyperv_time) { env->features[FEAT_HYPERV_EAX ] |=HV_X64_MSR_HYPERCALL_AVAILABLE ; env->features[FEAT_HYPERV_EAX ] |=HV_X64_MSR_TIME_REF_COUNT_AVAILABLE ; env->features[FEAT_HYPERV_EAX ] |=0x200 ; - has_msr_hv_tsc = true; }if (cpu->hyperv_crash && has_msr_hv_crash) { env->features[FEAT_HYPERV_EDX ] |=HV_X64_GUEST_CRASH_MSR_AVAILABLE ;
@@ -1683,7 +1685,7 @@ static int kvm_put_msrs(X86CPU *cpu, int level)kvm_msr_entry_add (cpu,HV_X64_MSR_APIC_ASSIST_PAGE , env->msr_hv_vapic); } -if (has_msr_hv_tsc) { +if (cpu->hyperv_time) {kvm_msr_entry_add (cpu,HV_X64_MSR_REFERENCE_TSC , env->msr_hv_tsc); }if (has_msr_hv_crash) {
@@ -2087,7 +2089,7 @@ static int kvm_get_msrs(X86CPU *cpu)if (cpu->hyperv_vapic) {kvm_msr_entry_add (cpu,HV_X64_MSR_APIC_ASSIST_PAGE ,0 ); } -if (has_msr_hv_tsc) { +if (cpu->hyperv_time) {kvm_msr_entry_add (cpu,HV_X64_MSR_REFERENCE_TSC ,0 ); }if (has_msr_hv_crash) {
Signature · 1 line
2.7.4
PATCH 4/5 target-i386: Clear KVM CPUID features if KVM is disabled
In reply to Eduardo HabkostThis will ensure all checks for features[FEAT_KVM] in the code will be correct in case the KVM CPUID leaf is completely disabled.
--- target-i386/cpu.c | 4 ++++ 1 file changed, 4 insertions(+)
target-i386/cpu.c +4 -0
@@ -2998,6 +2998,10 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) cpu->env.features[w] &= ~minus_features[w]; } +if (!kvm_enabled () || !cpu->expose_kvm) { + env->features[FEAT_KVM ] =0 ; + } +if (env->features[FEAT_7_0_EBX ] && env->cpuid_level <7 ) { env->cpuid_level =7 ; }
Signature · 1 line
2.7.4
PATCH 5/5 target-i386: Remove has_msr_* global vars for KVM features
In reply to Eduardo HabkostThe global variables are not necessary because we can check KVM feature flags in X86CPU directly.
--- target-i386/kvm.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-)
target-i386/kvm.c +6 -15
@@ -83,12 +83,9 @@ static bool has_msr_tsc_aux;static bool has_msr_tsc_adjust;static bool has_msr_tsc_deadline;static bool has_msr_feature_control; -static bool has_msr_async_pf_en; -static bool has_msr_pv_eoi_en;static bool has_msr_misc_enable;static bool has_msr_smbase;static bool has_msr_bndcfgs; -static bool has_msr_kvm_steal_time;static int lm_capable_kernel;static bool has_msr_hv_hypercall;static bool has_msr_hv_crash;
@@ -754,12 +751,6 @@ int kvm_arch_init_vcpu(CPUState *cs) c = &cpuid_data.entries[cpuid_i++]; c->function =KVM_CPUID_FEATURES | kvm_base; c->eax = env->features[FEAT_KVM ]; - - has_msr_async_pf_en = c->eax & (1 <<KVM_FEATURE_ASYNC_PF ); - - has_msr_pv_eoi_en = c->eax & (1 <<KVM_FEATURE_PV_EOI ); - - has_msr_kvm_steal_time = c->eax & (1 <<KVM_FEATURE_STEAL_TIME ); }cpu_x86_cpuid (env,0 ,0 , &limit, &unused, &unused, &unused);
@@ -1639,13 +1630,13 @@ static int kvm_put_msrs(X86CPU *cpu, int level)kvm_msr_entry_add (cpu,MSR_IA32_TSC , env->tsc);kvm_msr_entry_add (cpu,MSR_KVM_SYSTEM_TIME , env->system_time_msr);kvm_msr_entry_add (cpu,MSR_KVM_WALL_CLOCK , env->wall_clock_msr); -if (has_msr_async_pf_en) { +if (env->features[FEAT_KVM ] & (1 <<KVM_FEATURE_ASYNC_PF )) {kvm_msr_entry_add (cpu,MSR_KVM_ASYNC_PF_EN , env->async_pf_en_msr); } -if (has_msr_pv_eoi_en) { +if (env->features[FEAT_KVM ] & (1 <<KVM_FEATURE_PV_EOI )) {kvm_msr_entry_add (cpu,MSR_KVM_PV_EOI_EN , env->pv_eoi_en_msr); } -if (has_msr_kvm_steal_time) { +if (env->features[FEAT_KVM ] & (1 <<KVM_FEATURE_STEAL_TIME )) {kvm_msr_entry_add (cpu,MSR_KVM_STEAL_TIME , env->steal_time_msr); }if (has_msr_architectural_pmu) {
@@ -2048,13 +2039,13 @@ static int kvm_get_msrs(X86CPU *cpu)#endif kvm_msr_entry_add (cpu,MSR_KVM_SYSTEM_TIME ,0 );kvm_msr_entry_add (cpu,MSR_KVM_WALL_CLOCK ,0 ); -if (has_msr_async_pf_en) { +if (env->features[FEAT_KVM ] & (1 <<KVM_FEATURE_ASYNC_PF )) {kvm_msr_entry_add (cpu,MSR_KVM_ASYNC_PF_EN ,0 ); } -if (has_msr_pv_eoi_en) { +if (env->features[FEAT_KVM ] & (1 <<KVM_FEATURE_PV_EOI )) {kvm_msr_entry_add (cpu,MSR_KVM_PV_EOI_EN ,0 ); } -if (has_msr_kvm_steal_time) { +if (env->features[FEAT_KVM ] & (1 <<KVM_FEATURE_STEAL_TIME )) {kvm_msr_entry_add (cpu,MSR_KVM_STEAL_TIME ,0 ); }if (has_msr_architectural_pmu) {
Signature · 1 line
2.7.4
----- Original Message -----
Quoted 17 lines
From: "Eduardo Habkost" <[email protected]>
To: "Paolo Bonzini" <[email protected]>, "Marcelo Tosatti" <[email protected]>
Cc: [email protected], [email protected]
Sent: Tuesday, September 27, 2016 12:24:05 AM
Subject: [PATCH 0/5] target-i386: Eliminate unnecessary has_msr_* global variablesSome of the has_msr_* global variables are set depending on X86PCU fields and are unnecessary because we can look at the X86CPU object directly. This series eliminates some of them.
Eduardo Habkost (5):
target-i386: Removehas_msr_mtrrglobal variable
target-i386: Removehas_msr_hv_apicglobal variable
target-i386: Removehas_msr_hv_tscglobal variable
target-i386: Clear KVM CPUID features if KVM is disabled
target-i386: Remove has_msr_* global vars for KVM features
Quoted 3 lines
target-i386/cpu.c | 4 ++++ target-i386/kvm.c | 51 +++++++++++++++++++-------------------------------- 2 files changed, 23 insertions(+), 32 deletions(-)
Quoted 18 lines · Paolo Bonzini
----- Original Message -----
Quoted 17 lines
From: "Eduardo Habkost" <[email protected]>
To: "Paolo Bonzini" <[email protected]>, "Marcelo Tosatti" <[email protected]>
Cc: [email protected], [email protected]
Sent: Tuesday, September 27, 2016 12:24:05 AM
Subject: [PATCH 0/5] target-i386: Eliminate unnecessary has_msr_* global variablesSome of the has_msr_* global variables are set depending on X86PCU fields and are unnecessary because we can look at the X86CPU object directly. This series eliminates some of them.
Eduardo Habkost (5):
target-i386: Removehas_msr_mtrrglobal variable
target-i386: Removehas_msr_hv_apicglobal variable
target-i386: Removehas_msr_hv_tscglobal variable
target-i386: Clear KVM CPUID features if KVM is disabled
target-i386: Remove has_msr_* global vars for KVM features
Quoted 6 lines
Quoted 3 lines
target-i386/cpu.c | 4 ++++ target-i386/kvm.c | 51 +++++++++++++++++++-------------------------------- 2 files changed, 23 insertions(+), 32 deletions(-)Reviewed-by Paolo Bonzini <[email protected]>
Thanks, queued on x86-next.
Signature · 1 line
Eduardo