[PATCH kvm-kmod] adjust timekeeping compatibility code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux