linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/12]
@ 2014-11-21 19:44 John Stultz
  2014-11-21 19:44 ` [PATCH 01/12] time: Rename udelay_test.c to test_udelay.c John Stultz
                   ` (12 more replies)
  0 siblings, 13 replies; 19+ messages in thread
From: John Stultz @ 2014-11-21 19:44 UTC (permalink / raw)
  To: lkml
  Cc: John Stultz, Thomas Gleixner, Ingo Molnar, Arnd Bergmann,
	pang.xunlei, Miroslav Lichvar, Richard Cochran, Prarit Bhargava,
	Alessandro Zummo

Hey Thomas, All,

Just wanted to submit a handful of changes for 3.19

* udelay_test/test_udelay consistent file naming
* Time / ntp edge-case fixes from Xunlei
* y2038-safe internal interfaces from Xunlei and me
* Celanup suspend/resume timing y2038 issues
* Remove y2038 unsafe inject_sleeptime inteface

Just as an FYI, I'm trying out signing this tag with
a new subkey on my yubikey. Hopefully haven't mucked
it up.

If there's no objections, you can grab this via the
pull-request below.

Thanks
-john

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Arnd Bergmann <arnd.bergmann@linaro.org>
Cc: pang.xunlei <pang.xunlei@linaro.org>
Cc: Miroslav Lichvar <mlichvar@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>

The following changes since commit cac7f2429872d3733dc3f9915857b1691da2eb2f:

  Linux 3.18-rc2 (2014-10-26 16:48:41 -0700)

are available in the git repository at:

  https://git.linaro.org/people/john.stultz/linux.git tags/fortglx-3.19-time

for you to fetch changes up to b6adbbd9a2171aa4764ea8a56c4c1a5f63f2cca6:

  Merge commit '039348d8c131329742e80e37122f11d230fd270b' into fortglx/3.19/time (2014-11-20 21:37:59 -0800)


John Stultz (6):
  time: Rename udelay_test.c to test_udelay.c
  time: Expose getrawmonotonic64 for in-kernel uses
  time: Expose get_monotonic_corase64() for in-kernel uses
  time: Fixup comments to reflect usage of timespec64
  rtc: Update suspend/resume timing to use 64bit time
  time: Remove timekeeping_inject_sleeptime()

pang.xunlei (6):
  time: Avoid possible NTP adjustment mult overflow.
  time: Complete NTP adjustment threshold judging conditions
  time: Provide y2038 safe do_settimeofday() replacement
  time: Provide y2038 safe timekeeping_inject_sleeptime() replacement
  time: Provide y2038 safe mktime() replacement
  rtc/lib: Provide y2038 safe rtc_tm_to_time()/rtc_time_to_tm()
    replacement


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

* [PATCH 01/12] time: Rename udelay_test.c to test_udelay.c
  2014-11-21 19:44 [PATCH 00/12] John Stultz
@ 2014-11-21 19:44 ` John Stultz
  2014-11-21 23:30   ` Kees Cook
  2014-11-24 22:14   ` David Riley
  2014-11-21 19:44 ` [PATCH 02/12] time: Avoid possible NTP adjustment mult overflow John Stultz
                   ` (11 subsequent siblings)
  12 siblings, 2 replies; 19+ messages in thread
From: John Stultz @ 2014-11-21 19:44 UTC (permalink / raw)
  To: lkml
  Cc: John Stultz, Kees Cook, Greg KH, Stephen Rothwell,
	Thomas Gleixner, Ingo Molnar, Linux-Next, David Riley

Kees requested that this test module be renamed for consistency sake,
so this patch renames the udelay_test.c file (recently added to
tip/timers/core for 3.17) to test_udelay.c

Cc: Kees Cook <keescook@chromium.org>
Cc: Greg KH <greg@kroah.com>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Linux-Next <linux-next@vger.kernel.org>
Cc: David Riley <davidriley@chromium.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 kernel/time/Makefile      |   2 +-
 kernel/time/test_udelay.c | 168 ++++++++++++++++++++++++++++++++++++++++++++++
 kernel/time/udelay_test.c | 168 ----------------------------------------------
 3 files changed, 169 insertions(+), 169 deletions(-)
 create mode 100644 kernel/time/test_udelay.c
 delete mode 100644 kernel/time/udelay_test.c

diff --git a/kernel/time/Makefile b/kernel/time/Makefile
index 7347426..f622cf2 100644
--- a/kernel/time/Makefile
+++ b/kernel/time/Makefile
@@ -13,7 +13,7 @@ obj-$(CONFIG_TICK_ONESHOT)			+= tick-oneshot.o
 obj-$(CONFIG_TICK_ONESHOT)			+= tick-sched.o
 obj-$(CONFIG_TIMER_STATS)			+= timer_stats.o
 obj-$(CONFIG_DEBUG_FS)				+= timekeeping_debug.o
-obj-$(CONFIG_TEST_UDELAY)			+= udelay_test.o
+obj-$(CONFIG_TEST_UDELAY)			+= test_udelay.o
 
 $(obj)/time.o: $(obj)/timeconst.h
 
diff --git a/kernel/time/test_udelay.c b/kernel/time/test_udelay.c
new file mode 100644
index 0000000..e622ba3
--- /dev/null
+++ b/kernel/time/test_udelay.c
@@ -0,0 +1,168 @@
+/*
+ * udelay() test kernel module
+ *
+ * Test is executed by writing and reading to /sys/kernel/debug/udelay_test
+ * Tests are configured by writing: USECS ITERATIONS
+ * Tests are executed by reading from the same file.
+ * Specifying usecs of 0 or negative values will run multiples tests.
+ *
+ * Copyright (C) 2014 Google, Inc.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/debugfs.h>
+#include <linux/delay.h>
+#include <linux/ktime.h>
+#include <linux/module.h>
+#include <linux/uaccess.h>
+
+#define DEFAULT_ITERATIONS 100
+
+#define DEBUGFS_FILENAME "udelay_test"
+
+static DEFINE_MUTEX(udelay_test_lock);
+static struct dentry *udelay_test_debugfs_file;
+static int udelay_test_usecs;
+static int udelay_test_iterations = DEFAULT_ITERATIONS;
+
+static int udelay_test_single(struct seq_file *s, int usecs, uint32_t iters)
+{
+	int min = 0, max = 0, fail_count = 0;
+	uint64_t sum = 0;
+	uint64_t avg;
+	int i;
+	/* Allow udelay to be up to 0.5% fast */
+	int allowed_error_ns = usecs * 5;
+
+	for (i = 0; i < iters; ++i) {
+		struct timespec ts1, ts2;
+		int time_passed;
+
+		ktime_get_ts(&ts1);
+		udelay(usecs);
+		ktime_get_ts(&ts2);
+		time_passed = timespec_to_ns(&ts2) - timespec_to_ns(&ts1);
+
+		if (i == 0 || time_passed < min)
+			min = time_passed;
+		if (i == 0 || time_passed > max)
+			max = time_passed;
+		if ((time_passed + allowed_error_ns) / 1000 < usecs)
+			++fail_count;
+		WARN_ON(time_passed < 0);
+		sum += time_passed;
+	}
+
+	avg = sum;
+	do_div(avg, iters);
+	seq_printf(s, "%d usecs x %d: exp=%d allowed=%d min=%d avg=%lld max=%d",
+			usecs, iters, usecs * 1000,
+			(usecs * 1000) - allowed_error_ns, min, avg, max);
+	if (fail_count)
+		seq_printf(s, " FAIL=%d", fail_count);
+	seq_puts(s, "\n");
+
+	return 0;
+}
+
+static int udelay_test_show(struct seq_file *s, void *v)
+{
+	int usecs;
+	int iters;
+	int ret = 0;
+
+	mutex_lock(&udelay_test_lock);
+	usecs = udelay_test_usecs;
+	iters = udelay_test_iterations;
+	mutex_unlock(&udelay_test_lock);
+
+	if (usecs > 0 && iters > 0) {
+		return udelay_test_single(s, usecs, iters);
+	} else if (usecs == 0) {
+		struct timespec ts;
+
+		ktime_get_ts(&ts);
+		seq_printf(s, "udelay() test (lpj=%ld kt=%ld.%09ld)\n",
+				loops_per_jiffy, ts.tv_sec, ts.tv_nsec);
+		seq_puts(s, "usage:\n");
+		seq_puts(s, "echo USECS [ITERS] > " DEBUGFS_FILENAME "\n");
+		seq_puts(s, "cat " DEBUGFS_FILENAME "\n");
+	}
+
+	return ret;
+}
+
+static int udelay_test_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, udelay_test_show, inode->i_private);
+}
+
+static ssize_t udelay_test_write(struct file *file, const char __user *buf,
+		size_t count, loff_t *pos)
+{
+	char lbuf[32];
+	int ret;
+	int usecs;
+	int iters;
+
+	if (count >= sizeof(lbuf))
+		return -EINVAL;
+
+	if (copy_from_user(lbuf, buf, count))
+		return -EFAULT;
+	lbuf[count] = '\0';
+
+	ret = sscanf(lbuf, "%d %d", &usecs, &iters);
+	if (ret < 1)
+		return -EINVAL;
+	else if (ret < 2)
+		iters = DEFAULT_ITERATIONS;
+
+	mutex_lock(&udelay_test_lock);
+	udelay_test_usecs = usecs;
+	udelay_test_iterations = iters;
+	mutex_unlock(&udelay_test_lock);
+
+	return count;
+}
+
+static const struct file_operations udelay_test_debugfs_ops = {
+	.owner = THIS_MODULE,
+	.open = udelay_test_open,
+	.read = seq_read,
+	.write = udelay_test_write,
+	.llseek = seq_lseek,
+	.release = single_release,
+};
+
+static int __init udelay_test_init(void)
+{
+	mutex_lock(&udelay_test_lock);
+	udelay_test_debugfs_file = debugfs_create_file(DEBUGFS_FILENAME,
+			S_IRUSR, NULL, NULL, &udelay_test_debugfs_ops);
+	mutex_unlock(&udelay_test_lock);
+
+	return 0;
+}
+
+module_init(udelay_test_init);
+
+static void __exit udelay_test_exit(void)
+{
+	mutex_lock(&udelay_test_lock);
+	debugfs_remove(udelay_test_debugfs_file);
+	mutex_unlock(&udelay_test_lock);
+}
+
+module_exit(udelay_test_exit);
+
+MODULE_AUTHOR("David Riley <davidriley@chromium.org>");
+MODULE_LICENSE("GPL");
diff --git a/kernel/time/udelay_test.c b/kernel/time/udelay_test.c
deleted file mode 100644
index e622ba3..0000000
--- a/kernel/time/udelay_test.c
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * udelay() test kernel module
- *
- * Test is executed by writing and reading to /sys/kernel/debug/udelay_test
- * Tests are configured by writing: USECS ITERATIONS
- * Tests are executed by reading from the same file.
- * Specifying usecs of 0 or negative values will run multiples tests.
- *
- * Copyright (C) 2014 Google, Inc.
- *
- * This software is licensed under the terms of the GNU General Public
- * License version 2, as published by the Free Software Foundation, and
- * may be copied, distributed, and modified under those terms.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- */
-
-#include <linux/debugfs.h>
-#include <linux/delay.h>
-#include <linux/ktime.h>
-#include <linux/module.h>
-#include <linux/uaccess.h>
-
-#define DEFAULT_ITERATIONS 100
-
-#define DEBUGFS_FILENAME "udelay_test"
-
-static DEFINE_MUTEX(udelay_test_lock);
-static struct dentry *udelay_test_debugfs_file;
-static int udelay_test_usecs;
-static int udelay_test_iterations = DEFAULT_ITERATIONS;
-
-static int udelay_test_single(struct seq_file *s, int usecs, uint32_t iters)
-{
-	int min = 0, max = 0, fail_count = 0;
-	uint64_t sum = 0;
-	uint64_t avg;
-	int i;
-	/* Allow udelay to be up to 0.5% fast */
-	int allowed_error_ns = usecs * 5;
-
-	for (i = 0; i < iters; ++i) {
-		struct timespec ts1, ts2;
-		int time_passed;
-
-		ktime_get_ts(&ts1);
-		udelay(usecs);
-		ktime_get_ts(&ts2);
-		time_passed = timespec_to_ns(&ts2) - timespec_to_ns(&ts1);
-
-		if (i == 0 || time_passed < min)
-			min = time_passed;
-		if (i == 0 || time_passed > max)
-			max = time_passed;
-		if ((time_passed + allowed_error_ns) / 1000 < usecs)
-			++fail_count;
-		WARN_ON(time_passed < 0);
-		sum += time_passed;
-	}
-
-	avg = sum;
-	do_div(avg, iters);
-	seq_printf(s, "%d usecs x %d: exp=%d allowed=%d min=%d avg=%lld max=%d",
-			usecs, iters, usecs * 1000,
-			(usecs * 1000) - allowed_error_ns, min, avg, max);
-	if (fail_count)
-		seq_printf(s, " FAIL=%d", fail_count);
-	seq_puts(s, "\n");
-
-	return 0;
-}
-
-static int udelay_test_show(struct seq_file *s, void *v)
-{
-	int usecs;
-	int iters;
-	int ret = 0;
-
-	mutex_lock(&udelay_test_lock);
-	usecs = udelay_test_usecs;
-	iters = udelay_test_iterations;
-	mutex_unlock(&udelay_test_lock);
-
-	if (usecs > 0 && iters > 0) {
-		return udelay_test_single(s, usecs, iters);
-	} else if (usecs == 0) {
-		struct timespec ts;
-
-		ktime_get_ts(&ts);
-		seq_printf(s, "udelay() test (lpj=%ld kt=%ld.%09ld)\n",
-				loops_per_jiffy, ts.tv_sec, ts.tv_nsec);
-		seq_puts(s, "usage:\n");
-		seq_puts(s, "echo USECS [ITERS] > " DEBUGFS_FILENAME "\n");
-		seq_puts(s, "cat " DEBUGFS_FILENAME "\n");
-	}
-
-	return ret;
-}
-
-static int udelay_test_open(struct inode *inode, struct file *file)
-{
-	return single_open(file, udelay_test_show, inode->i_private);
-}
-
-static ssize_t udelay_test_write(struct file *file, const char __user *buf,
-		size_t count, loff_t *pos)
-{
-	char lbuf[32];
-	int ret;
-	int usecs;
-	int iters;
-
-	if (count >= sizeof(lbuf))
-		return -EINVAL;
-
-	if (copy_from_user(lbuf, buf, count))
-		return -EFAULT;
-	lbuf[count] = '\0';
-
-	ret = sscanf(lbuf, "%d %d", &usecs, &iters);
-	if (ret < 1)
-		return -EINVAL;
-	else if (ret < 2)
-		iters = DEFAULT_ITERATIONS;
-
-	mutex_lock(&udelay_test_lock);
-	udelay_test_usecs = usecs;
-	udelay_test_iterations = iters;
-	mutex_unlock(&udelay_test_lock);
-
-	return count;
-}
-
-static const struct file_operations udelay_test_debugfs_ops = {
-	.owner = THIS_MODULE,
-	.open = udelay_test_open,
-	.read = seq_read,
-	.write = udelay_test_write,
-	.llseek = seq_lseek,
-	.release = single_release,
-};
-
-static int __init udelay_test_init(void)
-{
-	mutex_lock(&udelay_test_lock);
-	udelay_test_debugfs_file = debugfs_create_file(DEBUGFS_FILENAME,
-			S_IRUSR, NULL, NULL, &udelay_test_debugfs_ops);
-	mutex_unlock(&udelay_test_lock);
-
-	return 0;
-}
-
-module_init(udelay_test_init);
-
-static void __exit udelay_test_exit(void)
-{
-	mutex_lock(&udelay_test_lock);
-	debugfs_remove(udelay_test_debugfs_file);
-	mutex_unlock(&udelay_test_lock);
-}
-
-module_exit(udelay_test_exit);
-
-MODULE_AUTHOR("David Riley <davidriley@chromium.org>");
-MODULE_LICENSE("GPL");
-- 
1.9.1


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

* [PATCH 02/12] time: Avoid possible NTP adjustment mult overflow.
  2014-11-21 19:44 [PATCH 00/12] John Stultz
  2014-11-21 19:44 ` [PATCH 01/12] time: Rename udelay_test.c to test_udelay.c John Stultz
