diff mbox

[v2,06/15] posix-timers:Convert to the 64bit methods for the syscall function

Message ID 1430381584-26425-1-git-send-email-baolin.wang@linaro.org
State New
Headers show

Commit Message

(Exiting) Baolin Wang April 30, 2015, 8:13 a.m. UTC
This patch converts to the 64bit methods with timespec64/itimerspec64 type
for the syscall function, and changes the syscall implementation according to
the CONFIG_64BIT macro.

Also introduces some default functions with timespec64/itimerspec64 type
for the 64bit methods.

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

Patch

diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 0db7f02..4c7c7d3 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;					   \
@@ -513,6 +514,57 @@  static struct pid *good_sigevent(sigevent_t * event)
 	return task_pid(rtn);
 }
 
+static int 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);
+	return 0;
+}
+
+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;
+
+	kc->timer_set(timr, flags, &new_setting, &old_setting);
+	return 0;
+}
+
+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;
+
+	kc->clock_set(which_clock, &tp);
+	return 0;
+}
+
+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;
+
+	kc->clock_get(which_clock, &tp);
+	return 0;
+}
+
+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;
+
+	kc->clock_getres(which_clock, &tp);
+	return 0;
+}
+
 void posix_timers_register_clock(const clockid_t clock_id,
 				 struct k_clock *new_clock)
 {
@@ -522,17 +574,28 @@  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;
 	}
-	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;
 	}
 
+	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);
@@ -579,7 +642,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];
 }
@@ -766,7 +830,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;
@@ -778,10 +842,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;
@@ -791,8 +855,17 @@  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;
+#ifdef CONFIG_64BIT
+	struct itimerspec64 cur_setting;
 	int ret = __timer_gettime(timer_id, &cur_setting);
+#else
+	struct itimerspec64 cur_setting64;
+	struct itimerspec cur_setting;
+	int ret = __timer_gettime(timer_id, &cur_setting64);
+
+	if (!ret)
+		cur_setting = itimerspec64_to_itimerspec(&cur_setting64);
+#endif
 
 	if (!ret && copy_to_user(setting, &cur_setting, sizeof (cur_setting)))
 		return -EFAULT;
@@ -876,8 +949,8 @@  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;
@@ -890,10 +963,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) {
@@ -909,9 +982,16 @@  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;
+#ifdef CONFIG_64BIT
+	struct itimerspec64 new_spec, old_spec;
+	struct itimerspec64 *rtn = old_setting ? &old_spec : NULL;
+#else
+	struct itimerspec new_spec, old_spec;
 	struct itimerspec *rtn = old_setting ? &old_spec : NULL;
+	struct itimerspec64 new_spec64;
+	struct itimerspec64 *rtn64;
+#endif
 
 	if (!new_setting)
 		return -EINVAL;
@@ -923,7 +1003,17 @@  SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
 	    !timespec_valid(&new_spec.it_value))
 		return -EINVAL;
 
+#ifdef CONFIG_64BIT
 	error = __timer_settime(timer_id, flags, &new_spec, rtn);
+#else
+	new_spec64 = itimerspec_to_itimerspec64(&new_spec);
+	if (rtn)
+		*rtn64 = itimerspec_to_itimerspec64(rtn);
+	else
+		rtn64 = NULL;
+
+	error = __timer_settime(timer_id, flags, &new_spec64, rtn64);
+#endif
 
 	if (old_setting && !error &&
 	    copy_to_user(old_setting, &old_spec, sizeof (old_spec)))
@@ -1019,44 +1109,62 @@  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)
 {
+#ifdef CONFIG_64BIT
+	struct timespec64 new_tp;
+#else
 	struct timespec new_tp;
+	struct timespec64 new_tp64;
+#endif
 
 	if (copy_from_user(&new_tp, tp, sizeof (*tp)))
 		return -EFAULT;
 
+#ifdef CONFIG_64BIT
 	return __clock_settime(which_clock, &new_tp);
+#else
+	new_tp64 = timespec_to_timespec64(new_tp);
+	return __clock_settime(which_clock, &new_tp64);
+#endif
 }
 
-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;
 	int error;
-
+#ifdef CONFIG_64BIT
+	struct timespec64 kernel_tp;
 	error = __clock_gettime(which_clock, &kernel_tp);
+#else
+	struct timespec64 kernel_tp64;
+	struct timespec kernel_tp;
+
+	error = __clock_gettime(which_clock, &kernel_tp64);
+	if (!error)
+		kernel_tp = timespec64_to_timespec(kernel_tp64);
+#endif
 
 	if (!error && copy_to_user(tp, &kernel_tp, sizeof (kernel_tp)))
 		error = -EFAULT;
@@ -1087,23 +1195,31 @@  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;
 	int error;
-
+#ifdef CONFIG_64BIT
+	struct timespec64 rtn_tp;
 	error = __clock_getres(which_clock, &rtn_tp);
+#else
+	struct timespec64 rtn_tp64;
+	struct timespec rtn_tp;
+
+	error = __clock_getres(which_clock, &rtn_tp64);
+	if (!error)
+		rtn_tp = timespec64_to_timespec(rtn_tp64);
+#endif
 
 	if (!error && tp && copy_to_user(tp, &rtn_tp, sizeof (rtn_tp)))
 		error = -EFAULT;