diff mbox series

[RFC,23/26] target/i386: Re-sync kvm-clock after confidential guest migration

Message ID 20210302204822.81901-24-dovmurik@linux.vnet.ibm.com (mailing list archive)
State New, archived
Headers show
Series Confidential guest live migration | expand

Commit Message

Dov Murik March 2, 2021, 8:48 p.m. UTC
If confidential guest support is active, set TSC to 0 on the target when
loading the CPU state.  This causes the guest OS to re-sync with
kvm-clock.

Without this change, the guest clocks after migration are stuck (don't
advance), except the *_COARSE clocks which advance normally.

Signed-off-by: Dov Murik <dovmurik@linux.vnet.ibm.com>
---
 target/i386/machine.c | 9 +++++++++
 1 file changed, 9 insertions(+)
diff mbox series

Patch

diff --git a/target/i386/machine.c b/target/i386/machine.c
index 3768a753af..36c52ec02e 100644
--- a/target/i386/machine.c
+++ b/target/i386/machine.c
@@ -297,8 +297,17 @@  static int cpu_post_load(void *opaque, int version_id)
     X86CPU *cpu = opaque;
     CPUState *cs = CPU(cpu);
     CPUX86State *env = &cpu->env;
+    MachineState *ms = MACHINE(qdev_get_machine());
     int i;
 
+    /*
+     * When loading the state of a confidential guest, set TSC to zero at allow
+     * the guest OS to re-sync with kvmclock.
+     */
+    if (ms->cgs) {
+        env->tsc = 0;
+    }
+
     if (env->tsc_khz && env->user_tsc_khz &&
         env->tsc_khz != env->user_tsc_khz) {
         error_report("Mismatch between user-specified TSC frequency and "