diff mbox

[v5,07/24] posix-timers: Implement y2038 safe timer_get64() callback

Message ID bd62cdd274711f481f68b5a41daecea87ddaeb2b.1434079263.git.baolin.wang@linaro.org
State New
Headers show

Commit Message

(Exiting) Baolin Wang June 12, 2015, 7:48 a.m. UTC
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 mbox

Patch

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;