2015-05-11 11:16:04

by Baolin Wang

[permalink] [raw]
Subject: [PATCH v3 07/22] posix-timers:Convert to the 64bit methods for the timer_settime syscall function

This patch introduces the timer_settime64 methods with itimerspec64 type for k_clock
structure.

Convert to the 64bit methods with timespec64/itimerspec64 type for the timer_settime
syscall function, and change the timer_settime syscall implementation according the
the CONFIG_64BIT macro.

Signed-off-by: Baolin Wang <[email protected]>
---
include/linux/posix-timers.h | 3 +++
kernel/time/posix-timers.c | 40 +++++++++++++++++++++++++++++++++++-----
2 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index e84436b..870ab93 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 0ec9647..f2fde32 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -524,6 +524,17 @@ static int default_timer_get64(struct k_itimer *timr,
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;
+}
+
void posix_timers_register_clock(const clockid_t clock_id,
struct k_clock *new_clock)
{
@@ -546,6 +557,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;
}
@@ -899,8 +912,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;
@@ -913,10 +926,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) {
@@ -932,9 +945,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;
@@ -946,7 +966,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)))
--
1.7.9.5


2015-05-11 16:32:58

by Arnd Bergmann

[permalink] [raw]
Subject: Re: [Y2038] [PATCH v3 07/22] posix-timers:Convert to the 64bit methods for the timer_settime syscall function

On Monday 11 May 2015 19:15:52 Baolin Wang wrote:
> +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;
> +}
>

As in patch 5, this is missing the conversion to and from the
old types.

Arnd