kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH kvm-kmod] adjust timekeeping compatibility code
@ 2014-09-23  8:22 Paolo Bonzini
  2014-09-30  7:54 ` Jan Kiszka
  0 siblings, 1 reply; 9+ messages in thread
From: Paolo Bonzini @ 2014-09-23  8:22 UTC (permalink / raw)
  To: kvm; +Cc: jan.kiszka

kvm_get_xtime_nsec could overflow.  If we make kvm_get_boot_base_ns
compute the equivalent of 3.17's base_mono+offs_boot formula (instead of
just offs_boot), we can avoid that and drop kvm_get_xtime_nsec altogether.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 external-module-compat-comm.h |  3 +--
 external-module-compat.c      | 19 ++++---------------
 sync                          |  4 +---
 3 files changed, 6 insertions(+), 20 deletions(-)

diff --git a/external-module-compat-comm.h b/external-module-compat-comm.h
index b6a2894..fdcd8e4 100644
--- a/external-module-compat-comm.h
+++ b/external-module-compat-comm.h
@@ -1412,9 +1412,8 @@ static inline void guest_exit(void)
  */
 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,17,0)
 extern u64 ktime_get_boot_ns(void);
-extern u64 kvm_get_boot_base_ns(void);
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)
 struct timekeeper;
-extern u64 kvm_get_xtime_nsec(struct timekeeper *tk);
+extern u64 kvm_get_boot_base_ns(struct timekeeper *tk);
 #endif
 #endif
diff --git a/external-module-compat.c b/external-module-compat.c
index eb7bc62..38717b6 100644
--- a/external-module-compat.c
+++ b/external-module-compat.c
@@ -350,26 +350,15 @@ u64 ktime_get_boot_ns(void)
 	return timespec_to_ns(&ts);
 }
 
-u64 kvm_get_boot_base_ns(void)
-{
-	struct timespec ts = { 0, 0 };
-
-	kvm_monotonic_to_bootbased(&ts);
-	return timespec_to_ns(&ts);
-}
-
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)
 #include <linux/timekeeper_internal.h>
 
-u64 kvm_get_xtime_nsec(struct timekeeper *tk)
+u64 kvm_get_boot_base_ns(struct timekeeper *tk)
 {
-	u64 monotonic_time_sec =
-		tk->xtime_sec + tk->wall_to_monotonic.tv_sec;
-	u64 monotonic_time_snsec =
-		tk->xtime_nsec + (tk->wall_to_monotonic.tv_nsec << tk->shift);
+	struct timespec ts = tk->wall_to_monotonic;
 
-	return ((monotonic_time_sec * (u64)NSEC_PER_SEC) << tk->shift) +
-		monotonic_time_snsec;
+	kvm_monotonic_to_bootbased(&ts);
+	return timespec_to_ns(&ts) + tk->xtime_sec * (u64)NSEC_PER_SEC;
 }
 #endif
 #endif
diff --git a/sync b/sync
index 0af0399..8b63ca7 100755
--- a/sync
+++ b/sync
@@ -306,9 +306,7 @@ def hack_content(fname, data):
             if match(r'tkr\.cycle_last') or match(r'tkr\.mask'):
                 w(sub(r'tkr\.', 'clock->', line))
             elif match(r'tkr\.base_mono'):
-                w('\tboot_ns = kvm_get_boot_base_ns();')
-            elif match(r'tkr\.xtime_nsec'):
-                w(sub(r'tk->tkr\.xtime_nsec', 'kvm_get_xtime_nsec(tk)', line))
+                w('\tboot_ns = kvm_get_boot_base_ns(tk);')
             else:
                 w(sub(r'tkr\.', '', line))
             line = '#endif'
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-10-08 16:00 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-23  8:22 [PATCH kvm-kmod] adjust timekeeping compatibility code Paolo Bonzini
2014-09-30  7:54 ` Jan Kiszka
2014-09-30  8:43   ` Paolo Bonzini
2014-09-30  8:48     ` Jan Kiszka
2014-09-30 10:39       ` Paolo Bonzini
2014-10-01  7:40         ` Jan Kiszka
2014-10-02 10:12           ` Paolo Bonzini
2014-10-02 12:17             ` Jan Kiszka
2014-10-08 16:00     ` Jan Kiszka

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).