From: Paolo Bonzini <pbonzini@redhat.com>
To: "Marcelo Tosatti" <mtosatti@redhat.com>,
"Marcin Gibuła" <m.gibula@beyond.pl>
Cc: Alexander Graf <agraf@suse.de>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2] kvmclock: Ensure time in migration never goes backward
Date: Tue, 03 Jun 2014 13:13:49 +0200 [thread overview]
Message-ID: <538DADED.4040609@redhat.com> (raw)
In-Reply-To: <20140603051630.GA2289@amt.cnet>
Il 03/06/2014 07:16, Marcelo Tosatti ha scritto:
> On Mon, Jun 02, 2014 at 10:31:44PM +0200, Marcin Gibuła wrote:
>>> + cpu_physical_memory_read(kvmclock_struct_pa, &time, sizeof(time));
>>> +
>>> + delta = migration_tsc - time.tsc_timestamp;
>>
>> Hi,
>>
>> when I was testing live storage migration with libvirt I found out
>> that this patch can cause virtual machine to hang when completing
>> mirror job.
>>
>> This is (probably) because kvmclock_current_nsec() is called twice
>> in a row and on second call time.tsc_timestamp is larger than
>> migration_tsc. This causes delta to be huge and sets timer to
>> invalid value.
>>
>> The double call happens when switching from old to new disk
>> (pivoting in libvirt's nomenclature).
>>
>> Example values:
>>
>> First call: migration_tsc: 12052203518652476, time_tsc:
>> 12052203301565676, delta 108543400
>>
>> Second call: migration_tsc: 12052203518652476, time_tsc:
>> 12052204478600322, delta 9223372036374801885
>>
>> Perhaps it is worth adding:
>>
>> if (time.tsc_timestamp > migration_tsc) {
>> return 0;
>> }
>>
>> there? Untested though...
>
> Hi Marcin,
>
> Can you give this patch a try? Should read the guest TSC values after
> stopping the VM.
>
>
> diff --git a/hw/i386/kvm/clock.c b/hw/i386/kvm/clock.c
> index 6f4ed28a..bef2504 100644
> --- a/hw/i386/kvm/clock.c
> +++ b/hw/i386/kvm/clock.c
> @@ -17,6 +17,7 @@
> #include "qemu/host-utils.h"
> #include "sysemu/sysemu.h"
> #include "sysemu/kvm.h"
> +#include "sysemu/cpus.h"
> #include "hw/sysbus.h"
> #include "hw/kvm/clock.h"
>
> @@ -65,6 +66,7 @@ static uint64_t kvmclock_current_nsec(KVMClockState *s)
>
> cpu_physical_memory_read(kvmclock_struct_pa, &time, sizeof(time));
>
> + assert(time.tsc_timestamp <= migration_tsc);
> delta = migration_tsc - time.tsc_timestamp;
> if (time.tsc_shift < 0) {
> delta >>= -time.tsc_shift;
> @@ -123,6 +125,8 @@ static void kvmclock_vm_state_change(void *opaque, int running,
> if (s->clock_valid) {
> return;
> }
> +
> + cpu_synchronize_all_states();
> ret = kvm_vm_ioctl(kvm_state, KVM_GET_CLOCK, &data);
> if (ret < 0) {
> fprintf(stderr, "KVM_GET_CLOCK failed: %s\n", strerror(ret));
>
Can you send it with a real commit message?
Paolo
next prev parent reply other threads:[~2014-06-03 11:14 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-16 15:15 [PATCH v2] kvmclock: Ensure time in migration never goes backward Alexander Graf
2014-05-16 15:15 ` [Qemu-devel] " Alexander Graf
2014-05-18 13:20 ` Marcelo Tosatti
2014-05-18 13:20 ` [Qemu-devel] " Marcelo Tosatti
2014-05-19 11:31 ` Paolo Bonzini
2014-05-19 11:31 ` [Qemu-devel] " Paolo Bonzini
2014-05-21 10:03 ` Alexander Graf
2014-05-21 10:03 ` [Qemu-devel] " Alexander Graf
2014-06-02 20:31 ` Marcin Gibuła
2014-06-03 5:16 ` Marcelo Tosatti
2014-06-03 9:11 ` Marcin Gibuła
2014-06-03 11:13 ` Paolo Bonzini [this message]
2014-06-03 16:34 ` [Qemu-devel] [PATCH uq/master] kvmclock: Ensure proper env->tsc value for kvmclock_current_nsec calculation Marcelo Tosatti
2014-07-15 19:45 ` Paolo Bonzini
2014-07-15 20:03 ` Marcin Gibuła
2014-07-15 20:15 ` Paolo Bonzini
2014-07-15 20:31 ` Marcelo Tosatti
2014-07-15 20:34 ` Marcelo Tosatti
2014-07-15 20:43 ` Paolo Bonzini
2014-07-15 21:05 ` Andrey Korolyov
2014-07-15 21:08 ` Paolo Bonzini
2014-07-15 20:43 ` Paolo Bonzini
2014-07-15 19:44 ` [PATCH v2] kvmclock: Ensure time in migration never goes backward Paolo Bonzini
2014-07-15 19:44 ` [Qemu-devel] " Paolo Bonzini
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=538DADED.4040609@redhat.com \
--to=pbonzini@redhat.com \
--cc=agraf@suse.de \
--cc=m.gibula@beyond.pl \
--cc=mtosatti@redhat.com \
--cc=qemu-devel@nongnu.org \
/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.