linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v5 00/24] Convert the posix_clock_operations and k_clock structure to ready for 2038
       [not found] <lfywpz1987>
@ 2015-06-12  7:19 ` Baolin Wang
  2015-06-12  7:27   ` [PATCH v5 01/24] time: Introduce struct itimerspec64 Baolin Wang
                     ` (24 more replies)
  0 siblings, 25 replies; 27+ messages in thread
From: Baolin Wang @ 2015-06-12  7:19 UTC (permalink / raw)
  To: tglx
  Cc: arnd, john.stultz, heenasirwani, pang.xunlei, peterz,
	rafael.j.wysocki, gregkh, richardcochran, benh, paulus, mpe,
	schwidefsky, heiko.carstens, linux390, rth, riel, cl, tj,
	fweisbec, ahh, pjt, linuxppc-dev, linux-s390, linux-arch,
	linux-kernel, netdev, serge.hallyn, james.l.morris, serge,
	pmoore, tiwai, jeffv, jlayton, keescook, sds, mark.d.rustad,
	linux-security-module, baolin.wang, y2038

This patch series changes the 32-bit time types (timespec/itimerspec) to
the 64-bit types (timespec64/itimerspec64), since 32-bit time types will
break in the year 2038 on 32bit systems.

This patch series introduces new methods with timespec64/itimerspec64 type,
and removes the old ones with timespec/itimerspec type for posix_clock_operations
and k_clock structure.

---
Changes since v4:
- Rebase the patch series.
- Modify the subject line and the changelog.

Changes since v3:
- Fix some introducing bugs.

Changes since v2:
- Split the syscall conversion patch into small some patches.

Changes since V1:
- Split some patch into small patch.
- Add some default function for new 64bit methods for syscall function.
- Move do_sys_settimeofday() function to head file.
- Modify the EXPORT_SYMPOL issue.
- Add new 64bit methods in cputime_nsecs.h file.
---

Baolin Wang (24):
  time: Introduce struct itimerspec64
  timekeeping: Introduce current_kernel_time64()
  security: Introduce security_settime64()
  time: Introduce do_sys_settimeofday64()
  posix-timers: Introduce {get,put}_timespec and {get,put}_itimerspec
  posix-timers: Factor out the guts of 'timer_gettime'
  posix-timers: Implement y2038 safe timer_get64() callback
  posix-timers: Factor out the guts of 'timer_settime'
  posix-timers: Implement y2038 safe timer_set64() callback
  posix-timers: Factor out the guts of 'clock_settime'
  posix-timers: Implement y2038 safe clock_set64() callback
  posix-timers: Factor out the guts of 'clock_gettime'
  posix-timers: Implement y2038 safe clock_get64() callback
  posix-timers: Factor out the guts of 'clcok_getres'
  posix-timers: Implement y2038 safe clock_getres64() callback
  timekeeping: Change the implementation of timekeeping_clocktai()
  posix-timers: Convert to y2038 safe callbacks
  mmtimer: Convert to y2038 safe callbacks
  alarmtimer: Convert to y2038 safe callbacks
  posix-clock: Convert to y2038 safe callbacks
  time: Introduce timespec64_to_jiffies()/jiffies_to_timespec64()
  cputime: Introduce cputime_to_timespec64()/timespec64_to_cputime()
  posix-cpu-timers: Convert to y2038 safe callbacks
  k_clock: Remove y2038 unsafe callbacks

 arch/powerpc/include/asm/cputime.h    |    6 +-
 arch/s390/include/asm/cputime.h       |    8 +-
 drivers/char/mmtimer.c                |   36 +++--
 drivers/ptp/ptp_clock.c               |   22 +--
 include/asm-generic/cputime_jiffies.h |   10 +-
 include/asm-generic/cputime_nsecs.h   |    6 +-
 include/linux/cputime.h               |   16 ++
 include/linux/jiffies.h               |   21 ++-
 include/linux/lsm_hooks.h             |    5 +-
 include/linux/posix-clock.h           |   10 +-
 include/linux/posix-timers.h          |   18 +--
 include/linux/security.h              |   20 ++-
 include/linux/time64.h                |   35 +++++
 include/linux/timekeeping.h           |   25 +++-
 kernel/time/alarmtimer.c              |   38 ++---
 kernel/time/posix-clock.c             |   20 +--
 kernel/time/posix-cpu-timers.c        |   84 ++++++-----
 kernel/time/posix-timers.c            |  257 +++++++++++++++++++++------------
 kernel/time/time.c                    |   19 +--
 kernel/time/timekeeping.c             |    6 +-
 security/commoncap.c                  |    2 +-
 security/security.c                   |    2 +-
 22 files changed, 412 insertions(+), 254 deletions(-)

-- 
1.7.9.5


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

* [PATCH v5 01/24] time: Introduce struct itimerspec64
  2015-06-12  7:19 ` [PATCH v5 00/24] Convert the posix_clock_operations and k_clock structure to ready for 2038 Baolin Wang
@ 2015-06-12  7:27   ` Baolin Wang
  2015-06-12  7:30   ` [PATCH v5 02/24] timekeeping: Introduce current_kernel_time64() Baolin Wang
                     ` (23 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Baolin Wang @ 2015-06-12  7:27 UTC (permalink / raw)
  To: tglx; +Cc: arnd, john.stultz, pang.xunlei, linux-kernel, baolin.wang, y2038

The itimerspec is not year 2038 safe on 32bit systems due to the
limitation of the struct timespec members. Introduce itimerspec64
which uses struct timespec64 instead and provide conversion
functions.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 include/linux/time64.h |   35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/include/linux/time64.h b/include/linux/time64.h
index 12d4e82..132062b 100644
--- a/include/linux/time64.h
+++ b/include/linux/time64.h
@@ -12,11 +12,18 @@ typedef __s64 time64_t;
  */
 #if __BITS_PER_LONG == 64
 # define timespec64 timespec
+#define itimerspec64 itimerspec
 #else
 struct timespec64 {
 	time64_t	tv_sec;			/* seconds */
 	long		tv_nsec;		/* nanoseconds */
 };
+
+struct itimerspec64 {
+	struct timespec64 it_interval;
+	struct timespec64 it_value;
+};
+
 #endif
 
 /* Parameters used to convert the timespec values: */
@@ -44,6 +51,16 @@ static inline struct timespec64 timespec_to_timespec64(const struct timespec ts)
 	return ts;
 }
 
+static inline struct itimerspec itimerspec64_to_itimerspec(struct itimerspec64 *its64)
+{
+	return *its64;
+}
+
+static inline struct itimerspec64 itimerspec_to_itimerspec64(struct itimerspec *its)
+{
+	return *its;
+}
+
 # define timespec64_equal		timespec_equal
 # define timespec64_compare		timespec_compare
 # define set_normalized_timespec64	set_normalized_timespec
@@ -76,6 +93,24 @@ static inline struct timespec64 timespec_to_timespec64(const struct timespec ts)
 	return ret;
 }
 
+static inline struct itimerspec itimerspec64_to_itimerspec(struct itimerspec64 *its64)
+{
+	struct itimerspec ret;
+
+	ret.it_interval = timespec64_to_timespec(its64->it_interval);
+	ret.it_value = timespec64_to_timespec(its64->it_value);
+	return ret;
+}
+
+static inline struct itimerspec64 itimerspec_to_itimerspec64(struct itimerspec *its)
+{
+	struct itimerspec64 ret;
+
+	ret.it_interval = timespec_to_timespec64(its->it_interval);
+	ret.it_value = timespec_to_timespec64(its->it_value);
+	return ret;
+}
+
 static inline int timespec64_equal(const struct timespec64 *a,
 				   const struct timespec64 *b)
 {
-- 
1.7.9.5


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

* [PATCH v5 02/24] timekeeping: Introduce current_kernel_time64()
  2015-06-12  7:19 ` [PATCH v5 00/24] Convert the posix_clock_operations and k_clock structure to ready for 2038 Baolin Wang
  2015-06-12  7:27   ` [PATCH v5 01/24] time: Introduce struct itimerspec64 Baolin Wang
@ 2015-06-12  7:30   ` Baolin Wang
  2015-06-12  7:37   ` [PATCH v5 03/24] security: Introduce security_settime64() Baolin Wang
                     ` (22 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Baolin Wang @ 2015-06-12  7:30 UTC (permalink / raw)
  To: tglx
  Cc: arnd, john.stultz, pang.xunlei, mingo, peterz, linux-kernel,
	baolin.wang, y2038

The current_kernel_time() is not year 2038 safe on 32bit systems
due to return timespec value. Introduce current_kernel_time64()
function which returns timespec64 value, also as a helper function
calling by current_kernel_time().

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 include/linux/timekeeping.h |   10 +++++++++-
 kernel/time/timekeeping.c   |    6 +++---
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h
index 3aa72e6..f886bdb 100644
--- a/include/linux/timekeeping.h
+++ b/include/linux/timekeeping.h
@@ -18,10 +18,18 @@ extern int do_sys_settimeofday(const struct timespec *tv,
  * Kernel time accessors
  */
 unsigned long get_seconds(void);
-struct timespec current_kernel_time(void);
+struct timespec64 current_kernel_time64(void);
 /* does not take xtime_lock */
 struct timespec __current_kernel_time(void);
 
+static inline struct timespec current_kernel_time(void)
+{
+	struct timespec64 now = current_kernel_time64();
+
+	return timespec64_to_timespec(now);
+}
+
 /*
  * timespec based interfaces
  */
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 0d784b3..5fe9b77 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -1857,7 +1857,7 @@ struct timespec __current_kernel_time(void)
 	return timespec64_to_timespec(tk_xtime(tk));
 }
 
-struct timespec current_kernel_time(void)
+struct timespec64 current_kernel_time64(void)
 {
 	struct timekeeper *tk = &tk_core.timekeeper;
 	struct timespec64 now;
@@ -1869,9 +1869,9 @@ struct timespec current_kernel_time(void)
 		now = tk_xtime(tk);
 	} while (read_seqcount_retry(&tk_core.seq, seq));
 
-	return timespec64_to_timespec(now);
+	return now;
 }
