All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jay Zhou <jianjay.zhou@huawei.com>
To: "Radim Krčmář" <rkrcmar@redhat.com>
Cc: <kvm@vger.kernel.org>, <qemu-devel@nongnu.org>,
	<wangxinxin.wang@huawei.com>, <weidong.huang@huawei.com>,
	<arei.gonglei@huawei.com>
Subject: Re: [PATCH RFC] KVM: X86: save and load PVCLOCK_TSC_UNSTABLE_BIT when migration
Date: Tue, 13 Jun 2017 20:00:32 +0800	[thread overview]
Message-ID: <593FD3E0.5070807@huawei.com> (raw)
In-Reply-To: <20170612195209.GA16151@potion>

Hi Radim,

On 2017/6/13 3:52, Radim Krčmář wrote:
> 2017-06-12 21:23+0800, Jay Zhou:
>> Guest using kvmclock will be hanged when migrating from unstable
>> tsc host to stable tsc host occasionally.
>> Sometimes, the tsc timestamp saved at the source side will be
>> backward when the guest stopped, and this value is transferred
>> to the destination side. The guest at the destination side thought
>> kvmclock is stable, so the protection mechanism against time
>> going backwards is not used.
>> When the first time vcpu0 enters the guest at the destination
>> side to update the wall clock, the result of
>> pvclock_clocksource_read will be backward occasionally,
>> which results in the wall clock drift.
>>
>> Signed-off-by: Jay Zhou <jianjay.zhou@huawei.com>
>> ---
>
> Hm, are you using KVM that has e3fd9a93a12a (4.9+)?

I'm using KVM (4.4.11) and QEMU (2.6.0). I thought the newest KVM
and QEMU have the same problem, maybe I'm wrong.

>
> If you get a timestamp from KVM_GET_CLOCK() and pass that to
> KVM_SET_CLOCK(), then kvmclock should not jump backwards anymore
> (it could before 4.9, but only if the host had stable tsc).

If migrating from old KVMs to newer KVMs (v4.9+), the clock member
of struct KVMClockState is migrated to the destination side, but the
clock_is_reliable isn't migrated. The value of clock_is_reliable is false
at the source side, and it is true at the destination side. Is it possible
the clock member of struct KVMClockState migrated is smaller than the
last_value saved in the guest theoretically? Could you explain more
why it should not jump backwards in the scenario of migrating from unstable tsc 
host to stable tsc host?

>
> A possible source of this bug in when QEMU recomputes the timestamp to
> pass to KVM_SET_CLOCK() using TSC and kvmclock page.

Yes, this bug happened in this scenario in my tests.

>
> Can you provide the values used for KVM_GET_CLOCK and KVM_SET_CLOCK when
> the bug occurs?

I didn't print these values out when the bug occured, and I do not have the 
physical machine with unstable tsc clocksource now. But I will try to reproduce 
with the newest KVM and QEMU once I have.


Regards,
Jay Zhou

WARNING: multiple messages have this Message-ID (diff)
From: Jay Zhou <jianjay.zhou@huawei.com>
To: "Radim Krčmář" <rkrcmar@redhat.com>
Cc: kvm@vger.kernel.org, qemu-devel@nongnu.org,
	wangxinxin.wang@huawei.com, weidong.huang@huawei.com,
	arei.gonglei@huawei.com
Subject: Re: [Qemu-devel] [PATCH RFC] KVM: X86: save and load PVCLOCK_TSC_UNSTABLE_BIT when migration
Date: Tue, 13 Jun 2017 20:00:32 +0800	[thread overview]
Message-ID: <593FD3E0.5070807@huawei.com> (raw)
In-Reply-To: <20170612195209.GA16151@potion>

Hi Radim,

On 2017/6/13 3:52, Radim Krčmář wrote:
> 2017-06-12 21:23+0800, Jay Zhou:
>> Guest using kvmclock will be hanged when migrating from unstable
>> tsc host to stable tsc host occasionally.
>> Sometimes, the tsc timestamp saved at the source side will be
>> backward when the guest stopped, and this value is transferred
>> to the destination side. The guest at the destination side thought
>> kvmclock is stable, so the protection mechanism against time
>> going backwards is not used.
>> When the first time vcpu0 enters the guest at the destination
>> side to update the wall clock, the result of
>> pvclock_clocksource_read will be backward occasionally,
>> which results in the wall clock drift.
>>
>> Signed-off-by: Jay Zhou <jianjay.zhou@huawei.com>
>> ---
>
> Hm, are you using KVM that has e3fd9a93a12a (4.9+)?

I'm using KVM (4.4.11) and QEMU (2.6.0). I thought the newest KVM
and QEMU have the same problem, maybe I'm wrong.

>
> If you get a timestamp from KVM_GET_CLOCK() and pass that to
> KVM_SET_CLOCK(), then kvmclock should not jump backwards anymore
> (it could before 4.9, but only if the host had stable tsc).

If migrating from old KVMs to newer KVMs (v4.9+), the clock member
of struct KVMClockState is migrated to the destination side, but the
clock_is_reliable isn't migrated. The value of clock_is_reliable is false
at the source side, and it is true at the destination side. Is it possible
the clock member of struct KVMClockState migrated is smaller than the
last_value saved in the guest theoretically? Could you explain more
why it should not jump backwards in the scenario of migrating from unstable tsc 
host to stable tsc host?

>
> A possible source of this bug in when QEMU recomputes the timestamp to
> pass to KVM_SET_CLOCK() using TSC and kvmclock page.

Yes, this bug happened in this scenario in my tests.

>
> Can you provide the values used for KVM_GET_CLOCK and KVM_SET_CLOCK when
> the bug occurs?

I didn't print these values out when the bug occured, and I do not have the 
physical machine with unstable tsc clocksource now. But I will try to reproduce 
with the newest KVM and QEMU once I have.


Regards,
Jay Zhou

  reply	other threads:[~2017-06-13 12:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-12 13:23 [PATCH RFC] KVM: X86: save and load PVCLOCK_TSC_UNSTABLE_BIT when migration Jay Zhou
2017-06-12 13:23 ` [Qemu-devel] " Jay Zhou
2017-06-12 19:52 ` Radim Krčmář
2017-06-12 19:52   ` [Qemu-devel] " Radim Krčmář
2017-06-13 12:00   ` Jay Zhou [this message]
2017-06-13 12:00     ` Jay Zhou
2017-06-13 13:52     ` Radim Krčmář
2017-06-13 13:52       ` [Qemu-devel] " Radim Krčmář

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=593FD3E0.5070807@huawei.com \
    --to=jianjay.zhou@huawei.com \
    --cc=arei.gonglei@huawei.com \
    --cc=kvm@vger.kernel.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rkrcmar@redhat.com \
    --cc=wangxinxin.wang@huawei.com \
    --cc=weidong.huang@huawei.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.