Hyper-V parameters
cover Hyper-V parameters
From: Vadim Rozenfeld <[email protected]>
This series conists of three patches and addresses the following issues:
- adjusting hyperv parameters according to MS requirements
http://msdn.microsoft.com/library/windows/hardware/hh975392
- make hyperv hypercall and vapic pages migratable
- add support for enabling hyperv reference counters
Vadim Rozenfeld (3):
cleanup hyper-v interface initialization
make hyperv hypercall, vapic, and os id MSRs migratable add support for hyperv time parameter
linux-headers/asm-x86/hyperv.h | 3 ++ linux-headers/linux/kvm.h | 1 + target-i386/cpu-qom.h | 1 + target-i386/cpu.c | 1 + target-i386/cpu.h | 5 +++ target-i386/kvm.c | 95 +++++++++++++++++++++++++++--------------- target-i386/machine.c | 25 +++++++++++ 7 files changed, 97 insertions(+), 34 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 1/3 cleanup hyper-v interface initialization
--- target-i386/kvm.c | 46 +++++++++++++++++----------------------------- 1 file changed, 17 insertions(+), 29 deletions(-)
target-i386/kvm.c +17 -29
@@ -71,6 +71,8 @@ static bool has_msr_pv_eoi_en;static bool has_msr_misc_enable;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_architectural_pmu;static uint32_t num_architectural_pmu_counters;
@@ -463,13 +465,7 @@ int kvm_arch_init_vcpu(CPUState *cs)/* Paravirtualization CPUIDs */ c = &cpuid_data.entries[cpuid_i++]; c->function =KVM_CPUID_SIGNATURE ; -if (!hyperv_enabled (cpu)) { -memcpy (signature,"KVMKVMKVM\0\0\0" ,12 ); - c->eax =0 ; - }else { -memcpy (signature,"Microsoft Hv" ,12 ); - c->eax =HYPERV_CPUID_MIN ; - } +memcpy (signature,"KVMKVMKVM\0\0\0" ,12 ); c->ebx = signature[0 ]; c->ecx = signature[1 ]; c->edx = signature[2 ];
@@ -478,23 +474,23 @@ int kvm_arch_init_vcpu(CPUState *cs) c->function =KVM_CPUID_FEATURES ; c->eax = env->features[FEAT_KVM ]; -if (hyperv_enabled (cpu)) { +if (hyperv_enabled (cpu) && +kvm_check_extension (cs->kvm_state,KVM_CAP_HYPERV ) >0 ) { + has_msr_hv_hypercall = true; +memcpy (signature,"Hv#1\0\0\0\0\0\0\0\0" ,12 ); c->eax = signature[0 ]; c = &cpuid_data.entries[cpuid_i++]; - c->function =HYPERV_CPUID_VERSION ; - c->eax =0x00001bbc ; - c->ebx =0x00060001 ; - - c = &cpuid_data.entries[cpuid_i++]; c->function =HYPERV_CPUID_FEATURES ;if (cpu->hyperv_relaxed_timing) { c->eax |=HV_X64_MSR_HYPERCALL_AVAILABLE ; } -if (cpu->hyperv_vapic) { +if (cpu->hyperv_vapic && +kvm_check_extension (cs->kvm_state,KVM_CAP_HYPERV_VAPIC ) >0 ) { c->eax |=HV_X64_MSR_HYPERCALL_AVAILABLE ; c->eax |=HV_X64_MSR_APIC_ACCESS_AVAILABLE ; + has_msr_hv_vapic = true; } c = &cpuid_data.entries[cpuid_i++];
@@ -502,23 +498,15 @@ int kvm_arch_init_vcpu(CPUState *cs)if (cpu->hyperv_relaxed_timing) { c->eax |=HV_X64_RELAXED_TIMING_RECOMMENDED ; } -if (cpu->hyperv_vapic) { +if (has_msr_hv_vapic) { c->eax |=HV_X64_APIC_ACCESS_RECOMMENDED ; } - c->ebx = cpu->hyperv_spinlock_attempts; - - c = &cpuid_data.entries[cpuid_i++]; - c->function =HYPERV_CPUID_IMPLEMENT_LIMITS ; - c->eax =0x40 ; - c->ebx =0x40 ; - - c = &cpuid_data.entries[cpuid_i++]; - c->function =KVM_CPUID_SIGNATURE_NEXT ; -memcpy (signature,"KVMKVMKVM\0\0\0" ,12 ); - c->eax =0 ; - c->ebx = signature[0 ]; - c->ecx = signature[1 ]; - c->edx = signature[2 ]; +if (cpu->hyperv_spinlock_attempts !=HYPERV_SPINLOCK_NEVER_RETRY && +kvm_check_extension (cs->kvm_state,KVM_CAP_HYPERV_SPIN ) >0 ) { + c->ebx = cpu->hyperv_spinlock_attempts; + }else { + c->ebx =HYPERV_SPINLOCK_NEVER_RETRY ; + } } has_msr_async_pf_en = c->eax & (1 <<KVM_FEATURE_ASYNC_PF );
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 1/3] cleanup hyper-v interface initialization
Il 21/01/2014 09:02, Vadim Rozenfeld ha scritto:
Quoted 4 lines
Signed-off-by Vadim Rozenfeld <[email protected]>--- target-i386/kvm.c | 46 +++++++++++++++++----------------------------- 1 file changed, 17 insertions(+), 29 deletions(-)
Please split this part into multiple parts and document each in the commit message.
Also please cite relevant parts of the MS document in the commit messages.
Paolo
Quoted 91 lines
target-i386/kvm.c +17
-29@@ -71,6 +71,8 @@ static bool has_msr_pv_eoi_en;static bool has_msr_misc_enable;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_architectural_pmu;static uint32_t num_architectural_pmu_counters;@@ -463,13 +465,7 @@ int kvm_arch_init_vcpu(CPUState *cs)/* Paravirtualization CPUIDs */ c = &cpuid_data.entries[cpuid_i++]; c->function =KVM_CPUID_SIGNATURE ; -if (!hyperv_enabled (cpu)) { -memcpy (signature,"KVMKVMKVM\0\0\0" ,12 ); - c->eax =0 ; - }else { -memcpy (signature,"Microsoft Hv" ,12 ); - c->eax =HYPERV_CPUID_MIN ; - } +memcpy (signature,"KVMKVMKVM\0\0\0" ,12 ); c->ebx = signature[0 ]; c->ecx = signature[1 ]; c->edx = signature[2 ];@@ -478,23 +474,23 @@ int kvm_arch_init_vcpu(CPUState *cs) c->function =KVM_CPUID_FEATURES ; c->eax = env->features[FEAT_KVM ]; -if (hyperv_enabled (cpu)) { +if (hyperv_enabled (cpu) && +kvm_check_extension (cs->kvm_state,KVM_CAP_HYPERV ) >0 ) { + has_msr_hv_hypercall = true; +memcpy (signature,"Hv#1\0\0\0\0\0\0\0\0" ,12 ); c->eax = signature[0 ]; c = &cpuid_data.entries[cpuid_i++]; - c->function =HYPERV_CPUID_VERSION ; - c->eax =0x00001bbc ; - c->ebx =0x00060001 ; - - c = &cpuid_data.entries[cpuid_i++]; c->function =HYPERV_CPUID_FEATURES ;if (cpu->hyperv_relaxed_timing) { c->eax |=HV_X64_MSR_HYPERCALL_AVAILABLE ; } -if (cpu->hyperv_vapic) { +if (cpu->hyperv_vapic && +kvm_check_extension (cs->kvm_state,KVM_CAP_HYPERV_VAPIC ) >0 ) { c->eax |=HV_X64_MSR_HYPERCALL_AVAILABLE ; c->eax |=HV_X64_MSR_APIC_ACCESS_AVAILABLE ; + has_msr_hv_vapic = true; } c = &cpuid_data.entries[cpuid_i++];@@ -502,23 +498,15 @@ int kvm_arch_init_vcpu(CPUState *cs)if (cpu->hyperv_relaxed_timing) { c->eax |=HV_X64_RELAXED_TIMING_RECOMMENDED ; } -if (cpu->hyperv_vapic) { +if (has_msr_hv_vapic) { c->eax |=HV_X64_APIC_ACCESS_RECOMMENDED ; } - c->ebx = cpu->hyperv_spinlock_attempts; - - c = &cpuid_data.entries[cpuid_i++]; - c->function =HYPERV_CPUID_IMPLEMENT_LIMITS ; - c->eax =0x40 ; - c->ebx =0x40 ; - - c = &cpuid_data.entries[cpuid_i++]; - c->function =KVM_CPUID_SIGNATURE_NEXT ; -memcpy (signature,"KVMKVMKVM\0\0\0" ,12 ); - c->eax =0 ; - c->ebx = signature[0 ]; - c->ecx = signature[1 ]; - c->edx = signature[2 ]; +if (cpu->hyperv_spinlock_attempts !=HYPERV_SPINLOCK_NEVER_RETRY && +kvm_check_extension (cs->kvm_state,KVM_CAP_HYPERV_SPIN ) >0 ) { + c->ebx = cpu->hyperv_spinlock_attempts; + }else { + c->ebx =HYPERV_SPINLOCK_NEVER_RETRY ; + } } has_msr_async_pf_en = c->eax & (1 <<KVM_FEATURE_ASYNC_PF );
PATCH 2/3 make hyperv hypercall, vapic, and os id MSRs migratable
In reply to Vadim Rozenfeld--- target-i386/cpu.h | 4 ++++ target-i386/kvm.c | 30 +++++++++++++++++++++++++----- target-i386/machine.c | 24 ++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 5 deletions(-)
target-i386/cpu.h +4 -0
@@ -847,6 +847,10 @@ typedef struct CPUX86State {uint64_t msr_gp_counters[MAX_GP_COUNTERS ];uint64_t msr_gp_evtsel[MAX_GP_COUNTERS ]; +uint64_t msr_hv_hypercall; +uint64_t msr_hv_guest_os_id; +uint64_t msr_hv_vapic; +/* exception/interrupt handling */ int error_code;int exception_is_int;
target-i386/kvm.c +25 -5
@@ -1185,12 +1185,15 @@ static int kvm_put_msrs(X86CPU *cpu, int level)kvm_msr_entry_set (&msrs[n++],MSR_CORE_PERF_GLOBAL_CTRL , env->msr_global_ctrl); } -if (hyperv_hypercall_available (cpu)) { -kvm_msr_entry_set (&msrs[n++],HV_X64_MSR_GUEST_OS_ID ,0 ); -kvm_msr_entry_set (&msrs[n++],HV_X64_MSR_HYPERCALL ,0 ); +if (has_msr_hv_hypercall) { +kvm_msr_entry_set (&msrs[n++],HV_X64_MSR_GUEST_OS_ID , + env->msr_hv_guest_os_id); +kvm_msr_entry_set (&msrs[n++],HV_X64_MSR_HYPERCALL , + env->msr_hv_hypercall); } -if (cpu->hyperv_vapic) { -kvm_msr_entry_set (&msrs[n++],HV_X64_MSR_APIC_ASSIST_PAGE ,0 ); +if (has_msr_hv_vapic) { +kvm_msr_entry_set (&msrs[n++],HV_X64_MSR_APIC_ASSIST_PAGE , + env->msr_hv_vapic); }if (has_msr_feature_control) { kvm_msr_entry_set(&msrs[n++], MSR_IA32_FEATURE_CONTROL,
@@ -1470,6 +1473,14 @@ static int kvm_get_msrs(X86CPU *cpu) } } +if (has_msr_hv_hypercall) { + msrs[n++].index =HV_X64_MSR_HYPERCALL ; + msrs[n++].index =HV_X64_MSR_GUEST_OS_ID ; + } +if (has_msr_hv_vapic) { + msrs[n++].index =HV_X64_MSR_APIC_ASSIST_PAGE ; + } + msr_data.info.nmsrs = n; ret =kvm_vcpu_ioctl (CPU (cpu),KVM_GET_MSRS , &msr_data);if (ret <0 ) {
@@ -1574,6 +1585,15 @@ static int kvm_get_msrs(X86CPU *cpu) case MSR_P6_EVNTSEL0 ... MSR_P6_EVNTSEL0 + MAX_GP_COUNTERS - 1: env->msr_gp_evtsel[index -MSR_P6_EVNTSEL0 ] = msrs[i].data;break ; +case HV_X64_MSR_HYPERCALL : + env->msr_hv_hypercall = msrs[i].data; +break ; +case HV_X64_MSR_GUEST_OS_ID : + env->msr_hv_guest_os_id = msrs[i].data; +break ; +case HV_X64_MSR_APIC_ASSIST_PAGE : + env->msr_hv_vapic = msrs[i].data; +break ; } }
target-i386/machine.c +24 -0
@@ -506,6 +506,27 @@ static const VMStateDescription vmstate_msr_architectural_pmu = { } }; +static bool hyperv_enable_needed (void *opaque) +{ +X86CPU *cpu = opaque; +CPUX86State *env = &cpu->env; + +return env->msr_hv_hypercall !=0 ; +} + +static const VMStateDescription vmstate_msr_hyperv = { + .name ="cpu/msr_hyperv" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_UINT64 (env.msr_hv_hypercall,X86CPU ), +VMSTATE_UINT64 (env.msr_hv_guest_os_id,X86CPU ), +VMSTATE_UINT64 (env.msr_hv_vapic,X86CPU ), +VMSTATE_END_OF_LIST () + } +}; +const VMStateDescription vmstate_x86_cpu = { .name ="cpu" , .version_id =12 ,
@@ -637,6 +658,9 @@ const VMStateDescription vmstate_x86_cpu = { }, { .vmsd = &vmstate_msr_architectural_pmu, .needed = pmu_enable_needed, + }, { + .vmsd = &vmstate_msr_hyperv, + .needed = hyperv_enable_needed, } , { /* empty */ }
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 2/3] make hyperv hypercall, vapic, and os id MSRs migratable
Il 21/01/2014 09:02, Vadim Rozenfeld ha scritto:
Quoted 35 lines
Signed-off-by Vadim Rozenfeld <[email protected]>--- target-i386/cpu.h | 4 ++++ target-i386/kvm.c | 30 +++++++++++++++++++++++++----- target-i386/machine.c | 24 ++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 5 deletions(-)target-i386/cpu.h +4
-0@@ -847,6 +847,10 @@ typedef struct CPUX86State {uint64_t msr_gp_counters[MAX_GP_COUNTERS ];uint64_t msr_gp_evtsel[MAX_GP_COUNTERS ]; +uint64_t msr_hv_hypercall; +uint64_t msr_hv_guest_os_id; +uint64_t msr_hv_vapic; +/* exception/interrupt handling */ int error_code;int exception_is_int;target-i386/kvm.c +2
-3@@ -1185,12 +1185,15 @@ static int kvm_put_msrs(X86CPU *cpu, int level)kvm_msr_entry_set (&msrs[n++],MSR_CORE_PERF_GLOBAL_CTRL , env->msr_global_ctrl); } -if (hyperv_hypercall_available (cpu)) { -kvm_msr_entry_set (&msrs[n++],HV_X64_MSR_GUEST_OS_ID ,0 ); -kvm_msr_entry_set (&msrs[n++],HV_X64_MSR_HYPERCALL ,0 ); +if (has_msr_hv_hypercall) { + kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_GUEST_OS_ID,
target-i386/kvm.c static int kvm_put_msrs(X86CPU *cpu, int level) · line 1197
Quoted 10 lines
target-i386/kvm.c +6
-2+ env->msr_hv_guest_os_id); +kvm_msr_entry_set (&msrs[n++],HV_X64_MSR_HYPERCALL , + env->msr_hv_hypercall); } -if (cpu->hyperv_vapic) { -kvm_msr_entry_set (&msrs[n++],HV_X64_MSR_APIC_ASSIST_PAGE ,0 ); +if (has_msr_hv_vapic) { +kvm_msr_entry_set (&msrs[n++],HV_X64_MSR_APIC_ASSIST_PAGE , + env->msr_hv_vapic); }
Changing the "if" condition should go in (one of the patches split out of) the previous patch.
Quoted 38 lines
target-i386/kvm.c +17
-0if (has_msr_feature_control) { kvm_msr_entry_set(&msrs[n++], MSR_IA32_FEATURE_CONTROL,@@ -1470,6 +1473,14 @@ static int kvm_get_msrs(X86CPU *cpu) } } +if (has_msr_hv_hypercall) { + msrs[n++].index =HV_X64_MSR_HYPERCALL ; + msrs[n++].index =HV_X64_MSR_GUEST_OS_ID ; + } +if (has_msr_hv_vapic) { + msrs[n++].index =HV_X64_MSR_APIC_ASSIST_PAGE ; + } + msr_data.info.nmsrs = n; ret =kvm_vcpu_ioctl (CPU (cpu),KVM_GET_MSRS , &msr_data);if (ret <0 ) {@@ -1574,6 +1585,15 @@ static int kvm_get_msrs(X86CPU *cpu) case MSR_P6_EVNTSEL0 ... MSR_P6_EVNTSEL0 + MAX_GP_COUNTERS - 1: env->msr_gp_evtsel[index -MSR_P6_EVNTSEL0 ] = msrs[i].data;break ; +case HV_X64_MSR_HYPERCALL : + env->msr_hv_hypercall = msrs[i].data; +break ; +case HV_X64_MSR_GUEST_OS_ID : + env->msr_hv_guest_os_id = msrs[i].data; +break ; +case HV_X64_MSR_APIC_ASSIST_PAGE : + env->msr_hv_vapic = msrs[i].data; +break ; } }target-i386/machine.c +0
-0
target-i386/machine.c static const VMStateDescription vmstate_msr_architectural_pmu = { · line 514
Quoted 9 lines
target-i386/machine.c +6
-0@@ -506,6 +506,27 @@ static const VMStateDescription vmstate_msr_architectural_pmu = { } }; +static bool hyperv_enable_needed (void *opaque) +{ +X86CPU *cpu = opaque; +CPUX86State *env = &cpu->env; + +return env->msr_hv_hypercall !=0 ;
I think you should test all three MSRs. It is theoretically possible that a guest OS writes the guest OS ID MSR first and the machine is migrated exactly after that write.
Paolo
Quoted 29 lines
target-i386/machine.c +18
-0+} + +static const VMStateDescription vmstate_msr_hyperv = { + .name ="cpu/msr_hyperv" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_UINT64 (env.msr_hv_hypercall,X86CPU ), +VMSTATE_UINT64 (env.msr_hv_guest_os_id,X86CPU ), +VMSTATE_UINT64 (env.msr_hv_vapic,X86CPU ), +VMSTATE_END_OF_LIST () + } +}; +const VMStateDescription vmstate_x86_cpu = { .name ="cpu" , .version_id =12 ,@@ -637,6 +658,9 @@ const VMStateDescription vmstate_x86_cpu = { }, { .vmsd = &vmstate_msr_architectural_pmu, .needed = pmu_enable_needed, + }, { + .vmsd = &vmstate_msr_hyperv, + .needed = hyperv_enable_needed, } , { /* empty */ }
PATCH 3/3 add support for hyperv time parameter
In reply to Vadim RozenfeldFrom: Vadim Rozenfeld <[email protected]>
--- linux-headers/asm-x86/hyperv.h | 3 +++ linux-headers/linux/kvm.h | 1 + target-i386/cpu-qom.h | 1 + target-i386/cpu.c | 1 + target-i386/cpu.h | 1 + target-i386/kvm.c | 19 +++++++++++++++++++ target-i386/machine.c | 1 + 7 files changed, 27 insertions(+)
linux-headers/asm-x86/hyperv.h +3 -0
@@ -149,6 +149,9 @@/* MSR used to read the per-partition time reference counter */ #define HV_X64_MSR_TIME_REF_COUNT 0x40000020 +/* A partition's reference time stamp counter (TSC) page */ +#define HV_X64_MSR_REFERENCE_TSC 0x40000021 +/* MSR used to retrieve the TSC frequency */ #define HV_X64_MSR_TSC_FREQUENCY 0x40000022
linux-headers/linux/kvm.h +1 -0
@@ -674,6 +674,7 @@ struct kvm_ppc_smmu_info {#define KVM_CAP_ARM_EL1_32BIT 93#define KVM_CAP_SPAPR_MULTITCE 94#define KVM_CAP_EXT_EMUL_CPUID 95 +#define KVM_CAP_HYPERV_TIME 96#ifdef KVM_CAP_IRQ_ROUTING
target-i386/cpu-qom.h +1 -0
@@ -69,6 +69,7 @@ typedef struct X86CPU {bool hyperv_vapic;bool hyperv_relaxed_timing;int hyperv_spinlock_attempts; +bool hyperv_time;bool check_cpuid;bool enforce_cpuid;
target-i386/cpu.c +1 -0
@@ -2744,6 +2744,7 @@ static Property x86_cpu_properties[] = { { .name = "hv-spinlocks", .info = &qdev_prop_spinlocks },DEFINE_PROP_BOOL ("hv-relaxed" ,X86CPU , hyperv_relaxed_timing, false),DEFINE_PROP_BOOL ("hv-vapic" ,X86CPU , hyperv_vapic, false), +DEFINE_PROP_BOOL ("hv-time" ,X86CPU , hyperv_time, false),DEFINE_PROP_BOOL ("check" ,X86CPU , check_cpuid, false),DEFINE_PROP_BOOL ("enforce" ,X86CPU , enforce_cpuid, false),DEFINE_PROP_END_OF_LIST ()
target-i386/cpu.h +1 -0
@@ -850,6 +850,7 @@ typedef struct CPUX86State {uint64_t msr_hv_hypercall;uint64_t msr_hv_guest_os_id;uint64_t msr_hv_vapic; +uint64_t msr_hv_tsc;/* exception/interrupt handling */ int error_code;
target-i386/kvm.c +19 -0
@@ -73,6 +73,7 @@ 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_architectural_pmu;static uint32_t num_architectural_pmu_counters;
@@ -433,6 +434,7 @@ unsigned long kvm_arch_vcpu_id(CPUState *cs)static bool hyperv_hypercall_available (X86CPU *cpu) {return cpu->hyperv_vapic || + cpu->hyperv_time || (cpu->hyperv_spinlock_attempts !=HYPERV_SPINLOCK_NEVER_RETRY ); }
@@ -492,6 +494,13 @@ int kvm_arch_init_vcpu(CPUState *cs) c->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 ) { + c->eax |=HV_X64_MSR_HYPERCALL_AVAILABLE ; + c->eax |=HV_X64_MSR_TIME_REF_COUNT_AVAILABLE ; + c->eax |=0x200 ; + has_msr_hv_tsc = true; + } c = &cpuid_data.entries[cpuid_i++]; c->function =HYPERV_CPUID_ENLIGHTMENT_INFO ;
@@ -1195,6 +1204,10 @@ static int kvm_put_msrs(X86CPU *cpu, int level)kvm_msr_entry_set (&msrs[n++],HV_X64_MSR_APIC_ASSIST_PAGE , env->msr_hv_vapic); } +if (has_msr_hv_tsc) { +kvm_msr_entry_set (&msrs[n++],HV_X64_MSR_REFERENCE_TSC , + env->msr_hv_tsc); + }if (has_msr_feature_control) {kvm_msr_entry_set (&msrs[n++],MSR_IA32_FEATURE_CONTROL , env->msr_ia32_feature_control);
@@ -1480,6 +1493,9 @@ static int kvm_get_msrs(X86CPU *cpu)if (has_msr_hv_vapic) { msrs[n++].index =HV_X64_MSR_APIC_ASSIST_PAGE ; } +if (has_msr_hv_tsc) { + msrs[n++].index =HV_X64_MSR_REFERENCE_TSC ; + } msr_data.info.nmsrs = n; ret =kvm_vcpu_ioctl (CPU (cpu),KVM_GET_MSRS , &msr_data);
@@ -1594,6 +1610,9 @@ static int kvm_get_msrs(X86CPU *cpu)case HV_X64_MSR_APIC_ASSIST_PAGE : env->msr_hv_vapic = msrs[i].data;break ; +case HV_X64_MSR_REFERENCE_TSC : + env->msr_hv_tsc = msrs[i].data; +break ; } }
target-i386/machine.c +1 -0
@@ -523,6 +523,7 @@ static const VMStateDescription vmstate_msr_hyperv = {VMSTATE_UINT64 (env.msr_hv_hypercall,X86CPU ),VMSTATE_UINT64 (env.msr_hv_guest_os_id,X86CPU ),VMSTATE_UINT64 (env.msr_hv_vapic,X86CPU ), +VMSTATE_UINT64 (env.msr_hv_tsc,X86CPU ), VMSTATE_END_OF_LIST() } };
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 3/3] add support for hyperv time parameter
Il 21/01/2014 09:02, Vadim Rozenfeld ha scritto:
Quoted 146 lines
From: Vadim Rozenfeld <[email protected]>
Signed-off-by Vadim Rozenfeld <[email protected]>--- linux-headers/asm-x86/hyperv.h | 3 +++ linux-headers/linux/kvm.h | 1 + target-i386/cpu-qom.h | 1 + target-i386/cpu.c | 1 + target-i386/cpu.h | 1 + target-i386/kvm.c | 19 +++++++++++++++++++ target-i386/machine.c | 1 + 7 files changed, 27 insertions(+)linux-headers/asm-x86/hyperv.h +3
-0@@ -149,6 +149,9 @@/* MSR used to read the per-partition time reference counter */ #define HV_X64_MSR_TIME_REF_COUNT 0x40000020 +/* A partition's reference time stamp counter (TSC) page */ +#define HV_X64_MSR_REFERENCE_TSC 0x40000021 +/* MSR used to retrieve the TSC frequency */ #define HV_X64_MSR_TSC_FREQUENCY 0x40000022linux-headers/linux/kvm.h +1
-0@@ -674,6 +674,7 @@ struct kvm_ppc_smmu_info {#define KVM_CAP_ARM_EL1_32BIT 93#define KVM_CAP_SPAPR_MULTITCE 94#define KVM_CAP_EXT_EMUL_CPUID 95 +#define KVM_CAP_HYPERV_TIME 96#ifdef KVM_CAP_IRQ_ROUTING target-i386/cpu-qom.h +1
-0@@ -69,6 +69,7 @@ typedef struct X86CPU {bool hyperv_vapic;bool hyperv_relaxed_timing;int hyperv_spinlock_attempts; +bool hyperv_time;bool check_cpuid;bool enforce_cpuid;target-i386/cpu.c +1
-0@@ -2744,6 +2744,7 @@ static Property x86_cpu_properties[] = { { .name = "hv-spinlocks", .info = &qdev_prop_spinlocks },DEFINE_PROP_BOOL ("hv-relaxed" ,X86CPU , hyperv_relaxed_timing, false),DEFINE_PROP_BOOL ("hv-vapic" ,X86CPU , hyperv_vapic, false), +DEFINE_PROP_BOOL ("hv-time" ,X86CPU , hyperv_time, false),DEFINE_PROP_BOOL ("check" ,X86CPU , check_cpuid, false),DEFINE_PROP_BOOL ("enforce" ,X86CPU , enforce_cpuid, false),DEFINE_PROP_END_OF_LIST ()target-i386/cpu.h +1
-0@@ -850,6 +850,7 @@ typedef struct CPUX86State {uint64_t msr_hv_hypercall;uint64_t msr_hv_guest_os_id;uint64_t msr_hv_vapic; +uint64_t msr_hv_tsc;/* exception/interrupt handling */ int error_code;target-i386/kvm.c +19
-0@@ -73,6 +73,7 @@ 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_architectural_pmu;static uint32_t num_architectural_pmu_counters;@@ -433,6 +434,7 @@ unsigned long kvm_arch_vcpu_id(CPUState *cs)static bool hyperv_hypercall_available (X86CPU *cpu) {return cpu->hyperv_vapic || + cpu->hyperv_time || (cpu->hyperv_spinlock_attempts !=HYPERV_SPINLOCK_NEVER_RETRY ); }@@ -492,6 +494,13 @@ int kvm_arch_init_vcpu(CPUState *cs) c->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 ) { + c->eax |=HV_X64_MSR_HYPERCALL_AVAILABLE ; + c->eax |=HV_X64_MSR_TIME_REF_COUNT_AVAILABLE ; + c->eax |=0x200 ; + has_msr_hv_tsc = true; + } c = &cpuid_data.entries[cpuid_i++]; c->function =HYPERV_CPUID_ENLIGHTMENT_INFO ;@@ -1195,6 +1204,10 @@ static int kvm_put_msrs(X86CPU *cpu, int level)kvm_msr_entry_set (&msrs[n++],HV_X64_MSR_APIC_ASSIST_PAGE , env->msr_hv_vapic); } +if (has_msr_hv_tsc) { +kvm_msr_entry_set (&msrs[n++],HV_X64_MSR_REFERENCE_TSC , + env->msr_hv_tsc); + }if (has_msr_feature_control) {kvm_msr_entry_set (&msrs[n++],MSR_IA32_FEATURE_CONTROL , env->msr_ia32_feature_control);@@ -1480,6 +1493,9 @@ static int kvm_get_msrs(X86CPU *cpu)if (has_msr_hv_vapic) { msrs[n++].index =HV_X64_MSR_APIC_ASSIST_PAGE ; } +if (has_msr_hv_tsc) { + msrs[n++].index =HV_X64_MSR_REFERENCE_TSC ; + } msr_data.info.nmsrs = n; ret =kvm_vcpu_ioctl (CPU (cpu),KVM_GET_MSRS , &msr_data);@@ -1594,6 +1610,9 @@ static int kvm_get_msrs(X86CPU *cpu)case HV_X64_MSR_APIC_ASSIST_PAGE : env->msr_hv_vapic = msrs[i].data;break ; +case HV_X64_MSR_REFERENCE_TSC : + env->msr_hv_tsc = msrs[i].data; +break ; } }target-i386/machine.c +0
-0
target-i386/machine.c static const VMStateDescription vmstate_msr_hyperv = { · line 529
Quoted 7 lines
target-i386/machine.c +1
-0@@ -523,6 +523,7 @@ static const VMStateDescription vmstate_msr_hyperv = {VMSTATE_UINT64 (env.msr_hv_hypercall,X86CPU ),VMSTATE_UINT64 (env.msr_hv_guest_os_id,X86CPU ),VMSTATE_UINT64 (env.msr_hv_vapic,X86CPU ), +VMSTATE_UINT64 (env.msr_hv_tsc,X86CPU ), VMSTATE_END_OF_LIST() } };
If you are planning some level of backwards compatibility with RHEL6, it may make sense to use separate subsections.
Paolo
Re: [Qemu-devel] [PATCH 3/3] add support for hyperv time parameter
Quoted 141 lines · Paolo Bonzini
Il 21/01/2014 09:02, Vadim Rozenfeld ha scritto:
Quoted 140 lines
From: Vadim Rozenfeld <[email protected]>
Signed-off-by Vadim Rozenfeld <[email protected]>--- linux-headers/asm-x86/hyperv.h | 3 +++ linux-headers/linux/kvm.h | 1 + target-i386/cpu-qom.h | 1 + target-i386/cpu.c | 1 + target-i386/cpu.h | 1 + target-i386/kvm.c | 19 +++++++++++++++++++ target-i386/machine.c | 1 + 7 files changed, 27 insertions(+)linux-headers/asm-x86/hyperv.h +3
-0@@ -149,6 +149,9 @@/* MSR used to read the per-partition time reference counter */ #define HV_X64_MSR_TIME_REF_COUNT 0x40000020 +/* A partition's reference time stamp counter (TSC) page */ +#define HV_X64_MSR_REFERENCE_TSC 0x40000021 +/* MSR used to retrieve the TSC frequency */ #define HV_X64_MSR_TSC_FREQUENCY 0x40000022linux-headers/linux/kvm.h +1
-0@@ -674,6 +674,7 @@ struct kvm_ppc_smmu_info {#define KVM_CAP_ARM_EL1_32BIT 93#define KVM_CAP_SPAPR_MULTITCE 94#define KVM_CAP_EXT_EMUL_CPUID 95 +#define KVM_CAP_HYPERV_TIME 96#ifdef KVM_CAP_IRQ_ROUTING target-i386/cpu-qom.h +1
-0@@ -69,6 +69,7 @@ typedef struct X86CPU {bool hyperv_vapic;bool hyperv_relaxed_timing;int hyperv_spinlock_attempts; +bool hyperv_time;bool check_cpuid;bool enforce_cpuid;target-i386/cpu.c +1
-0@@ -2744,6 +2744,7 @@ static Property x86_cpu_properties[] = { { .name = "hv-spinlocks", .info = &qdev_prop_spinlocks },DEFINE_PROP_BOOL ("hv-relaxed" ,X86CPU , hyperv_relaxed_timing, false),DEFINE_PROP_BOOL ("hv-vapic" ,X86CPU , hyperv_vapic, false), +DEFINE_PROP_BOOL ("hv-time" ,X86CPU , hyperv_time, false),DEFINE_PROP_BOOL ("check" ,X86CPU , check_cpuid, false),DEFINE_PROP_BOOL ("enforce" ,X86CPU , enforce_cpuid, false),DEFINE_PROP_END_OF_LIST ()target-i386/cpu.h +1
-0@@ -850,6 +850,7 @@ typedef struct CPUX86State {uint64_t msr_hv_hypercall;uint64_t msr_hv_guest_os_id;uint64_t msr_hv_vapic; +uint64_t msr_hv_tsc;/* exception/interrupt handling */ int error_code;target-i386/kvm.c +19
-0@@ -73,6 +73,7 @@ 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_architectural_pmu;static uint32_t num_architectural_pmu_counters;@@ -433,6 +434,7 @@ unsigned long kvm_arch_vcpu_id(CPUState *cs)static bool hyperv_hypercall_available (X86CPU *cpu) {return cpu->hyperv_vapic || + cpu->hyperv_time || (cpu->hyperv_spinlock_attempts !=HYPERV_SPINLOCK_NEVER_RETRY ); }@@ -492,6 +494,13 @@ int kvm_arch_init_vcpu(CPUState *cs) c->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 ) { + c->eax |=HV_X64_MSR_HYPERCALL_AVAILABLE ; + c->eax |=HV_X64_MSR_TIME_REF_COUNT_AVAILABLE ; + c->eax |=0x200 ; + has_msr_hv_tsc = true; + } c = &cpuid_data.entries[cpuid_i++]; c->function =HYPERV_CPUID_ENLIGHTMENT_INFO ;@@ -1195,6 +1204,10 @@ static int kvm_put_msrs(X86CPU *cpu, int level)kvm_msr_entry_set (&msrs[n++],HV_X64_MSR_APIC_ASSIST_PAGE , env->msr_hv_vapic); } +if (has_msr_hv_tsc) { +kvm_msr_entry_set (&msrs[n++],HV_X64_MSR_REFERENCE_TSC , + env->msr_hv_tsc); + }if (has_msr_feature_control) {kvm_msr_entry_set (&msrs[n++],MSR_IA32_FEATURE_CONTROL , env->msr_ia32_feature_control);@@ -1480,6 +1493,9 @@ static int kvm_get_msrs(X86CPU *cpu)if (has_msr_hv_vapic) { msrs[n++].index =HV_X64_MSR_APIC_ASSIST_PAGE ; } +if (has_msr_hv_tsc) { + msrs[n++].index =HV_X64_MSR_REFERENCE_TSC ; + } msr_data.info.nmsrs = n; ret =kvm_vcpu_ioctl (CPU (cpu),KVM_GET_MSRS , &msr_data);@@ -1594,6 +1610,9 @@ static int kvm_get_msrs(X86CPU *cpu)case HV_X64_MSR_APIC_ASSIST_PAGE : env->msr_hv_vapic = msrs[i].data;break ; +case HV_X64_MSR_REFERENCE_TSC : + env->msr_hv_tsc = msrs[i].data; +break ; } }
Quoted 16 lines
target-i386/machine.c static const VMStateDescription vmstate_msr_hyperv = { · line 529
Quoted 13 lines
target-i386/machine.c +1
-0@@ -523,6 +523,7 @@ static const VMStateDescription vmstate_msr_hyperv = {VMSTATE_UINT64 (env.msr_hv_hypercall,X86CPU ),VMSTATE_UINT64 (env.msr_hv_guest_os_id,X86CPU ),VMSTATE_UINT64 (env.msr_hv_vapic,X86CPU ), +VMSTATE_UINT64 (env.msr_hv_tsc,X86CPU ), VMSTATE_END_OF_LIST() } };If you are planning some level of backwards compatibility with RHEL6, it may make sense to use separate subsections.
I believe we have to make it backward compatible. In RHEL6 we added support for relaxed timers only, but upstream doesn't have such bits. Technically, hypercall page, vapic and iTSC pages will be introduced in RHEL7 and as you said, they will probably go to a different, new section, but for upstream the entire section is absolutely new.
Vadim.
Quoted 3 lines
Paolo
Re: [Qemu-devel] [PATCH 3/3] add support for hyperv time parameter
Il 21/01/2014 22:12, Vadim Rozenfeld ha scritto:
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
If you are planning some level of backwards compatibility with RHEL6, it may make sense to use separate subsections.
I believe we have to make it backward compatible. In RHEL6 we added support for relaxed timers only, but upstream doesn't have such bits. Technically, hypercall page, vapic and iTSC pages will be introduced in RHEL7 and as you said, they will probably go to a different, new section, but for upstream the entire section is absolutely new.
Ok, then upstream we have choice. Using 2 subsections is not wrong, and it makes sense since it's covered by different kernel capabilities.
Paolo