From: Arnd Bergmann <[email protected]>

Upstream commit:
    commit 311af51dcb5629f04976a8e451673f77e3301041
    Author: Arnd Bergmann <[email protected]>
    Date:   Mon Nov 27 12:41:38 2017 +0100

    openvswitch: use ktime_get_ts64() instead of ktime_get_ts()

    timespec is deprecated because of the y2038 overflow, so let's convert
    this one to ktime_get_ts64(). The code is already safe even on 32-bit
    architectures, since it uses monotonic times. On 64-bit architectures,
    nothing changes, while on 32-bit architectures this avoids one
    type conversion.

    Signed-off-by: Arnd Bergmann <[email protected]>
    Signed-off-by: David S. Miller <[email protected]>

Additional compatability check for ktime_get_ts64() exists or not.
If not, then just continue using ktime_get_ts(). I added a new
compatability header file "timekeeping.h".

Cc: Arnd Bergmann <[email protected]>
Signed-off-by: Greg Rose <[email protected]>
---
 acinclude.m4                                      |  3 +++
 datapath/flow.c                                   |  7 ++++---
 datapath/linux/Modules.mk                         |  1 +
 datapath/linux/compat/include/linux/timekeeping.h | 11 +++++++++++
 4 files changed, 19 insertions(+), 3 deletions(-)
 create mode 100644 datapath/linux/compat/include/linux/timekeeping.h

diff --git a/acinclude.m4 b/acinclude.m4
index b8ac7db..6d440f8 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -801,6 +801,9 @@ AC_DEFUN([OVS_CHECK_LINUX_COMPAT], [
   OVS_GREP_IFELSE([$KSRC/include/linux/compiler_types.h],
                   [__LINUX_COMPILER_TYPES_H],
                   [OVS_DEFINE([HAVE_LINUX_COMPILER_TYPES_H])])
+  OVS_GREP_IFELSE([$KSRC/include/linux/timekeeping.h],
+                  [ktime_get_ts64],
+                  [OVS_DEFINE([HAVE_KTIME_GET_TS64])])
 
   if cmp -s datapath/linux/kcompat.h.new \
             datapath/linux/kcompat.h >/dev/null 2>&1; then
diff --git a/datapath/flow.c b/datapath/flow.c
index 5da7e3e..1684762 100644
--- a/datapath/flow.c
+++ b/datapath/flow.c
@@ -41,6 +41,7 @@
 #include <linux/icmp.h>
 #include <linux/icmpv6.h>
 #include <linux/rculist.h>
+#include <linux/timekeeping.h>
 #include <net/ip.h>
 #include <net/ipv6.h>
 #include <net/mpls.h>
@@ -54,12 +55,12 @@
 
 u64 ovs_flow_used_time(unsigned long flow_jiffies)
 {
-       struct timespec cur_ts;
+       struct timespec64 cur_ts;
        u64 cur_ms, idle_ms;
 
-       ktime_get_ts(&cur_ts);
+       ktime_get_ts64(&cur_ts);
        idle_ms = jiffies_to_msecs(jiffies - flow_jiffies);
-       cur_ms = (u64)cur_ts.tv_sec * MSEC_PER_SEC +
+       cur_ms = (u64)(u32)cur_ts.tv_sec * MSEC_PER_SEC +
                 cur_ts.tv_nsec / NSEC_PER_MSEC;
 
        return cur_ms - idle_ms;
diff --git a/datapath/linux/Modules.mk b/datapath/linux/Modules.mk
index eec9f23..0fc4132 100644
--- a/datapath/linux/Modules.mk
+++ b/datapath/linux/Modules.mk
@@ -64,6 +64,7 @@ openvswitch_headers += \
        linux/compat/include/linux/u64_stats_sync.h \
        linux/compat/include/linux/udp.h \
        linux/compat/include/linux/workqueue.h \
+       linux/compat/include/linux/timekeeping.h \
        linux/compat/include/net/checksum.h \
        linux/compat/include/net/dst.h \
        linux/compat/include/net/dst_cache.h \
diff --git a/datapath/linux/compat/include/linux/timekeeping.h 
b/datapath/linux/compat/include/linux/timekeeping.h
new file mode 100644
index 0000000..3a3b183
--- /dev/null
+++ b/datapath/linux/compat/include/linux/timekeeping.h
@@ -0,0 +1,11 @@
+#ifndef _LINUX_TIMEKEEPING_WRAPPER_H
+#define _LINUX_TIMEKEEPING_WRAPPER_H
+
+#ifndef HAVE_KTIME_GET_TS64
+#define ktime_get_ts64 ktime_get_ts
+#define timespec64 timespec
+#else
+#include_next <linux/timekeeping.h>
+#endif
+
+#endif
-- 
1.8.3.1

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to