* [PATCH 1/2] kvm: kvmclock: apply kvmclock offset to guest wall clock time
@ 2012-07-19 15:21 Bruce Rogers
0 siblings, 0 replies; 6+ messages in thread
From: Bruce Rogers @ 2012-07-19 15:21 UTC (permalink / raw)
To: kvm; +Cc: Bruce Rogers, Glauber Costa, Zachary Amsden
When a guest migrates to a new host, the system time difference from the
previous host is used in the updates to the kvmclock system time visible
to the guest, resulting in a continuation of correct kvmclock based guest
timekeeping.
The wall clock component of the kvmclock provided time is currently not
updated with this same time offset. Since the Linux guest caches the
wall clock based time, this discrepency is not noticed until the guest is
rebooted. After reboot the guest's time calculations are off.
This patch adjusts the wall clock by the kvmclock_offset, resulting in
correct guest time after a reboot.
Cc: Glauber Costa <glommer@redhat.com>
Cc: Zachary Amsden <zamsden@redhat.com>
Signed-off-by: Bruce Rogers <brogers@suse.com>
---
arch/x86/kvm/x86.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index be6d549..14c290d 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -907,6 +907,10 @@ static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock)
*/
getboottime(&boot);
+ if (kvm->arch.kvmclock_offset) {
+ struct timespec ts = ns_to_timespec(kvm->arch.kvmclock_offset);
+ boot = timespec_sub(boot, ts);
+ }
wc.sec = boot.tv_sec;
wc.nsec = boot.tv_nsec;
wc.version = version;
--
1.7.7
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 1/2] kvm: kvmclock: apply kvmclock offset to guest wall clock time
@ 2012-07-20 16:44 Bruce Rogers
2012-07-24 0:44 ` Marcelo Tosatti
0 siblings, 1 reply; 6+ messages in thread
From: Bruce Rogers @ 2012-07-20 16:44 UTC (permalink / raw)
To: kvm; +Cc: Zamsden, glommer
When a guest migrates to a new host, the system time difference from the
previous host is used in the updates to the kvmclock system time visible
to the guest, resulting in a continuation of correct kvmclock based guest
timekeeping.
The wall clock component of the kvmclock provided time is currently not
updated with this same time offset. Since the Linux guest caches the
wall clock based time, this discrepency is not noticed until the guest is
rebooted. After reboot the guest's time calculations are off.
This patch adjusts the wall clock by the kvmclock_offset, resulting in
correct guest time after a reboot.
Cc: Glauber Costa <glommer@redhat.com>
Cc: Zachary Amsden <zamsden@gmail.com>
Signed-off-by: Bruce Rogers <brogers@suse.com>
---
arch/x86/kvm/x86.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index be6d549..14c290d 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -907,6 +907,10 @@ static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock)
*/
getboottime(&boot);
+ if (kvm->arch.kvmclock_offset) {
+ struct timespec ts = ns_to_timespec(kvm->arch.kvmclock_offset);
+ boot = timespec_sub(boot, ts);
+ }
wc.sec = boot.tv_sec;
wc.nsec = boot.tv_nsec;
wc.version = version;
--
1.7.7
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] kvm: kvmclock: apply kvmclock offset to guest wall clock time
2012-07-20 16:44 [PATCH 1/2] kvm: kvmclock: apply kvmclock offset to guest wall clock time Bruce Rogers
@ 2012-07-24 0:44 ` Marcelo Tosatti
2012-08-01 20:21 ` Marcelo Tosatti
0 siblings, 1 reply; 6+ messages in thread
From: Marcelo Tosatti @ 2012-07-24 0:44 UTC (permalink / raw)
To: Bruce Rogers; +Cc: kvm, Zamsden, glommer
On Fri, Jul 20, 2012 at 10:44:24AM -0600, Bruce Rogers wrote:
> When a guest migrates to a new host, the system time difference from the
> previous host is used in the updates to the kvmclock system time visible
> to the guest, resulting in a continuation of correct kvmclock based guest
> timekeeping.
>
> The wall clock component of the kvmclock provided time is currently not
> updated with this same time offset. Since the Linux guest caches the
> wall clock based time, this discrepency is not noticed until the guest is
> rebooted. After reboot the guest's time calculations are off.
>
> This patch adjusts the wall clock by the kvmclock_offset, resulting in
> correct guest time after a reboot.
>
> Cc: Glauber Costa <glommer@redhat.com>
> Cc: Zachary Amsden <zamsden@gmail.com>
> Signed-off-by: Bruce Rogers <brogers@suse.com>
> ---
> arch/x86/kvm/x86.c | 4 ++++
> 1 files changed, 4 insertions(+), 0 deletions(-)
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index be6d549..14c290d 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -907,6 +907,10 @@ static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock)
> */
> getboottime(&boot);
>
> + if (kvm->arch.kvmclock_offset) {
> + struct timespec ts = ns_to_timespec(kvm->arch.kvmclock_offset);
> + boot = timespec_sub(boot, ts);
> + }
kvmclock_offset is signed (both directions). Must check the sign and use
_sub and _add_safe accordingly.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] kvm: kvmclock: apply kvmclock offset to guest wall clock time
2012-07-24 0:44 ` Marcelo Tosatti
@ 2012-08-01 20:21 ` Marcelo Tosatti
2012-08-01 20:36 ` Marcelo Tosatti
2012-08-01 20:53 ` Bruce Rogers
0 siblings, 2 replies; 6+ messages in thread
From: Marcelo Tosatti @ 2012-08-01 20:21 UTC (permalink / raw)
To: Bruce Rogers; +Cc: kvm, Zamsden, glommer
On Mon, Jul 23, 2012 at 09:44:54PM -0300, Marcelo Tosatti wrote:
> On Fri, Jul 20, 2012 at 10:44:24AM -0600, Bruce Rogers wrote:
> > When a guest migrates to a new host, the system time difference from the
> > previous host is used in the updates to the kvmclock system time visible
> > to the guest, resulting in a continuation of correct kvmclock based guest
> > timekeeping.
> >
> > The wall clock component of the kvmclock provided time is currently not
> > updated with this same time offset. Since the Linux guest caches the
> > wall clock based time, this discrepency is not noticed until the guest is
> > rebooted. After reboot the guest's time calculations are off.
> >
> > This patch adjusts the wall clock by the kvmclock_offset, resulting in
> > correct guest time after a reboot.
> >
> > Cc: Glauber Costa <glommer@redhat.com>
> > Cc: Zachary Amsden <zamsden@gmail.com>
> > Signed-off-by: Bruce Rogers <brogers@suse.com>
> > ---
> > arch/x86/kvm/x86.c | 4 ++++
> > 1 files changed, 4 insertions(+), 0 deletions(-)
> >
> > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> > index be6d549..14c290d 100644
> > --- a/arch/x86/kvm/x86.c
> > +++ b/arch/x86/kvm/x86.c
> > @@ -907,6 +907,10 @@ static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock)
> > */
> > getboottime(&boot);
> >
> > + if (kvm->arch.kvmclock_offset) {
> > + struct timespec ts = ns_to_timespec(kvm->arch.kvmclock_offset);
> > + boot = timespec_sub(boot, ts);
> > + }
>
> kvmclock_offset is signed (both directions). Must check the sign and use
> _sub and _add_safe accordingly.
Your patch is correct, sorry (applied to master).
Patch 2 still makes no sense.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] kvm: kvmclock: apply kvmclock offset to guest wall clock time
2012-08-01 20:21 ` Marcelo Tosatti
@ 2012-08-01 20:36 ` Marcelo Tosatti
2012-08-01 20:53 ` Bruce Rogers
1 sibling, 0 replies; 6+ messages in thread
From: Marcelo Tosatti @ 2012-08-01 20:36 UTC (permalink / raw)
To: Bruce Rogers; +Cc: kvm, Zamsden, glommer
On Wed, Aug 01, 2012 at 05:21:46PM -0300, Marcelo Tosatti wrote:
> On Mon, Jul 23, 2012 at 09:44:54PM -0300, Marcelo Tosatti wrote:
> > On Fri, Jul 20, 2012 at 10:44:24AM -0600, Bruce Rogers wrote:
> > > When a guest migrates to a new host, the system time difference from the
> > > previous host is used in the updates to the kvmclock system time visible
> > > to the guest, resulting in a continuation of correct kvmclock based guest
> > > timekeeping.
> > >
> > > The wall clock component of the kvmclock provided time is currently not
> > > updated with this same time offset. Since the Linux guest caches the
> > > wall clock based time, this discrepency is not noticed until the guest is
> > > rebooted. After reboot the guest's time calculations are off.
> > >
> > > This patch adjusts the wall clock by the kvmclock_offset, resulting in
> > > correct guest time after a reboot.
> > >
> > > Cc: Glauber Costa <glommer@redhat.com>
> > > Cc: Zachary Amsden <zamsden@gmail.com>
> > > Signed-off-by: Bruce Rogers <brogers@suse.com>
> > > ---
> > > arch/x86/kvm/x86.c | 4 ++++
> > > 1 files changed, 4 insertions(+), 0 deletions(-)
> > >
> > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> > > index be6d549..14c290d 100644
> > > --- a/arch/x86/kvm/x86.c
> > > +++ b/arch/x86/kvm/x86.c
> > > @@ -907,6 +907,10 @@ static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock)
> > > */
> > > getboottime(&boot);
> > >
> > > + if (kvm->arch.kvmclock_offset) {
> > > + struct timespec ts = ns_to_timespec(kvm->arch.kvmclock_offset);
> > > + boot = timespec_sub(boot, ts);
> > > + }
> >
> > kvmclock_offset is signed (both directions). Must check the sign and use
> > _sub and _add_safe accordingly.
>
> Your patch is correct, sorry (applied to master).
>
> Patch 2 still makes no sense.
As in that the guest should not expect system_timestamp to be any
particular value.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] kvm: kvmclock: apply kvmclock offset to guest wall clock time
2012-08-01 20:21 ` Marcelo Tosatti
2012-08-01 20:36 ` Marcelo Tosatti
@ 2012-08-01 20:53 ` Bruce Rogers
1 sibling, 0 replies; 6+ messages in thread
From: Bruce Rogers @ 2012-08-01 20:53 UTC (permalink / raw)
To: Marcelo Tosatti; +Cc: Zamsden, glommer, kvm
>>> On 8/1/2012 at 02:21 PM, Marcelo Tosatti <mtosatti@redhat.com> wrote:
> On Mon, Jul 23, 2012 at 09:44:54PM -0300, Marcelo Tosatti wrote:
>> On Fri, Jul 20, 2012 at 10:44:24AM -0600, Bruce Rogers wrote:
>> > When a guest migrates to a new host, the system time difference from the
>> > previous host is used in the updates to the kvmclock system time visible
>> > to the guest, resulting in a continuation of correct kvmclock based guest
>> > timekeeping.
>> >
>> > The wall clock component of the kvmclock provided time is currently not
>> > updated with this same time offset. Since the Linux guest caches the
>> > wall clock based time, this discrepency is not noticed until the guest is
>> > rebooted. After reboot the guest's time calculations are off.
>> >
>> > This patch adjusts the wall clock by the kvmclock_offset, resulting in
>> > correct guest time after a reboot.
>> >
>> > Cc: Glauber Costa <glommer@redhat.com>
>> > Cc: Zachary Amsden <zamsden@gmail.com>
>> > Signed-off-by: Bruce Rogers <brogers@suse.com>
>> > ---
>> > arch/x86/kvm/x86.c | 4 ++++
>> > 1 files changed, 4 insertions(+), 0 deletions(-)
>> >
>> > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
>> > index be6d549..14c290d 100644
>> > --- a/arch/x86/kvm/x86.c
>> > +++ b/arch/x86/kvm/x86.c
>> > @@ -907,6 +907,10 @@ static void kvm_write_wall_clock(struct kvm *kvm, gpa_t
> wall_clock)
>> > */
>> > getboottime(&boot);
>> >
>> > + if (kvm->arch.kvmclock_offset) {
>> > + struct timespec ts = ns_to_timespec(kvm->arch.kvmclock_offset);
>> > + boot = timespec_sub(boot, ts);
>> > + }
>>
>> kvmclock_offset is signed (both directions). Must check the sign and use
>> _sub and _add_safe accordingly.
>
> Your patch is correct, sorry (applied to master).
>
> Patch 2 still makes no sense.
I'm fine with dropping the second patch.
Thanks
Bruce
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-08-01 20:53 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-20 16:44 [PATCH 1/2] kvm: kvmclock: apply kvmclock offset to guest wall clock time Bruce Rogers
2012-07-24 0:44 ` Marcelo Tosatti
2012-08-01 20:21 ` Marcelo Tosatti
2012-08-01 20:36 ` Marcelo Tosatti
2012-08-01 20:53 ` Bruce Rogers
-- strict thread matches above, loose matches on Subject: below --
2012-07-19 15:21 Bruce Rogers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox