i386: Fix KVM_CAP_ADJUST_CLOCK capability check
PATCH 1/1 i386: Fix KVM_CAP_ADJUST_CLOCK capability check
KVM commit c68dc1b577ea ("KVM: x86: Report host tsc and realtime values in KVM_GET_CLOCK") broke migration of certain workloads, e.g. Win11 + WSL2 guest reboots immediately after migration. KVM, however, is not to blame this time. When KVM_CAP_ADJUST_CLOCK capability is checked, the result is all supported flags (which the above mentioned KVM commit enhanced) but kvm_has_adjust_clock_stable() wants it to be KVM_CLOCK_TSC_STABLE precisely. The result is that 'clock_is_reliable' is not set in vmstate and the saved clock reading is discarded in kvmclock_vm_state_change().
--- target/i386/kvm/kvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/kvm/kvm.c +1 -1
@@ -157,7 +157,7 @@ bool kvm_has_adjust_clock_stable(void) {int ret =kvm_check_extension (kvm_state,KVM_CAP_ADJUST_CLOCK ); -return (ret ==KVM_CLOCK_TSC_STABLE ); +return ret &KVM_CLOCK_TSC_STABLE ; }bool kvm_has_adjust_clock (void )
Signature · 1 line
2.37.3
Quoted 32 lines · Vitaly Kuznetsov
KVM commit
c68dc1b577ea("KVM: x86: Report host tsc and realtime values inKVM_GET_CLOCK") broke migration of certain workloads, e.g. Win11 + WSL2 guest reboots immediately after migration. KVM, however, is not to blame this time. WhenKVM_CAP_ADJUST_CLOCKcapability is checked, the result is all supported flags (which the above mentioned KVM commit enhanced) butkvm_has_adjust_clock_stable()wants it to beKVM_CLOCK_TSC_STABLEprecisely. The result is that 'clock_is_reliable' is not set in vmstate and the saved clock reading is discarded inkvmclock_vm_state_change().Signed-off-by Vitaly Kuznetsov <[email protected]>--- target/i386/kvm/kvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/i386/kvm/kvm.c +1
-1@@ -157,7 +157,7 @@ bool kvm_has_adjust_clock_stable(void) {int ret =kvm_check_extension (kvm_state,KVM_CAP_ADJUST_CLOCK ); -return (ret ==KVM_CLOCK_TSC_STABLE ); +return ret &KVM_CLOCK_TSC_STABLE ; }bool kvm_has_adjust_clock (void )Signature · 1 line
2.37.3
ACK.
Quoted 20 lines · Vitaly Kuznetsov
KVM commit
c68dc1b577ea("KVM: x86: Report host tsc and realtime values inKVM_GET_CLOCK") broke migration of certain workloads, e.g. Win11 + WSL2 guest reboots immediately after migration. KVM, however, is not to blame this time. WhenKVM_CAP_ADJUST_CLOCKcapability is checked, the result is all supported flags (which the above mentioned KVM commit enhanced) butkvm_has_adjust_clock_stable()wants it to beKVM_CLOCK_TSC_STABLEprecisely. The result is that 'clock_is_reliable' is not set in vmstate and the saved clock reading is discarded inkvmclock_vm_state_change().Signed-off-by Vitaly Kuznetsov <[email protected]>--- target/i386/kvm/kvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/i386/kvm/kvm.c +0
-0
target/i386/kvm/kvm.c bool kvm_has_adjust_clock_stable(void) · line 163
Quoted 8 lines
target/i386/kvm/kvm.c +1
-1@@ -157,7 +157,7 @@ bool kvm_has_adjust_clock_stable(void) {int ret =kvm_check_extension (kvm_state,KVM_CAP_ADJUST_CLOCK ); -return (ret ==KVM_CLOCK_TSC_STABLE ); +return ret &KVM_CLOCK_TSC_STABLE ; }bool kvm_has_adjust_clock (void )
Ping) This issue seems to introduce major migration issues with KVM >= v5.16
Signature · 1 line
Vitaly
Quoted 25 lines · Vitaly Kuznetsov
Quoted 23 lines · Vitaly Kuznetsov
KVM commit
c68dc1b577ea("KVM: x86: Report host tsc and realtime values inKVM_GET_CLOCK") broke migration of certain workloads, e.g. Win11 + WSL2 guest reboots immediately after migration. KVM, however, is not to blame this time. WhenKVM_CAP_ADJUST_CLOCKcapability is checked, the result is all supported flags (which the above mentioned KVM commit enhanced) butkvm_has_adjust_clock_stable()wants it to beKVM_CLOCK_TSC_STABLEprecisely. The result is that 'clock_is_reliable' is not set in vmstate and the saved clock reading is discarded inkvmclock_vm_state_change().Signed-off-by Vitaly Kuznetsov <[email protected]>--- target/i386/kvm/kvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/i386/kvm/kvm.c +0
-0@@ -157,7 +157,7 @@ bool kvm_has_adjust_clock_stable(void) {int ret =kvm_check_extension (kvm_state,KVM_CAP_ADJUST_CLOCK );
Quoted 7 lines
target/i386/kvm/kvm.c bool kvm_has_adjust_clock_stable(void) · line 163
Quoted 5 lines
target/i386/kvm/kvm.c +1
-1-return (ret ==KVM_CLOCK_TSC_STABLE ); +return ret &KVM_CLOCK_TSC_STABLE ; }bool kvm_has_adjust_clock (void )Ping) This issue seems to introduce major migration issues with KVM >= v5.16
Ping)
Signature · 1 line
Vitaly
Hi, a similar patch is now in.
Paolo
Il ven 7 ott 2022, 05:26 Vitaly Kuznetsov <[email protected]> ha scritto:
Quoted 43 lines
Quoted 3 lines · Vitaly Kuznetsov
Quoted 1 line · Vitaly Kuznetsov
KVM commit
c68dc1b577ea("KVM: x86: Report host tsc and realtime valuesin
Quoted 22 lines
Quoted 22 lines
KVM_GET_CLOCK") broke migration of certain workloads, e.g. Win11 + WSL2 guest reboots immediately after migration. KVM, however, is not to blame this time. WhenKVM_CAP_ADJUST_CLOCKcapability is checked, the result is all supported flags (which the above mentioned KVM commit enhanced) butkvm_has_adjust_clock_stable()wants it to beKVM_CLOCK_TSC_STABLEprecisely. The result is that 'clock_is_reliable' is not set in vmstate and the saved clock reading is discarded inkvmclock_vm_state_change().Signed-off-by Vitaly Kuznetsov <[email protected]>--- target/i386/kvm/kvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/i386/kvm/kvm.c +0
-0@@ -157,7 +157,7 @@ bool kvm_has_adjust_clock_stable(void) {int ret =kvm_check_extension (kvm_state,KVM_CAP_ADJUST_CLOCK );Quoted 7 lines
target/i386/kvm/kvm.c bool kvm_has_adjust_clock_stable(void) · line 163
Quoted 5 lines
target/i386/kvm/kvm.c +1
-1-return (ret ==KVM_CLOCK_TSC_STABLE ); +return ret &KVM_CLOCK_TSC_STABLE ; }bool kvm_has_adjust_clock (void )Ping) This issue seems to introduce major migration issues with KVM >=
v5.16
Ping)
--
Vitaly
Quoted 2 lines · Paolo Bonzini
Hi, a similar patch is now in.
Indeed,
commit c4ef867f2949bf2a2ae18a4e27cf1a34bbc8aecb
Author: Ray Zhang <[email protected]> Date: Thu Sep 22 18:05:23 2022 +0800
target/i386/kvm: fix kvmclock_current_nsec: Assertion `time.tsc_timestamp <= migration_tsc' failed
solves the problem as well.
Signature · 1 line
Vitaly