Skip to contentSkip to conversation

cobalt/kernel: y2038: convert struct timeval to __kernel_old_timeval

PATCH In review Philippe Gerum 5 participants 57 messages Feb 20, 2021 – Mar 11, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 cobalt/kernel: y2038: convert struct timeval to __kernel_old_timeval

From: Philippe Gerum <[email protected]>

As internal interfaces are gradually being made y2038-safe, the deprecated timeval type is now available as __kernel_old_timeval in the mainline kernel for the sake of clarity. Switch to this type until Cobalt is y2038-safe as well.

A wrapper is provided to build on older kernels not defining __kernel_old_timeval yet.

---
 include/cobalt/kernel/compat.h                       | 4 ++--
 kernel/cobalt/include/asm-generic/xenomai/wrappers.h | 4 ++++
 kernel/cobalt/posix/clock.h                          | 4 ++--
 kernel/cobalt/posix/compat.c                         | 4 ++--
 kernel/cobalt/posix/io.c                             | 6 +++---
 kernel/cobalt/posix/io.h                             | 2 +-
 kernel/cobalt/posix/syscall32.c                      | 2 +-
 kernel/drivers/ipc/bufp.c                            | 5 +++--
 kernel/drivers/ipc/iddp.c                            | 5 +++--
 kernel/drivers/ipc/internal.h                        | 9 +++++----
 kernel/drivers/ipc/rtipc.c                           | 9 +++++----
 kernel/drivers/ipc/xddp.c                            | 5 +++--
 kernel/drivers/net/stack/ipv4/tcp/tcp.c              | 2 +-
 13 files changed, 35 insertions(+), 26 deletions(-)
include/cobalt/kernel/compat.h +2 -2
index c9cb84f72..313b6251b 100644
@@ -98,11 +98,11 @@ int sys32_get_itimerspec(struct itimerspec *its,
 int sys32_put_itimerspec(struct compat_itimerspec __user *cits,
 			 const struct itimerspec *its);
 
-int sys32_get_timeval(struct timeval *tv,
+int sys32_get_timeval(struct __kernel_old_timeval *tv,
 		      const struct compat_timeval __user *ctv);
 
 int sys32_put_timeval(struct compat_timeval __user *ctv,
-		      const struct timeval *tv);
+		      const struct __kernel_old_timeval *tv);
 
 int sys32_get_timex(struct timex *tx,
 		    const struct old_timex32 __user *ctx);
kernel/cobalt/include/asm-generic/xenomai/wrappers.h +4 -0
index e093676e1..2e9fb203a 100644
@@ -162,4 +162,8 @@ devm_hwmon_device_register_with_groups(struct device *dev, const char *name,
 #define mmiowb()		do { } while (0)
 #endif
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5,4,0)
+#define __kernel_old_timeval	timeval
+#endif
+
 #endif /* _COBALT_ASM_GENERIC_WRAPPERS_H */
kernel/cobalt/posix/clock.h +2 -2
index 0b06b9316..7cb161df2 100644
@@ -43,7 +43,7 @@ static inline xnticks_t ts2ns(const struct timespec *ts)
 	return nsecs;
 }
 
-static inline xnticks_t tv2ns(const struct timeval *tv)
+static inline xnticks_t tv2ns(const struct __kernel_old_timeval *tv)
 {
 	xnticks_t nsecs = tv->tv_usec * 1000;
 
@@ -53,7 +53,7 @@ static inline xnticks_t tv2ns(const struct timeval *tv)
 	return nsecs;
 }
 
-static inline void ticks2tv(struct timeval *tv, xnticks_t ticks)
+static inline void ticks2tv(struct __kernel_old_timeval *tv, xnticks_t ticks)
 {
 	unsigned long nsecs;
 
kernel/cobalt/posix/compat.c +2 -2
index e53e72e0c..2ffc0dbdf 100644
@@ -60,7 +60,7 @@ int sys32_put_itimerspec(struct compat_itimerspec __user *cits,
 }
 EXPORT_SYMBOL_GPL(sys32_put_itimerspec);
 
-int sys32_get_timeval(struct timeval *tv,
+int sys32_get_timeval(struct __kernel_old_timeval *tv,
 		      const struct compat_timeval __user *ctv)
 {
 	return (ctv == NULL ||
@@ -71,7 +71,7 @@ int sys32_get_timeval(struct timeval *tv,
 EXPORT_SYMBOL_GPL(sys32_get_timeval);
 
 int sys32_put_timeval(struct compat_timeval __user *ctv,
-		      const struct timeval *tv)
+		      const struct __kernel_old_timeval *tv)
 {
 	return (ctv == NULL ||
 		!access_wok(ctv, sizeof(*ctv)) ||
kernel/cobalt/posix/io.c +3 -3
index f35aaf8cd..e9908feeb 100644
@@ -212,13 +212,13 @@ int __cobalt_select_bind_all(struct xnselector *selector,
 	return 0;
 }
 
-/* int select(int, fd_set *, fd_set *, fd_set *, struct timeval *) */
+/* int select(int, fd_set *, fd_set *, fd_set *, struct __kernel_old_timeval *) */
 COBALT_SYSCALL(select, primary,
 	       (int nfds,
 		fd_set __user *u_rfds,
 		fd_set __user *u_wfds,
 		fd_set __user *u_xfds,
-		struct timeval __user *u_tv))
+		struct __kernel_old_timeval __user *u_tv))
 {
 	fd_set __user *ufd_sets[XNSELECT_MAX_TYPES] = {
 		[XNSELECT_READ] = u_rfds,
@@ -234,7 +234,7 @@ COBALT_SYSCALL(select, primary,
 	xntmode_t mode = XN_RELATIVE;
 	struct xnselector *selector;
 	struct xnthread *curr;
-	struct timeval tv;
+	struct __kernel_old_timeval tv;
 	size_t fds_size;
 	int i, err;
 
kernel/cobalt/posix/io.h +1 -1
index 6f20dbedd..82187cc7b 100644
@@ -71,6 +71,6 @@ COBALT_SYSCALL_DECL(select,
 		     fd_set __user *u_rfds,
 		     fd_set __user *u_wfds,
 		     fd_set __user *u_xfds,
-		     struct timeval __user *u_tv));
+		     struct __kernel_old_timeval __user *u_tv));
 
 #endif /* !_COBALT_POSIX_IO_H */
kernel/cobalt/posix/syscall32.c +1 -1
index c2fd6a1e0..cb02dacd3 100644
@@ -715,7 +715,7 @@ COBALT_SYSCALL32emu(select, nonrestartable,
 	xntmode_t mode = XN_RELATIVE;
 	struct xnselector *selector;
 	struct xnthread *curr;
-	struct timeval tv;
+	struct __kernel_old_timeval tv;
 	xnsticks_t diff;
 	size_t fds_size;
 	int i, err;
kernel/drivers/ipc/bufp.c +3 -2
index d45480f94..5692f3146 100644
@@ -22,6 +22,7 @@
 #include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/poll.h>
+#include <linux/time.h>
 #include <cobalt/kernel/heap.h>
 #include <cobalt/kernel/map.h>
 #include <cobalt/kernel/bufd.h>
@@ -818,7 +819,7 @@ static int __bufp_setsockopt(struct bufp_socket *sk,
 {
 	struct _rtdm_setsockopt_args sopt;
 	struct rtipc_port_label plabel;
-	struct timeval tv;
+	struct __kernel_old_timeval tv;
 	rtdm_lockctx_t s;
 	size_t len;
 	int ret;
@@ -907,7 +908,7 @@ static int __bufp_getsockopt(struct bufp_socket *sk,
 {
 	struct _rtdm_getsockopt_args sopt;
 	struct rtipc_port_label plabel;
-	struct timeval tv;
+	struct __kernel_old_timeval tv;
 	rtdm_lockctx_t s;
 	socklen_t len;
 	int ret;
kernel/drivers/ipc/iddp.c +3 -2
index f31b9bb66..3a9de845f 100644
@@ -22,6 +22,7 @@
 #include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/poll.h>
+#include <linux/time.h>
 #include <cobalt/kernel/heap.h>
 #include <cobalt/kernel/bufd.h>
 #include <cobalt/kernel/map.h>
@@ -700,7 +701,7 @@ static int __iddp_setsockopt(struct iddp_socket *sk,
 {
 	struct _rtdm_setsockopt_args sopt;
 	struct rtipc_port_label plabel;
-	struct timeval tv;
+	struct __kernel_old_timeval tv;
 	rtdm_lockctx_t s;
 	size_t len;
 	int ret;
@@ -789,7 +790,7 @@ static int __iddp_getsockopt(struct iddp_socket *sk,
 {
 	struct _rtdm_getsockopt_args sopt;
 	struct rtipc_port_label plabel;
-	struct timeval tv;
+	struct __kernel_old_timeval tv;
 	rtdm_lockctx_t s;
 	socklen_t len;
 	int ret;
kernel/drivers/ipc/internal.h +5 -4
index 7c09dd312..919a5d978 100644
@@ -21,6 +21,7 @@
 #define _RTIPC_INTERNAL_H
 
 #include <linux/uio.h>
+#include <linux/time.h>
 #include <cobalt/kernel/registry.h>
 #include <cobalt/kernel/clock.h>
 #include <cobalt/kernel/select.h>
@@ -65,7 +66,7 @@ static inline void *rtipc_fd_to_state(struct rtdm_fd *fd)
 	return p->state;
 }
 
-static inline nanosecs_rel_t rtipc_timeval_to_ns(const struct timeval *tv)
+static inline nanosecs_rel_t rtipc_timeval_to_ns(const struct __kernel_old_timeval *tv)
 {
 	nanosecs_rel_t ns = tv->tv_usec * 1000;
 
@@ -75,7 +76,7 @@ static inline nanosecs_rel_t rtipc_timeval_to_ns(const struct timeval *tv)
 	return ns;
 }
 
-static inline void rtipc_ns_to_timeval(struct timeval *tv, nanosecs_rel_t ns)
+static inline void rtipc_ns_to_timeval(struct __kernel_old_timeval *tv, nanosecs_rel_t ns)
 {
 	unsigned long nsecs;
 
@@ -101,11 +102,11 @@ int rtipc_get_sockoptin(struct rtdm_fd *fd,
 			struct _rtdm_setsockopt_args *sopt,
 			const void *arg);
 
-int rtipc_get_timeval(struct rtdm_fd *fd, struct timeval *tv,
+int rtipc_get_timeval(struct rtdm_fd *fd, struct __kernel_old_timeval *tv,
 		      const void *arg, size_t arglen);
 
 int rtipc_put_timeval(struct rtdm_fd *fd, void *arg,
-		      const struct timeval *tv, size_t arglen);
+		      const struct __kernel_old_timeval *tv, size_t arglen);
 
 int rtipc_get_length(struct rtdm_fd *fd, size_t *lenp,
 		     const void *arg, size_t arglen);
kernel/drivers/ipc/rtipc.c +5 -4
index 99f73202d..b6fafdb41 100644
@@ -21,6 +21,7 @@
 #include <linux/init.h>
 #include <linux/slab.h>
 #include <linux/poll.h>
+#include <linux/time.h>
 #include <rtdm/ipc.h>
 #include <rtdm/compat.h>
 #include "internal.h"
@@ -267,7 +268,7 @@ int rtipc_get_sockoptin(struct rtdm_fd *fd, struct _rtdm_setsockopt_args *sopt,
 	return rtdm_safe_copy_from_user(fd, sopt, arg, sizeof(*sopt));
 }
 
-int rtipc_get_timeval(struct rtdm_fd *fd, struct timeval *tv,
+int rtipc_get_timeval(struct rtdm_fd *fd, struct __kernel_old_timeval *tv,
 		      const void *arg, size_t arglen)
 {
 #ifdef CONFIG_XENO_ARCH_SYS3264
@@ -282,7 +283,7 @@ int rtipc_get_timeval(struct rtdm_fd *fd, struct timeval *tv,
 		return -EINVAL;
 
 	if (!rtdm_fd_is_user(fd)) {
-		*tv = *(struct timeval *)arg;
+		*tv = *(struct __kernel_old_timeval *)arg;
 		return 0;
 	}
 
@@ -290,7 +291,7 @@ int rtipc_get_timeval(struct rtdm_fd *fd, struct timeval *tv,
 }
 
 int rtipc_put_timeval(struct rtdm_fd *fd, void *arg,
-		      const struct timeval *tv, size_t arglen)
+		      const struct __kernel_old_timeval *tv, size_t arglen)
 {
 #ifdef CONFIG_XENO_ARCH_SYS3264
 	if (rtdm_fd_is_compat(fd)) {
@@ -304,7 +305,7 @@ int rtipc_put_timeval(struct rtdm_fd *fd, void *arg,
 		return -EINVAL;
 
 	if (!rtdm_fd_is_user(fd)) {
-		*(struct timeval *)arg = *tv;
+		*(struct __kernel_old_timeval *)arg = *tv;
 		return 0;
 	}
 
kernel/drivers/ipc/xddp.c +3 -2
index c9236a229..25dd68a9d 100644
@@ -21,6 +21,7 @@
 #include <linux/string.h>
 #include <linux/poll.h>
 #include <linux/slab.h>
+#include <linux/time.h>
 #include <cobalt/kernel/heap.h>
 #include <cobalt/kernel/bufd.h>
 #include <cobalt/kernel/pipe.h>
@@ -855,7 +856,7 @@ static int __xddp_setsockopt(struct xddp_socket *sk,
 	int (*monitor)(struct rtdm_fd *fd, int event, long arg);
 	struct _rtdm_setsockopt_args sopt;
 	struct rtipc_port_label plabel;
-	struct timeval tv;
+	struct __kernel_old_timeval tv;
 	rtdm_lockctx_t s;
 	size_t len;
 	int ret;
@@ -961,7 +962,7 @@ static int __xddp_getsockopt(struct xddp_socket *sk,
 {
 	struct _rtdm_getsockopt_args sopt;
 	struct rtipc_port_label plabel;
-	struct timeval tv;
+	struct __kernel_old_timeval tv;
 	rtdm_lockctx_t s;
 	socklen_t len;
 	int ret;
kernel/drivers/net/stack/ipv4/tcp/tcp.c +1 -1
index 54d6f7925..08753e48a 100644
@@ -1742,7 +1742,7 @@ static int rt_tcp_setsockopt(struct rtdm_fd *fd, struct tcp_socket *ts,
 			     socklen_t optlen)
 {
 	/* uint64_t val; */
-	struct timeval tv;
+	struct __kernel_old_timeval tv;
 	rtdm_lockctx_t context;
 
 	switch (optname) {
Signature · 1 line
2.26.2
#1 lore raw

PATCH 2/5 cobalt/kernel: y2038: convert struct timespec to timespec64

From: Philippe Gerum <[email protected]>

As internal interfaces are gradually being made y2038-safe, the timespec64 type should be used internally by the kernel to represent time values. Apply the same reasoning to Cobalt.

We still use a legacy y2038-unsafe timespec type at the kernel<->user interface boundary (struct __user_old_timespec) until libcobalt is y2038-safe.

---
 include/cobalt/kernel/clock.h                 |  6 +-
 include/cobalt/kernel/compat.h                |  4 +-
 .../cobalt/kernel/dovetail/pipeline/clock.h   |  4 +-
 include/cobalt/kernel/ipipe/pipeline/clock.h  |  4 +-
 include/cobalt/kernel/rtdm/fd.h               |  2 +-
 include/cobalt/uapi/kernel/types.h            | 10 ++++
 include/cobalt/uapi/sched.h                   | 12 ++--
 .../include/asm-generic/xenomai/syscall.h     | 58 +++++++++++++++++++
 kernel/cobalt/ipipe/clock.c                   |  2 +-
 kernel/cobalt/posix/clock.c                   | 38 ++++++------
 kernel/cobalt/posix/clock.h                   | 39 +++++++++----
 kernel/cobalt/posix/compat.c                  | 46 ++++++++++-----
 kernel/cobalt/posix/cond.c                    | 11 ++--
 kernel/cobalt/posix/cond.h                    |  4 +-
 kernel/cobalt/posix/event.c                   |  8 +--
 kernel/cobalt/posix/event.h                   |  4 +-
 kernel/cobalt/posix/io.c                      |  6 +-
 kernel/cobalt/posix/io.h                      |  2 +-
 kernel/cobalt/posix/monitor.c                 |  8 +--
 kernel/cobalt/posix/monitor.h                 |  4 +-
 kernel/cobalt/posix/mqueue.c                  | 18 +++---
 kernel/cobalt/posix/mqueue.h                  |  8 +--
 kernel/cobalt/posix/mutex.c                   | 10 ++--
 kernel/cobalt/posix/mutex.h                   |  6 +-
 kernel/cobalt/posix/sched.c                   | 16 ++---
 kernel/cobalt/posix/sem.c                     |  8 +--
 kernel/cobalt/posix/sem.h                     |  4 +-
 kernel/cobalt/posix/signal.c                  |  6 +-
 kernel/cobalt/posix/signal.h                  |  4 +-
 kernel/cobalt/posix/syscall32.c               | 26 ++++-----
 kernel/cobalt/posix/syscall32.h               |  2 +-
 kernel/cobalt/posix/thread.c                  |  6 +-
 kernel/cobalt/rtdm/fd.c                       |  4 +-
 kernel/cobalt/trace/cobalt-posix.h            | 30 +++++-----
 34 files changed, 260 insertions(+), 160 deletions(-)
include/cobalt/kernel/clock.h +3 -3
index bbf34c53c..1c99173ff 100644
@@ -54,7 +54,7 @@ struct xnclock {
 		xnticks_t (*read_raw)(struct xnclock *clock);
 		xnticks_t (*read_monotonic)(struct xnclock *clock);
 		int (*set_time)(struct xnclock *clock,
-				const struct timespec *ts);
+				const struct timespec64 *ts);
 		xnsticks_t (*ns_to_ticks)(struct xnclock *clock,
 					  xnsticks_t ns);
 		xnsticks_t (*ticks_to_ns)(struct xnclock *clock,
@@ -211,7 +211,7 @@ static inline xnticks_t xnclock_read_monotonic(struct xnclock *clock)
 }
 
 static inline int xnclock_set_time(struct xnclock *clock,
-				   const struct timespec *ts)
+				   const struct timespec64 *ts)
 {
 	if (likely(clock == &nkclock))
 		return -EINVAL;
@@ -264,7 +264,7 @@ static inline xnticks_t xnclock_read_monotonic(struct xnclock *clock)
 }
 
 static inline int xnclock_set_time(struct xnclock *clock,
-				   const struct timespec *ts)
+				   const struct timespec64 *ts)
 {
 	/*
 	 * There is no way to change the core clock's idea of time.
include/cobalt/kernel/compat.h +2 -2
index 313b6251b..c57ef6532 100644
@@ -86,11 +86,11 @@ struct compat_rtdm_mmap_request {
 	int flags;
 };
 
-int sys32_get_timespec(struct timespec *ts,
+int sys32_get_timespec(struct timespec64 *ts,
 		       const struct compat_timespec __user *cts);
 
 int sys32_put_timespec(struct compat_timespec __user *cts,
-		       const struct timespec *ts);
+		       const struct timespec64 *ts);
 
 int sys32_get_itimerspec(struct itimerspec *its,
 			 const struct compat_itimerspec __user *cits);
include/cobalt/kernel/dovetail/pipeline/clock.h +2 -2
index 933e100ba..19e3d8986 100644
@@ -8,7 +8,7 @@
 #include <cobalt/uapi/kernel/types.h>
 #include <cobalt/kernel/assert.h>
 
-struct timespec;
+struct timespec64;
 
 static inline u64 pipeline_read_cycle_counter(void)
 {
@@ -49,7 +49,7 @@ static inline const char *pipeline_clock_name(void)
 	return "?";
 }
 
-static inline int pipeline_get_host_time(struct timespec *tp)
+static inline int pipeline_get_host_time(struct timespec64 *tp)
 {
 	/* Convert ktime_get_real_fast_ns() to timespec. */
 	TODO();
include/cobalt/kernel/ipipe/pipeline/clock.h +2 -2
index fa7ac2a5e..d35aea17b 100644
@@ -7,7 +7,7 @@
 
 #include <linux/ipipe_tickdev.h>
 
-struct timespec;
+struct timespec64;
 
 static inline u64 pipeline_read_cycle_counter(void)
 {
@@ -31,7 +31,7 @@ static inline const char *pipeline_clock_name(void)
 	return ipipe_clock_name();
 }
 
-int pipeline_get_host_time(struct timespec *tp);
+int pipeline_get_host_time(struct timespec64 *tp);
 
 void pipeline_update_clock_freq(unsigned long long freq);
 
include/cobalt/kernel/rtdm/fd.h +1 -1
index 289065082..37a09c43e 100644
@@ -380,7 +380,7 @@ int __rtdm_fd_recvmmsg(int ufd, void __user *u_msgvec, unsigned int vlen,
 		       unsigned int flags, void __user *u_timeout,
 		       int (*get_mmsg)(struct mmsghdr *mmsg, void __user *u_mmsg),
 		       int (*put_mmsg)(void __user **u_mmsg_p, const struct mmsghdr *mmsg),
-		       int (*get_timespec)(struct timespec *ts, const void __user *u_ts));
+		       int (*get_timespec)(struct timespec64 *ts, const void __user *u_ts));
 
 ssize_t rtdm_fd_sendmsg(int ufd, const struct user_msghdr *msg,
 			int flags);
include/cobalt/uapi/kernel/types.h +10 -0
index ee5bbadca..8ce9b03df 100644
@@ -57,4 +57,14 @@ static inline xnhandle_t xnhandle_get_id(xnhandle_t handle)
 	return handle & ~XN_HANDLE_TRANSIENT_MASK;
 }
 
+/*
+ * Our representation of time at the kernel<->user interface boundary
+ * at the moment, until we have fully transitioned to a y2038-safe
+ * implementation in libcobalt.
+ */
+struct __user_old_timespec {
+	long  tv_sec;
+	long  tv_nsec;
+};
+
 #endif /* !_COBALT_UAPI_KERNEL_TYPES_H */
include/cobalt/uapi/sched.h +7 -5
index b672095c3..14095870f 100644
@@ -18,6 +18,8 @@
 #ifndef _COBALT_UAPI_SCHED_H
 #define _COBALT_UAPI_SCHED_H
 
+#include <cobalt/uapi/kernel/types.h>
+
 #define SCHED_COBALT		42
 #define SCHED_WEAK		43
 
@@ -31,15 +33,15 @@
 
 struct __sched_ss_param {
 	int __sched_low_priority;
-	struct timespec __sched_repl_period;
-	struct timespec __sched_init_budget;
+	struct __user_old_timespec __sched_repl_period;
+	struct __user_old_timespec __sched_init_budget;
 	int __sched_max_repl;
 };
 
 #define sched_rr_quantum	sched_u.rr.__sched_rr_quantum
 
 struct __sched_rr_param {
-	struct timespec __sched_rr_quantum;
+	struct __user_old_timespec __sched_rr_quantum;
 };
 
 #ifndef SCHED_TP
@@ -52,8 +54,8 @@ struct __sched_tp_param {
 };
 
 struct sched_tp_window {
-	struct timespec offset;
-	struct timespec duration;
+	struct __user_old_timespec offset;
+	struct __user_old_timespec duration;
 	int ptid;
 };
 
kernel/cobalt/include/asm-generic/xenomai/syscall.h +58 -0

70 lines not on this page · raw message

kernel/cobalt/ipipe/clock.c +1 -1
index 606c6bf8c..d40b0ac89 100644
@@ -67,7 +67,7 @@ EXPORT_SYMBOL_GPL(xnclock_core_ticks_to_ns);
 EXPORT_SYMBOL_GPL(xnclock_core_ticks_to_ns_rounded);
 EXPORT_SYMBOL_GPL(xnclock_core_ns_to_ticks);
 
-int pipeline_get_host_time(struct timespec *tp)
+int pipeline_get_host_time(struct timespec64 *tp)
 {
 #ifdef CONFIG_IPIPE_HAVE_HOSTRT
 	struct xnvdso_hostrt_data *hostrt_data;
kernel/cobalt/posix/clock.c +19 -19
index e957dd956..4a3365d2a 100644
@@ -51,7 +51,7 @@ DECLARE_BITMAP(cobalt_clock_extids, COBALT_MAX_EXTCLOCKS);
 	__val;							\
 })
 
-int __cobalt_clock_getres(clockid_t clock_id, struct timespec *ts)
+int __cobalt_clock_getres(clockid_t clock_id, struct timespec64 *ts)
 {
 	xnticks_t ns;
 	int ret;
@@ -75,16 +75,16 @@ int __cobalt_clock_getres(clockid_t clock_id, struct timespec *ts)
 }
 
 COBALT_SYSCALL(clock_getres, current,
-	       (clockid_t clock_id, struct timespec __user *u_ts))
+	       (clockid_t clock_id, struct __user_old_timespec __user *u_ts))
 {
-	struct timespec ts;
+	struct timespec64 ts;
 	int ret;
 
 	ret = __cobalt_clock_getres(clock_id, &ts);
 	if (ret)
 		return ret;
 
-	if (u_ts && cobalt_copy_to_user(u_ts, &ts, sizeof(ts)))
+	if (u_ts && cobalt_put_u_timespec(u_ts, &ts))
 		return -EFAULT;
 
 	trace_cobalt_clock_getres(clock_id, &ts);
@@ -92,7 +92,7 @@ COBALT_SYSCALL(clock_getres, current,
 	return 0;
 }
 
-int __cobalt_clock_gettime(clockid_t clock_id, struct timespec *ts)
+int __cobalt_clock_gettime(clockid_t clock_id, struct timespec64 *ts)
 {
 	xnticks_t ns;
 	int ret;
@@ -122,16 +122,16 @@ int __cobalt_clock_gettime(clockid_t clock_id, struct timespec *ts)
 }
 
 COBALT_SYSCALL(clock_gettime, current,
-	       (clockid_t clock_id, struct timespec __user *u_ts))
+	       (clockid_t clock_id, struct __user_old_timespec __user *u_ts))
 {
-	struct timespec ts;
+	struct timespec64 ts;
 	int ret;
 
 	ret = __cobalt_clock_gettime(clock_id, &ts);
 	if (ret)
 		return ret;
 
-	if (cobalt_copy_to_user(u_ts, &ts, sizeof(*u_ts)))
+	if (cobalt_put_u_timespec(u_ts, &ts))
 		return -EFAULT;
 
 	trace_cobalt_clock_gettime(clock_id, &ts);
@@ -139,7 +139,7 @@ COBALT_SYSCALL(clock_gettime, current,
 	return 0;
 }
 
-int __cobalt_clock_settime(clockid_t clock_id, const struct timespec *ts)
+int __cobalt_clock_settime(clockid_t clock_id, const struct timespec64 *ts)
 {
 	int _ret, ret = 0;
 	xnticks_t now;
@@ -188,11 +188,11 @@ int __cobalt_clock_adjtime(clockid_t clock_id, struct timex *tx)
 }
 
 COBALT_SYSCALL(clock_settime, current,
-	       (clockid_t clock_id, const struct timespec __user *u_ts))
+	       (clockid_t clock_id, const struct __user_old_timespec __user *u_ts))
 {
-	struct timespec ts;
+	struct timespec64 ts;
 
-	if (cobalt_copy_from_user(&ts, u_ts, sizeof(ts)))
+	if (cobalt_get_u_timespec(&ts, u_ts))
 		return -EFAULT;
 
 	return __cobalt_clock_settime(clock_id, &ts);
@@ -215,8 +215,8 @@ COBALT_SYSCALL(clock_adjtime, current,
 }
 
 int __cobalt_clock_nanosleep(clockid_t clock_id, int flags,
-			     const struct timespec *rqt,
-			     struct timespec *rmt)
+			     const struct timespec64 *rqt,
+			     struct timespec64 *rmt)
 {
 	struct restart_block *restart;
 	struct xnthread *cur;
@@ -296,21 +296,21 @@ int __cobalt_clock_nanosleep(clockid_t clock_id, int flags,
 
 COBALT_SYSCALL(clock_nanosleep, primary,
 	       (clockid_t clock_id, int flags,
-		const struct timespec __user *u_rqt,
-		struct timespec __user *u_rmt))
+		const struct __user_old_timespec __user *u_rqt,
+		struct __user_old_timespec __user *u_rmt))
 {
-	struct timespec rqt, rmt, *rmtp = NULL;
+	struct timespec64 rqt, rmt, *rmtp = NULL;
 	int ret;
 
 	if (u_rmt)
 		rmtp = &rmt;
 
-	if (cobalt_copy_from_user(&rqt, u_rqt, sizeof(rqt)))
+	if (cobalt_get_u_timespec(&rqt, u_rqt))
 		return -EFAULT;
 
 	ret = __cobalt_clock_nanosleep(clock_id, flags, &rqt, rmtp);
 	if (ret == -EINTR && flags == 0 && rmtp) {
-		if (cobalt_copy_to_user(u_rmt, rmtp, sizeof(*u_rmt)))
+		if (cobalt_put_u_timespec(u_rmt, rmtp))
 			return -EFAULT;
 	}
 
kernel/cobalt/posix/clock.h +27 -12
index 7cb161df2..7e45fdcc6 100644
@@ -28,12 +28,27 @@
 
 struct xnclock;
 
-static inline void ns2ts(struct timespec *ts, xnticks_t nsecs)
+static inline void ns2ts(struct timespec64 *ts, xnticks_t nsecs)
 {
 	ts->tv_sec = xnclock_divrem_billion(nsecs, &ts->tv_nsec);
 }
 
-static inline xnticks_t ts2ns(const struct timespec *ts)
+static inline void u_ns2ts(struct __user_old_timespec *ts, xnticks_t nsecs)
+{
+	ts->tv_sec = xnclock_divrem_billion(nsecs, &ts->tv_nsec);
+}
+
+static inline xnticks_t ts2ns(const struct timespec64 *ts)
+{
+	xnticks_t nsecs = ts->tv_nsec;
+
+	if (ts->tv_sec)
+		nsecs += (xnticks_t)ts->tv_sec * ONE_BILLION;
+
+	return nsecs;
+}
+
+static inline xnticks_t u_ts2ns(const struct __user_old_timespec *ts)
 {
 	xnticks_t nsecs = ts->tv_nsec;
 
@@ -80,37 +95,37 @@ static inline int clock_flag(int flag, clockid_t clock_id)
 }
 
 int __cobalt_clock_getres(clockid_t clock_id,
-			  struct timespec *ts);
+			  struct timespec64 *ts);
 
 int __cobalt_clock_gettime(clockid_t clock_id,
-			   struct timespec *ts);
+			   struct timespec64 *ts);
 
 int __cobalt_clock_settime(clockid_t clock_id,
-			   const struct timespec *ts);
+			   const struct timespec64 *ts);
 
 int __cobalt_clock_adjtime(clockid_t clock_id,
 			   struct timex *tx);
 
 int __cobalt_clock_nanosleep(clockid_t clock_id, int flags,
-			     const struct timespec *rqt,
-			     struct timespec *rmt);
+			     const struct timespec64 *rqt,
+			     struct timespec64 *rmt);
 
 COBALT_SYSCALL_DECL(clock_getres,
-		    (clockid_t clock_id, struct timespec __user *u_ts));
+		    (clockid_t clock_id, struct __user_old_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(clock_gettime,
-		    (clockid_t clock_id, struct timespec __user *u_ts));
+		    (clockid_t clock_id, struct __user_old_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(clock_settime,
-		    (clockid_t clock_id, const struct timespec __user *u_ts));
+		    (clockid_t clock_id, const struct __user_old_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(clock_adjtime,
 		    (clockid_t clock_id, struct timex __user *u_tx));
 
 COBALT_SYSCALL_DECL(clock_nanosleep,
 		    (clockid_t clock_id, int flags,
-		     const struct timespec __user *u_rqt,
-		     struct timespec __user *u_rmt));
+		     const struct __user_old_timespec __user *u_rqt,
+		     struct __user_old_timespec __user *u_rmt));
 
 int cobalt_clock_register(struct xnclock *clock,
 			  const cpumask_t *affinity,
kernel/cobalt/posix/compat.c +32 -14

69 lines not on this page · raw message

kernel/cobalt/posix/cond.c +5 -6
index 35a8f7176..bb18fe316 100644
@@ -270,25 +270,24 @@ struct us_cond_data {
 	int err;
 };
 
-static inline int cond_fetch_timeout(struct timespec *ts,
+static inline int cond_fetch_timeout(struct timespec64 *ts,
 				     const void __user *u_ts)
 {
-	return u_ts == NULL ? -EFAULT :
-		cobalt_copy_from_user(ts, u_ts, sizeof(*ts));
+	return u_ts == NULL ? -EFAULT :	cobalt_get_u_timespec(ts, u_ts);
 }
 
 int __cobalt_cond_wait_prologue(struct cobalt_cond_shadow __user *u_cnd,
 				struct cobalt_mutex_shadow __user *u_mx,
 				int *u_err,
 				void __user *u_ts,
-				int (*fetch_timeout)(struct timespec *ts,
+				int (*fetch_timeout)(struct timespec64 *ts,
 						     const void __user *u_ts))
 {
 	struct xnthread *cur = xnthread_current();
 	struct cobalt_cond *cond;
 	struct cobalt_mutex *mx;
 	struct us_cond_data d;
-	struct timespec ts;
+	struct timespec64 ts;
 	xnhandle_t handle;
 	int err, perr = 0;
 	__u32 offset;
@@ -349,7 +348,7 @@ COBALT_SYSCALL(cond_wait_prologue, nonrestartable,
 		struct cobalt_mutex_shadow __user *u_mx,
 		int *u_err,
 		unsigned int timed,
-		struct timespec __user *u_ts))
+		struct __user_old_timespec __user *u_ts))
 {
 	return __cobalt_cond_wait_prologue(u_cnd, u_mx, u_err, u_ts,
 					   timed ? cond_fetch_timeout : NULL);
kernel/cobalt/posix/cond.h +2 -2
index c7a9be451..7bec2a649 100644
@@ -43,7 +43,7 @@ int __cobalt_cond_wait_prologue(struct cobalt_cond_shadow __user *u_cnd,
 				struct cobalt_mutex_shadow __user *u_mx,
 				int *u_err,
 				void __user *u_ts,
-				int (*fetch_timeout)(struct timespec *ts,
+				int (*fetch_timeout)(struct timespec64 *ts,
 						     const void __user *u_ts));
 COBALT_SYSCALL_DECL(cond_init,
 		    (struct cobalt_cond_shadow __user *u_cnd,
@@ -57,7 +57,7 @@ COBALT_SYSCALL_DECL(cond_wait_prologue,
 		     struct cobalt_mutex_shadow __user *u_mx,
 		     int *u_err,
 		     unsigned int timed,
-		     struct timespec __user *u_ts));
+		     struct __user_old_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(cond_wait_epilogue,
 		    (struct cobalt_cond_shadow __user *u_cnd,
kernel/cobalt/posix/event.c +4 -4
index c566a09e3..3712154f5 100644
@@ -104,7 +104,7 @@ COBALT_SYSCALL(event_init, current,
 int __cobalt_event_wait(struct cobalt_event_shadow __user *u_event,
 			unsigned int bits,
 			unsigned int __user *u_bits_r,
-			int mode, const struct timespec *ts)
+			int mode, const struct timespec64 *ts)
 {
 	unsigned int rbits = 0, testval;
 	xnticks_t timeout = XN_INFINITE;
@@ -193,14 +193,14 @@ COBALT_SYSCALL(event_wait, primary,
 	       (struct cobalt_event_shadow __user *u_event,
 		unsigned int bits,
 		unsigned int __user *u_bits_r,
-		int mode, const struct timespec __user *u_ts))
+		int mode, const struct __user_old_timespec __user *u_ts))
 {
-	struct timespec ts, *tsp = NULL;
+	struct timespec64 ts, *tsp = NULL;
 	int ret;
 
 	if (u_ts) {
 		tsp = &ts;
-		ret = cobalt_copy_from_user(&ts, u_ts, sizeof(ts));
+		ret = cobalt_get_u_timespec(&ts, u_ts);
 		if (ret)
 			return ret;
 	}
kernel/cobalt/posix/event.h +2 -2
index 28d4516ac..ef592f72c 100644
@@ -39,7 +39,7 @@ struct cobalt_event {
 int __cobalt_event_wait(struct cobalt_event_shadow __user *u_event,
 			unsigned int bits,
 			unsigned int __user *u_bits_r,
-			int mode, const struct timespec *ts);
+			int mode, const struct timespec64 *ts);
 
 COBALT_SYSCALL_DECL(event_init,
 		    (struct cobalt_event_shadow __user *u_evtsh,
@@ -51,7 +51,7 @@ COBALT_SYSCALL_DECL(event_wait,
 		     unsigned int bits,
 		     unsigned int __user *u_bits_r,
 		     int mode,
-		     const struct timespec __user *u_ts));
+		     const struct __user_old_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(event_sync,
 		    (struct cobalt_event_shadow __user *u_evtsh));
kernel/cobalt/posix/io.c +3 -3
index e9908feeb..97a1f6afc 100644
@@ -93,10 +93,10 @@ COBALT_SYSCALL(recvmsg, handover,
 	return cobalt_copy_to_user(umsg, &m, sizeof(*umsg)) ?: ret;
 }
 
-static int get_timespec(struct timespec *ts,
+static int get_timespec(struct timespec64 *ts,
 			const void __user *u_ts)
 {
-	return cobalt_copy_from_user(ts, u_ts, sizeof(*ts));
+	return cobalt_get_u_timespec(ts, u_ts);
 }
 
 static int get_mmsg(struct mmsghdr *mmsg, void __user *u_mmsg)
@@ -114,7 +114,7 @@ static int put_mmsg(void __user **u_mmsg_p, const struct mmsghdr *mmsg)
 
 COBALT_SYSCALL(recvmmsg, primary,
 	       (int fd, struct mmsghdr __user *u_msgvec, unsigned int vlen,
-		unsigned int flags, struct timespec *u_timeout))
+		unsigned int flags, struct __user_old_timespec __user *u_timeout))
 {
 	return __rtdm_fd_recvmmsg(fd, u_msgvec, vlen, flags, u_timeout,
 				  get_mmsg, put_mmsg, get_timespec);
kernel/cobalt/posix/io.h +1 -1
index 82187cc7b..e4f7d4d51 100644
@@ -53,7 +53,7 @@ COBALT_SYSCALL_DECL(recvmsg,
 
 COBALT_SYSCALL_DECL(recvmmsg,
 		    (int fd, struct mmsghdr __user *u_msgvec, unsigned int vlen,
-		     unsigned int flags, struct timespec *u_timeout));
+		     unsigned int flags, struct __user_old_timespec __user *u_timeout));
 
 COBALT_SYSCALL_DECL(sendmsg,
 		    (int fd, struct user_msghdr __user *umsg, int flags));
kernel/cobalt/posix/monitor.c +4 -4
index 5237545be..b907e0050 100644
@@ -203,7 +203,7 @@ drain:
 }
 
 int __cobalt_monitor_wait(struct cobalt_monitor_shadow __user *u_mon,
-			  int event, const struct timespec *ts,
+			  int event, const struct timespec64 *ts,
 			  int __user *u_ret)
 {
 	struct cobalt_thread *curr = cobalt_current_thread();
@@ -291,15 +291,15 @@ out:
 
 COBALT_SYSCALL(monitor_wait, nonrestartable,
 	       (struct cobalt_monitor_shadow __user *u_mon,
-	       int event, const struct timespec __user *u_ts,
+	       int event, const struct __user_old_timespec __user *u_ts,
 	       int __user *u_ret))
 {
-	struct timespec ts, *tsp = NULL;
+	struct timespec64 ts, *tsp = NULL;
 	int ret;
 
 	if (u_ts) {
 		tsp = &ts;
-		ret = cobalt_copy_from_user(&ts, u_ts, sizeof(ts));
+		ret = cobalt_get_u_timespec(&ts, u_ts);
 		if (ret)
 			return ret;
 	}
kernel/cobalt/posix/monitor.h +2 -2
index 8b321aaec..d4a4aa24e 100644
@@ -39,7 +39,7 @@ struct cobalt_monitor {
 };
 
 int __cobalt_monitor_wait(struct cobalt_monitor_shadow __user *u_mon,
-			  int event, const struct timespec *ts,
+			  int event, const struct timespec64 *ts,
 			  int __user *u_ret);
 
 COBALT_SYSCALL_DECL(monitor_init,
@@ -58,7 +58,7 @@ COBALT_SYSCALL_DECL(monitor_exit,
 
 COBALT_SYSCALL_DECL(monitor_wait,
 		    (struct cobalt_monitor_shadow __user *u_monsh,
-		     int event, const struct timespec __user *u_ts,
+		     int event, const struct __user_old_timespec __user *u_ts,
 		     int __user *u_ret));
 
 COBALT_SYSCALL_DECL(monitor_destroy,
kernel/cobalt/posix/mqueue.c +9 -9
index cd1cf3ce8..b2cf92e43 100644
@@ -468,13 +468,13 @@ mq_tryrcv(struct cobalt_mqd *mqd, size_t len)
 static struct cobalt_msg *
 mq_timedsend_inner(struct cobalt_mqd *mqd,
 		   size_t len, const void __user *u_ts,
-		   int (*fetch_timeout)(struct timespec *ts,
+		   int (*fetch_timeout)(struct timespec64 *ts,
 					const void __user *u_ts))
 {
 	struct cobalt_mqwait_context mwc;
 	struct cobalt_msg *msg;
 	struct cobalt_mq *mq;
-	struct timespec ts;
+	struct timespec64 ts;
 	xntmode_t tmode;
 	xnticks_t to;
 	spl_t s;
@@ -597,13 +597,13 @@ static struct cobalt_msg *
 mq_timedrcv_inner(struct cobalt_mqd *mqd,
 		  size_t len,
 		  const void __user *u_ts,
-		  int (*fetch_timeout)(struct timespec *ts,
+		  int (*fetch_timeout)(struct timespec64 *ts,
 				       const void __user *u_ts))
 {
 	struct cobalt_mqwait_context mwc;
 	struct cobalt_msg *msg;
 	struct cobalt_mq *mq;
-	struct timespec ts;
+	struct timespec64 ts;
 	xntmode_t tmode;
 	xnticks_t to;
 	spl_t s;
@@ -880,7 +880,7 @@ COBALT_SYSCALL(mq_getattr, current,
 	return cobalt_copy_to_user(u_attr, &attr, sizeof(attr));
 }
 
-static inline int mq_fetch_timeout(struct timespec *ts,
+static inline int mq_fetch_timeout(struct timespec64 *ts,
 				   const void __user *u_ts)
 {
 	return u_ts == NULL ? -EFAULT :
@@ -889,7 +889,7 @@ static inline int mq_fetch_timeout(struct timespec *ts,
 
 int __cobalt_mq_timedsend(mqd_t uqd, const void __user *u_buf, size_t len,
 			  unsigned int prio, const void __user *u_ts,
-			  int (*fetch_timeout)(struct timespec *ts,
+			  int (*fetch_timeout)(struct timespec64 *ts,
 					       const void __user *u_ts))
 {
 	struct cobalt_msg *msg;
@@ -933,7 +933,7 @@ out:
 
 COBALT_SYSCALL(mq_timedsend, primary,
 	       (mqd_t uqd, const void __user *u_buf, size_t len,
-		unsigned int prio, const struct timespec __user *u_ts))
+		unsigned int prio, const struct __user_old_timespec __user *u_ts))
 {
 	return __cobalt_mq_timedsend(uqd, u_buf, len, prio,
 				     u_ts, u_ts ? mq_fetch_timeout : NULL);
@@ -943,7 +943,7 @@ int __cobalt_mq_timedreceive(mqd_t uqd, void __user *u_buf,
 			     ssize_t *lenp,
 			     unsigned int __user *u_prio,
 			     const void __user *u_ts,
-			     int (*fetch_timeout)(struct timespec *ts,
+			     int (*fetch_timeout)(struct timespec64 *ts,
 						  const void __user *u_ts))
 {
 	struct cobalt_mqd *mqd;
@@ -994,7 +994,7 @@ COBALT_SYSCALL(mq_timedreceive, primary,
 	       (mqd_t uqd, void __user *u_buf,
 		ssize_t __user *u_len,
 		unsigned int __user *u_prio,
-		const struct timespec __user *u_ts))
+		const struct __user_old_timespec __user *u_ts))
 {
 	ssize_t len;
 	int ret;
kernel/cobalt/posix/mqueue.h +4 -4
index acae2a424..d33220227 100644
@@ -37,14 +37,14 @@ int __cobalt_mq_getattr(mqd_t uqd, struct mq_attr *attr);
 
 int __cobalt_mq_timedsend(mqd_t uqd, const void __user *u_buf, size_t len,
 			  unsigned int prio, const void __user *u_ts,
-			  int (*fetch_timeout)(struct timespec *ts,
+			  int (*fetch_timeout)(struct timespec64 *ts,
 					       const void __user *u_ts));
 
 int __cobalt_mq_timedreceive(mqd_t uqd, void __user *u_buf,
 			     ssize_t *lenp,
 			     unsigned int __user *u_prio,
 			     const void __user *u_ts,
-			     int (*fetch_timeout)(struct timespec *ts,
+			     int (*fetch_timeout)(struct timespec64 *ts,
 						  const void __user *u_ts));
 
 int __cobalt_mq_notify(mqd_t fd, const struct sigevent *evp);
@@ -61,12 +61,12 @@ COBALT_SYSCALL_DECL(mq_getattr, (mqd_t uqd, struct mq_attr __user *u_attr));
 
 COBALT_SYSCALL_DECL(mq_timedsend,
 		    (mqd_t uqd, const void __user *u_buf, size_t len,
-		     unsigned int prio, const struct timespec __user *u_ts));
+		     unsigned int prio, const struct __user_old_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(mq_timedreceive,
 		    (mqd_t uqd, void __user *u_buf, ssize_t __user *u_len,
 		     unsigned int __user *u_prio,
-		     const struct timespec __user *u_ts));
+		     const struct __user_old_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(mq_notify,
 		    (mqd_t fd, const struct sigevent *__user evp));
kernel/cobalt/posix/mutex.c +5 -5
index 79260b544..d43a747b3 100644
@@ -71,7 +71,7 @@ static int cobalt_mutex_init_inner(struct cobalt_mutex_shadow *shadow,
 /* must be called with nklock locked, interrupts off. */
 int __cobalt_mutex_acquire_unchecked(struct xnthread *cur,
 				     struct cobalt_mutex *mutex,
-				     const struct timespec *ts)
+				     const struct timespec64 *ts)
 {
 	int ret;
 
@@ -134,11 +134,11 @@ int cobalt_mutex_release(struct xnthread *curr,
 
 int __cobalt_mutex_timedlock_break(struct cobalt_mutex_shadow __user *u_mx,
 				   const void __user *u_ts,
-				   int (*fetch_timeout)(struct timespec *ts,
+				   int (*fetch_timeout)(struct timespec64 *ts,
 							const void __user *u_ts))
 {
 	struct xnthread *curr = xnthread_current();
-	struct timespec ts, *tsp = NULL;
+	struct timespec64 ts, *tsp = NULL;
 	struct cobalt_mutex *mutex;
 	xnhandle_t handle;
 	spl_t s;
@@ -346,7 +346,7 @@ COBALT_SYSCALL(mutex_lock, primary,
 	return __cobalt_mutex_timedlock_break(u_mx, NULL, NULL);
 }
 
-static inline int mutex_fetch_timeout(struct timespec *ts,
+static inline int mutex_fetch_timeout(struct timespec64 *ts,
 				      const void __user *u_ts)
 {
 	return u_ts == NULL ? -EFAULT :
@@ -355,7 +355,7 @@ static inline int mutex_fetch_timeout(struct timespec *ts,
 
 COBALT_SYSCALL(mutex_timedlock, primary,
 	       (struct cobalt_mutex_shadow __user *u_mx,
-		const struct timespec __user *u_ts))
+		const struct __user_old_timespec __user *u_ts))
 {
 	return __cobalt_mutex_timedlock_break(u_mx, u_ts, mutex_fetch_timeout);
 }
kernel/cobalt/posix/mutex.h +3 -3
index ac1c50291..d76f2a9ea 100644
@@ -37,12 +37,12 @@ struct cobalt_mutex {
 
 int __cobalt_mutex_timedlock_break(struct cobalt_mutex_shadow __user *u_mx,
 				   const void __user *u_ts,
-				   int (*fetch_timeout)(struct timespec *ts,
+				   int (*fetch_timeout)(struct timespec64 *ts,
 							const void __user *u_ts));
 
 int __cobalt_mutex_acquire_unchecked(struct xnthread *cur,
 				     struct cobalt_mutex *mutex,
-				     const struct timespec *ts);
+				     const struct timespec64 *ts);
 
 COBALT_SYSCALL_DECL(mutex_check_init,
 		    (struct cobalt_mutex_shadow __user *u_mx));
@@ -62,7 +62,7 @@ COBALT_SYSCALL_DECL(mutex_lock,
 
 COBALT_SYSCALL_DECL(mutex_timedlock,
 		    (struct cobalt_mutex_shadow __user *u_mx,
-		     const struct timespec __user *u_ts));
+		     const struct __user_old_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(mutex_unlock,
 		    (struct cobalt_mutex_shadow __user *u_mx));
kernel/cobalt/posix/sched.c +8 -8
index 798a172d7..4fd9c2b46 100644
@@ -73,7 +73,7 @@ cobalt_sched_policy_param(union xnsched_policy_param *param,
 		break;
 	case SCHED_RR:
 		/* if unspecified, use current one. */
-		tslice = ts2ns(&param_ex->sched_rr_quantum);
+		tslice = u_ts2ns(&param_ex->sched_rr_quantum);
 		if (tslice == XN_INFINITE && tslice_r)
 			tslice = *tslice_r;
 		/* fallthrough */
@@ -92,8 +92,8 @@ cobalt_sched_policy_param(union xnsched_policy_param *param,
 		param->pss.normal_prio = param_ex->sched_priority;
 		param->pss.low_prio = param_ex->sched_ss_low_priority;
 		param->pss.current_prio = param->pss.normal_prio;
-		param->pss.init_budget = ts2ns(&param_ex->sched_ss_init_budget);
-		param->pss.repl_period = ts2ns(&param_ex->sched_ss_repl_period);
+		param->pss.init_budget = u_ts2ns(&param_ex->sched_ss_init_budget);
+		param->pss.repl_period = u_ts2ns(&param_ex->sched_ss_repl_period);
 		param->pss.max_repl = param_ex->sched_ss_max_repl;
 		sched_class = &xnsched_class_sporadic;
 		break;
@@ -280,11 +280,11 @@ int set_tp_config(int cpu, union sched_config *config, size_t len)
 		 * be defined using windows assigned to the pseudo
 		 * partition #-1.
 		 */
-		offset = ts2ns(&p->offset);
+		offset = u_ts2ns(&p->offset);
 		if (offset != next_offset)
 			goto cleanup_and_fail;
 
-		duration = ts2ns(&p->duration);
+		duration = u_ts2ns(&p->duration);
 		if (duration <= 0)
 			goto cleanup_and_fail;
 
@@ -357,11 +357,11 @@ ssize_t get_tp_config(int cpu, void __user *u_config, size_t len,
 	config->tp.nr_windows = gps->pwin_nr;
 	for (n = 0, pp = p = config->tp.windows, pw = w = gps->pwins;
 	     n < gps->pwin_nr; pp = p, p++, pw = w, w++, n++) {
-		ns2ts(&p->offset, w->w_offset);
-		ns2ts(&pp->duration, w->w_offset - pw->w_offset);
+		u_ns2ts(&p->offset, w->w_offset);
+		u_ns2ts(&pp->duration, w->w_offset - pw->w_offset);
 		p->ptid = w->w_part;
 	}
-	ns2ts(&pp->duration, gps->tf_duration - pw->w_offset);
+	u_ns2ts(&pp->duration, gps->tf_duration - pw->w_offset);
 	ret = put_config(SCHED_TP, u_config, len, config, elen);
 	xnfree(config);
 out:
kernel/cobalt/posix/sem.c +4 -4
index 05a861dfe..467a9b7dd 100644
@@ -267,7 +267,7 @@ out:
 	return ret;
 }
 
-static inline int sem_fetch_timeout(struct timespec *ts,
+static inline int sem_fetch_timeout(struct timespec64 *ts,
 				    const void __user *u_ts)
 {
 	return u_ts == NULL ? -EFAULT :
@@ -276,10 +276,10 @@ static inline int sem_fetch_timeout(struct timespec *ts,
 
 int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem,
 			   const void __user *u_ts,
-			   int (*fetch_timeout)(struct timespec *ts,
+			   int (*fetch_timeout)(struct timespec64 *ts,
 						const void __user *u_ts))
 {
-	struct timespec ts = { .tv_sec = 0, .tv_nsec = 0 };
+	struct timespec64 ts = { .tv_sec = 0, .tv_nsec = 0 };
 	int pull_ts = 1, ret, info;
 	struct cobalt_sem *sem;
 	xnhandle_t handle;
@@ -434,7 +434,7 @@ COBALT_SYSCALL(sem_wait, primary,
 
 COBALT_SYSCALL(sem_timedwait, primary,
 	       (struct cobalt_sem_shadow __user *u_sem,
-		struct timespec __user *u_ts))
+		struct __user_old_timespec __user *u_ts))
 {
 	return __cobalt_sem_timedwait(u_sem, u_ts, sem_fetch_timeout);
 }
kernel/cobalt/posix/sem.h +2 -2
index 17238078e..d17299495 100644
@@ -65,7 +65,7 @@ __cobalt_sem_open(struct cobalt_sem_shadow __user *usm,
 
 int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem,
 			   const void __user *u_ts,
-			   int (*fetch_timeout)(struct timespec *ts,
+			   int (*fetch_timeout)(struct timespec64 *ts,
 						const void __user *u_ts));
 
 int __cobalt_sem_destroy(xnhandle_t handle);
@@ -91,7 +91,7 @@ COBALT_SYSCALL_DECL(sem_wait,
 
 COBALT_SYSCALL_DECL(sem_timedwait,
 		    (struct cobalt_sem_shadow __user *u_sem,
-		     struct timespec __user *u_ts));
+		     struct __user_old_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(sem_trywait,
 		    (struct cobalt_sem_shadow __user *u_sem));
kernel/cobalt/posix/signal.c +3 -3
index 862a644c0..0b43b5fcf 100644
@@ -407,7 +407,7 @@ COBALT_SYSCALL(sigwait, primary,
 }
 
 int __cobalt_sigtimedwait(sigset_t *set,
-			  const struct timespec *timeout,
+			  const struct timespec64 *timeout,
 			  void __user *u_si,
 			  bool compat)
 {
@@ -426,9 +426,9 @@ int __cobalt_sigtimedwait(sigset_t *set,
 COBALT_SYSCALL(sigtimedwait, nonrestartable,
 	       (const sigset_t __user *u_set,
 		struct siginfo __user *u_si,
-		const struct timespec __user *u_timeout))
+		const struct __user_old_timespec __user *u_timeout))
 {
-	struct timespec timeout;
+	struct timespec64 timeout;
 	sigset_t set;
 
 	if (cobalt_copy_from_user(&set, u_set, sizeof(set)))
kernel/cobalt/posix/signal.h +2 -2
index 7a0b4b22b..fc26ad065 100644
@@ -59,7 +59,7 @@ void cobalt_copy_siginfo(int code,
 int __cobalt_sigwait(sigset_t *set);
 
 int __cobalt_sigtimedwait(sigset_t *set,
-			  const struct timespec *timeout,
+			  const struct timespec64 *timeout,
 			  void __user *u_si,
 			  bool compat);
 
@@ -94,7 +94,7 @@ COBALT_SYSCALL_DECL(sigwait,
 COBALT_SYSCALL_DECL(sigtimedwait,
 		    (const sigset_t __user *u_set,
 		     struct siginfo __user *u_si,
-		     const struct timespec __user *u_timeout));
+		     const struct __user_old_timespec __user *u_timeout));
 
 COBALT_SYSCALL_DECL(sigwaitinfo,
 		    (const sigset_t __user *u_set,
kernel/cobalt/posix/syscall32.c +12 -14
index cb02dacd3..ae25a6e74 100644
@@ -97,7 +97,7 @@ COBALT_SYSCALL32emu(thread_setschedprio, conforming,
 	return cobalt_thread_setschedprio(pth, prio, u_winoff, u_promoted);
 }
 
-static inline int sys32_fetch_timeout(struct timespec *ts,
+static inline int sys32_fetch_timeout(struct timespec64 *ts,
 				      const void __user *u_ts)
 {
 	return u_ts == NULL ? -EFAULT :
@@ -133,7 +133,7 @@ COBALT_SYSCALL32emu(clock_getres, current,
 		    (clockid_t clock_id,
 		     struct compat_timespec __user *u_ts))
 {
-	struct timespec ts;
+	struct timespec64 ts;
 	int ret;
 
 	ret = __cobalt_clock_getres(clock_id, &ts);
@@ -147,7 +147,7 @@ COBALT_SYSCALL32emu(clock_gettime, current,
 		    (clockid_t clock_id,
 		     struct compat_timespec __user *u_ts))
 {
-	struct timespec ts;
+	struct timespec64 ts;
 	int ret;
 
 	ret = __cobalt_clock_gettime(clock_id, &ts);
@@ -161,7 +161,7 @@ COBALT_SYSCALL32emu(clock_settime, current,
 		    (clockid_t clock_id,
 		     const struct compat_timespec __user *u_ts))
 {
-	struct timespec ts;
+	struct timespec64 ts;
 	int ret;
 
 	ret = sys32_get_timespec(&ts, u_ts);
@@ -193,7 +193,7 @@ COBALT_SYSCALL32emu(clock_nanosleep, nonrestartable,
 		     const struct compat_timespec __user *u_rqt,
 		     struct compat_timespec __user *u_rmt))
 {
-	struct timespec rqt, rmt, *rmtp = NULL;
+	struct timespec64 rqt, rmt, *rmtp = NULL;
 	int ret;
 
 	if (u_rmt)
@@ -289,12 +289,10 @@ COBALT_SYSCALL32emu(mq_timedreceive, primary,
 	return ret ?: cobalt_copy_to_user(u_len, &clen, sizeof(*u_len));
 }
 
-static inline int mq_fetch_timeout(struct timespec *ts,
+static inline int mq_fetch_timeout(struct timespec64 *ts,
 				   const void __user *u_ts)
 {
-	return u_ts == NULL ? -EFAULT :
-		cobalt_copy_from_user(ts, u_ts, sizeof(*ts));
-
+	return u_ts == NULL ? -EFAULT : cobalt_get_u_timespec(ts, u_ts);
 }
 
 COBALT_SYSCALL32emu(mq_notify, primary,
@@ -610,7 +608,7 @@ COBALT_SYSCALL32emu(sigtimedwait, nonrestartable,
 		     struct compat_siginfo __user *u_si,
 		     const struct compat_timespec __user *u_timeout))
 {
-	struct timespec timeout;
+	struct timespec64 timeout;
 	sigset_t set;
 	int ret;
 
@@ -663,7 +661,7 @@ COBALT_SYSCALL32emu(monitor_wait, nonrestartable,
 		     int event, const struct compat_timespec __user *u_ts,
 		     int __user *u_ret))
 {
-	struct timespec ts, *tsp = NULL;
+	struct timespec64 ts, *tsp = NULL;
 	int ret;
 
 	if (u_ts) {
@@ -682,7 +680,7 @@ COBALT_SYSCALL32emu(event_wait, primary,
 		     unsigned int __user *u_bits_r,
 		     int mode, const struct compat_timespec __user *u_ts))
 {
-	struct timespec ts, *tsp = NULL;
+	struct timespec64 ts, *tsp = NULL;
 	int ret;
 
 	if (u_ts) {
@@ -810,7 +808,7 @@ COBALT_SYSCALL32emu(recvmsg, handover,
 	return sys32_put_msghdr(umsg, &m) ?: ret;
 }
 
-static int get_timespec32(struct timespec *ts,
+static int get_timespec32(struct timespec64 *ts,
 			  const void __user *u_ts)
 {
 	return sys32_get_timespec(ts, u_ts);
@@ -924,7 +922,7 @@ COBALT_SYSCALL32x(mq_timedreceive, primary,
 		  (mqd_t uqd, void __user *u_buf,
 		   compat_ssize_t __user *u_len,
 		   unsigned int __user *u_prio,
-		   const struct timespec __user *u_ts))
+		   const struct __user_old_timespec __user *u_ts))
 {
 	compat_ssize_t clen;
 	ssize_t len;
kernel/cobalt/posix/syscall32.h +1 -1
index eb3e4bd30..9da405229 100644
@@ -105,7 +105,7 @@ COBALT_SYSCALL32x_DECL(mq_timedreceive,
 		       (mqd_t uqd, void __user *u_buf,
 			compat_ssize_t __user *u_len,
 			unsigned int __user *u_prio,
-			const struct timespec __user *u_ts));
+			const struct __user_old_timespec __user *u_ts));
 
 COBALT_SYSCALL32emu_DECL(mq_notify,
 			 (mqd_t fd, const struct compat_sigevent *__user u_cev));
kernel/cobalt/posix/thread.c +3 -3
index bf9c08212..cdeb66d4f 100644
@@ -302,7 +302,7 @@ int __cobalt_thread_getschedparam_ex(struct cobalt_thread *thread,
 
 	if (base_class == &xnsched_class_rt) {
 		if (xnthread_test_state(base_thread, XNRRB)) {
-			ns2ts(&param_ex->sched_rr_quantum, base_thread->rrperiod);
+			u_ns2ts(&param_ex->sched_rr_quantum, base_thread->rrperiod);
 			*policy_r = SCHED_RR;
 		}
 		goto out;
@@ -318,8 +318,8 @@ int __cobalt_thread_getschedparam_ex(struct cobalt_thread *thread,
 #ifdef CONFIG_XENO_OPT_SCHED_SPORADIC
 	if (base_class == &xnsched_class_sporadic) {
 		param_ex->sched_ss_low_priority = base_thread->pss->param.low_prio;
-		ns2ts(&param_ex->sched_ss_repl_period, base_thread->pss->param.repl_period);
-		ns2ts(&param_ex->sched_ss_init_budget, base_thread->pss->param.init_budget);
+		u_ns2ts(&param_ex->sched_ss_repl_period, base_thread->pss->param.repl_period);
+		u_ns2ts(&param_ex->sched_ss_init_budget, base_thread->pss->param.init_budget);
 		param_ex->sched_ss_max_repl = base_thread->pss->param.max_repl;
 		goto out;
 	}
kernel/cobalt/rtdm/fd.c +2 -2
index 7956a8800..038247d54 100644
@@ -650,11 +650,11 @@ int __rtdm_fd_recvmmsg(int ufd, void __user *u_msgvec, unsigned int vlen,
 		       unsigned int flags, void __user *u_timeout,
 		       int (*get_mmsg)(struct mmsghdr *mmsg, void __user *u_mmsg),
 		       int (*put_mmsg)(void __user **u_mmsg_p, const struct mmsghdr *mmsg),
-		       int (*get_timespec)(struct timespec *ts, const void __user *u_ts))
+		       int (*get_timespec)(struct timespec64 *ts, const void __user *u_ts))
 {
 	struct cobalt_recvmmsg_timer rq;
 	xntmode_t tmode = XN_RELATIVE;
-	struct timespec ts = { 0 };
+	struct timespec64 ts = { 0 };
 	int ret = 0, datagrams = 0;
 	xnticks_t timeout = 0;
 	struct mmsghdr mmsg;
kernel/cobalt/trace/cobalt-posix.h +15 -15
index aa78efbc0..3a649a671 100644
@@ -30,7 +30,7 @@
 #include <xenomai/posix/event.h>
 
 #define __timespec_fields(__name)				\
-	__field(__kernel_time_t, tv_sec_##__name)		\
+	__field(time64_t, tv_sec_##__name)			\
 	__field(long, tv_nsec_##__name)
 
 #define __assign_timespec(__to, __from)				\
@@ -40,7 +40,7 @@
 	} while (0)
 
 #define __timespec_args(__name)					\
-	__entry->tv_sec_##__name, __entry->tv_nsec_##__name
+	(long long)__entry->tv_sec_##__name, __entry->tv_nsec_##__name
 
 #ifdef CONFIG_X86_X32
 #define __sc_x32(__name)	, { sc_cobalt_##__name + __COBALT_X32_BASE, "x32-" #__name }
@@ -729,7 +729,7 @@ TRACE_EVENT(cobalt_psem_unlink,
 );
 
 DECLARE_EVENT_CLASS(cobalt_clock_timespec,
-	TP_PROTO(clockid_t clk_id, const struct timespec *val),
+	TP_PROTO(clockid_t clk_id, const struct timespec64 *val),
 	TP_ARGS(clk_id, val),
 
 	TP_STRUCT__entry(
@@ -742,24 +742,24 @@ DECLARE_EVENT_CLASS(cobalt_clock_timespec,
 		__assign_timespec(val, val);
 	),
 
-	TP_printk("clock_id=%d timeval=(%ld.%09ld)",
+	TP_printk("clock_id=%d timeval=(%lld.%09ld)",
 		  __entry->clk_id,
 		  __timespec_args(val)
 	)
 );
 
 DEFINE_EVENT(cobalt_clock_timespec, cobalt_clock_getres,
-	TP_PROTO(clockid_t clk_id, const struct timespec *res),
+	TP_PROTO(clockid_t clk_id, const struct timespec64 *res),
 	TP_ARGS(clk_id, res)
 );
 
 DEFINE_EVENT(cobalt_clock_timespec, cobalt_clock_gettime,
-	TP_PROTO(clockid_t clk_id, const struct timespec *time),
+	TP_PROTO(clockid_t clk_id, const struct timespec64 *time),
 	TP_ARGS(clk_id, time)
 );
 
 DEFINE_EVENT(cobalt_clock_timespec, cobalt_clock_settime,
-	TP_PROTO(clockid_t clk_id, const struct timespec *time),
+	TP_PROTO(clockid_t clk_id, const struct timespec64 *time),
 	TP_ARGS(clk_id, time)
 );
 
@@ -788,7 +788,7 @@ TRACE_EVENT(cobalt_clock_adjtime,
 		      {TIMER_ABSTIME, "TIMER_ABSTIME"})
 
 TRACE_EVENT(cobalt_clock_nanosleep,
-	TP_PROTO(clockid_t clk_id, int flags, const struct timespec *time),
+	TP_PROTO(clockid_t clk_id, int flags, const struct timespec64 *time),
 	TP_ARGS(clk_id, flags, time),
 
 	TP_STRUCT__entry(
@@ -803,7 +803,7 @@ TRACE_EVENT(cobalt_clock_nanosleep,
 		__assign_timespec(time, time);
 	),
 
-	TP_printk("clock_id=%d flags=%#x(%s) rqt=(%ld.%09ld)",
+	TP_printk("clock_id=%d flags=%#x(%s) rqt=(%lld.%09ld)",
 		  __entry->clk_id,
 		  __entry->flags, cobalt_print_timer_flags(__entry->flags),
 		  __timespec_args(time)
@@ -875,7 +875,7 @@ TRACE_EVENT(cobalt_cond_destroy,
 TRACE_EVENT(cobalt_cond_timedwait,
 	TP_PROTO(const struct cobalt_cond_shadow __user *u_cnd,
 		 const struct cobalt_mutex_shadow __user *u_mx,
-		 const struct timespec *timeout),
+		 const struct timespec64 *timeout),
 	TP_ARGS(u_cnd, u_mx, timeout),
 	TP_STRUCT__entry(
 		__field(const struct cobalt_cond_shadow __user *, u_cnd)
@@ -887,7 +887,7 @@ TRACE_EVENT(cobalt_cond_timedwait,
 		__entry->u_mx = u_mx;
 		__assign_timespec(timeout, timeout);
 	),
-	TP_printk("cond=%p, mutex=%p, timeout=(%ld.%09ld)",
+	TP_printk("cond=%p, mutex=%p, timeout=(%lld.%09ld)",
 		  __entry->u_cnd, __entry->u_mx, __timespec_args(timeout))
 );
 
@@ -1001,7 +1001,7 @@ TRACE_EVENT(cobalt_mq_send,
 
 TRACE_EVENT(cobalt_mq_timedreceive,
 	TP_PROTO(mqd_t mqd, const void __user *u_buf, size_t len,
-		 const struct timespec *timeout),
+		 const struct timespec64 *timeout),
 	TP_ARGS(mqd, u_buf, len, timeout),
 	TP_STRUCT__entry(
 		__field(mqd_t, mqd)
@@ -1015,7 +1015,7 @@ TRACE_EVENT(cobalt_mq_timedreceive,
 		__entry->len = len;
 		__assign_timespec(timeout, timeout);
 	),
-	TP_printk("mqd=%d buf=%p len=%zu timeout=(%ld.%09ld)",
+	TP_printk("mqd=%d buf=%p len=%zu timeout=(%lld.%09ld)",
 		  __entry->mqd, __entry->u_buf, __entry->len,
 		  __timespec_args(timeout))
 );
@@ -1105,7 +1105,7 @@ TRACE_EVENT(cobalt_event_init,
 TRACE_EVENT(cobalt_event_timedwait,
 	TP_PROTO(const struct cobalt_event_shadow __user *u_event,
 		 unsigned long bits, int mode,
-		 const struct timespec *timeout),
+		 const struct timespec64 *timeout),
 	TP_ARGS(u_event, bits, mode, timeout),
 	TP_STRUCT__entry(
 		__field(const struct cobalt_event_shadow __user *, u_event)
@@ -1119,7 +1119,7 @@ TRACE_EVENT(cobalt_event_timedwait,
 		__entry->mode = mode;
 		__assign_timespec(timeout, timeout);
 	),
-	TP_printk("event=%p bits=%#lx mode=%#x(%s) timeout=(%ld.%09ld)",
+	TP_printk("event=%p bits=%#lx mode=%#x(%s) timeout=(%lld.%09ld)",
 		  __entry->u_event, __entry->bits, __entry->mode,
 		  cobalt_print_evmode(__entry->mode),
 		  __timespec_args(timeout))
Signature · 1 line
2.26.2
#2 lore raw

Re: [PATCH 2/5] cobalt/kernel: y2038: convert struct timespec to timespec64

Quoted 161 lines · Philippe Gerum via Xenomai

From: Philippe Gerum <[email protected]>

As internal interfaces are gradually being made y2038-safe, the timespec64 type should be used internally by the kernel to represent time values. Apply the same reasoning to Cobalt.

We still use a legacy y2038-unsafe timespec type at the kernel<->user interface boundary (struct __user_old_timespec) until libcobalt is y2038-safe.

---
  include/cobalt/kernel/clock.h                 |  6 +-
  include/cobalt/kernel/compat.h                |  4 +-
  .../cobalt/kernel/dovetail/pipeline/clock.h   |  4 +-
  include/cobalt/kernel/ipipe/pipeline/clock.h  |  4 +-
  include/cobalt/kernel/rtdm/fd.h               |  2 +-
  include/cobalt/uapi/kernel/types.h            | 10 ++++
  include/cobalt/uapi/sched.h                   | 12 ++--
  .../include/asm-generic/xenomai/syscall.h     | 58 +++++++++++++++++++
  kernel/cobalt/ipipe/clock.c                   |  2 +-
  kernel/cobalt/posix/clock.c                   | 38 ++++++------
  kernel/cobalt/posix/clock.h                   | 39 +++++++++----
  kernel/cobalt/posix/compat.c                  | 46 ++++++++++-----
  kernel/cobalt/posix/cond.c                    | 11 ++--
  kernel/cobalt/posix/cond.h                    |  4 +-
  kernel/cobalt/posix/event.c                   |  8 +--
  kernel/cobalt/posix/event.h                   |  4 +-
  kernel/cobalt/posix/io.c                      |  6 +-
  kernel/cobalt/posix/io.h                      |  2 +-
  kernel/cobalt/posix/monitor.c                 |  8 +--
  kernel/cobalt/posix/monitor.h                 |  4 +-
  kernel/cobalt/posix/mqueue.c                  | 18 +++---
  kernel/cobalt/posix/mqueue.h                  |  8 +--
  kernel/cobalt/posix/mutex.c                   | 10 ++--
  kernel/cobalt/posix/mutex.h                   |  6 +-
  kernel/cobalt/posix/sched.c                   | 16 ++---
  kernel/cobalt/posix/sem.c                     |  8 +--
  kernel/cobalt/posix/sem.h                     |  4 +-
  kernel/cobalt/posix/signal.c                  |  6 +-
  kernel/cobalt/posix/signal.h                  |  4 +-
  kernel/cobalt/posix/syscall32.c               | 26 ++++-----
  kernel/cobalt/posix/syscall32.h               |  2 +-
  kernel/cobalt/posix/thread.c                  |  6 +-
  kernel/cobalt/rtdm/fd.c                       |  4 +-
  kernel/cobalt/trace/cobalt-posix.h            | 30 +++++-----
  34 files changed, 260 insertions(+), 160 deletions(-)
include/cobalt/kernel/clock.h +3 -3
index bbf34c53c..1c99173ff 100644
@@ -54,7 +54,7 @@ struct xnclock {
  		xnticks_t (*read_raw)(struct xnclock *clock);
  		xnticks_t (*read_monotonic)(struct xnclock *clock);
  		int (*set_time)(struct xnclock *clock,
-				const struct timespec *ts);
+				const struct timespec64 *ts);
  		xnsticks_t (*ns_to_ticks)(struct xnclock *clock,
  					  xnsticks_t ns);
  		xnsticks_t (*ticks_to_ns)(struct xnclock *clock,
@@ -211,7 +211,7 @@ static inline xnticks_t xnclock_read_monotonic(struct xnclock *clock)
  }
 
  static inline int xnclock_set_time(struct xnclock *clock,
-				   const struct timespec *ts)
+				   const struct timespec64 *ts)
  {
  	if (likely(clock == &nkclock))
  		return -EINVAL;
@@ -264,7 +264,7 @@ static inline xnticks_t xnclock_read_monotonic(struct xnclock *clock)
  }
 
  static inline int xnclock_set_time(struct xnclock *clock,
-				   const struct timespec *ts)
+				   const struct timespec64 *ts)
  {
  	/*
  	 * There is no way to change the core clock's idea of time.
include/cobalt/kernel/compat.h +2 -2
index 313b6251b..c57ef6532 100644
@@ -86,11 +86,11 @@ struct compat_rtdm_mmap_request {
  	int flags;
  };
 
-int sys32_get_timespec(struct timespec *ts,
+int sys32_get_timespec(struct timespec64 *ts,
  		       const struct compat_timespec __user *cts);
 
  int sys32_put_timespec(struct compat_timespec __user *cts,
-		       const struct timespec *ts);
+		       const struct timespec64 *ts);
 
  int sys32_get_itimerspec(struct itimerspec *its,
  			 const struct compat_itimerspec __user *cits);
include/cobalt/kernel/dovetail/pipeline/clock.h +2 -2
index 933e100ba..19e3d8986 100644
@@ -8,7 +8,7 @@
  #include <cobalt/uapi/kernel/types.h>
  #include <cobalt/kernel/assert.h>
 
-struct timespec;
+struct timespec64;
 
  static inline u64 pipeline_read_cycle_counter(void)
  {
@@ -49,7 +49,7 @@ static inline const char *pipeline_clock_name(void)
  	return "?";
  }
 
-static inline int pipeline_get_host_time(struct timespec *tp)
+static inline int pipeline_get_host_time(struct timespec64 *tp)
  {
  	/* Convert ktime_get_real_fast_ns() to timespec. */
  	TODO();
include/cobalt/kernel/ipipe/pipeline/clock.h +2 -2
index fa7ac2a5e..d35aea17b 100644
@@ -7,7 +7,7 @@
 
  #include <linux/ipipe_tickdev.h>
 
-struct timespec;
+struct timespec64;
 
  static inline u64 pipeline_read_cycle_counter(void)
  {
@@ -31,7 +31,7 @@ static inline const char *pipeline_clock_name(void)
  	return ipipe_clock_name();
  }
 
-int pipeline_get_host_time(struct timespec *tp);
+int pipeline_get_host_time(struct timespec64 *tp);
 
  void pipeline_update_clock_freq(unsigned long long freq);
 
include/cobalt/kernel/rtdm/fd.h +1 -1
index 289065082..37a09c43e 100644
@@ -380,7 +380,7 @@ int __rtdm_fd_recvmmsg(int ufd, void __user *u_msgvec, unsigned int vlen,
  		       unsigned int flags, void __user *u_timeout,
  		       int (*get_mmsg)(struct mmsghdr *mmsg, void __user *u_mmsg),
  		       int (*put_mmsg)(void __user **u_mmsg_p, const struct mmsghdr *mmsg),
-		       int (*get_timespec)(struct timespec *ts, const void __user *u_ts));
+		       int (*get_timespec)(struct timespec64 *ts, const void __user *u_ts));
 
  ssize_t rtdm_fd_sendmsg(int ufd, const struct user_msghdr *msg,
  			int flags);
include/cobalt/uapi/kernel/types.h +0 -0
index ee5bbadca..8ce9b03df 100644
@@ -57,4 +57,14 @@ static inline xnhandle_t xnhandle_get_id(xnhandle_t handle)
  	return handle & ~XN_HANDLE_TRANSIENT_MASK;
  }

include/cobalt/uapi/kernel/types.h static inline xnhandle_t xnhandle_get_id(xnhandle_t handle) · line 68

Quoted 10 lines
include/cobalt/uapi/kernel/types.h +9 -0
 
+/*
+ * Our representation of time at the kernel<->user interface boundary
+ * at the moment, until we have fully transitioned to a y2038-safe
+ * implementation in libcobalt.
+ */
+struct __user_old_timespec {
+	long  tv_sec;
+	long  tv_nsec;
+};

why not use old_timespec32, which is timespec32 representation defined in include/linux/time32?

Quoted 206 lines
include/cobalt/uapi/kernel/types.h +1 -0
+
  #endif /* !_COBALT_UAPI_KERNEL_TYPES_H */
include/cobalt/uapi/sched.h +7 -5
index b672095c3..14095870f 100644
@@ -18,6 +18,8 @@
  #ifndef _COBALT_UAPI_SCHED_H
  #define _COBALT_UAPI_SCHED_H
 
+#include <cobalt/uapi/kernel/types.h>
+
  #define SCHED_COBALT		42
  #define SCHED_WEAK		43
 
@@ -31,15 +33,15 @@
 
  struct __sched_ss_param {
  	int __sched_low_priority;
-	struct timespec __sched_repl_period;
-	struct timespec __sched_init_budget;
+	struct __user_old_timespec __sched_repl_period;
+	struct __user_old_timespec __sched_init_budget;
  	int __sched_max_repl;
  };
 
  #define sched_rr_quantum	sched_u.rr.__sched_rr_quantum
 
  struct __sched_rr_param {
-	struct timespec __sched_rr_quantum;
+	struct __user_old_timespec __sched_rr_quantum;
  };
 
  #ifndef SCHED_TP
@@ -52,8 +54,8 @@ struct __sched_tp_param {
  };
 
  struct sched_tp_window {
-	struct timespec offset;
-	struct timespec duration;
+	struct __user_old_timespec offset;
+	struct __user_old_timespec duration;
  	int ptid;
  };
 
kernel/cobalt/include/asm-generic/xenomai/syscall.h +58 -0
index 0d50d4107..05a7d2868 100644
@@ -26,6 +26,7 @@
  #include <asm/xenomai/wrappers.h>
  #include <asm/xenomai/machine.h>
  #include <cobalt/uapi/asm-generic/syscall.h>
+#include <cobalt/uapi/kernel/types.h>
 
  #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0)
  #define access_rok(addr, size)	access_ok((addr), (size))
@@ -81,6 +82,63 @@ static inline int cobalt_strncpy_from_user(char *dst, const char __user *src,
  	return __xn_strncpy_from_user(dst, src, count);
  }
 
+#if __BITS_PER_LONG == 64
+
+/*
+ * NOTE: those copy helpers won't work in compat mode: use
+ * sys32_get_timespec(), sys32_put_timespec() instead.
+ */
+
+static inline int cobalt_get_u_timespec(struct timespec64 *dst,
+			const struct __user_old_timespec __user *src)
+{
+	return cobalt_copy_from_user(dst, src, sizeof(*dst));
+}
+
+static inline int cobalt_put_u_timespec(
+	struct __user_old_timespec __user *dst,
+	const struct timespec64 *src)
+{
+	return cobalt_copy_to_user(dst, src, sizeof(*dst));
+}
+
+#else /* __BITS_PER_LONG == 32 */
+
+static inline int cobalt_get_u_timespec(struct timespec64 *dst,
+			const struct __user_old_timespec __user *src)
+{
+	struct __user_old_timespec u_ts;
+	int ret;
+
+	ret = cobalt_copy_from_user(&u_ts, src, sizeof(u_ts));
+	if (ret)
+		return ret;
+
+	dst->tv_sec = u_ts.tv_sec;
+	dst->tv_nsec = u_ts.tv_nsec;
+
+	return 0;
+}
+
+static inline int cobalt_put_u_timespec(
+	struct __user_old_timespec __user *dst,
+	const struct timespec64 *src)
+{
+	struct __user_old_timespec u_ts;
+	int ret;
+
+	u_ts.tv_sec = src->tv_sec;
+	u_ts.tv_nsec = src->tv_nsec;
+
+	ret = cobalt_copy_to_user(dst, &u_ts, sizeof(*dst));
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+#endif
+
  /* 32bit syscall emulation */
  #define __COBALT_COMPAT_BIT	0x1
  /* 32bit syscall emulation - extended form */
kernel/cobalt/ipipe/clock.c +1 -1
index 606c6bf8c..d40b0ac89 100644
@@ -67,7 +67,7 @@ EXPORT_SYMBOL_GPL(xnclock_core_ticks_to_ns);
  EXPORT_SYMBOL_GPL(xnclock_core_ticks_to_ns_rounded);
  EXPORT_SYMBOL_GPL(xnclock_core_ns_to_ticks);
 
-int pipeline_get_host_time(struct timespec *tp)
+int pipeline_get_host_time(struct timespec64 *tp)
  {
  #ifdef CONFIG_IPIPE_HAVE_HOSTRT
  	struct xnvdso_hostrt_data *hostrt_data;
kernel/cobalt/posix/clock.c +9 -9
index e957dd956..4a3365d2a 100644
@@ -51,7 +51,7 @@ DECLARE_BITMAP(cobalt_clock_extids, COBALT_MAX_EXTCLOCKS);
  	__val;							\
  })
 
-int __cobalt_clock_getres(clockid_t clock_id, struct timespec *ts)
+int __cobalt_clock_getres(clockid_t clock_id, struct timespec64 *ts)
  {
  	xnticks_t ns;
  	int ret;
@@ -75,16 +75,16 @@ int __cobalt_clock_getres(clockid_t clock_id, struct timespec *ts)
  }
 
  COBALT_SYSCALL(clock_getres, current,
-	       (clockid_t clock_id, struct timespec __user *u_ts))
+	       (clockid_t clock_id, struct __user_old_timespec __user *u_ts))
  {
-	struct timespec ts;
+	struct timespec64 ts;
  	int ret;
 
  	ret = __cobalt_clock_getres(clock_id, &ts);
  	if (ret)
  		return ret;
 
-	if (u_ts && cobalt_copy_to_user(u_ts, &ts, sizeof(ts)))
+	if (u_ts && cobalt_put_u_timespec(u_ts, &ts))
  		return -EFAULT;
 
  	trace_cobalt_clock_getres(clock_id, &ts);
@@ -92,7 +92,7 @@ COBALT_SYSCALL(clock_getres, current,
  	return 0;
  }
 
-int __cobalt_clock_gettime(clockid_t clock_id, struct timespec *ts)
+int __cobalt_clock_gettime(clockid_t clock_id, struct timespec64 *ts)
  {
  	xnticks_t ns;
  	int ret;
@@ -122,16 +122,16 @@ int __cobalt_clock_gettime(clockid_t clock_id, struct timespec *ts)
  }
 
  COBALT_SYSCALL(clock_gettime, current,
-	       (clockid_t clock_id, struct timespec __user *u_ts))
+	       (clockid_t clock_id, struct __user_old_timespec __user *u_ts))
  {
-	struct timespec ts;
+	struct timespec64 ts;
  	int ret;
 
  	ret = __cobalt_clock_gettime(clock_id, &ts);
  	if (ret)
  		return ret;
 
-	if (cobalt_copy_to_user(u_ts, &ts, sizeof(*u_ts)))
+	if (cobalt_put_u_timespec(u_ts, &ts))
  		return -EFAULT;
 
  	trace_cobalt_clock_gettime(clock_id, &ts);
@@ -139,7 +139,7 @@ COBALT_SYSCALL(clock_gettime, current,
  	return 0;
  }
 
-int __cobalt_clock_settime(clockid_t clock_id, const struct timespec *ts)
+int __cobalt_clock_settime(clockid_t clock_id, const struct timespec64 *ts)
  {
  	int _ret, ret = 0;
  	xnticks_t now;

kernel/cobalt/posix/clock.c int __cobalt_clock_adjtime(clockid_t clock_id, struct timex *tx) · line 191

Quoted 5 lines
kernel/cobalt/posix/clock.c +1 -1
@@ -188,11 +188,11 @@ int __cobalt_clock_adjtime(clockid_t clock_id, struct timex *tx)
  }
 
  COBALT_SYSCALL(clock_settime, current,
-	       (clockid_t clock_id, const struct timespec __user *u_ts))
+	       (clockid_t clock_id, const struct __user_old_timespec __user *u_ts))

I planned to still use timespec as the argument, tv_sec is defined as long, 32bit long in 32bit system, 64bit long in 64bit system, use timespec64 in implementation.

Quoted 1,060 lines
kernel/cobalt/posix/clock.c +9 -9
  {
-	struct timespec ts;
+	struct timespec64 ts;
 
-	if (cobalt_copy_from_user(&ts, u_ts, sizeof(ts)))
+	if (cobalt_get_u_timespec(&ts, u_ts))
  		return -EFAULT;
 
  	return __cobalt_clock_settime(clock_id, &ts);
@@ -215,8 +215,8 @@ COBALT_SYSCALL(clock_adjtime, current,
  }
 
  int __cobalt_clock_nanosleep(clockid_t clock_id, int flags,
-			     const struct timespec *rqt,
-			     struct timespec *rmt)
+			     const struct timespec64 *rqt,
+			     struct timespec64 *rmt)
  {
  	struct restart_block *restart;
  	struct xnthread *cur;
@@ -296,21 +296,21 @@ int __cobalt_clock_nanosleep(clockid_t clock_id, int flags,
 
  COBALT_SYSCALL(clock_nanosleep, primary,
  	       (clockid_t clock_id, int flags,
-		const struct timespec __user *u_rqt,
-		struct timespec __user *u_rmt))
+		const struct __user_old_timespec __user *u_rqt,
+		struct __user_old_timespec __user *u_rmt))
  {
-	struct timespec rqt, rmt, *rmtp = NULL;
+	struct timespec64 rqt, rmt, *rmtp = NULL;
  	int ret;
 
  	if (u_rmt)
  		rmtp = &rmt;
 
-	if (cobalt_copy_from_user(&rqt, u_rqt, sizeof(rqt)))
+	if (cobalt_get_u_timespec(&rqt, u_rqt))
  		return -EFAULT;
 
  	ret = __cobalt_clock_nanosleep(clock_id, flags, &rqt, rmtp);
  	if (ret == -EINTR && flags == 0 && rmtp) {
-		if (cobalt_copy_to_user(u_rmt, rmtp, sizeof(*u_rmt)))
+		if (cobalt_put_u_timespec(u_rmt, rmtp))
  			return -EFAULT;
  	}
 
kernel/cobalt/posix/clock.h +27 -12
index 7cb161df2..7e45fdcc6 100644
@@ -28,12 +28,27 @@
 
  struct xnclock;
 
-static inline void ns2ts(struct timespec *ts, xnticks_t nsecs)
+static inline void ns2ts(struct timespec64 *ts, xnticks_t nsecs)
  {
  	ts->tv_sec = xnclock_divrem_billion(nsecs, &ts->tv_nsec);
  }
 
-static inline xnticks_t ts2ns(const struct timespec *ts)
+static inline void u_ns2ts(struct __user_old_timespec *ts, xnticks_t nsecs)
+{
+	ts->tv_sec = xnclock_divrem_billion(nsecs, &ts->tv_nsec);
+}
+
+static inline xnticks_t ts2ns(const struct timespec64 *ts)
+{
+	xnticks_t nsecs = ts->tv_nsec;
+
+	if (ts->tv_sec)
+		nsecs += (xnticks_t)ts->tv_sec * ONE_BILLION;
+
+	return nsecs;
+}
+
+static inline xnticks_t u_ts2ns(const struct __user_old_timespec *ts)
  {
  	xnticks_t nsecs = ts->tv_nsec;
 
@@ -80,37 +95,37 @@ static inline int clock_flag(int flag, clockid_t clock_id)
  }
 
  int __cobalt_clock_getres(clockid_t clock_id,
-			  struct timespec *ts);
+			  struct timespec64 *ts);
 
  int __cobalt_clock_gettime(clockid_t clock_id,
-			   struct timespec *ts);
+			   struct timespec64 *ts);
 
  int __cobalt_clock_settime(clockid_t clock_id,
-			   const struct timespec *ts);
+			   const struct timespec64 *ts);
 
  int __cobalt_clock_adjtime(clockid_t clock_id,
  			   struct timex *tx);
 
  int __cobalt_clock_nanosleep(clockid_t clock_id, int flags,
-			     const struct timespec *rqt,
-			     struct timespec *rmt);
+			     const struct timespec64 *rqt,
+			     struct timespec64 *rmt);
 
  COBALT_SYSCALL_DECL(clock_getres,
-		    (clockid_t clock_id, struct timespec __user *u_ts));
+		    (clockid_t clock_id, struct __user_old_timespec __user *u_ts));
 
  COBALT_SYSCALL_DECL(clock_gettime,
-		    (clockid_t clock_id, struct timespec __user *u_ts));
+		    (clockid_t clock_id, struct __user_old_timespec __user *u_ts));
 
  COBALT_SYSCALL_DECL(clock_settime,
-		    (clockid_t clock_id, const struct timespec __user *u_ts));
+		    (clockid_t clock_id, const struct __user_old_timespec __user *u_ts));
 
  COBALT_SYSCALL_DECL(clock_adjtime,
  		    (clockid_t clock_id, struct timex __user *u_tx));
 
  COBALT_SYSCALL_DECL(clock_nanosleep,
  		    (clockid_t clock_id, int flags,
-		     const struct timespec __user *u_rqt,
-		     struct timespec __user *u_rmt));
+		     const struct __user_old_timespec __user *u_rqt,
+		     struct __user_old_timespec __user *u_rmt));
 
  int cobalt_clock_register(struct xnclock *clock,
  			  const cpumask_t *affinity,
kernel/cobalt/posix/compat.c +32 -14
index 2ffc0dbdf..185295082 100644
@@ -22,23 +22,41 @@
  #include <asm/xenomai/syscall.h>
  #include <xenomai/posix/mqueue.h>
 
-int sys32_get_timespec(struct timespec *ts,
-		       const struct compat_timespec __user *cts)
+int sys32_get_timespec(struct timespec64 *ts,
+		       const struct compat_timespec __user *u_cts)
  {
-	return (cts == NULL ||
-		!access_rok(cts, sizeof(*cts)) ||
-		__xn_get_user(ts->tv_sec, &cts->tv_sec) ||
-		__xn_get_user(ts->tv_nsec, &cts->tv_nsec)) ? -EFAULT : 0;
+	struct compat_timespec cts;
+
+	if (u_cts == NULL || !access_rok(u_cts, sizeof(*u_cts)))
+		return -EFAULT;
+
+	if (__xn_get_user(cts.tv_sec, &u_cts->tv_sec) ||
+		__xn_get_user(cts.tv_nsec, &u_cts->tv_nsec))
+		return -EFAULT;
+
+	ts->tv_sec = cts.tv_sec;
+	ts->tv_nsec = cts.tv_nsec;
+
+	return 0;
  }
  EXPORT_SYMBOL_GPL(sys32_get_timespec);
 
-int sys32_put_timespec(struct compat_timespec __user *cts,
-		       const struct timespec *ts)
+int sys32_put_timespec(struct compat_timespec __user *u_cts,
+		       const struct timespec64 *ts)
  {
-	return (cts == NULL ||
-		!access_wok(cts, sizeof(*cts)) ||
-		__xn_put_user(ts->tv_sec, &cts->tv_sec) ||
-		__xn_put_user(ts->tv_nsec, &cts->tv_nsec)) ? -EFAULT : 0;
+	struct compat_timespec cts;
+
+	if (u_cts == NULL || !access_wok(u_cts, sizeof(*u_cts)))
+		return -EFAULT;
+
+	cts.tv_sec = ts->tv_sec;
+	cts.tv_nsec = ts->tv_nsec;
+
+	if (__xn_put_user(cts.tv_sec, &u_cts->tv_sec) ||
+	    __xn_put_user(cts.tv_nsec, &u_cts->tv_nsec))
+		return -EFAULT;
+
+	return 0;
  }
  EXPORT_SYMBOL_GPL(sys32_put_timespec);
 
@@ -478,7 +496,7 @@ int sys32_get_iovec(struct iovec *iov,
  	const struct compat_iovec __user *p;
  	struct compat_iovec ciov;
  	int ret, n;
-	
+
  	for (n = 0, p = u_ciov; n < ciovlen; n++, p++) {
  		ret = cobalt_copy_from_user(&ciov, p, sizeof(ciov));
  		if (ret)
@@ -498,7 +516,7 @@ int sys32_put_iovec(struct compat_iovec __user *u_ciov,
  	struct compat_iovec __user *p;
  	struct compat_iovec ciov;
  	int ret, n;
-	
+
  	for (n = 0, p = u_ciov; n < iovlen; n++, p++) {
  		ciov.iov_base = ptr_to_compat(iov[n].iov_base);
  		ciov.iov_len = iov[n].iov_len;
kernel/cobalt/posix/cond.c +5 -6
index 35a8f7176..bb18fe316 100644
@@ -270,25 +270,24 @@ struct us_cond_data {
  	int err;
  };
 
-static inline int cond_fetch_timeout(struct timespec *ts,
+static inline int cond_fetch_timeout(struct timespec64 *ts,
  				     const void __user *u_ts)
  {
-	return u_ts == NULL ? -EFAULT :
-		cobalt_copy_from_user(ts, u_ts, sizeof(*ts));
+	return u_ts == NULL ? -EFAULT :	cobalt_get_u_timespec(ts, u_ts);
  }
 
  int __cobalt_cond_wait_prologue(struct cobalt_cond_shadow __user *u_cnd,
  				struct cobalt_mutex_shadow __user *u_mx,
  				int *u_err,
  				void __user *u_ts,
-				int (*fetch_timeout)(struct timespec *ts,
+				int (*fetch_timeout)(struct timespec64 *ts,
  						     const void __user *u_ts))
  {
  	struct xnthread *cur = xnthread_current();
  	struct cobalt_cond *cond;
  	struct cobalt_mutex *mx;
  	struct us_cond_data d;
-	struct timespec ts;
+	struct timespec64 ts;
  	xnhandle_t handle;
  	int err, perr = 0;
  	__u32 offset;
@@ -349,7 +348,7 @@ COBALT_SYSCALL(cond_wait_prologue, nonrestartable,
  		struct cobalt_mutex_shadow __user *u_mx,
  		int *u_err,
  		unsigned int timed,
-		struct timespec __user *u_ts))
+		struct __user_old_timespec __user *u_ts))
  {
  	return __cobalt_cond_wait_prologue(u_cnd, u_mx, u_err, u_ts,
  					   timed ? cond_fetch_timeout : NULL);
kernel/cobalt/posix/cond.h +2 -2
index c7a9be451..7bec2a649 100644
@@ -43,7 +43,7 @@ int __cobalt_cond_wait_prologue(struct cobalt_cond_shadow __user *u_cnd,
  				struct cobalt_mutex_shadow __user *u_mx,
  				int *u_err,
  				void __user *u_ts,
-				int (*fetch_timeout)(struct timespec *ts,
+				int (*fetch_timeout)(struct timespec64 *ts,
  						     const void __user *u_ts));
  COBALT_SYSCALL_DECL(cond_init,
  		    (struct cobalt_cond_shadow __user *u_cnd,
@@ -57,7 +57,7 @@ COBALT_SYSCALL_DECL(cond_wait_prologue,
  		     struct cobalt_mutex_shadow __user *u_mx,
  		     int *u_err,
  		     unsigned int timed,
-		     struct timespec __user *u_ts));
+		     struct __user_old_timespec __user *u_ts));
 
  COBALT_SYSCALL_DECL(cond_wait_epilogue,
  		    (struct cobalt_cond_shadow __user *u_cnd,
kernel/cobalt/posix/event.c +4 -4
index c566a09e3..3712154f5 100644
@@ -104,7 +104,7 @@ COBALT_SYSCALL(event_init, current,
  int __cobalt_event_wait(struct cobalt_event_shadow __user *u_event,
  			unsigned int bits,
  			unsigned int __user *u_bits_r,
-			int mode, const struct timespec *ts)
+			int mode, const struct timespec64 *ts)
  {
  	unsigned int rbits = 0, testval;
  	xnticks_t timeout = XN_INFINITE;
@@ -193,14 +193,14 @@ COBALT_SYSCALL(event_wait, primary,
  	       (struct cobalt_event_shadow __user *u_event,
  		unsigned int bits,
  		unsigned int __user *u_bits_r,
-		int mode, const struct timespec __user *u_ts))
+		int mode, const struct __user_old_timespec __user *u_ts))
  {
-	struct timespec ts, *tsp = NULL;
+	struct timespec64 ts, *tsp = NULL;
  	int ret;
 
  	if (u_ts) {
  		tsp = &ts;
-		ret = cobalt_copy_from_user(&ts, u_ts, sizeof(ts));
+		ret = cobalt_get_u_timespec(&ts, u_ts);
  		if (ret)
  			return ret;
  	}
kernel/cobalt/posix/event.h +2 -2
index 28d4516ac..ef592f72c 100644
@@ -39,7 +39,7 @@ struct cobalt_event {
  int __cobalt_event_wait(struct cobalt_event_shadow __user *u_event,
  			unsigned int bits,
  			unsigned int __user *u_bits_r,
-			int mode, const struct timespec *ts);
+			int mode, const struct timespec64 *ts);
 
  COBALT_SYSCALL_DECL(event_init,
  		    (struct cobalt_event_shadow __user *u_evtsh,
@@ -51,7 +51,7 @@ COBALT_SYSCALL_DECL(event_wait,
  		     unsigned int bits,
  		     unsigned int __user *u_bits_r,
  		     int mode,
-		     const struct timespec __user *u_ts));
+		     const struct __user_old_timespec __user *u_ts));
 
  COBALT_SYSCALL_DECL(event_sync,
  		    (struct cobalt_event_shadow __user *u_evtsh));
kernel/cobalt/posix/io.c +3 -3
index e9908feeb..97a1f6afc 100644
@@ -93,10 +93,10 @@ COBALT_SYSCALL(recvmsg, handover,
  	return cobalt_copy_to_user(umsg, &m, sizeof(*umsg)) ?: ret;
  }
 
-static int get_timespec(struct timespec *ts,
+static int get_timespec(struct timespec64 *ts,
  			const void __user *u_ts)
  {
-	return cobalt_copy_from_user(ts, u_ts, sizeof(*ts));
+	return cobalt_get_u_timespec(ts, u_ts);
  }
 
  static int get_mmsg(struct mmsghdr *mmsg, void __user *u_mmsg)
@@ -114,7 +114,7 @@ static int put_mmsg(void __user **u_mmsg_p, const struct mmsghdr *mmsg)
 
  COBALT_SYSCALL(recvmmsg, primary,
  	       (int fd, struct mmsghdr __user *u_msgvec, unsigned int vlen,
-		unsigned int flags, struct timespec *u_timeout))
+		unsigned int flags, struct __user_old_timespec __user *u_timeout))
  {
  	return __rtdm_fd_recvmmsg(fd, u_msgvec, vlen, flags, u_timeout,
  				  get_mmsg, put_mmsg, get_timespec);
kernel/cobalt/posix/io.h +1 -1
index 82187cc7b..e4f7d4d51 100644
@@ -53,7 +53,7 @@ COBALT_SYSCALL_DECL(recvmsg,
 
  COBALT_SYSCALL_DECL(recvmmsg,
  		    (int fd, struct mmsghdr __user *u_msgvec, unsigned int vlen,
-		     unsigned int flags, struct timespec *u_timeout));
+		     unsigned int flags, struct __user_old_timespec __user *u_timeout));
 
  COBALT_SYSCALL_DECL(sendmsg,
  		    (int fd, struct user_msghdr __user *umsg, int flags));
kernel/cobalt/posix/monitor.c +4 -4
index 5237545be..b907e0050 100644
@@ -203,7 +203,7 @@ drain:
  }
 
  int __cobalt_monitor_wait(struct cobalt_monitor_shadow __user *u_mon,
-			  int event, const struct timespec *ts,
+			  int event, const struct timespec64 *ts,
  			  int __user *u_ret)
  {
  	struct cobalt_thread *curr = cobalt_current_thread();
@@ -291,15 +291,15 @@ out:
 
  COBALT_SYSCALL(monitor_wait, nonrestartable,
  	       (struct cobalt_monitor_shadow __user *u_mon,
-	       int event, const struct timespec __user *u_ts,
+	       int event, const struct __user_old_timespec __user *u_ts,
  	       int __user *u_ret))
  {
-	struct timespec ts, *tsp = NULL;
+	struct timespec64 ts, *tsp = NULL;
  	int ret;
 
  	if (u_ts) {
  		tsp = &ts;
-		ret = cobalt_copy_from_user(&ts, u_ts, sizeof(ts));
+		ret = cobalt_get_u_timespec(&ts, u_ts);
  		if (ret)
  			return ret;
  	}
kernel/cobalt/posix/monitor.h +2 -2
index 8b321aaec..d4a4aa24e 100644
@@ -39,7 +39,7 @@ struct cobalt_monitor {
  };
 
  int __cobalt_monitor_wait(struct cobalt_monitor_shadow __user *u_mon,
-			  int event, const struct timespec *ts,
+			  int event, const struct timespec64 *ts,
  			  int __user *u_ret);
 
  COBALT_SYSCALL_DECL(monitor_init,
@@ -58,7 +58,7 @@ COBALT_SYSCALL_DECL(monitor_exit,
 
  COBALT_SYSCALL_DECL(monitor_wait,
  		    (struct cobalt_monitor_shadow __user *u_monsh,
-		     int event, const struct timespec __user *u_ts,
+		     int event, const struct __user_old_timespec __user *u_ts,
  		     int __user *u_ret));
 
  COBALT_SYSCALL_DECL(monitor_destroy,
kernel/cobalt/posix/mqueue.c +9 -9
index cd1cf3ce8..b2cf92e43 100644
@@ -468,13 +468,13 @@ mq_tryrcv(struct cobalt_mqd *mqd, size_t len)
  static struct cobalt_msg *
  mq_timedsend_inner(struct cobalt_mqd *mqd,
  		   size_t len, const void __user *u_ts,
-		   int (*fetch_timeout)(struct timespec *ts,
+		   int (*fetch_timeout)(struct timespec64 *ts,
  					const void __user *u_ts))
  {
  	struct cobalt_mqwait_context mwc;
  	struct cobalt_msg *msg;
  	struct cobalt_mq *mq;
-	struct timespec ts;
+	struct timespec64 ts;
  	xntmode_t tmode;
  	xnticks_t to;
  	spl_t s;
@@ -597,13 +597,13 @@ static struct cobalt_msg *
  mq_timedrcv_inner(struct cobalt_mqd *mqd,
  		  size_t len,
  		  const void __user *u_ts,
-		  int (*fetch_timeout)(struct timespec *ts,
+		  int (*fetch_timeout)(struct timespec64 *ts,
  				       const void __user *u_ts))
  {
  	struct cobalt_mqwait_context mwc;
  	struct cobalt_msg *msg;
  	struct cobalt_mq *mq;
-	struct timespec ts;
+	struct timespec64 ts;
  	xntmode_t tmode;
  	xnticks_t to;
  	spl_t s;
@@ -880,7 +880,7 @@ COBALT_SYSCALL(mq_getattr, current,
  	return cobalt_copy_to_user(u_attr, &attr, sizeof(attr));
  }
 
-static inline int mq_fetch_timeout(struct timespec *ts,
+static inline int mq_fetch_timeout(struct timespec64 *ts,
  				   const void __user *u_ts)
  {
  	return u_ts == NULL ? -EFAULT :
@@ -889,7 +889,7 @@ static inline int mq_fetch_timeout(struct timespec *ts,
 
  int __cobalt_mq_timedsend(mqd_t uqd, const void __user *u_buf, size_t len,
  			  unsigned int prio, const void __user *u_ts,
-			  int (*fetch_timeout)(struct timespec *ts,
+			  int (*fetch_timeout)(struct timespec64 *ts,
  					       const void __user *u_ts))
  {
  	struct cobalt_msg *msg;
@@ -933,7 +933,7 @@ out:
 
  COBALT_SYSCALL(mq_timedsend, primary,
  	       (mqd_t uqd, const void __user *u_buf, size_t len,
-		unsigned int prio, const struct timespec __user *u_ts))
+		unsigned int prio, const struct __user_old_timespec __user *u_ts))
  {
  	return __cobalt_mq_timedsend(uqd, u_buf, len, prio,
  				     u_ts, u_ts ? mq_fetch_timeout : NULL);
@@ -943,7 +943,7 @@ int __cobalt_mq_timedreceive(mqd_t uqd, void __user *u_buf,
  			     ssize_t *lenp,
  			     unsigned int __user *u_prio,
  			     const void __user *u_ts,
-			     int (*fetch_timeout)(struct timespec *ts,
+			     int (*fetch_timeout)(struct timespec64 *ts,
  						  const void __user *u_ts))
  {
  	struct cobalt_mqd *mqd;
@@ -994,7 +994,7 @@ COBALT_SYSCALL(mq_timedreceive, primary,
  	       (mqd_t uqd, void __user *u_buf,
  		ssize_t __user *u_len,
  		unsigned int __user *u_prio,
-		const struct timespec __user *u_ts))
+		const struct __user_old_timespec __user *u_ts))
  {
  	ssize_t len;
  	int ret;
kernel/cobalt/posix/mqueue.h +4 -4
index acae2a424..d33220227 100644
@@ -37,14 +37,14 @@ int __cobalt_mq_getattr(mqd_t uqd, struct mq_attr *attr);
 
  int __cobalt_mq_timedsend(mqd_t uqd, const void __user *u_buf, size_t len,
  			  unsigned int prio, const void __user *u_ts,
-			  int (*fetch_timeout)(struct timespec *ts,
+			  int (*fetch_timeout)(struct timespec64 *ts,
  					       const void __user *u_ts));
 
  int __cobalt_mq_timedreceive(mqd_t uqd, void __user *u_buf,
  			     ssize_t *lenp,
  			     unsigned int __user *u_prio,
  			     const void __user *u_ts,
-			     int (*fetch_timeout)(struct timespec *ts,
+			     int (*fetch_timeout)(struct timespec64 *ts,
  						  const void __user *u_ts));
 
  int __cobalt_mq_notify(mqd_t fd, const struct sigevent *evp);
@@ -61,12 +61,12 @@ COBALT_SYSCALL_DECL(mq_getattr, (mqd_t uqd, struct mq_attr __user *u_attr));
 
  COBALT_SYSCALL_DECL(mq_timedsend,
  		    (mqd_t uqd, const void __user *u_buf, size_t len,
-		     unsigned int prio, const struct timespec __user *u_ts));
+		     unsigned int prio, const struct __user_old_timespec __user *u_ts));
 
  COBALT_SYSCALL_DECL(mq_timedreceive,
  		    (mqd_t uqd, void __user *u_buf, ssize_t __user *u_len,
  		     unsigned int __user *u_prio,
-		     const struct timespec __user *u_ts));
+		     const struct __user_old_timespec __user *u_ts));
 
  COBALT_SYSCALL_DECL(mq_notify,
  		    (mqd_t fd, const struct sigevent *__user evp));
kernel/cobalt/posix/mutex.c +5 -5
index 79260b544..d43a747b3 100644
@@ -71,7 +71,7 @@ static int cobalt_mutex_init_inner(struct cobalt_mutex_shadow *shadow,
  /* must be called with nklock locked, interrupts off. */
  int __cobalt_mutex_acquire_unchecked(struct xnthread *cur,
  				     struct cobalt_mutex *mutex,
-				     const struct timespec *ts)
+				     const struct timespec64 *ts)
  {
  	int ret;
 
@@ -134,11 +134,11 @@ int cobalt_mutex_release(struct xnthread *curr,
 
  int __cobalt_mutex_timedlock_break(struct cobalt_mutex_shadow __user *u_mx,
  				   const void __user *u_ts,
-				   int (*fetch_timeout)(struct timespec *ts,
+				   int (*fetch_timeout)(struct timespec64 *ts,
  							const void __user *u_ts))
  {
  	struct xnthread *curr = xnthread_current();
-	struct timespec ts, *tsp = NULL;
+	struct timespec64 ts, *tsp = NULL;
  	struct cobalt_mutex *mutex;
  	xnhandle_t handle;
  	spl_t s;
@@ -346,7 +346,7 @@ COBALT_SYSCALL(mutex_lock, primary,
  	return __cobalt_mutex_timedlock_break(u_mx, NULL, NULL);
  }
 
-static inline int mutex_fetch_timeout(struct timespec *ts,
+static inline int mutex_fetch_timeout(struct timespec64 *ts,
  				      const void __user *u_ts)
  {
  	return u_ts == NULL ? -EFAULT :
@@ -355,7 +355,7 @@ static inline int mutex_fetch_timeout(struct timespec *ts,
 
  COBALT_SYSCALL(mutex_timedlock, primary,
  	       (struct cobalt_mutex_shadow __user *u_mx,
-		const struct timespec __user *u_ts))
+		const struct __user_old_timespec __user *u_ts))
  {
  	return __cobalt_mutex_timedlock_break(u_mx, u_ts, mutex_fetch_timeout);
  }
kernel/cobalt/posix/mutex.h +3 -3
index ac1c50291..d76f2a9ea 100644
@@ -37,12 +37,12 @@ struct cobalt_mutex {
 
  int __cobalt_mutex_timedlock_break(struct cobalt_mutex_shadow __user *u_mx,
  				   const void __user *u_ts,
-				   int (*fetch_timeout)(struct timespec *ts,
+				   int (*fetch_timeout)(struct timespec64 *ts,
  							const void __user *u_ts));
 
  int __cobalt_mutex_acquire_unchecked(struct xnthread *cur,
  				     struct cobalt_mutex *mutex,
-				     const struct timespec *ts);
+				     const struct timespec64 *ts);
 
  COBALT_SYSCALL_DECL(mutex_check_init,
  		    (struct cobalt_mutex_shadow __user *u_mx));
@@ -62,7 +62,7 @@ COBALT_SYSCALL_DECL(mutex_lock,
 
  COBALT_SYSCALL_DECL(mutex_timedlock,
  		    (struct cobalt_mutex_shadow __user *u_mx,
-		     const struct timespec __user *u_ts));
+		     const struct __user_old_timespec __user *u_ts));
 
  COBALT_SYSCALL_DECL(mutex_unlock,
  		    (struct cobalt_mutex_shadow __user *u_mx));
kernel/cobalt/posix/sched.c +8 -8
index 798a172d7..4fd9c2b46 100644
@@ -73,7 +73,7 @@ cobalt_sched_policy_param(union xnsched_policy_param *param,
  		break;
  	case SCHED_RR:
  		/* if unspecified, use current one. */
-		tslice = ts2ns(&param_ex->sched_rr_quantum);
+		tslice = u_ts2ns(&param_ex->sched_rr_quantum);
  		if (tslice == XN_INFINITE && tslice_r)
  			tslice = *tslice_r;
  		/* fallthrough */
@@ -92,8 +92,8 @@ cobalt_sched_policy_param(union xnsched_policy_param *param,
  		param->pss.normal_prio = param_ex->sched_priority;
  		param->pss.low_prio = param_ex->sched_ss_low_priority;
  		param->pss.current_prio = param->pss.normal_prio;
-		param->pss.init_budget = ts2ns(&param_ex->sched_ss_init_budget);
-		param->pss.repl_period = ts2ns(&param_ex->sched_ss_repl_period);
+		param->pss.init_budget = u_ts2ns(&param_ex->sched_ss_init_budget);
+		param->pss.repl_period = u_ts2ns(&param_ex->sched_ss_repl_period);
  		param->pss.max_repl = param_ex->sched_ss_max_repl;
  		sched_class = &xnsched_class_sporadic;
  		break;
@@ -280,11 +280,11 @@ int set_tp_config(int cpu, union sched_config *config, size_t len)
  		 * be defined using windows assigned to the pseudo
  		 * partition #-1.
  		 */
-		offset = ts2ns(&p->offset);
+		offset = u_ts2ns(&p->offset);
  		if (offset != next_offset)
  			goto cleanup_and_fail;
 
-		duration = ts2ns(&p->duration);
+		duration = u_ts2ns(&p->duration);
  		if (duration <= 0)
  			goto cleanup_and_fail;
 
@@ -357,11 +357,11 @@ ssize_t get_tp_config(int cpu, void __user *u_config, size_t len,
  	config->tp.nr_windows = gps->pwin_nr;
  	for (n = 0, pp = p = config->tp.windows, pw = w = gps->pwins;
  	     n < gps->pwin_nr; pp = p, p++, pw = w, w++, n++) {
-		ns2ts(&p->offset, w->w_offset);
-		ns2ts(&pp->duration, w->w_offset - pw->w_offset);
+		u_ns2ts(&p->offset, w->w_offset);
+		u_ns2ts(&pp->duration, w->w_offset - pw->w_offset);
  		p->ptid = w->w_part;
  	}
-	ns2ts(&pp->duration, gps->tf_duration - pw->w_offset);
+	u_ns2ts(&pp->duration, gps->tf_duration - pw->w_offset);
  	ret = put_config(SCHED_TP, u_config, len, config, elen);
  	xnfree(config);
  out:
kernel/cobalt/posix/sem.c +4 -4
index 05a861dfe..467a9b7dd 100644
@@ -267,7 +267,7 @@ out:
  	return ret;
  }
 
-static inline int sem_fetch_timeout(struct timespec *ts,
+static inline int sem_fetch_timeout(struct timespec64 *ts,
  				    const void __user *u_ts)
  {
  	return u_ts == NULL ? -EFAULT :
@@ -276,10 +276,10 @@ static inline int sem_fetch_timeout(struct timespec *ts,
 
  int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem,
  			   const void __user *u_ts,
-			   int (*fetch_timeout)(struct timespec *ts,
+			   int (*fetch_timeout)(struct timespec64 *ts,
  						const void __user *u_ts))
  {
-	struct timespec ts = { .tv_sec = 0, .tv_nsec = 0 };
+	struct timespec64 ts = { .tv_sec = 0, .tv_nsec = 0 };
  	int pull_ts = 1, ret, info;
  	struct cobalt_sem *sem;
  	xnhandle_t handle;
@@ -434,7 +434,7 @@ COBALT_SYSCALL(sem_wait, primary,
 
  COBALT_SYSCALL(sem_timedwait, primary,
  	       (struct cobalt_sem_shadow __user *u_sem,
-		struct timespec __user *u_ts))
+		struct __user_old_timespec __user *u_ts))
  {
  	return __cobalt_sem_timedwait(u_sem, u_ts, sem_fetch_timeout);
  }
kernel/cobalt/posix/sem.h +2 -2
index 17238078e..d17299495 100644
@@ -65,7 +65,7 @@ __cobalt_sem_open(struct cobalt_sem_shadow __user *usm,
 
  int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem,
  			   const void __user *u_ts,
-			   int (*fetch_timeout)(struct timespec *ts,
+			   int (*fetch_timeout)(struct timespec64 *ts,
  						const void __user *u_ts));
 
  int __cobalt_sem_destroy(xnhandle_t handle);
@@ -91,7 +91,7 @@ COBALT_SYSCALL_DECL(sem_wait,
 
  COBALT_SYSCALL_DECL(sem_timedwait,
  		    (struct cobalt_sem_shadow __user *u_sem,
-		     struct timespec __user *u_ts));
+		     struct __user_old_timespec __user *u_ts));
 
  COBALT_SYSCALL_DECL(sem_trywait,
  		    (struct cobalt_sem_shadow __user *u_sem));
kernel/cobalt/posix/signal.c +3 -3
index 862a644c0..0b43b5fcf 100644
@@ -407,7 +407,7 @@ COBALT_SYSCALL(sigwait, primary,
  }
 
  int __cobalt_sigtimedwait(sigset_t *set,
-			  const struct timespec *timeout,
+			  const struct timespec64 *timeout,
  			  void __user *u_si,
  			  bool compat)
  {
@@ -426,9 +426,9 @@ int __cobalt_sigtimedwait(sigset_t *set,
  COBALT_SYSCALL(sigtimedwait, nonrestartable,
  	       (const sigset_t __user *u_set,
  		struct siginfo __user *u_si,
-		const struct timespec __user *u_timeout))
+		const struct __user_old_timespec __user *u_timeout))
  {
-	struct timespec timeout;
+	struct timespec64 timeout;
  	sigset_t set;
 
  	if (cobalt_copy_from_user(&set, u_set, sizeof(set)))
kernel/cobalt/posix/signal.h +2 -2
index 7a0b4b22b..fc26ad065 100644
@@ -59,7 +59,7 @@ void cobalt_copy_siginfo(int code,
  int __cobalt_sigwait(sigset_t *set);
 
  int __cobalt_sigtimedwait(sigset_t *set,
-			  const struct timespec *timeout,
+			  const struct timespec64 *timeout,
  			  void __user *u_si,
  			  bool compat);
 
@@ -94,7 +94,7 @@ COBALT_SYSCALL_DECL(sigwait,
  COBALT_SYSCALL_DECL(sigtimedwait,
  		    (const sigset_t __user *u_set,
  		     struct siginfo __user *u_si,
-		     const struct timespec __user *u_timeout));
+		     const struct __user_old_timespec __user *u_timeout));
 
  COBALT_SYSCALL_DECL(sigwaitinfo,
  		    (const sigset_t __user *u_set,
kernel/cobalt/posix/syscall32.c +12 -14
index cb02dacd3..ae25a6e74 100644
@@ -97,7 +97,7 @@ COBALT_SYSCALL32emu(thread_setschedprio, conforming,
  	return cobalt_thread_setschedprio(pth, prio, u_winoff, u_promoted);
  }
 
-static inline int sys32_fetch_timeout(struct timespec *ts,
+static inline int sys32_fetch_timeout(struct timespec64 *ts,
  				      const void __user *u_ts)
  {
  	return u_ts == NULL ? -EFAULT :
@@ -133,7 +133,7 @@ COBALT_SYSCALL32emu(clock_getres, current,
  		    (clockid_t clock_id,
  		     struct compat_timespec __user *u_ts))
  {
-	struct timespec ts;
+	struct timespec64 ts;
  	int ret;
 
  	ret = __cobalt_clock_getres(clock_id, &ts);
@@ -147,7 +147,7 @@ COBALT_SYSCALL32emu(clock_gettime, current,
  		    (clockid_t clock_id,
  		     struct compat_timespec __user *u_ts))
  {
-	struct timespec ts;
+	struct timespec64 ts;
  	int ret;
 
  	ret = __cobalt_clock_gettime(clock_id, &ts);
@@ -161,7 +161,7 @@ COBALT_SYSCALL32emu(clock_settime, current,
  		    (clockid_t clock_id,
  		     const struct compat_timespec __user *u_ts))
  {
-	struct timespec ts;
+	struct timespec64 ts;
  	int ret;
 
  	ret = sys32_get_timespec(&ts, u_ts);
@@ -193,7 +193,7 @@ COBALT_SYSCALL32emu(clock_nanosleep, nonrestartable,
  		     const struct compat_timespec __user *u_rqt,
  		     struct compat_timespec __user *u_rmt))
  {
-	struct timespec rqt, rmt, *rmtp = NULL;
+	struct timespec64 rqt, rmt, *rmtp = NULL;
  	int ret;
 
  	if (u_rmt)
@@ -289,12 +289,10 @@ COBALT_SYSCALL32emu(mq_timedreceive, primary,
  	return ret ?: cobalt_copy_to_user(u_len, &clen, sizeof(*u_len));
  }
 
-static inline int mq_fetch_timeout(struct timespec *ts,
+static inline int mq_fetch_timeout(struct timespec64 *ts,
  				   const void __user *u_ts)
  {
-	return u_ts == NULL ? -EFAULT :
-		cobalt_copy_from_user(ts, u_ts, sizeof(*ts));
-
+	return u_ts == NULL ? -EFAULT : cobalt_get_u_timespec(ts, u_ts);
  }
 
  COBALT_SYSCALL32emu(mq_notify, primary,
@@ -610,7 +608,7 @@ COBALT_SYSCALL32emu(sigtimedwait, nonrestartable,
  		     struct compat_siginfo __user *u_si,
  		     const struct compat_timespec __user *u_timeout))
  {
-	struct timespec timeout;
+	struct timespec64 timeout;
  	sigset_t set;
  	int ret;
 
@@ -663,7 +661,7 @@ COBALT_SYSCALL32emu(monitor_wait, nonrestartable,
  		     int event, const struct compat_timespec __user *u_ts,
  		     int __user *u_ret))
  {
-	struct timespec ts, *tsp = NULL;
+	struct timespec64 ts, *tsp = NULL;
  	int ret;
 
  	if (u_ts) {
@@ -682,7 +680,7 @@ COBALT_SYSCALL32emu(event_wait, primary,
  		     unsigned int __user *u_bits_r,
  		     int mode, const struct compat_timespec __user *u_ts))
  {
-	struct timespec ts, *tsp = NULL;
+	struct timespec64 ts, *tsp = NULL;
  	int ret;
 
  	if (u_ts) {
@@ -810,7 +808,7 @@ COBALT_SYSCALL32emu(recvmsg, handover,
  	return sys32_put_msghdr(umsg, &m) ?: ret;
  }
 
-static int get_timespec32(struct timespec *ts,
+static int get_timespec32(struct timespec64 *ts,
  			  const void __user *u_ts)
  {
  	return sys32_get_timespec(ts, u_ts);
@@ -924,7 +922,7 @@ COBALT_SYSCALL32x(mq_timedreceive, primary,
  		  (mqd_t uqd, void __user *u_buf,
  		   compat_ssize_t __user *u_len,
  		   unsigned int __user *u_prio,
-		   const struct timespec __user *u_ts))
+		   const struct __user_old_timespec __user *u_ts))
  {
  	compat_ssize_t clen;
  	ssize_t len;
kernel/cobalt/posix/syscall32.h +1 -1
index eb3e4bd30..9da405229 100644
@@ -105,7 +105,7 @@ COBALT_SYSCALL32x_DECL(mq_timedreceive,
  		       (mqd_t uqd, void __user *u_buf,
  			compat_ssize_t __user *u_len,
  			unsigned int __user *u_prio,
-			const struct timespec __user *u_ts));
+			const struct __user_old_timespec __user *u_ts));
 
  COBALT_SYSCALL32emu_DECL(mq_notify,
  			 (mqd_t fd, const struct compat_sigevent *__user u_cev));
kernel/cobalt/posix/thread.c +3 -3
index bf9c08212..cdeb66d4f 100644
@@ -302,7 +302,7 @@ int __cobalt_thread_getschedparam_ex(struct cobalt_thread *thread,
 
  	if (base_class == &xnsched_class_rt) {
  		if (xnthread_test_state(base_thread, XNRRB)) {
-			ns2ts(&param_ex->sched_rr_quantum, base_thread->rrperiod);
+			u_ns2ts(&param_ex->sched_rr_quantum, base_thread->rrperiod);
  			*policy_r = SCHED_RR;
  		}
  		goto out;
@@ -318,8 +318,8 @@ int __cobalt_thread_getschedparam_ex(struct cobalt_thread *thread,
  #ifdef CONFIG_XENO_OPT_SCHED_SPORADIC
  	if (base_class == &xnsched_class_sporadic) {
  		param_ex->sched_ss_low_priority = base_thread->pss->param.low_prio;
-		ns2ts(&param_ex->sched_ss_repl_period, base_thread->pss->param.repl_period);
-		ns2ts(&param_ex->sched_ss_init_budget, base_thread->pss->param.init_budget);
+		u_ns2ts(&param_ex->sched_ss_repl_period, base_thread->pss->param.repl_period);
+		u_ns2ts(&param_ex->sched_ss_init_budget, base_thread->pss->param.init_budget);
  		param_ex->sched_ss_max_repl = base_thread->pss->param.max_repl;
  		goto out;
  	}
kernel/cobalt/rtdm/fd.c +2 -2
index 7956a8800..038247d54 100644
@@ -650,11 +650,11 @@ int __rtdm_fd_recvmmsg(int ufd, void __user *u_msgvec, unsigned int vlen,
  		       unsigned int flags, void __user *u_timeout,
  		       int (*get_mmsg)(struct mmsghdr *mmsg, void __user *u_mmsg),
  		       int (*put_mmsg)(void __user **u_mmsg_p, const struct mmsghdr *mmsg),
-		       int (*get_timespec)(struct timespec *ts, const void __user *u_ts))
+		       int (*get_timespec)(struct timespec64 *ts, const void __user *u_ts))
  {
  	struct cobalt_recvmmsg_timer rq;
  	xntmode_t tmode = XN_RELATIVE;
-	struct timespec ts = { 0 };
+	struct timespec64 ts = { 0 };
  	int ret = 0, datagrams = 0;
  	xnticks_t timeout = 0;
  	struct mmsghdr mmsg;
kernel/cobalt/trace/cobalt-posix.h +15 -15
index aa78efbc0..3a649a671 100644
@@ -30,7 +30,7 @@
  #include <xenomai/posix/event.h>
 
  #define __timespec_fields(__name)				\
-	__field(__kernel_time_t, tv_sec_##__name)		\
+	__field(time64_t, tv_sec_##__name)			\
  	__field(long, tv_nsec_##__name)
 
  #define __assign_timespec(__to, __from)				\
@@ -40,7 +40,7 @@
  	} while (0)
 
  #define __timespec_args(__name)					\
-	__entry->tv_sec_##__name, __entry->tv_nsec_##__name
+	(long long)__entry->tv_sec_##__name, __entry->tv_nsec_##__name
 
  #ifdef CONFIG_X86_X32
  #define __sc_x32(__name)	, { sc_cobalt_##__name + __COBALT_X32_BASE, "x32-" #__name }
@@ -729,7 +729,7 @@ TRACE_EVENT(cobalt_psem_unlink,
  );
 
  DECLARE_EVENT_CLASS(cobalt_clock_timespec,
-	TP_PROTO(clockid_t clk_id, const struct timespec *val),
+	TP_PROTO(clockid_t clk_id, const struct timespec64 *val),
  	TP_ARGS(clk_id, val),
 
  	TP_STRUCT__entry(
@@ -742,24 +742,24 @@ DECLARE_EVENT_CLASS(cobalt_clock_timespec,
  		__assign_timespec(val, val);
  	),
 
-	TP_printk("clock_id=%d timeval=(%ld.%09ld)",
+	TP_printk("clock_id=%d timeval=(%lld.%09ld)",
  		  __entry->clk_id,
  		  __timespec_args(val)
  	)
  );
 
  DEFINE_EVENT(cobalt_clock_timespec, cobalt_clock_getres,
-	TP_PROTO(clockid_t clk_id, const struct timespec *res),
+	TP_PROTO(clockid_t clk_id, const struct timespec64 *res),
  	TP_ARGS(clk_id, res)
  );
 
  DEFINE_EVENT(cobalt_clock_timespec, cobalt_clock_gettime,
-	TP_PROTO(clockid_t clk_id, const struct timespec *time),
+	TP_PROTO(clockid_t clk_id, const struct timespec64 *time),
  	TP_ARGS(clk_id, time)
  );
 
  DEFINE_EVENT(cobalt_clock_timespec, cobalt_clock_settime,
-	TP_PROTO(clockid_t clk_id, const struct timespec *time),
+	TP_PROTO(clockid_t clk_id, const struct timespec64 *time),
  	TP_ARGS(clk_id, time)
  );
 
@@ -788,7 +788,7 @@ TRACE_EVENT(cobalt_clock_adjtime,
  		      {TIMER_ABSTIME, "TIMER_ABSTIME"})
 
  TRACE_EVENT(cobalt_clock_nanosleep,
-	TP_PROTO(clockid_t clk_id, int flags, const struct timespec *time),
+	TP_PROTO(clockid_t clk_id, int flags, const struct timespec64 *time),
  	TP_ARGS(clk_id, flags, time),
 
  	TP_STRUCT__entry(
@@ -803,7 +803,7 @@ TRACE_EVENT(cobalt_clock_nanosleep,
  		__assign_timespec(time, time);
  	),
 
-	TP_printk("clock_id=%d flags=%#x(%s) rqt=(%ld.%09ld)",
+	TP_printk("clock_id=%d flags=%#x(%s) rqt=(%lld.%09ld)",
  		  __entry->clk_id,
  		  __entry->flags, cobalt_print_timer_flags(__entry->flags),
  		  __timespec_args(time)
@@ -875,7 +875,7 @@ TRACE_EVENT(cobalt_cond_destroy,
  TRACE_EVENT(cobalt_cond_timedwait,
  	TP_PROTO(const struct cobalt_cond_shadow __user *u_cnd,
  		 const struct cobalt_mutex_shadow __user *u_mx,
-		 const struct timespec *timeout),
+		 const struct timespec64 *timeout),
  	TP_ARGS(u_cnd, u_mx, timeout),
  	TP_STRUCT__entry(
  		__field(const struct cobalt_cond_shadow __user *, u_cnd)
@@ -887,7 +887,7 @@ TRACE_EVENT(cobalt_cond_timedwait,
  		__entry->u_mx = u_mx;
  		__assign_timespec(timeout, timeout);
  	),
-	TP_printk("cond=%p, mutex=%p, timeout=(%ld.%09ld)",
+	TP_printk("cond=%p, mutex=%p, timeout=(%lld.%09ld)",
  		  __entry->u_cnd, __entry->u_mx, __timespec_args(timeout))
  );
 
@@ -1001,7 +1001,7 @@ TRACE_EVENT(cobalt_mq_send,
 
  TRACE_EVENT(cobalt_mq_timedreceive,
  	TP_PROTO(mqd_t mqd, const void __user *u_buf, size_t len,
-		 const struct timespec *timeout),
+		 const struct timespec64 *timeout),
  	TP_ARGS(mqd, u_buf, len, timeout),
  	TP_STRUCT__entry(
  		__field(mqd_t, mqd)
@@ -1015,7 +1015,7 @@ TRACE_EVENT(cobalt_mq_timedreceive,
  		__entry->len = len;
  		__assign_timespec(timeout, timeout);
  	),
-	TP_printk("mqd=%d buf=%p len=%zu timeout=(%ld.%09ld)",
+	TP_printk("mqd=%d buf=%p len=%zu timeout=(%lld.%09ld)",
  		  __entry->mqd, __entry->u_buf, __entry->len,
  		  __timespec_args(timeout))
  );
@@ -1105,7 +1105,7 @@ TRACE_EVENT(cobalt_event_init,
  TRACE_EVENT(cobalt_event_timedwait,
  	TP_PROTO(const struct cobalt_event_shadow __user *u_event,
  		 unsigned long bits, int mode,
-		 const struct timespec *timeout),
+		 const struct timespec64 *timeout),
  	TP_ARGS(u_event, bits, mode, timeout),
  	TP_STRUCT__entry(
  		__field(const struct cobalt_event_shadow __user *, u_event)
@@ -1119,7 +1119,7 @@ TRACE_EVENT(cobalt_event_timedwait,
  		__entry->mode = mode;
  		__assign_timespec(timeout, timeout);
  	),
-	TP_printk("event=%p bits=%#lx mode=%#x(%s) timeout=(%ld.%09ld)",
+	TP_printk("event=%p bits=%#lx mode=%#x(%s) timeout=(%lld.%09ld)",
  		  __entry->u_event, __entry->bits, __entry->mode,
  		  cobalt_print_evmode(__entry->mode),
  		  __timespec_args(timeout))
#3 lore raw

Re: [PATCH 2/5] cobalt/kernel: y2038: convert struct timespec to timespec64

Quoted 4 lines · chensong via Xenomai
Quoted 4 lines

+/*
+ * Our representation of time at the kernel<->user interface boundary
+ * at the moment, until we have fully transitioned to a y2038-safe
+ * implementation in libcobalt.

Quoted 9 lines

include/cobalt/uapi/kernel/types.h static inline xnhandle_t xnhandle_get_id(xnhandle_t handle) · line 68

Quoted 5 lines

+ */

include/cobalt/uapi/kernel/types.h +4 -0
+struct __user_old_timespec {
+	long  tv_sec;
+	long  tv_nsec;
+};

why not use old_timespec32, which is timespec32 representation defined in include/linux/time32?

Using old_timespec32 in this context would mean that any time value received from userland by the core should be restricted to 32bit time_t, which is not what we want, at least for 64bit platforms:

include/vdso/time32.h:

struct old_timespec32 {
	old_time32_t	tv_sec;
	s32		tv_nsec;
};

__user_old_timespec conveys the notion that we are generically talking about "the old timespec type which has a y2038 problem"; this is not specifically about the legacy timespec type on 32bit machines.

Since v5.4-rc6, we do have __kernel_old_timespec though, which could have been used instead of __user_old_timespec:

include/uapi/asm-generic/posix_types.h:

typedef long __kernel_long_t;

include/uapi/linux/time_types.h:

struct __kernel_old_timespec {
	__kernel_long_t		tv_sec;		/* seconds */
	long			tv_nsec;	/* nanoseconds */
};

However, older (non-x86) toolchains do not define __kernel_old_timespec, so I went for adding __user_old_timespec to the Cobalt UAPI. This may be seen as a temporary option until stricter requirements on the minimum toolchain support for building Cobalt is decided.

Quoted 9 lines

kernel/cobalt/posix/clock.c int __cobalt_clock_adjtime(clockid_t clock_id, struct timex *tx) · line 191

Quoted 4 lines

COBALT_SYSCALL(clock_settime, current,

kernel/cobalt/posix/clock.c +1 -1
-	       (clockid_t clock_id, const struct timespec __user *u_ts))
+	       (clockid_t clock_id, const struct __user_old_timespec __user *u_ts))

I planned to still use timespec as the argument, tv_sec is defined as long, 32bit long in 32bit system, 64bit long in 64bit system, use timespec64 in implementation.

Keeping struct timespec for the argument does not seem the right thing to do, as this type has been phased out from recent kernels, precisely to stop spreading ambiguity wrt 32/64 bit time_t. It is only available from the UAPI section as a compat tweak for user code, not for kernel code.

What should be done wrt addressing the y2038 issue fully is beyond this patch series. __user_old_timespec is merely an annotation on the existing implementation in order to highlight the kernel<->user interface boundary, which may help in fully addressing y2038 later on.

Eventually, it should be decided whether a legacy timespec32 should still be supported for 32bit applications building in dual-time configurations (time32_t and time64_t), or single-time configuration should be the norm with user-space using time64_t exclusively. This is beyond the scope of this patch series to decide of the way to go.

Signature · 1 line
Philippe.
#4 lore raw

Re: [PATCH 2/5] cobalt/kernel: y2038: convert struct timespec to timespec64

Quoted 46 lines · Philippe Gerum
Quoted 4 lines · chensong via Xenomai
Quoted 4 lines

+/*
+ * Our representation of time at the kernel<->user interface boundary
+ * at the moment, until we have fully transitioned to a y2038-safe
+ * implementation in libcobalt.

Quoted 9 lines

include/cobalt/uapi/kernel/types.h static inline xnhandle_t xnhandle_get_id(xnhandle_t handle) · line 68

Quoted 5 lines

+ */

include/cobalt/uapi/kernel/types.h +4 -0
+struct __user_old_timespec {
+	long  tv_sec;
+	long  tv_nsec;
+};

why not use old_timespec32, which is timespec32 representation defined in include/linux/time32?

Using old_timespec32 in this context would mean that any time value received from userland by the core should be restricted to 32bit time_t, which is not what we want, at least for 64bit platforms:

include/vdso/time32.h:

struct old_timespec32 {
	old_time32_t	tv_sec;
	s32		tv_nsec;
};

__user_old_timespec conveys the notion that we are generically talking about "the old timespec type which has a y2038 problem"; this is not specifically about the legacy timespec type on 32bit machines.

Since v5.4-rc6, we do have __kernel_old_timespec though, which could have been used instead of __user_old_timespec:

include/uapi/asm-generic/posix_types.h:

typedef long __kernel_long_t;

include/uapi/linux/time_types.h:

struct __kernel_old_timespec {
	__kernel_long_t		tv_sec;		/* seconds */
	long			tv_nsec;	/* nanoseconds */
};
Quoted 4 lines

However, older (non-x86) toolchains do not define __kernel_old_timespec, so I went for adding __user_old_timespec to the Cobalt UAPI. This may be seen as a temporary option until stricter requirements on the minimum toolchain support for building Cobalt is decided.

what if we define __kernel_old_timespec in ./kernel/cobalt/include/asm-generic/xenomai/wrappers.h, like we always do. we don't have to introduce a new struct.

Quoted 10 lines
Quoted 10 lines

kernel/cobalt/posix/clock.c int __cobalt_clock_adjtime(clockid_t clock_id, struct timex *tx) · line 191

Quoted 5 lines

COBALT_SYSCALL(clock_settime, current,

kernel/cobalt/posix/clock.c +1 -1
-	       (clockid_t clock_id, const struct timespec __user *u_ts))
+	       (clockid_t clock_id, const struct __user_old_timespec __user *u_ts))

I planned to still use timespec as the argument, tv_sec is defined as long, 32bit long in 32bit system, 64bit long in 64bit system, use timespec64 in implementation.

same with above, like "__kernel_old_timespec __user *u_ts",.

Quoted 7 lines

Keeping struct timespec for the argument does not seem the right thing to do, as this type has been phased out from recent kernels, precisely to stop spreading ambiguity wrt 32/64 bit time_t. It is only available from the UAPI section as a compat tweak for user code, not for kernel code.

agree, in linux kernel, __kernel_timespec is specific for 64bit and old_timespec32 is specific for 32bit, clear. but we kind of need a blurry timespec, that's why we planed to keep timespec. __kernel_old_timespec looks like a good solution in this case.

Quoted 11 lines

What should be done wrt addressing the y2038 issue fully is beyond this patch series. __user_old_timespec is merely an annotation on the existing implementation in order to highlight the kernel<->user interface boundary, which may help in fully addressing y2038 later on.

Eventually, it should be decided whether a legacy timespec32 should still be supported for 32bit applications building in dual-time configurations (time32_t and time64_t), or single-time configuration should be the norm with user-space using time64_t exclusively. This is beyond the scope of this patch series to decide of the way to go.

#5 lore raw

Re: [PATCH 2/5] cobalt/kernel: y2038: convert struct timespec to timespec64

In reply to Philippe Gerum
Quoted 27 lines · Philippe Gerum via Xenomai
Quoted 4 lines · chensong via Xenomai
Quoted 4 lines

+/*
+ * Our representation of time at the kernel<->user interface boundary
+ * at the moment, until we have fully transitioned to a y2038-safe
+ * implementation in libcobalt.

Quoted 9 lines

include/cobalt/uapi/kernel/types.h static inline xnhandle_t xnhandle_get_id(xnhandle_t handle) · line 68

Quoted 5 lines

+ */

include/cobalt/uapi/kernel/types.h +4 -0
+struct __user_old_timespec {
+	long  tv_sec;
+	long  tv_nsec;
+};

why not use old_timespec32, which is timespec32 representation defined in include/linux/time32?

Using old_timespec32 in this context would mean that any time value received from userland by the core should be restricted to 32bit time_t, which is not what we want, at least for 64bit platforms:

include/vdso/time32.h:

struct old_timespec32 {
	old_time32_t	tv_sec;
	s32		tv_nsec;
};
Quoted 6 lines

__user_old_timespec conveys the notion that we are generically talking about "the old timespec type which has a y2038 problem"; this is not specifically about the legacy timespec type on 32bit machines.

Since v5.4-rc6, we do have __kernel_old_timespec though, which could have been used instead of __user_old_timespec:

According to my information (based on
https://elixir.bootlin.com/linux/v5.5-rc1/A/ident/__kernel_old_timespec
) this is available since v5.5-rc1.

Quoted 7 lines

include/uapi/asm-generic/posix_types.h:

typedef long __kernel_long_t;

include/uapi/linux/time_types.h:

Quoted 8 lines
struct __kernel_old_timespec {
	__kernel_long_t		tv_sec;		/* seconds */
	long			tv_nsec;	/* nanoseconds */
};

so I went for adding __user_old_timespec to the Cobalt UAPI. This may be seen as a temporary option until stricter requirements on the minimum toolchain support for building Cobalt is decided.

__kernel_old_timespec is part of the "common" Linux uapi, so not x86 specific. Could you explain the problem you know of (or even see) with some of the toolchains? Sounds strange...

Quoted 11 lines
Quoted 10 lines

kernel/cobalt/posix/clock.c int __cobalt_clock_adjtime(clockid_t clock_id, struct timex *tx) · line 191

Quoted 5 lines

  COBALT_SYSCALL(clock_settime, current,

kernel/cobalt/posix/clock.c +1 -1
-	       (clockid_t clock_id, const struct timespec __user *u_ts))
+	       (clockid_t clock_id, const struct __user_old_timespec __user *u_ts))

I planned to still use timespec as the argument, tv_sec is defined as long, 32bit long in 32bit system, 64bit long in 64bit system, use timespec64 in implementation.

Quoted 5 lines

Keeping struct timespec for the argument does not seem the right thing to do, as this type has been phased out from recent kernels, precisely to stop spreading ambiguity wrt 32/64 bit time_t. It is only available from the UAPI section as a compat tweak for user code, not for kernel code.

We would need a definition for older kernels anyway, but why are we not allowed to re-use the definition from the uapi here?

Quoted 11 lines

What should be done wrt addressing the y2038 issue fully is beyond this patch series. __user_old_timespec is merely an annotation on the existing implementation in order to highlight the kernel<->user interface boundary, which may help in fully addressing y2038 later on.

Eventually, it should be decided whether a legacy timespec32 should still be supported for 32bit applications building in dual-time configurations (time32_t and time64_t), or single-time configuration should be the norm with user-space using time64_t exclusively. This is beyond the scope of this patch series to decide of the way to go.

Let's discuss that within the next Community Meeting Minutes. When we started scanning the code base to get an overview of all the things that have to be done we assumed that we would need to stay fully backward compatible and "single time_t" defined by the libc that is beeing used. That may have changed in the meantime and we could take other patterns into account as well.

#6 lore raw

Re: [PATCH 2/5] cobalt/kernel: y2038: convert struct timespec to timespec64

Quoted 32 lines · [email protected] <[email protected]> writes:
Quoted 31 lines · Philippe Gerum via Xenomai
Quoted 4 lines · chensong via Xenomai
Quoted 4 lines

+/*
+ * Our representation of time at the kernel<->user interface boundary
+ * at the moment, until we have fully transitioned to a y2038-safe
+ * implementation in libcobalt.

Quoted 9 lines

include/cobalt/uapi/kernel/types.h static inline xnhandle_t xnhandle_get_id(xnhandle_t handle) · line 68

Quoted 5 lines

+ */

include/cobalt/uapi/kernel/types.h +4 -0
+struct __user_old_timespec {
+	long  tv_sec;
+	long  tv_nsec;
+};

why not use old_timespec32, which is timespec32 representation defined in include/linux/time32?

Using old_timespec32 in this context would mean that any time value received from userland by the core should be restricted to 32bit time_t, which is not what we want, at least for 64bit platforms:

include/vdso/time32.h:

struct old_timespec32 {
	old_time32_t	tv_sec;
	s32		tv_nsec;
};

__user_old_timespec conveys the notion that we are generically talking about "the old timespec type which has a y2038 problem"; this is not specifically about the legacy timespec type on 32bit machines.

Quoted 7 lines
Quoted 2 lines

Since v5.4-rc6, we do have __kernel_old_timespec though, which could have been used instead of __user_old_timespec:

According to my information (based on
https://elixir.bootlin.com/linux/v5.5-rc1/A/ident/__kernel_old_timespec
) this is available since v5.5-rc1.

This disagrees with the git history then:

commit 94c467ddb273dc9a6a4fb09aef392c119b151edb
Author: Arnd Bergmann <[email protected]>

y2038: add __kernel_old_timespec and __kernel_old_time_t

$ git describe 94c467ddb273dc9a6a4fb09aef392c119b151edb
v5.4-rc6-2-g94c467ddb273dc9
Quoted 12 lines
Quoted 12 lines

include/uapi/asm-generic/posix_types.h:

typedef long __kernel_long_t;

include/uapi/linux/time_types.h:

struct __kernel_old_timespec {
	__kernel_long_t		tv_sec;		/* seconds */
	long			tv_nsec;	/* nanoseconds */
};
Quoted 8 lines
Quoted 3 lines

so I went for adding __user_old_timespec to the Cobalt UAPI. This may be seen as a temporary option until stricter requirements on the minimum toolchain support for building Cobalt is decided.

__kernel_old_timespec is part of the "common" Linux uapi, so not x86 specific. Could you explain the problem you know of (or even see) with some of the toolchains? Sounds strange...

(Cross) toolchains use a snapshot of the linux UAPI taken at some point in time. If a toolchain is somewhat outdated compared to the current state of the kernel UAPI, then there is a problem with using the types it defines. e.g. recent linaro toolchains for aarch32, aarch64 do not provide any definition for __kernel_old_timespec, yet.

Now, as Song suggested, I could have defined __kernel_old_timespec in the Cobalt UAPI to address this, instead of defining __user_old_timespec. I found an upside in clearly stating this particular interface boundary for time values Cobalt-wise, using a Cobalt-specific type. What this should become in a subsequent series of patches addressing the y2038 issue fully is beyond the scope of the current series.

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

kernel/cobalt/posix/clock.c int __cobalt_clock_adjtime(clockid_t clock_id, struct timex *tx) · line 191

Quoted 5 lines

COBALT_SYSCALL(clock_settime, current,

kernel/cobalt/posix/clock.c +1 -1
-	       (clockid_t clock_id, const struct timespec __user *u_ts))
+	       (clockid_t clock_id, const struct __user_old_timespec __user *u_ts))

I planned to still use timespec as the argument, tv_sec is defined as long, 32bit long in 32bit system, 64bit long in 64bit system, use timespec64 in implementation.

Quoted 9 lines
Quoted 5 lines

Keeping struct timespec for the argument does not seem the right thing to do, as this type has been phased out from recent kernels, precisely to stop spreading ambiguity wrt 32/64 bit time_t. It is only available from the UAPI section as a compat tweak for user code, not for kernel code.

We would need a definition for older kernels anyway, but why are we not allowed to re-use the definition from the uapi here?

Because the timespec type along with all other ambiguous types are now hidden from the kernel code in recent mainline releases:

commit c766d1472c70d25ad475cf56042af1652e792b23
Author: Arnd Bergmann <[email protected]>

y2038: hide timeval/timespec/itimerval/itimerspec types

Which gives, in include/uapi/linux/time.h:

#ifndef __KERNEL__
#ifndef _STRUCT_TIMESPEC
#define _STRUCT_TIMESPEC

struct timespec {
	__kernel_old_time_t	tv_sec;		/* seconds */
	long			tv_nsec;	/* nanoseconds */
};

#endif

struct timeval {
	__kernel_old_time_t	tv_sec;		/* seconds */
	__kernel_suseconds_t	tv_usec;	/* microseconds */
};

struct itimerspec {
struct timespec it_interval;/* timer period */
struct timespec it_value; /* timer expiration */
};

struct itimerval {
struct timeval it_interval;/* timer interval */
struct timeval it_value; /* current value */
};
#endif

Quoted 18 lines
Quoted 11 lines

What should be done wrt addressing the y2038 issue fully is beyond this patch series. __user_old_timespec is merely an annotation on the existing implementation in order to highlight the kernel<->user interface boundary, which may help in fully addressing y2038 later on.

Eventually, it should be decided whether a legacy timespec32 should still be supported for 32bit applications building in dual-time configurations (time32_t and time64_t), or single-time configuration should be the norm with user-space using time64_t exclusively. This is beyond the scope of this patch series to decide of the way to go.

Let's discuss that within the next Community Meeting Minutes. When we started scanning the code base to get an overview of all the things that have to be done we assumed that we would need to stay fully backward compatible and "single time_t" defined by the libc that is beeing used. That may have changed in the meantime and we could take other patterns into account as well.

Signature · 1 line
Philippe.
#7 lore raw

Re: [PATCH 2/5] cobalt/kernel: y2038: convert struct timespec to timespec64

Quoted 45 lines · Philippe Gerum via Xenomai
Quoted 32 lines · [email protected] <[email protected]> writes:
Quoted 31 lines · Philippe Gerum via Xenomai
Quoted 4 lines · chensong via Xenomai
Quoted 4 lines

+/*
+ * Our representation of time at the kernel<->user interface boundary
+ * at the moment, until we have fully transitioned to a y2038-safe
+ * implementation in libcobalt.

Quoted 9 lines

include/cobalt/uapi/kernel/types.h static inline xnhandle_t xnhandle_get_id(xnhandle_t handle) · line 68

Quoted 5 lines

+ */

include/cobalt/uapi/kernel/types.h +4 -0
+struct __user_old_timespec {
+	long  tv_sec;
+	long  tv_nsec;
+};

why not use old_timespec32, which is timespec32 representation defined in include/linux/time32?

Using old_timespec32 in this context would mean that any time value received from userland by the core should be restricted to 32bit time_t, which is not what we want, at least for 64bit platforms:

include/vdso/time32.h:

struct old_timespec32 {
	old_time32_t	tv_sec;
	s32		tv_nsec;
};

__user_old_timespec conveys the notion that we are generically talking about "the old timespec type which has a y2038 problem"; this is not specifically about the legacy timespec type on 32bit machines.

Quoted 7 lines
Quoted 2 lines

Since v5.4-rc6, we do have __kernel_old_timespec though, which could have been used instead of __user_old_timespec:

According to my information (based on
https://elixir.bootlin.com/linux/v5.5-rc1/A/ident/__kernel_old_timespec
) this is available since v5.5-rc1.

This disagrees with the git history then:

Quoted 8 lines

commit 94c467ddb273dc9a6a4fb09aef392c119b151edb
Author: Arnd Bergmann <[email protected]>

y2038: add __kernel_old_timespec and __kernel_old_time_t

$ git describe 94c467ddb273dc9a6a4fb09aef392c119b151edb
v5.4-rc6-2-g94c467ddb273dc9

This tells you *after* which tag it was applied, not when it was in and tagged there. That was indeed v5.5-rc1 (seen via gitk, still looking for a handy git command line to explore that).

Jan

Signature · 2 lines
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux
#8 lore raw

Re: [PATCH 2/5] cobalt/kernel: y2038: convert struct timespec to timespec64

Quoted 49 lines · Jan Kiszka
Quoted 48 lines · Philippe Gerum via Xenomai
Quoted 32 lines · [email protected] <[email protected]> writes:
Quoted 31 lines · Philippe Gerum via Xenomai
Quoted 4 lines · chensong via Xenomai
Quoted 4 lines

+/*
+ * Our representation of time at the kernel<->user interface boundary
+ * at the moment, until we have fully transitioned to a y2038-safe
+ * implementation in libcobalt.

Quoted 9 lines

include/cobalt/uapi/kernel/types.h static inline xnhandle_t xnhandle_get_id(xnhandle_t handle) · line 68

Quoted 5 lines

+ */

include/cobalt/uapi/kernel/types.h +4 -0
+struct __user_old_timespec {
+	long  tv_sec;
+	long  tv_nsec;
+};

why not use old_timespec32, which is timespec32 representation defined in include/linux/time32?

Using old_timespec32 in this context would mean that any time value received from userland by the core should be restricted to 32bit time_t, which is not what we want, at least for 64bit platforms:

include/vdso/time32.h:

struct old_timespec32 {
	old_time32_t	tv_sec;
	s32		tv_nsec;
};

__user_old_timespec conveys the notion that we are generically talking about "the old timespec type which has a y2038 problem"; this is not specifically about the legacy timespec type on 32bit machines.

Quoted 7 lines
Quoted 2 lines

Since v5.4-rc6, we do have __kernel_old_timespec though, which could have been used instead of __user_old_timespec:

According to my information (based on
https://elixir.bootlin.com/linux/v5.5-rc1/A/ident/__kernel_old_timespec
) this is available since v5.5-rc1.

This disagrees with the git history then:

commit 94c467ddb273dc9a6a4fb09aef392c119b151edb
Author: Arnd Bergmann <[email protected]>

Quoted 8 lines
Quoted 5 lines

y2038: add __kernel_old_timespec and __kernel_old_time_t

$ git describe 94c467ddb273dc9a6a4fb09aef392c119b151edb
v5.4-rc6-2-g94c467ddb273dc9

This tells you *after* which tag it was applied, not when it was in and tagged there.

That's right. My mistake.

Quoted 3 lines

That was indeed v5.5-rc1 (seen via gitk, still looking for a handy git command line to explore that).

$ git describe --contains
Signature · 1 line
Philippe.
#9 lore raw

Re: [PATCH 2/5] cobalt/kernel: y2038: convert struct timespec to timespec64

Quoted 61 lines · Philippe Gerum
Quoted 49 lines · Jan Kiszka
Quoted 48 lines · Philippe Gerum via Xenomai
Quoted 32 lines · [email protected] <[email protected]> writes:
Quoted 31 lines · Philippe Gerum via Xenomai
Quoted 4 lines · chensong via Xenomai
Quoted 4 lines

+/*
+ * Our representation of time at the kernel<->user interface boundary
+ * at the moment, until we have fully transitioned to a y2038-safe
+ * implementation in libcobalt.

Quoted 9 lines

Review

Quoted 5 lines

+ */

(quoted diff) +4 -0
+struct __user_old_timespec {
+	long  tv_sec;
+	long  tv_nsec;
+};

why not use old_timespec32, which is timespec32 representation defined in include/linux/time32?

Using old_timespec32 in this context would mean that any time value received from userland by the core should be restricted to 32bit time_t, which is not what we want, at least for 64bit platforms:

include/vdso/time32.h:

struct old_timespec32 {
	old_time32_t	tv_sec;
	s32		tv_nsec;
};

__user_old_timespec conveys the notion that we are generically talking about "the old timespec type which has a y2038 problem"; this is not specifically about the legacy timespec type on 32bit machines.

Quoted 7 lines
Quoted 2 lines

Since v5.4-rc6, we do have __kernel_old_timespec though, which could have been used instead of __user_old_timespec:

According to my information (based on
https://elixir.bootlin.com/linux/v5.5-rc1/A/ident/__kernel_old_timespec
) this is available since v5.5-rc1.

This disagrees with the git history then:

commit 94c467ddb273dc9a6a4fb09aef392c119b151edb
Author: Arnd Bergmann <[email protected]>

Quoted 8 lines
Quoted 5 lines

y2038: add __kernel_old_timespec and __kernel_old_time_t

$ git describe 94c467ddb273dc9a6a4fb09aef392c119b151edb
v5.4-rc6-2-g94c467ddb273dc9

This tells you *after* which tag it was applied, not when it was in and tagged there.

Quoted 8 lines

That's right. My mistake.

Quoted 3 lines

That was indeed v5.5-rc1 (seen via gitk, still looking for a handy git command line to explore that).

$ git describe --contains

Ah, that is worth to remember!

Thanks,
Jan

Signature · 2 lines
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux
#10 lore raw

Re: [PATCH 2/5] cobalt/kernel: y2038: convert struct timespec to timespec64

In reply to Philippe Gerum

On Sat, 2021-02-20 at 16:18 +0100, Philippe Gerum via Xenomai wrote:
[snip]

Quoted 11 lines
kernel/cobalt/posix/sem.c +0 -0
index 05a861dfe..467a9b7dd 100644
@@ -267,7 +267,7 @@ out:
  	return ret;
  }

kernel/cobalt/posix/sem.c +1 -1
-static inline int sem_fetch_timeout(struct timespec *ts,
+static inline int sem_fetch_timeout(struct timespec64 *ts,

      const void __user *u_ts)

Handle the following with care, maybe my understanding of CONFIG_XENO_ARCH_SYS3264 is wrong. See below...

My understanding is that this is a breaking change for 32 bit kernels. The broken part is hidden here, but sem_fetch_timeout() now assumes that the user provided timespec64, which is not be the case for 32 bit applications running on a 32 bit kernel.

Quoted 19 lines

 {
  return u_ts == NULL ? -EFAULT :

kernel/cobalt/posix/sem.c +0 -0
@@ -276,10 +276,10 @@ static inline int sem_fetch_timeout(struct timespec *ts,


 int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem, const void __user *u_ts,

kernel/cobalt/posix/sem.c +1 -1
-			   int (*fetch_timeout)(struct timespec *ts,
+			   int (*fetch_timeout)(struct timespec64 *ts,

  const void __user *u_ts)) {

kernel/cobalt/posix/sem.c +1 -1
-	struct timespec ts = { .tv_sec = 0, .tv_nsec = 0 };
+	struct timespec64 ts = { .tv_sec = 0, .tv_nsec = 0 };

  int pull_ts = 1, ret, info;
  struct cobalt_sem *sem;
  xnhandle_t handle;

kernel/cobalt/posix/sem.c +0 -0
@@ -434,7 +434,7 @@ COBALT_SYSCALL(sem_wait, primary,


 COBALT_SYSCALL(sem_timedwait, primary, (struct cobalt_sem_shadow __user *u_sem,

kernel/cobalt/posix/sem.c

Quoted 2 lines
kernel/cobalt/posix/sem.c +1 -1
-		struct timespec __user *u_ts))
+		struct __user_old_timespec __user *u_ts))

This change is still correct, but this is where the journey begins. If my understanding of CONFIG_XENO_ARCH_SYS3264 is correct, this syscall is being used on 32 bit kernels as well. Is that understanding correct?

Quoted 3 lines

 {
  return __cobalt_sem_timedwait(u_sem, u_ts, sem_fetch_timeout); }

#11 lore raw

Re: [PATCH 2/5] cobalt/kernel: y2038: convert struct timespec to timespec64

Quoted 17 lines · [email protected] <[email protected]> writes:

On Sat, 2021-02-20 at 16:18 +0100, Philippe Gerum via Xenomai wrote:
[snip]

kernel/cobalt/posix/sem.c out: · line 271

Quoted 11 lines
kernel/cobalt/posix/sem.c +1 -1
index 05a861dfe..467a9b7dd 100644
@@ -267,7 +267,7 @@ out:
 	return ret;
 }
 
-static inline int sem_fetch_timeout(struct timespec *ts,
+static inline int sem_fetch_timeout(struct timespec64 *ts,
 				    const void __user *u_ts)

Handle the following with care, maybe my understanding of CONFIG_XENO_ARCH_SYS3264 is wrong. See below...

Quoted 5 lines

My understanding is that this is a breaking change for 32 bit kernels. The broken part is hidden here, but sem_fetch_timeout() now assumes that the user provided timespec64, which is not be the case for 32 bit applications running on a 32 bit kernel.

The user-provided memory is referred to by u_ts, not ts, which receives the timestamp fetch_timeout() is supposed to return. The change should only affect the return type, not the source one. sys32_fetch_timeout() should still do the right thing via sys32_get_timespec().

Did you observe a manifest breakage with 32_64 setups?

Quoted 18 lines
Quoted 18 lines
kernel/cobalt/posix/sem.c +2 -2
 {
 	return u_ts == NULL ? -EFAULT :
@@ -276,10 +276,10 @@ static inline int sem_fetch_timeout(struct timespec *ts,
 
 int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem,
 			   const void __user *u_ts,
-			   int (*fetch_timeout)(struct timespec *ts,
+			   int (*fetch_timeout)(struct timespec64 *ts,
 						const void __user *u_ts))
 {
-	struct timespec ts = { .tv_sec = 0, .tv_nsec = 0 };
+	struct timespec64 ts = { .tv_sec = 0, .tv_nsec = 0 };
 	int pull_ts = 1, ret, info;
 	struct cobalt_sem *sem;
 	xnhandle_t handle;
@@ -434,7 +434,7 @@ COBALT_SYSCALL(sem_wait, primary,
 
Quoted 8 lines

kernel/cobalt/posix/sem.c COBALT_SYSCALL(sem_wait, primary, · line 437

Quoted 4 lines
kernel/cobalt/posix/sem.c +1 -1
 COBALT_SYSCALL(sem_timedwait, primary,
 	       (struct cobalt_sem_shadow __user *u_sem,
-		struct timespec __user *u_ts))
+		struct __user_old_timespec __user *u_ts))

This change is still correct, but this is where the journey begins. If my understanding of CONFIG_XENO_ARCH_SYS3264 is correct, this syscall is being used on 32 bit kernels as well. Is that understanding correct?

COBALT_SYSCALL(sem_timedwait, ...) is only used in native (e.g. mere 64bit, or 32bit) mode. The following one is used in 32bit over 64bit mode specifically:

COBALT_SYSCALL32emu(sem_timedwait, primary,
(struct cobalt_sem_shadow __user *u_sem,
struct old_timespec32 __user *u_ts))

Signature · 1 line
Philippe.
#12 lore raw

Re: [PATCH 2/5] cobalt/kernel: y2038: convert struct timespec to timespec64

Quoted 28 lines · Philippe Gerum
Quoted 20 lines · [email protected] <[email protected]> writes:

On Sat, 2021-02-20 at 16:18 +0100, Philippe Gerum via Xenomai wrote:
[snip]

Quoted 13 lines
kernel/cobalt/posix/sem.c +0 -0
index 05a861dfe..467a9b7dd 100644
@@ -267,7 +267,7 @@ out:
  	return ret;
  }

kernel/cobalt/posix/sem.c +1 -1
-static inline int sem_fetch_timeout(struct timespec *ts,
+static inline int sem_fetch_timeout(struct timespec64 *ts,
Quoted 1 line

  const void __user *u_ts)

Handle the following with care, maybe my understanding of CONFIG_XENO_ARCH_SYS3264 is wrong. See below...

Quoted 5 lines

My understanding is that this is a breaking change for 32 bit kernels. The broken part is hidden here, but sem_fetch_timeout() now assumes that the user provided timespec64, which is not be the case for 32 bit applications running on a 32 bit kernel.

Quoted 4 lines

The user-provided memory is referred to by u_ts, not ts, which receives the timestamp fetch_timeout() is supposed to return. The change should only affect the return type, not the source one. sys32_fetch_timeout() should still do the right thing via sys32_get_timespec().

Adding the full code:

static inline int sem_fetch_timeout(struct timespec64 *ts,
const void __user *u_ts)

{
	return u_ts == NULL ? -EFAULT :
		cobalt_copy_from_user(ts, u_ts, sizeof(*ts));
}

Copying sizeof(*ts) is to much if the application provided "__old_time_t" (sizeof(time_t) =4) only. Isn't it? I would expect the result (in ts) to be garbage. Due to different padding the "sec" field (in ts) would now contain the nsec value from u_ts as well.

I will come up with a proposal to fix that. We need some discussion anyway...

Quoted 45 lines

Did you observe a manifest breakage with 32_64 setups?

Quoted 24 lines
Quoted 24 lines

 {
  return u_ts == NULL ? -EFAULT :

kernel/cobalt/posix/sem.c +0 -0
@@ -276,10 +276,10 @@ static inline int sem_fetch_timeout(struct timespec *ts,

 int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem, const void __user *u_ts,

kernel/cobalt/posix/sem.c +1 -1
-			   int (*fetch_timeout)(struct timespec *ts,
+			   int (*fetch_timeout)(struct timespec64 *ts,

  const void __user *u_ts)) {

kernel/cobalt/posix/sem.c +1 -1
-	struct timespec ts = { .tv_sec = 0, .tv_nsec = 0 };
+	struct timespec64 ts = { .tv_sec = 0, .tv_nsec = 0 };

  int pull_ts = 1, ret, info;
  struct cobalt_sem *sem;
  xnhandle_t handle;

kernel/cobalt/posix/sem.c +0 -0
@@ -434,7 +434,7 @@ COBALT_SYSCALL(sem_wait, primary,

Quoted 8 lines

kernel/cobalt/posix/sem.c

Quoted 4 lines

 COBALT_SYSCALL(sem_timedwait, primary, (struct cobalt_sem_shadow __user *u_sem,

kernel/cobalt/posix/sem.c +1 -1
-		struct timespec __user *u_ts))
+		struct __user_old_timespec __user *u_ts))

This change is still correct, but this is where the journey begins. If my understanding of CONFIG_XENO_ARCH_SYS3264 is correct, this syscall is being used on 32 bit kernels as well. Is that understanding correct?

COBALT_SYSCALL(sem_timedwait, ...) is only used in native (e.g. mere 64bit, or 32bit) mode. The following one is used in 32bit over 64bit mode specifically:

COBALT_SYSCALL32emu(sem_timedwait, primary,
(struct cobalt_sem_shadow __user *u_sem,
struct old_timespec32 __user *u_ts))

#13 lore raw

Re: [PATCH 2/5] cobalt/kernel: y2038: convert struct timespec to timespec64

Quoted 43 lines · [email protected] <[email protected]> writes:
Quoted 28 lines · Philippe Gerum
Quoted 20 lines · [email protected] <[email protected]> writes:

On Sat, 2021-02-20 at 16:18 +0100, Philippe Gerum via Xenomai wrote:
[snip]

Quoted 13 lines
kernel/cobalt/posix/sem.c +1 -1
index 05a861dfe..467a9b7dd 100644
@@ -267,7 +267,7 @@ out:
 	return ret;
 }
 
 
 
 
-static inline int sem_fetch_timeout(struct timespec *ts,
+static inline int sem_fetch_timeout(struct timespec64 *ts,
Quoted 1 line

const void __user *u_ts)

Handle the following with care, maybe my understanding of CONFIG_XENO_ARCH_SYS3264 is wrong. See below...

Quoted 5 lines

My understanding is that this is a breaking change for 32 bit kernels. The broken part is hidden here, but sem_fetch_timeout() now assumes that the user provided timespec64, which is not be the case for 32 bit applications running on a 32 bit kernel.

Quoted 4 lines

The user-provided memory is referred to by u_ts, not ts, which receives the timestamp fetch_timeout() is supposed to return. The change should only affect the return type, not the source one. sys32_fetch_timeout() should still do the right thing via sys32_get_timespec().

Adding the full code:

static inline int sem_fetch_timeout(struct timespec64 *ts,
const void __user *u_ts)

{
	return u_ts == NULL ? -EFAULT :
		cobalt_copy_from_user(ts, u_ts, sizeof(*ts));
}
Quoted 5 lines

Copying sizeof(*ts) is to much if the application provided "__old_time_t" (sizeof(time_t) =4) only. Isn't it? I would expect the result (in ts) to be garbage. Due to different padding the "sec" field (in ts) would now contain the nsec value from u_ts as well.

Ah, I was looking at the wrong path (32emu). Yes, this is broken for mere 32bit now (i.e. natively 32bit platform).

Signature · 1 line
Philippe.
#14 lore raw

Re: [PATCH 2/5] cobalt/kernel: y2038: convert struct timespec to timespec64

Quoted 11 lines · Philippe Gerum
Quoted 11 lines

Adding the full code:

static inline int sem_fetch_timeout(struct timespec64 *ts,
const void __user *u_ts)

{
	return u_ts == NULL ? -EFAULT :
		cobalt_copy_from_user(ts, u_ts, sizeof(*ts));
}
Quoted 9 lines
Quoted 5 lines

Copying sizeof(*ts) is to much if the application provided "__old_time_t" (sizeof(time_t) =4) only. Isn't it? I would expect the result (in ts) to be garbage. Due to different padding the "sec" field (in ts) would now contain the nsec value from u_ts as well.

Ah, I was looking at the wrong path (32emu). Yes, this is broken for mere 32bit now (i.e. natively 32bit platform).

I already prepared a patch. That's useful for some further discussion as well. Coming soon, no need to interrupt dovetail porting ;-)

#15 lore raw

Re: [PATCH 2/5] cobalt/kernel: y2038: convert struct timespec to timespec64

In reply to Philippe Gerum
Quoted 45 lines · Philippe Gerum
Quoted 43 lines · [email protected] <[email protected]> writes:
Quoted 28 lines · Philippe Gerum
Quoted 20 lines · [email protected] <[email protected]> writes:

On Sat, 2021-02-20 at 16:18 +0100, Philippe Gerum via Xenomai wrote:
[snip]

Quoted 13 lines
kernel/cobalt/posix/sem.c +1 -1
index 05a861dfe..467a9b7dd 100644
@@ -267,7 +267,7 @@ out:
 	return ret;
 }
 
 
 
 
-static inline int sem_fetch_timeout(struct timespec *ts,
+static inline int sem_fetch_timeout(struct timespec64 *ts,
Quoted 1 line

const void __user *u_ts)

Handle the following with care, maybe my understanding of CONFIG_XENO_ARCH_SYS3264 is wrong. See below...

Quoted 5 lines

My understanding is that this is a breaking change for 32 bit kernels. The broken part is hidden here, but sem_fetch_timeout() now assumes that the user provided timespec64, which is not be the case for 32 bit applications running on a 32 bit kernel.

Quoted 4 lines

The user-provided memory is referred to by u_ts, not ts, which receives the timestamp fetch_timeout() is supposed to return. The change should only affect the return type, not the source one. sys32_fetch_timeout() should still do the right thing via sys32_get_timespec().

Adding the full code:

static inline int sem_fetch_timeout(struct timespec64 *ts,
const void __user *u_ts)

{
	return u_ts == NULL ? -EFAULT :
		cobalt_copy_from_user(ts, u_ts, sizeof(*ts));
}
Quoted 8 lines
Quoted 5 lines

Copying sizeof(*ts) is to much if the application provided "__old_time_t" (sizeof(time_t) =4) only. Isn't it? I would expect the result (in ts) to be garbage. Due to different padding the "sec" field (in ts) would now contain the nsec value from u_ts as well.

Ah, I was looking at the wrong path (32emu). Yes, this is broken for mere 32bit now (i.e. natively 32bit platform).

We could simply use cobalt_get_u_timespec() instead of open coding the call to cobalt_copy_from_user(). Condvars have this right already, mutex, mq and sema4s have their fetch_timeout() helper broken indeed. Good spot.

Signature · 1 line
Philippe.
#16 lore raw

cover Pattern for implementing y2038 syscalls

Hi!

A small RFC series for establishing / discussing a pattern for the implementation of y2038 syscalls.

"The Linux pattern":
Convert the time_t related data structures to time64_t directly in the syscall handler and pass it to the time64_t based internal APIs.

We can follow this pattern, which allows us to re-use most of the code that is needed for all the syscall implementations, including the compat or ia32 / x32 ones.

But: Some of the syscalls are calling cobalt_copy_from_user() just before using the value the first time. As some syscalls (like sc_cobalt_sem_timedwait) might not need the value in all code paths we would end up with a couple of instructions that were "wasted". Would that be acceptable for us?

If we can not follow this pattern I guess we have to duplicate all the helpers in use to get time_t as well as time64_t support. Mainly because we share a single syscall table between different entry points on x86.

"The syscall integration topic":
We need:
- a new native syscall for each time_t affected syscall
- a new compat/emulation syscall to get 32 bit applications running on 64 bit kernels done (so far only x86 is implemented)

As 64 bit kernels are currently using the same syscall tables as 32 bit kernels we would end up with one superflous entry in the table for 64 bit kernels. Is that acceptable?

"The syscall naming topic":
My proposal is adding "_time64" to all y2038 safe syscalls. We can't really use "_time32" for the "affected" ones because for 64i bit kernels they are y2038 safe already. Further ideas?

Best regards,
Florian

Florian Bezdeka (2):
y2038: Fixing the sem_timedwait syscall for 32 bit systems
y2038: Adding sem_timedwait_time64

 include/cobalt/uapi/syscall.h   |  1 +
 kernel/cobalt/posix/sem.c       | 49 +++++++++++++++++----------------
 kernel/cobalt/posix/sem.h       | 10 ++++---
 kernel/cobalt/posix/syscall32.c | 23 ++++++++++++++--
 kernel/cobalt/posix/syscall32.h |  6 +++-
 5 files changed, 59 insertions(+), 30 deletions(-)
Signature · 1 line
2.29.2
#17 lore raw

RFC PATCH 1/2 y2038: Fixing the sem_timedwait syscall for 32 bit systems

On systems using 32 bit for time_t the sem_timedwait syscall was broken because the function used for copying the timeout value from userspace to kernel (=sem_fetch_timeout()) was always copying sizeof(struct timespec64).

A 32 bit application (or more specific an application with 4 byte time_t) would only provide sizeof(struct old_timespec32).

Notable changes:
- The copy operation from userspace to kernel is now already done in the syscall handler. So it is always done. Previously it was copied over and validated before the first use (when used at all). So we have some additional instructions now that may be unnecessary, but that simplifies the code.

- Validation: Switched to timespec64_valid() instead of our own check.

Fixes 8043eccd232d ("cobalt/kernel: y2038: convert struct timespec to timespec64")
---
 kernel/cobalt/posix/sem.c       | 37 +++++++++++++--------------------
 kernel/cobalt/posix/sem.h       |  6 ++----
 kernel/cobalt/posix/syscall32.c | 11 ++++++++--
 kernel/cobalt/posix/syscall32.h |  2 +-
 4 files changed, 26 insertions(+), 30 deletions(-)
kernel/cobalt/posix/sem.c +14 -23
index 467a9b7dd..a0565e9f8 100644
@@ -267,20 +267,11 @@ out:
 	return ret;
 }
 
-static inline int sem_fetch_timeout(struct timespec64 *ts,
-				    const void __user *u_ts)
-{
-	return u_ts == NULL ? -EFAULT :
-		cobalt_copy_from_user(ts, u_ts, sizeof(*ts));
-}
-
 int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem,
-			   const void __user *u_ts,
-			   int (*fetch_timeout)(struct timespec64 *ts,
-						const void __user *u_ts))
+			   const struct timespec64 *ts)
 {
-	struct timespec64 ts = { .tv_sec = 0, .tv_nsec = 0 };
-	int pull_ts = 1, ret, info;
+	int ret, info;
+	bool validate_ts = true;
 	struct cobalt_sem *sem;
 	xnhandle_t handle;
 	xntmode_t tmode;
@@ -304,24 +295,19 @@ int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem,
 		 * it's actually more complex, to keep some
 		 * applications ported to Linux happy.
 		 */
-		if (pull_ts) {
+		if (validate_ts) {
 			atomic_inc(&sem->state->value);
-			xnlock_put_irqrestore(&nklock, s);
-			ret = fetch_timeout(&ts, u_ts);
-			xnlock_get_irqsave(&nklock, s);
-			if (ret)
-				break;
-			if (ts.tv_nsec >= ONE_BILLION) {
+			if (!timespec64_valid(ts)) {
 				ret = -EINVAL;
 				break;
 			}
-			pull_ts = 0;
+			validate_ts = false;
 			continue;
 		}
 
 		ret = 0;
 		tmode = sem->flags & SEM_RAWCLOCK ? XN_ABSOLUTE : XN_REALTIME;
-		info = xnsynch_sleep_on(&sem->synchbase, ts2ns(&ts) + 1, tmode);
+		info = xnsynch_sleep_on(&sem->synchbase, ts2ns(ts) + 1, tmode);
 		if (info & XNRMID)
 			ret = -EINVAL;
 		else if (info & (XNBREAK|XNTIMEO)) {
@@ -434,9 +420,14 @@ COBALT_SYSCALL(sem_wait, primary,
 
 COBALT_SYSCALL(sem_timedwait, primary,
 	       (struct cobalt_sem_shadow __user *u_sem,
-		struct __user_old_timespec __user *u_ts))
+		const struct __user_old_timespec __user *u_ts))
 {
-	return __cobalt_sem_timedwait(u_sem, u_ts, sem_fetch_timeout);
+	struct timespec64 ts64;
+
+	if (cobalt_get_u_timespec(&ts64, u_ts))
+		return -EFAULT;
+
+	return __cobalt_sem_timedwait(u_sem, &ts64);
 }
 
 COBALT_SYSCALL(sem_trywait, primary,
kernel/cobalt/posix/sem.h +2 -4
index d17299495..658e11f7a 100644
@@ -64,9 +64,7 @@ __cobalt_sem_open(struct cobalt_sem_shadow __user *usm,
 		  int oflags, mode_t mode, unsigned int value);
 
 int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem,
-			   const void __user *u_ts,
-			   int (*fetch_timeout)(struct timespec64 *ts,
-						const void __user *u_ts));
+			   const struct timespec64 *ts);
 
 int __cobalt_sem_destroy(xnhandle_t handle);
 
@@ -91,7 +89,7 @@ COBALT_SYSCALL_DECL(sem_wait,
 
 COBALT_SYSCALL_DECL(sem_timedwait,
 		    (struct cobalt_sem_shadow __user *u_sem,
-		     struct __user_old_timespec __user *u_ts));
+		     const struct __user_old_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(sem_trywait,
 		    (struct cobalt_sem_shadow __user *u_sem));
kernel/cobalt/posix/syscall32.c +9 -2
index 57aa7251a..c2a2423ed 100644
@@ -124,9 +124,16 @@ COBALT_SYSCALL32emu(sem_open, lostage,
 
 COBALT_SYSCALL32emu(sem_timedwait, primary,
 		    (struct cobalt_sem_shadow __user *u_sem,
-		     struct old_timespec32 __user *u_ts))
+		     const struct old_timespec32 __user *u_ts))
 {
-	return __cobalt_sem_timedwait(u_sem, u_ts, sys32_fetch_timeout);
+	int ret;
+	struct timespec64 ts64;
+
+	ret = sys32_fetch_timeout(&ts64, u_ts);
+	if (ret)
+		return ret;
+
+	return __cobalt_sem_timedwait(u_sem, &ts64);
 }
 
 COBALT_SYSCALL32emu(clock_getres, current,
kernel/cobalt/posix/syscall32.h +1 -1
index 66cd2a5d2..d72fd2022 100644
@@ -229,6 +229,6 @@ COBALT_SYSCALL32emu_DECL(sem_open,
 
 COBALT_SYSCALL32emu_DECL(sem_timedwait,
 			 (struct cobalt_sem_shadow __user *u_sem,
-			  struct old_timespec32 __user *u_ts));
+			  const struct old_timespec32 __user *u_ts));
 
 #endif /* !_COBALT_POSIX_SYSCALL32_H */
Signature · 1 line
2.29.2
author NAK
#18 lore raw

Re: [y2038][RFC PATCH 1/2] y2038: Fixing the sem_timedwait syscall for 32 bit systems

Quoted 8 lines · Florian Bezdeka

On systems using 32 bit for time_t the sem_timedwait syscall was broken because the function used for copying the timeout value from userspace to kernel (=sem_fetch_timeout()) was always copying sizeof(struct timespec64).

A 32 bit application (or more specific an application with 4 byte time_t) would only provide sizeof(struct old_timespec32).

Quoted 6 lines

Notable changes:
- The copy operation from userspace to kernel is now already done in the syscall handler. So it is always done. Previously it was copied over and validated before the first use (when used at all). So we have some additional instructions now that may be unnecessary, but that simplifies the code.

Nack, there is a reason for this postponed copy of timespecs up to the point where they are actually needed. This patch would break POSIX compliance for some users. Please see the last sentence in the Description of sem_timedwait()
https://pubs.opengroup.org/onlinepubs/009696699/functions/sem_timedwait.html

I agree that the standard says "need not be checked", not "must not be checked" which may make this implementation-defined, but some test suites Xenomai runs against do expect this to pass.

Signature · 1 line
Philippe.
#19 lore raw

Re: [y2038][RFC PATCH 1/2] y2038: Fixing the sem_timedwait syscall for 32 bit systems

Quoted 17 lines · Philippe Gerum
Quoted 8 lines · Florian Bezdeka

On systems using 32 bit for time_t the sem_timedwait syscall was broken because the function used for copying the timeout value from userspace to kernel (=sem_fetch_timeout()) was always copying sizeof(struct timespec64).

A 32 bit application (or more specific an application with 4 byte time_t) would only provide sizeof(struct old_timespec32).

Quoted 6 lines

Notable changes:
  - The copy operation from userspace to kernel is now already done in the syscall handler. So it is always done. Previously it was copied over and validated before the first use (when used at all). So we have some additional instructions now that may be unnecessary, but that simplifies the code.

Quoted 5 lines

Nack, there is a reason for this postponed copy of timespecs up to the point where they are actually needed. This patch would break POSIX compliance for some users. Please see the last sentence in the Description of sem_timedwait()
https://pubs.opengroup.org/onlinepubs/009696699/functions/sem_timedwait.html

I can't find any comment regarding the point in time where we copy this timespec to the kernel space. For the time of validation see below. Could you point me to the failing tests or some more documentation?

Quoted 5 lines

I agree that the standard says "need not be checked", not "must not be checked" which may make this implementation-defined, but some test suites Xenomai runs against do expect this to pass.

The validation did not change. It's done right before the first usage. So if not needed (because sem could be taken without timeout) there is still no validation.

Thanks for your feedback, Philippe!

#20 lore raw

Re: [y2038][RFC PATCH 1/2] y2038: Fixing the sem_timedwait syscall for 32 bit systems

Quoted 24 lines · [email protected] <[email protected]> writes:
Quoted 17 lines · Philippe Gerum
Quoted 8 lines · Florian Bezdeka

On systems using 32 bit for time_t the sem_timedwait syscall was broken because the function used for copying the timeout value from userspace to kernel (=sem_fetch_timeout()) was always copying sizeof(struct timespec64).

A 32 bit application (or more specific an application with 4 byte time_t) would only provide sizeof(struct old_timespec32).

Quoted 6 lines

Notable changes:
- The copy operation from userspace to kernel is now already done in the syscall handler. So it is always done. Previously it was copied over and validated before the first use (when used at all). So we have some additional instructions now that may be unnecessary, but that simplifies the code.

Quoted 5 lines

Nack, there is a reason for this postponed copy of timespecs up to the point where they are actually needed. This patch would break POSIX compliance for some users. Please see the last sentence in the Description of sem_timedwait()
https://pubs.opengroup.org/onlinepubs/009696699/functions/sem_timedwait.html

Quoted 4 lines

I can't find any comment regarding the point in time where we copy this timespec to the kernel space. For the time of validation see below. Could you point me to the failing tests or some more documentation?

Assuming single thread, doing that in sequence:

sem_t foo;

sem_init(&foo, 0, 0);
sem_post(&foo);
sem_timedwait(&foo, NULL); /* <= should be ok, because we surely won't block */

Disclaimer: I do find this fairly weird as well, but the privilege of any standard is to do weird things pretending this is the sane way.

Quoted 11 lines
Quoted 5 lines

I agree that the standard says "need not be checked", not "must not be checked" which may make this implementation-defined, but some test suites Xenomai runs against do expect this to pass.

The validation did not change. It's done right before the first usage. So if not needed (because sem could be taken without timeout) there is still no validation.

Thanks for your feedback, Philippe!

The short log of the patch says that the copy of timespec is always done from user->kernel, which is the issue I'm referring to. Whether the data copied is sane is a different aspect.

Signature · 1 line
Philippe.
#21 lore raw

v2 cover Pattern for implementing y2038 syscalls

Changes in v2:
- Added a smokey plugin named y2038 for running Y2038 related tests (Should be extended with all related tests)
- Review implementations (covered by tests now as well)
- Drop support for kernel 4.4
- Added the libcobalt part

Maintainers: Comments about naming / style welcome. That will speed up the process when we just have to follow the right pattern.

Florian Bezdeka (4):
y2038: Fixing the sem_timedwait syscall for 32 bit systems
y2038: Adding sem_timedwait_time64
y2038: Add tests for the sc_cobalt_sem_timedwait_time64 syscall
y2038: lib/cobalt: Add support of sc_cobalt_sem_timedwait_time64

 configure.ac                                  |   1 +
 include/cobalt/uapi/syscall.h                 |   1 +
 .../include/asm-generic/xenomai/syscall.h     |  23 +++
 kernel/cobalt/posix/sem.c                     |  53 +++---
 kernel/cobalt/posix/sem.h                     |  10 +-
 kernel/cobalt/posix/syscall32.c               |  23 ++-
 kernel/cobalt/posix/syscall32.h               |   6 +-
 lib/cobalt/semaphore.c                        |   5 +
 testsuite/smokey/Makefile.am                  |   6 +-
 testsuite/smokey/y2038/Makefile.am            |  10 ++
 testsuite/smokey/y2038/syscall-tests.c        | 170 ++++++++++++++++++
 11 files changed, 277 insertions(+), 31 deletions(-)
 create mode 100644 testsuite/smokey/y2038/Makefile.am
 create mode 100644 testsuite/smokey/y2038/syscall-tests.c
Signature · 1 line
2.29.2
#22 lore raw

RFC PATCH v2 1/4 y2038: Fixing the sem_timedwait syscall for 32 bit systems

On systems using 32 bit for time_t the sem_timedwait syscall was broken because the function used for copying the timeout value from userspace to kernel (=sem_fetch_timeout()) was always copying sizeof(struct timespec64).

A 32 bit application (or more specific an application with 4 byte time_t) would only provide sizeof(struct old_timespec32).

Notable changes:
- The copy operation from userspace to kernel is now already done in the syscall handler. So it is always done. Previously it was copied over and validated before the first use (when used at all). So we have some additional instructions now that may be unnecessary, but that simplifies the code.

- Validation: Switched to timespec64_valid() instead of our own check.

Fixes 8043eccd232d ("cobalt/kernel: y2038: convert struct timespec to timespec64")
---
 kernel/cobalt/posix/sem.c       | 40 +++++++++++++++------------------
 kernel/cobalt/posix/sem.h       |  6 ++---
 kernel/cobalt/posix/syscall32.c | 10 +++++++--
 kernel/cobalt/posix/syscall32.h |  2 +-
 4 files changed, 29 insertions(+), 29 deletions(-)
kernel/cobalt/posix/sem.c +18 -22
index 467a9b7dd..827a4751a 100644
@@ -267,20 +267,11 @@ out:
 	return ret;
 }
 
-static inline int sem_fetch_timeout(struct timespec64 *ts,
-				    const void __user *u_ts)
-{
-	return u_ts == NULL ? -EFAULT :
-		cobalt_copy_from_user(ts, u_ts, sizeof(*ts));
-}
-
 int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem,
-			   const void __user *u_ts,
-			   int (*fetch_timeout)(struct timespec64 *ts,
-						const void __user *u_ts))
+			   const struct timespec64 *ts)
 {
-	struct timespec64 ts = { .tv_sec = 0, .tv_nsec = 0 };
-	int pull_ts = 1, ret, info;
+	int ret, info;
+	bool validate_ts = true;
 	struct cobalt_sem *sem;
 	xnhandle_t handle;
 	xntmode_t tmode;
@@ -304,24 +295,23 @@ int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem,
 		 * it's actually more complex, to keep some
 		 * applications ported to Linux happy.
 		 */
-		if (pull_ts) {
+		if (validate_ts) {
 			atomic_inc(&sem->state->value);
-			xnlock_put_irqrestore(&nklock, s);
-			ret = fetch_timeout(&ts, u_ts);
-			xnlock_get_irqsave(&nklock, s);
-			if (ret)
+			if (!ts) {
+				ret = -EFAULT;
 				break;
-			if (ts.tv_nsec >= ONE_BILLION) {
+			}
+			if (!timespec64_valid(ts)) {
 				ret = -EINVAL;
 				break;
 			}
-			pull_ts = 0;
+			validate_ts = false;
 			continue;
 		}
 
 		ret = 0;
 		tmode = sem->flags & SEM_RAWCLOCK ? XN_ABSOLUTE : XN_REALTIME;
-		info = xnsynch_sleep_on(&sem->synchbase, ts2ns(&ts) + 1, tmode);
+		info = xnsynch_sleep_on(&sem->synchbase, ts2ns(ts) + 1, tmode);
 		if (info & XNRMID)
 			ret = -EINVAL;
 		else if (info & (XNBREAK|XNTIMEO)) {
@@ -434,9 +424,15 @@ COBALT_SYSCALL(sem_wait, primary,
 
 COBALT_SYSCALL(sem_timedwait, primary,
 	       (struct cobalt_sem_shadow __user *u_sem,
-		struct __user_old_timespec __user *u_ts))
+		const struct __user_old_timespec __user *u_ts))
 {
-	return __cobalt_sem_timedwait(u_sem, u_ts, sem_fetch_timeout);
+	int ret = 1;
+	struct timespec64 ts64;
+
+	if (u_ts)
+		ret = cobalt_get_u_timespec(&ts64, u_ts);
+
+	return __cobalt_sem_timedwait(u_sem, ret ? NULL : &ts64);
 }
 
 COBALT_SYSCALL(sem_trywait, primary,
kernel/cobalt/posix/sem.h +2 -4
index d17299495..658e11f7a 100644
@@ -64,9 +64,7 @@ __cobalt_sem_open(struct cobalt_sem_shadow __user *usm,
 		  int oflags, mode_t mode, unsigned int value);
 
 int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem,
-			   const void __user *u_ts,
-			   int (*fetch_timeout)(struct timespec64 *ts,
-						const void __user *u_ts));
+			   const struct timespec64 *ts);
 
 int __cobalt_sem_destroy(xnhandle_t handle);
 
@@ -91,7 +89,7 @@ COBALT_SYSCALL_DECL(sem_wait,
 
 COBALT_SYSCALL_DECL(sem_timedwait,
 		    (struct cobalt_sem_shadow __user *u_sem,
-		     struct __user_old_timespec __user *u_ts));
+		     const struct __user_old_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(sem_trywait,
 		    (struct cobalt_sem_shadow __user *u_sem));
kernel/cobalt/posix/syscall32.c +8 -2
index 57aa7251a..edac7ea4a 100644
@@ -124,9 +124,15 @@ COBALT_SYSCALL32emu(sem_open, lostage,
 
 COBALT_SYSCALL32emu(sem_timedwait, primary,
 		    (struct cobalt_sem_shadow __user *u_sem,
-		     struct old_timespec32 __user *u_ts))
+		     const struct old_timespec32 __user *u_ts))
 {
-	return __cobalt_sem_timedwait(u_sem, u_ts, sys32_fetch_timeout);
+	int ret = 1;
+	struct timespec64 ts64;
+
+	if (u_ts)
+		ret = sys32_fetch_timeout(&ts64, u_ts);
+
+	return __cobalt_sem_timedwait(u_sem, ret ? NULL : &ts64);
 }
 
 COBALT_SYSCALL32emu(clock_getres, current,
kernel/cobalt/posix/syscall32.h +1 -1
index 66cd2a5d2..d72fd2022 100644
@@ -229,6 +229,6 @@ COBALT_SYSCALL32emu_DECL(sem_open,
 
 COBALT_SYSCALL32emu_DECL(sem_timedwait,
 			 (struct cobalt_sem_shadow __user *u_sem,
-			  struct old_timespec32 __user *u_ts));
+			  const struct old_timespec32 __user *u_ts));
 
 #endif /* !_COBALT_POSIX_SYSCALL32_H */
Signature · 1 line
2.29.2
#23 lore raw

Re: [RFC PATCH v2 1/4] y2038: Fixing the sem_timedwait syscall for 32 bit systems

Quoted 15 lines · Florian Bezdeka

On systems using 32 bit for time_t the sem_timedwait syscall was broken because the function used for copying the timeout value from userspace to kernel (=sem_fetch_timeout()) was always copying sizeof(struct timespec64).

A 32 bit application (or more specific an application with 4 byte time_t) would only provide sizeof(struct old_timespec32).

Notable changes:
- The copy operation from userspace to kernel is now already done in the syscall handler. So it is always done. Previously it was copied over and validated before the first use (when used at all). So we have some additional instructions now that may be unnecessary, but that simplifies the code.

Quoted 4 lines

- Validation: Switched to timespec64_valid() instead of our own check.

Fixes 8043eccd232d ("cobalt/kernel: y2038: convert struct timespec to timespec64")

This patch was dropped from next again (and that sha was never applied). We should go a for fixed version of that series (patches 2..5, only patch 1 is now applied).

Jan

Signature · 2 lines
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux
#24 lore raw

Re: [RFC PATCH v2 1/4] y2038: Fixing the sem_timedwait syscall for 32 bit systems

Quoted 16 lines · Jan Kiszka
Quoted 15 lines · Florian Bezdeka

On systems using 32 bit for time_t the sem_timedwait syscall was broken because the function used for copying the timeout value from userspace to kernel (=sem_fetch_timeout()) was always copying sizeof(struct timespec64).

A 32 bit application (or more specific an application with 4 byte time_t) would only provide sizeof(struct old_timespec32).

Notable changes:
  - The copy operation from userspace to kernel is now already done in the syscall handler. So it is always done. Previously it was copied over and validated before the first use (when used at all). So we have some additional instructions now that may be unnecessary, but that simplifies the code.

Quoted 8 lines
Quoted 4 lines

  - Validation: Switched to timespec64_valid() instead of our own check.

Fixes 8043eccd232d ("cobalt/kernel: y2038: convert struct timespec to timespec64")

This patch was dropped from next again (and that sha was never applied). We should go a for fixed version of that series (patches 2..5, only patch 1 is now applied).

That's one of the things that may happen when working with branches that are getting rebased... The correct refspec is maybe 4d31feb5 now, which is part of wip/dovetail.

Please note the RFC tag. Would be nice to get some feedback before going ahead, otherwise the loops with all the necessary synchronization and rebases is getting endless...

Thanks!

Quoted 3 lines

Jan

#25 lore raw

Re: [RFC PATCH v2 1/4] y2038: Fixing the sem_timedwait syscall for 32 bit systems

Quoted 22 lines · Florian (T RDA IOT SES-DE)
Quoted 21 lines · Jan Kiszka
Quoted 19 lines · Florian Bezdeka

On systems using 32 bit for time_t the sem_timedwait syscall was broken because the function used for copying the timeout value from userspace to kernel (=sem_fetch_timeout()) was always copying sizeof(struct timespec64).

A 32 bit application (or more specific an application with 4 byte time_t) would only provide sizeof(struct old_timespec32).

Notable changes:
- The copy operation from userspace to kernel is now already done in the syscall handler. So it is always done. Previously it was copied over and validated before the first use (when used at all). So we have some additional instructions now that may be unnecessary, but that simplifies the code.

- Validation: Switched to timespec64_valid() instead of our own check.

Fixes 8043eccd232d ("cobalt/kernel: y2038: convert struct timespec to timespec64")
Quoted 7 lines
Quoted 3 lines

This patch was dropped from next again (and that sha was never applied). We should go a for fixed version of that series (patches 2..5, only patch 1 is now applied).

That's one of the things that may happen when working with branches that are getting rebased... The correct refspec is maybe 4d31feb5 now, which is part of wip/dovetail.

All these are development branches, nothing considered stable. And, no, even wip/dovetail is the wrong target. The right one is the patch that needs to be fixed in v2 of Philippe's series.

Quoted 4 lines

Please note the RFC tag. Would be nice to get some feedback before going ahead, otherwise the loops with all the necessary synchronization and rebases is getting endless...

For this particular patch, Philippe should comment first. I will have a look at the rest now.

Jan

Signature · 2 lines
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux
#26 lore raw

Re: [RFC PATCH v2 1/4] y2038: Fixing the sem_timedwait syscall for 32 bit systems

In reply to Florian Bezdeka
Quoted 56 lines · Florian Bezdeka

On systems using 32 bit for time_t the sem_timedwait syscall was broken because the function used for copying the timeout value from userspace to kernel (=sem_fetch_timeout()) was always copying sizeof(struct timespec64).

A 32 bit application (or more specific an application with 4 byte time_t) would only provide sizeof(struct old_timespec32).

Notable changes:
- The copy operation from userspace to kernel is now already done in the syscall handler. So it is always done. Previously it was copied over and validated before the first use (when used at all). So we have some additional instructions now that may be unnecessary, but that simplifies the code.

- Validation: Switched to timespec64_valid() instead of our own check.

Fixes 8043eccd232d ("cobalt/kernel: y2038: convert struct timespec to timespec64")
---
 kernel/cobalt/posix/sem.c       | 40 +++++++++++++++------------------
 kernel/cobalt/posix/sem.h       |  6 ++---
 kernel/cobalt/posix/syscall32.c | 10 +++++++--
 kernel/cobalt/posix/syscall32.h |  2 +-
 4 files changed, 29 insertions(+), 29 deletions(-)
kernel/cobalt/posix/sem.c +3 -12
index 467a9b7dd..827a4751a 100644
@@ -267,20 +267,11 @@ out:
 	return ret;
 }
 
-static inline int sem_fetch_timeout(struct timespec64 *ts,
-				    const void __user *u_ts)
-{
-	return u_ts == NULL ? -EFAULT :
-		cobalt_copy_from_user(ts, u_ts, sizeof(*ts));
-}
-
 int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem,
-			   const void __user *u_ts,
-			   int (*fetch_timeout)(struct timespec64 *ts,
-						const void __user *u_ts))
+			   const struct timespec64 *ts)
 {
-	struct timespec64 ts = { .tv_sec = 0, .tv_nsec = 0 };
-	int pull_ts = 1, ret, info;
+	int ret, info;
+	bool validate_ts = true;
 	struct cobalt_sem *sem;
 	xnhandle_t handle;
 	xntmode_t tmode;

kernel/cobalt/posix/sem.c int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem, · line 312

Quoted 10 lines
kernel/cobalt/posix/sem.c +1 -5
@@ -304,24 +295,23 @@ int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem,
 		 * it's actually more complex, to keep some
 		 * applications ported to Linux happy.
 		 */
-		if (pull_ts) {
+		if (validate_ts) {
 			atomic_inc(&sem->state->value);
-			xnlock_put_irqrestore(&nklock, s);
-			ret = fetch_timeout(&ts, u_ts);
-			xnlock_get_irqsave(&nklock, s);
-			if (ret)

As mentioned in a previous comment on this series, this type of patch is subtly changing where the core currently stands with respect to a peculiar POSIX compliance issue. Checking the content of a valid timespec struct is currently postponed until the timeout is needed, but the validity of the timespec pointer referring to that information is checked as late as possible too.

If the code now pre-loads the timespec struct early on in the syscall path, before the timed services are called, the pointer is explicitly checked for validity before we can decide if that timeout information is going to be used.

e.g.

struct timespec ts = { .tv_sec = 0, .tv_nsec = 1000000000 }; sem_init(&sem, 0, 0);
sem_post(&sem);
sem_timedwait(&sem, &ts); /* should not fail, and won't as expected. */

but,

sem_init(&sem, 0, 0);
sem_post(&sem);
sem_timedwait(&sem, (void *)0xdeadbeefUL); /* should not fail, but will. */

Since the standard does not mandates such behavior but seems to tag it as an implementation-dependent option ("The validity of the abstime need not be checked if..."), the change would still be acceptable POSIX-wise I believe. However, I'm pretty sure that there are POSIX compliance test suites around which would start reporting failures due to this change.

Signature · 1 line
Philippe.
#27 lore raw

Re: [RFC PATCH v2 1/4] y2038: Fixing the sem_timedwait syscall for 32 bit systems

Quoted 70 lines · Philippe Gerum
Quoted 68 lines · Florian Bezdeka

On systems using 32 bit for time_t the sem_timedwait syscall was broken because the function used for copying the timeout value from userspace to kernel (=sem_fetch_timeout()) was always copying sizeof(struct timespec64).

A 32 bit application (or more specific an application with 4 byte time_t) would only provide sizeof(struct old_timespec32).

Notable changes:
  - The copy operation from userspace to kernel is now already done in the syscall handler. So it is always done. Previously it was copied over and validated before the first use (when used at all). So we have some additional instructions now that may be unnecessary, but that simplifies the code.

  - Validation: Switched to timespec64_valid() instead of our own check.

Fixes 8043eccd232d ("cobalt/kernel: y2038: convert struct timespec to timespec64")

---

 kernel/cobalt/posix/sem.c       | 40 +++++++++++++++------------------
 kernel/cobalt/posix/sem.h       |  6 ++---
 kernel/cobalt/posix/syscall32.c | 10 +++++++--
 kernel/cobalt/posix/syscall32.h |  2 +-
 4 files changed, 29 insertions(+), 29 deletions(-)
kernel/cobalt/posix/sem.c +0 -0
index 467a9b7dd..827a4751a 100644
@@ -267,20 +267,11 @@ out:
  	return ret;
  }

kernel/cobalt/posix/sem.c +0 -7
-static inline int sem_fetch_timeout(struct timespec64 *ts,
-				    const void __user *u_ts)
-{
-	return u_ts == NULL ? -EFAULT :
-		cobalt_copy_from_user(ts, u_ts, sizeof(*ts));
-}
-

 int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem,

kernel/cobalt/posix/sem.c +1 -3
-			   const void __user *u_ts,
-			   int (*fetch_timeout)(struct timespec64 *ts,
-						const void __user *u_ts))
+			   const struct timespec64 *ts)

 {

kernel/cobalt/posix/sem.c +2 -2
-	struct timespec64 ts = { .tv_sec = 0, .tv_nsec = 0 };
-	int pull_ts = 1, ret, info;
+	int ret, info;
+	bool validate_ts = true;

  struct cobalt_sem *sem;
  xnhandle_t handle;
  xntmode_t tmode;

kernel/cobalt/posix/sem.c +1 -4
@@ -304,24 +295,23 @@ int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem,
  		 * it's actually more complex, to keep some
  		 * applications ported to Linux happy.
  		 */
-		if (pull_ts) {
+		if (validate_ts) {
  			atomic_inc(&sem->state->value);
-			xnlock_put_irqrestore(&nklock, s);
-			ret = fetch_timeout(&ts, u_ts);
-			xnlock_get_irqsave(&nklock, s);
Quoted 8 lines

kernel/cobalt/posix/sem.c int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem, · line 312

Quoted 1 line
kernel/cobalt/posix/sem.c +0 -1
-			if (ret)

As mentioned in a previous comment on this series, this type of patch is subtly changing where the core currently stands with respect to a peculiar POSIX compliance issue. Checking the content of a valid timespec struct is currently postponed until the timeout is needed, but the validity of the timespec pointer referring to that information is checked as late as possible too.

I took care of that comment. Please note that "ts" supplied to __cobalt_sem_timedwait() is non NULL only if it could be properly read. If the read failed (inside the handler) we will not return an error. The error will occur when trying to validate later.

Quoted 6 lines

If the code now pre-loads the timespec struct early on in the syscall path, before the timed services are called, the pointer is explicitly checked for validity before we can decide if that timeout information is going to be used.

Quoted 6 lines

e.g.

struct timespec ts = { .tv_sec = 0, .tv_nsec = 1000000000 }; sem_init(&sem, 0, 0);
sem_post(&sem);
sem_timedwait(&sem, &ts); /* should not fail, and won't as expected. */

This is already part of the smokey y2038 plugin, and does not fail.

Quoted 7 lines

but,

sem_init(&sem, 0, 0);
sem_post(&sem);
sem_timedwait(&sem, (void *)0xdeadbeefUL); /* should not fail, but will. */

This is not yet part of the y2038 smokey tests, but works (= does not fail). I will add it to the tests as well.

Quoted 7 lines

Since the standard does not mandates such behavior but seems to tag it as an implementation-dependent option ("The validity of the abstime need not be checked if..."), the change would still be acceptable POSIX-wise I believe. However, I'm pretty sure that there are POSIX compliance test suites around which would start reporting failures due to this change.

#28 lore raw

RFC PATCH v2 2/4 y2038: Adding sem_timedwait_time64

In reply to Florian Bezdeka

Implementation is heavily inspired by the sem_timedwait syscall, but expecting time64 based timespec / timeout.

We need two new syscall handlers:
- The native one (COBALT_SYSCALL()) to get 32 bit kernels time64 aware. This handler is added for 64 bit kernels as well, but not used. As we don't have separate syscall tables for this both worlds we have to add it.

- The compat handler (COBALT_SYSCALL32emu()) for x32 or x86 applications running on an x86_64 kernel. Otherwise the redirection to the compat / emulation syscalls is broken.

---
 include/cobalt/uapi/syscall.h                 |  1 +
 .../include/asm-generic/xenomai/syscall.h     | 23 +++++++++++++++++++
 kernel/cobalt/posix/sem.c                     | 13 +++++++++++
 kernel/cobalt/posix/sem.h                     |  4 ++++
 kernel/cobalt/posix/syscall32.c               | 13 +++++++++++
 kernel/cobalt/posix/syscall32.h               |  4 ++++
 6 files changed, 58 insertions(+)
include/cobalt/uapi/syscall.h +1 -0
index aa3c308d0..9b005da47 100644
@@ -122,6 +122,7 @@
 #define sc_cobalt_sendmmsg			99
 #define sc_cobalt_clock_adjtime			100
 #define sc_cobalt_thread_setschedprio		101
+#define sc_cobalt_sem_timedwait_time64		102
 
 #define __NR_COBALT_SYSCALLS			128 /* Power of 2 */
 
kernel/cobalt/include/asm-generic/xenomai/syscall.h +23 -0
index 91bbf3bfd..40d64b7a1 100644
@@ -19,6 +19,7 @@
 #ifndef _COBALT_ASM_GENERIC_SYSCALL_H
 #define _COBALT_ASM_GENERIC_SYSCALL_H
 
+#include <linux/compat.h>
 #include <linux/types.h>
 #include <linux/version.h>
 #include <linux/uaccess.h>
@@ -82,6 +83,28 @@ static inline int cobalt_strncpy_from_user(char *dst, const char __user *src,
 	return __xn_strncpy_from_user(dst, src, count);
 }
 
+static inline int cobalt_get_timespec64(struct timespec64 *ts,
+				const struct __kernel_timespec __user *uts)
+{
+	struct __kernel_timespec kts;
+	int ret;
+
+	ret = cobalt_copy_from_user(&kts, uts, sizeof(kts));
+	if (ret)
+		return -EFAULT;
+
+	ts->tv_sec = kts.tv_sec;
+
+	/* Zero out the padding in compat mode */
+	if (in_compat_syscall())
+		kts.tv_nsec &= 0xFFFFFFFFUL;
+
+	/* In 32-bit mode, this drops the padding */
+	ts->tv_nsec = kts.tv_nsec;
+
+	return 0;
+}
+
 #if __BITS_PER_LONG == 64
 
 /*
kernel/cobalt/posix/sem.c +13 -0
index 827a4751a..3055a456d 100644
@@ -435,6 +435,19 @@ COBALT_SYSCALL(sem_timedwait, primary,
 	return __cobalt_sem_timedwait(u_sem, ret ? NULL : &ts64);
 }
 
+COBALT_SYSCALL(sem_timedwait_time64, primary,
+	       (struct cobalt_sem_shadow __user *u_sem,
+		const struct __kernel_timespec __user *u_ts))
+{
+	int ret = 1;
+	struct timespec64 ts64;
+
+	if (u_ts)
+		ret = cobalt_get_timespec64(&ts64, u_ts);
+
+	return __cobalt_sem_timedwait(u_sem, ret ? NULL : &ts64);
+}
+
 COBALT_SYSCALL(sem_trywait, primary,
 	       (struct cobalt_sem_shadow __user *u_sem))
 {
kernel/cobalt/posix/sem.h +4 -0
index 658e11f7a..8491b69ba 100644
@@ -66,6 +66,10 @@ __cobalt_sem_open(struct cobalt_sem_shadow __user *usm,
 int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem,
 			   const struct timespec64 *ts);
 
+COBALT_SYSCALL_DECL(sem_timedwait_time64,
+		    (struct cobalt_sem_shadow __user *u_sem,
+		     const struct __kernel_timespec __user *u_ts));
+
 int __cobalt_sem_destroy(xnhandle_t handle);
 
 void cobalt_nsem_reclaim(struct cobalt_process *process);
kernel/cobalt/posix/syscall32.c +13 -0
index edac7ea4a..f73bfcda3 100644
@@ -135,6 +135,19 @@ COBALT_SYSCALL32emu(sem_timedwait, primary,
 	return __cobalt_sem_timedwait(u_sem, ret ? NULL : &ts64);
 }
 
+COBALT_SYSCALL32emu(sem_timedwait_time64, primary,
+		    (struct cobalt_sem_shadow __user *u_sem,
+		     const struct __kernel_timespec __user *u_ts))
+{
+	int ret = 1;
+	struct timespec64 ts64;
+
+	if (u_ts)
+		ret = cobalt_get_timespec64(&ts64, u_ts);
+
+	return __cobalt_sem_timedwait(u_sem, ret ? NULL : &ts64);
+}
+
 COBALT_SYSCALL32emu(clock_getres, current,
 		    (clockid_t clock_id,
 		     struct old_timespec32 __user *u_ts))
kernel/cobalt/posix/syscall32.h +4 -0
index d72fd2022..3612bf751 100644
@@ -231,4 +231,8 @@ COBALT_SYSCALL32emu_DECL(sem_timedwait,
 			 (struct cobalt_sem_shadow __user *u_sem,
 			  const struct old_timespec32 __user *u_ts));
 
+COBALT_SYSCALL32emu_DECL(sem_timedwait_time64,
+			 (struct cobalt_sem_shadow __user * u_sem,
+			  const struct __kernel_timespec __user *u_ts));
+
 #endif /* !_COBALT_POSIX_SYSCALL32_H */
Signature · 1 line
2.29.2
#29 lore raw

Re: [RFC PATCH v2 2/4] y2038: Adding sem_timedwait_time64

Quoted 28 lines · Florian Bezdeka

Implementation is heavily inspired by the sem_timedwait syscall, but expecting time64 based timespec / timeout.

We need two new syscall handlers:
- The native one (COBALT_SYSCALL()) to get 32 bit kernels time64 aware. This handler is added for 64 bit kernels as well, but not used. As we don't have separate syscall tables for this both worlds we have to add it.

- The compat handler (COBALT_SYSCALL32emu()) for x32 or x86 applications running on an x86_64 kernel. Otherwise the redirection to the compat / emulation syscalls is broken.

---
 include/cobalt/uapi/syscall.h                 |  1 +
 .../include/asm-generic/xenomai/syscall.h     | 23 +++++++++++++++++++
 kernel/cobalt/posix/sem.c                     | 13 +++++++++++
 kernel/cobalt/posix/sem.h                     |  4 ++++
 kernel/cobalt/posix/syscall32.c               | 13 +++++++++++
 kernel/cobalt/posix/syscall32.h               |  4 ++++
 6 files changed, 58 insertions(+)
include/cobalt/uapi/syscall.h +0 -0
index aa3c308d0..9b005da47 100644

include/cobalt/uapi/syscall.h line 125

Quoted 4 lines
include/cobalt/uapi/syscall.h +1 -0
@@ -122,6 +122,7 @@
 #define sc_cobalt_sendmmsg			99
 #define sc_cobalt_clock_adjtime			100
 #define sc_cobalt_thread_setschedprio		101
+#define sc_cobalt_sem_timedwait_time64		102

Maybe just sc_cobalt_sem_timedwait64?

How many additional calls are probably required?

Quoted 31 lines
include/cobalt/uapi/syscall.h +0 -0
 #define __NR_COBALT_SYSCALLS			128 /* Power of 2 */
 
kernel/cobalt/include/asm-generic/xenomai/syscall.h +13 -0
index 91bbf3bfd..40d64b7a1 100644
@@ -19,6 +19,7 @@
 #ifndef _COBALT_ASM_GENERIC_SYSCALL_H
 #define _COBALT_ASM_GENERIC_SYSCALL_H
 
+#include <linux/compat.h>
 #include <linux/types.h>
 #include <linux/version.h>
 #include <linux/uaccess.h>
@@ -82,6 +83,28 @@ static inline int cobalt_strncpy_from_user(char *dst, const char __user *src,
 	return __xn_strncpy_from_user(dst, src, count);
 }
 
+static inline int cobalt_get_timespec64(struct timespec64 *ts,
+				const struct __kernel_timespec __user *uts)
+{
+	struct __kernel_timespec kts;
+	int ret;
+
+	ret = cobalt_copy_from_user(&kts, uts, sizeof(kts));
+	if (ret)
+		return -EFAULT;
+
+	ts->tv_sec = kts.tv_sec;
+

kernel/cobalt/include/asm-generic/xenomai/syscall.h static inline int cobalt_strncpy_from_user(char *dst, const char __user *src, · line 107

Quoted 10 lines
kernel/cobalt/include/asm-generic/xenomai/syscall.h +10 -0
+	/* Zero out the padding in compat mode */
+	if (in_compat_syscall())
+		kts.tv_nsec &= 0xFFFFFFFFUL;
+
+	/* In 32-bit mode, this drops the padding */
+	ts->tv_nsec = kts.tv_nsec;
+
+	return 0;
+}
+

Why inline? But that question is likely obsolete when we can avoid the code duplication below.

Quoted 52 lines
kernel/cobalt/include/asm-generic/xenomai/syscall.h +0 -0
 #if __BITS_PER_LONG == 64
 
 /*
kernel/cobalt/posix/sem.c +13 -0
index 827a4751a..3055a456d 100644
@@ -435,6 +435,19 @@ COBALT_SYSCALL(sem_timedwait, primary,
 	return __cobalt_sem_timedwait(u_sem, ret ? NULL : &ts64);
 }
 
+COBALT_SYSCALL(sem_timedwait_time64, primary,
+	       (struct cobalt_sem_shadow __user *u_sem,
+		const struct __kernel_timespec __user *u_ts))
+{
+	int ret = 1;
+	struct timespec64 ts64;
+
+	if (u_ts)
+		ret = cobalt_get_timespec64(&ts64, u_ts);
+
+	return __cobalt_sem_timedwait(u_sem, ret ? NULL : &ts64);
+}
+
 COBALT_SYSCALL(sem_trywait, primary,
 	       (struct cobalt_sem_shadow __user *u_sem))
 {
kernel/cobalt/posix/sem.h +4 -0
index 658e11f7a..8491b69ba 100644
@@ -66,6 +66,10 @@ __cobalt_sem_open(struct cobalt_sem_shadow __user *usm,
 int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem,
 			   const struct timespec64 *ts);
 
+COBALT_SYSCALL_DECL(sem_timedwait_time64,
+		    (struct cobalt_sem_shadow __user *u_sem,
+		     const struct __kernel_timespec __user *u_ts));
+
 int __cobalt_sem_destroy(xnhandle_t handle);
 
 void cobalt_nsem_reclaim(struct cobalt_process *process);
kernel/cobalt/posix/syscall32.c +2 -0
index edac7ea4a..f73bfcda3 100644
@@ -135,6 +135,19 @@ COBALT_SYSCALL32emu(sem_timedwait, primary,
 	return __cobalt_sem_timedwait(u_sem, ret ? NULL : &ts64);
 }
 
+COBALT_SYSCALL32emu(sem_timedwait_time64, primary,
+		    (struct cobalt_sem_shadow __user *u_sem,

kernel/cobalt/posix/syscall32.c COBALT_SYSCALL32emu(sem_timedwait, primary, · line 149

Quoted 10 lines
kernel/cobalt/posix/syscall32.c +10 -0
+		     const struct __kernel_timespec __user *u_ts))
+{
+	int ret = 1;
+	struct timespec64 ts64;
+
+	if (u_ts)
+		ret = cobalt_get_timespec64(&ts64, u_ts);
+
+	return __cobalt_sem_timedwait(u_sem, ret ? NULL : &ts64);
+}

Why do we need to code this out twice? I don't spot the difference to the native implementation yet. Can't we point to it directly?

Quoted 10 lines
kernel/cobalt/posix/syscall32.c +1 -0
+
 COBALT_SYSCALL32emu(clock_getres, current,
 		    (clockid_t clock_id,
 		     struct old_timespec32 __user *u_ts))
kernel/cobalt/posix/syscall32.h +0 -0
index d72fd2022..3612bf751 100644

kernel/cobalt/posix/syscall32.h COBALT_SYSCALL32emu_DECL(sem_timedwait, · line 238

Quoted 8 lines
kernel/cobalt/posix/syscall32.h +4 -0
@@ -231,4 +231,8 @@ COBALT_SYSCALL32emu_DECL(sem_timedwait,
 			 (struct cobalt_sem_shadow __user *u_sem,
 			  const struct old_timespec32 __user *u_ts));
 
+COBALT_SYSCALL32emu_DECL(sem_timedwait_time64,
+			 (struct cobalt_sem_shadow __user * u_sem,
+			  const struct __kernel_timespec __user *u_ts));
+
 #endif /* !_COBALT_POSIX_SYSCALL32_H */

Jan

Signature · 2 lines
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux
#30 lore raw

Re: [RFC PATCH v2 2/4] y2038: Adding sem_timedwait_time64

Quoted 36 lines · Jan Kiszka
Quoted 28 lines · Florian Bezdeka

Implementation is heavily inspired by the sem_timedwait syscall, but expecting time64 based timespec / timeout.

We need two new syscall handlers:
  - The native one (COBALT_SYSCALL()) to get 32 bit kernels time64 aware. This handler is added for 64 bit kernels as well, but not used. As we don't have separate syscall tables for this both worlds we have to add it.

 - The compat handler (COBALT_SYSCALL32emu()) for x32 or x86 applications running on an x86_64 kernel. Otherwise the redirection to the compat / emulation syscalls is broken.

---

 include/cobalt/uapi/syscall.h                 |  1 +
 .../include/asm-generic/xenomai/syscall.h     | 23 +++++++++++++++++++
 kernel/cobalt/posix/sem.c                     | 13 +++++++++++
 kernel/cobalt/posix/sem.h                     |  4 ++++
 kernel/cobalt/posix/syscall32.c               | 13 +++++++++++
 kernel/cobalt/posix/syscall32.h               |  4 ++++
 6 files changed, 58 insertions(+)
include/cobalt/uapi/syscall.h +0 -0
index aa3c308d0..9b005da47 100644

include/cobalt/uapi/syscall.h line 125

Quoted 4 lines
include/cobalt/uapi/syscall.h +1 -0
@@ -122,6 +122,7 @@
  #define sc_cobalt_sendmmsg			99
  #define sc_cobalt_clock_adjtime			100
  #define sc_cobalt_thread_setschedprio		101
+#define sc_cobalt_sem_timedwait_time64		102

Maybe just sc_cobalt_sem_timedwait64?

Quoted 1 line

How many additional calls are probably required?

Yes, we can shrink to the "64" suffix instead of "time64" if you prefer.

We have identified 15 syscalls so far.

Quoted 36 lines
Quoted 36 lines
include/cobalt/uapi/syscall.h +0 -0
  #define __NR_COBALT_SYSCALLS			128 /* Power of 2 */

kernel/cobalt/include/asm-generic/xenomai/syscall.h +1 -0
index 91bbf3bfd..40d64b7a1 100644
@@ -19,6 +19,7 @@
  #ifndef _COBALT_ASM_GENERIC_SYSCALL_H
  #define _COBALT_ASM_GENERIC_SYSCALL_H
 
+#include <linux/compat.h>
  #include <linux/types.h>
  #include <linux/version.h>
  #include <linux/uaccess.h>
@@ -82,6 +83,28 @@ static inline int cobalt_strncpy_from_user(char *dst, const char __user *src,
  	return __xn_strncpy_from_user(dst, src, count);
  }

kernel/cobalt/include/asm-generic/xenomai/syscall.h +17 -0
+static inline int cobalt_get_timespec64(struct timespec64 *ts,
+				const struct __kernel_timespec __user *uts)
+{
+	struct __kernel_timespec kts;
+	int ret;
+
+	ret = cobalt_copy_from_user(&kts, uts, sizeof(kts));
+	if (ret)
+		return -EFAULT;
+
+	ts->tv_sec = kts.tv_sec;
+
+	/* Zero out the padding in compat mode */
+	if (in_compat_syscall())
+		kts.tv_nsec &= 0xFFFFFFFFUL;
+
+	/* In 32-bit mode, this drops the padding */
Quoted 8 lines

kernel/cobalt/include/asm-generic/xenomai/syscall.h static inline int cobalt_strncpy_from_user(char *dst, const char __user *src, · line 107

Quoted 5 lines
kernel/cobalt/include/asm-generic/xenomai/syscall.h +5 -0
+	ts->tv_nsec = kts.tv_nsec;
+
+	return 0;
+}
+

Why inline? But that question is likely obsolete when we can avoid the code duplication below.

Inline can be removed. Something for v3. There will follow more calls to that helper. All syscalls reading a struct timespec from userspace will have to use it.

Quoted 54 lines
Quoted 54 lines

 #if __BITS_PER_LONG == 64

 /*

kernel/cobalt/posix/sem.c +0 -0
index 827a4751a..3055a456d 100644
@@ -435,6 +435,19 @@ COBALT_SYSCALL(sem_timedwait, primary,
  	return __cobalt_sem_timedwait(u_sem, ret ? NULL : &ts64);
  }

kernel/cobalt/posix/sem.c +13 -0
+COBALT_SYSCALL(sem_timedwait_time64, primary,
+	       (struct cobalt_sem_shadow __user *u_sem,
+		const struct __kernel_timespec __user *u_ts))
+{
+	int ret = 1;
+	struct timespec64 ts64;
+
+	if (u_ts)
+		ret = cobalt_get_timespec64(&ts64, u_ts);
+
+	return __cobalt_sem_timedwait(u_sem, ret ? NULL : &ts64);
+}
+

 COBALT_SYSCALL(sem_trywait, primary,
  (struct cobalt_sem_shadow __user *u_sem)) {

kernel/cobalt/posix/sem.h +0 -0
index 658e11f7a..8491b69ba 100644
@@ -66,6 +66,10 @@ __cobalt_sem_open(struct cobalt_sem_shadow __user *usm,
  int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem,
  			   const struct timespec64 *ts);

kernel/cobalt/posix/sem.h +4 -0
+COBALT_SYSCALL_DECL(sem_timedwait_time64,
+		    (struct cobalt_sem_shadow __user *u_sem,
+		     const struct __kernel_timespec __user *u_ts));
+

 int __cobalt_sem_destroy(xnhandle_t handle);

 void cobalt_nsem_reclaim(struct cobalt_process *process);

kernel/cobalt/posix/syscall32.c +0 -0
index edac7ea4a..f73bfcda3 100644
@@ -135,6 +135,19 @@ COBALT_SYSCALL32emu(sem_timedwait, primary,
  	return __cobalt_sem_timedwait(u_sem, ret ? NULL : &ts64);
  }

Quoted 15 lines

kernel/cobalt/posix/syscall32.c COBALT_SYSCALL32emu(sem_timedwait, primary, · line 149

Quoted 12 lines
kernel/cobalt/posix/syscall32.c +12 -0
+COBALT_SYSCALL32emu(sem_timedwait_time64, primary,
+		    (struct cobalt_sem_shadow __user *u_sem,
+		     const struct __kernel_timespec __user *u_ts))
+{
+	int ret = 1;
+	struct timespec64 ts64;
+
+	if (u_ts)
+		ret = cobalt_get_timespec64(&ts64, u_ts);
+
+	return __cobalt_sem_timedwait(u_sem, ret ? NULL : &ts64);
+}

Why do we need to code this out twice? I don't spot the difference to the native implementation yet. Can't we point to it directly?

AFAIK we can't point to the same handler. That's how the internal creation of the syscall table works. The "compat interfaces" of Linux and Xenomai are different. Linux has a syscall table for each entry point while Xenomai has only a single table, where compat syscalls are located at a specific offset.

We need one handler defined by COBALT_SYSCALL() and one defined by COBALT_SYSCALL32emu().

As all the "64 bit always" related will have the same content we could move the content into a function that is being called from both handlers. Will do...

Thanks for the feedback / review!

Quoted 23 lines
Quoted 18 lines

+
 COBALT_SYSCALL32emu(clock_getres, current, (clockid_t clock_id,
  struct old_timespec32 __user *u_ts))

kernel/cobalt/posix/syscall32.h +0 -0
index d72fd2022..3612bf751 100644
@@ -231,4 +231,8 @@ COBALT_SYSCALL32emu_DECL(sem_timedwait,
  			 (struct cobalt_sem_shadow __user *u_sem,
  			  const struct old_timespec32 __user *u_ts));

kernel/cobalt/posix/syscall32.h +4 -0
+COBALT_SYSCALL32emu_DECL(sem_timedwait_time64,
+			 (struct cobalt_sem_shadow __user * u_sem,
+			  const struct __kernel_timespec __user *u_ts));
+
Quoted 2 lines

 #endif /* !_COBALT_POSIX_SYSCALL32_H */

Jan

#31 lore raw

Re: [RFC PATCH v2 2/4] y2038: Adding sem_timedwait_time64

Quoted 36 lines · florian.bezdeka--- via Xenomai
Quoted 26 lines · Jan Kiszka
Quoted 25 lines · Florian Bezdeka

Implementation is heavily inspired by the sem_timedwait syscall, but expecting time64 based timespec / timeout.

[snip]

kernel/cobalt/include/asm-generic/xenomai/syscall.h +0 -0
@@ -82,6 +83,28 @@ static inline int cobalt_strncpy_from_user(char *dst, const char __user *src,
  	return __xn_strncpy_from_user(dst, src, count);
  }

kernel/cobalt/include/asm-generic/xenomai/syscall.h +17 -0
+static inline int cobalt_get_timespec64(struct timespec64 *ts,
+				const struct __kernel_timespec __user *uts)
+{
+	struct __kernel_timespec kts;
+	int ret;
+
+	ret = cobalt_copy_from_user(&kts, uts, sizeof(kts));
+	if (ret)
+		return -EFAULT;
+
+	ts->tv_sec = kts.tv_sec;
+
+	/* Zero out the padding in compat mode */
+	if (in_compat_syscall())
+		kts.tv_nsec &= 0xFFFFFFFFUL;
+
+	/* In 32-bit mode, this drops the padding */
Quoted 8 lines

kernel/cobalt/include/asm-generic/xenomai/syscall.h static inline int cobalt_strncpy_from_user(char *dst, const char __user *src, · line 107

Quoted 5 lines
kernel/cobalt/include/asm-generic/xenomai/syscall.h +5 -0
+	ts->tv_nsec = kts.tv_nsec;
+
+	return 0;
+}
+

Why inline? But that question is likely obsolete when we can avoid the code duplication below.

Quoted 4 lines

Inline can be removed. Something for v3. There will follow more calls to that helper. All syscalls reading a struct timespec from userspace will have to use it.

Quoted 1 line
Quoted 1 line

I was following the pattern of all the other struct timespec64 heplers introduced by Philippe here. So "static inline". Removing "inline" now throws some warnings (at least on gcc 10), because the function is unused in this file.

So my question is now: Where should this function reside?

Linux pattern: kernel/time/time.c (where get_timespec64 resides) Xenomai path would be kernel/cobalt/time.c

This is the last thing I have to address. A non RFC series will follow afterwards, based on Philippe's tree.

@Song: My hope was this series can be used as pattern, to start integration of all the other remaining parts. What do you think? Is that sufficient?
-

#32 lore raw

Re: [RFC PATCH v2 2/4] y2038: Adding sem_timedwait_time64

Quoted 53 lines · florian.bezdeka--- via Xenomai
Quoted 36 lines · florian.bezdeka--- via Xenomai
Quoted 26 lines · Jan Kiszka
Quoted 25 lines · Florian Bezdeka

Implementation is heavily inspired by the sem_timedwait syscall, but expecting time64 based timespec / timeout.

[snip]

kernel/cobalt/include/asm-generic/xenomai/syscall.h +17 -0
@@ -82,6 +83,28 @@ static inline int cobalt_strncpy_from_user(char *dst, const char __user *src,
  	return __xn_strncpy_from_user(dst, src, count);
  }
 
+static inline int cobalt_get_timespec64(struct timespec64 *ts,
+				const struct __kernel_timespec __user *uts)
+{
+	struct __kernel_timespec kts;
+	int ret;
+
+	ret = cobalt_copy_from_user(&kts, uts, sizeof(kts));
+	if (ret)
+		return -EFAULT;
+
+	ts->tv_sec = kts.tv_sec;
+
+	/* Zero out the padding in compat mode */
+	if (in_compat_syscall())
+		kts.tv_nsec &= 0xFFFFFFFFUL;
+
+	/* In 32-bit mode, this drops the padding */
Quoted 8 lines

kernel/cobalt/include/asm-generic/xenomai/syscall.h static inline int cobalt_strncpy_from_user(char *dst, const char __user *src, · line 107

Quoted 5 lines
kernel/cobalt/include/asm-generic/xenomai/syscall.h +5 -0
+	ts->tv_nsec = kts.tv_nsec;
+
+	return 0;
+}
+

Why inline? But that question is likely obsolete when we can avoid the code duplication below.

Quoted 4 lines

Inline can be removed. Something for v3. There will follow more calls to that helper. All syscalls reading a struct timespec from userspace will have to use it.

Quoted 1 line
Quoted 1 line

I was following the pattern of all the other struct timespec64 heplers introduced by Philippe here. So "static inline". Removing "inline" now throws some warnings (at least on gcc 10), because the function is unused in this file.

So my question is now: Where should this function reside?

Linux pattern: kernel/time/time.c (where get_timespec64 resides) Xenomai path would be kernel/cobalt/time.c

Quoted 6 lines

This is the last thing I have to address. A non RFC series will follow afterwards, based on Philippe's tree.

@Song: My hope was this series can be used as pattern, to start integration of all the other remaining parts. What do you think? Is that sufficient?

This series look good to me and i'm following it to work on my patches.

Song

Quoted 2 lines

-

#33 lore raw

RFC PATCH v2 3/4 y2038: Add tests for the sc_cobalt_sem_timedwait_time64 syscall

In reply to Florian Bezdeka

Introducing a new smokey plugin that can be extended for all kind of y2038 tests.

---
 configure.ac                           |   1 +
 testsuite/smokey/Makefile.am           |   6 +-
 testsuite/smokey/y2038/Makefile.am     |  10 ++
 testsuite/smokey/y2038/syscall-tests.c | 170 +++++++++++++++++++++++++
 4 files changed, 185 insertions(+), 2 deletions(-)
 create mode 100644 testsuite/smokey/y2038/Makefile.am
 create mode 100644 testsuite/smokey/y2038/syscall-tests.c
configure.ac +1 -0
index abe538dbd..bd5fd5ba9 100644
@@ -990,6 +990,7 @@ AC_CONFIG_FILES([ \
 	testsuite/smokey/net_common/Makefile \
 	testsuite/smokey/cpu-affinity/Makefile \
 	testsuite/smokey/gdb/Makefile \
+	testsuite/smokey/y2038/Makefile \
 	testsuite/clocktest/Makefile \
 	testsuite/xeno-test/Makefile \
 	utils/Makefile \
testsuite/smokey/Makefile.am +4 -2
index 02613c7dc..56c873026 100644
@@ -38,7 +38,8 @@ COBALT_SUBDIRS = 	\
 	timerfd		\
 	tsc		\
 	vdso-access 	\
-	xddp
+	xddp		\
+	y2038
 
 MERCURY_SUBDIRS =	\
 	memory-heapmem	\
@@ -76,7 +77,8 @@ DIST_SUBDIRS = 		\
 	timerfd		\
 	tsc		\
 	vdso-access 	\
-	xddp
+	xddp		\
+	y2038
 
 if XENO_COBALT
 if CONFIG_XENO_LIBS_DLOPEN
testsuite/smokey/y2038/Makefile.am new file +10 -0
new file mode 100644
index 000000000..a97591aa2
@@ -0,0 +1,10 @@
+
+noinst_LIBRARIES = liby2038.a
+
+liby2038_a_SOURCES = syscall-tests.c
+
+liby2038_a_CPPFLAGS = 	\
+	@XENO_USER_CFLAGS@	\
+	-I$(top_srcdir)		\
+	-I$(top_srcdir)/include
+
testsuite/smokey/y2038/syscall-tests.c new file +170 -0

170 lines not on this page · raw message

Signature · 1 line
2.29.2
#34 lore raw

Re: [RFC PATCH v2 3/4] y2038: Add tests for the sc_cobalt_sem_timedwait_time64 syscall

Quoted 2 lines · Florian Bezdeka

Introducing a new smokey plugin that can be extended for all kind of y2038 tests.

And what does this version test? Some more words on how the new syscall is stressed would be valuable here.

Quoted 155 lines
---
 configure.ac                           |   1 +
 testsuite/smokey/Makefile.am           |   6 +-
 testsuite/smokey/y2038/Makefile.am     |  10 ++
 testsuite/smokey/y2038/syscall-tests.c | 170 +++++++++++++++++++++++++
 4 files changed, 185 insertions(+), 2 deletions(-)
 create mode 100644 testsuite/smokey/y2038/Makefile.am
 create mode 100644 testsuite/smokey/y2038/syscall-tests.c
configure.ac +1 -0
index abe538dbd..bd5fd5ba9 100644
@@ -990,6 +990,7 @@ AC_CONFIG_FILES([ \
 	testsuite/smokey/net_common/Makefile \
 	testsuite/smokey/cpu-affinity/Makefile \
 	testsuite/smokey/gdb/Makefile \
+	testsuite/smokey/y2038/Makefile \
 	testsuite/clocktest/Makefile \
 	testsuite/xeno-test/Makefile \
 	utils/Makefile \
testsuite/smokey/Makefile.am +4 -2
index 02613c7dc..56c873026 100644
@@ -38,7 +38,8 @@ COBALT_SUBDIRS = 	\
 	timerfd		\
 	tsc		\
 	vdso-access 	\
-	xddp
+	xddp		\
+	y2038
 
 MERCURY_SUBDIRS =	\
 	memory-heapmem	\
@@ -76,7 +77,8 @@ DIST_SUBDIRS = 		\
 	timerfd		\
 	tsc		\
 	vdso-access 	\
-	xddp
+	xddp		\
+	y2038
 
 if XENO_COBALT
 if CONFIG_XENO_LIBS_DLOPEN
testsuite/smokey/y2038/Makefile.am new file +10 -0
new file mode 100644
index 000000000..a97591aa2
@@ -0,0 +1,10 @@
+
+noinst_LIBRARIES = liby2038.a
+
+liby2038_a_SOURCES = syscall-tests.c
+
+liby2038_a_CPPFLAGS = 	\
+	@XENO_USER_CFLAGS@	\
+	-I$(top_srcdir)		\
+	-I$(top_srcdir)/include
+
testsuite/smokey/y2038/syscall-tests.c new file +86 -0
new file mode 100644
index 000000000..0fc96374f
@@ -0,0 +1,170 @@
+/*
+ * y2038 tests
+ *
+ * Copyright (c) Siemens AG 2021
+ *
+ * Authors:
+ *  Florian Bezdeka <[email protected]>
+ *
+ * Released under the terms of GPLv2.
+ */
+#include <cobalt/uapi/syscall.h>
+#include <smokey/smokey.h>
+#include <semaphore.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <errno.h>
+
+smokey_test_plugin(y2038, SMOKEY_NOARGS, "Validate correct y2038 support");
+
+/*
+ * libc independent data type representing a time64_t based struct timespec
+ */
+struct xn_timespec64 {
+	int64_t tv_sec;
+	int64_t tv_nsec;
+};
+
+#define NSEC_PER_SEC 1000000000
+
+static void ts_normalise(struct xn_timespec64 *ts)
+{
+	while (ts->tv_nsec >= NSEC_PER_SEC) {
+		ts->tv_nsec += 1;
+		ts->tv_nsec -= NSEC_PER_SEC;
+	}
+
+	while (ts->tv_nsec <= -NSEC_PER_SEC) {
+		ts->tv_sec -= 1;
+		ts->tv_nsec += NSEC_PER_SEC;
+	}
+
+	if (ts->tv_nsec < 0) {
+		/*
+		 * Negative nanoseconds isn't valid according to POSIX.
+		 * Decrement tv_sec and roll tv_nsec over.
+		 */
+		ts->tv_sec -= 1;
+		ts->tv_nsec = (NSEC_PER_SEC + ts->tv_nsec);
+	}
+}
+
+static inline void ts_add_ns(struct xn_timespec64 *ts, int ns)
+{
+	ts->tv_nsec += ns;
+	ts_normalise(ts);
+}
+
+/**
+ * Compare two struct timespec instances
+ *
+ * @param a
+ * @param b
+ * @return True if a < b, false otherwise
+ */
+static inline bool ts_less(const struct xn_timespec64 *a,
+			   const struct xn_timespec64 *b)
+{
+	if (a->tv_sec < b->tv_sec)
+		return true;
+
+	if (a->tv_sec > b->tv_sec)
+		return false;
+
+	/* a->tv_sec == b->tv_sec */
+
+	if (a->tv_nsec < b->tv_nsec)
+		return true;
+
+	return false;
+}
+
+static int test_sc_cobalt_sem_timedwait_time64(void)
+{
+	long ret;
+	sem_t sem;
+	int code = __xn_syscode(sc_cobalt_sem_timedwait_time64);

testsuite/smokey/y2038/syscall-tests.c line 96

Quoted 10 lines
testsuite/smokey/y2038/syscall-tests.c new file +10 -0
+	struct xn_timespec64 ts64, ts_wu;
+	struct timespec ts_nat;
+
+	sem_init(&sem, 0, 0);
+
+	/*
+	 * TODO: Calling the syscall directly for now, as y2038 support is not
+	 * yet available in glibc. Once this is available we should use our
+	 * glibc wrappers provided by libcobalt.
+	 */

Maybe wrap that, to make the invocations more readable? Maybe a macro can do that in a way that will not affect the code once glibc is ready.

Quoted 51 lines
testsuite/smokey/y2038/syscall-tests.c new file +51 -0
+
+	/* Make sure we don't crash because of NULL pointers */
+	ret = syscall(code, NULL, NULL);
+	if (ret == -1 && errno == ENOSYS)
+		return 0; // Not implemented, nothing to test, success
+	if (!smokey_assert(ret == -1) || !smokey_assert(errno == EINVAL))
+		return errno;
+
+	/* Timeout is never read by the kernel, so NULL should be OK */
+	sem_post(&sem);
+	ret = syscall(code, &sem, NULL);
+	if (!smokey_assert(!ret))
+		return errno;
+
+	/*
+	 * The semaphore is already exhausted, so calling again will validate
+	 * the provided timeout now. Providing NULL has to deliver EFAULT
+	 */
+	ret = syscall(code, &sem, NULL);
+	if (!smokey_assert(ret == -1) || !smokey_assert(errno == EFAULT))
+		return errno;
+
+	/*
+	 * The semaphore is still exhausted, calling again will validate the
+	 * timeout, providing an invalid timeout has to deliver EINVAL
+	 */
+	ts64.tv_sec = -1;
+	ret = syscall(code, &sem, &ts64);
+	if (!smokey_assert(ret == -1) || !smokey_assert(errno == EINVAL))
+		return errno;
+
+	/*
+	 * Providing a valid timeout, waiting for it to time out and check
+	 * that we didn't come back to early.
+	 */
+	ret = clock_gettime(CLOCK_MONOTONIC, &ts_nat);
+	if (ret)
+		return errno;
+
+	ts64.tv_sec = ts_nat.tv_sec;
+	ts64.tv_nsec = ts_nat.tv_nsec;
+	ts_add_ns(&ts64, 500000);
+
+	ret = syscall(code, &sem, &ts64);
+	if (!smokey_assert(ret == -1) || !smokey_assert(errno == ETIMEDOUT))
+		return errno;
+
+	ret = clock_gettime(CLOCK_MONOTONIC, &ts_nat);
+	if (ret)
+		return errno;
+

testsuite/smokey/y2038/syscall-tests.c line 157

Quoted 10 lines
testsuite/smokey/y2038/syscall-tests.c new file +10 -0
+	ts_wu.tv_sec = ts_nat.tv_sec;
+	ts_wu.tv_nsec = ts_nat.tv_nsec;
+
+	if (ts_less(&ts_wu, &ts64))
+		smokey_warning("sem_timedwait_time64 returned to early!\n"
+			       "Expected wakeup at: %lld sec %lld nsec\n"
+			       "Back at           : %lld sec %lld nsec\n",
+			       ts64.tv_sec, ts64.tv_nsec, ts_wu.tv_sec,
+			       ts_wu.tv_nsec);
+

Does this already stress the 64-bit range of time_t? I don't spot that yet.

Quoted 4 lines
testsuite/smokey/y2038/syscall-tests.c new file +3 -0
+	return 0;
+}
+

testsuite/smokey/y2038/syscall-tests.c line 170

Quoted 10 lines
testsuite/smokey/y2038/syscall-tests.c new file +10 -0
+static int run_y2038(struct smokey_test *t, int argc, char *const argv[])
+{
+	int ret;
+
+	ret = test_sc_cobalt_sem_timedwait_time64();
+	if (ret)
+		return ret;
+
+	return 0;
+}

Such a test is obviously key to approach the issue correctly. It's a complex beast.

Jan

Signature · 2 lines
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux
#35 lore raw

Re: [RFC PATCH v2 3/4] y2038: Add tests for the sc_cobalt_sem_timedwait_time64 syscall

Quoted 6 lines · Jan Kiszka
Quoted 2 lines · Florian Bezdeka

Introducing a new smokey plugin that can be extended for all kind of y2038 tests.

And what does this version test? Some more words on how the new syscall is stressed would be valuable here.

Yes. Will do.

Quoted 175 lines
Quoted 175 lines

---

 configure.ac                           |   1 +
 testsuite/smokey/Makefile.am           |   6 +-
 testsuite/smokey/y2038/Makefile.am     |  10 ++
 testsuite/smokey/y2038/syscall-tests.c | 170 +++++++++++++++++++++++++
 4 files changed, 185 insertions(+), 2 deletions(-)

 create mode 100644 testsuite/smokey/y2038/Makefile.am create mode 100644 testsuite/smokey/y2038/syscall-tests.c

configure.ac +1 -0
index abe538dbd..bd5fd5ba9 100644
@@ -990,6 +990,7 @@ AC_CONFIG_FILES([ \
  	testsuite/smokey/net_common/Makefile \
  	testsuite/smokey/cpu-affinity/Makefile \
  	testsuite/smokey/gdb/Makefile \
+	testsuite/smokey/y2038/Makefile \
  	testsuite/clocktest/Makefile \
  	testsuite/xeno-test/Makefile \
  	utils/Makefile \
testsuite/smokey/Makefile.am +2 -1
index 02613c7dc..56c873026 100644
@@ -38,7 +38,8 @@ COBALT_SUBDIRS = 	\
  	timerfd		\
  	tsc		\
  	vdso-access 	\
-	xddp
+	xddp		\
+	y2038

 MERCURY_SUBDIRS = \
  memory-heapmem \

testsuite/smokey/Makefile.am +2 -1
@@ -76,7 +77,8 @@ DIST_SUBDIRS = 		\
  	timerfd		\
  	tsc		\
  	vdso-access 	\
-	xddp
+	xddp		\
+	y2038

 if XENO_COBALT
 if CONFIG_XENO_LIBS_DLOPEN

testsuite/smokey/y2038/Makefile.am new file +10 -0
new file mode 100644
index 000000000..a97591aa2
@@ -0,0 +1,10 @@
+
+noinst_LIBRARIES = liby2038.a
+
+liby2038_a_SOURCES = syscall-tests.c
+
+liby2038_a_CPPFLAGS = 	\
+	@XENO_USER_CFLAGS@	\
+	-I$(top_srcdir)		\
+	-I$(top_srcdir)/include
+
testsuite/smokey/y2038/syscall-tests.c new file +91 -0
new file mode 100644
index 000000000..0fc96374f
@@ -0,0 +1,170 @@
+/*
+ * y2038 tests
+ *
+ * Copyright (c) Siemens AG 2021
+ *
+ * Authors:
+ *  Florian Bezdeka <[email protected]>
+ *
+ * Released under the terms of GPLv2.
+ */
+#include <cobalt/uapi/syscall.h>
+#include <smokey/smokey.h>
+#include <semaphore.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <errno.h>
+
+smokey_test_plugin(y2038, SMOKEY_NOARGS, "Validate correct y2038 support");
+
+/*
+ * libc independent data type representing a time64_t based struct timespec
+ */
+struct xn_timespec64 {
+	int64_t tv_sec;
+	int64_t tv_nsec;
+};
+
+#define NSEC_PER_SEC 1000000000
+
+static void ts_normalise(struct xn_timespec64 *ts)
+{
+	while (ts->tv_nsec >= NSEC_PER_SEC) {
+		ts->tv_nsec += 1;
+		ts->tv_nsec -= NSEC_PER_SEC;
+	}
+
+	while (ts->tv_nsec <= -NSEC_PER_SEC) {
+		ts->tv_sec -= 1;
+		ts->tv_nsec += NSEC_PER_SEC;
+	}
+
+	if (ts->tv_nsec < 0) {
+		/*
+		 * Negative nanoseconds isn't valid according to POSIX.
+		 * Decrement tv_sec and roll tv_nsec over.
+		 */
+		ts->tv_sec -= 1;
+		ts->tv_nsec = (NSEC_PER_SEC + ts->tv_nsec);
+	}
+}
+
+static inline void ts_add_ns(struct xn_timespec64 *ts, int ns)
+{
+	ts->tv_nsec += ns;
+	ts_normalise(ts);
+}
+
+/**
+ * Compare two struct timespec instances
+ *
+ * @param a
+ * @param b
+ * @return True if a < b, false otherwise
+ */
+static inline bool ts_less(const struct xn_timespec64 *a,
+			   const struct xn_timespec64 *b)
+{
+	if (a->tv_sec < b->tv_sec)
+		return true;
+
+	if (a->tv_sec > b->tv_sec)
+		return false;
+
+	/* a->tv_sec == b->tv_sec */
+
+	if (a->tv_nsec < b->tv_nsec)
+		return true;
+
+	return false;
+}
+
+static int test_sc_cobalt_sem_timedwait_time64(void)
+{
+	long ret;
+	sem_t sem;
+	int code = __xn_syscode(sc_cobalt_sem_timedwait_time64);
+	struct xn_timespec64 ts64, ts_wu;
+	struct timespec ts_nat;
+
+	sem_init(&sem, 0, 0);
+
Quoted 8 lines

testsuite/smokey/y2038/syscall-tests.c line 96

Quoted 5 lines
testsuite/smokey/y2038/syscall-tests.c new file +5 -0
+	/*
+	 * TODO: Calling the syscall directly for now, as y2038 support is not
+	 * yet available in glibc. Once this is available we should use our
+	 * glibc wrappers provided by libcobalt.
+	 */

Maybe wrap that, to make the invocations more readable? Maybe a macro can do that in a way that will not affect the code once glibc is ready.

Not sure if that is possible, but will think about that. We shouldn't limit our implementation to glibc only, there are other implementations like musl out there as well.

The idea was to test the libcobalt libc wrappers here as well, but maybe that is not an good idea. Even glibc has the y2038 in the future it may not be activated by user code... So calling the syscall directly might be right thing to do here, and just remove the TODO comment.

Quoted 85 lines
Quoted 52 lines
testsuite/smokey/y2038/syscall-tests.c new file +51 -0
+
+	/* Make sure we don't crash because of NULL pointers */
+	ret = syscall(code, NULL, NULL);
+	if (ret == -1 && errno == ENOSYS)
+		return 0; // Not implemented, nothing to test, success
+	if (!smokey_assert(ret == -1) || !smokey_assert(errno == EINVAL))
+		return errno;
+
+	/* Timeout is never read by the kernel, so NULL should be OK */
+	sem_post(&sem);
+	ret = syscall(code, &sem, NULL);
+	if (!smokey_assert(!ret))
+		return errno;
+
+	/*
+	 * The semaphore is already exhausted, so calling again will validate
+	 * the provided timeout now. Providing NULL has to deliver EFAULT
+	 */
+	ret = syscall(code, &sem, NULL);
+	if (!smokey_assert(ret == -1) || !smokey_assert(errno == EFAULT))
+		return errno;
+
+	/*
+	 * The semaphore is still exhausted, calling again will validate the
+	 * timeout, providing an invalid timeout has to deliver EINVAL
+	 */
+	ts64.tv_sec = -1;
+	ret = syscall(code, &sem, &ts64);
+	if (!smokey_assert(ret == -1) || !smokey_assert(errno == EINVAL))
+		return errno;
+
+	/*
+	 * Providing a valid timeout, waiting for it to time out and check
+	 * that we didn't come back to early.
+	 */
+	ret = clock_gettime(CLOCK_MONOTONIC, &ts_nat);
+	if (ret)
+		return errno;
+
+	ts64.tv_sec = ts_nat.tv_sec;
+	ts64.tv_nsec = ts_nat.tv_nsec;
+	ts_add_ns(&ts64, 500000);
+
+	ret = syscall(code, &sem, &ts64);
+	if (!smokey_assert(ret == -1) || !smokey_assert(errno == ETIMEDOUT))
+		return errno;
+
+	ret = clock_gettime(CLOCK_MONOTONIC, &ts_nat);
+	if (ret)
+		return errno;
+

testsuite/smokey/y2038/syscall-tests.c line 157

Quoted 10 lines
testsuite/smokey/y2038/syscall-tests.c new file +10 -0
+	ts_wu.tv_sec = ts_nat.tv_sec;
+	ts_wu.tv_nsec = ts_nat.tv_nsec;
+
+	if (ts_less(&ts_wu, &ts64))
+		smokey_warning("sem_timedwait_time64 returned to early!\n"
+			       "Expected wakeup at: %lld sec %lld nsec\n"
+			       "Back at           : %lld sec %lld nsec\n",
+			       ts64.tv_sec, ts64.tv_nsec, ts_wu.tv_sec,
+			       ts_wu.tv_nsec);
+

Does this already stress the 64-bit range of time_t? I don't spot that yet.

Quoted 4 lines
testsuite/smokey/y2038/syscall-tests.c new file +3 -0
+	return 0;
+}
+

testsuite/smokey/y2038/syscall-tests.c line 170

Quoted 10 lines
testsuite/smokey/y2038/syscall-tests.c new file +10 -0
+static int run_y2038(struct smokey_test *t, int argc, char *const argv[])
+{
+	int ret;
+
+	ret = test_sc_cobalt_sem_timedwait_time64();
+	if (ret)
+		return ret;
+
+	return 0;
+}

Such a test is obviously key to approach the issue correctly. It's a complex beast.

Jan

#36 lore raw

RFC PATCH v2 4/4 y2038: lib/cobalt: Add support of sc_cobalt_sem_timedwait_time64

In reply to Florian Bezdeka

In case libcobalt is build with -D_TIME_BITS=64 sc_cobalt_sem_timedwait_time64 will be used instead of sc_cobalt_sem_timedwait.

---
 lib/cobalt/semaphore.c | 5 +++++
 1 file changed, 5 insertions(+)
lib/cobalt/semaphore.c +5 -0
index 45705d48f..7e7e6c707 100644
@@ -373,7 +373,12 @@ COBALT_IMPL(int, sem_timedwait, (sem_t *sem, const struct timespec *abs_timeout)
 
 	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
 
+#ifdef __USE_TIME_BITS64
+	ret = XENOMAI_SYSCALL2(sc_cobalt_sem_timedwait_time64, _sem,
+			       abs_timeout);
+#else
 	ret = XENOMAI_SYSCALL2(sc_cobalt_sem_timedwait, _sem, abs_timeout);
+#endif
 
 	pthread_setcanceltype(oldtype, NULL);
 
Signature · 1 line
2.29.2
#37 lore raw

v3 cover Pattern for implementing y2038 syscalls

This series was tested against the following branches:
- upstream: wip/dovetail
- philippe-private: for-upstream/dovetail

Song can take this series as template and continue to bring in more y2038 syscalls, while I will go and fixup some of the things that are alredy broken (on 32 bit systems).

Changes in v3:
- Removed RFC tag
- Extended tests to cover one of the POSIX edge cases found during review

Changes in v2:
- Added a smokey plugin named y2038 for running Y2038 related tests (Should be extended with all related tests)
- Review implementations (covered by tests now as well)
- Drop support for kernel 4.4
- Added the libcobalt part

Florian Bezdeka (4):
y2038: Fixing the sem_timedwait syscall for 32 bit systems
y2038: Adding sem_timedwait64
y2038: Add tests for the sc_cobalt_sem_timedwait64 syscall
y2038: lib/cobalt: Add support of sc_cobalt_sem_timedwait64

 configure.ac                           |   1 +
 include/cobalt/kernel/time.h           |  22 ++++
 include/cobalt/uapi/syscall.h          |   1 +
 kernel/cobalt/Makefile                 |   1 +
 kernel/cobalt/posix/sem.c              |  60 +++++----
 kernel/cobalt/posix/sem.h              |  13 +-
 kernel/cobalt/posix/syscall32.c        |  17 ++-
 kernel/cobalt/posix/syscall32.h        |   6 +-
 kernel/cobalt/time.c                   |  29 ++++
 lib/cobalt/semaphore.c                 |   5 +
 testsuite/smokey/Makefile.am           |   6 +-
 testsuite/smokey/y2038/Makefile.am     |  10 ++
 testsuite/smokey/y2038/syscall-tests.c | 175 +++++++++++++++++++++++++
 13 files changed, 315 insertions(+), 31 deletions(-)
 create mode 100644 include/cobalt/kernel/time.h
 create mode 100644 kernel/cobalt/time.c
 create mode 100644 testsuite/smokey/y2038/Makefile.am
 create mode 100644 testsuite/smokey/y2038/syscall-tests.c
Signature · 1 line
2.29.2
#38 lore raw

PATCH v3 1/4 y2038: Fixing the sem_timedwait syscall for 32 bit systems

On systems using 32 bit for time_t the sem_timedwait syscall was broken because the function used for copying the timeout value from userspace to kernel (=sem_fetch_timeout()) was always copying sizeof(struct timespec64).

A 32 bit application (or more specific an application with 4 byte time_t) would only provide sizeof(struct old_timespec32).

Notable changes:
- The copy operation from userspace to kernel is now already done in the syscall handler. So it is always done and might fail. Reporting a failure is delayed until the timeout is being validated.

- Validation: Switched to timespec64_valid() instead of our own check.

---
 kernel/cobalt/posix/sem.c       | 40 +++++++++++++++------------------
 kernel/cobalt/posix/sem.h       |  6 ++---
 kernel/cobalt/posix/syscall32.c | 10 +++++++--
 kernel/cobalt/posix/syscall32.h |  2 +-
 4 files changed, 29 insertions(+), 29 deletions(-)
kernel/cobalt/posix/sem.c +18 -22
index 467a9b7dd..827a4751a 100644
@@ -267,20 +267,11 @@ out:
 	return ret;
 }
 
-static inline int sem_fetch_timeout(struct timespec64 *ts,
-				    const void __user *u_ts)
-{
-	return u_ts == NULL ? -EFAULT :
-		cobalt_copy_from_user(ts, u_ts, sizeof(*ts));
-}
-
 int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem,
-			   const void __user *u_ts,
-			   int (*fetch_timeout)(struct timespec64 *ts,
-						const void __user *u_ts))
+			   const struct timespec64 *ts)
 {
-	struct timespec64 ts = { .tv_sec = 0, .tv_nsec = 0 };
-	int pull_ts = 1, ret, info;
+	int ret, info;
+	bool validate_ts = true;
 	struct cobalt_sem *sem;
 	xnhandle_t handle;
 	xntmode_t tmode;
@@ -304,24 +295,23 @@ int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem,
 		 * it's actually more complex, to keep some
 		 * applications ported to Linux happy.
 		 */
-		if (pull_ts) {
+		if (validate_ts) {
 			atomic_inc(&sem->state->value);
-			xnlock_put_irqrestore(&nklock, s);
-			ret = fetch_timeout(&ts, u_ts);
-			xnlock_get_irqsave(&nklock, s);
-			if (ret)
+			if (!ts) {
+				ret = -EFAULT;
 				break;
-			if (ts.tv_nsec >= ONE_BILLION) {
+			}
+			if (!timespec64_valid(ts)) {
 				ret = -EINVAL;
 				break;
 			}
-			pull_ts = 0;
+			validate_ts = false;
 			continue;
 		}
 
 		ret = 0;
 		tmode = sem->flags & SEM_RAWCLOCK ? XN_ABSOLUTE : XN_REALTIME;
-		info = xnsynch_sleep_on(&sem->synchbase, ts2ns(&ts) + 1, tmode);
+		info = xnsynch_sleep_on(&sem->synchbase, ts2ns(ts) + 1, tmode);
 		if (info & XNRMID)
 			ret = -EINVAL;
 		else if (info & (XNBREAK|XNTIMEO)) {
@@ -434,9 +424,15 @@ COBALT_SYSCALL(sem_wait, primary,
 
 COBALT_SYSCALL(sem_timedwait, primary,
 	       (struct cobalt_sem_shadow __user *u_sem,
-		struct __user_old_timespec __user *u_ts))
+		const struct __user_old_timespec __user *u_ts))
 {
-	return __cobalt_sem_timedwait(u_sem, u_ts, sem_fetch_timeout);
+	int ret = 1;
+	struct timespec64 ts64;
+
+	if (u_ts)
+		ret = cobalt_get_u_timespec(&ts64, u_ts);
+
+	return __cobalt_sem_timedwait(u_sem, ret ? NULL : &ts64);
 }
 
 COBALT_SYSCALL(sem_trywait, primary,
kernel/cobalt/posix/sem.h +2 -4
index d17299495..658e11f7a 100644
@@ -64,9 +64,7 @@ __cobalt_sem_open(struct cobalt_sem_shadow __user *usm,
 		  int oflags, mode_t mode, unsigned int value);
 
 int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem,
-			   const void __user *u_ts,
-			   int (*fetch_timeout)(struct timespec64 *ts,
-						const void __user *u_ts));
+			   const struct timespec64 *ts);
 
 int __cobalt_sem_destroy(xnhandle_t handle);
 
@@ -91,7 +89,7 @@ COBALT_SYSCALL_DECL(sem_wait,
 
 COBALT_SYSCALL_DECL(sem_timedwait,
 		    (struct cobalt_sem_shadow __user *u_sem,
-		     struct __user_old_timespec __user *u_ts));
+		     const struct __user_old_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(sem_trywait,
 		    (struct cobalt_sem_shadow __user *u_sem));
kernel/cobalt/posix/syscall32.c +8 -2
index b83944089..bc60a81a7 100644
@@ -124,9 +124,15 @@ COBALT_SYSCALL32emu(sem_open, lostage,
 
 COBALT_SYSCALL32emu(sem_timedwait, primary,
 		    (struct cobalt_sem_shadow __user *u_sem,
-		     struct old_timespec32 __user *u_ts))
+		     const struct old_timespec32 __user *u_ts))
 {
-	return __cobalt_sem_timedwait(u_sem, u_ts, sys32_fetch_timeout);
+	int ret = 1;
+	struct timespec64 ts64;
+
+	if (u_ts)
+		ret = sys32_fetch_timeout(&ts64, u_ts);
+
+	return __cobalt_sem_timedwait(u_sem, ret ? NULL : &ts64);
 }
 
 COBALT_SYSCALL32emu(clock_getres, current,
kernel/cobalt/posix/syscall32.h +1 -1
index 936343fa4..d5b07da86 100644
@@ -223,6 +223,6 @@ COBALT_SYSCALL32emu_DECL(sem_open,
 
 COBALT_SYSCALL32emu_DECL(sem_timedwait,
 			 (struct cobalt_sem_shadow __user *u_sem,
-			  struct old_timespec32 __user *u_ts));
+			  const struct old_timespec32 __user *u_ts));
 
 #endif /* !_COBALT_POSIX_SYSCALL32_H */
Signature · 1 line
2.29.2
#39 lore raw

PATCH v3 2/4 y2038: Adding sem_timedwait64

In reply to Florian Bezdeka

Implementation is heavily inspired by the sem_timedwait syscall, but expecting time64 based timespec / timeout.

We need two new syscall handlers:
- The native one (COBALT_SYSCALL()) to get 32 bit kernels time64 aware. This handler is added for 64 bit kernels as well, but not used. As we don't have separate syscall tables for this both worlds we have to add it.

- The compat handler (COBALT_SYSCALL32emu()) for x32 or x86 applications running on an x86_64 kernel. Otherwise the redirection to the compat / emulation syscalls is broken.

---
 include/cobalt/kernel/time.h    | 22 ++++++++++++++++++++++
 include/cobalt/uapi/syscall.h   |  1 +
 kernel/cobalt/Makefile          |  1 +
 kernel/cobalt/posix/sem.c       | 20 ++++++++++++++++++++
 kernel/cobalt/posix/sem.h       |  7 +++++++
 kernel/cobalt/posix/syscall32.c |  7 +++++++
 kernel/cobalt/posix/syscall32.h |  4 ++++
 kernel/cobalt/time.c            | 29 +++++++++++++++++++++++++++++
 8 files changed, 91 insertions(+)
 create mode 100644 include/cobalt/kernel/time.h
 create mode 100644 kernel/cobalt/time.c
include/cobalt/kernel/time.h new file +22 -0
new file mode 100644
index 000000000..19e8f2c56
@@ -0,0 +1,22 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ */
+
+#ifndef _COBALT_KERNEL_TIME_H
+#define _COBALT_KERNEL_TIME_H
+
+#include <linux/time.h>
+#include <linux/time64.h>
+
+/**
+ * Read struct __kernel_timespec from userspace and convert to
+ * struct timespec64
+ *
+ * @param ts The destination, will be filled
+ * @param uts The source, provided by an application
+ * @return 0 on success, -EFAULT otherwise
+ */
+int cobalt_get_timespec64(struct timespec64 *ts,
+			  const struct __kernel_timespec __user *uts);
+
+#endif //_COBALT_KERNEL_TIME_H
include/cobalt/uapi/syscall.h +1 -0
index aa3c308d0..8895d2bff 100644
@@ -122,6 +122,7 @@
 #define sc_cobalt_sendmmsg			99
 #define sc_cobalt_clock_adjtime			100
 #define sc_cobalt_thread_setschedprio		101
+#define sc_cobalt_sem_timedwait64		102
 
 #define __NR_COBALT_SYSCALLS			128 /* Power of 2 */
 
kernel/cobalt/Makefile +1 -0
index 129005d8f..6cd2d5994 100644
@@ -13,6 +13,7 @@ xenomai-y :=	arith.o 	\
 		select.o	\
 		synch.o		\
 		thread.o	\
+		time.o		\
 		timer.o		\
 		tree.o
 
kernel/cobalt/posix/sem.c +20 -0
index 827a4751a..72b20c78d 100644
@@ -19,6 +19,7 @@
 
 #include <stddef.h>
 #include <linux/err.h>
+#include <cobalt/kernel/time.h>
 #include "internal.h"
 #include "thread.h"
 #include "clock.h"
@@ -326,6 +327,18 @@ int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem,
 	return ret;
 }
 
+int __cobalt_sem_timedwait64(struct cobalt_sem_shadow __user *u_sem,
+			     const struct __kernel_timespec __user *u_ts)
+{
+	int ret = 1;
+	struct timespec64 ts64;
+
+	if (u_ts)
+		ret = cobalt_get_timespec64(&ts64, u_ts);
+
+	return __cobalt_sem_timedwait(u_sem, ret ? NULL : &ts64);
+}
+
 static int sem_post(xnhandle_t handle)
 {
 	struct cobalt_sem *sem;
@@ -435,6 +448,13 @@ COBALT_SYSCALL(sem_timedwait, primary,
 	return __cobalt_sem_timedwait(u_sem, ret ? NULL : &ts64);
 }
 
+COBALT_SYSCALL(sem_timedwait64, primary,
+	       (struct cobalt_sem_shadow __user *u_sem,
+		const struct __kernel_timespec __user *u_ts))
+{
+	return __cobalt_sem_timedwait64(u_sem, u_ts);
+}
+
 COBALT_SYSCALL(sem_trywait, primary,
 	       (struct cobalt_sem_shadow __user *u_sem))
 {
kernel/cobalt/posix/sem.h +7 -0
index 658e11f7a..d7dbb9098 100644
@@ -66,6 +66,9 @@ __cobalt_sem_open(struct cobalt_sem_shadow __user *usm,
 int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem,
 			   const struct timespec64 *ts);
 
+int __cobalt_sem_timedwait64(struct cobalt_sem_shadow __user *u_sem,
+			     const struct __kernel_timespec __user *u_ts);
+
 int __cobalt_sem_destroy(xnhandle_t handle);
 
 void cobalt_nsem_reclaim(struct cobalt_process *process);
@@ -91,6 +94,10 @@ COBALT_SYSCALL_DECL(sem_timedwait,
 		    (struct cobalt_sem_shadow __user *u_sem,
 		     const struct __user_old_timespec __user *u_ts));
 
+COBALT_SYSCALL_DECL(sem_timedwait64,
+		    (struct cobalt_sem_shadow __user *u_sem,
+		     const struct __kernel_timespec __user *u_ts));
+
 COBALT_SYSCALL_DECL(sem_trywait,
 		    (struct cobalt_sem_shadow __user *u_sem));
 
kernel/cobalt/posix/syscall32.c +7 -0
index bc60a81a7..8bc74e997 100644
@@ -135,6 +135,13 @@ COBALT_SYSCALL32emu(sem_timedwait, primary,
 	return __cobalt_sem_timedwait(u_sem, ret ? NULL : &ts64);
 }
 
+COBALT_SYSCALL32emu(sem_timedwait64, primary,
+		    (struct cobalt_sem_shadow __user *u_sem,
+		     const struct __kernel_timespec __user *u_ts))
+{
+	return __cobalt_sem_timedwait64(u_sem, u_ts);
+}
+
 COBALT_SYSCALL32emu(clock_getres, current,
 		    (clockid_t clock_id,
 		     struct old_timespec32 __user *u_ts))
kernel/cobalt/posix/syscall32.h +4 -0
index d5b07da86..c2e4bf355 100644
@@ -225,4 +225,8 @@ COBALT_SYSCALL32emu_DECL(sem_timedwait,
 			 (struct cobalt_sem_shadow __user *u_sem,
 			  const struct old_timespec32 __user *u_ts));
 
+COBALT_SYSCALL32emu_DECL(sem_timedwait64,
+			 (struct cobalt_sem_shadow __user * u_sem,
+			  const struct __kernel_timespec __user *u_ts));
+
 #endif /* !_COBALT_POSIX_SYSCALL32_H */
kernel/cobalt/time.c new file +29 -0
new file mode 100644
index 000000000..a3fd8a740
@@ -0,0 +1,29 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ */
+
+#include <asm-generic/xenomai/syscall.h>
+#include <cobalt/kernel/time.h>
+#include <linux/compat.h>
+
+int cobalt_get_timespec64(struct timespec64 *ts,
+			  const struct __kernel_timespec __user *uts)
+{
+	struct __kernel_timespec kts;
+	int ret;
+
+	ret = cobalt_copy_from_user(&kts, uts, sizeof(kts));
+	if (ret)
+		return -EFAULT;
+
+	ts->tv_sec = kts.tv_sec;
+
+	/* Zero out the padding in compat mode */
+	if (in_compat_syscall())
+		kts.tv_nsec &= 0xFFFFFFFFUL;
+
+	/* In 32-bit mode, this drops the padding */
+	ts->tv_nsec = kts.tv_nsec;
+
+	return 0;
+}
Signature · 1 line
2.29.2
#40 lore raw

PATCH v3 3/4 y2038: Add tests for the sc_cobalt_sem_timedwait64 syscall

In reply to Florian Bezdeka

Introducing a new smokey plugin that can be extended for all kind of y2038 tests. For now we are testing the new sc_cobalt_sem_timedwait64 syscall without using any libc wrappers provided by libcobalt.

---
 configure.ac                           |   1 +
 testsuite/smokey/Makefile.am           |   6 +-
 testsuite/smokey/y2038/Makefile.am     |  10 ++
 testsuite/smokey/y2038/syscall-tests.c | 175 +++++++++++++++++++++++++
 4 files changed, 190 insertions(+), 2 deletions(-)
 create mode 100644 testsuite/smokey/y2038/Makefile.am
 create mode 100644 testsuite/smokey/y2038/syscall-tests.c
configure.ac +1 -0
index abe538dbd..bd5fd5ba9 100644
@@ -990,6 +990,7 @@ AC_CONFIG_FILES([ \
 	testsuite/smokey/net_common/Makefile \
 	testsuite/smokey/cpu-affinity/Makefile \
 	testsuite/smokey/gdb/Makefile \
+	testsuite/smokey/y2038/Makefile \
 	testsuite/clocktest/Makefile \
 	testsuite/xeno-test/Makefile \
 	utils/Makefile \
testsuite/smokey/Makefile.am +4 -2
index 02613c7dc..56c873026 100644
@@ -38,7 +38,8 @@ COBALT_SUBDIRS = 	\
 	timerfd		\
 	tsc		\
 	vdso-access 	\
-	xddp
+	xddp		\
+	y2038
 
 MERCURY_SUBDIRS =	\
 	memory-heapmem	\
@@ -76,7 +77,8 @@ DIST_SUBDIRS = 		\
 	timerfd		\
 	tsc		\
 	vdso-access 	\
-	xddp
+	xddp		\
+	y2038
 
 if XENO_COBALT
 if CONFIG_XENO_LIBS_DLOPEN
testsuite/smokey/y2038/Makefile.am new file +10 -0
new file mode 100644
index 000000000..a97591aa2
@@ -0,0 +1,10 @@
+
+noinst_LIBRARIES = liby2038.a
+
+liby2038_a_SOURCES = syscall-tests.c
+
+liby2038_a_CPPFLAGS = 	\
+	@XENO_USER_CFLAGS@	\
+	-I$(top_srcdir)		\
+	-I$(top_srcdir)/include
+
testsuite/smokey/y2038/syscall-tests.c new file +175 -0

175 lines not on this page · raw message

Signature · 1 line
2.29.2
#41 lore raw

PATCH v3 4/4 y2038: lib/cobalt: Add support of sc_cobalt_sem_timedwait64

In reply to Florian Bezdeka

In case libcobalt is build with -D_TIME_BITS=64
sc_cobalt_sem_timedwait64 will be used instead of
sc_cobalt_sem_timedwait.

---
 lib/cobalt/semaphore.c | 5 +++++
 1 file changed, 5 insertions(+)
lib/cobalt/semaphore.c +5 -0
index 45705d48f..bff005440 100644
@@ -373,7 +373,12 @@ COBALT_IMPL(int, sem_timedwait, (sem_t *sem, const struct timespec *abs_timeout)
 
 	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
 
+#ifdef __USE_TIME_BITS64
+	ret = XENOMAI_SYSCALL2(sc_cobalt_sem_timedwait64, _sem,
+			       abs_timeout);
+#else
 	ret = XENOMAI_SYSCALL2(sc_cobalt_sem_timedwait, _sem, abs_timeout);
+#endif
 
 	pthread_setcanceltype(oldtype, NULL);
 
Signature · 1 line
2.29.2
#42 lore raw

Re: [y2038][PATCH v3 4/4] y2038: lib/cobalt: Add support of sc_cobalt_sem_timedwait64

Quoted 17 lines · Florian Bezdeka via Xenomai

In case libcobalt is build with -D_TIME_BITS=64
sc_cobalt_sem_timedwait64 will be used instead of
sc_cobalt_sem_timedwait.

---
  lib/cobalt/semaphore.c | 5 +++++
  1 file changed, 5 insertions(+)
lib/cobalt/semaphore.c +0 -0
index 45705d48f..bff005440 100644
@@ -373,7 +373,12 @@ COBALT_IMPL(int, sem_timedwait, (sem_t *sem, const struct timespec *abs_timeout)
 
  	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);

lib/cobalt/semaphore.c COBALT_IMPL(int, sem_timedwait, (sem_t *sem, const struct timespec *abs_timeout) · line 384

Quoted 10 lines
lib/cobalt/semaphore.c +5 -0
 
+#ifdef __USE_TIME_BITS64
+	ret = XENOMAI_SYSCALL2(sc_cobalt_sem_timedwait64, _sem,
+			       abs_timeout);
+#else
  	ret = XENOMAI_SYSCALL2(sc_cobalt_sem_timedwait, _sem, abs_timeout);
+#endif
 
  	pthread_setcanceltype(oldtype, NULL);
 

shall we take cobalt_features_available into account?

Song

#43 lore raw

RFC PATCH 2/2 y2038: Adding sem_timedwait_time64

In reply to Florian Bezdeka

Implementation is heavily inspired by the sem_timedwait syscall, but expecting time64 based timespec / timeout.

We need two new syscall handlers:
- The native one (COBALT_SYSCALL()) to get 32 bit kernels time64 aware. This handler is added for 64 bit kernels as well, but not used. As we don't have separate syscall tables for this both worlds we have to add it.

- The compat handler (COBALT_SYSCALL32emu()) for x32 or x86 applications running on an x86_64 kernel. Otherwise the redirection to the compat / emulation syscalls is broken.

---
 include/cobalt/uapi/syscall.h   |  1 +
 kernel/cobalt/posix/sem.c       | 12 ++++++++++++
 kernel/cobalt/posix/sem.h       |  4 ++++
 kernel/cobalt/posix/syscall32.c | 12 ++++++++++++
 kernel/cobalt/posix/syscall32.h |  4 ++++
 5 files changed, 33 insertions(+)
include/cobalt/uapi/syscall.h +1 -0
index aa3c308d0..9b005da47 100644
@@ -122,6 +122,7 @@
 #define sc_cobalt_sendmmsg			99
 #define sc_cobalt_clock_adjtime			100
 #define sc_cobalt_thread_setschedprio		101
+#define sc_cobalt_sem_timedwait_time64		102
 
 #define __NR_COBALT_SYSCALLS			128 /* Power of 2 */
 
kernel/cobalt/posix/sem.c +12 -0
index a0565e9f8..a2211af36 100644
@@ -430,6 +430,18 @@ COBALT_SYSCALL(sem_timedwait, primary,
 	return __cobalt_sem_timedwait(u_sem, &ts64);
 }
 
+COBALT_SYSCALL(sem_timedwait_time64, primary,
+	       (struct cobalt_sem_shadow __user *u_sem,
+		const struct __kernel_timespec __user *u_ts))
+{
+	struct timespec64 ts64;
+
+	if (get_timespec64(&ts64, u_ts))
+		return -EFAULT;
+
+	return __cobalt_sem_timedwait(u_sem, &ts64);
+}
+
 COBALT_SYSCALL(sem_trywait, primary,
 	       (struct cobalt_sem_shadow __user *u_sem))
 {
kernel/cobalt/posix/sem.h +4 -0
index 658e11f7a..8491b69ba 100644
@@ -66,6 +66,10 @@ __cobalt_sem_open(struct cobalt_sem_shadow __user *usm,
 int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem,
 			   const struct timespec64 *ts);
 
+COBALT_SYSCALL_DECL(sem_timedwait_time64,
+		    (struct cobalt_sem_shadow __user *u_sem,
+		     const struct __kernel_timespec __user *u_ts));
+
 int __cobalt_sem_destroy(xnhandle_t handle);
 
 void cobalt_nsem_reclaim(struct cobalt_process *process);
kernel/cobalt/posix/syscall32.c +12 -0
index c2a2423ed..d50532952 100644
@@ -136,6 +136,18 @@ COBALT_SYSCALL32emu(sem_timedwait, primary,
 	return __cobalt_sem_timedwait(u_sem, &ts64);
 }
 
+COBALT_SYSCALL32emu(sem_timedwait_time64, primary,
+		    (struct cobalt_sem_shadow __user *u_sem,
+		     const struct __kernel_timespec __user *u_ts))
+{
+	struct timespec64 ts64;
+
+	if (get_timespec64(&ts64, u_ts))
+		return -EFAULT;
+
+	return __cobalt_sem_timedwait(u_sem, &ts64);
+}
+
 COBALT_SYSCALL32emu(clock_getres, current,
 		    (clockid_t clock_id,
 		     struct old_timespec32 __user *u_ts))
kernel/cobalt/posix/syscall32.h +4 -0
index d72fd2022..3612bf751 100644
@@ -231,4 +231,8 @@ COBALT_SYSCALL32emu_DECL(sem_timedwait,
 			 (struct cobalt_sem_shadow __user *u_sem,
 			  const struct old_timespec32 __user *u_ts));
 
+COBALT_SYSCALL32emu_DECL(sem_timedwait_time64,
+			 (struct cobalt_sem_shadow __user * u_sem,
+			  const struct __kernel_timespec __user *u_ts));
+
 #endif /* !_COBALT_POSIX_SYSCALL32_H */
Signature · 1 line
2.29.2
#44 lore raw

Re: [y2038][RFC PATCH 2/2] y2038: Adding sem_timedwait_time64

Quoted 39 lines · Florian Bezdeka via Xenomai

Implementation is heavily inspired by the sem_timedwait syscall, but expecting time64 based timespec / timeout.

We need two new syscall handlers:
- The native one (COBALT_SYSCALL()) to get 32 bit kernels time64 aware. This handler is added for 64 bit kernels as well, but not used. As we don't have separate syscall tables for this both worlds we have to add it.

- The compat handler (COBALT_SYSCALL32emu()) for x32 or x86 applications running on an x86_64 kernel. Otherwise the redirection to the compat / emulation syscalls is broken.

---
  include/cobalt/uapi/syscall.h   |  1 +
  kernel/cobalt/posix/sem.c       | 12 ++++++++++++
  kernel/cobalt/posix/sem.h       |  4 ++++
  kernel/cobalt/posix/syscall32.c | 12 ++++++++++++
  kernel/cobalt/posix/syscall32.h |  4 ++++
  5 files changed, 33 insertions(+)
include/cobalt/uapi/syscall.h +1 -0
index aa3c308d0..9b005da47 100644
@@ -122,6 +122,7 @@
  #define sc_cobalt_sendmmsg			99
  #define sc_cobalt_clock_adjtime			100
  #define sc_cobalt_thread_setschedprio		101
+#define sc_cobalt_sem_timedwait_time64		102
 
  #define __NR_COBALT_SYSCALLS			128 /* Power of 2 */
 
kernel/cobalt/posix/sem.c +0 -0
index a0565e9f8..a2211af36 100644

kernel/cobalt/posix/sem.c COBALT_SYSCALL(sem_timedwait, primary, · line 439

Quoted 10 lines
kernel/cobalt/posix/sem.c +7 -0
@@ -430,6 +430,18 @@ COBALT_SYSCALL(sem_timedwait, primary,
  	return __cobalt_sem_timedwait(u_sem, &ts64);
  }
 
+COBALT_SYSCALL(sem_timedwait_time64, primary,
+	       (struct cobalt_sem_shadow __user *u_sem,
+		const struct __kernel_timespec __user *u_ts))
+{
+	struct timespec64 ts64;
+
+	if (get_timespec64(&ts64, u_ts))

get_timespec64 didn't exist until kernel 4.13, shall we take care of this? get_timespec64 uses copy_from_user, is there any side effect?

Quoted 60 lines
kernel/cobalt/posix/sem.c +5 -0
+		return -EFAULT;
+
+	return __cobalt_sem_timedwait(u_sem, &ts64);
+}
+
  COBALT_SYSCALL(sem_trywait, primary,
  	       (struct cobalt_sem_shadow __user *u_sem))
  {
kernel/cobalt/posix/sem.h +4 -0
index 658e11f7a..8491b69ba 100644
@@ -66,6 +66,10 @@ __cobalt_sem_open(struct cobalt_sem_shadow __user *usm,
  int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem,
  			   const struct timespec64 *ts);
 
+COBALT_SYSCALL_DECL(sem_timedwait_time64,
+		    (struct cobalt_sem_shadow __user *u_sem,
+		     const struct __kernel_timespec __user *u_ts));
+
  int __cobalt_sem_destroy(xnhandle_t handle);
 
  void cobalt_nsem_reclaim(struct cobalt_process *process);
kernel/cobalt/posix/syscall32.c +12 -0
index c2a2423ed..d50532952 100644
@@ -136,6 +136,18 @@ COBALT_SYSCALL32emu(sem_timedwait, primary,
  	return __cobalt_sem_timedwait(u_sem, &ts64);
  }
 
+COBALT_SYSCALL32emu(sem_timedwait_time64, primary,
+		    (struct cobalt_sem_shadow __user *u_sem,
+		     const struct __kernel_timespec __user *u_ts))
+{
+	struct timespec64 ts64;
+
+	if (get_timespec64(&ts64, u_ts))
+		return -EFAULT;
+
+	return __cobalt_sem_timedwait(u_sem, &ts64);
+}
+
  COBALT_SYSCALL32emu(clock_getres, current,
  		    (clockid_t clock_id,
  		     struct old_timespec32 __user *u_ts))
kernel/cobalt/posix/syscall32.h +4 -0
index d72fd2022..3612bf751 100644
@@ -231,4 +231,8 @@ COBALT_SYSCALL32emu_DECL(sem_timedwait,
  			 (struct cobalt_sem_shadow __user *u_sem,
  			  const struct old_timespec32 __user *u_ts));
 
+COBALT_SYSCALL32emu_DECL(sem_timedwait_time64,
+			 (struct cobalt_sem_shadow __user * u_sem,
+			  const struct __kernel_timespec __user *u_ts));
+
  #endif /* !_COBALT_POSIX_SYSCALL32_H */
#45 lore raw

Re: [y2038][RFC PATCH 2/2] y2038: Adding sem_timedwait_time64

Quoted 44 lines · chensong
Quoted 42 lines · Florian Bezdeka via Xenomai

Implementation is heavily inspired by the sem_timedwait syscall, but expecting time64 based timespec / timeout.

We need two new syscall handlers:
   - The native one (COBALT_SYSCALL()) to get 32 bit kernels time64 aware. This handler is added for 64 bit kernels as well, but not used. As we don't have separate syscall tables for this both worlds we have to add it.

  - The compat handler (COBALT_SYSCALL32emu()) for x32 or x86 applications running on an x86_64 kernel. Otherwise the redirection to the compat / emulation syscalls is broken.

---

  include/cobalt/uapi/syscall.h   |  1 +
  kernel/cobalt/posix/sem.c       | 12 ++++++++++++
  kernel/cobalt/posix/sem.h       |  4 ++++
  kernel/cobalt/posix/syscall32.c | 12 ++++++++++++
  kernel/cobalt/posix/syscall32.h |  4 ++++
  5 files changed, 33 insertions(+)
include/cobalt/uapi/syscall.h +1 -0
index aa3c308d0..9b005da47 100644
@@ -122,6 +122,7 @@
   #define sc_cobalt_sendmmsg			99
   #define sc_cobalt_clock_adjtime			100
   #define sc_cobalt_thread_setschedprio		101
+#define sc_cobalt_sem_timedwait_time64		102
 
   #define __NR_COBALT_SYSCALLS			128 /* Power of 2 */
 
kernel/cobalt/posix/sem.c +0 -0
index a0565e9f8..a2211af36 100644
@@ -430,6 +430,18 @@ COBALT_SYSCALL(sem_timedwait, primary,
   	return __cobalt_sem_timedwait(u_sem, &ts64);
   }
 
Quoted 10 lines

kernel/cobalt/posix/sem.c COBALT_SYSCALL(sem_timedwait, primary, · line 439

Quoted 7 lines
kernel/cobalt/posix/sem.c +7 -0
+COBALT_SYSCALL(sem_timedwait_time64, primary,
+	       (struct cobalt_sem_shadow __user *u_sem,
+		const struct __kernel_timespec __user *u_ts))
+{
+	struct timespec64 ts64;
+
+	if (get_timespec64(&ts64, u_ts))

get_timespec64 didn't exist until kernel 4.13, shall we take care of this? get_timespec64 uses copy_from_user, is there any side effect?

Yes and yes. I already noticed it but did not send out v2 due to some other this I have to address first. Still trying to find a way that allows us to prevent duplication all the necessary helpers...

Quoted 63 lines
Quoted 61 lines
kernel/cobalt/posix/sem.c +5 -0
+		return -EFAULT;
+
+	return __cobalt_sem_timedwait(u_sem, &ts64);
+}
+
   COBALT_SYSCALL(sem_trywait, primary,
   	       (struct cobalt_sem_shadow __user *u_sem))
   {
kernel/cobalt/posix/sem.h +4 -0
index 658e11f7a..8491b69ba 100644
@@ -66,6 +66,10 @@ __cobalt_sem_open(struct cobalt_sem_shadow __user *usm,
   int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem,
   			   const struct timespec64 *ts);
 
+COBALT_SYSCALL_DECL(sem_timedwait_time64,
+		    (struct cobalt_sem_shadow __user *u_sem,
+		     const struct __kernel_timespec __user *u_ts));
+
   int __cobalt_sem_destroy(xnhandle_t handle);
 
   void cobalt_nsem_reclaim(struct cobalt_process *process);
kernel/cobalt/posix/syscall32.c +12 -0
index c2a2423ed..d50532952 100644
@@ -136,6 +136,18 @@ COBALT_SYSCALL32emu(sem_timedwait, primary,
   	return __cobalt_sem_timedwait(u_sem, &ts64);
   }
 
+COBALT_SYSCALL32emu(sem_timedwait_time64, primary,
+		    (struct cobalt_sem_shadow __user *u_sem,
+		     const struct __kernel_timespec __user *u_ts))
+{
+	struct timespec64 ts64;
+
+	if (get_timespec64(&ts64, u_ts))
+		return -EFAULT;
+
+	return __cobalt_sem_timedwait(u_sem, &ts64);
+}
+
   COBALT_SYSCALL32emu(clock_getres, current,
   		    (clockid_t clock_id,
   		     struct old_timespec32 __user *u_ts))
kernel/cobalt/posix/syscall32.h +4 -0
index d72fd2022..3612bf751 100644
@@ -231,4 +231,8 @@ COBALT_SYSCALL32emu_DECL(sem_timedwait,
   			 (struct cobalt_sem_shadow __user *u_sem,
   			  const struct old_timespec32 __user *u_ts));
 
+COBALT_SYSCALL32emu_DECL(sem_timedwait_time64,
+			 (struct cobalt_sem_shadow __user * u_sem,
+			  const struct __kernel_timespec __user *u_ts));
+
   #endif /* !_COBALT_POSIX_SYSCALL32_H */
#46 lore raw

Re: [y2038][RFC PATCH 2/2] y2038: Adding sem_timedwait_time64

Quoted 56 lines · On 2021年03月05日 14:36, [email protected] wrote:
Quoted 44 lines · chensong
Quoted 42 lines · Florian Bezdeka via Xenomai

Implementation is heavily inspired by the sem_timedwait syscall, but expecting time64 based timespec / timeout.

We need two new syscall handlers:
- The native one (COBALT_SYSCALL()) to get 32 bit kernels time64 aware. This handler is added for 64 bit kernels as well, but not used. As we don't have separate syscall tables for this both worlds we have to add it.

- The compat handler (COBALT_SYSCALL32emu()) for x32 or x86 applications running on an x86_64 kernel. Otherwise the redirection to the compat / emulation syscalls is broken.

---
   include/cobalt/uapi/syscall.h   |  1 +
   kernel/cobalt/posix/sem.c       | 12 ++++++++++++
   kernel/cobalt/posix/sem.h       |  4 ++++
   kernel/cobalt/posix/syscall32.c | 12 ++++++++++++
   kernel/cobalt/posix/syscall32.h |  4 ++++
   5 files changed, 33 insertions(+)
include/cobalt/uapi/syscall.h +1 -0
index aa3c308d0..9b005da47 100644
@@ -122,6 +122,7 @@
   #define sc_cobalt_sendmmsg			99
   #define sc_cobalt_clock_adjtime			100
   #define sc_cobalt_thread_setschedprio		101
+#define sc_cobalt_sem_timedwait_time64		102
 
   #define __NR_COBALT_SYSCALLS			128 /* Power of 2 */
 
kernel/cobalt/posix/sem.c +0 -0
index a0565e9f8..a2211af36 100644
@@ -430,6 +430,18 @@ COBALT_SYSCALL(sem_timedwait, primary,
   	return __cobalt_sem_timedwait(u_sem, &ts64);
   }
 
Quoted 10 lines

kernel/cobalt/posix/sem.c COBALT_SYSCALL(sem_timedwait, primary, · line 439

Quoted 7 lines
kernel/cobalt/posix/sem.c +7 -0
+COBALT_SYSCALL(sem_timedwait_time64, primary,
+	       (struct cobalt_sem_shadow __user *u_sem,
+		const struct __kernel_timespec __user *u_ts))
+{
+	struct timespec64 ts64;
+
+	if (get_timespec64(&ts64, u_ts))

get_timespec64 didn't exist until kernel 4.13, shall we take care of this? get_timespec64 uses copy_from_user, is there any side effect?

Quoted 3 lines

Yes and yes. I already noticed it but did not send out v2 due to some other this I have to address first. Still trying to find a way that allows us to prevent duplication all the necessary helpers...

Or we don't use helpers, like this
struct __kernel_timespec kts;
struct timespec64 ts64;

cobalt_copy_from_user(&kts, u_ts, sizeof(kts));

ts64.tv_sec = kts.tv_sec;

i'm working on clock.c, and will submit patches, please review.

Quoted 65 lines
Quoted 64 lines
Quoted 62 lines
kernel/cobalt/posix/sem.c +5 -0
+		return -EFAULT;
+
+	return __cobalt_sem_timedwait(u_sem, &ts64);
+}
+
   COBALT_SYSCALL(sem_trywait, primary,
   	       (struct cobalt_sem_shadow __user *u_sem))
   {
kernel/cobalt/posix/sem.h +4 -0
index 658e11f7a..8491b69ba 100644
@@ -66,6 +66,10 @@ __cobalt_sem_open(struct cobalt_sem_shadow __user *usm,
   int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem,
   			   const struct timespec64 *ts);
 
+COBALT_SYSCALL_DECL(sem_timedwait_time64,
+		    (struct cobalt_sem_shadow __user *u_sem,
+		     const struct __kernel_timespec __user *u_ts));
+
   int __cobalt_sem_destroy(xnhandle_t handle);
 
   void cobalt_nsem_reclaim(struct cobalt_process *process);
kernel/cobalt/posix/syscall32.c +12 -0
index c2a2423ed..d50532952 100644
@@ -136,6 +136,18 @@ COBALT_SYSCALL32emu(sem_timedwait, primary,
   	return __cobalt_sem_timedwait(u_sem, &ts64);
   }
 
+COBALT_SYSCALL32emu(sem_timedwait_time64, primary,
+		    (struct cobalt_sem_shadow __user *u_sem,
+		     const struct __kernel_timespec __user *u_ts))
+{
+	struct timespec64 ts64;
+
+	if (get_timespec64(&ts64, u_ts))
+		return -EFAULT;
+
+	return __cobalt_sem_timedwait(u_sem, &ts64);
+}
+
   COBALT_SYSCALL32emu(clock_getres, current,
   		    (clockid_t clock_id,
   		     struct old_timespec32 __user *u_ts))
kernel/cobalt/posix/syscall32.h +4 -0
index d72fd2022..3612bf751 100644
@@ -231,4 +231,8 @@ COBALT_SYSCALL32emu_DECL(sem_timedwait,
   			 (struct cobalt_sem_shadow __user *u_sem,
   			  const struct old_timespec32 __user *u_ts));
 
+COBALT_SYSCALL32emu_DECL(sem_timedwait_time64,
+			 (struct cobalt_sem_shadow __user * u_sem,
+			  const struct __kernel_timespec __user *u_ts));
+
   #endif /* !_COBALT_POSIX_SYSCALL32_H */
#47 lore raw

Re: [y2038][RFC PATCH 2/2] y2038: Adding sem_timedwait_time64

Quoted 21 lines · chensong
Quoted 13 lines
Quoted 12 lines

kernel/cobalt/posix/sem.c COBALT_SYSCALL(sem_timedwait, primary, · line 439

Quoted 9 lines
kernel/cobalt/posix/sem.c +7 -0
+COBALT_SYSCALL(sem_timedwait_time64, primary,
+	       (struct cobalt_sem_shadow __user *u_sem,
+		const struct __kernel_timespec __user *u_ts))
+{
+	struct timespec64 ts64;
+
+	if (get_timespec64(&ts64, u_ts))

get_timespec64 didn't exist until kernel 4.13, shall we take care of this? get_timespec64 uses copy_from_user, is there any side effect?

Quoted 3 lines

Yes and yes. I already noticed it but did not send out v2 due to some other this I have to address first. Still trying to find a way that allows us to prevent duplication all the necessary helpers...

Or we don't use helpers, like this
struct __kernel_timespec kts;
struct timespec64 ts64;

Quoted 5 lines

cobalt_copy_from_user(&kts, u_ts, sizeof(kts));

ts64.tv_sec = kts.tv_sec;

i'm working on clock.c, and will submit patches, please review.

This is not correct in case of a compat syscall. We have different padding between kernel and application which needs to be addressed. That can be done nicely in a helper which can check the context it is being called in. (See get_timespec64() of a kernel that has it)

As you pointed out we can not use get_timespec64() as is, we need a cobalt version of it.

Please wait for v2, you will see...

Quoted 1 line
#48 lore raw

Re: [PATCH 2/5] cobalt/kernel: y2038: convert struct timespec to timespec64

In reply to Philippe Gerum
Quoted 54 lines · Philippe Gerum
Quoted 51 lines · Philippe Gerum
Quoted 48 lines · [email protected] <[email protected]> writes:
Quoted 28 lines · Philippe Gerum
Quoted 20 lines · [email protected] <[email protected]> writes:

On Sat, 2021-02-20 at 16:18 +0100, Philippe Gerum via Xenomai wrote:
[snip]

Quoted 13 lines
kernel/cobalt/posix/sem.c +1 -1
index 05a861dfe..467a9b7dd 100644
@@ -267,7 +267,7 @@ out:
 	return ret;
 }
 
 
 
 
-static inline int sem_fetch_timeout(struct timespec *ts,
+static inline int sem_fetch_timeout(struct timespec64 *ts,
Quoted 1 line

const void __user *u_ts)

Handle the following with care, maybe my understanding of CONFIG_XENO_ARCH_SYS3264 is wrong. See below...

Quoted 5 lines

My understanding is that this is a breaking change for 32 bit kernels. The broken part is hidden here, but sem_fetch_timeout() now assumes that the user provided timespec64, which is not be the case for 32 bit applications running on a 32 bit kernel.

Quoted 4 lines

The user-provided memory is referred to by u_ts, not ts, which receives the timestamp fetch_timeout() is supposed to return. The change should only affect the return type, not the source one. sys32_fetch_timeout() should still do the right thing via sys32_get_timespec().

Adding the full code:

static inline int sem_fetch_timeout(struct timespec64 *ts,
const void __user *u_ts)

{
	return u_ts == NULL ? -EFAULT :
		cobalt_copy_from_user(ts, u_ts, sizeof(*ts));
}

Copying sizeof(*ts) is to much if the application provided "__old_time_t" (sizeof(time_t) =4) only. Isn't it? I would expect the result (in ts) to be garbage. Due to different padding the "sec" field (in ts) would now contain the nsec value from u_ts as well.

Quoted 8 lines
Quoted 2 lines

Ah, I was looking at the wrong path (32emu). Yes, this is broken for mere 32bit now (i.e. natively 32bit platform).

We could simply use cobalt_get_u_timespec() instead of open coding the call to cobalt_copy_from_user(). Condvars have this right already, mutex, mq and sema4s have their fetch_timeout() helper broken indeed. Good spot.

Oops, missed this. Patch is in next (all 5, in fact, and all built find), but I will revert things back to patch 1 only.

Jan

Signature · 2 lines
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux
#49 lore raw

Re: [PATCH 2/5] cobalt/kernel: y2038: convert struct timespec to timespec64

In reply to Philippe Gerum
Quoted 24 lines · Philippe Gerum
Quoted 22 lines · Philippe Gerum
Quoted 19 lines · [email protected] <[email protected]> writes:
Quoted 4 lines · Philippe Gerum
Quoted 2 lines · [email protected] <[email protected]> writes:

On Sat, 2021-02-20 at 16:18 +0100, Philippe Gerum via Xenomai wrote:
[snip]

Adding the full code:

static inline int sem_fetch_timeout(struct timespec64 *ts,
const void __user *u_ts)

{
	return u_ts == NULL ? -EFAULT :
		cobalt_copy_from_user(ts, u_ts, sizeof(*ts));
}

Copying sizeof(*ts) is to much if the application provided "__old_time_t" (sizeof(time_t) =4) only. Isn't it? I would expect the result (in ts) to be garbage. Due to different padding the "sec" field (in ts) would now contain the nsec value from u_ts as well.

Quoted 8 lines
Quoted 2 lines

Ah, I was looking at the wrong path (32emu). Yes, this is broken for mere 32bit now (i.e. natively 32bit platform).

We could simply use cobalt_get_u_timespec() instead of open coding the call to cobalt_copy_from_user(). Condvars have this right already, mutex, mq and sema4s have their fetch_timeout() helper broken indeed. Good spot.

I had a look at the affected mutex syscalls today. pthread_mutex_timedlock() has the well known "The validity of the abs_timeout parameter need not be checked if the mutex can be locked immediately." as well.

Could someone please confirm that Xenomai is already validating the supplied timeout even if the mutex could be taken immediately? Maybe I'm missing something.

Should we fix that as well? Any advice how to do so?

Starting point:
__cobalt_mutex_timedlock_break()
__cobalt_mutex_timedlock_break(): Validation before calling
__cobalt_mutex_acquire_unchecked()

If I'm right, the problem was once fixed with:
860ea449a298 ("cobalt/posix/mutex: fix timeout handling in pthread_mutex_timedlock()")

but broken again in:
c53a9dd3ebc7 ("cobalt/posix/mutex: prepare for 32bit syscall emulation")

#50 lore raw

Re: [PATCH 2/5] cobalt/kernel: y2038: convert struct timespec to timespec64

Quoted 34 lines · [email protected] <[email protected]> writes:
Quoted 24 lines · Philippe Gerum
Quoted 22 lines · Philippe Gerum
Quoted 19 lines · [email protected] <[email protected]> writes:
Quoted 4 lines · Philippe Gerum
Quoted 2 lines · [email protected] <[email protected]> writes:

On Sat, 2021-02-20 at 16:18 +0100, Philippe Gerum via Xenomai wrote:
[snip]

Adding the full code:

static inline int sem_fetch_timeout(struct timespec64 *ts,
const void __user *u_ts)

{
	return u_ts == NULL ? -EFAULT :
		cobalt_copy_from_user(ts, u_ts, sizeof(*ts));
}

Copying sizeof(*ts) is to much if the application provided "__old_time_t" (sizeof(time_t) =4) only. Isn't it? I would expect the result (in ts) to be garbage. Due to different padding the "sec" field (in ts) would now contain the nsec value from u_ts as well.

Quoted 8 lines
Quoted 2 lines

Ah, I was looking at the wrong path (32emu). Yes, this is broken for mere 32bit now (i.e. natively 32bit platform).

We could simply use cobalt_get_u_timespec() instead of open coding the call to cobalt_copy_from_user(). Condvars have this right already, mutex, mq and sema4s have their fetch_timeout() helper broken indeed. Good spot.

Quoted 9 lines

I had a look at the affected mutex syscalls today. pthread_mutex_timedlock() has the well known "The validity of the abs_timeout parameter need not be checked if the mutex can be locked immediately." as well.

Could someone please confirm that Xenomai is already validating the supplied timeout even if the mutex could be taken immediately? Maybe I'm missing something.

Yes it does, and probably should not for consistency with other calls.

Quoted 7 lines

Should we fix that as well? Any advice how to do so?

Starting point:
__cobalt_mutex_timedlock_break()
__cobalt_mutex_timedlock_break(): Validation before calling
__cobalt_mutex_acquire_unchecked()

Quoted 8 lines

If I'm right, the problem was once fixed with:
860ea449a298 ("cobalt/posix/mutex: fix timeout handling in pthread_mutex_timedlock()")

but broken again in:
c53a9dd3ebc7 ("cobalt/posix/mutex: prepare for 32bit syscall emulation")

The less intrusive way would be to try lock first calling xnsynch_try_acquire(), then fallback to xnsynch_acquire() if failed. This is likely to become the hot path for this code, assuming a mutex is most often unlocked on entry.

We are all locked under the big ugly nklock at this point, so there should be nothing to care about preemption-wise.

Signature · 1 line
Philippe.
#51 lore raw

Re: [PATCH 2/5] cobalt/kernel: y2038: convert struct timespec to timespec64

In reply to Philippe Gerum

On Sat, 2021-02-20 at 16:18 +0100, Philippe Gerum via Xenomai wrote:
[snip]

Quoted 1 line

+#if __BITS_PER_LONG == 64

That might be a beginner question, but I'm learning from the best ;-)

Do we really care about each single assignment (two per timespec) and each object on the stack that it is worth duplicating all this helpers? We could use the __BITS_PER_LONG == 32 version for both worlds, couldn't we?

Thanks in advance...

Quoted 55 lines
kernel/cobalt/include/asm-generic/xenomai/syscall.h +55 -0
+
+/*
+ * NOTE: those copy helpers won't work in compat mode: use
+ * sys32_get_timespec(), sys32_put_timespec() instead.
+ */
+
+static inline int cobalt_get_u_timespec(struct timespec64 *dst,
+			const struct __user_old_timespec __user *src)
+{
+	return cobalt_copy_from_user(dst, src, sizeof(*dst));
+}
+
+static inline int cobalt_put_u_timespec(
+	struct __user_old_timespec __user *dst,
+	const struct timespec64 *src)
+{
+	return cobalt_copy_to_user(dst, src, sizeof(*dst));
+}
+
+#else /* __BITS_PER_LONG == 32 */
+
+static inline int cobalt_get_u_timespec(struct timespec64 *dst,
+			const struct __user_old_timespec __user *src)
+{
+	struct __user_old_timespec u_ts;
+	int ret;
+
+	ret = cobalt_copy_from_user(&u_ts, src, sizeof(u_ts));
+	if (ret)
+		return ret;
+
+	dst->tv_sec = u_ts.tv_sec;
+	dst->tv_nsec = u_ts.tv_nsec;
+
+	return 0;
+}
+
+static inline int cobalt_put_u_timespec(
+	struct __user_old_timespec __user *dst,
+	const struct timespec64 *src)
+{
+	struct __user_old_timespec u_ts;
+	int ret;
+
+	u_ts.tv_sec = src->tv_sec;
+	u_ts.tv_nsec = src->tv_nsec;
+
+	ret = cobalt_copy_to_user(dst, &u_ts, sizeof(*dst));
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+#endif

[snip]

#52 lore raw

Re: [PATCH 2/5] cobalt/kernel: y2038: convert struct timespec to timespec64

Quoted 10 lines · [email protected] <[email protected]> writes:

On Sat, 2021-02-20 at 16:18 +0100, Philippe Gerum via Xenomai wrote:
[snip]

Quoted 1 line

+#if __BITS_PER_LONG == 64

That might be a beginner question, but I'm learning from the best ;-)

Do we really care about each single assignment (two per timespec) and each object on the stack that it is worth duplicating all this helpers? We could use the __BITS_PER_LONG == 32 version for both worlds, couldn't we?

Yes, this would work as well. I agree that the very limited gain is not worth the code duplication.

Signature · 1 line
Philippe.
#53 lore raw

Re: [PATCH 2/5] cobalt/kernel: y2038: convert struct timespec to timespec64

Quoted 8 lines · Philippe Gerum
Quoted 6 lines · [email protected] <[email protected]> writes:

On Sat, 2021-02-20 at 16:18 +0100, Philippe Gerum via Xenomai wrote:
[snip]

Quoted 1 line

+#if __BITS_PER_LONG == 64

That might be a beginner question, but I'm learning from the best ;-)

Quoted 8 lines
Quoted 4 lines

Do we really care about each single assignment (two per timespec) and each object on the stack that it is worth duplicating all this helpers? We could use the __BITS_PER_LONG == 32 version for both worlds, couldn't we?

Yes, this would work as well. I agree that the very limited gain is not worth the code duplication.

I (or Song) will take care of it. No need to interrupt dovetail stuff...

#54 lore raw

PATCH 3/5 lib: y2038: convert to internal timespec type

In reply to Philippe Gerum

From: Philippe Gerum <[email protected]>

---
 lib/alchemy/task.c          | 9 ++++++---
 lib/copperplate/threadobj.c | 9 ++++++---
 lib/psos/task.c             | 9 ++++++---
 lib/vxworks/kernLib.c       | 6 ++++--
 lib/vxworks/taskLib.c       | 6 ++++--
 5 files changed, 26 insertions(+), 13 deletions(-)
lib/alchemy/task.c +6 -3
index 949a996d0..9afa2af57 100644
@@ -1410,11 +1410,14 @@ int rt_task_slice(RT_TASK *task, RTIME quantum)
 
 	param_ex.sched_priority = threadobj_get_priority(&tcb->thobj);
 	if (quantum) {
+		struct timespec ts;
 		policy = SCHED_RR;
-		clockobj_ticks_to_timespec(&alchemy_clock, quantum,
-					   &param_ex.sched_rr_quantum);
-	} else
+		clockobj_ticks_to_timespec(&alchemy_clock, quantum, &ts);
+		param_ex.sched_rr_quantum.tv_sec = ts.tv_sec;
+		param_ex.sched_rr_quantum.tv_nsec = ts.tv_nsec;
+	} else {
 		policy = param_ex.sched_priority ? SCHED_FIFO : SCHED_OTHER;
+	}
 
 	ret = threadobj_set_schedparam(&tcb->thobj, policy, &param_ex);
 	switch (ret) {
lib/copperplate/threadobj.c +6 -3
index a3101baa1..f4588a17a 100644
@@ -1741,7 +1741,8 @@ int threadobj_set_schedparam(struct threadobj *thobj, int policy,
 		ret = enable_rr_corespec(thobj, param_ex);
 		if (ret)
 			return __bt(ret);
-		thobj->tslice = param_ex->sched_rr_quantum;
+		thobj->tslice.tv_sec = param_ex->sched_rr_quantum.tv_sec;
+		thobj->tslice.tv_nsec = param_ex->sched_rr_quantum.tv_nsec;
 	} else if (thobj->policy == SCHED_RR) /* Switching off round-robin. */
 		disable_rr_corespec(thobj);
 
@@ -1761,8 +1762,10 @@ int threadobj_set_schedprio(struct threadobj *thobj, int priority)
 	param_ex.sched_priority = priority;
 	policy = thobj->policy;
 
-	if (policy == SCHED_RR)
-		param_ex.sched_rr_quantum = thobj->tslice;
+	if (policy == SCHED_RR) {
+		param_ex.sched_rr_quantum.tv_sec = thobj->tslice.tv_sec;
+		param_ex.sched_rr_quantum.tv_nsec = thobj->tslice.tv_nsec;
+	}
 
 	return threadobj_set_schedparam(thobj, policy, &param_ex);
 }
lib/psos/task.c +6 -3
index 46e49ea88..f678be61d 100644
@@ -192,7 +192,8 @@ static void *task_trampoline(void *arg)
 
 	if (task->mode & T_TSLICE) {
 		param_ex.sched_priority = threadobj_get_priority(&task->thobj);
-		param_ex.sched_rr_quantum = psos_rrperiod;
+		param_ex.sched_rr_quantum.tv_sec = psos_rrperiod.tv_sec;
+		param_ex.sched_rr_quantum.tv_nsec = psos_rrperiod.tv_nsec;
 		threadobj_set_schedparam(&task->thobj, SCHED_RR, &param_ex);
 	}
 
@@ -630,9 +631,11 @@ u_long t_mode(u_long mask, u_long newmask, u_long *oldmode_r)
 
 	if (task->mode & T_TSLICE) {
 		policy = SCHED_RR;
-		param_ex.sched_rr_quantum = psos_rrperiod;
-	} else
+		param_ex.sched_rr_quantum.tv_sec = psos_rrperiod.tv_sec;
+		param_ex.sched_rr_quantum.tv_nsec = psos_rrperiod.tv_nsec;
+	} else {
 		policy = param_ex.sched_priority ? SCHED_FIFO : SCHED_OTHER;
+	}
 
 	/* Working on self, so -EIDRM can't happen. */
 	threadobj_set_schedparam(&task->thobj, policy, &param_ex);
lib/vxworks/kernLib.c +4 -2
index 4f3bd8201..d67502730 100644
@@ -30,9 +30,11 @@ static int switch_slicing(struct threadobj *thobj, struct timespec *quantum)
 
 	if (quantum) {
 		policy = SCHED_RR;
-		param_ex.sched_rr_quantum = *quantum;
-	} else
+		param_ex.sched_rr_quantum.tv_sec = quantum->tv_sec;
+		param_ex.sched_rr_quantum.tv_nsec = quantum->tv_nsec;
+	} else {
 		policy = param_ex.sched_priority ? SCHED_FIFO : SCHED_OTHER;
+	}
 
 	return threadobj_set_schedparam(thobj, policy, &param_ex);
 }
lib/vxworks/taskLib.c +4 -2
index a4af36c1f..c8723c6be 100644
@@ -265,8 +265,10 @@ static void *task_trampoline(void *arg)
 
 	/* Turn on time slicing if RR globally enabled. */
 	if (wind_time_slice) {
-		clockobj_ticks_to_timespec(&wind_clock, wind_time_slice,
-					   &param_ex.sched_rr_quantum);
+		struct timespec ts;
+		clockobj_ticks_to_timespec(&wind_clock, wind_time_slice, &ts);
+		param_ex.sched_rr_quantum.tv_sec = ts.tv_sec;
+		param_ex.sched_rr_quantum.tv_nsec = ts.tv_nsec;
 		threadobj_lock(&task->thobj);
 		param_ex.sched_priority = threadobj_get_priority(&task->thobj);
 		threadobj_set_schedparam(&task->thobj, SCHED_RR, &param_ex);
Signature · 1 line
2.26.2
#55 lore raw

PATCH 4/5 cobalt/kernel: y2038: convert struct itimerspec to itimerspec64

In reply to Philippe Gerum

From: Philippe Gerum <[email protected]>

As internal interfaces are gradually being made y2038-safe, the itimerspec64 type should be used internally by the kernel to represent interval timer specs. Apply the same reasoning to Cobalt.

We still use a legacy y2038-unsafe itimerspec type at the kernel<->user interface boundary (struct __user_old_itimerspec) until libcobalt is y2038-safe.

---
 include/cobalt/kernel/compat.h                |  4 +-
 include/cobalt/uapi/kernel/types.h            |  5 ++
 .../include/asm-generic/xenomai/syscall.h     | 47 ++++++++++++++++++-
 kernel/cobalt/posix/compat.c                  |  4 +-
 kernel/cobalt/posix/extension.h               |  4 +-
 kernel/cobalt/posix/syscall32.c               |  8 ++--
 kernel/cobalt/posix/timer.c                   | 30 ++++++------
 kernel/cobalt/posix/timer.h                   | 16 +++----
 kernel/cobalt/posix/timerfd.c                 | 22 ++++-----
 kernel/cobalt/posix/timerfd.h                 | 12 ++---
 10 files changed, 101 insertions(+), 51 deletions(-)
include/cobalt/kernel/compat.h +2 -2
index c57ef6532..7bec8c3be 100644
@@ -92,11 +92,11 @@ int sys32_get_timespec(struct timespec64 *ts,
 int sys32_put_timespec(struct compat_timespec __user *cts,
 		       const struct timespec64 *ts);
 
-int sys32_get_itimerspec(struct itimerspec *its,
+int sys32_get_itimerspec(struct itimerspec64 *its,
 			 const struct compat_itimerspec __user *cits);
 
 int sys32_put_itimerspec(struct compat_itimerspec __user *cits,
-			 const struct itimerspec *its);
+			 const struct itimerspec64 *its);
 
 int sys32_get_timeval(struct __kernel_old_timeval *tv,
 		      const struct compat_timeval __user *ctv);
include/cobalt/uapi/kernel/types.h +5 -0
index 8ce9b03df..10abbb55a 100644
@@ -67,4 +67,9 @@ struct __user_old_timespec {
 	long  tv_nsec;
 };
 
+struct __user_old_itimerspec {
+	struct __user_old_timespec it_interval;
+	struct __user_old_timespec it_value;
+};
+
 #endif /* !_COBALT_UAPI_KERNEL_TYPES_H */
kernel/cobalt/include/asm-generic/xenomai/syscall.h +46 -1

65 lines not on this page · raw message

kernel/cobalt/posix/compat.c +2 -2
index 185295082..767a8033a 100644
@@ -60,7 +60,7 @@ int sys32_put_timespec(struct compat_timespec __user *u_cts,
 }
 EXPORT_SYMBOL_GPL(sys32_put_timespec);
 
-int sys32_get_itimerspec(struct itimerspec *its,
+int sys32_get_itimerspec(struct itimerspec64 *its,
 			 const struct compat_itimerspec __user *cits)
 {
 	int ret = sys32_get_timespec(&its->it_value, &cits->it_value);
@@ -70,7 +70,7 @@ int sys32_get_itimerspec(struct itimerspec *its,
 EXPORT_SYMBOL_GPL(sys32_get_itimerspec);
 
 int sys32_put_itimerspec(struct compat_itimerspec __user *cits,
-			 const struct itimerspec *its)
+			 const struct itimerspec64 *its)
 {
 	int ret = sys32_put_timespec(&cits->it_value, &its->it_value);
 
kernel/cobalt/posix/extension.h +2 -2
index ae365c787..e23c26ccc 100644
@@ -39,10 +39,10 @@ struct cobalt_extension {
 		(*timer_init)(struct cobalt_extref *reftimer, /* nklocked, IRQs off. */
 			      const struct sigevent *__restrict__ evp);
 		int (*timer_settime)(struct cobalt_extref *reftimer, /* nklocked, IRQs off. */
-				     const struct itimerspec *__restrict__ value,
+				     const struct itimerspec64 *__restrict__ value,
 				     int flags);
 		int (*timer_gettime)(struct cobalt_extref *reftimer, /* nklocked, IRQs off. */
-				     struct itimerspec *__restrict__ value);
+				     struct itimerspec64 *__restrict__ value);
 		int (*timer_delete)(struct cobalt_extref *reftimer); /* nklocked, IRQs off. */
 		int (*timer_cleanup)(struct cobalt_extref *reftimer); /* nklocked, IRQs off. */
 		int (*signal_deliver)(struct cobalt_extref *refthread,
kernel/cobalt/posix/syscall32.c +4 -4
index ae25a6e74..5c858806b 100644
@@ -514,7 +514,7 @@ COBALT_SYSCALL32emu(timer_settime, primary,
 		     const struct compat_itimerspec __user *u_newval,
 		     struct compat_itimerspec __user *u_oldval))
 {
-	struct itimerspec newv, oldv, *oldvp = &oldv;
+	struct itimerspec64 newv, oldv, *oldvp = &oldv;
 	int ret;
 
 	if (u_oldval == NULL)
@@ -540,7 +540,7 @@ COBALT_SYSCALL32emu(timer_settime, primary,
 COBALT_SYSCALL32emu(timer_gettime, current,
 		    (timer_t tm, struct compat_itimerspec __user *u_val))
 {
-	struct itimerspec val;
+	struct itimerspec64 val;
 	int ret;
 
 	ret = __cobalt_timer_gettime(tm, &val);
@@ -553,7 +553,7 @@ COBALT_SYSCALL32emu(timerfd_settime, primary,
 		     const struct compat_itimerspec __user *new_value,
 		     struct compat_itimerspec __user *old_value))
 {
-	struct itimerspec ovalue, value;
+	struct itimerspec64 ovalue, value;
 	int ret;
 
 	ret = sys32_get_itimerspec(&value, new_value);
@@ -577,7 +577,7 @@ COBALT_SYSCALL32emu(timerfd_settime, primary,
 COBALT_SYSCALL32emu(timerfd_gettime, current,
 		    (int fd, struct compat_itimerspec __user *curr_value))
 {
-	struct itimerspec value;
+	struct itimerspec64 value;
 	int ret;
 
 	ret = __cobalt_timerfd_gettime(fd, &value);
kernel/cobalt/posix/timer.c +15 -15
index 3aca90de9..a58ea99a3 100644
@@ -261,7 +261,7 @@ out:
 }
 
 void __cobalt_timer_getval(struct xntimer *__restrict__ timer,
-			   struct itimerspec *__restrict__ value)
+			   struct itimerspec64 *__restrict__ value)
 {
 	ns2ts(&value->it_interval, xntimer_interval(timer));
 
@@ -275,7 +275,7 @@ void __cobalt_timer_getval(struct xntimer *__restrict__ timer,
 
 static inline void
 timer_gettimeout(struct cobalt_timer *__restrict__ timer,
-		 struct itimerspec *__restrict__ value)
+		 struct itimerspec64 *__restrict__ value)
 {
 	int ret = 0;
 
@@ -287,7 +287,7 @@ timer_gettimeout(struct cobalt_timer *__restrict__ timer,
 }
 
 int __cobalt_timer_setval(struct xntimer *__restrict__ timer, int clock_flag,
-			  const struct itimerspec *__restrict__ value)
+			  const struct itimerspec64 *__restrict__ value)
 {
 	xnticks_t start, period;
 
@@ -312,7 +312,7 @@ int __cobalt_timer_setval(struct xntimer *__restrict__ timer, int clock_flag,
 }
 
 static inline int timer_set(struct cobalt_timer *timer, int flags,
-			    const struct itimerspec *__restrict__ value)
+			    const struct itimerspec64 *__restrict__ value)
 {				/* nklocked, IRQs off. */
 	struct cobalt_thread *thread;
 	int ret = 0;
@@ -362,8 +362,8 @@ timer_deliver_late(struct cobalt_process *cc, timer_t timerid)
 }
 
 int __cobalt_timer_settime(timer_t timerid, int flags,
-			   const struct itimerspec *__restrict__ value,
-			   struct itimerspec *__restrict__ ovalue)
+			   const struct itimerspec64 *__restrict__ value,
+			   struct itimerspec64 *__restrict__ ovalue)
 {
 	struct cobalt_timer *timer;
 	struct cobalt_process *cc;
@@ -402,7 +402,7 @@ out:
 	return ret;
 }
 
-int __cobalt_timer_gettime(timer_t timerid, struct itimerspec *value)
+int __cobalt_timer_gettime(timer_t timerid, struct itimerspec64 *value)
 {
 	struct cobalt_timer *timer;
 	struct cobalt_process *cc;
@@ -471,23 +471,23 @@ COBALT_SYSCALL(timer_create, current,
 
 COBALT_SYSCALL(timer_settime, primary,
 	       (timer_t tm, int flags,
-		const struct itimerspec __user *u_newval,
-		struct itimerspec __user *u_oldval))
+		const struct __user_old_itimerspec __user *u_newval,
+		struct __user_old_itimerspec __user *u_oldval))
 {
-	struct itimerspec newv, oldv, *oldvp = &oldv;
+	struct itimerspec64 newv, oldv, *oldvp = &oldv;
 	int ret;
 
 	if (u_oldval == NULL)
 		oldvp = NULL;
 
-	if (cobalt_copy_from_user(&newv, u_newval, sizeof(newv)))
+	if (cobalt_get_u_itimerspec(&newv, u_newval))
 		return -EFAULT;
 
 	ret = __cobalt_timer_settime(tm, flags, &newv, oldvp);
 	if (ret)
 		return ret;
 
-	if (oldvp && cobalt_copy_to_user(u_oldval, oldvp, sizeof(oldv))) {
+	if (oldvp && cobalt_put_u_itimerspec(u_oldval, oldvp)) {
 		__cobalt_timer_settime(tm, flags, oldvp, NULL);
 		return -EFAULT;
 	}
@@ -496,16 +496,16 @@ COBALT_SYSCALL(timer_settime, primary,
 }
 
 COBALT_SYSCALL(timer_gettime, current,
-	       (timer_t tm, struct itimerspec __user *u_val))
+	       (timer_t tm, struct __user_old_itimerspec __user *u_val))
 {
-	struct itimerspec val;
+	struct itimerspec64 val;
 	int ret;
 
 	ret = __cobalt_timer_gettime(tm, &val);
 	if (ret)
 		return ret;
 
-	return cobalt_copy_to_user(u_val, &val, sizeof(val));
+	return cobalt_put_u_itimerspec(u_val, &val);
 }
 
 COBALT_SYSCALL(timer_getoverrun, current, (timer_t timerid))
kernel/cobalt/posix/timer.h +8 -8
index 0f5402aee..3b580d470 100644
@@ -51,20 +51,20 @@ cobalt_timer_by_id(struct cobalt_process *p, timer_t timer_id);
 void cobalt_timer_handler(struct xntimer *xntimer);
 
 void __cobalt_timer_getval(struct xntimer *__restrict__ timer, 
-			   struct itimerspec *__restrict__ value);
+			   struct itimerspec64 *__restrict__ value);
 
 int __cobalt_timer_setval(struct xntimer *__restrict__ timer, int clock_flag, 
-			  const struct itimerspec *__restrict__ value);
+			  const struct itimerspec64 *__restrict__ value);
 
 int __cobalt_timer_create(clockid_t clock,
 			  const struct sigevent *sev,
 			  timer_t __user *u_tm);
 
 int __cobalt_timer_settime(timer_t timerid, int flags,
-			   const struct itimerspec *__restrict__ value,
-			   struct itimerspec *__restrict__ ovalue);
+			   const struct itimerspec64 *__restrict__ value,
+			   struct itimerspec64 *__restrict__ ovalue);
 
-int __cobalt_timer_gettime(timer_t timerid, struct itimerspec *value);
+int __cobalt_timer_gettime(timer_t timerid, struct itimerspec64 *value);
 
 COBALT_SYSCALL_DECL(timer_create,
 		    (clockid_t clock,
@@ -75,11 +75,11 @@ COBALT_SYSCALL_DECL(timer_delete, (timer_t tm));
 
 COBALT_SYSCALL_DECL(timer_settime,
 		    (timer_t tm, int flags,
-		     const struct itimerspec __user *u_newval,
-		     struct itimerspec __user *u_oldval));
+		     const struct __user_old_itimerspec __user *u_newval,
+		     struct __user_old_itimerspec __user *u_oldval));
 
 COBALT_SYSCALL_DECL(timer_gettime,
-		    (timer_t tm, struct itimerspec __user *u_val));
+		    (timer_t tm, struct __user_old_itimerspec __user *u_val));
 
 COBALT_SYSCALL_DECL(timer_getoverrun, (timer_t tm));
 
kernel/cobalt/posix/timerfd.c +11 -11
index 29046cfec..472c4cba0 100644
@@ -32,7 +32,7 @@ struct cobalt_tfd {
 	struct rtdm_fd fd;
 	struct xntimer timer;
 	DECLARE_XNSELECT(read_select);
-	struct itimerspec value;
+	struct itimerspec64 value;
 	struct xnsynch readers;
 	struct xnthread *target;
 };
@@ -236,8 +236,8 @@ static inline void tfd_put(struct cobalt_tfd *tfd)
 }
 
 int __cobalt_timerfd_settime(int fd, int flags,
-			     const struct itimerspec *value,
-			     struct itimerspec *ovalue)
+			     const struct itimerspec64 *value,
+			     struct itimerspec64 *ovalue)
 {
 	struct cobalt_tfd *tfd;
 	int cflag, ret;
@@ -280,13 +280,13 @@ out:
 
 COBALT_SYSCALL(timerfd_settime, primary,
 	       (int fd, int flags,
-		const struct itimerspec __user *new_value,
-		struct itimerspec __user *old_value))
+		const struct __user_old_itimerspec __user *new_value,
+		struct __user_old_itimerspec __user *old_value))
 {
-	struct itimerspec ovalue, value;
+	struct itimerspec64 ovalue, value;
 	int ret;
 
-	ret = cobalt_copy_from_user(&value, new_value, sizeof(value));
+	ret = cobalt_get_u_itimerspec(&value, new_value);
 	if (ret)
 		return ret;
 
@@ -304,7 +304,7 @@ COBALT_SYSCALL(timerfd_settime, primary,
 	return ret;
 }
 
-int __cobalt_timerfd_gettime(int fd, struct itimerspec *value)
+int __cobalt_timerfd_gettime(int fd, struct itimerspec64 *value)
 {
 	struct cobalt_tfd *tfd;
 	spl_t s;
@@ -323,12 +323,12 @@ int __cobalt_timerfd_gettime(int fd, struct itimerspec *value)
 }
 
 COBALT_SYSCALL(timerfd_gettime, current,
-	       (int fd, struct itimerspec __user *curr_value))
+	       (int fd, struct __user_old_itimerspec __user *curr_value))
 {
-	struct itimerspec value;
+	struct itimerspec64 value;
 	int ret;
 
 	ret = __cobalt_timerfd_gettime(fd, &value);
 
-	return ret ?: cobalt_copy_to_user(curr_value, &value, sizeof(value));
+	return ret ?: cobalt_put_u_itimerspec(curr_value, &value);
 }
kernel/cobalt/posix/timerfd.h +6 -6
index 5787ff60a..245b8698b 100644
@@ -22,21 +22,21 @@
 #include <xenomai/posix/syscall.h>
 
 int __cobalt_timerfd_settime(int fd, int flags,
-			     const struct itimerspec *new_value,
-			     struct itimerspec *old_value);
+			     const struct itimerspec64 *new_value,
+			     struct itimerspec64 *old_value);
 
 int __cobalt_timerfd_gettime(int fd,
-			     struct itimerspec *value);
+			     struct itimerspec64 *value);
 
 COBALT_SYSCALL_DECL(timerfd_create,
 		    (int clockid, int flags));
 
 COBALT_SYSCALL_DECL(timerfd_settime,
 		    (int fd, int flags,
-		     const struct itimerspec __user *new_value,
-		     struct itimerspec __user *old_value));
+		     const struct __user_old_itimerspec __user *new_value,
+		     struct __user_old_itimerspec __user *old_value));
 
 COBALT_SYSCALL_DECL(timerfd_gettime,
-		    (int fd, struct itimerspec __user *curr_value));
+		    (int fd, struct __user_old_itimerspec __user *curr_value));
 
 #endif /* TIMERFD_H */
Signature · 1 line
2.26.2
#56 lore raw

PATCH 5/5 cobalt/kernel: y2038: convert struct timex to __kernel_timex

In reply to Philippe Gerum

From: Philippe Gerum <[email protected]>

As internal interfaces are gradually being made y2038-safe, the __kernel_timex type should be used internally by the kernel to represent time adjustment parameters. Apply the same reasoning to Cobalt.

We still use a legacy y2038-unsafe timex type at the kernel<->user interface boundary (struct __user_old_timex) until libcobalt is y2038-safe.

---
 include/cobalt/kernel/clock.h                 |  7 +--
 include/cobalt/kernel/compat.h                |  4 +-
 include/cobalt/uapi/kernel/types.h            | 44 +++++++++++++++++--
 .../include/asm-generic/xenomai/wrappers.h    |  4 ++
 kernel/cobalt/posix/clock.c                   |  6 +--
 kernel/cobalt/posix/clock.h                   |  4 +-
 kernel/cobalt/posix/compat.c                  | 28 +++++++++---
 kernel/cobalt/posix/syscall32.c               |  2 +-
 kernel/cobalt/trace/cobalt-posix.h            |  4 +-
 9 files changed, 81 insertions(+), 22 deletions(-)
include/cobalt/kernel/clock.h +4 -3
index 1c99173ff..0e4f1e1cb 100644
@@ -24,6 +24,7 @@
 #include <cobalt/kernel/list.h>
 #include <cobalt/kernel/vfile.h>
 #include <cobalt/uapi/kernel/types.h>
+#include <asm/xenomai/wrappers.h>
 
 /**
  * @addtogroup cobalt_core_clock
@@ -32,7 +33,7 @@
 
 struct xnsched;
 struct xntimerdata;
-struct timex;
+struct __kernel_timex;
 
 struct xnclock_gravity {
 	unsigned long irq;
@@ -67,7 +68,7 @@ struct xnclock {
 					    struct xnsched *sched);
 #endif
 		int (*adjust_time)(struct xnclock *clock,
-				   struct timex *tx);
+				   struct __kernel_timex *tx);
 		int (*set_gravity)(struct xnclock *clock,
 				   const struct xnclock_gravity *p);
 		void (*reset_gravity)(struct xnclock *clock);
@@ -275,7 +276,7 @@ static inline int xnclock_set_time(struct xnclock *clock,
 #endif /* !CONFIG_XENO_OPT_EXTCLOCK */
 
 static inline int xnclock_adjust_time(struct xnclock *clock,
-				      struct timex *tx)
+				      struct __kernel_timex *tx)
 {
 	if (clock->ops.adjust_time == NULL)
 		return -EOPNOTSUPP;
include/cobalt/kernel/compat.h +2 -2
index 7bec8c3be..d7f0008d9 100644
@@ -104,11 +104,11 @@ int sys32_get_timeval(struct __kernel_old_timeval *tv,
 int sys32_put_timeval(struct compat_timeval __user *ctv,
 		      const struct __kernel_old_timeval *tv);
 
-int sys32_get_timex(struct timex *tx,
+int sys32_get_timex(struct __kernel_timex *tx,
 		    const struct old_timex32 __user *ctx);
 
 int sys32_put_timex(struct old_timex32 __user *ctx,
-		    const struct timex *tx);
+		    const struct __kernel_timex *tx);
 
 ssize_t sys32_get_fdset(fd_set *fds, const compat_fd_set __user *cfds,
 			size_t cfdsize);
include/cobalt/uapi/kernel/types.h +41 -3

54 lines not on this page · raw message

kernel/cobalt/include/asm-generic/xenomai/wrappers.h +4 -0
index 2e9fb203a..eaeeafd68 100644
@@ -152,6 +152,10 @@ devm_hwmon_device_register_with_groups(struct device *dev, const char *name,
 #error "Xenomai/cobalt requires Linux kernel 3.10 or above"
 #endif /* < 3.10 */
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5,0,0)
+#define __kernel_timex		timex
+#endif
+
 #if LINUX_VERSION_CODE < KERNEL_VERSION(5,1,0)
 #define old_timex32		compat_timex
 #define SO_RCVTIMEO_OLD		SO_RCVTIMEO
kernel/cobalt/posix/clock.c +3 -3
index 4a3365d2a..23a45bba9 100644
@@ -166,7 +166,7 @@ int __cobalt_clock_settime(clockid_t clock_id, const struct timespec64 *ts)
 	return 0;
 }
 
-int __cobalt_clock_adjtime(clockid_t clock_id, struct timex *tx)
+int __cobalt_clock_adjtime(clockid_t clock_id, struct __kernel_timex *tx)
 {
 	int _ret, ret = 0;
 
@@ -199,9 +199,9 @@ COBALT_SYSCALL(clock_settime, current,
 }
 
 COBALT_SYSCALL(clock_adjtime, current,
-	       (clockid_t clock_id, struct timex __user *u_tx))
+	       (clockid_t clock_id, struct __user_old_timex __user *u_tx))
 {
-	struct timex tx;
+	struct __kernel_timex tx;
 	int ret;
 
 	if (cobalt_copy_from_user(&tx, u_tx, sizeof(tx)))
kernel/cobalt/posix/clock.h +2 -2
index 7e45fdcc6..e69e76e1b 100644
@@ -104,7 +104,7 @@ int __cobalt_clock_settime(clockid_t clock_id,
 			   const struct timespec64 *ts);
 
 int __cobalt_clock_adjtime(clockid_t clock_id,
-			   struct timex *tx);
+			   struct __kernel_timex *tx);
 
 int __cobalt_clock_nanosleep(clockid_t clock_id, int flags,
 			     const struct timespec64 *rqt,
@@ -120,7 +120,7 @@ COBALT_SYSCALL_DECL(clock_settime,
 		    (clockid_t clock_id, const struct __user_old_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(clock_adjtime,
-		    (clockid_t clock_id, struct timex __user *u_tx));
+		    (clockid_t clock_id, struct __user_old_timex __user *u_tx));
 
 COBALT_SYSCALL_DECL(clock_nanosleep,
 		    (clockid_t clock_id, int flags,
kernel/cobalt/posix/compat.c +22 -6
index 767a8033a..6002d7480 100644
@@ -98,11 +98,21 @@ int sys32_put_timeval(struct compat_timeval __user *ctv,
 }
 EXPORT_SYMBOL_GPL(sys32_put_timeval);
 
-int sys32_get_timex(struct timex *tx,
+int sys32_get_timex(struct __kernel_timex *tx,
 		    const struct old_timex32 __user *ctx)
 {
+	struct __kernel_old_timeval time;
+	int ret;
+
 	memset(tx, 0, sizeof(*tx));
 
+	ret = sys32_get_timeval(&time, &ctx->time);
+	if (ret)
+		return ret;
+
+	tx->time.tv_sec = time.tv_sec;
+	tx->time.tv_usec = time.tv_usec;
+
 	if (!access_rok(ctx, sizeof(*ctx)) ||
 	    __xn_get_user(tx->modes, &ctx->modes) ||
 	    __xn_get_user(tx->offset, &ctx->offset) ||
@@ -113,8 +123,6 @@ int sys32_get_timex(struct timex *tx,
 	    __xn_get_user(tx->constant, &ctx->constant) ||
 	    __xn_get_user(tx->precision, &ctx->precision) ||
 	    __xn_get_user(tx->tolerance, &ctx->tolerance) ||
-	    __xn_get_user(tx->time.tv_sec, &ctx->time.tv_sec) ||
-	    __xn_get_user(tx->time.tv_usec, &ctx->time.tv_usec) ||
 	    __xn_get_user(tx->tick, &ctx->tick) ||
 	    __xn_get_user(tx->ppsfreq, &ctx->ppsfreq) ||
 	    __xn_get_user(tx->jitter, &ctx->jitter) ||
@@ -131,8 +139,18 @@ int sys32_get_timex(struct timex *tx,
 EXPORT_SYMBOL_GPL(sys32_get_timex);
 
 int sys32_put_timex(struct old_timex32 __user *ctx,
-		    const struct timex *tx)
+		    const struct __kernel_timex *tx)
 {
+	struct __kernel_old_timeval time;
+	int ret;
+
+	time.tv_sec = tx->time.tv_sec;
+	time.tv_usec = tx->time.tv_usec;
+
+	ret = sys32_put_timeval(&ctx->time, &time);
+	if (ret)
+		return ret;
+
 	if (!access_wok(ctx, sizeof(*ctx)) ||
 	    __xn_put_user(tx->modes, &ctx->modes) ||
 	    __xn_put_user(tx->offset, &ctx->offset) ||
@@ -143,8 +161,6 @@ int sys32_put_timex(struct old_timex32 __user *ctx,
 	    __xn_put_user(tx->constant, &ctx->constant) ||
 	    __xn_put_user(tx->precision, &ctx->precision) ||
 	    __xn_put_user(tx->tolerance, &ctx->tolerance) ||
-	    __xn_put_user(tx->time.tv_sec, &ctx->time.tv_sec) ||
-	    __xn_put_user(tx->time.tv_usec, &ctx->time.tv_usec) ||
 	    __xn_put_user(tx->tick, &ctx->tick) ||
 	    __xn_put_user(tx->ppsfreq, &ctx->ppsfreq) ||
 	    __xn_put_user(tx->jitter, &ctx->jitter) ||
kernel/cobalt/posix/syscall32.c +1 -1
index 5c858806b..4f819e0e5 100644
@@ -174,7 +174,7 @@ COBALT_SYSCALL32emu(clock_settime, current,
 COBALT_SYSCALL32emu(clock_adjtime, current,
 		    (clockid_t clock_id, struct old_timex32 __user *u_tx))
 {
-	struct timex tx;
+	struct __kernel_timex tx;
 	int ret;
 
 	ret = sys32_get_timex(&tx, u_tx);
kernel/cobalt/trace/cobalt-posix.h +2 -2
index 3a649a671..cff1bd9b7 100644
@@ -764,12 +764,12 @@ DEFINE_EVENT(cobalt_clock_timespec, cobalt_clock_settime,
 );
 
 TRACE_EVENT(cobalt_clock_adjtime,
-	TP_PROTO(clockid_t clk_id, struct timex *tx),
+	TP_PROTO(clockid_t clk_id, struct __kernel_timex *tx),
 	TP_ARGS(clk_id, tx),
 
 	TP_STRUCT__entry(
 		__field(clockid_t, clk_id)
-		__field(struct timex *, tx)
+		__field(struct __kernel_timex *, tx)
 	),
 
 	TP_fast_assign(
Signature · 1 line
2.26.2