-EXPORT_SYMBOL(current_kernel_time);
+EXPORT_SYMBOL(current_kernel_time64);
 
 struct timespec64 get_monotonic_coarse64(void)
 {
-- 
1.7.9.5


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

* [PATCH v5 03/24] security: Introduce security_settime64()
  2015-06-12  7:19 ` [PATCH v5 00/24] Convert the posix_clock_operations and k_clock structure to ready for 2038 Baolin Wang
  2015-06-12  7:27   ` [PATCH v5 01/24] time: Introduce struct itimerspec64 Baolin Wang
  2015-06-12  7:30   ` [PATCH v5 02/24] timekeeping: Introduce current_kernel_time64() Baolin Wang
@ 2015-06-12  7:37   ` Baolin Wang
  2015-06-12  7:44   ` [PATCH v5 04/24] time: Introduce do_sys_settimeofday64() Baolin Wang
                     ` (21 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Baolin Wang @ 2015-06-12  7:37 UTC (permalink / raw)
  To: serge.hallyn
  Cc: arnd, linux-kernel, james.l.morris, serge, paul, john.johansen,
	sds, casey, penguin-kernel, neilb, edumazet, jlayton,
	linux-security-module, baolin.wang, y2038

Due to the security_settime() with timespec type is not year 2038
safe on 32bit systems. Introduce the security_settime64()
function with timespec64 type.

Change the settime() callback of security_list_options structure
argument with timespec64 type as a helper function wrapped by
security_settime64().

The cap_settime() as a helper function is only called by
security_settime64() and security_settime() functions, and it
need change the argument with timespec64 type.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 include/linux/lsm_hooks.h |    5 +++--
 include/linux/security.h  |   20 +++++++++++++++++---
 security/commoncap.c      |    2 +-
 security/security.c       |    2 +-
 4 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h
index 9429f05..d791f35 100644
--- a/include/linux/lsm_hooks.h
+++ b/include/linux/lsm_hooks.h
@@ -1191,7 +1191,8 @@
  *	Return 0 if permission is granted.
  * @settime:
  *	Check permission to change the system time.
- *	struct timespec and timezone are defined in include/linux/time.h
+ *	struct timespec64 is defined in include/linux/time64.h and timezone
+ *	is defined in include/linux/time.h
  *	@ts contains new time
  *	@tz contains new timezone
  *	Return 0 if permission is granted.
@@ -1324,7 +1325,7 @@ union security_list_options {
 	int (*quotactl)(int cmds, int type, int id, struct super_block *sb);
 	int (*quota_on)(struct dentry *dentry);
 	int (*syslog)(int type);
-	int (*settime)(const struct timespec *ts, const struct timezone *tz);
+	int (*settime)(const struct timespec64 *ts, const struct timezone *tz);
 	int (*vm_enough_memory)(struct mm_struct *mm, long pages);
 
 	int (*bprm_set_creds)(struct linux_binprm *bprm);
diff --git a/include/linux/security.h b/include/linux/security.h
index 79d85dd..520f903 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -69,7 +69,7 @@ struct timezone;
 /* These functions are in security/commoncap.c */
 extern int cap_capable(const struct cred *cred, struct user_namespace *ns,
 		       int cap, int audit);
-extern int cap_settime(const struct timespec *ts, const struct timezone *tz);
+extern int cap_settime(const struct timespec64 *ts, const struct timezone *tz);
 extern int cap_ptrace_access_check(struct task_struct *child, unsigned int mode);
 extern int cap_ptrace_traceme(struct task_struct *parent);
 extern int cap_capget(struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted);
@@ -206,7 +206,13 @@ int security_capable_noaudit(const struct cred *cred, struct user_namespace *ns,
 int security_quotactl(int cmds, int type, int id, struct super_block *sb);
 int security_quota_on(struct dentry *dentry);
 int security_syslog(int type);
-int security_settime(const struct timespec *ts, const struct timezone *tz);
+int security_settime64(const struct timespec64 *ts, const struct timezone *tz);
+static int security_settime(const struct timespec *ts, const struct timezone *tz)
+{
+	struct timespec64 ts64 = timespec_to_timespec64(*ts);
+
+	return security_settime64(&ts64, tz);
+}
 int security_vm_enough_memory_mm(struct mm_struct *mm, long pages);
 int security_bprm_set_creds(struct linux_binprm *bprm);
 int security_bprm_check(struct linux_binprm *bprm);
@@ -457,10 +463,18 @@ static inline int security_syslog(int type)
 	return 0;
 }
 
+static inline int security_settime64(const struct timespec64 *ts,
+				     const struct timezone *tz)
+{
+	return cap_settime(ts, tz);
+}
+
 static inline int security_settime(const struct timespec *ts,
 				   const struct timezone *tz)
 {
-	return cap_settime(ts, tz);
+	struct timsepc64 ts64 = timespec_to_timespec64(*ts);
+
+	return cap_settime(&ts64, tz);
 }
 
 static inline int security_vm_enough_memory_mm(struct mm_struct *mm, long pages)
diff --git a/security/commoncap.c b/security/commoncap.c
index d103f5a4..17b1f79 100644
--- a/security/commoncap.c
+++ b/security/commoncap.c
@@ -111,7 +111,7 @@ int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
  * Determine whether the current process may set the system clock and timezone
  * information, returning 0 if permission granted, -ve if denied.
  */
-int cap_settime(const struct timespec *ts, const struct timezone *tz)
+int cap_settime(const struct timespec64 *ts, const struct timezone *tz)
 {
 	if (!capable(CAP_SYS_TIME))
 		return -EPERM;
diff --git a/security/security.c b/security/security.c
index 595fffa..8d0dbd6 100644
--- a/security/security.c
+++ b/security/security.c
@@ -213,7 +213,7 @@ int security_syslog(int type)
 	return call_int_hook(syslog, 0, type);
 }
 
-int security_settime(const struct timespec *ts, const struct timezone *tz)
+int security_settime64(const struct timespec64 *ts, const struct timezone *tz)
 {
 	return call_int_hook(settime, 0, ts, tz);
 }
-- 
1.7.9.5


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

* [PATCH v5 04/24] time: Introduce do_sys_settimeofday64()
  2015-06-12  7:19 ` [PATCH v5 00/24] Convert the posix_clock_operations and k_clock structure to ready for 2038 Baolin Wang
                     ` (2 preceding siblings ...)
  2015-06-12  7:37   ` [PATCH v5 03/24] security: Introduce security_settime64() Baolin Wang
@ 2015-06-12  7:44   ` Baolin Wang
  2015-06-12  7:48   ` [PATCH v5 05/24] posix-timers: Introduce {get,put}_timespec and {get,put}_itimerspec Baolin Wang
                     ` (20 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Baolin Wang @ 2015-06-12  7:44 UTC (permalink / raw)
  To: tglx
  Cc: arnd, john.stultz, pang.xunlei, mingo, peterz, linux-kernel,
	baolin.wang, y2038

Due to the do_sys_settimeofday() with timespec type is not year 2038
safe on 32bit systems, and it should introduce the do_sys_settimeofday64()
function with timespec64 type to make it is ready for 2038 issue.

For removing the old do_sys_settimeofday() function with timespec type
conveniently in future, it should move the do_sys_settimeofday() function
to the timekeeping.h file as a 'static inline' helper that just calls
do_sys_settimeofday64().

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 include/linux/timekeeping.h |   11 +++++++++--
 kernel/time/time.c          |    8 ++++----
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h
index f886bdb..2dcc86b 100644
--- a/include/linux/timekeeping.h
+++ b/include/linux/timekeeping.h
@@ -11,8 +11,15 @@ extern int timekeeping_suspended;
  */
 extern void do_gettimeofday(struct timeval *tv);
 extern int do_settimeofday64(const struct timespec64 *ts);
-extern int do_sys_settimeofday(const struct timespec *tv,
-			       const struct timezone *tz);
+extern int do_sys_settimeofday64(const struct timespec64 *tv,
+				 const struct timezone *tz);
+static inline int do_sys_settimeofday(const struct timespec *tv,
+				      const struct timezone *tz)
+{
+	struct timespec64 ts64 = timespec_to_timespec64(*tv);
+
+	return do_sys_settimeofday64(&ts64, tz);
+}
 
 /*
  * Kernel time accessors
diff --git a/kernel/time/time.c b/kernel/time/time.c
index 972e3bb..5aefe2d 100644
--- a/kernel/time/time.c
+++ b/kernel/time/time.c
@@ -160,15 +160,15 @@ static inline void warp_clock(void)
  * various programs will get confused when the clock gets warped.
  */
 
-int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
+int do_sys_settimeofday64(const struct timespec64 *tv, const struct timezone *tz)
 {
 	static int firsttime = 1;
 	int error = 0;
 
-	if (tv && !timespec_valid(tv))
+	if (tv && !timespec64_valid(tv))
 		return -EINVAL;
 
-	error = security_settime(tv, tz);
+	error = security_settime64(tv, tz);
 	if (error)
 		return error;
 
@@ -186,7 +186,7 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
 		}
 	}
 	if (tv)
-		return do_settimeofday(tv);
+		return do_settimeofday64(tv);
 	return 0;
 }
 
-- 
1.7.9.5


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

* [PATCH v5 05/24] posix-timers: Introduce {get,put}_timespec and {get,put}_itimerspec
  2015-06-12  7:19 ` [PATCH v5 00/24] Convert the posix_clock_operations and k_clock structure to ready for 2038 Baolin Wang
                     ` (3 preceding siblings ...)
  2015-06-12  7:44   ` [PATCH v5 04/24] time: Introduce do_sys_settimeofday64() Baolin Wang
@ 2015-06-12  7:48   ` Baolin Wang
  2015-06-12  7:48   ` [PATCH v5 06/24] posix-timers: Factor out the guts of 'timer_gettime' for reusing Baolin Wang
                     ` (19 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Baolin Wang @ 2015-06-12  7:48 UTC (permalink / raw)
  To: tglx; +Cc: arnd, linux-kernel, baolin.wang, y2038

These are new helper macros that convert between a user timespec/
itimerspec and a kernel timespec64/itimerspec64 structure.

When converting syscall functions, it need to deal with these conversions:
  user timespec (32 bit), kernel timespec (32 bit)
  user timespec (64 bit), kernel timespec (64 bit)
  user timespec (32 bit), kernel timespec64 (64 bit)
  user timespec (64 bit), kernel timespec64 (64 bit)
  user itimerspec (32 bit), kernel itimerspec (32 bit)
  user itimerspec (64 bit), kernel itimerspec (64 bit)
  user itimerspec (32 bit), kernel itimerspec64 (64 bit)
  user itimerspec (64 bit), kernel itimerspec64 (64 bit)

In order to handle all these conversions, and ensure that it can change
over all callers at the same time with the structure type above, and
introduce the get/put macros based on __put_user() and __get_user().

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 kernel/time/posix-timers.c |   29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 31d11ac..5ddd912 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -147,6 +147,35 @@ static struct k_itimer *__lock_timer(timer_t timer_id, unsigned long *flags);
 	__timr;								   \
 })
 
+#define __get_timespec(kts, uts) \
+	(__get_user((kts)->tv_sec, &(uts)->tv_sec) || \
+	__get_user((kts)->tv_nsec, &(uts)->tv_nsec))
+
+#define __put_timespec(kts, uts) \
+	(__put_user((kts)->tv_sec, &(uts)->tv_sec) || \
+	__put_user((kts)->tv_nsec, &(uts)->tv_nsec))
+
+#define get_timespec(kts, uts) \
+	((access_ok(VERIFY_READ, (uts), sizeof(*(uts))) || \
+	__get_timespec((kts), (uts))) ? \
+	-EFAULT : 0)
+
+#define put_timespec(kts, uts) \
+	((access_ok(VERIFY_WRITE, (uts), sizeof(*(uts))) || \
+	__put_timespec((kts), (uts))) ? \
+	-EFAULT : 0)
+
+#define get_itimerspec(kit, uit) \
+	((access_ok(VERIFY_READ, (uit), sizeof(*(uit))) || \
+	__get_timespec(&(kit)->it_interval, &(uit)->it_interval) || \
+	__get_timespec(&(kit)->it_value, &(uit)->it_value)))
+
+#define put_itimerspec(kit, uit) \
+	((access_ok(VERIFY_WRITE, (uit), sizeof(*(uit))) || \
+	__put_timespec(&(kit)->it_interval, &(uit)->it_interval) || \
+	__put_timespec(&(kit)->it_value, &(uit)->it_value)) ? \
+	-EFAULT : 0)
+
 static int hash(struct signal_struct *sig, unsigned int nr)
 {
 	return hash_32(hash32_ptr(sig) ^ nr, HASH_BITS(posix_timers_hashtable));
-- 
1.7.9.5


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

* [PATCH v5 06/24] posix-timers: Factor out the guts of 'timer_gettime' for reusing
  2015-06-12  7:19 ` [PATCH v5 00/24] Convert the posix_clock_operations and k_clock structure to ready for 2038 Baolin Wang
                     ` (4 preceding siblings ...)
  2015-06-12  7:48   ` [PATCH v5 05/24] posix-timers: Introduce {get,put}_timespec and {get,put}_itimerspec Baolin Wang
@ 2015-06-12  7:48   ` Baolin Wang
  2015-06-12  7:48   ` [PATCH v5 07/24] posix-timers: Implement y2038 safe timer_get64() callback Baolin Wang
                     ` (18 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Baolin Wang @ 2015-06-12  7:48 UTC (permalink / raw)
  To: tglx; +Cc: arnd, linux-kernel, baolin.wang, y2038

In order to reuse the very same logic for the year 2038 safe syscalls
which we need to introduce for 32bit systems, factor out the guts of
the 'timer_gettime' syscall.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 kernel/time/posix-timers.c |   16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 5ddd912..7d1973a 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -802,11 +802,8 @@ common_timer_get(struct k_itimer *timr, struct itimerspec *cur_setting)
 		cur_setting->it_value = ktime_to_timespec(remaining);
 }
 
-/* Get the time remaining on a POSIX.1b interval timer. */
-SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
-		struct itimerspec __user *, setting)
+static int __timer_gettime(timer_t timer_id, struct itimerspec *cur_setting)
 {
-	struct itimerspec cur_setting;
 	struct k_itimer *timr;
 	struct k_clock *kc;
 	unsigned long flags;
@@ -820,9 +817,18 @@ SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
 	if (WARN_ON_ONCE(!kc || !kc->timer_get))
 		ret = -EINVAL;
 	else
-		kc->timer_get(timr, &cur_setting);
+		kc->timer_get(timr, cur_setting);
 
 	unlock_timer(timr, flags);
+	return ret;
+}
+
+/* Get the time remaining on a POSIX.1b interval timer. */
+SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
+		struct itimerspec __user *, setting)
+{
+	struct itimerspec cur_setting;
+	int ret = __timer_gettime(timer_id, &cur_setting);
 
 	if (!ret && copy_to_user(setting, &cur_setting, sizeof (cur_setting)))
 		return -EFAULT;
-- 
1.7.9.5


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

* [PATCH v5 07/24] posix-timers: Implement y2038 safe timer_get64() callback
  2015-06-12  7:19 ` [PATCH v5 00/24] Convert the posix_clock_operations and k_clock structure to ready for 2038 Baolin Wang
                     ` (5 preceding siblings ...)
  2015-06-12  7:48   ` [PATCH v5 06/24] posix-timers: Factor out the guts of 'timer_gettime' for reusing Baolin Wang
@ 2015-06-12  7:48   ` Baolin Wang
  2015-06-12  7:48   ` [PATCH v5 08/24] posix-timers: Factor out the guts of 'timer_settime' for reusing Baolin Wang
                     ` (17 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Baolin Wang @ 2015-06-12  7:48 UTC (permalink / raw)
  To: tglx; +Cc: arnd, linux-kernel, baolin.wang, y2038

The timer_get() callback in struct k_clock is not year 2038 safe on
32bit systems.

To address this implement a new callback timer_get64() which uses
struct itimerspec64 along with a default implementation which is a
wrapper for the existing timer_get() callback. The default callback
is installed at registration time for all posix clocks which are not
yet converted to timer_get64() and will be removed once this is
completed.

Use the new callback in __timer_gettime().

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 include/linux/posix-timers.h |    2 ++
 kernel/time/posix-timers.c   |   25 ++++++++++++++++++++-----
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index 907f3fd..e84436b 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -113,6 +113,8 @@ struct k_clock {
 #define TIMER_RETRY 1
 	void (*timer_get) (struct k_itimer * timr,
 			   struct itimerspec * cur_setting);
+	void (*timer_get64) (struct k_itimer *timr,
+			     struct itimerspec64 *cur_setting);
 };
 
 extern struct k_clock clock_posix_cpu;
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 7d1973a..70b5550 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -140,6 +140,7 @@ static int common_timer_del(struct k_itimer *timer);
 static enum hrtimer_restart posix_timer_fn(struct hrtimer *data);
 
 static struct k_itimer *__lock_timer(timer_t timer_id, unsigned long *flags);
+static struct k_clock *clockid_to_kclock(const clockid_t id);
 
 #define lock_timer(tid, flags)						   \
 ({	struct k_itimer *__timr;					   \
@@ -549,6 +550,16 @@ static struct pid *good_sigevent(sigevent_t * event)
 	return task_pid(rtn);
 }
 
+static void default_timer_get64(struct k_itimer *timr,
+				struct itimerspec64 *cur_setting64)
+{
+	struct itimerspec cur_setting;
+	struct k_clock *kc = clockid_to_kclock(timr->it_clock);
+
+	kc->timer_get(timr, &cur_setting);
+	*cur_setting64 = itimerspec_to_itimerspec64(&cur_setting);
+}
+
 void posix_timers_register_clock(const clockid_t clock_id,
 				 struct k_clock *new_clock)
 {
@@ -569,6 +580,9 @@ void posix_timers_register_clock(const clockid_t clock_id,
 		return;
 	}
 
+	if (new_clock->timer_get && !new_clock->timer_get64)
+		new_clock->timer_get64 = default_timer_get64;
+
 	posix_clocks[clock_id] = *new_clock;
 }
 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
@@ -802,7 +816,7 @@ common_timer_get(struct k_itimer *timr, struct itimerspec *cur_setting)
 		cur_setting->it_value = ktime_to_timespec(remaining);
 }
 
-static int __timer_gettime(timer_t timer_id, struct itimerspec *cur_setting)
+static int __timer_gettime(timer_t timer_id, struct itimerspec64 *cur_setting)
 {
 	struct k_itimer *timr;
 	struct k_clock *kc;
@@ -814,10 +828,10 @@ static int __timer_gettime(timer_t timer_id, struct itimerspec *cur_setting)
 		return -EINVAL;
 
 	kc = clockid_to_kclock(timr->it_clock);
-	if (WARN_ON_ONCE(!kc || !kc->timer_get))
+	if (WARN_ON_ONCE(!kc || !kc->timer_get64))
 		ret = -EINVAL;
 	else
-		kc->timer_get(timr, cur_setting);
+		kc->timer_get64(timr, cur_setting);
 
 	unlock_timer(timr, flags);
 	return ret;
@@ -827,10 +841,11 @@ static int __timer_gettime(timer_t timer_id, struct itimerspec *cur_setting)
 SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
 		struct itimerspec __user *, setting)
 {
-	struct itimerspec cur_setting;
+	struct itimerspec64 cur_setting;
+
 	int ret = __timer_gettime(timer_id, &cur_setting);
 
-	if (!ret && copy_to_user(setting, &cur_setting, sizeof (cur_setting)))
+	if (!ret && put_itimerspec(&cur_setting, setting))
 		return -EFAULT;
 
 	return ret;
-- 
1.7.9.5


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

* [PATCH v5 08/24] posix-timers: Factor out the guts of 'timer_settime' for reusing
  2015-06-12  7:19 ` [PATCH v5 00/24] Convert the posix_clock_operations and k_clock structure to ready for 2038 Baolin Wang
                     ` (6 preceding siblings ...)
  2015-06-12  7:48   ` [PATCH v5 07/24] posix-timers: Implement y2038 safe timer_get64() callback Baolin Wang
@ 2015-06-12  7:48   ` Baolin Wang
  2015-06-12  7:48   ` [PATCH v5 09/24] posix-timers: Implement y2038 safe timer_set64() callback Baolin Wang
                     ` (16 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Baolin Wang @ 2015-06-12  7:48 UTC (permalink / raw)
  To: tglx; +Cc: arnd, linux-kernel, baolin.wang, y2038

In order to reuse the very same logic for the year 2038 safe syscalls
which we need to introduce for 32bit system, factor out the guts of
the 'timer_settime' syscall.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 kernel/time/posix-timers.c |   41 ++++++++++++++++++++++++++---------------
 1 file changed, 26 insertions(+), 15 deletions(-)

diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 70b5550..2f1c26f 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -927,27 +927,18 @@ common_timer_set(struct k_itimer *timr, int flags,
 	return 0;
 }
 
-/* Set a POSIX.1b interval timer */
-SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
-		const struct itimerspec __user *, new_setting,
-		struct itimerspec __user *, old_setting)
+static int __timer_settime(timer_t timer_id, int flags, struct itimerspec *new_spec,
+			   struct itimerspec *old_spec)
 {
 	struct k_itimer *timr;
-	struct itimerspec new_spec, old_spec;
 	int error = 0;
 	unsigned long flag;
-	struct itimerspec *rtn = old_setting ? &old_spec : NULL;
 	struct k_clock *kc;
 
-	if (!new_setting)
+	if (!timespec_valid(&new_spec->it_interval) ||
+	    !timespec_valid(&new_spec->it_value))
 		return -EINVAL;
 
-	if (copy_from_user(&new_spec, new_setting, sizeof (new_spec)))
-		return -EFAULT;
-
-	if (!timespec_valid(&new_spec.it_interval) ||
-	    !timespec_valid(&new_spec.it_value))
-		return -EINVAL;
 retry:
 	timr = lock_timer(timer_id, &flag);
 	if (!timr)
@@ -957,14 +948,34 @@ retry:
 	if (WARN_ON_ONCE(!kc || !kc->timer_set))
 		error = -EINVAL;
 	else
-		error = kc->timer_set(timr, flags, &new_spec, rtn);
+		error = kc->timer_set(timr, flags, new_spec, old_spec);
 
 	unlock_timer(timr, flag);
 	if (error == TIMER_RETRY) {
-		rtn = NULL;	// We already got the old time...
+		old_spec = NULL;     // We already got the old time...
 		goto retry;
 	}
 
+	return error;
+}
+
+/* Set a POSIX.1b interval timer */
+SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
+		const struct itimerspec __user *, new_setting,
+		struct itimerspec __user *, old_setting)
+{
+	struct itimerspec new_spec, old_spec;
+	int error = 0;
+	struct itimerspec *rtn = old_setting ? &old_spec : NULL;
+
+	if (!new_setting)
+		return -EINVAL;
+
+	if (copy_from_user(&new_spec, new_setting, sizeof (new_spec)))
+		return -EFAULT;
+
+	error = __timer_settime(timer_id, flags, &new_spec, rtn);
+
 	if (old_setting && !error &&
 	    copy_to_user(old_setting, &old_spec, sizeof (old_spec)))
 		error = -EFAULT;
-- 
1.7.9.5


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

* [PATCH v5 09/24] posix-timers: Implement y2038 safe timer_set64() callback
  2015-06-12  7:19 ` [PATCH v5 00/24] Convert the posix_clock_operations and k_clock structure to ready for 2038 Baolin Wang
                     ` (7 preceding siblings ...)
  2015-06-12  7:48   ` [PATCH v5 08/24] posix-timers: Factor out the guts of 'timer_settime' for reusing Baolin Wang
@ 2015-06-12  7:48   ` Baolin Wang
  2015-06-12  7:48   ` [PATCH v5 10/24] posix-timers: Factor out the guts of 'clock_settime' for reusing Baolin Wang
                     ` (15 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Baolin Wang @ 2015-06-12  7:48 UTC (permalink / raw)
  To: tglx; +Cc: arnd, linux-kernel, baolin.wang, y2038

The timer_set() callback in struct k_clock is not year 2038 safe on
32bit systems.

To address this implement a new callback timer_set64() which uses
struct itimerspec64 along with a default implementation which is a
wrapper for the existing timer_set() callback. The default callback
is installed at registration time for all posix clocks which are not
yet converted to timer_set64() and will be removed once this is
completed.

Use the new callback in __timer_settime().

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 include/linux/posix-timers.h |    3 +++
 kernel/time/posix-timers.c   |   39 +++++++++++++++++++++++++++++----------
 2 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index e84436b..16c3364 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -109,6 +109,9 @@ struct k_clock {
 	int (*timer_set) (struct k_itimer * timr, int flags,
 			  struct itimerspec * new_setting,
 			  struct itimerspec * old_setting);
+	int (*timer_set64) (struct k_itimer *timr, int flags,
+			    struct itimerspec64 *new_setting,
+			    struct itimerspec64 *old_setting);
 	int (*timer_del) (struct k_itimer * timr);
 #define TIMER_RETRY 1
 	void (*timer_get) (struct k_itimer * timr,
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 2f1c26f..778610c 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -560,6 +560,23 @@ static void default_timer_get64(struct k_itimer *timr,
 	*cur_setting64 = itimerspec_to_itimerspec64(&cur_setting);
 }
 
+static int default_timer_set64(struct k_itimer *timr, int flags,
+			       struct itimerspec64 *new_setting64,
+			       struct itimerspec64 *old_setting64)
+{
+	struct k_clock *kc = clockid_to_kclock(timr->it_clock);
+	struct itimerspec new_setting, old_setting;
+	struct itimerspec *rtn = old_setting64 ? &old_setting : NULL;
+	int ret;
+
+	new_setting = itimerspec64_to_itimerspec(new_setting64);
+	ret = kc->timer_set(timr, flags, &new_setting, rtn);
+	if (!ret && old_setting64)
+		*old_setting64 = itimerspec_to_itimerspec64(&old_setting);
+
+	return ret;
+}
+
 void posix_timers_register_clock(const clockid_t clock_id,
 				 struct k_clock *new_clock)
 {
@@ -582,6 +599,8 @@ void posix_timers_register_clock(const clockid_t clock_id,
 
 	if (new_clock->timer_get && !new_clock->timer_get64)
 		new_clock->timer_get64 = default_timer_get64;
+	if (new_clock->timer_set && !new_clock->timer_set64)
+		new_clock->timer_set64 = default_timer_set64;
 
 	posix_clocks[clock_id] = *new_clock;
 }
@@ -927,16 +946,16 @@ common_timer_set(struct k_itimer *timr, int flags,
 	return 0;
 }
 
-static int __timer_settime(timer_t timer_id, int flags, struct itimerspec *new_spec,
-			   struct itimerspec *old_spec)
+static int __timer_settime(timer_t timer_id, int flags, struct itimerspec64 *new_spec,
+			   struct itimerspec64 *old_spec)
 {
 	struct k_itimer *timr;
 	int error = 0;
 	unsigned long flag;
 	struct k_clock *kc;
 
-	if (!timespec_valid(&new_spec->it_interval) ||
-	    !timespec_valid(&new_spec->it_value))
+	if (!timespec64_valid(&new_spec->it_interval) ||
+	    !timespec64_valid(&new_spec->it_value))
 		return -EINVAL;
 
 retry:
@@ -945,10 +964,10 @@ retry:
 		return -EINVAL;
 
 	kc = clockid_to_kclock(timr->it_clock);
-	if (WARN_ON_ONCE(!kc || !kc->timer_set))
+	if (WARN_ON_ONCE(!kc || !kc->timer_set64))
 		error = -EINVAL;
 	else
-		error = kc->timer_set(timr, flags, new_spec, old_spec);
+		error = kc->timer_set64(timr, flags, new_spec, old_spec);
 
 	unlock_timer(timr, flag);
 	if (error == TIMER_RETRY) {
@@ -964,20 +983,20 @@ SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
 		const struct itimerspec __user *, new_setting,
 		struct itimerspec __user *, old_setting)
 {
-	struct itimerspec new_spec, old_spec;
+	struct itimerspec64 new_spec, old_spec;
 	int error = 0;
-	struct itimerspec *rtn = old_setting ? &old_spec : NULL;
+	struct itimerspec64 *rtn = old_setting ? &old_spec : NULL;
 
 	if (!new_setting)
 		return -EINVAL;
 
-	if (copy_from_user(&new_spec, new_setting, sizeof (new_spec)))
+	if (get_itimerspec(&new_spec, new_setting))
 		return -EFAULT;
 
 	error = __timer_settime(timer_id, flags, &new_spec, rtn);
 
 	if (old_setting && !error &&
-	    copy_to_user(old_setting, &old_spec, sizeof (old_spec)))
+	    put_itimerspec(&old_spec, old_setting))
 		error = -EFAULT;
 
 	return error;
-- 
1.7.9.5


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

* [PATCH v5 10/24] posix-timers: Factor out the guts of 'clock_settime' for reusing
  2015-06-12  7:19 ` [PATCH v5 00/24] Convert the posix_clock_operations and k_clock structure to ready for 2038 Baolin Wang
                     ` (8 preceding siblings ...)
  2015-06-12  7:48   ` [PATCH v5 09/24] posix-timers: Implement y2038 safe timer_set64() callback Baolin Wang
@ 2015-06-12  7:48   ` Baolin Wang
  2015-06-12  7:48   ` [PATCH v5 11/24] posix-timers: Implement y2038 safe clock_set64() callback Baolin Wang
                     ` (14 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Baolin Wang @ 2015-06-12  7:48 UTC (permalink / raw)
  To: tglx; +Cc: arnd, linux-kernel, baolin.wang, y2038

In order to reuse the very same logic for the year 2038 safe syscalls
which we need to introduce for 32bit system, factor out the guts of
the 'clock_settime' syscall.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 kernel/time/posix-timers.c |   14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 778610c..65610ac 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -1089,19 +1089,25 @@ void exit_itimers(struct signal_struct *sig)
 	}
 }
 
-SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
-		const struct timespec __user *, tp)
+static int __clock_settime(clockid_t which_clock, struct timespec *ts)
 {
 	struct k_clock *kc = clockid_to_kclock(which_clock);
-	struct timespec new_tp;
 
 	if (!kc || !kc->clock_set)
 		return -EINVAL;
 
+	return kc->clock_set(which_clock, ts);
+}
+
+SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
+		const struct timespec __user *, tp)
+{
+	struct timespec new_tp;
+
 	if (copy_from_user(&new_tp, tp, sizeof (*tp)))
 		return -EFAULT;
 
-	return kc->clock_set(which_clock, &new_tp);
+	return __clock_settime(which_clock, &new_tp);
 }
 
 SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
-- 
1.7.9.5


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

* [PATCH v5 11/24] posix-timers: Implement y2038 safe clock_set64() callback
  2015-06-12  7:19 ` [PATCH v5 00/24] Convert the posix_clock_operations and k_clock structure to ready for 2038 Baolin Wang
                     ` (9 preceding siblings ...)
  2015-06-12  7:48   ` [PATCH v5 10/24] posix-timers: Factor out the guts of 'clock_settime' for reusing Baolin Wang
@ 2015-06-12  7:48   ` Baolin Wang
  2015-06-12  7:48   ` [PATCH v5 12/24] posix-timers: Factor out the guts of 'clock_gettime' for reusing Baolin Wang
                     ` (13 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Baolin Wang @ 2015-06-12  7:48 UTC (permalink / raw)
  To: tglx; +Cc: arnd, linux-kernel, baolin.wang, y2038

The clock_set() callback in struct k_clock is not year 2038 safe on
32bit systems.

To address this implement a new callback clock_set64() which uses
struct timespec64 along with a default implementation which is a
wrapper for the existing clock_set() callback. The default callback
is installed at registration time for all posix clocks which are not
yet converted to clock_set64() and will be removed once this is
completed.

Use the new callback in __clock_settime().

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 include/linux/posix-timers.h |    2 ++
 kernel/time/posix-timers.c   |   24 +++++++++++++++++++-----
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index 16c3364..2b19ec8 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -100,6 +100,8 @@ struct k_clock {
 	int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
 	int (*clock_set) (const clockid_t which_clock,
 			  const struct timespec *tp);
+	int (*clock_set64) (const clockid_t which_clock,
+			    const struct timespec64 *tp);
 	int (*clock_get) (const clockid_t which_clock, struct timespec * tp);
 	int (*clock_adj) (const clockid_t which_clock, struct timex *tx);
 	int (*timer_create) (struct k_itimer *timer);
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 65610ac..dcc632c 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -577,6 +577,18 @@ static int default_timer_set64(struct k_itimer *timr, int flags,
 	return ret;
 }
 
+static int default_clock_set64(const clockid_t which_clock,
+			       const struct timespec64 *tp64)
+{
+	struct k_clock *kc = clockid_to_kclock(which_clock);
+	struct timespec tp;
+	int ret;
+
+	tp = timespec64_to_timespec(*tp64);
+	ret = kc->clock_set(which_clock, &tp);
+	return ret;
+}
+
 void posix_timers_register_clock(const clockid_t clock_id,
 				 struct k_clock *new_clock)
 {
@@ -601,6 +613,8 @@ void posix_timers_register_clock(const clockid_t clock_id,
 		new_clock->timer_get64 = default_timer_get64;
 	if (new_clock->timer_set && !new_clock->timer_set64)
 		new_clock->timer_set64 = default_timer_set64;
+	if (new_clock->clock_set && !new_clock->clock_set64)
+		new_clock->clock_set64 = default_clock_set64;
 
 	posix_clocks[clock_id] = *new_clock;
 }
@@ -1089,22 +1103,22 @@ void exit_itimers(struct signal_struct *sig)
 	}
 }
 
-static int __clock_settime(clockid_t which_clock, struct timespec *ts)
+static int __clock_settime(clockid_t which_clock, struct timespec64 *ts)
 {
 	struct k_clock *kc = clockid_to_kclock(which_clock);
 
-	if (!kc || !kc->clock_set)
+	if (!kc || !kc->clock_set64)
 		return -EINVAL;
 
-	return kc->clock_set(which_clock, ts);
+	return kc->clock_set64(which_clock, ts);
 }
 
 SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
 		const struct timespec __user *, tp)
 {
-	struct timespec new_tp;
+	struct timespec64 new_tp;
 
-	if (copy_from_user(&new_tp, tp, sizeof (*tp)))
+	if (get_timespec(&new_tp, tp))
 		return -EFAULT;
 
 	return __clock_settime(which_clock, &new_tp);
-- 
1.7.9.5


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

* [PATCH v5 12/24] posix-timers: Factor out the guts of 'clock_gettime' for reusing
  2015-06-12  7:19 ` [PATCH v5 00/24] Convert the posix_clock_operations and k_clock structure to ready for 2038 Baolin Wang
                     ` (10 preceding siblings ...)
  2015-06-12  7:48   ` [PATCH v5 11/24] posix-timers: Implement y2038 safe clock_set64() callback Baolin Wang
@ 2015-06-12  7:48   ` Baolin Wang
  2015-06-12  7:48   ` [PATCH v5 13/24] posix-timers: Implement y2038 safe clock_get64() callback Baolin Wang
                     ` (12 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Baolin Wang @ 2015-06-12  7:48 UTC (permalink / raw)
  To: tglx; +Cc: arnd, linux-kernel, baolin.wang, y2038

In order to reuse the very same logic for the year 2038 safe syscalls
which we need to introduce for 32bit system, factor out the guts of
the 'clock_gettime' syscall.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 kernel/time/posix-timers.c |   16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index dcc632c..ca63626 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -1124,17 +1124,23 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
 	return __clock_settime(which_clock, &new_tp);
 }
 
-SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
-		struct timespec __user *,tp)
+static int __clock_gettime(clockid_t which_clock, struct timespec *ts)
 {
 	struct k_clock *kc = clockid_to_kclock(which_clock);
-	struct timespec kernel_tp;
-	int error;
 
 	if (!kc)
 		return -EINVAL;
 
-	error = kc->clock_get(which_clock, &kernel_tp);
+	return kc->clock_get(which_clock, ts);
+}
+
+SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
+		struct timespec __user *,tp)
+{
+	struct timespec kernel_tp;
+	int error;
+
+	error = __clock_gettime(which_clock, &kernel_tp);
 
 	if (!error && copy_to_user(tp, &kernel_tp, sizeof (kernel_tp)))
 		error = -EFAULT;
-- 
1.7.9.5


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

* [PATCH v5 13/24] posix-timers: Implement y2038 safe clock_get64() callback
  2015-06-12  7:19 ` [PATCH v5 00/24] Convert the posix_clock_operations and k_clock structure to ready for 2038 Baolin Wang
                     ` (11 preceding siblings ...)
  2015-06-12  7:48   ` [PATCH v5 12/24] posix-timers: Factor out the guts of 'clock_gettime' for reusing Baolin Wang
@ 2015-06-12  7:48   ` Baolin Wang
  2015-06-12  7:48   ` [PATCH v5 14/24] posix-timers: Factor out the guts of 'clcok_getres' for reusing Baolin Wang
                     ` (11 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Baolin Wang @ 2015-06-12  7:48 UTC (permalink / raw)
  To: tglx; +Cc: arnd, linux-kernel, baolin.wang, y2038

The clock_get() callback in struct k_clock is not year 2038 safe on
32bit systems.

To address this implement a new callback clock_get64() which uses
struct timespec64 along with a default implementation which is a
wrapper for the existing clock_get() callback. The default callback
is installed at registration time for all posix clocks which are not
yet converted to clock_get64() and will be removed once this is
completed.

Use the new callback in __clock_gettime().

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 include/linux/posix-timers.h |    1 +
 kernel/time/posix-timers.c   |   28 ++++++++++++++++++++++------
 2 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index 2b19ec8..be2123d 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -103,6 +103,7 @@ struct k_clock {
 	int (*clock_set64) (const clockid_t which_clock,
 			    const struct timespec64 *tp);
 	int (*clock_get) (const clockid_t which_clock, struct timespec * tp);
+	int (*clock_get64) (const clockid_t which_clock, struct timespec64 *tp);
 	int (*clock_adj) (const clockid_t which_clock, struct timex *tx);
 	int (*timer_create) (struct k_itimer *timer);
 	int (*nsleep) (const clockid_t which_clock, int flags,
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index ca63626..021cd8f 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -589,6 +589,20 @@ static int default_clock_set64(const clockid_t which_clock,
 	return ret;
 }
 
+static int default_clock_get64(const clockid_t which_clock,
+			       struct timespec64 *tp64)
+{
+	struct k_clock *kc = clockid_to_kclock(which_clock);
+	struct timespec tp;
+	int ret;
+
+	ret = kc->clock_get(which_clock, &tp);
+	if (!ret)
+		*tp64 = timespec_to_timespec64(tp);
+
+	return ret;
+}
+
 void posix_timers_register_clock(const clockid_t clock_id,
 				 struct k_clock *new_clock)
 {
@@ -598,8 +612,8 @@ void posix_timers_register_clock(const clockid_t clock_id,
 		return;
 	}
 
-	if (!new_clock->clock_get) {
-		printk(KERN_WARNING "POSIX clock id %d lacks clock_get()\n",
+	if (!new_clock->clock_get && !new_clock->clock_get64) {
+		printk(KERN_WARNING "POSIX clock id %d lacks clock_get() and clock_get64()\n",
 		       clock_id);
 		return;
 	}
@@ -615,6 +629,8 @@ void posix_timers_register_clock(const clockid_t clock_id,
 		new_clock->timer_set64 = default_timer_set64;
 	if (new_clock->clock_set && !new_clock->clock_set64)
 		new_clock->clock_set64 = default_clock_set64;
+	if (new_clock->clock_get && !new_clock->clock_get64)
+		new_clock->clock_get64 = default_clock_get64;
 
 	posix_clocks[clock_id] = *new_clock;
 }
@@ -1124,25 +1140,25 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
 	return __clock_settime(which_clock, &new_tp);
 }
 
-static int __clock_gettime(clockid_t which_clock, struct timespec *ts)
+static int __clock_gettime(clockid_t which_clock, struct timespec64 *ts)
 {
 	struct k_clock *kc = clockid_to_kclock(which_clock);
 
 	if (!kc)
 		return -EINVAL;
 
-	return kc->clock_get(which_clock, ts);
+	return kc->clock_get64(which_clock, ts);
 }
 
 SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
 		struct timespec __user *,tp)
 {
-	struct timespec kernel_tp;
+	struct timespec64 kernel_tp;
 	int error;
 
 	error = __clock_gettime(which_clock, &kernel_tp);
 
-	if (!error && copy_to_user(tp, &kernel_tp, sizeof (kernel_tp)))
+	if (!error && put_timespec(&kernel_tp, tp))
 		error = -EFAULT;
 
 	return error;
-- 
1.7.9.5


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

* [PATCH v5 14/24] posix-timers: Factor out the guts of 'clcok_getres' for reusing
  2015-06-12  7:19 ` [PATCH v5 00/24] Convert the posix_clock_operations and k_clock structure to ready for 2038 Baolin Wang
                     ` (12 preceding siblings ...)
  2015-06-12  7:48   ` [PATCH v5 13/24] posix-timers: Implement y2038 safe clock_get64() callback Baolin Wang
@ 2015-06-12  7:48   ` Baolin Wang
  2015-06-12  7:48   ` [PATCH v5 15/24] posix-timers: Implement y2038 safe clock_getres64() callback Baolin Wang
                     ` (10 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Baolin Wang @ 2015-06-12  7:48 UTC (permalink / raw)
  To: tglx; +Cc: arnd, linux-kernel, baolin.wang, y2038

In order to reuse the very same logic for the year 2038 safe syscalls
which we need to introduce for 32bit system, factor out the guts of
the 'clock_getres' syscall.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 kernel/time/posix-timers.c |   16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 021cd8f..a5207f0 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -1187,17 +1187,23 @@ SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock,
 	return err;
 }
 
-SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock,
-		struct timespec __user *, tp)
+static int __clock_getres(clockid_t which_clock, struct timespec *ts)
 {
 	struct k_clock *kc = clockid_to_kclock(which_clock);
-	struct timespec rtn_tp;
-	int error;
 
 	if (!kc)
 		return -EINVAL;
 
-	error = kc->clock_getres(which_clock, &rtn_tp);
+	return kc->clock_getres(which_clock, ts);
+}
+
+SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock,
+		struct timespec __user *, tp)
+{
+	struct timespec rtn_tp;
+	int error;
+
+	error = __clock_getres(which_clock, &rtn_tp);
 
 	if (!error && tp && copy_to_user(tp, &rtn_tp, sizeof (rtn_tp)))
 		error = -EFAULT;
-- 
1.7.9.5


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

* [PATCH v5 15/24] posix-timers: Implement y2038 safe clock_getres64() callback
  2015-06-12  7:19 ` [PATCH v5 00/24] Convert the posix_clock_operations and k_clock structure to ready for 2038 Baolin Wang
                     ` (13 preceding siblings ...)
  2015-06-12  7:48   ` [PATCH v5 14/24] posix-timers: Factor out the guts of 'clcok_getres' for reusing Baolin Wang
@ 2015-06-12  7:48   ` Baolin Wang
  2015-06-12  7:53   ` [PATCH v5 16/24] timekeeping: Change the implementation of timekeeping_clocktai() Baolin Wang
                     ` (9 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Baolin Wang @ 2015-06-12  7:48 UTC (permalink / raw)
  To: tglx; +Cc: arnd, linux-kernel, baolin.wang, y2038

The clock_getres() callback in struct k_clock is not year 2038 safe on
32bit systems.

To address this implement a new callback clock_getres64() which uses
struct timespec64 along with a default implementation which is a
wrapper for the existing clock_getres() callback. The default callback
is installed at registration time for all posix clocks which are not
yet converted to clock_getres64() and will be removed once this is
completed.

Use the new callback in __clock_getres().

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 include/linux/posix-timers.h |    1 +
 kernel/time/posix-timers.c   |   31 ++++++++++++++++++++++++-------
 2 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index be2123d..35786c5 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -98,6 +98,7 @@ struct k_itimer {
 
 struct k_clock {
 	int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
+	int (*clock_getres64) (const clockid_t which_clock, struct timespec64 *tp);
 	int (*clock_set) (const clockid_t which_clock,
 			  const struct timespec *tp);
 	int (*clock_set64) (const clockid_t which_clock,
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index a5207f0..0b0663a 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -603,6 +603,20 @@ static int default_clock_get64(const clockid_t which_clock,
 	return ret;
 }
 
+static int default_clock_getres64(const clockid_t which_clock,
+				  struct timespec64 *tp64)
+{
+	struct k_clock *kc = clockid_to_kclock(which_clock);
+	struct timespec tp;
+	int ret;
+
+	ret = kc->clock_getres(which_clock, &tp);
+	if (!ret)
+		*tp64 = timespec_to_timespec64(tp);
+
+	return 0;
+}
+
 void posix_timers_register_clock(const clockid_t clock_id,
 				 struct k_clock *new_clock)
 {
@@ -617,8 +631,8 @@ void posix_timers_register_clock(const clockid_t clock_id,
 		       clock_id);
 		return;
 	}
-	if (!new_clock->clock_getres) {
-		printk(KERN_WARNING "POSIX clock id %d lacks clock_getres()\n",
+	if (!new_clock->clock_getres && !new_clock->clock_getres64) {
+		printk(KERN_WARNING "POSIX clock id %d lacks clock_getres() and clock_getres64()\n",
 		       clock_id);
 		return;
 	}
@@ -631,6 +645,8 @@ void posix_timers_register_clock(const clockid_t clock_id,
 		new_clock->clock_set64 = default_clock_set64;
 	if (new_clock->clock_get && !new_clock->clock_get64)
 		new_clock->clock_get64 = default_clock_get64;
+	if (new_clock->clock_getres && !new_clock->clock_getres64)
+		new_clock->clock_getres64 = default_clock_getres64;
 
 	posix_clocks[clock_id] = *new_clock;
 }
@@ -678,7 +694,8 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
 		return (id & CLOCKFD_MASK) == CLOCKFD ?
 			&clock_posix_dynamic : &clock_posix_cpu;
 
-	if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
+	if (id >= MAX_CLOCKS || (!posix_clocks[id].clock_getres
+	    && !posix_clocks[id].clock_getres64))
 		return NULL;
 	return &posix_clocks[id];
 }
@@ -1187,25 +1204,25 @@ SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock,
 	return err;
 }
 
-static int __clock_getres(clockid_t which_clock, struct timespec *ts)
+static int __clock_getres(clockid_t which_clock, struct timespec64 *ts)
 {
 	struct k_clock *kc = clockid_to_kclock(which_clock);
 
 	if (!kc)
 		return -EINVAL;
 
-	return kc->clock_getres(which_clock, ts);
+	return kc->clock_getres64(which_clock, ts);
 }
 
 SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock,
 		struct timespec __user *, tp)
 {
-	struct timespec rtn_tp;
+	struct timespec64 rtn_tp;
 	int error;
 
 	error = __clock_getres(which_clock, &rtn_tp);
 
-	if (!error && tp && copy_to_user(tp, &rtn_tp, sizeof (rtn_tp)))
+	if (!error && tp && put_timespec(&rtn_tp, tp))
 		error = -EFAULT;
 
 	return error;
-- 
1.7.9.5


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

* [PATCH v5 16/24] timekeeping: Change the implementation of timekeeping_clocktai()
  2015-06-12  7:19 ` [PATCH v5 00/24] Convert the posix_clock_operations and k_clock structure to ready for 2038 Baolin Wang
                     ` (14 preceding siblings ...)
  2015-06-12  7:48   ` [PATCH v5 15/24] posix-timers: Implement y2038 safe clock_getres64() callback Baolin Wang
@ 2015-06-12  7:53   ` Baolin Wang
  2015-06-12  7:56   ` [PATCH v5 17/24] posix-timers: Convert to y2038 safe callbacks Baolin Wang
                     ` (8 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Baolin Wang @ 2015-06-12  7:53 UTC (permalink / raw)
  To: tglx
  Cc: arnd, john.stultz, pang.xunlei, mingo, peterz, linux-kernel,
	baolin.wang, y2038

The timekeeping_clocktai() function is not year 2038 safe on 32bit
systems, change its implementation with using struct timespec64.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 include/linux/timekeeping.h |    4 ++--
 kernel/time/posix-timers.c  |    4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h
index 2dcc86b..07581c0 100644
--- a/include/linux/timekeeping.h
+++ b/include/linux/timekeeping.h
@@ -256,9 +256,9 @@ static inline void get_monotonic_boottime64(struct timespec64 *ts)
 	*ts = ktime_to_timespec64(ktime_get_boottime());
 }
 
-static inline void timekeeping_clocktai(struct timespec *ts)
+static inline void timekeeping_clocktai(struct timespec64 *ts)
 {
-	*ts = ktime_to_timespec(ktime_get_clocktai());
+	*ts = ktime_to_timespec64(ktime_get_clocktai());
 }
 
 /*
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 0b0663a..029a2b6 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -296,7 +296,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
 	return 0;
 }
 
-static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
+static int posix_get_tai(clockid_t which_clock, struct timespec64 *tp)
 {
 	timekeeping_clocktai(tp);
 	return 0;
@@ -350,7 +350,7 @@ static __init int init_posix_timers(void)
 	};
 	struct k_clock clock_tai = {
 		.clock_getres	= posix_get_hrtimer_res,
-		.clock_get	= posix_get_tai,
+		.clock_get64	= posix_get_tai,
 		.nsleep		= common_nsleep,
 		.nsleep_restart	= hrtimer_nanosleep_restart,
 		.timer_create	= common_timer_create,
-- 
1.7.9.5


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

* [PATCH v5 17/24] posix-timers: Convert to y2038 safe callbacks
  2015-06-12  7:19 ` [PATCH v5 00/24] Convert the posix_clock_operations and k_clock structure to ready for 2038 Baolin Wang
                     ` (15 preceding siblings ...)
  2015-06-12  7:53   ` [PATCH v5 16/24] timekeeping: Change the implementation of timekeeping_clocktai() Baolin Wang
@ 2015-06-12  7:56   ` Baolin Wang
  2015-06-12  7:58   ` [PATCH v5 18/24] mmtimer: " Baolin Wang
                     ` (7 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Baolin Wang @ 2015-06-12  7:56 UTC (permalink / raw)
  To: tglx; +Cc: arnd, linux-kernel, baolin.wang, y2038

The clock_getres()/clock_get()/clock_set()/timer_set()/timer_get()
callbacks in struct k_clock are not year 2038 safe on 32bit systems,
and it need convert to safe callbacks which use struct timespec64
or struct itimerspec64.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 kernel/time/posix-timers.c |   94 ++++++++++++++++++++++----------------------
 1 file changed, 47 insertions(+), 47 deletions(-)

diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 029a2b6..80f630a 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -132,9 +132,9 @@ static struct k_clock posix_clocks[MAX_CLOCKS];
 static int common_nsleep(const clockid_t, int flags, struct timespec *t,
 			 struct timespec __user *rmtp);
 static int common_timer_create(struct k_itimer *new_timer);
-static void common_timer_get(struct k_itimer *, struct itimerspec *);
+static void common_timer_get(struct k_itimer *, struct itimerspec64 *);
 static int common_timer_set(struct k_itimer *, int,
-			    struct itimerspec *, struct itimerspec *);
+			    struct itimerspec64 *, struct itimerspec64 *);
 static int common_timer_del(struct k_itimer *timer);
 
 static enum hrtimer_restart posix_timer_fn(struct hrtimer *data);
@@ -233,17 +233,17 @@ static inline void unlock_timer(struct k_itimer *timr, unsigned long flags)
 }
 
 /* Get clock_realtime */
-static int posix_clock_realtime_get(clockid_t which_clock, struct timespec *tp)
+static int posix_clock_realtime_get(clockid_t which_clock, struct timespec64 *tp)
 {
-	ktime_get_real_ts(tp);
+	ktime_get_real_ts64(tp);
 	return 0;
 }
 
 /* Set clock_realtime */
 static int posix_clock_realtime_set(const clockid_t which_clock,
-				    const struct timespec *tp)
+				    const struct timespec64 *tp)
 {
-	return do_sys_settimeofday(tp, NULL);
+	return do_sys_settimeofday64(tp, NULL);
 }
 
 static int posix_clock_realtime_adj(const clockid_t which_clock,
@@ -255,44 +255,44 @@ static int posix_clock_realtime_adj(const clockid_t which_clock,
 /*
  * Get monotonic time for posix timers
  */
-static int posix_ktime_get_ts(clockid_t which_clock, struct timespec *tp)
+static int posix_ktime_get_ts(clockid_t which_clock, struct timespec64 *tp)
 {
-	ktime_get_ts(tp);
+	ktime_get_ts64(tp);
 	return 0;
 }
 
 /*
  * Get monotonic-raw time for posix timers
  */
-static int posix_get_monotonic_raw(clockid_t which_clock, struct timespec *tp)
+static int posix_get_monotonic_raw(clockid_t which_clock, struct timespec64 *tp)
 {
-	getrawmonotonic(tp);
+	getrawmonotonic64(tp);
 	return 0;
 }
 
 
-static int posix_get_realtime_coarse(clockid_t which_clock, struct timespec *tp)
+static int posix_get_realtime_coarse(clockid_t which_clock, struct timespec64 *tp)
 {
-	*tp = current_kernel_time();
+	*tp = current_kernel_time64();
 	return 0;
 }
 
 static int posix_get_monotonic_coarse(clockid_t which_clock,
-						struct timespec *tp)
+						struct timespec64 *tp)
 {
-	*tp = get_monotonic_coarse();
+	*tp = get_monotonic_coarse64();
 	return 0;
 }
 
-static int posix_get_coarse_res(const clockid_t which_clock, struct timespec *tp)
+static int posix_get_coarse_res(const clockid_t which_clock, struct timespec64 *tp)
 {
-	*tp = ktime_to_timespec(KTIME_LOW_RES);
+	*tp = ktime_to_timespec64(KTIME_LOW_RES);
 	return 0;
 }
 
-static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
+static int posix_get_boottime(const clockid_t which_clock, struct timespec64 *tp)
 {
-	get_monotonic_boottime(tp);
+	get_monotonic_boottime64(tp);
 	return 0;
 }
 
@@ -302,7 +302,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec64 *tp)
 	return 0;
 }
 
-static int posix_get_hrtimer_res(clockid_t which_clock, struct timespec *tp)
+static int posix_get_hrtimer_res(clockid_t which_clock, struct timespec64 *tp)
 {
 	tp->tv_sec = 0;
 	tp->tv_nsec = hrtimer_resolution;
@@ -315,57 +315,57 @@ static int posix_get_hrtimer_res(clockid_t which_clock, struct timespec *tp)
 static __init int init_posix_timers(void)
 {
 	struct k_clock clock_realtime = {
-		.clock_getres	= posix_get_hrtimer_res,
-		.clock_get	= posix_clock_realtime_get,
-		.clock_set	= posix_clock_realtime_set,
+		.clock_getres64	= posix_get_hrtimer_res,
+		.clock_get64	= posix_clock_realtime_get,
+		.clock_set64	= posix_clock_realtime_set,
 		.clock_adj	= posix_clock_realtime_adj,
 		.nsleep		= common_nsleep,
 		.nsleep_restart	= hrtimer_nanosleep_restart,
 		.timer_create	= common_timer_create,
-		.timer_set	= common_timer_set,
-		.timer_get	= common_timer_get,
+		.timer_set64	= common_timer_set,
+		.timer_get64	= common_timer_get,
 		.timer_del	= common_timer_del,
 	};
 	struct k_clock clock_monotonic = {
-		.clock_getres	= posix_get_hrtimer_res,
-		.clock_get	= posix_ktime_get_ts,
+		.clock_getres64	= posix_get_hrtimer_res,
+		.clock_get64	= posix_ktime_get_ts,
 		.nsleep		= common_nsleep,
 		.nsleep_restart	= hrtimer_nanosleep_restart,
 		.timer_create	= common_timer_create,
-		.timer_set	= common_timer_set,
-		.timer_get	= common_timer_get,
+		.timer_set64	= common_timer_set,
+		.timer_get64	= common_timer_get,
 		.timer_del	= common_timer_del,
 	};
 	struct k_clock clock_monotonic_raw = {
-		.clock_getres	= posix_get_hrtimer_res,
-		.clock_get	= posix_get_monotonic_raw,
+		.clock_getres64	= posix_get_hrtimer_res,
+		.clock_get64	= posix_get_monotonic_raw,
 	};
 	struct k_clock clock_realtime_coarse = {
-		.clock_getres	= posix_get_coarse_res,
-		.clock_get	= posix_get_realtime_coarse,
+		.clock_getres64	= posix_get_coarse_res,
+		.clock_get64	= posix_get_realtime_coarse,
 	};
 	struct k_clock clock_monotonic_coarse = {
-		.clock_getres	= posix_get_coarse_res,
-		.clock_get	= posix_get_monotonic_coarse,
+		.clock_getres64	= posix_get_coarse_res,
+		.clock_get64	= posix_get_monotonic_coarse,
 	};
 	struct k_clock clock_tai = {
-		.clock_getres	= posix_get_hrtimer_res,
+		.clock_getres64	= posix_get_hrtimer_res,
 		.clock_get64	= posix_get_tai,
 		.nsleep		= common_nsleep,
 		.nsleep_restart	= hrtimer_nanosleep_restart,
 		.timer_create	= common_timer_create,
-		.timer_set	= common_timer_set,
-		.timer_get	= common_timer_get,
+		.timer_set64	= common_timer_set,
+		.timer_get64	= common_timer_get,
 		.timer_del	= common_timer_del,
 	};
 	struct k_clock clock_boottime = {
-		.clock_getres	= posix_get_hrtimer_res,
-		.clock_get	= posix_get_boottime,
+		.clock_getres64	= posix_get_hrtimer_res,
+		.clock_get64	= posix_get_boottime,
 		.nsleep		= common_nsleep,
 		.nsleep_restart	= hrtimer_nanosleep_restart,
 		.timer_create	= common_timer_create,
-		.timer_set	= common_timer_set,
-		.timer_get	= common_timer_get,
+		.timer_set64	= common_timer_set,
+		.timer_get64	= common_timer_get,
 		.timer_del	= common_timer_del,
 	};
 
@@ -842,7 +842,7 @@ static struct k_itimer *__lock_timer(timer_t timer_id, unsigned long *flags)
  * report.
  */
 static void
-common_timer_get(struct k_itimer *timr, struct itimerspec *cur_setting)
+common_timer_get(struct k_itimer *timr, struct itimerspec64 *cur_setting)
 {
 	ktime_t now, remaining, iv;
 	struct hrtimer *timer = &timr->it.real.timer;
@@ -853,7 +853,7 @@ common_timer_get(struct k_itimer *timr, struct itimerspec *cur_setting)
 
 	/* interval timer ? */
 	if (iv.tv64)
-		cur_setting->it_interval = ktime_to_timespec(iv);
+		cur_setting->it_interval = ktime_to_timespec64(iv);
 	else if (!hrtimer_active(timer) &&
 		 (timr->it_sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_NONE)
 		return;
@@ -879,7 +879,7 @@ common_timer_get(struct k_itimer *timr, struct itimerspec *cur_setting)
 		if ((timr->it_sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_NONE)
 			cur_setting->it_value.tv_nsec = 1;
 	} else
-		cur_setting->it_value = ktime_to_timespec(remaining);
+		cur_setting->it_value = ktime_to_timespec64(remaining);
 }
 
 static int __timer_gettime(timer_t timer_id, struct itimerspec64 *cur_setting)
@@ -946,7 +946,7 @@ SYSCALL_DEFINE1(timer_getoverrun, timer_t, timer_id)
 /* timr->it_lock is taken. */
 static int
 common_timer_set(struct k_itimer *timr, int flags,
-		 struct itimerspec *new_setting, struct itimerspec *old_setting)
+		 struct itimerspec64 *new_setting, struct itimerspec64 *old_setting)
 {
 	struct hrtimer *timer = &timr->it.real.timer;
 	enum hrtimer_mode mode;
@@ -975,10 +975,10 @@ common_timer_set(struct k_itimer *timr, int flags,
 	hrtimer_init(&timr->it.real.timer, timr->it_clock, mode);
 	timr->it.real.timer.function = posix_timer_fn;
 
-	hrtimer_set_expires(timer, timespec_to_ktime(new_setting->it_value));
+	hrtimer_set_expires(timer, timespec64_to_ktime(new_setting->it_value));
 
 	/* Convert interval */
-	timr->it.real.interval = timespec_to_ktime(new_setting->it_interval);
+	timr->it.real.interval = timespec64_to_ktime(new_setting->it_interval);
 
 	/* SIGEV_NONE timers are not queued ! See common_timer_get */
 	if (((timr->it_sigev_notify & ~SIGEV_THREAD_ID) == SIGEV_NONE)) {
-- 
1.7.9.5


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

* [PATCH v5 18/24] mmtimer: Convert to y2038 safe callbacks
  2015-06-12  7:19 ` [PATCH v5 00/24] Convert the posix_clock_operations and k_clock structure to ready for 2038 Baolin Wang
                     ` (16 preceding siblings ...)
  2015-06-12  7:56   ` [PATCH v5 17/24] posix-timers: Convert to y2038 safe callbacks Baolin Wang
@ 2015-06-12  7:58   ` Baolin Wang
  2015-06-12  8:00   ` [PATCH v5 19/24] alarmtimer: " Baolin Wang
                     ` (6 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Baolin Wang @ 2015-06-12  7:58 UTC (permalink / raw)
  To: arnd; +Cc: gregkh, linux-kernel, baolin.wang, y2038

The clock_getres()/clock_get()/clock_set()/timer_set()/timer_get()
callbacks in struct k_clock are not year 2038 safe on 32bit systems,
and it need convert to safe callbacks which use struct timespec64
or struct itimerspec64.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 drivers/char/mmtimer.c |   36 +++++++++++++++++-------------------
 1 file changed, 17 insertions(+), 19 deletions(-)

diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index 3d6c067..213d0bb 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -478,18 +478,18 @@ static int sgi_clock_period;
 static struct timespec sgi_clock_offset;
 static int sgi_clock_period;
 
-static int sgi_clock_get(clockid_t clockid, struct timespec *tp)
+static int sgi_clock_get(clockid_t clockid, struct timespec64 *tp)
 {
 	u64 nsec;
 
 	nsec = rtc_time() * sgi_clock_period
 			+ sgi_clock_offset.tv_nsec;
-	*tp = ns_to_timespec(nsec);
+	*tp = ns_to_timespec64(nsec);
 	tp->tv_sec += sgi_clock_offset.tv_sec;
 	return 0;
 };
 
-static int sgi_clock_set(const clockid_t clockid, const struct timespec *tp)
+static int sgi_clock_set(const clockid_t clockid, const struct timespec64 *tp)
 {
 
 	u64 nsec;
@@ -657,7 +657,7 @@ static int sgi_timer_del(struct k_itimer *timr)
 }
 
 /* Assumption: it_lock is already held with irq's disabled */
-static void sgi_timer_get(struct k_itimer *timr, struct itimerspec *cur_setting)
+static void sgi_timer_get(struct k_itimer *timr, struct itimerspec64 *cur_setting)
 {
 
 	if (timr->it.mmtimer.clock == TIMER_OFF) {
@@ -668,14 +668,14 @@ static void sgi_timer_get(struct k_itimer *timr, struct itimerspec *cur_setting)
 		return;
 	}
 
-	cur_setting->it_interval = ns_to_timespec(timr->it.mmtimer.incr * sgi_clock_period);
-	cur_setting->it_value = ns_to_timespec((timr->it.mmtimer.expires - rtc_time()) * sgi_clock_period);
+	cur_setting->it_interval = ns_to_timespec64(timr->it.mmtimer.incr * sgi_clock_period);
+	cur_setting->it_value = ns_to_timespec64((timr->it.mmtimer.expires - rtc_time()) * sgi_clock_period);
 }
 
 
 static int sgi_timer_set(struct k_itimer *timr, int flags,
-	struct itimerspec * new_setting,
-	struct itimerspec * old_setting)
+	struct itimerspec64 *new_setting,
+	struct itimerspec64 *old_setting)
 {
 	unsigned long when, period, irqflags;
 	int err = 0;
@@ -687,8 +687,8 @@ static int sgi_timer_set(struct k_itimer *timr, int flags,
 		sgi_timer_get(timr, old_setting);
 
 	sgi_timer_del(timr);
-	when = timespec_to_ns(&new_setting->it_value);
-	period = timespec_to_ns(&new_setting->it_interval);
+	when = timespec64_to_ns(&new_setting->it_value);
+	period = timespec64_to_ns(&new_setting->it_interval);
 
 	if (when == 0)
 		/* Clear timer */
@@ -699,11 +699,9 @@ static int sgi_timer_set(struct k_itimer *timr, int flags,
 		return -ENOMEM;
 
 	if (flags & TIMER_ABSTIME) {
-		struct timespec n;
 		unsigned long now;
 
-		getnstimeofday(&n);
-		now = timespec_to_ns(&n);
+		now = ktime_get_real_ns();
 		if (when > now)
 			when -= now;
 		else
@@ -765,7 +763,7 @@ static int sgi_timer_set(struct k_itimer *timr, int flags,
 	return err;
 }
 
-static int sgi_clock_getres(const clockid_t which_clock, struct timespec *tp)
+static int sgi_clock_getres(const clockid_t which_clock, struct timespec64 *tp)
 {
 	tp->tv_sec = 0;
 	tp->tv_nsec = sgi_clock_period;
@@ -773,13 +771,13 @@ static int sgi_clock_getres(const clockid_t which_clock, struct timespec *tp)
 }
 
 static struct k_clock sgi_clock = {
-	.clock_set	= sgi_clock_set,
-	.clock_get	= sgi_clock_get,
-	.clock_getres	= sgi_clock_getres,
+	.clock_set64	= sgi_clock_set,
+	.clock_get64	= sgi_clock_get,
+	.clock_getres64	= sgi_clock_getres,
 	.timer_create	= sgi_timer_create,
-	.timer_set	= sgi_timer_set,
+	.timer_set64	= sgi_timer_set,
 	.timer_del	= sgi_timer_del,
-	.timer_get	= sgi_timer_get
+	.timer_get64	= sgi_timer_get
 };
 
 /**
-- 
1.7.9.5


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

* [PATCH v5 19/24] alarmtimer: Convert to y2038 safe callbacks
  2015-06-12  7:19 ` [PATCH v5 00/24] Convert the posix_clock_operations and k_clock structure to ready for 2038 Baolin Wang
                     ` (17 preceding siblings ...)
  2015-06-12  7:58   ` [PATCH v5 18/24] mmtimer: " Baolin Wang
@ 2015-06-12  8:00   ` Baolin Wang
  2015-06-12  8:03   ` [PATCH v5 20/24] posix-clock: " Baolin Wang
                     ` (5 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Baolin Wang @ 2015-06-12  8:00 UTC (permalink / raw)
  To: tglx; +Cc: arnd, linux-kernel, baolin.wang, y2038

The clock_getres()/clock_get()/clock_set()/timer_set()/timer_get()
callbacks in struct k_clock are not year 2038 safe on 32bit systems,
and it need convert to safe callbacks which use struct timespec64
or struct itimerspec64.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 kernel/time/alarmtimer.c |   38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index 7fbba63..c9a0adf 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -486,11 +486,11 @@ static enum alarmtimer_restart alarm_handle_timer(struct alarm *alarm,
 /**
  * alarm_clock_getres - posix getres interface
  * @which_clock: clockid
- * @tp: timespec to fill
+ * @tp: timespec64 to fill
  *
  * Returns the granularity of underlying alarm base clock
  */
-static int alarm_clock_getres(const clockid_t which_clock, struct timespec *tp)
+static int alarm_clock_getres(const clockid_t which_clock, struct timespec64 *tp)
 {
 	if (!alarmtimer_get_rtcdev())
 		return -EINVAL;
@@ -503,18 +503,18 @@ static int alarm_clock_getres(const clockid_t which_clock, struct timespec *tp)
 /**
  * alarm_clock_get - posix clock_get interface
  * @which_clock: clockid
- * @tp: timespec to fill.
+ * @tp: timespec64 to fill.
  *
  * Provides the underlying alarm base time.
  */
-static int alarm_clock_get(clockid_t which_clock, struct timespec *tp)
+static int alarm_clock_get(clockid_t which_clock, struct timespec64 *tp)
 {
 	struct alarm_base *base = &alarm_bases[clock2alarm(which_clock)];
 
 	if (!alarmtimer_get_rtcdev())
 		return -EINVAL;
 
-	*tp = ktime_to_timespec(base->gettime());
+	*tp = ktime_to_timespec64(base->gettime());
 	return 0;
 }
 
@@ -544,24 +544,24 @@ static int alarm_timer_create(struct k_itimer *new_timer)
 /**
  * alarm_timer_get - posix timer_get interface
  * @new_timer: k_itimer pointer
- * @cur_setting: itimerspec data to fill
+ * @cur_setting: itimerspec64 data to fill
  *
  * Copies out the current itimerspec data
  */
 static void alarm_timer_get(struct k_itimer *timr,
-				struct itimerspec *cur_setting)
+				struct itimerspec64 *cur_setting)
 {
 	ktime_t relative_expiry_time =
 		alarm_expires_remaining(&(timr->it.alarm.alarmtimer));
 
 	if (ktime_to_ns(relative_expiry_time) > 0) {
-		cur_setting->it_value = ktime_to_timespec(relative_expiry_time);
+		cur_setting->it_value = ktime_to_timespec64(relative_expiry_time);
 	} else {
 		cur_setting->it_value.tv_sec = 0;
 		cur_setting->it_value.tv_nsec = 0;
 	}
 
-	cur_setting->it_interval = ktime_to_timespec(timr->it.alarm.interval);
+	cur_setting->it_interval = ktime_to_timespec64(timr->it.alarm.interval);
 }
 
 /**
@@ -585,14 +585,14 @@ static int alarm_timer_del(struct k_itimer *timr)
  * alarm_timer_set - posix timer_set interface
  * @timr: k_itimer pointer to be deleted
  * @flags: timer flags
- * @new_setting: itimerspec to be used
- * @old_setting: itimerspec being replaced
+ * @new_setting: itimerspec64 to be used
+ * @old_setting: itimerspec64 being replaced
  *
  * Sets the timer to new_setting, and starts the timer.
  */
 static int alarm_timer_set(struct k_itimer *timr, int flags,
-				struct itimerspec *new_setting,
-				struct itimerspec *old_setting)
+				struct itimerspec64 *new_setting,
+				struct itimerspec64 *old_setting)
 {
 	ktime_t exp;
 
@@ -610,8 +610,8 @@ static int alarm_timer_set(struct k_itimer *timr, int flags,
 		return TIMER_RETRY;
 
 	/* start the timer */
-	timr->it.alarm.interval = timespec_to_ktime(new_setting->it_interval);
-	exp = timespec_to_ktime(new_setting->it_value);
+	timr->it.alarm.interval = timespec64_to_ktime(new_setting->it_interval);
+	exp = timespec64_to_ktime(new_setting->it_value);
 	/* Convert (if necessary) to absolute time */
 	if (flags != TIMER_ABSTIME) {
 		ktime_t now;
@@ -821,12 +821,12 @@ static int __init alarmtimer_init(void)
 	int error = 0;
 	int i;
 	struct k_clock alarm_clock = {
-		.clock_getres	= alarm_clock_getres,
-		.clock_get	= alarm_clock_get,
+		.clock_getres64	= alarm_clock_getres,
+		.clock_get64	= alarm_clock_get,
 		.timer_create	= alarm_timer_create,
-		.timer_set	= alarm_timer_set,
+		.timer_set64	= alarm_timer_set,
 		.timer_del	= alarm_timer_del,
-		.timer_get	= alarm_timer_get,
+		.timer_get64	= alarm_timer_get,
 		.nsleep		= alarm_timer_nsleep,
 	};
 
-- 
1.7.9.5


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

* [PATCH v5 20/24] posix-clock: Convert to y2038 safe callbacks
  2015-06-12  7:19 ` [PATCH v5 00/24] Convert the posix_clock_operations and k_clock structure to ready for 2038 Baolin Wang
                     ` (18 preceding siblings ...)
  2015-06-12  8:00   ` [PATCH v5 19/24] alarmtimer: " Baolin Wang
@ 2015-06-12  8:03   ` Baolin Wang
  2015-06-12  8:06   ` [PATCH v5 21/24] time: Introduce timespec64_to_jiffies()/jiffies_to_timespec64() Baolin Wang
                     ` (4 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Baolin Wang @ 2015-06-12  8:03 UTC (permalink / raw)
  To: richardcochran; +Cc: arnd, linux-kernel, netdev, baolin.wang, y2038

The clock_getres()/clock_get()/clock_set()/timer_set()/timer_get()
callbacks in struct k_clock are not year 2038 safe on 32bit systems,
and it need convert to safe callbacks which use struct timespec64
or struct itimerspec64.

The clock_gettime()/clock_settime()/clock_getres()/timer_gettime()/
timer_settime() callbacks in struct posix_clock_operations are not
year 2038 safe on 32bit systems, and it need convert to year 2038
safe callbacks which use struct timespec64 or struct itimerspec64.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 drivers/ptp/ptp_clock.c     |   22 +++++++---------------
 include/linux/posix-clock.h |   10 +++++-----
 kernel/time/posix-clock.c   |   20 ++++++++++----------
 3 files changed, 22 insertions(+), 30 deletions(-)

diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c
index 2e481b9..7040f20 100644
--- a/drivers/ptp/ptp_clock.c
+++ b/drivers/ptp/ptp_clock.c
@@ -97,31 +97,25 @@ static s32 scaled_ppm_to_ppb(long ppm)
 
 /* posix clock implementation */
 
-static int ptp_clock_getres(struct posix_clock *pc, struct timespec *tp)
+static int ptp_clock_getres(struct posix_clock *pc, struct timespec64 *tp)
 {
 	tp->tv_sec = 0;
 	tp->tv_nsec = 1;
 	return 0;
 }
 
-static int ptp_clock_settime(struct posix_clock *pc, const struct timespec *tp)
+static int ptp_clock_settime(struct posix_clock *pc, const struct timespec64 *tp)
 {
 	struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock);
-	struct timespec64 ts = timespec_to_timespec64(*tp);
 
-	return  ptp->info->settime64(ptp->info, &ts);
+	return  ptp->info->settime64(ptp->info, tp);
 }
 
-static int ptp_clock_gettime(struct posix_clock *pc, struct timespec *tp)
+static int ptp_clock_gettime(struct posix_clock *pc, struct timespec64 *tp)
 {
 	struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock);
-	struct timespec64 ts;
-	int err;
 
-	err = ptp->info->gettime64(ptp->info, &ts);
-	if (!err)
-		*tp = timespec64_to_timespec(ts);
-	return err;
+	return ptp->info->gettime64(ptp->info, tp);
 }
 
 static int ptp_clock_adjtime(struct posix_clock *pc, struct timex *tx)
@@ -133,8 +127,7 @@ static int ptp_clock_adjtime(struct posix_clock *pc, struct timex *tx)
 	ops = ptp->info;
 
 	if (tx->modes & ADJ_SETOFFSET) {
-		struct timespec ts;
-		ktime_t kt;
+		struct timespec64 ts;
 		s64 delta;
 
 		ts.tv_sec  = tx->time.tv_sec;
@@ -146,8 +139,7 @@ static int ptp_clock_adjtime(struct posix_clock *pc, struct timex *tx)
 		if ((unsigned long) ts.tv_nsec >= NSEC_PER_SEC)
 			return -EINVAL;
 
-		kt = timespec_to_ktime(ts);
-		delta = ktime_to_ns(kt);
+		delta = timespec64_to_ns(&ts);
 		err = ops->adjtime(ops, delta);
 	} else if (tx->modes & ADJ_FREQUENCY) {
 		s32 ppb = scaled_ppm_to_ppb(tx->freq);
diff --git a/include/linux/posix-clock.h b/include/linux/posix-clock.h
index 34c4498..83b22ae 100644
--- a/include/linux/posix-clock.h
+++ b/include/linux/posix-clock.h
@@ -59,23 +59,23 @@ struct posix_clock_operations {
 
 	int  (*clock_adjtime)(struct posix_clock *pc, struct timex *tx);
 
-	int  (*clock_gettime)(struct posix_clock *pc, struct timespec *ts);
+	int  (*clock_gettime)(struct posix_clock *pc, struct timespec64 *ts);
 
-	int  (*clock_getres) (struct posix_clock *pc, struct timespec *ts);
+	int  (*clock_getres) (struct posix_clock *pc, struct timespec64 *ts);
 
 	int  (*clock_settime)(struct posix_clock *pc,
-			      const struct timespec *ts);
+			      const struct timespec64 *ts);
 
 	int  (*timer_create) (struct posix_clock *pc, struct k_itimer *kit);
 
 	int  (*timer_delete) (struct posix_clock *pc, struct k_itimer *kit);
 
 	void (*timer_gettime)(struct posix_clock *pc,
-			      struct k_itimer *kit, struct itimerspec *tsp);
+			      struct k_itimer *kit, struct itimerspec64 *tsp);
 
 	int  (*timer_settime)(struct posix_clock *pc,
 			      struct k_itimer *kit, int flags,
-			      struct itimerspec *tsp, struct itimerspec *old);
+			      struct itimerspec64 *tsp, struct itimerspec64 *old);
 	/*
 	 * Optional character device methods:
 	 */
diff --git a/kernel/time/posix-clock.c b/kernel/time/posix-clock.c
index ce033c7..e21e4c1 100644
--- a/kernel/time/posix-clock.c
+++ b/kernel/time/posix-clock.c
@@ -297,7 +297,7 @@ out:
 	return err;
 }
 
-static int pc_clock_gettime(clockid_t id, struct timespec *ts)
+static int pc_clock_gettime(clockid_t id, struct timespec64 *ts)
 {
 	struct posix_clock_desc cd;
 	int err;
@@ -316,7 +316,7 @@ static int pc_clock_gettime(clockid_t id, struct timespec *ts)
 	return err;
 }
 
-static int pc_clock_getres(clockid_t id, struct timespec *ts)
+static int pc_clock_getres(clockid_t id, struct timespec64 *ts)
 {
 	struct posix_clock_desc cd;
 	int err;
@@ -335,7 +335,7 @@ static int pc_clock_getres(clockid_t id, struct timespec *ts)
 	return err;
 }
 
-static int pc_clock_settime(clockid_t id, const struct timespec *ts)
+static int pc_clock_settime(clockid_t id, const struct timespec64 *ts)
 {
 	struct posix_clock_desc cd;
 	int err;
@@ -399,7 +399,7 @@ static int pc_timer_delete(struct k_itimer *kit)
 	return err;
 }
 
-static void pc_timer_gettime(struct k_itimer *kit, struct itimerspec *ts)
+static void pc_timer_gettime(struct k_itimer *kit, struct itimerspec64 *ts)
 {
 	clockid_t id = kit->it_clock;
 	struct posix_clock_desc cd;
@@ -414,7 +414,7 @@ static void pc_timer_gettime(struct k_itimer *kit, struct itimerspec *ts)
 }
 
 static int pc_timer_settime(struct k_itimer *kit, int flags,
-			    struct itimerspec *ts, struct itimerspec *old)
+			    struct itimerspec64 *ts, struct itimerspec64 *old)
 {
 	clockid_t id = kit->it_clock;
 	struct posix_clock_desc cd;
@@ -435,12 +435,12 @@ static int pc_timer_settime(struct k_itimer *kit, int flags,
 }
 
 struct k_clock clock_posix_dynamic = {
-	.clock_getres	= pc_clock_getres,
-	.clock_set	= pc_clock_settime,
-	.clock_get	= pc_clock_gettime,
+	.clock_getres64	= pc_clock_getres,
+	.clock_set64	= pc_clock_settime,
+	.clock_get64	= pc_clock_gettime,
 	.clock_adj	= pc_clock_adjtime,
 	.timer_create	= pc_timer_create,
-	.timer_set	= pc_timer_settime,
+	.timer_set64	= pc_timer_settime,
 	.timer_del	= pc_timer_delete,
-	.timer_get	= pc_timer_gettime,
+	.timer_get64	= pc_timer_gettime,
 };
-- 
1.7.9.5


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

* [PATCH v5 21/24] time: Introduce timespec64_to_jiffies()/jiffies_to_timespec64()
  2015-06-12  7:19 ` [PATCH v5 00/24] Convert the posix_clock_operations and k_clock structure to ready for 2038 Baolin Wang
                     ` (19 preceding siblings ...)
  2015-06-12  8:03   ` [PATCH v5 20/24] posix-clock: " Baolin Wang
@ 2015-06-12  8:06   ` Baolin Wang
  2015-06-12  8:10   ` [PATCH v5 22/24] cputime: Introduce cputime_to_timespec64()/timespec64_to_cputime() Baolin Wang
                     ` (3 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Baolin Wang @ 2015-06-12  8:06 UTC (permalink / raw)
  To: tglx; +Cc: arnd, john.stultz, hofrat, ahh, linux-kernel, baolin.wang, y2038

The conversion between struct timespec and jiffies is not year 2038
safe on 32bit systems. Introduce timespec64_to_jiffies() and
jiffies_to_timespec64() functions which use struct timespec64 to
make it ready for 2038 issue.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 include/linux/jiffies.h |   21 ++++++++++++++++++---
 kernel/time/time.c      |   11 ++++++-----
 2 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
index 3bde5eb..be37eae 100644
--- a/include/linux/jiffies.h
+++ b/include/linux/jiffies.h
@@ -363,9 +363,24 @@ static inline unsigned long msecs_to_jiffies(const unsigned int m)
 }
 
 extern unsigned long usecs_to_jiffies(const unsigned int u);
-extern unsigned long timespec_to_jiffies(const struct timespec *value);
-extern void jiffies_to_timespec(const unsigned long jiffies,
-				struct timespec *value);
+extern unsigned long __timespec_to_jiffies(unsigned long sec, long nsec);
+extern unsigned long timespec64_to_jiffies(const struct timespec64 *value);
+extern void jiffies_to_timespec64(const unsigned long jiffies,
+				  struct timespec64 *value);
+static inline unsigned long timespec_to_jiffies(const struct timespec *value)
+{
+	return __timespec_to_jiffies(value->tv_sec, value->tv_nsec);
+}
+
+static inline void jiffies_to_timespec(const unsigned long jiffies,
+				       struct timespec *value)
+{
+	struct timespec64 ts;
+
+	jiffies_to_timespec64(jiffies, &ts);
+	*value = timespec64_to_timespec(ts);
+}
+
 extern unsigned long timeval_to_jiffies(const struct timeval *value);
 extern void jiffies_to_timeval(const unsigned long jiffies,
 			       struct timeval *value);
diff --git a/kernel/time/time.c b/kernel/time/time.c
index 5aefe2d..8318cab 100644
--- a/kernel/time/time.c
+++ b/kernel/time/time.c
@@ -552,7 +552,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
  * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
  * value to a scaled second value.
  */
-static unsigned long
+unsigned long
 __timespec_to_jiffies(unsigned long sec, long nsec)
 {
 	nsec = nsec + TICK_NSEC - 1;
@@ -566,17 +566,18 @@ __timespec_to_jiffies(unsigned long sec, long nsec)
 		 (NSEC_JIFFIE_SC - SEC_JIFFIE_SC))) >> SEC_JIFFIE_SC;
 
 }
+EXPORT_SYMBOL(__timespec_to_jiffies);
 
 unsigned long
-timespec_to_jiffies(const struct timespec *value)
+timespec64_to_jiffies(const struct timespec64 *value)
 {
 	return __timespec_to_jiffies(value->tv_sec, value->tv_nsec);
 }
 
-EXPORT_SYMBOL(timespec_to_jiffies);
+EXPORT_SYMBOL(timespec64_to_jiffies);
 
 void
-jiffies_to_timespec(const unsigned long jiffies, struct timespec *value)
+jiffies_to_timespec64(const unsigned long jiffies, struct timespec64 *value)
 {
 	/*
 	 * Convert jiffies to nanoseconds and separate with
@@ -587,7 +588,7 @@ jiffies_to_timespec(const unsigned long jiffies, struct timespec *value)
 				    NSEC_PER_SEC, &rem);
 	value->tv_nsec = rem;
 }
-EXPORT_SYMBOL(jiffies_to_timespec);
+EXPORT_SYMBOL(jiffies_to_timespec64);
 
 /*
  * We could use a similar algorithm to timespec_to_jiffies (with a
-- 
1.7.9.5


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

* [PATCH v5 22/24] cputime: Introduce cputime_to_timespec64()/timespec64_to_cputime()
  2015-06-12  7:19 ` [PATCH v5 00/24] Convert the posix_clock_operations and k_clock structure to ready for 2038 Baolin Wang
                     ` (20 preceding siblings ...)
  2015-06-12  8:06   ` [PATCH v5 21/24] time: Introduce timespec64_to_jiffies()/jiffies_to_timespec64() Baolin Wang
@ 2015-06-12  8:10   ` Baolin Wang
  2015-06-12  8:12   ` [PATCH v5 23/24] posix-cpu-timers: Convert to y2038 safe callbacks Baolin Wang
                     ` (2 subsequent siblings)
  24 siblings, 0 replies; 27+ messages in thread
From: Baolin Wang @ 2015-06-12  8:10 UTC (permalink / raw)
  To: benh
  Cc: arnd, peterz, paulus, mpe, schwidefsky, heiko.carstens, linux390,
	rth, riel, cl, tj, fweisbec, linuxppc-dev, linux-s390,
	linux-arch, linux-kernel, baolin.wang, y2038

The cputime_to_timespec() and timespec_to_cputime() functions are
not year 2038 safe on 32bit systems due to the struct timepsec will
overflow in 2038 year. Introduce cputime_to_timespec64() and
timespec64_to_cputime() functions which use struct timespec64,
as well as for arch/s390 and arch/powerpc architecture.

The cputime_to_timespec() and timespec_to_cputime() functions are
moved to include/linux/cputime.h file as 'static inline' for removing
conveniently in future.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 arch/powerpc/include/asm/cputime.h    |    6 +++---
 arch/s390/include/asm/cputime.h       |    8 ++++----
 include/asm-generic/cputime_jiffies.h |   10 +++++-----
 include/asm-generic/cputime_nsecs.h   |    6 +++---
 include/linux/cputime.h               |   16 ++++++++++++++++
 5 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/arch/powerpc/include/asm/cputime.h b/arch/powerpc/include/asm/cputime.h
index e245255..5dda5c0 100644
--- a/arch/powerpc/include/asm/cputime.h
+++ b/arch/powerpc/include/asm/cputime.h
@@ -154,9 +154,9 @@ static inline cputime_t secs_to_cputime(const unsigned long sec)
 }
 
 /*
- * Convert cputime <-> timespec
+ * Convert cputime <-> timespec64
  */
-static inline void cputime_to_timespec(const cputime_t ct, struct timespec *p)
+static inline void cputime_to_timespec64(const cputime_t ct, struct timespec64 *p)
 {
 	u64 x = (__force u64) ct;
 	unsigned int frac;
@@ -168,7 +168,7 @@ static inline void cputime_to_timespec(const cputime_t ct, struct timespec *p)
 	p->tv_nsec = x;
 }
 
-static inline cputime_t timespec_to_cputime(const struct timespec *p)
+static inline cputime_t timespec64_to_cputime(const struct timespec64 *p)
 {
 	u64 ct;
 
diff --git a/arch/s390/include/asm/cputime.h b/arch/s390/include/asm/cputime.h
index 221b454..3319b51 100644
--- a/arch/s390/include/asm/cputime.h
+++ b/arch/s390/include/asm/cputime.h
@@ -81,16 +81,16 @@ static inline cputime_t secs_to_cputime(const unsigned int s)
 }
 
 /*
- * Convert cputime to timespec and back.
+ * Convert cputime to timespec64 and back.
  */
-static inline cputime_t timespec_to_cputime(const struct timespec *value)
+static inline cputime_t timespec64_to_cputime(const struct timespec64 *value)
 {
 	unsigned long long ret = value->tv_sec * CPUTIME_PER_SEC;
 	return (__force cputime_t)(ret + __div(value->tv_nsec * CPUTIME_PER_USEC, NSEC_PER_USEC));
 }
 
-static inline void cputime_to_timespec(const cputime_t cputime,
-				       struct timespec *value)
+static inline void cputime_to_timespec64(const cputime_t cputime,
+					 struct timespec64 *value)
 {
 	unsigned long long __cputime = (__force unsigned long long) cputime;
 	value->tv_nsec = (__cputime % CPUTIME_PER_SEC) * NSEC_PER_USEC / CPUTIME_PER_USEC;
diff --git a/include/asm-generic/cputime_jiffies.h b/include/asm-generic/cputime_jiffies.h
index fe386fc..54e034c 100644
--- a/include/asm-generic/cputime_jiffies.h
+++ b/include/asm-generic/cputime_jiffies.h
@@ -44,12 +44,12 @@ typedef u64 __nocast cputime64_t;
 #define secs_to_cputime(sec)		jiffies_to_cputime((sec) * HZ)
 
 /*
- * Convert cputime to timespec and back.
+ * Convert cputime to timespec64 and back.
  */
-#define timespec_to_cputime(__val)	\
-	jiffies_to_cputime(timespec_to_jiffies(__val))
-#define cputime_to_timespec(__ct,__val)	\
-	jiffies_to_timespec(cputime_to_jiffies(__ct),__val)
+#define timespec64_to_cputime(__val)	\
+	jiffies_to_cputime(timespec64_to_jiffies(__val))
+#define cputime_to_timespec64(__ct,__val)	\
+	jiffies_to_timespec64(cputime_to_jiffies(__ct),__val)
 
 /*
  * Convert cputime to timeval and back.
diff --git a/include/asm-generic/cputime_nsecs.h b/include/asm-generic/cputime_nsecs.h
index 0419485..c0cafc0 100644
--- a/include/asm-generic/cputime_nsecs.h
+++ b/include/asm-generic/cputime_nsecs.h
@@ -71,14 +71,14 @@ typedef u64 __nocast cputime64_t;
 	(__force cputime_t)((__secs) * NSEC_PER_SEC)
 
 /*
- * Convert cputime <-> timespec (nsec)
+ * Convert cputime <-> timespec64 (nsec)
  */
-static inline cputime_t timespec_to_cputime(const struct timespec *val)
+static inline cputime_t timespec64_to_cputime(const struct timespec64 *val)
 {
 	u64 ret = val->tv_sec * NSEC_PER_SEC + val->tv_nsec;
 	return (__force cputime_t) ret;
 }
-static inline void cputime_to_timespec(const cputime_t ct, struct timespec *val)
+static inline void cputime_to_timespec64(const cputime_t ct, struct timespec64 *val)
 {
 	u32 rem;
 
diff --git a/include/linux/cputime.h b/include/linux/cputime.h
index f2eb2ee..cd638a0 100644
--- a/include/linux/cputime.h
+++ b/include/linux/cputime.h
@@ -13,4 +13,20 @@
 	usecs_to_cputime((__nsecs) / NSEC_PER_USEC)
 #endif
 
+static inline cputime_t timespec_to_cputime(const struct timespec *ts)
+{
+	struct timespec64 ts64 = timespec_to_timespec64(*ts);
+
+	return timespec64_to_cputime(&ts64);
+}
+
+static inline void cputime_to_timespec(const cputime_t cputime,
+				       struct timespec *value)
+{
+	struct timespec64 ts64;
+
+	cputime_to_timespec64(cputime, &ts64);
+	*value = timespec64_to_timespec(ts64);
+}
+
 #endif /* __LINUX_CPUTIME_H */
-- 
1.7.9.5


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

* [PATCH v5 23/24] posix-cpu-timers: Convert to y2038 safe callbacks
  2015-06-12  7:19 ` [PATCH v5 00/24] Convert the posix_clock_operations and k_clock structure to ready for 2038 Baolin Wang
                     ` (21 preceding siblings ...)
  2015-06-12  8:10   ` [PATCH v5 22/24] cputime: Introduce cputime_to_timespec64()/timespec64_to_cputime() Baolin Wang
@ 2015-06-12  8:12   ` Baolin Wang
  2015-06-12  8:12   ` [PATCH v5 24/24] k_clock: Remove y2038 unsafe callbacks Baolin Wang
  2015-06-12 13:16   ` [PATCH v5 00/24] Convert the posix_clock_operations and k_clock structure to ready for 2038 Thomas Gleixner
  24 siblings, 0 replies; 27+ messages in thread
From: Baolin Wang @ 2015-06-12  8:12 UTC (permalink / raw)
  To: tglx; +Cc: arnd, linux-kernel, baolin.wang, y2038

The clock_getres()/clock_get()/clock_set()/timer_set()/timer_get()
callbacks in struct k_clock are not year 2038 safe on 32bit systems,
and it need convert to safe callbacks which use struct timespec64
or struct itimerspec64.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 kernel/time/posix-cpu-timers.c |   84 +++++++++++++++++++++-------------------
 1 file changed, 45 insertions(+), 39 deletions(-)

diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
index 892e3da..1d4605c 100644
--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -52,7 +52,7 @@ static int check_clock(const clockid_t which_clock)
 }
 
 static inline unsigned long long
-timespec_to_sample(const clockid_t which_clock, const struct timespec *tp)
+timespec64_to_sample(const clockid_t which_clock, const struct timespec64 *tp)
 {
 	unsigned long long ret;
 
@@ -60,19 +60,19 @@ timespec_to_sample(const clockid_t which_clock, const struct timespec *tp)
 	if (CPUCLOCK_WHICH(which_clock) == CPUCLOCK_SCHED) {
 		ret = (unsigned long long)tp->tv_sec * NSEC_PER_SEC + tp->tv_nsec;
 	} else {
-		ret = cputime_to_expires(timespec_to_cputime(tp));
+		ret = cputime_to_expires(timespec64_to_cputime(tp));
 	}
 	return ret;
 }
 
-static void sample_to_timespec(const clockid_t which_clock,
+static void sample_to_timespec64(const clockid_t which_clock,
 			       unsigned long long expires,
-			       struct timespec *tp)
+			       struct timespec64 *tp)
 {
 	if (CPUCLOCK_WHICH(which_clock) == CPUCLOCK_SCHED)
-		*tp = ns_to_timespec(expires);
+		*tp = ns_to_timespec64(expires);
 	else
-		cputime_to_timespec((__force cputime_t)expires, tp);
+		cputime_to_timespec64((__force cputime_t)expires, tp);
 }
 
 /*
@@ -141,7 +141,7 @@ static inline unsigned long long virt_ticks(struct task_struct *p)
 }
 
 static int
-posix_cpu_clock_getres(const clockid_t which_clock, struct timespec *tp)
+posix_cpu_clock_getres(const clockid_t which_clock, struct timespec64 *tp)
 {
 	int error = check_clock(which_clock);
 	if (!error) {
@@ -160,7 +160,7 @@ posix_cpu_clock_getres(const clockid_t which_clock, struct timespec *tp)
 }
 
 static int
-posix_cpu_clock_set(const clockid_t which_clock, const struct timespec *tp)
+posix_cpu_clock_set(const clockid_t which_clock, const struct timespec64 *tp)
 {
 	/*
 	 * You can never reset a CPU clock, but we check for other errors
@@ -286,7 +286,7 @@ static int cpu_clock_sample_group(const clockid_t which_clock,
 
 static int posix_cpu_clock_get_task(struct task_struct *tsk,
 				    const clockid_t which_clock,
-				    struct timespec *tp)
+				    struct timespec64 *tp)
 {
 	int err = -EINVAL;
 	unsigned long long rtn;
@@ -300,13 +300,14 @@ static int posix_cpu_clock_get_task(struct task_struct *tsk,
 	}
 
 	if (!err)
-		sample_to_timespec(which_clock, rtn, tp);
+		sample_to_timespec64(which_clock, rtn, tp);
 
 	return err;
 }
 
 
-static int posix_cpu_clock_get(const clockid_t which_clock, struct timespec *tp)
+static int posix_cpu_clock_get(const clockid_t which_clock,
+				struct timespec64 *tp)
 {
 	const pid_t pid = CPUCLOCK_PID(which_clock);
 	int err = -EINVAL;
@@ -622,7 +623,7 @@ static inline void posix_cpu_timer_kick_nohz(void) { }
  * and try again.  (This happens when the timer is in the middle of firing.)
  */
 static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags,
-			       struct itimerspec *new, struct itimerspec *old)
+			       struct itimerspec64 *new, struct itimerspec64 *old)
 {
 	unsigned long flags;
 	struct sighand_struct *sighand;
@@ -632,7 +633,7 @@ static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags,
 
 	WARN_ON_ONCE(p == NULL);
 
-	new_expires = timespec_to_sample(timer->it_clock, &new->it_value);
+	new_expires = timespec64_to_sample(timer->it_clock, &new->it_value);
 
 	/*
 	 * Protect against sighand release/switch in exit/exec and p->cpu_timers
@@ -693,7 +694,7 @@ static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags,
 			bump_cpu_timer(timer, val);
 			if (val < timer->it.cpu.expires) {
 				old_expires = timer->it.cpu.expires - val;
-				sample_to_timespec(timer->it_clock,
+				sample_to_timespec64(timer->it_clock,
 						   old_expires,
 						   &old->it_value);
 			} else {
@@ -733,7 +734,7 @@ static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags,
 	 * Install the new reload setting, and
 	 * set up the signal and overrun bookkeeping.
 	 */
-	timer->it.cpu.incr = timespec_to_sample(timer->it_clock,
+	timer->it.cpu.incr = timespec64_to_sample(timer->it_clock,
 						&new->it_interval);
 
 	/*
@@ -758,7 +759,7 @@ static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags,
 	ret = 0;
  out:
 	if (old) {
-		sample_to_timespec(timer->it_clock,
+		sample_to_timespec64(timer->it_clock,
 				   old_incr, &old->it_interval);
 	}
 	if (!ret)
@@ -766,7 +767,7 @@ static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags,
 	return ret;
 }
 
-static void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec *itp)
+static void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec64 *itp)
 {
 	unsigned long long now;
 	struct task_struct *p = timer->it.cpu.task;
@@ -776,7 +777,7 @@ static void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec *itp)
 	/*
 	 * Easy part: convert the reload time.
 	 */
-	sample_to_timespec(timer->it_clock,
+	sample_to_timespec64(timer->it_clock,
 			   timer->it.cpu.incr, &itp->it_interval);
 
 	if (timer->it.cpu.expires == 0) {	/* Timer not armed at all.  */
@@ -806,7 +807,7 @@ static void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec *itp)
 			 * Call the timer disarmed, nothing else to do.
 			 */
 			timer->it.cpu.expires = 0;
-			sample_to_timespec(timer->it_clock, timer->it.cpu.expires,
+			sample_to_timespec64(timer->it_clock, timer->it.cpu.expires,
 					   &itp->it_value);
 		} else {
 			cpu_timer_sample_group(timer->it_clock, p, &now);
@@ -815,7 +816,7 @@ static void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec *itp)
 	}
 
 	if (now < timer->it.cpu.expires) {
-		sample_to_timespec(timer->it_clock,
+		sample_to_timespec64(timer->it_clock,
 				   timer->it.cpu.expires - now,
 				   &itp->it_value);
 	} else {
@@ -1269,6 +1270,8 @@ static int do_cpu_nanosleep(const clockid_t which_clock, int flags,
 			    struct timespec *rqtp, struct itimerspec *it)
 {
 	struct k_itimer timer;
+	struct timespec64 ts64;
+	struct itimerspec64 it64;
 	int error;
 
 	/*
@@ -1281,13 +1284,14 @@ static int do_cpu_nanosleep(const clockid_t which_clock, int flags,
 	error = posix_cpu_timer_create(&timer);
 	timer.it_process = current;
 	if (!error) {
-		static struct itimerspec zero_it;
+		static struct itimerspec64 zero_it;
 
 		memset(it, 0, sizeof *it);
 		it->it_value = *rqtp;
 
 		spin_lock_irq(&timer.it_lock);
-		error = posix_cpu_timer_set(&timer, flags, it, NULL);
+		it64 = itimerspec_to_itimerspec64(it);
+		error = posix_cpu_timer_set(&timer, flags, &it64, NULL);
 		if (error) {
 			spin_unlock_irq(&timer.it_lock);
 			return error;
@@ -1316,13 +1320,15 @@ static int do_cpu_nanosleep(const clockid_t which_clock, int flags,
 		/*
 		 * We were interrupted by a signal.
 		 */
-		sample_to_timespec(which_clock, timer.it.cpu.expires, rqtp);
-		error = posix_cpu_timer_set(&timer, 0, &zero_it, it);
+		sample_to_timespec64(which_clock, timer.it.cpu.expires, &ts64);
+		*rqtp = timespec64_to_timespec(ts64);
+		error = posix_cpu_timer_set(&timer, 0, &zero_it, &it64);
 		if (!error) {
 			/*
 			 * Timer is now unarmed, deletion can not fail.
 			 */
 			posix_cpu_timer_del(&timer);
+			*it = itimerspec64_to_itimerspec(&it64);
 		}
 		spin_unlock_irq(&timer.it_lock);
 
@@ -1416,12 +1422,12 @@ static long posix_cpu_nsleep_restart(struct restart_block *restart_block)
 #define THREAD_CLOCK	MAKE_THREAD_CPUCLOCK(0, CPUCLOCK_SCHED)
 
 static int process_cpu_clock_getres(const clockid_t which_clock,
-				    struct timespec *tp)
+				    struct timespec64 *tp)
 {
 	return posix_cpu_clock_getres(PROCESS_CLOCK, tp);
 }
 static int process_cpu_clock_get(const clockid_t which_clock,
-				 struct timespec *tp)
+				 struct timespec64 *tp)
 {
 	return posix_cpu_clock_get(PROCESS_CLOCK, tp);
 }
@@ -1441,12 +1447,12 @@ static long process_cpu_nsleep_restart(struct restart_block *restart_block)
 	return -EINVAL;
 }
 static int thread_cpu_clock_getres(const clockid_t which_clock,
-				   struct timespec *tp)
+				   struct timespec64 *tp)
 {
 	return posix_cpu_clock_getres(THREAD_CLOCK, tp);
 }
 static int thread_cpu_clock_get(const clockid_t which_clock,
-				struct timespec *tp)
+				struct timespec64 *tp)
 {
 	return posix_cpu_clock_get(THREAD_CLOCK, tp);
 }
@@ -1457,37 +1463,37 @@ static int thread_cpu_timer_create(struct k_itimer *timer)
 }
 
 struct k_clock clock_posix_cpu = {
-	.clock_getres	= posix_cpu_clock_getres,
-	.clock_set	= posix_cpu_clock_set,
-	.clock_get	= posix_cpu_clock_get,
+	.clock_getres64	= posix_cpu_clock_getres,
+	.clock_set64	= posix_cpu_clock_set,
+	.clock_get64	= posix_cpu_clock_get,
 	.timer_create	= posix_cpu_timer_create,
 	.nsleep		= posix_cpu_nsleep,
 	.nsleep_restart	= posix_cpu_nsleep_restart,
-	.timer_set	= posix_cpu_timer_set,
+	.timer_set64	= posix_cpu_timer_set,
 	.timer_del	= posix_cpu_timer_del,
-	.timer_get	= posix_cpu_timer_get,
+	.timer_get64	= posix_cpu_timer_get,
 };
 
 static __init int init_posix_cpu_timers(void)
 {
 	struct k_clock process = {
-		.clock_getres	= process_cpu_clock_getres,
-		.clock_get	= process_cpu_clock_get,
+		.clock_getres64	= process_cpu_clock_getres,
+		.clock_get64	= process_cpu_clock_get,
 		.timer_create	= process_cpu_timer_create,
 		.nsleep		= process_cpu_nsleep,
 		.nsleep_restart	= process_cpu_nsleep_restart,
 	};
 	struct k_clock thread = {
-		.clock_getres	= thread_cpu_clock_getres,
-		.clock_get	= thread_cpu_clock_get,
+		.clock_getres64	= thread_cpu_clock_getres,
+		.clock_get64	= thread_cpu_clock_get,
 		.timer_create	= thread_cpu_timer_create,
 	};
-	struct timespec ts;
+	struct timespec64 ts;
 
 	posix_timers_register_clock(CLOCK_PROCESS_CPUTIME_ID, &process);
 	posix_timers_register_clock(CLOCK_THREAD_CPUTIME_ID, &thread);
 
-	cputime_to_timespec(cputime_one_jiffy, &ts);
+	cputime_to_timespec64(cputime_one_jiffy, &ts);
 	onecputick = ts.tv_nsec;
 	WARN_ON(ts.tv_sec != 0);
 
-- 
1.7.9.5


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

* [PATCH v5 24/24] k_clock: Remove y2038 unsafe callbacks
  2015-06-12  7:19 ` [PATCH v5 00/24] Convert the posix_clock_operations and k_clock structure to ready for 2038 Baolin Wang
                     ` (22 preceding siblings ...)
  2015-06-12  8:12   ` [PATCH v5 23/24] posix-cpu-timers: Convert to y2038 safe callbacks Baolin Wang
@ 2015-06-12  8:12   ` Baolin Wang
  2015-06-12 13:16   ` [PATCH v5 00/24] Convert the posix_clock_operations and k_clock structure to ready for 2038 Thomas Gleixner
  24 siblings, 0 replies; 27+ messages in thread
From: Baolin Wang @ 2015-06-12  8:12 UTC (permalink / raw)
  To: tglx; +Cc: arnd, linux-kernel, baolin.wang, y2038

All of the k_clock users have been converted to the y2038 safe methods,
this patch removes the older methods with timepsec/itimerspec type,
as a result the k_clock structure is ready for the year 2038.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 include/linux/posix-timers.h |    9 -----
 kernel/time/posix-timers.c   |   90 +++---------------------------------------
 2 files changed, 5 insertions(+), 94 deletions(-)

diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index 35786c5..7c3dae2 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -97,29 +97,20 @@ struct k_itimer {
 };
 
 struct k_clock {
-	int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
 	int (*clock_getres64) (const clockid_t which_clock, struct timespec64 *tp);
-	int (*clock_set) (const clockid_t which_clock,
-			  const struct timespec *tp);
 	int (*clock_set64) (const clockid_t which_clock,
 			    const struct timespec64 *tp);
-	int (*clock_get) (const clockid_t which_clock, struct timespec * tp);
 	int (*clock_get64) (const clockid_t which_clock, struct timespec64 *tp);
 	int (*clock_adj) (const clockid_t which_clock, struct timex *tx);
 	int (*timer_create) (struct k_itimer *timer);
 	int (*nsleep) (const clockid_t which_clock, int flags,
 		       struct timespec *, struct timespec __user *);
 	long (*nsleep_restart) (struct restart_block *restart_block);
-	int (*timer_set) (struct k_itimer * timr, int flags,
-			  struct itimerspec * new_setting,
-			  struct itimerspec * old_setting);
 	int (*timer_set64) (struct k_itimer *timr, int flags,
 			    struct itimerspec64 *new_setting,
 			    struct itimerspec64 *old_setting);
 	int (*timer_del) (struct k_itimer * timr);
 #define TIMER_RETRY 1
-	void (*timer_get) (struct k_itimer * timr,
-			   struct itimerspec * cur_setting);
 	void (*timer_get64) (struct k_itimer *timr,
 			     struct itimerspec64 *cur_setting);
 };
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 80f630a..e9e6e29 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -140,7 +140,6 @@ static int common_timer_del(struct k_itimer *timer);
 static enum hrtimer_restart posix_timer_fn(struct hrtimer *data);
 
 static struct k_itimer *__lock_timer(timer_t timer_id, unsigned long *flags);
-static struct k_clock *clockid_to_kclock(const clockid_t id);
 
 #define lock_timer(tid, flags)						   \
 ({	struct k_itimer *__timr;					   \
@@ -550,73 +549,6 @@ static struct pid *good_sigevent(sigevent_t * event)
 	return task_pid(rtn);
 }
 
-static void default_timer_get64(struct k_itimer *timr,
-				struct itimerspec64 *cur_setting64)
-{
-	struct itimerspec cur_setting;
-	struct k_clock *kc = clockid_to_kclock(timr->it_clock);
-
-	kc->timer_get(timr, &cur_setting);
-	*cur_setting64 = itimerspec_to_itimerspec64(&cur_setting);
-}
-
-static int default_timer_set64(struct k_itimer *timr, int flags,
-			       struct itimerspec64 *new_setting64,
-			       struct itimerspec64 *old_setting64)
-{
-	struct k_clock *kc = clockid_to_kclock(timr->it_clock);
-	struct itimerspec new_setting, old_setting;
-	struct itimerspec *rtn = old_setting64 ? &old_setting : NULL;
-	int ret;
-
-	new_setting = itimerspec64_to_itimerspec(new_setting64);
-	ret = kc->timer_set(timr, flags, &new_setting, rtn);
-	if (!ret && old_setting64)
-		*old_setting64 = itimerspec_to_itimerspec64(&old_setting);
-
-	return ret;
-}
-
-static int default_clock_set64(const clockid_t which_clock,
-			       const struct timespec64 *tp64)
-{
-	struct k_clock *kc = clockid_to_kclock(which_clock);
-	struct timespec tp;
-	int ret;
-
-	tp = timespec64_to_timespec(*tp64);
-	ret = kc->clock_set(which_clock, &tp);
-	return ret;
-}
-
-static int default_clock_get64(const clockid_t which_clock,
-			       struct timespec64 *tp64)
-{
-	struct k_clock *kc = clockid_to_kclock(which_clock);
-	struct timespec tp;
-	int ret;
-
-	ret = kc->clock_get(which_clock, &tp);
-	if (!ret)
-		*tp64 = timespec_to_timespec64(tp);
-
-	return ret;
-}
-
-static int default_clock_getres64(const clockid_t which_clock,
-				  struct timespec64 *tp64)
-{
-	struct k_clock *kc = clockid_to_kclock(which_clock);
-	struct timespec tp;
-	int ret;
-
-	ret = kc->clock_getres(which_clock, &tp);
-	if (!ret)
-		*tp64 = timespec_to_timespec64(tp);
-
-	return 0;
-}
-
 void posix_timers_register_clock(const clockid_t clock_id,
 				 struct k_clock *new_clock)
 {
@@ -626,28 +558,17 @@ void posix_timers_register_clock(const clockid_t clock_id,
 		return;
 	}
 
-	if (!new_clock->clock_get && !new_clock->clock_get64) {
-		printk(KERN_WARNING "POSIX clock id %d lacks clock_get() and clock_get64()\n",
+	if (!new_clock->clock_get64) {
+		printk(KERN_WARNING "POSIX clock id %d lacks clock_get64()\n",
 		       clock_id);
 		return;
 	}
-	if (!new_clock->clock_getres && !new_clock->clock_getres64) {
-		printk(KERN_WARNING "POSIX clock id %d lacks clock_getres() and clock_getres64()\n",
+	if (!new_clock->clock_getres64) {
+		printk(KERN_WARNING "POSIX clock id %d lacks clock_getres64()\n",
 		       clock_id);
 		return;
 	}
 
-	if (new_clock->timer_get && !new_clock->timer_get64)
-		new_clock->timer_get64 = default_timer_get64;
-	if (new_clock->timer_set && !new_clock->timer_set64)
-		new_clock->timer_set64 = default_timer_set64;
-	if (new_clock->clock_set && !new_clock->clock_set64)
-		new_clock->clock_set64 = default_clock_set64;
-	if (new_clock->clock_get && !new_clock->clock_get64)
-		new_clock->clock_get64 = default_clock_get64;
-	if (new_clock->clock_getres && !new_clock->clock_getres64)
-		new_clock->clock_getres64 = default_clock_getres64;
-
 	posix_clocks[clock_id] = *new_clock;
 }
 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
@@ -694,8 +615,7 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
 		return (id & CLOCKFD_MASK) == CLOCKFD ?
 			&clock_posix_dynamic : &clock_posix_cpu;
 
-	if (id >= MAX_CLOCKS || (!posix_clocks[id].clock_getres
-	    && !posix_clocks[id].clock_getres64))
+	if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres64)
 		return NULL;
 	return &posix_clocks[id];
 }
-- 
1.7.9.5


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

* Re: [PATCH v5 00/24] Convert the posix_clock_operations and k_clock structure to ready for 2038
  2015-06-12  7:19 ` [PATCH v5 00/24] Convert the posix_clock_operations and k_clock structure to ready for 2038 Baolin Wang
                     ` (23 preceding siblings ...)
  2015-06-12  8:12   ` [PATCH v5 24/24] k_clock: Remove y2038 unsafe callbacks Baolin Wang
@ 2015-06-12 13:16   ` Thomas Gleixner
  2015-06-15  2:27     ` Baolin Wang
  24 siblings, 1 reply; 27+ messages in thread
From: Thomas Gleixner @ 2015-06-12 13:16 UTC (permalink / raw)
  To: Baolin Wang
  Cc: arnd, john.stultz, heenasirwani, pang.xunlei, peterz,
	rafael.j.wysocki, gregkh, richardcochran, benh, paulus, mpe,
	schwidefsky, heiko.carstens, linux390, rth, riel, cl, tj,
	fweisbec, ahh, pjt, linuxppc-dev, linux-s390, linux-arch,
	linux-kernel, netdev, serge.hallyn, james.l.morris, serge,
	pmoore, tiwai, jeffv, jlayton, keescook, sds, mark.d.rustad,
	linux-security-module, y2038

On Fri, 12 Jun 2015, Baolin Wang wrote:

Sigh. Again threading of the series failed. Some patches are, the
whole series is not. Can you please get your tools straight?

You neither managed to cc me on the security patch.

> - Modify the subject line and the changelog:

>   timekeeping: Change the implementation of timekeeping_clocktai()

Sigh. How is that better than the previous one? It's more accurate,
but equally useless.

And of course you did not address my request to change the macro mess
in

>   posix-timers: Introduce {get,put}_timespec and {get,put}_itimerspec

according to the discussion with Arnd.

Thanks,

	tglx

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

* Re: [PATCH v5 00/24] Convert the posix_clock_operations and k_clock structure to ready for 2038
  2015-06-12 13:16   ` [PATCH v5 00/24] Convert the posix_clock_operations and k_clock structure to ready for 2038 Thomas Gleixner
@ 2015-06-15  2:27     ` Baolin Wang
  0 siblings, 0 replies; 27+ messages in thread
From: Baolin Wang @ 2015-06-15  2:27 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Arnd Bergmann, John Stultz, Heena Sirwani, Xunlei Pang, peterz,
	rafael.j.wysocki, Greg KH, Richard Cochran, benh, paulus, mpe,
	schwidefsky, heiko.carstens, linux390, rth, riel, cl, tj,
	Frédéric Weisbecker, Andrew Hunter, Paul Turner,
	linuxppc-dev, linux-s390, linux-arch, LKML, netdev, Serge Hallyn,
	James Morris, Serge E. Hallyn, Paul Moore, Takashi Iwai,
	Jeffrey Vander Stoep, Jeffrey Layton, Kees Cook, Stephen Smalley,
	mark.d.rustad, linux-security-module, y2038 Mailman List

On 12 June 2015 at 21:16, Thomas Gleixner <tglx@linutronix.de> wrote:
> On Fri, 12 Jun 2015, Baolin Wang wrote:
>
> Sigh. Again threading of the series failed. Some patches are, the
> whole series is not. Can you please get your tools straight?
>
> You neither managed to cc me on the security patch.
>
>> - Modify the subject line and the changelog:
>
>>   timekeeping: Change the implementation of timekeeping_clocktai()
>
> Sigh. How is that better than the previous one? It's more accurate,
> but equally useless.
>
> And of course you did not address my request to change the macro mess
> in
>
>>   posix-timers: Introduce {get,put}_timespec and {get,put}_itimerspec
>
> according to the discussion with Arnd.
>
> Thanks,
>
>         tglx

Hi Thomas,

Thanks for your comments, and i'll fix these problems you point out.

-- 
Baolin.wang
Best Regards

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

end of thread, other threads:[~2015-06-15  2:28 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <lfywpz1987>
2015-06-12  7:19 ` [PATCH v5 00/24] Convert the posix_clock_operations and k_clock structure to ready for 2038 Baolin Wang
2015-06-12  7:27   ` [PATCH v5 01/24] time: Introduce struct itimerspec64 Baolin Wang
2015-06-12  7:30   ` [PATCH v5 02/24] timekeeping: Introduce current_kernel_time64() Baolin Wang
2015-06-12  7:37   ` [PATCH v5 03/24] security: Introduce security_settime64() Baolin Wang
2015-06-12  7:44   ` [PATCH v5 04/24] time: Introduce do_sys_settimeofday64() Baolin Wang
2015-06-12  7:48   ` [PATCH v5 05/24] posix-timers: Introduce {get,put}_timespec and {get,put}_itimerspec Baolin Wang
2015-06-12  7:48   ` [PATCH v5 06/24] posix-timers: Factor out the guts of 'timer_gettime' for reusing Baolin Wang
2015-06-12  7:48   ` [PATCH v5 07/24] posix-timers: Implement y2038 safe timer_get64() callback Baolin Wang
2015-06-12  7:48   ` [PATCH v5 08/24] posix-timers: Factor out the guts of 'timer_settime' for reusing Baolin Wang
2015-06-12  7:48   ` [PATCH v5 09/24] posix-timers: Implement y2038 safe timer_set64() callback Baolin Wang
2015-06-12  7:48   ` [PATCH v5 10/24] posix-timers: Factor out the guts of 'clock_settime' for reusing Baolin Wang
2015-06-12  7:48   ` [PATCH v5 11/24] posix-timers: Implement y2038 safe clock_set64() callback Baolin Wang
2015-06-12  7:48   ` [PATCH v5 12/24] posix-timers: Factor out the guts of 'clock_gettime' for reusing Baolin Wang
2015-06-12  7:48   ` [PATCH v5 13/24] posix-timers: Implement y2038 safe clock_get64() callback Baolin Wang
2015-06-12  7:48   ` [PATCH v5 14/24] posix-timers: Factor out the guts of 'clcok_getres' for reusing Baolin Wang
2015-06-12  7:48   ` [PATCH v5 15/24] posix-timers: Implement y2038 safe clock_getres64() callback Baolin Wang
2015-06-12  7:53   ` [PATCH v5 16/24] timekeeping: Change the implementation of timekeeping_clocktai() Baolin Wang
2015-06-12  7:56   ` [PATCH v5 17/24] posix-timers: Convert to y2038 safe callbacks Baolin Wang
2015-06-12  7:58   ` [PATCH v5 18/24] mmtimer: " Baolin Wang
2015-06-12  8:00   ` [PATCH v5 19/24] alarmtimer: " Baolin Wang
2015-06-12  8:03   ` [PATCH v5 20/24] posix-clock: " Baolin Wang
2015-06-12  8:06   ` [PATCH v5 21/24] time: Introduce timespec64_to_jiffies()/jiffies_to_timespec64() Baolin Wang
2015-06-12  8:10   ` [PATCH v5 22/24] cputime: Introduce cputime_to_timespec64()/timespec64_to_cputime() Baolin Wang
2015-06-12  8:12   ` [PATCH v5 23/24] posix-cpu-timers: Convert to y2038 safe callbacks Baolin Wang
2015-06-12  8:12   ` [PATCH v5 24/24] k_clock: Remove y2038 unsafe callbacks Baolin Wang
2015-06-12 13:16   ` [PATCH v5 00/24] Convert the posix_clock_operations and k_clock structure to ready for 2038 Thomas Gleixner
2015-06-15  2:27     ` Baolin Wang

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