From: Paolo Bonzini <pbonzini@redhat.com>
To: Huaitong Han <huaitong.han@intel.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH] kvmclock: fix wall clock msr write error
Date: Tue, 10 Jan 2017 11:49:30 +0100 [thread overview]
Message-ID: <c0fd6834-3ace-7b48-648d-071bbba26b94@redhat.com> (raw)
In-Reply-To: <1484043900-28111-1-git-send-email-huaitong.han@intel.com>
On 10/01/2017 11:25, Huaitong Han wrote:
> kvmclock_offset is negative, it should be timespec64_add intead of
> timespec64_sub.
>
> kvm->arch.kvmclock_offset = -ktime_get_boot_ns()
No, timespec64_sub is correct (and kvmclock.flat in kvm-unit-tests tests
it). The guest computes CLOCK_REALTIME as pvclock_wall_clock + kvmclock
(see pvclock_read_wallclock in arch/x86/kvm/pvclock.c).
So:
host_boot_time = getboottime64()
pvclock_wall_clock = guest_boot_time
kvmclock_offset = host_boot_time - guest_boot_time
The latter is important: kvmclock_offset is negative because
guest_boot_time > host_boot_time. Then:
pvclock_wall_clock =
= guest_boot_time
= host_boot_time - (host_boot_time - guest_boot_time)
= getboottime64() - kvmclock_offset
Thanks,
Paolo
> Signed-off-by: Huaitong Han <huaitong.han@intel.com>
> ---
> arch/x86/kvm/x86.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 2f22810..7668a0e 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -1208,7 +1208,7 @@ static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock)
>
> if (kvm->arch.kvmclock_offset) {
> struct timespec64 ts = ns_to_timespec64(kvm->arch.kvmclock_offset);
> - boot = timespec64_sub(boot, ts);
> + boot = timespec64_add(boot, ts);
> }
> wc.sec = (u32)boot.tv_sec; /* overflow in 2106 guest time */
> wc.nsec = boot.tv_nsec;
>
prev parent reply other threads:[~2017-01-10 10:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-10 10:25 [PATCH] kvmclock: fix wall clock msr write error Huaitong Han
2017-01-10 10:49 ` Paolo Bonzini [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=c0fd6834-3ace-7b48-648d-071bbba26b94@redhat.com \
--to=pbonzini@redhat.com \
--cc=huaitong.han@intel.com \
--cc=kvm@vger.kernel.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