[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 5/7] make hyperv hypercall and guest os id MSRs m
From: |
Vadim Rozenfeld |
Subject: |
[Qemu-devel] [PATCH v2 5/7] make hyperv hypercall and guest os id MSRs migratable. |
Date: |
Fri, 24 Jan 2014 00:40:47 +1100 |
Signed-off-by: Vadim Rozenfeld <address@hidden>
---
target-i386/cpu.h | 2 ++
target-i386/kvm.c | 25 ++++++++++++++++++++-----
target-i386/machine.c | 23 +++++++++++++++++++++++
3 files changed, 45 insertions(+), 5 deletions(-)
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 1d94a9d..3bfaf87 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -846,6 +846,8 @@ typedef struct CPUX86State {
uint64_t msr_fixed_counters[MAX_FIXED_COUNTERS];
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;
/* exception/interrupt handling */
int error_code;
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index c1bc8c0..48a747e 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -71,6 +71,7 @@ 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_architectural_pmu;
static uint32_t num_architectural_pmu_counters;
@@ -464,8 +465,10 @@ int kvm_arch_init_vcpu(CPUState *cs)
c = &cpuid_data.entries[cpuid_i++];
c->function = KVM_CPUID_SIGNATURE;
memcpy(signature, "KVMKVMKVM\0\0\0", 12);
- if (hyperv_enabled(cpu)) {
+ if (hyperv_enabled(cpu) &&
+ kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV) > 0) {
c->eax = HYPERV_CPUID_MIN;
+ has_msr_hv_hypercall = true;
}
c->ebx = signature[0];
c->ecx = signature[1];
@@ -475,7 +478,7 @@ int kvm_arch_init_vcpu(CPUState *cs)
c->function = KVM_CPUID_FEATURES;
c->eax = env->features[FEAT_KVM];
- if (hyperv_enabled(cpu)) {
+ if (has_msr_hv_hypercall) {
memcpy(signature, "Hv#1\0\0\0\0\0\0\0\0", 12);
c->eax = signature[0];
@@ -1176,9 +1179,11 @@ 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);
@@ -1461,6 +1466,10 @@ 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;
+ }
msr_data.info.nmsrs = n;
ret = kvm_vcpu_ioctl(CPU(cpu), KVM_GET_MSRS, &msr_data);
if (ret < 0) {
@@ -1565,6 +1574,12 @@ 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;
}
}
diff --git a/target-i386/machine.c b/target-i386/machine.c
index e568da2..3809d06 100644
--- a/target-i386/machine.c
+++ b/target-i386/machine.c
@@ -506,6 +506,26 @@ static const VMStateDescription
vmstate_msr_architectural_pmu = {
}
};
+static bool hyperv_hypercall_enable_needed(void *opaque)
+{
+ X86CPU *cpu = opaque;
+ CPUX86State *env = &cpu->env;
+
+ return env->msr_hv_hypercall != 0 || env->msr_hv_guest_os_id != 0;
+}
+
+static const VMStateDescription vmstate_msr_hypercall_hypercall = {
+ .name = "cpu/msr_hyperv_hypercall",
+ .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_END_OF_LIST()
+ }
+};
+
const VMStateDescription vmstate_x86_cpu = {
.name = "cpu",
.version_id = 12,
@@ -637,6 +657,9 @@ const VMStateDescription vmstate_x86_cpu = {
}, {
.vmsd = &vmstate_msr_architectural_pmu,
.needed = pmu_enable_needed,
+ }, {
+ .vmsd = &vmstate_msr_hypercall_hypercall,
+ .needed = hyperv_hypercall_enable_needed,
} , {
/* empty */
}
--
1.8.1.4
- [Qemu-devel] [PATCH v2 0/7] Hyper-V parameters update, Vadim Rozenfeld, 2014/01/23
- [Qemu-devel] [PATCH v2 1/7] Don't report "Microsoft" as the vendor ID signature., Vadim Rozenfeld, 2014/01/23
- [Qemu-devel] [PATCH v2 2/7] Don't specify hypervisor system identity, Vadim Rozenfeld, 2014/01/23
- [Qemu-devel] [PATCH v2 3/7] Don't specify implementation limits, Vadim Rozenfeld, 2014/01/23
- [Qemu-devel] [PATCH v2 4/7] Don't report the KVM signature twice, since it's already reported in KVM_CPUID_SIGNATURE CPUID leaf., Vadim Rozenfeld, 2014/01/23
- [Qemu-devel] [PATCH v2 5/7] make hyperv hypercall and guest os id MSRs migratable.,
Vadim Rozenfeld <=
- [Qemu-devel] [PATCH v2 6/7] make hyperv vapic assist page migratable, Vadim Rozenfeld, 2014/01/23
- [Qemu-devel] [PATCH v2 7/7] add support for hyper-v timers http://msdn.microsoft.com/en-us/library/windows/hardware/ff541625%28v=vs.85%29.aspx This code is generic for activating reference time counter or virtual reference time stamp counter, Vadim Rozenfeld, 2014/01/23
- Re: [Qemu-devel] [PATCH v2 0/7] Hyper-V parameters update, Paolo Bonzini, 2014/01/23