qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 16/23] hyperv: map overlay pages after updating msrs


From: Roman Kagan
Subject: [Qemu-devel] [PATCH 16/23] hyperv: map overlay pages after updating msrs
Date: Tue, 6 Jun 2017 21:19:41 +0300

There is a design flaw in the Hyper-V SynIC implementation in KVM: when
message page or event flags page is enabled by setting the corresponding
msr, KVM zeroes it out.  This violates the spec in general (per spec,
the pages have to be overlay ones and only zeroed at cpu reset), but
it's non-fatal in normal operation because the user exit happens after
the page is zeroed, so it's the underlying guest page which is zeroed
out, and sane guests don't depend on its contents to be preserved while
it's overlaid.

However, in the case of vmstate load the overlay pages are set up before
msrs are set so the contents of those pages get lost.

To work it around, avoid setting up overlay pages in .post_load.
Instead, postpone it until after the msrs are pushed to KVM.  As a
result, KVM just zeroes out the underlying guest pages similar to how it
happens during guest-initiated msr writes, which is tolerable.

Signed-off-by: Roman Kagan <address@hidden>
---
 target/i386/kvm.c     | 8 ++++++++
 target/i386/machine.c | 9 ---------
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/target/i386/kvm.c b/target/i386/kvm.c
index 433c912..b0b7595 100644
--- a/target/i386/kvm.c
+++ b/target/i386/kvm.c
@@ -2761,6 +2761,14 @@ int kvm_arch_put_registers(CPUState *cpu, int level)
             return ret;
         }
     }
+    /*
+     * to work around buggy KVM which zeroes out the message and event pages in
+     * KVM_SET_MSRS handler, only map the overlay pages after kvm_put_msrs,
+     * making vmstate load work similar to guest-initiated set_msr
+     */
+    if (level >= KVM_PUT_RESET_STATE) {
+        hyperv_synic_update(x86_cpu);
+    }
 
     ret = kvm_put_tscdeadline_msr(x86_cpu);
     if (ret < 0) {
diff --git a/target/i386/machine.c b/target/i386/machine.c
index 8022c24..eb00b19 100644
--- a/target/i386/machine.c
+++ b/target/i386/machine.c
@@ -7,7 +7,6 @@
 #include "hw/i386/pc.h"
 #include "hw/isa/isa.h"
 #include "migration/cpu.h"
-#include "hyperv.h"
 
 #include "sysemu/kvm.h"
 
@@ -634,19 +633,11 @@ static bool hyperv_synic_enable_needed(void *opaque)
     return false;
 }
 
-static int hyperv_synic_post_load(void *opaque, int version_id)
-{
-    X86CPU *cpu = opaque;
-    hyperv_synic_update(cpu);
-    return 0;
-}
-
 static const VMStateDescription vmstate_msr_hyperv_synic = {
     .name = "cpu/msr_hyperv_synic",
     .version_id = 1,
     .minimum_version_id = 1,
     .needed = hyperv_synic_enable_needed,
-    .post_load = hyperv_synic_post_load,
     .fields = (VMStateField[]) {
         VMSTATE_UINT64(env.msr_hv_synic_control, X86CPU),
         VMSTATE_UINT64(env.msr_hv_synic_evt_page, X86CPU),
-- 
2.9.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]