y2038: clock_getres64 and clock_adjtime64
cover y2038: clock_getres64 and clock_adjtime64
Hi!
The next set of changes for fixing the y2038 problem for Xenomai:
- clock_getres64
- clock_adjtime64 (only relevant for external clocks, so with limited testing)
Once again: Patches provided by Song, fixes like style adjustments, updated error handling, fixing failing tests done by me and squashed into the patch that introdoced the problem.
Best regards,
Florian
Song Chen (3):
y2038: cobalt/posix/clock: Adding clock_adjtime64
y2038: lib/cobalt/clock: dispatch clock_adjtime
y2038: testsuite/smokey/y2038: testcase for adjtime64
chensong (3):
y2038: cobalt/posix/clock: Adding clock_getres64
y2038: lib/cobalt/clock: dispatch clock_getres
y2038: testsuite/smokey/y2038: testcase for getres64
include/cobalt/uapi/syscall.h | 2 + kernel/cobalt/posix/clock.c | 48 ++++++++++- kernel/cobalt/posix/clock.h | 12 +++ kernel/cobalt/posix/syscall32.c | 14 ++++ kernel/cobalt/posix/syscall32.h | 8 ++ lib/cobalt/clock.c | 10 +++ testsuite/smokey/y2038/syscall-tests.c | 105 +++++++++++++++++++++++++ 7 files changed, 198 insertions(+), 1 deletion(-)
Signature · 1 line
2.31.1
PATCH 1/6 y2038: cobalt/posix/clock: Adding clock_getres64
From: chensong <[email protected]>
Add a syscall specific for clock_getres with 64bit time_t.
--- include/cobalt/uapi/syscall.h | 1 + kernel/cobalt/posix/clock.c | 26 +++++++++++++++++++++++++- kernel/cobalt/posix/clock.h | 6 ++++++ kernel/cobalt/posix/syscall32.c | 7 +++++++ kernel/cobalt/posix/syscall32.h | 4 ++++ 5 files changed, 43 insertions(+), 1 deletion(-)
include/cobalt/uapi/syscall.h +1 -0
@@ -126,6 +126,7 @@#define sc_cobalt_clock_gettime64 103#define sc_cobalt_clock_settime64 104#define sc_cobalt_clock_nanosleep64 105 +#define sc_cobalt_clock_getres64 106#define __NR_COBALT_SYSCALLS 128/* Power of 2 */
kernel/cobalt/posix/clock.c +25 -1
@@ -93,6 +93,30 @@ COBALT_SYSCALL(clock_getres, current,return 0 ; } +int __cobalt_clock_getres64 (clockid_t clock_id, +struct __kernel_timespec __user *u_ts) +{ +struct timespec64 ts; +int ret; + + ret =__cobalt_clock_getres (clock_id, &ts); +if (ret) +return ret; + +if (cobalt_put_timespec64 (&ts, u_ts)) +return -EFAULT ; + +trace_cobalt_clock_getres (clock_id, &ts); + +return 0 ; +} + +COBALT_SYSCALL (clock_getres64, current, + (clockid_t clock_id, struct __kernel_timespec __user *u_ts)) +{ +return __cobalt_clock_getres64 (clock_id, u_ts); +} +int __cobalt_clock_gettime (clockid_t clock_id,struct timespec64 *ts) {xnticks_t ns;
@@ -442,7 +466,7 @@ struct xnclock *cobalt_clock_find(clockid_t clock_id) clock_id ==CLOCK_MONOTONIC_RAW || clock_id == CLOCK_REALTIME) return &nkclock; - +if (__COBALT_CLOCK_EXT_P (clock_id)) { nr =__COBALT_CLOCK_EXT_INDEX (clock_id);xnlock_get_irqsave (&nklock, s);
kernel/cobalt/posix/clock.h +6 -0
@@ -97,6 +97,9 @@ static inline int clock_flag(int flag, clockid_t clock_id)int __cobalt_clock_getres (clockid_t clock_id,struct timespec64 *ts); +int __cobalt_clock_getres64 (clockid_t clock_id, +struct __kernel_timespec __user *u_ts); +int __cobalt_clock_gettime (clockid_t clock_id,struct timespec64 *ts);
@@ -123,6 +126,9 @@ int __cobalt_clock_nanosleep64(clockid_t clock_id, int flags,COBALT_SYSCALL_DECL (clock_getres, (clockid_t clock_id, struct __user_old_timespec __user *u_ts)); +COBALT_SYSCALL_DECL (clock_getres64, + (clockid_t clock_id, struct __kernel_timespec __user *u_ts)); +COBALT_SYSCALL_DECL (clock_gettime, (clockid_t clock_id, struct __user_old_timespec __user *u_ts));
kernel/cobalt/posix/syscall32.c +7 -0
@@ -156,6 +156,13 @@ COBALT_SYSCALL32emu(clock_getres, current,return u_ts ?sys32_put_timespec (u_ts, &ts) :0 ; } +COBALT_SYSCALL32emu (clock_getres64, current, + (clockid_t clock_id, + struct __kernel_timespec __user *u_ts)) +{ +return __cobalt_clock_getres64 (clock_id, u_ts); +} +COBALT_SYSCALL32emu (clock_gettime, current, (clockid_t clock_id, struct old_timespec32 __user *u_ts))
kernel/cobalt/posix/syscall32.h +4 -0
@@ -55,6 +55,10 @@ COBALT_SYSCALL32emu_DECL(clock_getres, (clockid_t clock_id, struct old_timespec32 __user *u_ts)); +COBALT_SYSCALL32emu_DECL (clock_getres64, + (clockid_t clock_id, + struct __kernel_timespec __user *u_ts)); +COBALT_SYSCALL32emu_DECL (clock_gettime, (clockid_t clock_id, struct old_timespec32 __user *u_ts));
Signature · 1 line
2.31.1
PATCH 2/6 y2038: lib/cobalt/clock: dispatch clock_getres
In reply to Florian BezdekaFrom: chensong <[email protected]>
If sizeof time_t bigger than 4, which means glibc supports 64bit timespec, go to clock_getres64.
otherwise, go to original clock_getres.
--- lib/cobalt/clock.c | 5 +++++ 1 file changed, 5 insertions(+)
lib/cobalt/clock.c +5 -0
@@ -101,7 +101,12 @@ COBALT_IMPL(int, clock_getres, (clockid_t clock_id, struct timespec *tp)) {int ret; +#ifdef __USE_TIME_BITS64 + ret = -XENOMAI_SYSCALL2 (sc_cobalt_clock_getres64, clock_id, tp); +#else ret = -XENOMAI_SYSCALL2 (sc_cobalt_clock_getres, clock_id, tp); +#endif +if (ret) { errno = ret;return -1 ;
Signature · 1 line
2.31.1
PATCH 3/6 y2038: testsuite/smokey/y2038: testcase for getres64
In reply to Florian BezdekaFrom: chensong <[email protected]>
add test case for clock_getres64 in testsuite
--- testsuite/smokey/y2038/syscall-tests.c | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
testsuite/smokey/y2038/syscall-tests.c +36 -0
@@ -305,8 +305,40 @@ static int test_sc_cobalt_clock_nanosleep64(void)return 0 ; } +static int test_sc_cobalt_clock_getres64 (void ) +{ +int ret; +int sc_nr = sc_cobalt_clock_getres64; +struct xn_timespec64 ts64; + +/* Make sure we don't crash because of NULL pointers */ + ret =XENOMAI_SYSCALL2 (sc_nr,NULL ,NULL ); +if (ret == -ENOSYS ) { +smokey_note ("clock_getres64: skipped. (no kernel support)" ); +return 0 ;// Not implemented, nothing to test, success + } +if (!smokey_assert (ret == -EFAULT )) +return ret ? ret : -EINVAL ; + +/* Providing an invalid address has to deliver EFAULT */ + ret =XENOMAI_SYSCALL2 (sc_nr,CLOCK_MONOTONIC , (void *)0xdeadbeefUL ); +if (!smokey_assert (ret == -EFAULT )) +return ret ? ret : -EINVAL ; + +/* Provide a valid 64bit timespec */ + ret =XENOMAI_SYSCALL2 (sc_nr,CLOCK_MONOTONIC , &ts64); +if (!smokey_assert (!ret)) +return ret ? ret : -EINVAL ; + +if (ts64.tv_sec !=0 || ts64.tv_nsec !=1 ) +smokey_warning ("High resolution timers not available\n" ); + +return 0 ; +} +static int run_y2038 (struct smokey_test *t,int argc,char *const argv[]) { +int ret; ret =test_sc_cobalt_sem_timedwait64 ();
@@ -325,5 +357,9 @@ static int run_y2038(struct smokey_test *t, int argc, char *const argv[])if (ret)return ret; + ret =test_sc_cobalt_clock_getres64 (); +if (ret) +return ret; +return 0 ; }
Signature · 1 line
2.31.1
Re: [PATCH 3/6] y2038: testsuite/smokey/y2038: testcase for getres64
Quoted 43 lines · Florian Bezdeka
From: chensong <[email protected]>
add test case for
clock_getres64in testsuiteSigned-off-by chensong <[email protected]>[Florian: syscall()->XENOMAI_SYSCALLx(), fix test error handling]Signed-off-by Florian Bezdeka <[email protected]>--- testsuite/smokey/y2038/syscall-tests.c | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)testsuite/smokey/y2038/syscall-tests.c +24
-0@@ -305,8 +305,40 @@ static int test_sc_cobalt_clock_nanosleep64(void)return 0 ; } +static int test_sc_cobalt_clock_getres64 (void ) +{ +int ret; +int sc_nr = sc_cobalt_clock_getres64; +struct xn_timespec64 ts64; + +/* Make sure we don't crash because of NULL pointers */ + ret =XENOMAI_SYSCALL2 (sc_nr,NULL ,NULL ); +if (ret == -ENOSYS ) { +smokey_note ("clock_getres64: skipped. (no kernel support)" ); +return 0 ;// Not implemented, nothing to test, success + } +if (!smokey_assert (ret == -EFAULT )) +return ret ? ret : -EINVAL ; + +/* Providing an invalid address has to deliver EFAULT */ + ret =XENOMAI_SYSCALL2 (sc_nr,CLOCK_MONOTONIC , (void *)0xdeadbeefUL ); +if (!smokey_assert (ret == -EFAULT )) +return ret ? ret : -EINVAL ; + +/* Provide a valid 64bit timespec */ + ret =XENOMAI_SYSCALL2 (sc_nr,CLOCK_MONOTONIC , &ts64); +if (!smokey_assert (!ret)) +return ret ? ret : -EINVAL ;
testsuite/smokey/y2038/syscall-tests.c static int test_sc_cobalt_clock_nanosleep64(void) · line 341
Quoted 10 lines
testsuite/smokey/y2038/syscall-tests.c +8
-0+ +if (ts64.tv_sec !=0 || ts64.tv_nsec !=1 ) +smokey_warning ("High resolution timers not available\n" ); + +return 0 ; +} +static int run_y2038 (struct smokey_test *t,int argc,char *const argv[]) { +
Spurious newline, dropping on merge.
Quoted 5 lines
testsuite/smokey/y2038/syscall-tests.c +0
-0int ret; ret =test_sc_cobalt_sem_timedwait64 ();
testsuite/smokey/y2038/syscall-tests.c static int run_y2038(struct smokey_test *t, int argc, char *const argv[]) · line 365
Quoted 9 lines
testsuite/smokey/y2038/syscall-tests.c +4
-0@@ -325,5 +357,9 @@ static int run_y2038(struct smokey_test *t, int argc, char *const argv[])if (ret)return ret; + ret =test_sc_cobalt_clock_getres64 (); +if (ret) +return ret; +return 0 ; }
Jan
Signature · 2 lines
Siemens AG, T RDA IOT Corporate Competence Center Embedded Linux
PATCH 4/6 y2038: cobalt/posix/clock: Adding clock_adjtime64
In reply to Florian BezdekaFrom: Song Chen <[email protected]>
Add a syscall specific for clock_adjtime with 64bit time_t.
--- include/cobalt/uapi/syscall.h | 1 + kernel/cobalt/posix/clock.c | 22 ++++++++++++++++++++++ kernel/cobalt/posix/clock.h | 6 ++++++ kernel/cobalt/posix/syscall32.c | 7 +++++++ kernel/cobalt/posix/syscall32.h | 4 ++++ 5 files changed, 40 insertions(+)
include/cobalt/uapi/syscall.h +1 -0
@@ -127,6 +127,7 @@#define sc_cobalt_clock_settime64 104#define sc_cobalt_clock_nanosleep64 105#define sc_cobalt_clock_getres64 106 +#define sc_cobalt_clock_adjtime64 107#define __NR_COBALT_SYSCALLS 128/* Power of 2 */
kernel/cobalt/posix/clock.c +22 -0
@@ -276,6 +276,28 @@ COBALT_SYSCALL(clock_adjtime, current,return cobalt_copy_to_user (u_tx, &tx,sizeof (tx)); } +int __cobalt_clock_adjtime64 (clockid_t clock_id, +struct __kernel_timex __user *u_tx) +{ +struct __kernel_timex tx; +int ret; + +if (cobalt_copy_from_user (&tx, u_tx,sizeof (tx))) +return -EFAULT ; + + ret =__cobalt_clock_adjtime (clock_id, &tx); +if (ret) +return ret; + +return cobalt_copy_to_user (u_tx, &tx,sizeof (tx)); +} + +COBALT_SYSCALL (clock_adjtime64, current, + (clockid_t clock_id, struct __kernel_timex __user *u_tx)) +{ +return __cobalt_clock_adjtime64 (clock_id, u_tx); +} +int __cobalt_clock_nanosleep (clockid_t clock_id,int flags,const struct timespec64 *rqt,struct timespec64 *rmt)
kernel/cobalt/posix/clock.h +6 -0
@@ -115,6 +115,9 @@ int __cobalt_clock_settime64(clockid_t clock_id,int __cobalt_clock_adjtime (clockid_t clock_id,struct __kernel_timex *tx); +int __cobalt_clock_adjtime64 (clockid_t clock_id, +struct __kernel_timex __user *u_tx); +int __cobalt_clock_nanosleep (clockid_t clock_id,int flags,const struct timespec64 *rqt,struct timespec64 *rmt);
@@ -145,6 +148,9 @@ COBALT_SYSCALL_DECL(clock_settime64,COBALT_SYSCALL_DECL (clock_adjtime, (clockid_t clock_id, struct __user_old_timex __user *u_tx)); +COBALT_SYSCALL_DECL (clock_adjtime64, + (clockid_t clock_id, struct __kernel_timex __user *u_tx)); + COBALT_SYSCALL_DECL(clock_nanosleep, (clockid_t clock_id, int flags, const struct __user_old_timespec __user *u_rqt,
kernel/cobalt/posix/syscall32.c +7 -0
@@ -222,6 +222,13 @@ COBALT_SYSCALL32emu(clock_adjtime, current,return sys32_put_timex (u_tx, &tx); } +COBALT_SYSCALL32emu (clock_adjtime64, current, + (clockid_t clock_id, struct __kernel_timex __user *u_tx)) +{ +return __cobalt_clock_adjtime64 (clock_id, u_tx); +} + + COBALT_SYSCALL32emu(clock_nanosleep, nonrestartable, (clockid_t clock_id, int flags, const struct old_timespec32 __user *u_rqt,
kernel/cobalt/posix/syscall32.h +4 -0
@@ -79,6 +79,10 @@ COBALT_SYSCALL32emu_DECL(clock_adjtime, (clockid_t clock_id, struct old_timex32 __user *u_tx)); +COBALT_SYSCALL32emu_DECL (clock_adjtime64, + (clockid_t clock_id, + struct __kernel_timex __user *u_tx)); + COBALT_SYSCALL32emu_DECL(clock_nanosleep, (clockid_t clock_id, int flags, const struct old_timespec32 __user *u_rqt,
Signature · 1 line
2.31.1
PATCH 5/6 y2038: lib/cobalt/clock: dispatch clock_adjtime
In reply to Florian BezdekaFrom: Song Chen <[email protected]>
If sizeof time_t bigger than 4, which means glibc supports 64bit timespec, go to clock_adjtime64.
otherwise, go to original clock_adjtime.
--- lib/cobalt/clock.c | 5 +++++ 1 file changed, 5 insertions(+)
lib/cobalt/clock.c +5 -0
@@ -309,7 +309,12 @@ COBALT_IMPL(int, clock_adjtime, (clockid_t clock_id, struct timex *tx)) {int ret; +#ifdef __USE_TIME_BITS64 + ret = -XENOMAI_SYSCALL2 (sc_cobalt_clock_adjtime64, clock_id, tx); +#else ret = -XENOMAI_SYSCALL2 (sc_cobalt_clock_adjtime, clock_id, tx); +#endif +if (ret <0 ) { errno = ret;return -1 ;
Signature · 1 line
2.31.1
PATCH 6/6 y2038: testsuite/smokey/y2038: testcase for adjtime64
In reply to Florian BezdekaFrom: Song Chen <[email protected]>
add test case for clock_adjtime64 in testsuite
--- testsuite/smokey/y2038/syscall-tests.c | 69 ++++++++++++++++++++++++++ 1 file changed, 69 insertions(+)
testsuite/smokey/y2038/syscall-tests.c +69 -0
@@ -28,6 +28,39 @@ struct xn_timespec64 {int64_t tv_nsec; }; +struct xn_timex_timeval { +int64_t tv_sec; +int64_t tv_usec; +}; + +struct xn_timex64 { +int32_t modes;/* mode selector */ +/* pad */ +int64_t offset;/* time offset (usec) */ +int64_t freq;/* frequency offset (scaled ppm) */ +int64_t maxerror;/* maximum error (usec) */ +int64_t esterror;/* estimated error (usec) */ +int32_t status;/* clock command/status */ +/* pad */ +int64_t constant;/* pll time constant */ +int64_t precision;/* clock precision (usec) (read only) */ +int64_t tolerance;/* clock frequency tolerance (ppm) (read only) */ +struct xn_timex_timeval time;/* (read only, except for ADJ_SETOFFSET) */ +int64_t tick;/* (modified) usecs between clock ticks */ + +int64_t ppsfreq;/* pps frequency (scaled ppm) (ro) */ +int64_t jitter;/* pps jitter (us) (ro) */ +int32_t shift;/* interval duration (s) (shift) (ro) */ +/* pad */ +int64_t stabil;/* pps stability (scaled ppm) (ro) */ +int64_t jitcnt;/* jitter limit exceeded (ro) */ +int64_t calcnt;/* calibration intervals (ro) */ +int64_t errcnt;/* calibration errors (ro) */ +int64_t stbcnt;/* stability limit exceeded (ro) */ + +int32_t tai;/* TAI offset (ro) */ +}; +#define NSEC_PER_SEC 1000000000static void ts_normalise (struct xn_timespec64 *ts)
@@ -336,6 +369,38 @@ static int test_sc_cobalt_clock_getres64(void)return 0 ; } +static int test_sc_cobalt_clock_adjtime64 (void ) +{ +int ret; +int sc_nr = sc_cobalt_clock_adjtime64; +struct xn_timex64 tx64 = {}; + +/* Make sure we don't crash because of NULL pointers */ + ret =XENOMAI_SYSCALL2 (sc_nr,NULL ,NULL ); +if (ret == -ENOSYS ) { +smokey_note ("clock_adjtime64: skipped. (no kernel support)" ); +return 0 ;// Not implemented, nothing to test, success + } +if (!smokey_assert (ret == -EFAULT )) +return ret ? ret : -EINVAL ; + +/* Providing an invalid address has to deliver EFAULT */ + ret =XENOMAI_SYSCALL2 (sc_nr,CLOCK_REALTIME , (void *)0xdeadbeefUL ); +if (!smokey_assert (ret == -EFAULT )) +return ret ? ret : -EINVAL ; + +/* Provide a valid 64bit timex */ + tx64.modes =ADJ_SETOFFSET ; + tx64.time.tv_usec =123 ; + ret =XENOMAI_SYSCALL2 (sc_nr,CLOCK_REALTIME , &tx64); + +/* adjtime is supported for external clocks only, expect EOPNOTSUPP */ +if (!smokey_assert (ret == -EOPNOTSUPP )) +return ret ? ret : -EINVAL ; + +return 0 ; +} +static int run_y2038 (struct smokey_test *t,int argc,char *const argv[]) {
@@ -361,5 +426,9 @@ static int run_y2038(struct smokey_test *t, int argc, char *const argv[])if (ret)return ret; + ret =test_sc_cobalt_clock_adjtime64 (); +if (ret) +return ret; +return 0 ; }
Signature · 1 line
2.31.1
Quoted 25 lines · Florian Bezdeka
Hi!
The next set of changes for fixing the y2038 problem for Xenomai:
-
clock_getres64
-clock_adjtime64(only relevant for external clocks, so with limited testing)Once again: Patches provided by Song, fixes like style adjustments, updated error handling, fixing failing tests done by me and squashed into the patch that introdoced the problem.
Best regards,
FlorianSong Chen (3):
y2038: cobalt/posix/clock: Addingclock_adjtime64
y2038:lib/cobalt/clock: dispatchclock_adjtime
y2038: testsuite/smokey/y2038: testcase for adjtime64chensong (3):
y2038: cobalt/posix/clock: Addingclock_getres64
y2038:lib/cobalt/clock: dispatchclock_getres
y2038: testsuite/smokey/y2038: testcase for getres64
Quoted 9 lines
include/cobalt/uapi/syscall.h | 2 + kernel/cobalt/posix/clock.c | 48 ++++++++++- kernel/cobalt/posix/clock.h | 12 +++ kernel/cobalt/posix/syscall32.c | 14 ++++ kernel/cobalt/posix/syscall32.h | 8 ++ lib/cobalt/clock.c | 10 +++ testsuite/smokey/y2038/syscall-tests.c | 105 +++++++++++++++++++++++++ 7 files changed, 198 insertions(+), 1 deletion(-)
Thanks, also applied to next.
Jan
Signature · 2 lines
Siemens AG, T RDA IOT Corporate Competence Center Embedded Linux