qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Vadim Rozenfeld <vrozenfe@redhat.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, mtosatti@redhat.com, pl@dlhnet.de,
	Vadim Rozenfeld <vrozenfe@redhat.com>,
	aliguori@amazon.com
Subject: [Qemu-devel] [PATCH 2/3] make hyperv hypercall, vapic, and os id MSRs migratable
Date: Tue, 21 Jan 2014 19:02:46 +1100	[thread overview]
Message-ID: <1390291367-21958-3-git-send-email-vrozenfe@redhat.com> (raw)
In-Reply-To: <1390291367-21958-1-git-send-email-vrozenfe@redhat.com>

Signed-off-by: Vadim Rozenfeld <vrozenfe@redhat.com>
---
 target-i386/cpu.h     |  4 ++++
 target-i386/kvm.c     | 30 +++++++++++++++++++++++++-----
 target-i386/machine.c | 24 ++++++++++++++++++++++++
 3 files changed, 53 insertions(+), 5 deletions(-)

diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 1d94a9d..6eeafdc 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -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;
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 768ca1d..5152e64 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -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;
         }
     }
 
diff --git a/target-i386/machine.c b/target-i386/machine.c
index e568da2..58c5b45 100644
--- a/target-i386/machine.c
+++ b/target-i386/machine.c
@@ -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 */
         }
-- 
1.8.3.1

  parent reply	other threads:[~2014-01-21  8:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-21  8:02 [Qemu-devel] [PATCH 0/3] Hyper-V parameters Vadim Rozenfeld
2014-01-21  8:02 ` [Qemu-devel] [PATCH 1/3] cleanup hyper-v interface initialization Vadim Rozenfeld
2014-01-21 10:14   ` Paolo Bonzini
2014-01-21  8:02 ` Vadim Rozenfeld [this message]
2014-01-21 10:17   ` [Qemu-devel] [PATCH 2/3] make hyperv hypercall, vapic, and os id MSRs migratable Paolo Bonzini
2014-01-21  8:02 ` [Qemu-devel] [PATCH 3/3] add support for hyperv time parameter Vadim Rozenfeld
2014-01-21 10:21   ` Paolo Bonzini
2014-01-21 21:12     ` Vadim Rozenfeld
2014-01-22 10:02       ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1390291367-21958-3-git-send-email-vrozenfe@redhat.com \
    --to=vrozenfe@redhat.com \
    --cc=aliguori@amazon.com \
    --cc=mtosatti@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=pl@dlhnet.de \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).