@ 2014-11-21 19:44 ` John Stultz
  2014-11-21 19:44 ` [PATCH 03/12] time: Complete NTP adjustment threshold judging conditions John Stultz
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: John Stultz @ 2014-11-21 19:44 UTC (permalink / raw)
  To: lkml
  Cc: pang.xunlei, Thomas Gleixner, Ingo Molnar, Arnd Bergmann,
	Miroslav Lichvar, Richard Cochran, Prarit Bhargava,
	Alessandro Zummo, John Stultz

From: "pang.xunlei" <pang.xunlei@linaro.org>

Ideally, __clocksource_updatefreq_scale, selects the largest shift
value possible for a clocksource. This results in the mult memember of
struct clocksource being particularly large, although not so large
that NTP would adjust the clock to cause it to overflow.

That said, nothing actually prohibits an overflow from occuring, its
just that it "shouldn't" occur.

So while very unlikely, and so far never observed, the value of
(cs->mult+cs->maxadj) may have a chance to reach very near 0xFFFFFFFF,
so there is a possibility it may overflow when doing NTP positive
adjustment

See the following detail: When NTP slewes the clock, kernel goes
through update_wall_time()->...->timekeeping_apply_adjustment():
	tk->tkr.mult += mult_adj;

Since there is no guard against it, its possible tk->tkr.mult may
overflow during this operation.

