[Y2038] [PATCH 04/37] staging/lustre: tracefile: use 64-bit seconds

Arnd Bergmann arnd at arndb.de
Fri Sep 25 10:37:50 UTC 2015


On Friday 25 September 2015 12:17:18 Arnd Bergmann wrote:
> On Friday 25 September 2015 01:52:37 Drokin, Oleg wrote:
> > On Sep 24, 2015, at 3:46 AM, Arnd Bergmann wrote:
> > > On Thursday 24 September 2015 04:02:09 Drokin, Oleg wrote:
> > These are all the users.
> > Seems to be pretty much u32 (or unsigned int when printing) everywhere.
> 
> Ok, I'll the patch then to clarify this and leave the format unchanged.

This is what I have committed now:

>From b56ff589e6a25a6b199c7f526d16281bbc5080a5 Mon Sep 17 00:00:00 2001
From: Arnd Bergmann <arnd at arndb.de>
Date: Fri, 18 Sep 2015 16:02:57 +0200
Subject: [PATCH] staging/lustre: tracefile: document seconds overflow

The lustre tracefile has a timestamp defined as

       __u32 ph_sec;
       __u64 ph_usec;

which seems completely backwards, as the microsecond portion of
a time stamp will always fit into a __u32 value, while the second
portion will overflow in 2038 or 2106 (in case of unsigned seconds).

Changing this would unfortunately change the format in an incompatible
way, breaking all existing user space tools that access the data.

This uses ktime_get_real_ts64() to replace the insufficient
do_gettimeofday() and then truncates the seconds portion to
an u32 type, along with comments to explain the result.

A possible alternative would be the use of ktime_get_ts64() to
read a monotonic timestamp that never overflows, but this would
trigger a check in user space 'hdr->ph_sec < (1 << 30)' that
attempts to ensure that the values are within a reasonable range.

Signed-off-by: Arnd Bergmann <arnd at arndb.de>

diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h
index a3aa644154e2..a1787bb43483 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h
@@ -73,6 +73,7 @@ struct ptldebug_header {
 	__u32 ph_mask;
 	__u16 ph_cpu_id;
 	__u16 ph_type;
+	/* time_t overflow in 2106 */
 	__u32 ph_sec;
 	__u64 ph_usec;
 	__u32 ph_stack;
diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c
index 87d844953522..a1a361d1b040 100644
--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c
+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c
@@ -191,16 +191,18 @@ cfs_set_ptldebug_header(struct ptldebug_header *header,
 			struct libcfs_debug_msg_data *msgdata,
 			unsigned long stack)
 {
-	struct timeval tv;
+	struct timespec64 ts;
 
-	do_gettimeofday(&tv);
+	ktime_get_real_ts64(&ts);
 
 	header->ph_subsys = msgdata->msg_subsys;
 	header->ph_mask = msgdata->msg_mask;
 	header->ph_cpu_id = smp_processor_id();
 	header->ph_type = cfs_trace_buf_idx_get();
-	header->ph_sec = (__u32)tv.tv_sec;
-	header->ph_usec = tv.tv_usec;
+	/* y2038 safe since all user space treats this as unsigned, but
+	   will overflow in 2106 */
+	header->ph_sec = (u32)ts.tv_sec;
+	header->ph_usec = ts.tv_nsec / NSEC_PER_USEC;
 	header->ph_stack = stack;
 	header->ph_pid = current->pid;
 	header->ph_line_num = msgdata->msg_line;



More information about the devel mailing list