[Y2038] [RESEND PATCH 7/7] Change k_clock nsleep() to use timespec64

2017-03-18 Thread Deepa Dinamani
struct timespec is not y2038 safe. The plan is to
get rid of all uses of timespec internally in the
kernel. Replace uses of timespec with timespec64.
The syscall interfaces themselves will be changed
in a separate series.

Signed-off-by: Deepa Dinamani 
---
 include/linux/hrtimer.h|  2 +-
 include/linux/posix-timers.h   |  2 +-
 kernel/compat.c|  6 --
 kernel/time/alarmtimer.c   |  4 ++--
 kernel/time/hrtimer.c  | 10 ++
 kernel/time/posix-cpu-timers.c | 36 ++--
 kernel/time/posix-stubs.c  |  6 --
 kernel/time/posix-timers.c | 10 ++
 8 files changed, 42 insertions(+), 34 deletions(-)

diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h
index 249e579..7d019c0 100644
--- a/include/linux/hrtimer.h
+++ b/include/linux/hrtimer.h
@@ -456,7 +456,7 @@ static inline u64 hrtimer_forward_now(struct hrtimer *timer,
 }
 
 /* Precise sleep: */
-extern long hrtimer_nanosleep(struct timespec *rqtp,
+extern long hrtimer_nanosleep(struct timespec64 *rqtp,
  struct timespec __user *rmtp,
  const enum hrtimer_mode mode,
  const clockid_t clockid);
diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index f608941..97a883a 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -94,7 +94,7 @@ struct k_clock {
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 *);
+  struct timespec64 *, struct timespec __user *);
long (*nsleep_restart) (struct restart_block *restart_block);
int (*timer_set) (struct k_itimer * timr, int flags,
  struct itimerspec64 * new_setting,
diff --git a/kernel/compat.c b/kernel/compat.c
index e29a01a..8ec15d1 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -240,18 +240,20 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec 
__user *, rqtp,
   struct compat_timespec __user *, rmtp)
 {
struct timespec tu, rmt;
+   struct timespec64 tu64;
mm_segment_t oldfs;
long ret;
 
if (compat_get_timespec(&tu, rqtp))
return -EFAULT;
 
-   if (!timespec_valid(&tu))
+   tu64 = timespec_to_timespec64(tu);
+   if (!timespec64_valid(&tu64))
return -EINVAL;
 
oldfs = get_fs();
set_fs(KERNEL_DS);
-   ret = hrtimer_nanosleep(&tu,
+   ret = hrtimer_nanosleep(&tu64,
rmtp ? (struct timespec __user *)&rmt : NULL,
HRTIMER_MODE_REL, CLOCK_MONOTONIC);
set_fs(oldfs);
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index 81db6df..cc20417 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -790,7 +790,7 @@ static long __sched alarm_timer_nsleep_restart(struct 
restart_block *restart)
  * Handles clock_nanosleep calls against _ALARM clockids
  */
 static int alarm_timer_nsleep(const clockid_t which_clock, int flags,
-struct timespec *tsreq, struct timespec __user *rmtp)
+struct timespec64 *tsreq, struct timespec __user *rmtp)
 {
enum  alarmtimer_type type = clock2alarm(which_clock);
struct alarm alarm;
@@ -809,7 +809,7 @@ static int alarm_timer_nsleep(const clockid_t which_clock, 
int flags,
 
alarm_init(&alarm, type, alarmtimer_nsleep_wakeup);
 
-   exp = timespec_to_ktime(*tsreq);
+   exp = timespec64_to_ktime(*tsreq);
/* Convert (if necessary) to absolute time */
if (flags != TIMER_ABSTIME) {
ktime_t now = alarm_bases[type].gettime();
diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index ec08f52..f530295 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -1506,7 +1506,7 @@ long __sched hrtimer_nanosleep_restart(struct 
restart_block *restart)
return ret;
 }
 
-long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
+long hrtimer_nanosleep(struct timespec64 *rqtp, struct timespec __user *rmtp,
   const enum hrtimer_mode mode, const clockid_t clockid)
 {
struct restart_block *restart;
@@ -1519,7 +1519,7 @@ long hrtimer_nanosleep(struct timespec *rqtp, struct 
timespec __user *rmtp,
slack = 0;
 
hrtimer_init_on_stack(&t.timer, clockid, mode);
-   hrtimer_set_expires_range_ns(&t.timer, timespec_to_ktime(*rqtp), slack);
+   hrtimer_set_expires_range_ns(&t.timer, timespec64_to_ktime(*rqtp), 
slack);
if (do_nanosleep(&t, mode))
goto out;
 
@@ -1551,14 +1551,16 @@ SYSCALL_DEFINE2(nanosleep, struct timespec __user *, 
rqtp,
struct timespec __user *, rmtp)

[Y2038] [RESEND PATCH 6/7] Change k_clock timer_set() and timer_get() to use timespec64

2017-03-18 Thread Deepa Dinamani
struct timespec is not y2038 safe. The plan is to
get rid of all uses of timespec internally in the
kernel. Replace uses of timespec with timespec64.
The syscall interfaces themselves will be changed
in a separate series.

Signed-off-by: Deepa Dinamani 
---
 drivers/char/mmtimer.c | 20 ++--
 include/linux/posix-timers.h   |  6 +++---
 kernel/time/alarmtimer.c   | 14 +++---
 kernel/time/posix-clock.c  | 21 +++--
 kernel/time/posix-cpu-timers.c | 28 
 kernel/time/posix-timers.c | 33 +++--
 6 files changed, 62 insertions(+), 60 deletions(-)

diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index ba1b892..863a111 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -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,11 @@ static int sgi_timer_set(struct k_itimer *timr, int flags,
return -ENOMEM;
 
if (flags & TIMER_ABSTIME) {
-   struct timespec n;
+   struct timespec64 n;
unsigned long now;
 
-   getnstimeofday(&n);
-   now = timespec_to_ns(&n);
+   getnstimeofday64(&n);
+   now = timespec64_to_ns(&n);
if (when > now)
when -= now;
else
diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index 249429c..f608941 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -97,12 +97,12 @@ struct k_clock {
   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);
+ 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);
+  struct itimerspec64 * cur_setting);
 };
 
 extern struct k_clock clock_posix_cpu;
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index e8a45e2..81db6df 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -598,19 +598,19 @@ static int alarm_timer_create(struct k_itimer *new_timer)
  * 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

[Y2038] [RESEND PATCH 5/7] Change k_clock clock_set() to use timespec64

2017-03-18 Thread Deepa Dinamani
struct timespec is not y2038 safe. The plan is to
get rid of all uses of timespec internally in the
kernel. Replace uses of timespec with timespec64.
The syscall interfaces themselves will be changed
in a separate series.

Signed-off-by: Deepa Dinamani 
---
 drivers/char/mmtimer.c |  2 +-
 include/linux/posix-timers.h   |  2 +-
 kernel/time/posix-clock.c  |  5 ++---
 kernel/time/posix-cpu-timers.c |  2 +-
 kernel/time/posix-timers.c | 11 +--
 5 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index 79d8ada..ba1b892 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -489,7 +489,7 @@ static int sgi_clock_get(clockid_t clockid, struct 
timespec64 *tp)
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;
diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index 2555d1c..249429c 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -89,7 +89,7 @@ struct k_itimer {
 struct k_clock {
int (*clock_getres) (const clockid_t which_clock, struct timespec64 
*tp);
int (*clock_set) (const clockid_t which_clock,
- const struct timespec *tp);
+ const struct timespec64 *tp);
int (*clock_get) (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);
diff --git a/kernel/time/posix-clock.c b/kernel/time/posix-clock.c
index d5a4bec..6378fc6 100644
--- a/kernel/time/posix-clock.c
+++ b/kernel/time/posix-clock.c
@@ -335,10 +335,9 @@ static int pc_clock_getres(clockid_t id, struct timespec64 
*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;
-   struct timespec64 ts64 = timespec_to_timespec64(*ts);
int err;
 
err = get_clock_desc(id, &cd);
@@ -351,7 +350,7 @@ static int pc_clock_settime(clockid_t id, const struct 
timespec *ts)
}
 
if (cd.clk->ops.clock_settime)
-   err = cd.clk->ops.clock_settime(cd.clk, &ts64);
+   err = cd.clk->ops.clock_settime(cd.clk, ts);
else
err = -EOPNOTSUPP;
 out:
diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
index 42ca205..0db0e16 100644
--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -135,7 +135,7 @@ posix_cpu_clock_getres(const clockid_t which_clock, struct 
timespec64 *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
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index a314a63..6c09f87 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -212,12 +212,9 @@ static int posix_clock_realtime_get(clockid_t which_clock, 
struct timespec64 *tp
 
 /* Set clock_realtime */
 static int posix_clock_realtime_set(const clockid_t which_clock,
-   const struct timespec *tp)
+   const struct timespec64 *tp)
 {
-   struct timespec64 tp64;
-
-   tp64 = timespec_to_timespec64(*tp);
-   return do_sys_settimeofday64(&tp64, NULL);
+   return do_sys_settimeofday64(tp, NULL);
 }
 
 static int posix_clock_realtime_adj(const clockid_t which_clock,
@@ -1018,14 +1015,16 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, 
which_clock,
 {
struct k_clock *kc = clockid_to_kclock(which_clock);
struct timespec new_tp;
+   struct timespec64 new_tp64;
 
if (!kc || !kc->clock_set)
return -EINVAL;
 
if (copy_from_user(&new_tp, tp, sizeof (*tp)))
return -EFAULT;
+   new_tp64 = timespec_to_timespec64(new_tp);
 
-   return kc->clock_set(which_clock, &new_tp);
+   return kc->clock_set(which_clock, &new_tp64);
 }
 
 SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [RESEND PATCH 4/7] Change k_clock clock_getres() to use timespec64

2017-03-18 Thread Deepa Dinamani
struct timespec is not y2038 safe. The plan is to
get rid of all uses of timespec internally in the
kernel. Replace uses of timespec with timespec64.
The syscall interfaces themselves will be changed
in a separate series.

Signed-off-by: Deepa Dinamani 
---
 drivers/char/mmtimer.c |  2 +-
 include/linux/posix-timers.h   |  2 +-
 kernel/time/alarmtimer.c   |  2 +-
 kernel/time/posix-clock.c  |  9 +++--
 kernel/time/posix-cpu-timers.c |  6 +++---
 kernel/time/posix-timers.c | 10 ++
 6 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index 40d880b..79d8ada 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -765,7 +765,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;
diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index db54f1b..2555d1c 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -87,7 +87,7 @@ struct k_itimer {
 };
 
 struct k_clock {
-   int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
+   int (*clock_getres) (const clockid_t which_clock, struct timespec64 
*tp);
int (*clock_set) (const clockid_t which_clock,
  const struct timespec *tp);
int (*clock_get) (const clockid_t which_clock, struct timespec64 * tp);
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index 944ca6e..e8a45e2 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -541,7 +541,7 @@ static enum alarmtimer_restart alarm_handle_timer(struct 
alarm *alarm,
  *
  * 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;
diff --git a/kernel/time/posix-clock.c b/kernel/time/posix-clock.c
index 0427c8c..d5a4bec 100644
--- a/kernel/time/posix-clock.c
+++ b/kernel/time/posix-clock.c
@@ -316,20 +316,17 @@ static int pc_clock_gettime(clockid_t id, struct 
timespec64 *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;
-   struct timespec64 ts64;
int err;
 
err = get_clock_desc(id, &cd);
if (err)
return err;
 
-   if (cd.clk->ops.clock_getres) {
-   err = cd.clk->ops.clock_getres(cd.clk, &ts64);
-   *ts = timespec64_to_timespec(ts64);
-   }
+   if (cd.clk->ops.clock_getres)
+   err = cd.clk->ops.clock_getres(cd.clk, ts);
else
err = -EOPNOTSUPP;
 
diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
index 6c509ea..42ca205 100644
--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -116,7 +116,7 @@ static inline u64 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) {
@@ -1364,7 +1364,7 @@ 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);
 }
@@ -1389,7 +1389,7 @@ 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);
 }
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index ba0c472..a314a63 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -258,9 +258,9 @@ static int posix_get_monotonic_coarse(clockid_t which_clock,
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;
 }
 
@@ -276,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct 
timespec64 

[Y2038] [RESEND PATCH 0/7] Change k_clock interfaces to use timespec64

2017-03-18 Thread Deepa Dinamani
Resending to update author id in patch 7/7.

The series is aimed at replacing struct timespec which is not
y2038 safe with y2038 safe struct timespec64 for k_clock interfaces.

The series does not change the syscall interface.
This will be done in a follow up series.

A few existing checkpatch-noted style issues, such as the 80 line
character limit, have been left as-is to facilitate easier review.

Deepa Dinamani (7):
  time: Delete do_sys_setimeofday()
  time: Change posix clocks ops interfaces to use timespec64
  Change k_clock clock_get() to use timespec64
  Change k_clock clock_getres() to use timespec64
  Change k_clock clock_set() to use timespec64
  Change k_clock timer_set() and timer_get() to use timespec64
  Change k_clock nsleep() to use timespec64

 drivers/char/mmtimer.c | 28 ++---
 drivers/ptp/ptp_clock.c| 18 
 include/linux/hrtimer.h|  2 +-
 include/linux/posix-clock.h| 10 ++---
 include/linux/posix-timers.h   | 14 +++
 include/linux/timekeeping.h| 20 +++--
 kernel/compat.c| 10 +++--
 kernel/time/alarmtimer.c   | 24 +--
 kernel/time/hrtimer.c  | 10 +++--
 kernel/time/posix-clock.c  | 10 ++---
 kernel/time/posix-cpu-timers.c | 66 --
 kernel/time/posix-stubs.c  | 20 ++---
 kernel/time/posix-timers.c | 93 --
 kernel/time/time.c |  4 +-
 14 files changed, 172 insertions(+), 157 deletions(-)

-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [RESEND PATCH 2/7] time: Change posix clocks ops interfaces to use timespec64

2017-03-18 Thread Deepa Dinamani
 struct timespec is not y2038 safe.
 Replace the posix_clock ops interfaces to use
 struct timespec64.
 The patch also changes struct itimerspec interfaces to
 struct itimerspec64 as itimerspec internally uses timespec
 and itimerspec64 uses timespec64.
 PTP clocks is the only module that sets up these interfaces.
 All individual drivers rely on PTP class driver for exposure
 to userspace. Hence, the change also deals with fixing up these
 PTP interfaces.
 The patch also changes dynamic posix clock implementation to
 reflect the changes in the functional clock interface.

Signed-off-by: Deepa Dinamani 
---
 drivers/ptp/ptp_clock.c | 18 +++---
 include/linux/posix-clock.h | 10 +-
 kernel/time/posix-clock.c   | 34 --
 3 files changed, 36 insertions(+), 26 deletions(-)

diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c
index e814280..b774357 100644
--- a/drivers/ptp/ptp_clock.c
+++ b/drivers/ptp/ptp_clock.c
@@ -97,30 +97,26 @@ 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);
+   err = ptp->info->gettime64(ptp->info, tp);
return err;
 }
 
@@ -133,7 +129,7 @@ static int ptp_clock_adjtime(struct posix_clock *pc, struct 
timex *tx)
ops = ptp->info;
 
if (tx->modes & ADJ_SETOFFSET) {
-   struct timespec ts;
+   struct timespec64 ts;
ktime_t kt;
s64 delta;
 
@@ -146,7 +142,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);
+   kt = timespec64_to_ktime(ts);
delta = ktime_to_ns(kt);
err = ops->adjtime(ops, delta);
} else if (tx->modes & ADJ_FREQUENCY) {
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 9cff0ab..f2af1b5 100644
--- a/kernel/time/posix-clock.c
+++ b/kernel/time/posix-clock.c
@@ -300,14 +300,17 @@ static int pc_clock_adjtime(clockid_t id, struct timex 
*tx)
 static int pc_clock_gettime(clockid_t id, struct timespec *ts)
 {
struct posix_clock_desc cd;
+   struct timespec64 ts64;
int err;
 
err = get_clock_desc(id, &cd);
if (err)
return err;
 
-   if (cd.clk->ops.clock_gettime)
-   err = cd.clk->ops.clock_gettime(cd.clk, 

[Y2038] [RESEND PATCH 3/7] Change k_clock clock_get() to use timespec64

2017-03-18 Thread Deepa Dinamani
struct timespec is not y2038 safe. The plan is to
get rid of all uses of timespec internally in the
kernel. Replace uses of timespec with timespec64.
The syscall interfaces themselves will be changed
in a separate series.

Signed-off-by: Deepa Dinamani 
---
 drivers/char/mmtimer.c |  4 ++--
 include/linux/posix-timers.h   |  2 +-
 include/linux/timekeeping.h|  5 +
 kernel/time/alarmtimer.c   |  4 ++--
 kernel/time/posix-clock.c  |  9 +++--
 kernel/time/posix-cpu-timers.c | 10 +-
 kernel/time/posix-stubs.c  |  9 ++---
 kernel/time/posix-timers.c | 32 +---
 8 files changed, 41 insertions(+), 34 deletions(-)

diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index b708c85..40d880b 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -478,13 +478,13 @@ 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;
 };
diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index 64aa189..db54f1b 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -90,7 +90,7 @@ 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_get) (const clockid_t which_clock, struct timespec * tp);
+   int (*clock_get) (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/include/linux/timekeeping.h b/include/linux/timekeeping.h
index 3617a78..ddc229f 100644
--- a/include/linux/timekeeping.h
+++ b/include/linux/timekeeping.h
@@ -258,6 +258,11 @@ static inline void timekeeping_clocktai(struct timespec 
*ts)
*ts = ktime_to_timespec(ktime_get_clocktai());
 }
 
+static inline void timekeeping_clocktai64(struct timespec64 *ts)
+{
+   *ts = ktime_to_timespec64(ktime_get_clocktai());
+}
+
 /*
  * RTC specific
  */
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index ce3a31e..944ca6e 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -558,14 +558,14 @@ static int alarm_clock_getres(const clockid_t 
which_clock, struct timespec *tp)
  *
  * 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;
 }
 
diff --git a/kernel/time/posix-clock.c b/kernel/time/posix-clock.c
index f2af1b5..0427c8c 100644
--- a/kernel/time/posix-clock.c
+++ b/kernel/time/posix-clock.c
@@ -297,20 +297,17 @@ static int pc_clock_adjtime(clockid_t id, struct timex 
*tx)
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;
-   struct timespec64 ts64;
int err;
 
err = get_clock_desc(id, &cd);
if (err)
return err;
 
-   if (cd.clk->ops.clock_gettime) {
-   err = cd.clk->ops.clock_gettime(cd.clk, &ts64);
-   *ts = timespec64_to_timespec(ts64);
-   }
+   if (cd.clk->ops.clock_gettime)
+   err = cd.clk->ops.clock_gettime(cd.clk, ts);
else
err = -EOPNOTSUPP;
 
diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
index 4513ad1..6c509ea 100644
--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -261,7 +261,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;
u64 rtn;
@@ -275,13 +275,13 @@ static int posix_cpu_clock_get_task(struct task_struct 
*tsk,
}
 
if (!err)
-   *tp = ns_to_timespec(rtn);
+   *tp = ns_to_timespec64(rtn);
 
return err;
 }
 
 
-static

[Y2038] [RESEND PATCH 1/7] time: Delete do_sys_setimeofday()

2017-03-18 Thread Deepa Dinamani
struct timespec is not y2038 safe. The plan is to
get rid of all uses of timespec internally in the
kernel. Replace uses of timespec with timespec64.
The syscall interfaces will be changed in a separate
series.
Call to do_sys_setimeofday() is superfluous as all
the necessary checks and functions are done by the
underlying function do_sys_setimeofday64().
Replace do_sys_setimeofday64() directly instead of
do_sys_settimeofday(). The do_sys_setimeofday64()
calls timespec64_valid() internally, which is the
same as timespec_valid().

Signed-off-by: Deepa Dinamani 
---
 include/linux/timekeeping.h | 15 ---
 kernel/compat.c |  4 ++--
 kernel/time/posix-stubs.c   |  5 -
 kernel/time/posix-timers.c  |  5 -
 kernel/time/time.c  |  4 ++--
 5 files changed, 12 insertions(+), 21 deletions(-)

diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h
index b598cbc..3617a78 100644
--- a/include/linux/timekeeping.h
+++ b/include/linux/timekeeping.h
@@ -19,21 +19,6 @@ extern void do_gettimeofday(struct timeval *tv);
 extern int do_settimeofday64(const struct timespec64 *ts);
 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;
-
-   if (!tv)
-   return do_sys_settimeofday64(NULL, tz);
-
-   if (!timespec_valid(tv))
-   return -EINVAL;
-
-   ts64 = timespec_to_timespec64(*tv);
-   return do_sys_settimeofday64(&ts64, tz);
-}
-
 /*
  * Kernel time accessors
  */
diff --git a/kernel/compat.c b/kernel/compat.c
index 19aec5d..e29a01a 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -109,7 +109,7 @@ COMPAT_SYSCALL_DEFINE2(settimeofday, struct compat_timeval 
__user *, tv,
   struct timezone __user *, tz)
 {
struct timeval user_tv;
-   struct timespec new_ts;
+   struct timespec64 new_ts;
struct timezone new_tz;
 
if (tv) {
@@ -123,7 +123,7 @@ COMPAT_SYSCALL_DEFINE2(settimeofday, struct compat_timeval 
__user *, tv,
return -EFAULT;
}
 
-   return do_sys_settimeofday(tv ? &new_ts : NULL, tz ? &new_tz : NULL);
+   return do_sys_settimeofday64(tv ? &new_ts : NULL, tz ? &new_tz : NULL);
 }
 
 static int __compat_get_timeval(struct timeval *tv, const struct 
compat_timeval __user *ctv)
diff --git a/kernel/time/posix-stubs.c b/kernel/time/posix-stubs.c
index cd6716e..df275db 100644
--- a/kernel/time/posix-stubs.c
+++ b/kernel/time/posix-stubs.c
@@ -50,12 +50,15 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
const struct timespec __user *, tp)
 {
struct timespec new_tp;
+   struct timespec64 new_tp64;
 
if (which_clock != CLOCK_REALTIME)
return -EINVAL;
if (copy_from_user(&new_tp, tp, sizeof (*tp)))
return -EFAULT;
-   return do_sys_settimeofday(&new_tp, NULL);
+
+   new_tp64 = timespec_to_timespec64(new_tp);
+   return do_sys_settimeofday64(&new_tp64, NULL);
 }
 
 SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 50a6a47..f215ef7 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -214,7 +214,10 @@ static int posix_clock_realtime_get(clockid_t which_clock, 
struct timespec *tp)
 static int posix_clock_realtime_set(const clockid_t which_clock,
const struct timespec *tp)
 {
-   return do_sys_settimeofday(tp, NULL);
+   struct timespec64 tp64;
+
+   tp64 = timespec_to_timespec64(*tp);
+   return do_sys_settimeofday64(&tp64, NULL);
 }
 
 static int posix_clock_realtime_adj(const clockid_t which_clock,
diff --git a/kernel/time/time.c b/kernel/time/time.c
index 25bdd25..450e8a1 100644
--- a/kernel/time/time.c
+++ b/kernel/time/time.c
@@ -194,7 +194,7 @@ SYSCALL_DEFINE2(settimeofday, struct timeval __user *, tv,
struct timezone __user *, tz)
 {
struct timeval user_tv;
-   struct timespec new_ts;
+   struct timespec64 new_ts;
struct timezone new_tz;
 
if (tv) {
@@ -212,7 +212,7 @@ SYSCALL_DEFINE2(settimeofday, struct timeval __user *, tv,
return -EFAULT;
}
 
-   return do_sys_settimeofday(tv ? &new_ts : NULL, tz ? &new_tz : NULL);
+   return do_sys_settimeofday64(tv ? &new_ts : NULL, tz ? &new_tz : NULL);
 }
 
 SYSCALL_DEFINE1(adjtimex, struct timex __user *, txc_p)
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH 5/7] Change k_clock clock_set() to use timespec64

2017-03-18 Thread Deepa Dinamani
struct timespec is not y2038 safe. The plan is to
get rid of all uses of timespec internally in the
kernel. Replace uses of timespec with timespec64.
The syscall interfaces themselves will be changed
in a separate series.

Signed-off-by: Deepa Dinamani 
---
 drivers/char/mmtimer.c |  2 +-
 include/linux/posix-timers.h   |  2 +-
 kernel/time/posix-clock.c  |  5 ++---
 kernel/time/posix-cpu-timers.c |  2 +-
 kernel/time/posix-timers.c | 11 +--
 5 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index 79d8ada..ba1b892 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -489,7 +489,7 @@ static int sgi_clock_get(clockid_t clockid, struct 
timespec64 *tp)
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;
diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index 2555d1c..249429c 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -89,7 +89,7 @@ struct k_itimer {
 struct k_clock {
int (*clock_getres) (const clockid_t which_clock, struct timespec64 
*tp);
int (*clock_set) (const clockid_t which_clock,
- const struct timespec *tp);
+ const struct timespec64 *tp);
int (*clock_get) (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);
diff --git a/kernel/time/posix-clock.c b/kernel/time/posix-clock.c
index d5a4bec..6378fc6 100644
--- a/kernel/time/posix-clock.c
+++ b/kernel/time/posix-clock.c
@@ -335,10 +335,9 @@ static int pc_clock_getres(clockid_t id, struct timespec64 
*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;
-   struct timespec64 ts64 = timespec_to_timespec64(*ts);
int err;
 
err = get_clock_desc(id, &cd);
@@ -351,7 +350,7 @@ static int pc_clock_settime(clockid_t id, const struct 
timespec *ts)
}
 
if (cd.clk->ops.clock_settime)
-   err = cd.clk->ops.clock_settime(cd.clk, &ts64);
+   err = cd.clk->ops.clock_settime(cd.clk, ts);
else
err = -EOPNOTSUPP;
 out:
diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
index 42ca205..0db0e16 100644
--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -135,7 +135,7 @@ posix_cpu_clock_getres(const clockid_t which_clock, struct 
timespec64 *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
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index a314a63..6c09f87 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -212,12 +212,9 @@ static int posix_clock_realtime_get(clockid_t which_clock, 
struct timespec64 *tp
 
 /* Set clock_realtime */
 static int posix_clock_realtime_set(const clockid_t which_clock,
-   const struct timespec *tp)
+   const struct timespec64 *tp)
 {
-   struct timespec64 tp64;
-
-   tp64 = timespec_to_timespec64(*tp);
-   return do_sys_settimeofday64(&tp64, NULL);
+   return do_sys_settimeofday64(tp, NULL);
 }
 
 static int posix_clock_realtime_adj(const clockid_t which_clock,
@@ -1018,14 +1015,16 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, 
which_clock,
 {
struct k_clock *kc = clockid_to_kclock(which_clock);
struct timespec new_tp;
+   struct timespec64 new_tp64;
 
if (!kc || !kc->clock_set)
return -EINVAL;
 
if (copy_from_user(&new_tp, tp, sizeof (*tp)))
return -EFAULT;
+   new_tp64 = timespec_to_timespec64(new_tp);
 
-   return kc->clock_set(which_clock, &new_tp);
+   return kc->clock_set(which_clock, &new_tp64);
 }
 
 SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH 6/7] Change k_clock timer_set() and timer_get() to use timespec64

2017-03-18 Thread Deepa Dinamani
struct timespec is not y2038 safe. The plan is to
get rid of all uses of timespec internally in the
kernel. Replace uses of timespec with timespec64.
The syscall interfaces themselves will be changed
in a separate series.

Signed-off-by: Deepa Dinamani 
---
 drivers/char/mmtimer.c | 20 ++--
 include/linux/posix-timers.h   |  6 +++---
 kernel/time/alarmtimer.c   | 14 +++---
 kernel/time/posix-clock.c  | 21 +++--
 kernel/time/posix-cpu-timers.c | 28 
 kernel/time/posix-timers.c | 33 +++--
 6 files changed, 62 insertions(+), 60 deletions(-)

diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index ba1b892..863a111 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -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,11 @@ static int sgi_timer_set(struct k_itimer *timr, int flags,
return -ENOMEM;
 
if (flags & TIMER_ABSTIME) {
-   struct timespec n;
+   struct timespec64 n;
unsigned long now;
 
-   getnstimeofday(&n);
-   now = timespec_to_ns(&n);
+   getnstimeofday64(&n);
+   now = timespec64_to_ns(&n);
if (when > now)
when -= now;
else
diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index 249429c..f608941 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -97,12 +97,12 @@ struct k_clock {
   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);
+ 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);
+  struct itimerspec64 * cur_setting);
 };
 
 extern struct k_clock clock_posix_cpu;
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index e8a45e2..81db6df 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -598,19 +598,19 @@ static int alarm_timer_create(struct k_itimer *new_timer)
  * 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

[Y2038] [PATCH 4/7] Change k_clock clock_getres() to use timespec64

2017-03-18 Thread Deepa Dinamani
struct timespec is not y2038 safe. The plan is to
get rid of all uses of timespec internally in the
kernel. Replace uses of timespec with timespec64.
The syscall interfaces themselves will be changed
in a separate series.

Signed-off-by: Deepa Dinamani 
---
 drivers/char/mmtimer.c |  2 +-
 include/linux/posix-timers.h   |  2 +-
 kernel/time/alarmtimer.c   |  2 +-
 kernel/time/posix-clock.c  |  9 +++--
 kernel/time/posix-cpu-timers.c |  6 +++---
 kernel/time/posix-timers.c | 10 ++
 6 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index 40d880b..79d8ada 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -765,7 +765,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;
diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index db54f1b..2555d1c 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -87,7 +87,7 @@ struct k_itimer {
 };
 
 struct k_clock {
-   int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
+   int (*clock_getres) (const clockid_t which_clock, struct timespec64 
*tp);
int (*clock_set) (const clockid_t which_clock,
  const struct timespec *tp);
int (*clock_get) (const clockid_t which_clock, struct timespec64 * tp);
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index 944ca6e..e8a45e2 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -541,7 +541,7 @@ static enum alarmtimer_restart alarm_handle_timer(struct 
alarm *alarm,
  *
  * 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;
diff --git a/kernel/time/posix-clock.c b/kernel/time/posix-clock.c
index 0427c8c..d5a4bec 100644
--- a/kernel/time/posix-clock.c
+++ b/kernel/time/posix-clock.c
@@ -316,20 +316,17 @@ static int pc_clock_gettime(clockid_t id, struct 
timespec64 *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;
-   struct timespec64 ts64;
int err;
 
err = get_clock_desc(id, &cd);
if (err)
return err;
 
-   if (cd.clk->ops.clock_getres) {
-   err = cd.clk->ops.clock_getres(cd.clk, &ts64);
-   *ts = timespec64_to_timespec(ts64);
-   }
+   if (cd.clk->ops.clock_getres)
+   err = cd.clk->ops.clock_getres(cd.clk, ts);
else
err = -EOPNOTSUPP;
 
diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
index 6c509ea..42ca205 100644
--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -116,7 +116,7 @@ static inline u64 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) {
@@ -1364,7 +1364,7 @@ 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);
 }
@@ -1389,7 +1389,7 @@ 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);
 }
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index ba0c472..a314a63 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -258,9 +258,9 @@ static int posix_get_monotonic_coarse(clockid_t which_clock,
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;
 }
 
@@ -276,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct 
timespec64 

[Y2038] [PATCH 7/7] Change k_clock nsleep() to use timespec64

2017-03-18 Thread Deepa Dinamani
From: Deepa Dinamani 

struct timespec is not y2038 safe. The plan is to
get rid of all uses of timespec internally in the
kernel. Replace uses of timespec with timespec64.
The syscall interfaces themselves will be changed
in a separate series.

Signed-off-by: Deepa Dinamani 
---
 include/linux/hrtimer.h|  2 +-
 include/linux/posix-timers.h   |  2 +-
 kernel/compat.c|  6 --
 kernel/time/alarmtimer.c   |  4 ++--
 kernel/time/hrtimer.c  | 10 ++
 kernel/time/posix-cpu-timers.c | 36 ++--
 kernel/time/posix-stubs.c  |  6 --
 kernel/time/posix-timers.c | 10 ++
 8 files changed, 42 insertions(+), 34 deletions(-)

diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h
index 249e579..7d019c0 100644
--- a/include/linux/hrtimer.h
+++ b/include/linux/hrtimer.h
@@ -456,7 +456,7 @@ static inline u64 hrtimer_forward_now(struct hrtimer *timer,
 }
 
 /* Precise sleep: */
-extern long hrtimer_nanosleep(struct timespec *rqtp,
+extern long hrtimer_nanosleep(struct timespec64 *rqtp,
  struct timespec __user *rmtp,
  const enum hrtimer_mode mode,
  const clockid_t clockid);
diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index f608941..97a883a 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -94,7 +94,7 @@ struct k_clock {
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 *);
+  struct timespec64 *, struct timespec __user *);
long (*nsleep_restart) (struct restart_block *restart_block);
int (*timer_set) (struct k_itimer * timr, int flags,
  struct itimerspec64 * new_setting,
diff --git a/kernel/compat.c b/kernel/compat.c
index e29a01a..8ec15d1 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -240,18 +240,20 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec 
__user *, rqtp,
   struct compat_timespec __user *, rmtp)
 {
struct timespec tu, rmt;
+   struct timespec64 tu64;
mm_segment_t oldfs;
long ret;
 
if (compat_get_timespec(&tu, rqtp))
return -EFAULT;
 
-   if (!timespec_valid(&tu))
+   tu64 = timespec_to_timespec64(tu);
+   if (!timespec64_valid(&tu64))
return -EINVAL;
 
oldfs = get_fs();
set_fs(KERNEL_DS);
-   ret = hrtimer_nanosleep(&tu,
+   ret = hrtimer_nanosleep(&tu64,
rmtp ? (struct timespec __user *)&rmt : NULL,
HRTIMER_MODE_REL, CLOCK_MONOTONIC);
set_fs(oldfs);
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index 81db6df..cc20417 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -790,7 +790,7 @@ static long __sched alarm_timer_nsleep_restart(struct 
restart_block *restart)
  * Handles clock_nanosleep calls against _ALARM clockids
  */
 static int alarm_timer_nsleep(const clockid_t which_clock, int flags,
-struct timespec *tsreq, struct timespec __user *rmtp)
+struct timespec64 *tsreq, struct timespec __user *rmtp)
 {
enum  alarmtimer_type type = clock2alarm(which_clock);
struct alarm alarm;
@@ -809,7 +809,7 @@ static int alarm_timer_nsleep(const clockid_t which_clock, 
int flags,
 
alarm_init(&alarm, type, alarmtimer_nsleep_wakeup);
 
-   exp = timespec_to_ktime(*tsreq);
+   exp = timespec64_to_ktime(*tsreq);
/* Convert (if necessary) to absolute time */
if (flags != TIMER_ABSTIME) {
ktime_t now = alarm_bases[type].gettime();
diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index ec08f52..f530295 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -1506,7 +1506,7 @@ long __sched hrtimer_nanosleep_restart(struct 
restart_block *restart)
return ret;
 }
 
-long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
+long hrtimer_nanosleep(struct timespec64 *rqtp, struct timespec __user *rmtp,
   const enum hrtimer_mode mode, const clockid_t clockid)
 {
struct restart_block *restart;
@@ -1519,7 +1519,7 @@ long hrtimer_nanosleep(struct timespec *rqtp, struct 
timespec __user *rmtp,
slack = 0;
 
hrtimer_init_on_stack(&t.timer, clockid, mode);
-   hrtimer_set_expires_range_ns(&t.timer, timespec_to_ktime(*rqtp), slack);
+   hrtimer_set_expires_range_ns(&t.timer, timespec64_to_ktime(*rqtp), 
slack);
if (do_nanosleep(&t, mode))
goto out;
 
@@ -1551,14 +1551,16 @@ SYSCALL_DEFINE2(nanosleep, struct timespec __user *, 
rqtp,
struct ti

[Y2038] [PATCH 2/7] time: Change posix clocks ops interfaces to use timespec64

2017-03-18 Thread Deepa Dinamani
 struct timespec is not y2038 safe.
 Replace the posix_clock ops interfaces to use
 struct timespec64.
 The patch also changes struct itimerspec interfaces to
 struct itimerspec64 as itimerspec internally uses timespec
 and itimerspec64 uses timespec64.
 PTP clocks is the only module that sets up these interfaces.
 All individual drivers rely on PTP class driver for exposure
 to userspace. Hence, the change also deals with fixing up these
 PTP interfaces.
 The patch also changes dynamic posix clock implementation to
 reflect the changes in the functional clock interface.

Signed-off-by: Deepa Dinamani 
---
 drivers/ptp/ptp_clock.c | 18 +++---
 include/linux/posix-clock.h | 10 +-
 kernel/time/posix-clock.c   | 34 --
 3 files changed, 36 insertions(+), 26 deletions(-)

diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c
index e814280..b774357 100644
--- a/drivers/ptp/ptp_clock.c
+++ b/drivers/ptp/ptp_clock.c
@@ -97,30 +97,26 @@ 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);
+   err = ptp->info->gettime64(ptp->info, tp);
return err;
 }
 
@@ -133,7 +129,7 @@ static int ptp_clock_adjtime(struct posix_clock *pc, struct 
timex *tx)
ops = ptp->info;
 
if (tx->modes & ADJ_SETOFFSET) {
-   struct timespec ts;
+   struct timespec64 ts;
ktime_t kt;
s64 delta;
 
@@ -146,7 +142,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);
+   kt = timespec64_to_ktime(ts);
delta = ktime_to_ns(kt);
err = ops->adjtime(ops, delta);
} else if (tx->modes & ADJ_FREQUENCY) {
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 9cff0ab..f2af1b5 100644
--- a/kernel/time/posix-clock.c
+++ b/kernel/time/posix-clock.c
@@ -300,14 +300,17 @@ static int pc_clock_adjtime(clockid_t id, struct timex 
*tx)
 static int pc_clock_gettime(clockid_t id, struct timespec *ts)
 {
struct posix_clock_desc cd;
+   struct timespec64 ts64;
int err;
 
err = get_clock_desc(id, &cd);
if (err)
return err;
 
-   if (cd.clk->ops.clock_gettime)
-   err = cd.clk->ops.clock_gettime(cd.clk, 

[Y2038] [PATCH 3/7] Change k_clock clock_get() to use timespec64

2017-03-18 Thread Deepa Dinamani
struct timespec is not y2038 safe. The plan is to
get rid of all uses of timespec internally in the
kernel. Replace uses of timespec with timespec64.
The syscall interfaces themselves will be changed
in a separate series.

Signed-off-by: Deepa Dinamani 
---
 drivers/char/mmtimer.c |  4 ++--
 include/linux/posix-timers.h   |  2 +-
 include/linux/timekeeping.h|  5 +
 kernel/time/alarmtimer.c   |  4 ++--
 kernel/time/posix-clock.c  |  9 +++--
 kernel/time/posix-cpu-timers.c | 10 +-
 kernel/time/posix-stubs.c  |  9 ++---
 kernel/time/posix-timers.c | 32 +---
 8 files changed, 41 insertions(+), 34 deletions(-)

diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index b708c85..40d880b 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -478,13 +478,13 @@ 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;
 };
diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index 64aa189..db54f1b 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -90,7 +90,7 @@ 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_get) (const clockid_t which_clock, struct timespec * tp);
+   int (*clock_get) (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/include/linux/timekeeping.h b/include/linux/timekeeping.h
index 3617a78..ddc229f 100644
--- a/include/linux/timekeeping.h
+++ b/include/linux/timekeeping.h
@@ -258,6 +258,11 @@ static inline void timekeeping_clocktai(struct timespec 
*ts)
*ts = ktime_to_timespec(ktime_get_clocktai());
 }
 
+static inline void timekeeping_clocktai64(struct timespec64 *ts)
+{
+   *ts = ktime_to_timespec64(ktime_get_clocktai());
+}
+
 /*
  * RTC specific
  */
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index ce3a31e..944ca6e 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -558,14 +558,14 @@ static int alarm_clock_getres(const clockid_t 
which_clock, struct timespec *tp)
  *
  * 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;
 }
 
diff --git a/kernel/time/posix-clock.c b/kernel/time/posix-clock.c
index f2af1b5..0427c8c 100644
--- a/kernel/time/posix-clock.c
+++ b/kernel/time/posix-clock.c
@@ -297,20 +297,17 @@ static int pc_clock_adjtime(clockid_t id, struct timex 
*tx)
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;
-   struct timespec64 ts64;
int err;
 
err = get_clock_desc(id, &cd);
if (err)
return err;
 
-   if (cd.clk->ops.clock_gettime) {
-   err = cd.clk->ops.clock_gettime(cd.clk, &ts64);
-   *ts = timespec64_to_timespec(ts64);
-   }
+   if (cd.clk->ops.clock_gettime)
+   err = cd.clk->ops.clock_gettime(cd.clk, ts);
else
err = -EOPNOTSUPP;
 
diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
index 4513ad1..6c509ea 100644
--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -261,7 +261,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;
u64 rtn;
@@ -275,13 +275,13 @@ static int posix_cpu_clock_get_task(struct task_struct 
*tsk,
}
 
if (!err)
-   *tp = ns_to_timespec(rtn);
+   *tp = ns_to_timespec64(rtn);
 
return err;
 }
 
 
-static

[Y2038] [PATCH 1/7] time: Delete do_sys_setimeofday()

2017-03-18 Thread Deepa Dinamani
struct timespec is not y2038 safe. The plan is to
get rid of all uses of timespec internally in the
kernel. Replace uses of timespec with timespec64.
The syscall interfaces will be changed in a separate
series.
Call to do_sys_setimeofday() is superfluous as all
the necessary checks and functions are done by the
underlying function do_sys_setimeofday64().
Replace do_sys_setimeofday64() directly instead of
do_sys_settimeofday(). The do_sys_setimeofday64()
calls timespec64_valid() internally, which is the
same as timespec_valid().

Signed-off-by: Deepa Dinamani 
---
 include/linux/timekeeping.h | 15 ---
 kernel/compat.c |  4 ++--
 kernel/time/posix-stubs.c   |  5 -
 kernel/time/posix-timers.c  |  5 -
 kernel/time/time.c  |  4 ++--
 5 files changed, 12 insertions(+), 21 deletions(-)

diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h
index b598cbc..3617a78 100644
--- a/include/linux/timekeeping.h
+++ b/include/linux/timekeeping.h
@@ -19,21 +19,6 @@ extern void do_gettimeofday(struct timeval *tv);
 extern int do_settimeofday64(const struct timespec64 *ts);
 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;
-
-   if (!tv)
-   return do_sys_settimeofday64(NULL, tz);
-
-   if (!timespec_valid(tv))
-   return -EINVAL;
-
-   ts64 = timespec_to_timespec64(*tv);
-   return do_sys_settimeofday64(&ts64, tz);
-}
-
 /*
  * Kernel time accessors
  */
diff --git a/kernel/compat.c b/kernel/compat.c
index 19aec5d..e29a01a 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -109,7 +109,7 @@ COMPAT_SYSCALL_DEFINE2(settimeofday, struct compat_timeval 
__user *, tv,
   struct timezone __user *, tz)
 {
struct timeval user_tv;
-   struct timespec new_ts;
+   struct timespec64 new_ts;
struct timezone new_tz;
 
if (tv) {
@@ -123,7 +123,7 @@ COMPAT_SYSCALL_DEFINE2(settimeofday, struct compat_timeval 
__user *, tv,
return -EFAULT;
}
 
-   return do_sys_settimeofday(tv ? &new_ts : NULL, tz ? &new_tz : NULL);
+   return do_sys_settimeofday64(tv ? &new_ts : NULL, tz ? &new_tz : NULL);
 }
 
 static int __compat_get_timeval(struct timeval *tv, const struct 
compat_timeval __user *ctv)
diff --git a/kernel/time/posix-stubs.c b/kernel/time/posix-stubs.c
index cd6716e..df275db 100644
--- a/kernel/time/posix-stubs.c
+++ b/kernel/time/posix-stubs.c
@@ -50,12 +50,15 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
const struct timespec __user *, tp)
 {
struct timespec new_tp;
+   struct timespec64 new_tp64;
 
if (which_clock != CLOCK_REALTIME)
return -EINVAL;
if (copy_from_user(&new_tp, tp, sizeof (*tp)))
return -EFAULT;
-   return do_sys_settimeofday(&new_tp, NULL);
+
+   new_tp64 = timespec_to_timespec64(new_tp);
+   return do_sys_settimeofday64(&new_tp64, NULL);
 }
 
 SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 50a6a47..f215ef7 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -214,7 +214,10 @@ static int posix_clock_realtime_get(clockid_t which_clock, 
struct timespec *tp)
 static int posix_clock_realtime_set(const clockid_t which_clock,
const struct timespec *tp)
 {
-   return do_sys_settimeofday(tp, NULL);
+   struct timespec64 tp64;
+
+   tp64 = timespec_to_timespec64(*tp);
+   return do_sys_settimeofday64(&tp64, NULL);
 }
 
 static int posix_clock_realtime_adj(const clockid_t which_clock,
diff --git a/kernel/time/time.c b/kernel/time/time.c
index 25bdd25..450e8a1 100644
--- a/kernel/time/time.c
+++ b/kernel/time/time.c
@@ -194,7 +194,7 @@ SYSCALL_DEFINE2(settimeofday, struct timeval __user *, tv,
struct timezone __user *, tz)
 {
struct timeval user_tv;
-   struct timespec new_ts;
+   struct timespec64 new_ts;
struct timezone new_tz;
 
if (tv) {
@@ -212,7 +212,7 @@ SYSCALL_DEFINE2(settimeofday, struct timeval __user *, tv,
return -EFAULT;
}
 
-   return do_sys_settimeofday(tv ? &new_ts : NULL, tz ? &new_tz : NULL);
+   return do_sys_settimeofday64(tv ? &new_ts : NULL, tz ? &new_tz : NULL);
 }
 
 SYSCALL_DEFINE1(adjtimex, struct timex __user *, txc_p)
-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH 0/7] Change k_clock interfaces to use timespec64

2017-03-18 Thread Deepa Dinamani
The series is aimed at replacing struct timespec which is not
y2038 safe with y2038 safe struct timespec64 for k_clock interfaces.

The series does not change the syscall interface.
This will be done in a follow up series.

A few existing checkpatch-noted style issues, such as the 80 line
character limit, have been left as-is to facilitate easier review.

Deepa Dinamani (7):
  time: Delete do_sys_setimeofday()
  time: Change posix clocks ops interfaces to use timespec64
  Change k_clock clock_get() to use timespec64
  Change k_clock clock_getres() to use timespec64
  Change k_clock clock_set() to use timespec64
  Change k_clock timer_set() and timer_get() to use timespec64
  Change k_clock nsleep() to use timespec64

 drivers/char/mmtimer.c | 28 ++---
 drivers/ptp/ptp_clock.c| 18 
 include/linux/hrtimer.h|  2 +-
 include/linux/posix-clock.h| 10 ++---
 include/linux/posix-timers.h   | 14 +++
 include/linux/timekeeping.h| 20 +++--
 kernel/compat.c| 10 +++--
 kernel/time/alarmtimer.c   | 24 +--
 kernel/time/hrtimer.c  | 10 +++--
 kernel/time/posix-clock.c  | 10 ++---
 kernel/time/posix-cpu-timers.c | 66 --
 kernel/time/posix-stubs.c  | 20 ++---
 kernel/time/posix-timers.c | 93 --
 kernel/time/time.c |  4 +-
 14 files changed, 172 insertions(+), 157 deletions(-)

-- 
2.7.4

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038