From: Marcelo Tosatti <mtosatti@redhat.com>
To: "Li, Liang Z" <liang.z.li@intel.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Marcin Gibula <m.gibula@beyond.pl>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] about the patch kvmclock Ensure proper env->tsc value for kvmclock_current_nsec calculation
Date: Fri, 14 Aug 2015 19:35:23 -0300 [thread overview]
Message-ID: <20150814223523.GA5592@amt.cnet> (raw)
In-Reply-To: <F2CBF3009FA73547804AE4C663CAB28E5B94E2@shsmsx102.ccr.corp.intel.com>
On Fri, Aug 14, 2015 at 09:18:01AM +0000, Li, Liang Z wrote:
> > Subject: Re: [Qemu-devel] about the patch kvmclock Ensure proper env->tsc
> > value for kvmclock_current_nsec calculation
> >
> > > Thanks for your reply, I have read the thread in your email, what's the
> > mean of 'switching from old to new disk', could give a detail description?
> >
> > The test case was like that (using libvirt):
> >
> > 1. Get VM running (linux, using kvmclock), 2. Use blockcopy to copy disk data
> > from one location to another, 3. Issue blockjob --pivot (to finish mirroring)
> >
> > From what I remember, at point 3, VM is momentarily paused and resumed,
> > so kvm state change handler is called twice. Without this patch, the VM
> > hanged because its time goes backwards (or qemu crashed if assertion was
> > not compiled out).
> >
> > --
> > mg
>
> So, the problem is cause by stop_vm(RUN_STATE_PAUSED), in this case the env->tsc is not updated, which lead to the issue.
> Is that right? If the cpu_clean_all_dirty() is needed just for the APIC status reason, I think we can do the cpu_synchronize_all_states() in do_vm_stop
> and after vm_state_notify() when the RUN_STATE_PAUSED is hit, at this point all the device models is stopped, there is no outdated APIC status.
>
> I want to write a patch to fix this issue in another way, could help to verify it in you environment, very appreciate if you could.
>
> Thanks.
>
> Liang
Liang,
The problem is this:
Think two hosts, source and destination. The code is running in the
destination host.
The clock which the source host maintains (CLOCK_MONOTONIC), which is what
KVM_GET_CLOCK ioctl uses, is corrected by NTP.
The clock which the guest uses can be based on TSC, which can drift
relative to UTC.
So at the moment the guest is stopped at the source, KVM_GET_CLOCK clock
(s->clock in kvmclock.c) might be behind of TSC based clock (which means
that setting that clock value at the destination would case the guest to
see time going backwards which is fatal).
What the code does is to, on the destination host, read the clock value
from memory rather than to use what has been retrieved in the source
host with KVM_GET_CLOCK.
For that, it needs uptodated env->tsc value relative to the destination
host (TSC+TSC_OFFSET of destination host).
Yes i can test your patch.
prev parent reply other threads:[~2015-08-14 22:50 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-13 1:25 [Qemu-devel] about the patch kvmclock Ensure proper env->tsc value for kvmclock_current_nsec calculation Li, Liang Z
2015-08-13 22:16 ` Marcelo Tosatti
2015-08-14 1:23 ` Li, Liang Z
2015-08-14 7:31 ` Marcin Gibuła
2015-08-14 7:51 ` Li, Liang Z
2015-08-14 8:51 ` Marcin Gibuła
2015-08-14 9:18 ` Li, Liang Z
2015-08-14 14:10 ` Marcin Gibuła
2015-08-14 22:35 ` Marcelo Tosatti [this message]
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=20150814223523.GA5592@amt.cnet \
--to=mtosatti@redhat.com \
--cc=liang.z.li@intel.com \
--cc=m.gibula@beyond.pl \
--cc=pbonzini@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 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).