qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i386: Fix KVM_CAP_ADJUST_CLOCK capability check
@ 2022-09-20 14:40 Vitaly Kuznetsov
  2022-09-20 18:33 ` Marcelo Tosatti
  2022-09-27  9:45 ` Vitaly Kuznetsov
  0 siblings, 2 replies; 6+ messages in thread
From: Vitaly Kuznetsov @ 2022-09-20 14:40 UTC (permalink / raw)
  To: qemu-devel, Paolo Bonzini; +Cc: Marcelo Tosatti, Oliver Upton, Maxim Levitsky

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().

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 target/i386/kvm/kvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index a1fd1f53791d..c33192a87dcb 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -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)
-- 
2.37.3



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] i386: Fix KVM_CAP_ADJUST_CLOCK capability check
  2022-09-20 14:40 [PATCH] i386: Fix KVM_CAP_ADJUST_CLOCK capability check Vitaly Kuznetsov
@ 2022-09-20 18:33 ` Marcelo Tosatti
  2022-09-27  9:45 ` Vitaly Kuznetsov
  1 sibling, 0 replies; 6+ messages in thread
From: Marcelo Tosatti @ 2022-09-20 18:33 UTC (permalink / raw)
  To: Vitaly Kuznetsov; +Cc: qemu-devel, Paolo Bonzini, Oliver Upton, Maxim Levitsky

On Tue, Sep 20, 2022 at 04:40:24PM +0200, Vitaly Kuznetsov wrote:
> 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().
> 
> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> ---
>  target/i386/kvm/kvm.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
> index a1fd1f53791d..c33192a87dcb 100644
> --- a/target/i386/kvm/kvm.c
> +++ b/target/i386/kvm/kvm.c
> @@ -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)
> -- 
> 2.37.3
> 
> 

ACK.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] i386: Fix KVM_CAP_ADJUST_CLOCK capability check
  2022-09-20 14:40 [PATCH] i386: Fix KVM_CAP_ADJUST_CLOCK capability check Vitaly Kuznetsov
  2022-09-20 18:33 ` Marcelo Tosatti
@ 2022-09-27  9:45 ` Vitaly Kuznetsov
  2022-10-07  9:26   ` Vitaly Kuznetsov
  1 sibling, 1 reply; 6+ messages in thread
From: Vitaly Kuznetsov @ 2022-09-27  9:45 UTC (permalink / raw)
  To: qemu-devel, Paolo Bonzini; +Cc: Marcelo Tosatti, Oliver Upton, Maxim Levitsky

Vitaly Kuznetsov <vkuznets@redhat.com> writes:

> 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().
>
> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> ---
>  target/i386/kvm/kvm.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
> index a1fd1f53791d..c33192a87dcb 100644
> --- a/target/i386/kvm/kvm.c
> +++ b/target/i386/kvm/kvm.c
> @@ -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

-- 
Vitaly



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] i386: Fix KVM_CAP_ADJUST_CLOCK capability check
  2022-09-27  9:45 ` Vitaly Kuznetsov
@ 2022-10-07  9:26   ` Vitaly Kuznetsov
  2022-10-07 10:49     ` Paolo Bonzini
  0 siblings, 1 reply; 6+ messages in thread
From: Vitaly Kuznetsov @ 2022-10-07  9:26 UTC (permalink / raw)
  To: qemu-devel, Paolo Bonzini; +Cc: Marcelo Tosatti, Oliver Upton, Maxim Levitsky

Vitaly Kuznetsov <vkuznets@redhat.com> writes:

> Vitaly Kuznetsov <vkuznets@redhat.com> writes:
>
>> 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().
>>
>> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
>> ---
>>  target/i386/kvm/kvm.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
>> index a1fd1f53791d..c33192a87dcb 100644
>> --- a/target/i386/kvm/kvm.c
>> +++ b/target/i386/kvm/kvm.c
>> @@ -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

Ping)

-- 
Vitaly



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] i386: Fix KVM_CAP_ADJUST_CLOCK capability check
  2022-10-07  9:26   ` Vitaly Kuznetsov
@ 2022-10-07 10:49     ` Paolo Bonzini
  2022-10-07 11:53       ` Vitaly Kuznetsov
  0 siblings, 1 reply; 6+ messages in thread
From: Paolo Bonzini @ 2022-10-07 10:49 UTC (permalink / raw)
  To: Vitaly Kuznetsov
  Cc: qemu-devel, Marcelo Tosatti, Oliver Upton, Maxim Levitsky

[-- Attachment #1: Type: text/plain, Size: 1597 bytes --]

Hi, a similar patch is now in.

Paolo

Il ven 7 ott 2022, 05:26 Vitaly Kuznetsov <vkuznets@redhat.com> ha scritto:

> Vitaly Kuznetsov <vkuznets@redhat.com> writes:
>
> > Vitaly Kuznetsov <vkuznets@redhat.com> writes:
> >
> >> 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().
> >>
> >> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> >> ---
> >>  target/i386/kvm/kvm.c | 2 +-
> >>  1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
> >> index a1fd1f53791d..c33192a87dcb 100644
> >> --- a/target/i386/kvm/kvm.c
> >> +++ b/target/i386/kvm/kvm.c
> >> @@ -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
>
> Ping)
>
> --
> Vitaly
>
>

[-- Attachment #2: Type: text/html, Size: 2486 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] i386: Fix KVM_CAP_ADJUST_CLOCK capability check
  2022-10-07 10:49     ` Paolo Bonzini
@ 2022-10-07 11:53       ` Vitaly Kuznetsov
  0 siblings, 0 replies; 6+ messages in thread
From: Vitaly Kuznetsov @ 2022-10-07 11:53 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel, Marcelo Tosatti, Oliver Upton, Maxim Levitsky

Paolo Bonzini <pbonzini@redhat.com> writes:

> Hi, a similar patch is now in.
>

Indeed,

commit c4ef867f2949bf2a2ae18a4e27cf1a34bbc8aecb
Author: Ray Zhang <zhanglei002@gmail.com>
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.

-- 
Vitaly



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-10-07 13:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-20 14:40 [PATCH] i386: Fix KVM_CAP_ADJUST_CLOCK capability check Vitaly Kuznetsov
2022-09-20 18:33 ` Marcelo Tosatti
2022-09-27  9:45 ` Vitaly Kuznetsov
2022-10-07  9:26   ` Vitaly Kuznetsov
2022-10-07 10:49     ` Paolo Bonzini
2022-10-07 11:53       ` Vitaly Kuznetsov

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).