Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754332AbbFLHuS (ORCPT ); Fri, 12 Jun 2015 03:50:18 -0400 Received: from mail-pa0-f44.google.com ([209.85.220.44]:36671 "EHLO mail-pa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753695AbbFLHuI (ORCPT ); Fri, 12 Jun 2015 03:50:08 -0400 From: Baolin Wang To: tglx@linutronix.de Cc: arnd@arndb.de, linux-kernel@vger.kernel.org, baolin.wang@linaro.org, y2038@lists.linaro.org Subject: [PATCH v5 09/24] posix-timers: Implement y2038 safe timer_set64() callback Date: Fri, 12 Jun 2015 15:48:24 +0800 Message-Id: <3551d1848e35f659e3753073c7ef58938faad776.1434079263.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <647dcc7ede88d9d95a6f9a2878487d46c233fb2a.1434079262.git.baolin.wang@linaro.org> References: <647dcc7ede88d9d95a6f9a2878487d46c233fb2a.1434079262.git.baolin.wang@linaro.org> In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4713 Lines: 136 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 --- 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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/