This patch avoids any possible mult overflow by judging the overflow
case before adding mult_adj to mult, also adds the WARNING message
when capturing such case.

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Arnd Bergmann <arnd.bergmann@linaro.org>
Cc: pang.xunlei <pang.xunlei@linaro.org>
Cc: Miroslav Lichvar <mlichvar@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: pang.xunlei <pang.xunlei@linaro.org>
[jstultz: Reworded commit message]
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 kernel/time/timekeeping.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index ec1791f..cad61b3 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -1332,6 +1332,12 @@ static __always_inline void timekeeping_apply_adjustment(struct timekeeper *tk,
 	 *
 	 * XXX - TODO: Doc ntp_error calculation.
 	 */
+	if (tk->tkr.mult + mult_adj < mult_adj) {
+		/* NTP adjustment caused clocksource mult overflow */
+		WARN_ON_ONCE(1);
+		return;
+	}
+
 	tk->tkr.mult += mult_adj;
 	tk->xtime_interval += interval;
 	tk->tkr.xtime_nsec -= offset;
-- 
1.9.1


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

* [PATCH 03/12] time: Complete NTP adjustment threshold judging conditions
  2014-11-21 19:44 [PATCH 00/12] John Stultz
  2014-11-21 19:44 ` [PATCH 01/12] time: Rename udelay_test.c to test_udelay.c John Stultz
  2014-11-21 19:44 ` [PATCH 02/12] time: Avoid possible NTP adjustment mult overflow John Stultz
@ 2014-11-21 19:44 ` John Stultz
  2014-11-21 19:44 ` [PATCH 04/12] time: Provide y2038 safe do_settimeofday() replacement John Stultz
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: John Stultz @ 2014-11-21 19:44 UTC (permalink / raw)
  To: lkml
  Cc: pang.xunlei, Thomas Gleixner, Ingo Molnar, Arnd Bergmann,
	Miroslav Lichvar, Richard Cochran, Prarit Bhargava,
	Alessandro Zummo, John Stultz

From: "pang.xunlei" <pang.xunlei@linaro.org>

The clocksource mult-adjustment threshold is [mult-maxadj, mult+maxadj],
timekeeping_adjust() only deals with the upper threshold, but misses the
lower threshold.

This patch adds the lower threshold judging condition.

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Arnd Bergmann <arnd.bergmann@linaro.org>
Cc: pang.xunlei <pang.xunlei@linaro.org>
Cc: Miroslav Lichvar <mlichvar@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: pang.xunlei <pang.xunlei@linaro.org>
[jstultz: Minor fix for > 80 char line]
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 kernel/time/timekeeping.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index cad61b3..41fcbe1 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -1403,7 +1403,8 @@ static void timekeeping_adjust(struct timekeeper *tk, s64 offset)
 	}
 
 	if (unlikely(tk->tkr.clock->maxadj &&
-		(tk->tkr.mult > tk->tkr.clock->mult + tk->tkr.clock->maxadj))) {
+		(abs(tk->tkr.mult - tk->tkr.clock->mult)
+			> tk->tkr.clock->maxadj))) {
 		printk_once(KERN_WARNING
 			"Adjusting %s more than 11%% (%ld vs %ld)\n",
 			tk->tkr.clock->name, (long)tk->tkr.mult,
-- 
1.9.1


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

* [PATCH 04/12] time: Provide y2038 safe do_settimeofday() replacement
  2014-11-21 19:44 [PATCH 00/12] John Stultz
                   ` (2 preceding siblings ...)
  2014-11-21 19:44 ` [PATCH 03/12] time: Complete NTP adjustment threshold judging conditions John Stultz
@ 2014-11-21 19:44 ` John Stultz
  2014-11-21 19:44 ` [PATCH 05/12] time: Provide y2038 safe timekeeping_inject_sleeptime() replacement John Stultz
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: John Stultz @ 2014-11-21 19:44 UTC (permalink / raw)
  To: lkml
  Cc: pang.xunlei, Thomas Gleixner, Ingo Molnar, Arnd Bergmann,
	Miroslav Lichvar, Richard Cochran, Prarit Bhargava,
	Alessandro Zummo, John Stultz

From: "pang.xunlei" <pang.xunlei@linaro.org>

The kernel uses 32-bit signed value(time_t) for seconds elapsed
1970-01-01:00:00:00, thus it will overflow at 2038-01-19 03:14:08
on 32-bit systems. This is widely known as the y2038 problem.

As part of addressing "y2038 problem" for in-kernel uses, this patch
adds safe do_settimeofday64() using timespec64.

After this patch, do_settimeofday() is deprecated and all its call
sites will be fixed using do_settimeofday64(), after that it can be
removed.

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Arnd Bergmann <arnd.bergmann@linaro.org>
Cc: pang.xunlei <pang.xunlei@linaro.org>
Cc: Miroslav Lichvar <mlichvar@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: pang.xunlei <pang.xunlei@linaro.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 include/linux/timekeeping.h | 21 ++++++++++++++++++++-
 kernel/time/timekeeping.c   | 19 +++++++++----------
 2 files changed, 29 insertions(+), 11 deletions(-)

diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h
index 1caa6b0..071ad7e 100644
--- a/include/linux/timekeeping.h
+++ b/include/linux/timekeeping.h
@@ -10,7 +10,7 @@ extern int timekeeping_suspended;
  * Get and set timeofday
  */
 extern void do_gettimeofday(struct timeval *tv);
-extern int do_settimeofday(const struct timespec *tv);
+extern int do_settimeofday64(const struct timespec64 *ts);
 extern int do_sys_settimeofday(const struct timespec *tv,
 			       const struct timezone *tz);
 
@@ -33,6 +33,14 @@ extern int __getnstimeofday64(struct timespec64 *tv);
 extern void getnstimeofday64(struct timespec64 *tv);
 
 #if BITS_PER_LONG == 64
+/**
+ * Deprecated. Use do_settimeofday64().
+ */
+static inline int do_settimeofday(const struct timespec *ts)
+{
+	return do_settimeofday64(ts);
+}
+
 static inline int __getnstimeofday(struct timespec *ts)
 {
 	return __getnstimeofday64(ts);
@@ -54,6 +62,17 @@ static inline void ktime_get_real_ts(struct timespec *ts)
 }
 
 #else
+/**
+ * Deprecated. Use do_settimeofday64().
+ */
+static inline int do_settimeofday(const struct timespec *ts)
+{
+	struct timespec64 ts64;
+
+	ts64 = timespec_to_timespec64(*ts);
+	return do_settimeofday64(&ts64);
+}
+
 static inline int __getnstimeofday(struct timespec *ts)
 {
 	struct timespec64 ts64;
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index ec1791f..1d33550 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -703,18 +703,18 @@ void do_gettimeofday(struct timeval *tv)
 EXPORT_SYMBOL(do_gettimeofday);
 
 /**
- * do_settimeofday - Sets the time of day
- * @tv:		pointer to the timespec variable containing the new time
+ * do_settimeofday64 - Sets the time of day.
+ * @ts:     pointer to the timespec64 variable containing the new time
  *
  * Sets the time of day to the new time and update NTP and notify hrtimers
  */
-int do_settimeofday(const struct timespec *tv)
+int do_settimeofday64(const struct timespec64 *ts)
 {
 	struct timekeeper *tk = &tk_core.timekeeper;
-	struct timespec64 ts_delta, xt, tmp;
+	struct timespec64 ts_delta, xt;
 	unsigned long flags;
 
-	if (!timespec_valid_strict(tv))
+	if (!timespec64_valid_strict(ts))
 		return -EINVAL;
 
 	raw_spin_lock_irqsave(&timekeeper_lock, flags);
@@ -723,13 +723,12 @@ int do_settimeofday(const struct timespec *tv)
 	timekeeping_forward_now(tk);
 
 	xt = tk_xtime(tk);
-	ts_delta.tv_sec = tv->tv_sec - xt.tv_sec;
-	ts_delta.tv_nsec = tv->tv_nsec - xt.tv_nsec;
+	ts_delta.tv_sec = ts->tv_sec - xt.tv_sec;
+	ts_delta.tv_nsec = ts->tv_nsec - xt.tv_nsec;
 
 	tk_set_wall_to_mono(tk, timespec64_sub(tk->wall_to_monotonic, ts_delta));
 
-	tmp = timespec_to_timespec64(*tv);
-	tk_set_xtime(tk, &tmp);
+	tk_set_xtime(tk, ts);
 
 	timekeeping_update(tk, TK_CLEAR_NTP | TK_MIRROR | TK_CLOCK_WAS_SET);
 
@@ -741,7 +740,7 @@ int do_settimeofday(const struct timespec *tv)
 
 	return 0;
 }
-EXPORT_SYMBOL(do_settimeofday);
+EXPORT_SYMBOL(do_settimeofday64);
 
 /**
  * timekeeping_inject_offset - Adds or subtracts from the current time.
-- 
1.9.1


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

* [PATCH 05/12] time: Provide y2038 safe timekeeping_inject_sleeptime() replacement
  2014-11-21 19:44 [PATCH 00/12] John Stultz
                   ` (3 preceding siblings ...)
  2014-11-21 19:44 ` [PATCH 04/12] time: Provide y2038 safe do_settimeofday() replacement John Stultz
@ 2014-11-21 19:44 ` John Stultz
  2014-11-21 19:44 ` [PATCH 06/12] time: Provide y2038 safe mktime() replacement John Stultz
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: John Stultz @ 2014-11-21 19:44 UTC (permalink / raw)
  To: lkml
  Cc: pang.xunlei, Thomas Gleixner, Ingo Molnar, Arnd Bergmann,
	Miroslav Lichvar, Richard Cochran, Prarit Bhargava,
	Alessandro Zummo, John Stultz

From: "pang.xunlei" <pang.xunlei@linaro.org>

As part of addressing "y2038 problem" for in-kernel uses, this
patch adds timekeeping_inject_sleeptime64() using timespec64.

After this patch, timekeeping_inject_sleeptime() is deprecated
and all its call sites will be fixed using the new interface,
after that it can be removed.

NOTE: timekeeping_inject_sleeptime() is safe actually, but we
want to eliminate timespec eventually, so comes this patch.

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Arnd Bergmann <arnd.bergmann@linaro.org>
Cc: pang.xunlei <pang.xunlei@linaro.org>
Cc: Miroslav Lichvar <mlichvar@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: pang.xunlei <pang.xunlei@linaro.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 include/linux/timekeeping.h | 13 ++++++++++++-
 kernel/time/timekeeping.c   | 10 ++++------
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h
index 071ad7e..6d76c65 100644
--- a/include/linux/timekeeping.h
+++ b/include/linux/timekeeping.h
@@ -201,7 +201,18 @@ static inline void timekeeping_clocktai(struct timespec *ts)
 /*
  * RTC specific
  */
-extern void timekeeping_inject_sleeptime(struct timespec *delta);
+extern void timekeeping_inject_sleeptime64(struct timespec64 *delta);
+
+/**
+ * Deprecated. Use timekeeping_inject_sleeptime64().
+ */
+static inline void timekeeping_inject_sleeptime(struct timespec *delta)
+{
+	struct timespec64 delta64;
+
+	delta64 = timespec_to_timespec64(*delta);
+	timekeeping_inject_sleeptime64(&delta64);
+}
 
 /*
  * PPS accessor
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 1d33550..d37f775 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -1067,8 +1067,8 @@ static void __timekeeping_inject_sleeptime(struct timekeeper *tk,
 }
 
 /**
- * timekeeping_inject_sleeptime - Adds suspend interval to timeekeeping values
- * @delta: pointer to a timespec delta value
+ * timekeeping_inject_sleeptime64 - Adds suspend interval to timeekeeping values
+ * @delta: pointer to a timespec64 delta value
  *
  * This hook is for architectures that cannot support read_persistent_clock
  * because their RTC/persistent clock is only accessible when irqs are enabled.
@@ -1076,10 +1076,9 @@ static void __timekeeping_inject_sleeptime(struct timekeeper *tk,
  * This function should only be called by rtc_resume(), and allows
  * a suspend offset to be injected into the timekeeping values.
  */
-void timekeeping_inject_sleeptime(struct timespec *delta)
+void timekeeping_inject_sleeptime64(struct timespec64 *delta)
 {
 	struct timekeeper *tk = &tk_core.timekeeper;
-	struct timespec64 tmp;
 	unsigned long flags;
 
 	/*
@@ -1094,8 +1093,7 @@ void timekeeping_inject_sleeptime(struct timespec *delta)
 
 	timekeeping_forward_now(tk);
 
-	tmp = timespec_to_timespec64(*delta);
-	__timekeeping_inject_sleeptime(tk, &tmp);
+	__timekeeping_inject_sleeptime(tk, delta);
 
 	timekeeping_update(tk, TK_CLEAR_NTP | TK_MIRROR | TK_CLOCK_WAS_SET);
 
-- 
1.9.1


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

* [PATCH 06/12] time: Provide y2038 safe mktime() replacement
  2014-11-21 19:44 [PATCH 00/12] John Stultz
                   ` (4 preceding siblings ...)
  2014-11-21 19:44 ` [PATCH 05/12] time: Provide y2038 safe timekeeping_inject_sleeptime() replacement John Stultz
@ 2014-11-21 19:44 ` John Stultz
  2014-11-21 19:44 ` [PATCH 07/12] time: Expose getrawmonotonic64 for in-kernel uses John Stultz
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: John Stultz @ 2014-11-21 19:44 UTC (permalink / raw)
  To: lkml
  Cc: pang.xunlei, Thomas Gleixner, Ingo Molnar, Arnd Bergmann,
	Miroslav Lichvar, Richard Cochran, Prarit Bhargava,
	Alessandro Zummo, John Stultz

From: "pang.xunlei" <pang.xunlei@linaro.org>

As part of addressing "y2038 problem" for in-kernel uses, this
patch adds safe mktime64() using time64_t.

After this patch, mktime() is deprecated and all its call sites
will be fixed using mktime64(), after that it can be removed.

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Arnd Bergmann <arnd.bergmann@linaro.org>
Cc: pang.xunlei <pang.xunlei@linaro.org>
Cc: Miroslav Lichvar <mlichvar@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: pang.xunlei <pang.xunlei@linaro.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 include/linux/time.h | 17 ++++++++++++++---
 kernel/time/time.c   | 20 ++++++++------------
 2 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/include/linux/time.h b/include/linux/time.h
index 8c42cf8..203c2ad 100644
--- a/include/linux/time.h
+++ b/include/linux/time.h
@@ -39,9 +39,20 @@ static inline int timeval_compare(const struct timeval *lhs, const struct timeva
 	return lhs->tv_usec - rhs->tv_usec;
 }
 
-extern unsigned long mktime(const unsigned int year, const unsigned int mon,
-			    const unsigned int day, const unsigned int hour,
-			    const unsigned int min, const unsigned int sec);
+extern time64_t mktime64(const unsigned int year, const unsigned int mon,
+			const unsigned int day, const unsigned int hour,
+			const unsigned int min, const unsigned int sec);
+
+/**
+ * Deprecated. Use mktime64().
+ */
+static inline unsigned long mktime(const unsigned int year,
+			const unsigned int mon, const unsigned int day,
+			const unsigned int hour, const unsigned int min,
+			const unsigned int sec)
+{
+	return mktime64(year, mon, day, hour, min, sec);
+}
 
 extern void set_normalized_timespec(struct timespec *ts, time_t sec, s64 nsec);
 
diff --git a/kernel/time/time.c b/kernel/time/time.c
index a9ae20f..65015ff 100644
--- a/kernel/time/time.c
+++ b/kernel/time/time.c
@@ -304,7 +304,9 @@ struct timespec timespec_trunc(struct timespec t, unsigned gran)
 }
 EXPORT_SYMBOL(timespec_trunc);
 
-/* Converts Gregorian date to seconds since 1970-01-01 00:00:00.
+/*
+ * mktime64 - Converts date to seconds.
+ * Converts Gregorian date to seconds since 1970-01-01 00:00:00.
  * Assumes input in normal date format, i.e. 1980-12-31 23:59:59
  * => year=1980, mon=12, day=31, hour=23, min=59, sec=59.
  *
@@ -314,15 +316,10 @@ EXPORT_SYMBOL(timespec_trunc);
  * -year/100+year/400 terms, and add 10.]
  *
  * This algorithm was first published by Gauss (I think).
- *
- * WARNING: this function will overflow on 2106-02-07 06:28:16 on
- * machines where long is 32-bit! (However, as time_t is signed, we
- * will already get problems at other places on 2038-01-19 03:14:08)
  */
-unsigned long
-mktime(const unsigned int year0, const unsigned int mon0,
-       const unsigned int day, const unsigned int hour,
-       const unsigned int min, const unsigned int sec)
+time64_t mktime64(const unsigned int year0, const unsigned int mon0,
+		const unsigned int day, const unsigned int hour,
+		const unsigned int min, const unsigned int sec)
 {
 	unsigned int mon = mon0, year = year0;
 
@@ -332,15 +329,14 @@ mktime(const unsigned int year0, const unsigned int mon0,
 		year -= 1;
 	}
 
-	return ((((unsigned long)
+	return ((((time64_t)
 		  (year/4 - year/100 + year/400 + 367*mon/12 + day) +
 		  year*365 - 719499
 	    )*24 + hour /* now have hours */
 	  )*60 + min /* now have minutes */
 	)*60 + sec; /* finally seconds */
 }
-
-EXPORT_SYMBOL(mktime);
+EXPORT_SYMBOL(mktime64);
 
 /**
  * set_normalized_timespec - set timespec sec and nsec parts and normalize
-- 
1.9.1


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

* [PATCH 07/12] time: Expose getrawmonotonic64 for in-kernel uses
  2014-11-21 19:44 [PATCH 00/12] John Stultz
                   ` (5 preceding siblings ...)
  2014-11-21 19:44 ` [PATCH 06/12] time: Provide y2038 safe mktime() replacement John Stultz
@ 2014-11-21 19:44 ` John Stultz
  2014-11-21 19:44 ` [PATCH 08/12] time: Expose get_monotonic_corase64() " John Stultz
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: John Stultz @ 2014-11-21 19:44 UTC (permalink / raw)
  To: lkml
  Cc: John Stultz, Thomas Gleixner, Ingo Molnar, Arnd Bergmann,
	pang.xunlei, Miroslav Lichvar, Richard Cochran, Prarit Bhargava,
	Alessandro Zummo

Adds a timespec64 based getrawmonotonic64() implementation
that can be used as we convert internal users of
getrawmonotonic away from using timespecs.

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Arnd Bergmann <arnd.bergmann@linaro.org>
Cc: pang.xunlei <pang.xunlei@linaro.org>
Cc: Miroslav Lichvar <mlichvar@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 include/linux/timekeeping.h | 15 ++++++++++++++-
 kernel/time/timekeeping.c   | 11 ++++++-----
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h
index 6d76c65..e40a8d6 100644
--- a/include/linux/timekeeping.h
+++ b/include/linux/timekeeping.h
@@ -26,7 +26,7 @@ struct timespec __current_kernel_time(void);
  * timespec based interfaces
  */
 struct timespec get_monotonic_coarse(void);
-extern void getrawmonotonic(struct timespec *ts);
+extern void getrawmonotonic64(struct timespec64 *ts);
 extern void ktime_get_ts64(struct timespec64 *ts);
 
 extern int __getnstimeofday64(struct timespec64 *tv);
@@ -61,6 +61,11 @@ static inline void ktime_get_real_ts(struct timespec *ts)
 	getnstimeofday64(ts);
 }
 
+static inline void getrawmonotonic(struct timespec *ts)
+{
+	getrawmonotonic64(ts);
+}
+
 #else
 /**
  * Deprecated. Use do_settimeofday64().
@@ -105,6 +110,14 @@ static inline void ktime_get_real_ts(struct timespec *ts)
 	getnstimeofday64(&ts64);
 	*ts = timespec64_to_timespec(ts64);
 }
+
+static inline void getrawmonotonic(struct timespec *ts)
+{
+	struct timespec64 ts64;
+
+	getrawmonotonic64(&ts64);
+	*ts = timespec64_to_timespec(ts64);
+}
 #endif
 
 extern void getboottime(struct timespec *ts);
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index d37f775..b329586 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -894,12 +894,12 @@ int timekeeping_notify(struct clocksource *clock)
 }
 
 /**
- * getrawmonotonic - Returns the raw monotonic time in a timespec
- * @ts:		pointer to the timespec to be set
+ * getrawmonotonic64 - Returns the raw monotonic time in a timespec
+ * @ts:		pointer to the timespec64 to be set
  *
  * Returns the raw monotonic time (completely un-modified by ntp)
  */
-void getrawmonotonic(struct timespec *ts)
+void getrawmonotonic64(struct timespec64 *ts)
 {
 	struct timekeeper *tk = &tk_core.timekeeper;
 	struct timespec64 ts64;
@@ -914,9 +914,10 @@ void getrawmonotonic(struct timespec *ts)
 	} while (read_seqcount_retry(&tk_core.seq, seq));
 
 	timespec64_add_ns(&ts64, nsecs);
-	*ts = timespec64_to_timespec(ts64);
+	*ts = ts64;
 }
-EXPORT_SYMBOL(getrawmonotonic);
+EXPORT_SYMBOL(getrawmonotonic64);
+
 
 /**
  * timekeeping_valid_for_hres - Check if timekeeping is suitable for hres
-- 
1.9.1


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

* [PATCH 08/12] time: Expose get_monotonic_corase64() for in-kernel uses
  2014-11-21 19:44 [PATCH 00/12] John Stultz
                   ` (6 preceding siblings ...)
  2014-11-21 19:44 ` [PATCH 07/12] time: Expose getrawmonotonic64 for in-kernel uses John Stultz
@ 2014-11-21 19:44 ` John Stultz
  2014-11-21 19:44 ` [PATCH 09/12] time: Fixup comments to reflect usage of timespec64 John Stultz
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: John Stultz @ 2014-11-21 19:44 UTC (permalink / raw)
  To: lkml
  Cc: John Stultz, Thomas Gleixner, Ingo Molnar, Arnd Bergmann,
	pang.xunlei, Miroslav Lichvar, Richard Cochran, Prarit Bhargava,
	Alessandro Zummo

Adds a timespec64 based get_monotonic_coarse64() implementation
that can be used as we convert internal users of
get_monotonic_corase away from usingtimespecs.

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Arnd Bergmann <arnd.bergmann@linaro.org>
Cc: pang.xunlei <pang.xunlei@linaro.org>
Cc: Miroslav Lichvar <mlichvar@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 include/linux/timekeeping.h | 11 ++++++++++-
 kernel/time/timekeeping.c   |  4 ++--
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h
index e40a8d6..8cab4b7 100644
--- a/include/linux/timekeeping.h
+++ b/include/linux/timekeeping.h
@@ -25,7 +25,7 @@ struct timespec __current_kernel_time(void);
 /*
  * timespec based interfaces
  */
-struct timespec get_monotonic_coarse(void);
+struct timespec64 get_monotonic_coarse64(void);
 extern void getrawmonotonic64(struct timespec64 *ts);
 extern void ktime_get_ts64(struct timespec64 *ts);
 
@@ -66,6 +66,10 @@ static inline void getrawmonotonic(struct timespec *ts)
 	getrawmonotonic64(ts);
 }
 
+static inline struct timespec get_monotonic_coarse(void)
+{
+	return get_monotonic_coarse64();
+}
 #else
 /**
  * Deprecated. Use do_settimeofday64().
@@ -118,6 +122,11 @@ static inline void getrawmonotonic(struct timespec *ts)
 	getrawmonotonic64(&ts64);
 	*ts = timespec64_to_timespec(ts64);
 }
+
+static inline struct timespec get_monotonic_coarse(void)
+{
+	return timespec64_to_timespec(get_monotonic_coarse64());
+}
 #endif
 
 extern void getboottime(struct timespec *ts);
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index b329586..62440b1 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -1644,7 +1644,7 @@ struct timespec current_kernel_time(void)
 }
 EXPORT_SYMBOL(current_kernel_time);
 
-struct timespec get_monotonic_coarse(void)
+struct timespec64 get_monotonic_coarse64(void)
 {
 	struct timekeeper *tk = &tk_core.timekeeper;
 	struct timespec64 now, mono;
@@ -1660,7 +1660,7 @@ struct timespec get_monotonic_coarse(void)
 	set_normalized_timespec64(&now, now.tv_sec + mono.tv_sec,
 				now.tv_nsec + mono.tv_nsec);
 
-	return timespec64_to_timespec(now);
+	return now;
 }
 
 /*
-- 
1.9.1


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

* [PATCH 09/12] time: Fixup comments to reflect usage of timespec64
  2014-11-21 19:44 [PATCH 00/12] John Stultz
                   ` (7 preceding siblings ...)
  2014-11-21 19:44 ` [PATCH 08/12] time: Expose get_monotonic_corase64() " John Stultz
@ 2014-11-21 19:44 ` John Stultz
  2014-11-21 19:44 ` [PATCH 10/12] rtc/lib: Provide y2038 safe rtc_tm_to_time()/rtc_time_to_tm() replacement John Stultz
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: John Stultz @ 2014-11-21 19:44 UTC (permalink / raw)
  To: lkml
  Cc: John Stultz, Thomas Gleixner, Ingo Molnar, Arnd Bergmann,
	pang.xunlei, Miroslav Lichvar, Richard Cochran, Prarit Bhargava,
	Alessandro Zummo

Fix up a few comments that weren't updated when the
functions were converted to use timespec64 structures.

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Arnd Bergmann <arnd.bergmann@linaro.org>
Cc: pang.xunlei <pang.xunlei@linaro.org>
Cc: Miroslav Lichvar <mlichvar@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Acked-by: Arnd Bergmann <arnd.bergmann@linaro.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 kernel/time/timekeeping.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 62440b1..14c6270 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -519,9 +519,9 @@ EXPORT_SYMBOL(__getnstimeofday64);
 
 /**
  * getnstimeofday64 - Returns the time of day in a timespec64.
- * @ts:		pointer to the timespec to be set
+ * @ts:		pointer to the timespec64 to be set
  *
- * Returns the time of day in a timespec (WARN if suspended).
+ * Returns the time of day in a timespec64 (WARN if suspended).
  */
 void getnstimeofday64(struct timespec64 *ts)
 {
@@ -623,7 +623,7 @@ EXPORT_SYMBOL_GPL(ktime_get_raw);
  *
  * The function calculates the monotonic clock from the realtime
  * clock and the wall_to_monotonic offset and stores the result
- * in normalized timespec format in the variable pointed to by @ts.
+ * in normalized timespec64 format in the variable pointed to by @ts.
  */
 void ktime_get_ts64(struct timespec64 *ts)
 {
-- 
1.9.1


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

* [PATCH 10/12] rtc/lib: Provide y2038 safe rtc_tm_to_time()/rtc_time_to_tm() replacement
  2014-11-21 19:44 [PATCH 00/12] John Stultz
                   ` (8 preceding siblings ...)
  2014-11-21 19:44 ` [PATCH 09/12] time: Fixup comments to reflect usage of timespec64 John Stultz
@ 2014-11-21 19:44 ` John Stultz
  2014-11-21 19:44 ` [PATCH 11/12] rtc: Update suspend/resume timing to use 64bit time John Stultz
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: John Stultz @ 2014-11-21 19:44 UTC (permalink / raw)
  To: lkml
  Cc: pang.xunlei, Thomas Gleixner, Ingo Molnar, Arnd Bergmann,
	Miroslav Lichvar, Richard Cochran, Prarit Bhargava,
	Alessandro Zummo, John Stultz

From: "pang.xunlei" <pang.xunlei@linaro.org>

As part of addressing "y2038 problem" for in-kernel uses, this patch
adds safe rtc_tm_to_time64()/rtc_time64_to_tm() respectively using
time64_t.

After this patch, rtc_tm_to_time() is deprecated and all its call
sites will be fixed using corresponding safe versions, it can be
removed when having no users. Also change rtc_tm_to_time64() to
return time64_t directly instead of just as a parameter like
rtc_tm_to_time() does.

After this patch, rtc_time_to_tm() is deprecated and all its call
sites will be fixed using corresponding safe versions, it can be
removed when having no users.

In addition, change rtc_tm_to_ktime() and rtc_ktime_to_tm() to use
the safe version in passing.

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Arnd Bergmann <arnd.bergmann@linaro.org>
Cc: pang.xunlei <pang.xunlei@linaro.org>
Cc: Miroslav Lichvar <mlichvar@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: pang.xunlei <pang.xunlei@linaro.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 drivers/rtc/rtc-lib.c | 38 ++++++++++++++++++++------------------
 include/linux/rtc.h   | 21 +++++++++++++++++++--
 2 files changed, 39 insertions(+), 20 deletions(-)

diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c
index c4cf057..e6bfb9c 100644
--- a/drivers/rtc/rtc-lib.c
+++ b/drivers/rtc/rtc-lib.c
@@ -45,16 +45,20 @@ int rtc_year_days(unsigned int day, unsigned int month, unsigned int year)
 }
 EXPORT_SYMBOL(rtc_year_days);
 
+
 /*
+ * rtc_time_to_tm64 - Converts time64_t to rtc_time.
  * Convert seconds since 01-01-1970 00:00:00 to Gregorian date.
  */
-void rtc_time_to_tm(unsigned long time, struct rtc_time *tm)
+void rtc_time64_to_tm(time64_t time, struct rtc_time *tm)
 {
 	unsigned int month, year;
+	unsigned long secs;
 	int days;
 
-	days = time / 86400;
-	time -= (unsigned int) days * 86400;
+	/* time must be positive */
+	days = div_s64(time, 86400);
+	secs = time - (unsigned int) days * 86400;
 
 	/* day of the week, 1970-01-01 was a Thursday */
 	tm->tm_wday = (days + 4) % 7;
@@ -81,14 +85,14 @@ void rtc_time_to_tm(unsigned long time, struct rtc_time *tm)
 	tm->tm_mon = month;
 	tm->tm_mday = days + 1;
 
-	tm->tm_hour = time / 3600;
-	time -= tm->tm_hour * 3600;
-	tm->tm_min = time / 60;
-	tm->tm_sec = time - tm->tm_min * 60;
+	tm->tm_hour = secs / 3600;
+	secs -= tm->tm_hour * 3600;
+	tm->tm_min = secs / 60;
+	tm->tm_sec = secs - tm->tm_min * 60;
 
 	tm->tm_isdst = 0;
 }
-EXPORT_SYMBOL(rtc_time_to_tm);
+EXPORT_SYMBOL(rtc_time64_to_tm);
 
 /*
  * Does the rtc_time represent a valid date/time?
@@ -109,24 +113,22 @@ int rtc_valid_tm(struct rtc_time *tm)
 EXPORT_SYMBOL(rtc_valid_tm);
 
 /*
+ * rtc_tm_to_time64 - Converts rtc_time to time64_t.
  * Convert Gregorian date to seconds since 01-01-1970 00:00:00.
  */
-int rtc_tm_to_time(struct rtc_time *tm, unsigned long *time)
+time64_t rtc_tm_to_time64(struct rtc_time *tm)
 {
-	*time = mktime(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
+	return mktime64(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
 			tm->tm_hour, tm->tm_min, tm->tm_sec);
-	return 0;
 }
-EXPORT_SYMBOL(rtc_tm_to_time);
+EXPORT_SYMBOL(rtc_tm_to_time64);
 
 /*
  * Convert rtc_time to ktime
  */
 ktime_t rtc_tm_to_ktime(struct rtc_time tm)
 {
-	time_t time;
-	rtc_tm_to_time(&tm, &time);
-	return ktime_set(time, 0);
+	return ktime_set(rtc_tm_to_time64(&tm), 0);
 }
 EXPORT_SYMBOL_GPL(rtc_tm_to_ktime);
 
@@ -135,14 +137,14 @@ EXPORT_SYMBOL_GPL(rtc_tm_to_ktime);
  */
 struct rtc_time rtc_ktime_to_tm(ktime_t kt)
 {
-	struct timespec ts;
+	struct timespec64 ts;
 	struct rtc_time ret;
 
-	ts = ktime_to_timespec(kt);
+	ts = ktime_to_timespec64(kt);
 	/* Round up any ns */
 	if (ts.tv_nsec)
 		ts.tv_sec++;
-	rtc_time_to_tm(ts.tv_sec, &ret);
+	rtc_time64_to_tm(ts.tv_sec, &ret);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(rtc_ktime_to_tm);
diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index c2c2897..6d6be09 100644
--- a/include/linux/rtc.h
+++ b/include/linux/rtc.h
@@ -19,11 +19,28 @@
 extern int rtc_month_days(unsigned int month, unsigned int year);
 extern int rtc_year_days(unsigned int day, unsigned int month, unsigned int year);
 extern int rtc_valid_tm(struct rtc_time *tm);
-extern int rtc_tm_to_time(struct rtc_time *tm, unsigned long *time);
-extern void rtc_time_to_tm(unsigned long time, struct rtc_time *tm);
+extern time64_t rtc_tm_to_time64(struct rtc_time *tm);
+extern void rtc_time64_to_tm(time64_t time, struct rtc_time *tm);
 ktime_t rtc_tm_to_ktime(struct rtc_time tm);
 struct rtc_time rtc_ktime_to_tm(ktime_t kt);
 
+/**
+ * Deprecated. Use rtc_time64_to_tm().
+ */
+static inline void rtc_time_to_tm(unsigned long time, struct rtc_time *tm)
+{
+	rtc_time64_to_tm(time, tm);
+}
+
+/**
+ * Deprecated. Use rtc_tm_to_time64().
+ */
+static inline int rtc_tm_to_time(struct rtc_time *tm, unsigned long *time)
+{
+	*time = rtc_tm_to_time64(tm);
+
+	return 0;
+}
 
 #include <linux/device.h>
 #include <linux/seq_file.h>
-- 
1.9.1


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

* [PATCH 11/12] rtc: Update suspend/resume timing to use 64bit time
  2014-11-21 19:44 [PATCH 00/12] John Stultz
                   ` (9 preceding siblings ...)
  2014-11-21 19:44 ` [PATCH 10/12] rtc/lib: Provide y2038 safe rtc_tm_to_time()/rtc_time_to_tm() replacement John Stultz
@ 2014-11-21 19:44 ` John Stultz
  2014-11-21 19:44 ` [PATCH 12/12] time: Remove timekeeping_inject_sleeptime() John Stultz
  2014-11-21 19:53 ` [PATCH 00/12] John Stultz
  12 siblings, 0 replies; 19+ messages in thread
From: John Stultz @ 2014-11-21 19:44 UTC (permalink / raw)
  To: lkml
  Cc: John Stultz, Thomas Gleixner, Ingo Molnar, Arnd Bergmann,
	pang.xunlei, Miroslav Lichvar, Richard Cochran, Prarit Bhargava,
	Alessandro Zummo

Currently the rtc suspend/resume timing is done using
y2038 problematic timespecs. So update the code to utilize
timespec64 types.

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Arnd Bergmann <arnd.bergmann@linaro.org>
Cc: pang.xunlei <pang.xunlei@linaro.org>
Cc: Miroslav Lichvar <mlichvar@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 drivers/rtc/class.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index 38e26be..472a5ad 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -45,14 +45,14 @@ int rtc_hctosys_ret = -ENODEV;
  * system's wall clock; restore it on resume().
  */
 
-static struct timespec old_rtc, old_system, old_delta;
+static struct timespec64 old_rtc, old_system, old_delta;
 
 
 static int rtc_suspend(struct device *dev)
 {
 	struct rtc_device	*rtc = to_rtc_device(dev);
 	struct rtc_time		tm;
-	struct timespec		delta, delta_delta;
+	struct timespec64	delta, delta_delta;
 	int err;
 
 	if (has_persistent_clock())
@@ -68,8 +68,8 @@ static int rtc_suspend(struct device *dev)
 		return 0;
 	}
 
-	getnstimeofday(&old_system);
-	rtc_tm_to_time(&tm, &old_rtc.tv_sec);
+	getnstimeofday64(&old_system);
+	old_rtc.tv_sec = rtc_tm_to_time64(&tm);
 
 
 	/*
@@ -78,8 +78,8 @@ static int rtc_suspend(struct device *dev)
 	 * try to compensate so the difference in system time
 	 * and rtc time stays close to constant.
 	 */
-	delta = timespec_sub(old_system, old_rtc);
-	delta_delta = timespec_sub(delta, old_delta);
+	delta = timespec64_sub(old_system, old_rtc);
+	delta_delta = timespec64_sub(delta, old_delta);
 	if (delta_delta.tv_sec < -2 || delta_delta.tv_sec >= 2) {
 		/*
 		 * if delta_delta is too large, assume time correction
@@ -88,7 +88,7 @@ static int rtc_suspend(struct device *dev)
 		old_delta = delta;
 	} else {
 		/* Otherwise try to adjust old_system to compensate */
-		old_system = timespec_sub(old_system, delta_delta);
+		old_system = timespec64_sub(old_system, delta_delta);
 	}
 
 	return 0;
@@ -98,8 +98,8 @@ static int rtc_resume(struct device *dev)
 {
 	struct rtc_device	*rtc = to_rtc_device(dev);
 	struct rtc_time		tm;
-	struct timespec		new_system, new_rtc;
-	struct timespec		sleep_time;
+	struct timespec64	new_system, new_rtc;
+	struct timespec64	sleep_time;
 	int err;
 
 	if (has_persistent_clock())
@@ -110,7 +110,7 @@ static int rtc_resume(struct device *dev)
 		return 0;
 
 	/* snapshot the current rtc and system time at resume */
-	getnstimeofday(&new_system);
+	getnstimeofday64(&new_system);
 	err = rtc_read_time(rtc, &tm);
 	if (err < 0) {
 		pr_debug("%s:  fail to read rtc time\n", dev_name(&rtc->dev));
@@ -121,7 +121,7 @@ static int rtc_resume(struct device *dev)
 		pr_debug("%s:  bogus resume time\n", dev_name(&rtc->dev));
 		return 0;
 	}
-	rtc_tm_to_time(&tm, &new_rtc.tv_sec);
+	new_rtc.tv_sec = rtc_tm_to_time64(&tm);
 	new_rtc.tv_nsec = 0;
 
 	if (new_rtc.tv_sec < old_rtc.tv_sec) {
@@ -130,7 +130,7 @@ static int rtc_resume(struct device *dev)
 	}
 
 	/* calculate the RTC time delta (sleep time)*/
-	sleep_time = timespec_sub(new_rtc, old_rtc);
+	sleep_time = timespec64_sub(new_rtc, old_rtc);
 
 	/*
 	 * Since these RTC suspend/resume handlers are not called
@@ -139,11 +139,11 @@ static int rtc_resume(struct device *dev)
 	 * so subtract kernel run-time between rtc_suspend to rtc_resume
 	 * to keep things accurate.
 	 */
-	sleep_time = timespec_sub(sleep_time,
-			timespec_sub(new_system, old_system));
+	sleep_time = timespec64_sub(sleep_time,
+			timespec64_sub(new_system, old_system));
 
 	if (sleep_time.tv_sec >= 0)
-		timekeeping_inject_sleeptime(&sleep_time);
+		timekeeping_inject_sleeptime64(&sleep_time);
 	rtc_hctosys_ret = 0;
 	return 0;
 }
-- 
1.9.1


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

* [PATCH 12/12] time: Remove timekeeping_inject_sleeptime()
  2014-11-21 19:44 [PATCH 00/12] John Stultz
                   ` (10 preceding siblings ...)
  2014-11-21 19:44 ` [PATCH 11/12] rtc: Update suspend/resume timing to use 64bit time John Stultz
@ 2014-11-21 19:44 ` John Stultz
  2014-11-21 19:53 ` [PATCH 00/12] John Stultz
  12 siblings, 0 replies; 19+ messages in thread
From: John Stultz @ 2014-11-21 19:44 UTC (permalink / raw)
  To: lkml
  Cc: John Stultz, Thomas Gleixner, Ingo Molnar, Arnd Bergmann,
	pang.xunlei, Miroslav Lichvar, Richard Cochran, Prarit Bhargava,
	Alessandro Zummo

Since all users have been converted to using the 64bit
timekeeping_inject_sleeptime64(), remove the old y2038
problematic timekeeping_inject_sleeptime().

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Arnd Bergmann <arnd.bergmann@linaro.org>
Cc: pang.xunlei <pang.xunlei@linaro.org>
Cc: Miroslav Lichvar <mlichvar@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 include/linux/timekeeping.h | 11 -----------
 1 file changed, 11 deletions(-)

diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h
index 8cab4b7..961fea3 100644
--- a/include/linux/timekeeping.h
+++ b/include/linux/timekeeping.h
@@ -225,17 +225,6 @@ static inline void timekeeping_clocktai(struct timespec *ts)
  */
 extern void timekeeping_inject_sleeptime64(struct timespec64 *delta);
 
-/**
- * Deprecated. Use timekeeping_inject_sleeptime64().
- */
-static inline void timekeeping_inject_sleeptime(struct timespec *delta)
-{
-	struct timespec64 delta64;
-
-	delta64 = timespec_to_timespec64(*delta);
-	timekeeping_inject_sleeptime64(&delta64);
-}
-
 /*
  * PPS accessor
  */
-- 
1.9.1


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

* Re: [PATCH 00/12]
  2014-11-21 19:44 [PATCH 00/12] John Stultz
                   ` (11 preceding siblings ...)
  2014-11-21 19:44 ` [PATCH 12/12] time: Remove timekeeping_inject_sleeptime() John Stultz
@ 2014-11-21 19:53 ` John Stultz
  2014-11-21 20:07   ` Arnd Bergmann
  12 siblings, 1 reply; 19+ messages in thread
From: John Stultz @ 2014-11-21 19:53 UTC (permalink / raw)
  To: lkml
  Cc: John Stultz, Thomas Gleixner, Ingo Molnar, Arnd Bergmann,
	pang.xunlei, Miroslav Lichvar, Richard Cochran, Prarit Bhargava,
	Alessandro Zummo

On Fri, Nov 21, 2014 at 11:44 AM, John Stultz <john.stultz@linaro.org> wrote:
> Hey Thomas, All,
>
> Just wanted to submit a handful of changes for 3.19
>
> * udelay_test/test_udelay consistent file naming
> * Time / ntp edge-case fixes from Xunlei
> * y2038-safe internal interfaces from Xunlei and me
> * Celanup suspend/resume timing y2038 issues
> * Remove y2038 unsafe inject_sleeptime inteface
>
> Just as an FYI, I'm trying out signing this tag with
> a new subkey on my yubikey. Hopefully haven't mucked
> it up.

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

* Re: [PATCH 00/12]
  2014-11-21 19:53 ` [PATCH 00/12] John Stultz
@ 2014-11-21 20:07   ` Arnd Bergmann
  2014-11-21 20:17     ` John Stultz
  0 siblings, 1 reply; 19+ messages in thread
From: Arnd Bergmann @ 2014-11-21 20:07 UTC (permalink / raw)
  To: John Stultz
  Cc: lkml, Thomas Gleixner, Ingo Molnar, Arnd Bergmann, pang.xunlei,
	Miroslav Lichvar, Richard Cochran, Prarit Bhargava,
	Alessandro Zummo

On Friday 21 November 2014 11:53:04 John Stultz wrote:
> On Fri, Nov 21, 2014 at 11:44 AM, John Stultz <john.stultz@linaro.org> wrote:
> > Hey Thomas, All,
> >
> > Just wanted to submit a handful of changes for 3.19
> >
> > * udelay_test/test_udelay consistent file naming
> > * Time / ntp edge-case fixes from Xunlei
> > * y2038-safe internal interfaces from Xunlei and me
> > * Celanup suspend/resume timing y2038 issues
> > * Remove y2038 unsafe inject_sleeptime inteface
> >
> > Just as an FYI, I'm trying out signing this tag with
> > a new subkey on my yubikey. Hopefully haven't mucked
> > it up.

Hmm, patch 1 doesn't seem to have made it to the list.
Can you send that again?

	Arnd

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

* Re: [PATCH 00/12]
  2014-11-21 20:07   ` Arnd Bergmann
@ 2014-11-21 20:17     ` John Stultz
  0 siblings, 0 replies; 19+ messages in thread
From: John Stultz @ 2014-11-21 20:17 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: lkml, Thomas Gleixner, Ingo Molnar, Arnd Bergmann, pang.xunlei,
	Miroslav Lichvar, Richard Cochran, Prarit Bhargava,
	Alessandro Zummo

On Fri, Nov 21, 2014 at 12:07 PM, Arnd Bergmann <arnd@arndb.de> wrote:
> On Friday 21 November 2014 11:53:04 John Stultz wrote:
>> On Fri, Nov 21, 2014 at 11:44 AM, John Stultz <john.stultz@linaro.org> wrote:
>> > Hey Thomas, All,
>> >
>> > Just wanted to submit a handful of changes for 3.19
>> >
>> > * udelay_test/test_udelay consistent file naming
>> > * Time / ntp edge-case fixes from Xunlei
>> > * y2038-safe internal interfaces from Xunlei and me
>> > * Celanup suspend/resume timing y2038 issues
>> > * Remove y2038 unsafe inject_sleeptime inteface
>> >
>> > Just as an FYI, I'm trying out signing this tag with
>> > a new subkey on my yubikey. Hopefully haven't mucked
>> > it up.
>
> Hmm, patch 1 doesn't seem to have made it to the list.

I suspect its just I didn't CC you on that one (it already had a long
cc list from the last time I sent it around for 3.17). I do see it in
my list archive.

> Can you send that again?

Given I forgot the subject for the cover-letter and then managed to
hit send before writing my apology for that, I'm going to give it a
rest for today. :)

Thomas has pointed out one other typo issue in one of the patches so
I've already updated it. If he doesn't pull that in, or if there are
any other objections I'll rework and resend on Monday.

thanks
-john

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

* Re: [PATCH 01/12] time: Rename udelay_test.c to test_udelay.c
  2014-11-21 19:44 ` [PATCH 01/12] time: Rename udelay_test.c to test_udelay.c John Stultz
@ 2014-11-21 23:30   ` Kees Cook
  2014-11-22  3:45     ` Greg KH
  2014-11-24 22:14   ` David Riley
  1 sibling, 1 reply; 19+ messages in thread
From: Kees Cook @ 2014-11-21 23:30 UTC (permalink / raw)
  To: John Stultz
  Cc: lkml, Greg KH, Stephen Rothwell, Thomas Gleixner, Ingo Molnar,
	Linux-Next, David Riley

On Fri, Nov 21, 2014 at 11:44 AM, John Stultz <john.stultz@linaro.org> wrote:
> Kees requested that this test module be renamed for consistency sake,
> so this patch renames the udelay_test.c file (recently added to
> tip/timers/core for 3.17) to test_udelay.c
>
> Cc: Kees Cook <keescook@chromium.org>
> Cc: Greg KH <greg@kroah.com>
> Cc: Stephen Rothwell <sfr@canb.auug.org.au>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@elte.hu>
> Cc: Linux-Next <linux-next@vger.kernel.org>
> Cc: David Riley <davidriley@chromium.org>
> Signed-off-by: John Stultz <john.stultz@linaro.org>

Reviewed-by: Kees Cook <keescook@chromium.org>

Yes please! :)

-Kees

> ---
>  kernel/time/Makefile      |   2 +-
>  kernel/time/test_udelay.c | 168 ++++++++++++++++++++++++++++++++++++++++++++++
>  kernel/time/udelay_test.c | 168 ----------------------------------------------
>  3 files changed, 169 insertions(+), 169 deletions(-)
>  create mode 100644 kernel/time/test_udelay.c
>  delete mode 100644 kernel/time/udelay_test.c
>
> diff --git a/kernel/time/Makefile b/kernel/time/Makefile
> index 7347426..f622cf2 100644
> --- a/kernel/time/Makefile
> +++ b/kernel/time/Makefile
> @@ -13,7 +13,7 @@ obj-$(CONFIG_TICK_ONESHOT)                    += tick-oneshot.o
>  obj-$(CONFIG_TICK_ONESHOT)                     += tick-sched.o
>  obj-$(CONFIG_TIMER_STATS)                      += timer_stats.o
>  obj-$(CONFIG_DEBUG_FS)                         += timekeeping_debug.o
> -obj-$(CONFIG_TEST_UDELAY)                      += udelay_test.o
> +obj-$(CONFIG_TEST_UDELAY)                      += test_udelay.o
>
>  $(obj)/time.o: $(obj)/timeconst.h
>
> diff --git a/kernel/time/test_udelay.c b/kernel/time/test_udelay.c
> new file mode 100644
> index 0000000..e622ba3
> --- /dev/null
> +++ b/kernel/time/test_udelay.c
> @@ -0,0 +1,168 @@
> +/*
> + * udelay() test kernel module
> + *
> + * Test is executed by writing and reading to /sys/kernel/debug/udelay_test
> + * Tests are configured by writing: USECS ITERATIONS
> + * Tests are executed by reading from the same file.
> + * Specifying usecs of 0 or negative values will run multiples tests.
> + *
> + * Copyright (C) 2014 Google, Inc.
> + *
> + * This software is licensed under the terms of the GNU General Public
> + * License version 2, as published by the Free Software Foundation, and
> + * may be copied, distributed, and modified under those terms.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + */
> +
> +#include <linux/debugfs.h>
> +#include <linux/delay.h>
> +#include <linux/ktime.h>
> +#include <linux/module.h>
> +#include <linux/uaccess.h>
> +
> +#define DEFAULT_ITERATIONS 100
> +
> +#define DEBUGFS_FILENAME "udelay_test"
> +
> +static DEFINE_MUTEX(udelay_test_lock);
> +static struct dentry *udelay_test_debugfs_file;
> +static int udelay_test_usecs;
> +static int udelay_test_iterations = DEFAULT_ITERATIONS;
> +
> +static int udelay_test_single(struct seq_file *s, int usecs, uint32_t iters)
> +{
> +       int min = 0, max = 0, fail_count = 0;
> +       uint64_t sum = 0;
> +       uint64_t avg;
> +       int i;
> +       /* Allow udelay to be up to 0.5% fast */
> +       int allowed_error_ns = usecs * 5;
> +
> +       for (i = 0; i < iters; ++i) {
> +               struct timespec ts1, ts2;
> +               int time_passed;
> +
> +               ktime_get_ts(&ts1);
> +               udelay(usecs);
> +               ktime_get_ts(&ts2);
> +               time_passed = timespec_to_ns(&ts2) - timespec_to_ns(&ts1);
> +
> +               if (i == 0 || time_passed < min)
> +                       min = time_passed;
> +               if (i == 0 || time_passed > max)
> +                       max = time_passed;
> +               if ((time_passed + allowed_error_ns) / 1000 < usecs)
> +                       ++fail_count;
> +               WARN_ON(time_passed < 0);
> +               sum += time_passed;
> +       }
> +
> +       avg = sum;
> +       do_div(avg, iters);
> +       seq_printf(s, "%d usecs x %d: exp=%d allowed=%d min=%d avg=%lld max=%d",
> +                       usecs, iters, usecs * 1000,
> +                       (usecs * 1000) - allowed_error_ns, min, avg, max);
> +       if (fail_count)
> +               seq_printf(s, " FAIL=%d", fail_count);
> +       seq_puts(s, "\n");
> +
> +       return 0;
> +}
> +
> +static int udelay_test_show(struct seq_file *s, void *v)
> +{
> +       int usecs;
> +       int iters;
> +       int ret = 0;
> +
> +       mutex_lock(&udelay_test_lock);
> +       usecs = udelay_test_usecs;
> +       iters = udelay_test_iterations;
> +       mutex_unlock(&udelay_test_lock);
> +
> +       if (usecs > 0 && iters > 0) {
> +               return udelay_test_single(s, usecs, iters);
> +       } else if (usecs == 0) {
> +               struct timespec ts;
> +
> +               ktime_get_ts(&ts);
> +               seq_printf(s, "udelay() test (lpj=%ld kt=%ld.%09ld)\n",
> +                               loops_per_jiffy, ts.tv_sec, ts.tv_nsec);
> +               seq_puts(s, "usage:\n");
> +               seq_puts(s, "echo USECS [ITERS] > " DEBUGFS_FILENAME "\n");
> +               seq_puts(s, "cat " DEBUGFS_FILENAME "\n");
> +       }
> +
> +       return ret;
> +}
> +
> +static int udelay_test_open(struct inode *inode, struct file *file)
> +{
> +       return single_open(file, udelay_test_show, inode->i_private);
> +}
> +
> +static ssize_t udelay_test_write(struct file *file, const char __user *buf,
> +               size_t count, loff_t *pos)
> +{
> +       char lbuf[32];
> +       int ret;
> +       int usecs;
> +       int iters;
> +
> +       if (count >= sizeof(lbuf))
> +               return -EINVAL;
> +
> +       if (copy_from_user(lbuf, buf, count))
> +               return -EFAULT;
> +       lbuf[count] = '\0';
> +
> +       ret = sscanf(lbuf, "%d %d", &usecs, &iters);
> +       if (ret < 1)
> +               return -EINVAL;
> +       else if (ret < 2)
> +               iters = DEFAULT_ITERATIONS;
> +
> +       mutex_lock(&udelay_test_lock);
> +       udelay_test_usecs = usecs;
> +       udelay_test_iterations = iters;
> +       mutex_unlock(&udelay_test_lock);
> +
> +       return count;
> +}
> +
> +static const struct file_operations udelay_test_debugfs_ops = {
> +       .owner = THIS_MODULE,
> +       .open = udelay_test_open,
> +       .read = seq_read,
> +       .write = udelay_test_write,
> +       .llseek = seq_lseek,
> +       .release = single_release,
> +};
> +
> +static int __init udelay_test_init(void)
> +{
> +       mutex_lock(&udelay_test_lock);
> +       udelay_test_debugfs_file = debugfs_create_file(DEBUGFS_FILENAME,
> +                       S_IRUSR, NULL, NULL, &udelay_test_debugfs_ops);
> +       mutex_unlock(&udelay_test_lock);
> +
> +       return 0;
> +}
> +
> +module_init(udelay_test_init);
> +
> +static void __exit udelay_test_exit(void)
> +{
> +       mutex_lock(&udelay_test_lock);
> +       debugfs_remove(udelay_test_debugfs_file);
> +       mutex_unlock(&udelay_test_lock);
> +}
> +
> +module_exit(udelay_test_exit);
> +
> +MODULE_AUTHOR("David Riley <davidriley@chromium.org>");
> +MODULE_LICENSE("GPL");
> diff --git a/kernel/time/udelay_test.c b/kernel/time/udelay_test.c
> deleted file mode 100644
> index e622ba3..0000000
> --- a/kernel/time/udelay_test.c
> +++ /dev/null
> @@ -1,168 +0,0 @@
> -/*
> - * udelay() test kernel module
> - *
> - * Test is executed by writing and reading to /sys/kernel/debug/udelay_test
> - * Tests are configured by writing: USECS ITERATIONS
> - * Tests are executed by reading from the same file.
> - * Specifying usecs of 0 or negative values will run multiples tests.
> - *
> - * Copyright (C) 2014 Google, Inc.
> - *
> - * This software is licensed under the terms of the GNU General Public
> - * License version 2, as published by the Free Software Foundation, and
> - * may be copied, distributed, and modified under those terms.
> - *
> - * This program is distributed in the hope that it will be useful,
> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> - * GNU General Public License for more details.
> - */
> -
> -#include <linux/debugfs.h>
> -#include <linux/delay.h>
> -#include <linux/ktime.h>
> -#include <linux/module.h>
> -#include <linux/uaccess.h>
> -
> -#define DEFAULT_ITERATIONS 100
> -
> -#define DEBUGFS_FILENAME "udelay_test"
> -
> -static DEFINE_MUTEX(udelay_test_lock);
> -static struct dentry *udelay_test_debugfs_file;
> -static int udelay_test_usecs;
> -static int udelay_test_iterations = DEFAULT_ITERATIONS;
> -
> -static int udelay_test_single(struct seq_file *s, int usecs, uint32_t iters)
> -{
> -       int min = 0, max = 0, fail_count = 0;
> -       uint64_t sum = 0;
> -       uint64_t avg;
> -       int i;
> -       /* Allow udelay to be up to 0.5% fast */
> -       int allowed_error_ns = usecs * 5;
> -
> -       for (i = 0; i < iters; ++i) {
> -               struct timespec ts1, ts2;
> -               int time_passed;
> -
> -               ktime_get_ts(&ts1);
> -               udelay(usecs);
> -               ktime_get_ts(&ts2);
> -               time_passed = timespec_to_ns(&ts2) - timespec_to_ns(&ts1);
> -
> -               if (i == 0 || time_passed < min)
> -                       min = time_passed;
> -               if (i == 0 || time_passed > max)
> -                       max = time_passed;
> -               if ((time_passed + allowed_error_ns) / 1000 < usecs)
> -                       ++fail_count;
> -               WARN_ON(time_passed < 0);
> -               sum += time_passed;
> -       }
> -
> -       avg = sum;
> -       do_div(avg, iters);
> -       seq_printf(s, "%d usecs x %d: exp=%d allowed=%d min=%d avg=%lld max=%d",
> -                       usecs, iters, usecs * 1000,
> -                       (usecs * 1000) - allowed_error_ns, min, avg, max);
> -       if (fail_count)
> -               seq_printf(s, " FAIL=%d", fail_count);
> -       seq_puts(s, "\n");
> -
> -       return 0;
> -}
> -
> -static int udelay_test_show(struct seq_file *s, void *v)
> -{
> -       int usecs;
> -       int iters;
> -       int ret = 0;
> -
> -       mutex_lock(&udelay_test_lock);
> -       usecs = udelay_test_usecs;
> -       iters = udelay_test_iterations;
> -       mutex_unlock(&udelay_test_lock);
> -
> -       if (usecs > 0 && iters > 0) {
> -               return udelay_test_single(s, usecs, iters);
> -       } else if (usecs == 0) {
> -               struct timespec ts;
> -
> -               ktime_get_ts(&ts);
> -               seq_printf(s, "udelay() test (lpj=%ld kt=%ld.%09ld)\n",
> -                               loops_per_jiffy, ts.tv_sec, ts.tv_nsec);
> -               seq_puts(s, "usage:\n");
> -               seq_puts(s, "echo USECS [ITERS] > " DEBUGFS_FILENAME "\n");
> -               seq_puts(s, "cat " DEBUGFS_FILENAME "\n");
> -       }
> -
> -       return ret;
> -}
> -
> -static int udelay_test_open(struct inode *inode, struct file *file)
> -{
> -       return single_open(file, udelay_test_show, inode->i_private);
> -}
> -
> -static ssize_t udelay_test_write(struct file *file, const char __user *buf,
> -               size_t count, loff_t *pos)
> -{
> -       char lbuf[32];
> -       int ret;
> -       int usecs;
> -       int iters;
> -
> -       if (count >= sizeof(lbuf))
> -               return -EINVAL;
> -
> -       if (copy_from_user(lbuf, buf, count))
> -               return -EFAULT;
> -       lbuf[count] = '\0';
> -
> -       ret = sscanf(lbuf, "%d %d", &usecs, &iters);
> -       if (ret < 1)
> -               return -EINVAL;
> -       else if (ret < 2)
> -               iters = DEFAULT_ITERATIONS;
> -
> -       mutex_lock(&udelay_test_lock);
> -       udelay_test_usecs = usecs;
> -       udelay_test_iterations = iters;
> -       mutex_unlock(&udelay_test_lock);
> -
> -       return count;
> -}
> -
> -static const struct file_operations udelay_test_debugfs_ops = {
> -       .owner = THIS_MODULE,
> -       .open = udelay_test_open,
> -       .read = seq_read,
> -       .write = udelay_test_write,
> -       .llseek = seq_lseek,
> -       .release = single_release,
> -};
> -
> -static int __init udelay_test_init(void)
> -{
> -       mutex_lock(&udelay_test_lock);
> -       udelay_test_debugfs_file = debugfs_create_file(DEBUGFS_FILENAME,
> -                       S_IRUSR, NULL, NULL, &udelay_test_debugfs_ops);
> -       mutex_unlock(&udelay_test_lock);
> -
> -       return 0;
> -}
> -
> -module_init(udelay_test_init);
> -
> -static void __exit udelay_test_exit(void)
> -{
> -       mutex_lock(&udelay_test_lock);
> -       debugfs_remove(udelay_test_debugfs_file);
> -       mutex_unlock(&udelay_test_lock);
> -}
> -
> -module_exit(udelay_test_exit);
> -
> -MODULE_AUTHOR("David Riley <davidriley@chromium.org>");
> -MODULE_LICENSE("GPL");
> --
> 1.9.1
>



-- 
Kees Cook
Chrome OS Security

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

* Re: [PATCH 01/12] time: Rename udelay_test.c to test_udelay.c
  2014-11-21 23:30   ` Kees Cook
@ 2014-11-22  3:45     ` Greg KH
  0 siblings, 0 replies; 19+ messages in thread
From: Greg KH @ 2014-11-22  3:45 UTC (permalink / raw)
  To: Kees Cook
  Cc: John Stultz, lkml, Stephen Rothwell, Thomas Gleixner,
	Ingo Molnar, Linux-Next, David Riley

On Fri, Nov 21, 2014 at 03:30:51PM -0800, Kees Cook wrote:
> On Fri, Nov 21, 2014 at 11:44 AM, John Stultz <john.stultz@linaro.org> wrote:
> > Kees requested that this test module be renamed for consistency sake,
> > so this patch renames the udelay_test.c file (recently added to
> > tip/timers/core for 3.17) to test_udelay.c
> >
> > Cc: Kees Cook <keescook@chromium.org>
> > Cc: Greg KH <greg@kroah.com>
> > Cc: Stephen Rothwell <sfr@canb.auug.org.au>
> > Cc: Thomas Gleixner <tglx@linutronix.de>
> > Cc: Ingo Molnar <mingo@elte.hu>
> > Cc: Linux-Next <linux-next@vger.kernel.org>
> > Cc: David Riley <davidriley@chromium.org>
> > Signed-off-by: John Stultz <john.stultz@linaro.org>
> 
> Reviewed-by: Kees Cook <keescook@chromium.org>


Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

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

* Re: [PATCH 01/12] time: Rename udelay_test.c to test_udelay.c
  2014-11-21 19:44 ` [PATCH 01/12] time: Rename udelay_test.c to test_udelay.c John Stultz
  2014-11-21 23:30   ` Kees Cook
@ 2014-11-24 22:14   ` David Riley
  1 sibling, 0 replies; 19+ messages in thread
From: David Riley @ 2014-11-24 22:14 UTC (permalink / raw)
  To: John Stultz
  Cc: lkml, Kees Cook, Greg KH, Stephen Rothwell, Thomas Gleixner,
	Ingo Molnar, Linux-Next

On Fri, Nov 21, 2014 at 11:44 AM, John Stultz <john.stultz@linaro.org> wrote:
> Kees requested that this test module be renamed for consistency sake,
> so this patch renames the udelay_test.c file (recently added to
> tip/timers/core for 3.17) to test_udelay.c
>
> Cc: Kees Cook <keescook@chromium.org>
> Cc: Greg KH <greg@kroah.com>
> Cc: Stephen Rothwell <sfr@canb.auug.org.au>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@elte.hu>
> Cc: Linux-Next <linux-next@vger.kernel.org>
> Cc: David Riley <davidriley@chromium.org>
> Signed-off-by: John Stultz <john.stultz@linaro.org>

Reviewed-by: David Riley <davidriley@chromium.org>

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

end of thread, other threads:[~2014-11-24 22:14 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-21 19:44 [PATCH 00/12] John Stultz
2014-11-21 19:44 ` [PATCH 01/12] time: Rename udelay_test.c to test_udelay.c John Stultz
2014-11-21 23:30   ` Kees Cook
2014-11-22  3:45     ` Greg KH
2014-11-24 22:14   ` David Riley
2014-11-21 19:44 ` [PATCH 02/12] time: Avoid possible NTP adjustment mult overflow John Stultz
2014-11-21 19:44 ` [PATCH 03/12] time: Complete NTP adjustment threshold judging conditions John Stultz
2014-11-21 19:44 ` [PATCH 04/12] time: Provide y2038 safe do_settimeofday() replacement John Stultz
2014-11-21 19:44 ` [PATCH 05/12] time: Provide y2038 safe timekeeping_inject_sleeptime() replacement John Stultz
2014-11-21 19:44 ` [PATCH 06/12] time: Provide y2038 safe mktime() replacement John Stultz
2014-11-21 19:44 ` [PATCH 07/12] time: Expose getrawmonotonic64 for in-kernel uses John Stultz
2014-11-21 19:44 ` [PATCH 08/12] time: Expose get_monotonic_corase64() " John Stultz
2014-11-21 19:44 ` [PATCH 09/12] time: Fixup comments to reflect usage of timespec64 John Stultz
2014-11-21 19:44 ` [PATCH 10/12] rtc/lib: Provide y2038 safe rtc_tm_to_time()/rtc_time_to_tm() replacement John Stultz
2014-11-21 19:44 ` [PATCH 11/12] rtc: Update suspend/resume timing to use 64bit time John Stultz
2014-11-21 19:44 ` [PATCH 12/12] time: Remove timekeeping_inject_sleeptime() John Stultz
2014-11-21 19:53 ` [PATCH 00/12] John Stultz
2014-11-21 20:07   ` Arnd Bergmann
2014-11-21 20:17     ` John Stultz

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