cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-make-hyperv-hypercall-and-guest-os-id-MSRs-migra.patch

0a122b
From ab03fc7dbf876e611f43be34faa6945728977056 Mon Sep 17 00:00:00 2001
0a122b
From: Vadim Rozenfeld <vrozenfe@redhat.com>
0a122b
Date: Mon, 3 Mar 2014 12:09:17 +0100
0a122b
Subject: [PATCH 05/12] kvm: make hyperv hypercall and guest os id MSRs migratable.
0a122b
0a122b
RH-Author: Vadim Rozenfeld <vrozenfe@redhat.com>
0a122b
Message-id: <1393848564-10511-6-git-send-email-vrozenfe@redhat.com>
0a122b
Patchwork-id: 57961
0a122b
O-Subject: [RHEL-7.0 qemu-kvm v4 PATCH 05/12] kvm: make hyperv hypercall and guest os id MSRs migratable.
0a122b
Bugzilla: 1004773
0a122b
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
0a122b
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
0a122b
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
0a122b
RH-Acked-by: Juan Quintela <quintela@redhat.com>
0a122b
0a122b
Note: The field order in vmstate_msr_hypercall_hypercall follows the same
0a122b
      pattern as in RHEL6, but not upstream.
0a122b
0a122b
Signed-off-by: Vadim Rozenfeld <vrozenfe@redhat.com>
0a122b
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
0a122b
(cherry picked from commit 1c90ef2619dd6e5c4fec7e9e18c04c0a08e93aac)
0a122b
0a122b
Conflicts:
0a122b
	target-i386/machine.c
0a122b
---
0a122b
 target-i386/cpu.h     |  2 ++
0a122b
 target-i386/kvm.c     | 16 ++++++++++++++--
0a122b
 target-i386/machine.c | 23 +++++++++++++++++++++++
0a122b
 3 files changed, 39 insertions(+), 2 deletions(-)
0a122b
0a122b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
0a122b
---
0a122b
 target-i386/cpu.h     |    2 ++
0a122b
 target-i386/kvm.c     |   16 ++++++++++++++--
0a122b
 target-i386/machine.c |   23 +++++++++++++++++++++++
0a122b
 3 files changed, 39 insertions(+), 2 deletions(-)
0a122b
0a122b
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
0a122b
index 4c4c9ff..4835a64 100644
0a122b
--- a/target-i386/cpu.h
0a122b
+++ b/target-i386/cpu.h
0a122b
@@ -844,6 +844,8 @@ typedef struct CPUX86State {
0a122b
     uint64_t msr_fixed_counters[MAX_FIXED_COUNTERS];
0a122b
     uint64_t msr_gp_counters[MAX_GP_COUNTERS];
0a122b
     uint64_t msr_gp_evtsel[MAX_GP_COUNTERS];
0a122b
+    uint64_t msr_hv_hypercall;
0a122b
+    uint64_t msr_hv_guest_os_id;
0a122b
 
0a122b
     /* exception/interrupt handling */
0a122b
     int error_code;
0a122b
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
0a122b
index 495021b..943abe1 100644
0a122b
--- a/target-i386/kvm.c
0a122b
+++ b/target-i386/kvm.c
0a122b
@@ -1198,8 +1198,10 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
0a122b
                               env->msr_global_ctrl);
0a122b
         }
0a122b
         if (has_msr_hv_hypercall) {
0a122b
-            kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_GUEST_OS_ID, 0);
0a122b
-            kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_HYPERCALL, 0);
0a122b
+            kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_GUEST_OS_ID,
0a122b
+                              env->msr_hv_guest_os_id);
0a122b
+            kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_HYPERCALL,
0a122b
+                              env->msr_hv_hypercall);
0a122b
         }
0a122b
         if (has_msr_hv_vapic) {
0a122b
             kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_APIC_ASSIST_PAGE, 0);
0a122b
@@ -1475,6 +1477,10 @@ static int kvm_get_msrs(X86CPU *cpu)
0a122b
         }
0a122b
     }
0a122b
 
0a122b
+    if (has_msr_hv_hypercall) {
0a122b
+        msrs[n++].index = HV_X64_MSR_HYPERCALL;
0a122b
+        msrs[n++].index = HV_X64_MSR_GUEST_OS_ID;
0a122b
+    }
0a122b
     msr_data.info.nmsrs = n;
0a122b
     ret = kvm_vcpu_ioctl(CPU(cpu), KVM_GET_MSRS, &msr_data);
0a122b
     if (ret < 0) {
0a122b
@@ -1576,6 +1582,12 @@ static int kvm_get_msrs(X86CPU *cpu)
0a122b
         case MSR_P6_EVNTSEL0 ... MSR_P6_EVNTSEL0 + MAX_GP_COUNTERS - 1:
0a122b
             env->msr_gp_evtsel[index - MSR_P6_EVNTSEL0] = msrs[i].data;
0a122b
             break;
0a122b
+        case HV_X64_MSR_HYPERCALL:
0a122b
+            env->msr_hv_hypercall = msrs[i].data;
0a122b
+            break;
0a122b
+        case HV_X64_MSR_GUEST_OS_ID:
0a122b
+            env->msr_hv_guest_os_id = msrs[i].data;
0a122b
+            break;
0a122b
         }
0a122b
     }
0a122b
 
0a122b
diff --git a/target-i386/machine.c b/target-i386/machine.c
0a122b
index 08b4ed3..817f8e4 100644
0a122b
--- a/target-i386/machine.c
0a122b
+++ b/target-i386/machine.c
0a122b
@@ -506,6 +506,26 @@ static const VMStateDescription vmstate_msr_architectural_pmu = {
0a122b
     }
0a122b
 };
0a122b
 
0a122b
+static bool hyperv_hypercall_enable_needed(void *opaque)
0a122b
+{
0a122b
+    X86CPU *cpu = opaque;
0a122b
+    CPUX86State *env = &cpu->env;
0a122b
+
0a122b
+    return env->msr_hv_hypercall != 0 || env->msr_hv_guest_os_id != 0;
0a122b
+}
0a122b
+
0a122b
+static const VMStateDescription vmstate_msr_hypercall_hypercall = {
0a122b
+    .name = "cpu/msr_hyperv_hypercall",
0a122b
+    .version_id = 1,
0a122b
+    .minimum_version_id = 1,
0a122b
+    .minimum_version_id_old = 1,
0a122b
+    .fields      = (VMStateField []) {
0a122b
+        VMSTATE_UINT64(env.msr_hv_guest_os_id, X86CPU),
0a122b
+        VMSTATE_UINT64(env.msr_hv_hypercall, X86CPU),
0a122b
+        VMSTATE_END_OF_LIST()
0a122b
+    }
0a122b
+};
0a122b
+
0a122b
 const VMStateDescription vmstate_x86_cpu = {
0a122b
     .name = "cpu",
0a122b
     .version_id = 12,
0a122b
@@ -638,6 +658,9 @@ const VMStateDescription vmstate_x86_cpu = {
0a122b
             .vmsd = &vmstate_msr_architectural_pmu,
0a122b
             .needed = pmu_enable_needed,
0a122b
         }, {
0a122b
+            .vmsd = &vmstate_msr_hypercall_hypercall,
0a122b
+            .needed = hyperv_hypercall_enable_needed,
0a122b
+        } , {
0a122b
             /* empty */
0a122b
         }
0a122b
     }
0a122b
-- 
0a122b
1.7.1
0a122b