xenomai.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/12] y2038: Add time64_t support to scheduler and thread APIs
@ 2023-07-05  6:38 Florian Bezdeka
  2023-07-05  6:38 ` [PATCH 01/12] y2038: cobalt: Introduce sched_param_ex64 and use it internally Florian Bezdeka
                   ` (12 more replies)
  0 siblings, 13 replies; 28+ messages in thread
From: Florian Bezdeka @ 2023-07-05  6:38 UTC (permalink / raw)
  To: jan.kiszka, xenomai; +Cc: Florian Bezdeka

Hi all,

this is hopefully the last preparation series necessary to turn on
time64_t support (a.k.a. y2038 support). 

With this series applied the Xenomai specific APIs around scheduler and
thread APIs will support time64_t when requested. The final "turn on by
default" switch will be part of the final y2038 series (which is hopefully
the next one).

The remaining stuff can be found in my y2038 queue at [1].
The Xenomai hackerspace wiki is up to date and represents the current
state of the y2038 work. See [2].

Best regards,
Florian

[1] https://gitlab.com/Xenomai/xenomai-hacker-space/-/commits/florian%2Fy2038
[2] https://gitlab.com/Xenomai/xenomai-hacker-space/-/wikis/y2038/Y2038_Roadmap

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
Florian Bezdeka (12):
      y2038: cobalt: Introduce sched_param_ex64 and use it internally
      y2038: cobalt: Introduce sched_config64 and use it internally
      y2038: cobalt/posix/{sched,thread}: Add time64_t based syscalls
      y2038: lib/cobalt/{sched,thread}: Dispatch time64_t related services
      y2038: cobalt/uapi: Introduce xntimespec for struct sched_param_ex API
      y2038: cobalt/uapi: Align memory layout for time64 related types
      y2038: cobalt/uapi: Remove __user_old_{timespec,itimerspec,timeval,timex}
      y2038: testsuite/smokey/y2038: Fix reporting of thread return status
      y2038: testsuite/smokey/y2038: Add tests for sched_param_ex related syscalls
      y2038: testsuite/smokey/y2038: Fix a race in the pselect interruption test
      y2038: testsuite/smokey/y2038: Fix normalization of struct xn_timespec64
      testsuite/smokey: Fix unconditional unloads of the xeno_rtdmtest module

 include/cobalt/kernel/compat.h                     |   9 +-
 include/cobalt/uapi/kernel/types.h                 |  53 ----
 include/cobalt/uapi/sched.h                        |  20 +-
 include/cobalt/uapi/syscall.h                      |   7 +
 .../arch/arm/include/asm/xenomai/uapi/features.h   |   2 +-
 .../arch/arm64/include/asm/xenomai/uapi/features.h |   2 +-
 .../arch/x86/include/asm/xenomai/uapi/features.h   |   2 +-
 .../cobalt/include/asm-generic/xenomai/syscall.h   |  20 +-
 kernel/cobalt/posix/clock.c                        |  13 +-
 kernel/cobalt/posix/clock.h                        |  29 +-
 kernel/cobalt/posix/compat.c                       |   5 +-
 kernel/cobalt/posix/cond.c                         |   2 +-
 kernel/cobalt/posix/cond.h                         |   2 +-
 kernel/cobalt/posix/event.c                        |   2 +-
 kernel/cobalt/posix/event.h                        |   2 +-
 kernel/cobalt/posix/io.c                           |   2 +-
 kernel/cobalt/posix/io.h                           |   2 +-
 kernel/cobalt/posix/monitor.c                      |   2 +-
 kernel/cobalt/posix/monitor.h                      |   2 +-
 kernel/cobalt/posix/mqueue.c                       |   4 +-
 kernel/cobalt/posix/mqueue.h                       |   4 +-
 kernel/cobalt/posix/mutex.c                        |   2 +-
 kernel/cobalt/posix/mutex.h                        |   2 +-
 kernel/cobalt/posix/sched.c                        | 293 +++++++++++++----
 kernel/cobalt/posix/sched.h                        |  55 +++-
 kernel/cobalt/posix/sem.c                          |   2 +-
 kernel/cobalt/posix/sem.h                          |   2 +-
 kernel/cobalt/posix/signal.c                       |   2 +-
 kernel/cobalt/posix/signal.h                       |   2 +-
 kernel/cobalt/posix/syscall32.c                    |  24 +-
 kernel/cobalt/posix/thread.c                       | 172 ++++++++--
 kernel/cobalt/posix/thread.h                       |  55 +++-
 kernel/cobalt/posix/timer.c                        |  14 +-
 kernel/cobalt/posix/timer.h                        |   6 +-
 kernel/cobalt/posix/timerfd.c                      |  14 +-
 kernel/cobalt/posix/timerfd.h                      |   6 +-
 kernel/cobalt/trace/cobalt-posix.h                 |  29 +-
 lib/cobalt/clock.c                                 |   2 +-
 lib/cobalt/internal.h                              |   5 +
 lib/cobalt/sched.c                                 |  38 ++-
 lib/cobalt/thread.c                                |  29 +-
 lib/cobalt/timer.c                                 |   4 +-
 lib/cobalt/timerfd.c                               |   4 +-
 testsuite/smokey/cpu-affinity/cpu-affinity.c       |  13 +-
 testsuite/smokey/rtdm/rtdm.c                       |   7 +-
 testsuite/smokey/y2038/syscall-tests.c             | 346 ++++++++++++++++++++-
 46 files changed, 1038 insertions(+), 276 deletions(-)
---
base-commit: ba202eb8e976bbd03c524250dd4fa6810d167851
change-id: 20230630-florian-y2038-part-four-upstreaming-0c10a5eccfc1

Best regards,
-- 
Florian Bezdeka <florian.bezdeka@siemens.com>


^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 01/12] y2038: cobalt: Introduce sched_param_ex64 and use it internally
  2023-07-05  6:38 [PATCH 00/12] y2038: Add time64_t support to scheduler and thread APIs Florian Bezdeka
@ 2023-07-05  6:38 ` Florian Bezdeka
  2023-07-06  7:13   ` Jan Kiszka
  2023-07-06  7:14   ` Jan Kiszka
  2023-07-05  6:38 ` [PATCH 02/12] y2038: cobalt: Introduce sched_config64 " Florian Bezdeka
                   ` (11 subsequent siblings)
  12 siblings, 2 replies; 28+ messages in thread
From: Florian Bezdeka @ 2023-07-05  6:38 UTC (permalink / raw)
  To: jan.kiszka, xenomai; +Cc: Florian Bezdeka

Introducing a new type sched_param_ex64. All members are (always) based
on time64_t. All internal APIs have been migrated now. Existing compat
and native system call entry points will do the necessary translation.

This is a preparation step for introducing time64_t based cobalt thread
cobalt services.

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 include/cobalt/kernel/compat.h     |   5 +-
 kernel/cobalt/posix/clock.h        |  38 +++++++++--
 kernel/cobalt/posix/compat.c       |   5 +-
 kernel/cobalt/posix/sched.c        |  39 +++++++-----
 kernel/cobalt/posix/sched.h        |   8 +--
 kernel/cobalt/posix/syscall32.c    |  12 ++--
 kernel/cobalt/posix/thread.c       | 126 ++++++++++++++++++++++++++++++-------
 kernel/cobalt/posix/thread.h       |  39 ++++++++++--
 kernel/cobalt/trace/cobalt-posix.h |  20 +++---
 9 files changed, 219 insertions(+), 73 deletions(-)

diff --git a/include/cobalt/kernel/compat.h b/include/cobalt/kernel/compat.h
index 275735df5..f2dce74b4 100644
--- a/include/cobalt/kernel/compat.h
+++ b/include/cobalt/kernel/compat.h
@@ -26,6 +26,7 @@
 #include <cobalt/uapi/sched.h>
 
 struct mq_attr;
+struct sched_param_ex64;
 
 struct __compat_sched_ss_param {
 	int __sched_low_priority;
@@ -117,12 +118,12 @@ int sys32_put_fdset(compat_fd_set __user *cfds, const fd_set *fds,
 		    size_t fdsize);
 
 int sys32_get_param_ex(int policy,
-		       struct sched_param_ex *p,
+		       struct sched_param_ex64 *p,
 		       const struct compat_sched_param_ex __user *u_cp);
 
 int sys32_put_param_ex(int policy,
 		       struct compat_sched_param_ex __user *u_cp,
-		       const struct sched_param_ex *p);
+		       const struct sched_param_ex64 *p);
 
 int sys32_get_mqattr(struct mq_attr *ap,
 		     const struct compat_mq_attr __user *u_cap);
diff --git a/kernel/cobalt/posix/clock.h b/kernel/cobalt/posix/clock.h
index 38b59e24f..b0fc84396 100644
--- a/kernel/cobalt/posix/clock.h
+++ b/kernel/cobalt/posix/clock.h
@@ -18,6 +18,7 @@
 #ifndef _COBALT_POSIX_CLOCK_H
 #define _COBALT_POSIX_CLOCK_H
 
+#include <linux/compat.h>
 #include <linux/types.h>
 #include <linux/time.h>
 #include <linux/cpumask.h>
@@ -38,6 +39,14 @@ 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 void ns2kts(struct __kernel_timespec *kts, xnticks_t ticks)
+{
+	unsigned long nsecs;
+
+	kts->tv_sec = xnclock_divrem_billion(ticks, &nsecs);
+	kts->tv_nsec = (long long)nsecs;
+}
+
 static inline xnticks_t ts2ns(const struct timespec64 *ts)
 {
 	xnticks_t nsecs = ts->tv_nsec;
@@ -48,6 +57,23 @@ static inline xnticks_t ts2ns(const struct timespec64 *ts)
 	return nsecs;
 }
 
+static inline xnticks_t kts2ns(const struct __kernel_timespec *ts)
+{
+	xnticks_t nsecs = ts->tv_nsec;
+
+	/* zero out padding in compat mode */
+	if (in_compat_syscall())
+		nsecs &= 0xFFFFFFFFUL;
+
+	/* In 32-bit mode, this drops the padding */
+	nsecs = (long)nsecs;
+
+	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;
@@ -111,34 +137,34 @@ int __cobalt_clock_nanosleep(clockid_t clock_id, int flags,
 			     struct timespec64 *rmt);
 
 COBALT_SYSCALL_DECL(clock_getres,
-		    (clockid_t clock_id, struct __user_old_timespec __user *u_ts));
+		    (clockid_t clock_id, struct __kernel_old_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(clock_getres64,
 		    (clockid_t clock_id, struct __kernel_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(clock_gettime,
-		    (clockid_t clock_id, struct __user_old_timespec __user *u_ts));
+		    (clockid_t clock_id, struct __kernel_old_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(clock_gettime64,
 		    (clockid_t clock_id, struct __kernel_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(clock_settime,
-		    (clockid_t clock_id, const struct __user_old_timespec __user *u_ts));
+		    (clockid_t clock_id, const struct __kernel_old_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(clock_settime64,
 		    (clockid_t clock_id,
 			 const struct __kernel_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(clock_adjtime,
-		    (clockid_t clock_id, struct __user_old_timex __user *u_tx));
+		    (clockid_t clock_id, struct old_timex32 __user *u_tx));
 
 COBALT_SYSCALL_DECL(clock_adjtime64,
 		    (clockid_t clock_id, struct __kernel_timex __user *u_tx));
 
 COBALT_SYSCALL_DECL(clock_nanosleep,
 		    (clockid_t clock_id, int flags,
-		     const struct __user_old_timespec __user *u_rqt,
-		     struct __user_old_timespec __user *u_rmt));
+		     const struct __kernel_old_timespec __user *u_rqt,
+		     struct __kernel_old_timespec __user *u_rmt));
 
 COBALT_SYSCALL_DECL(clock_nanosleep64,
 		    (clockid_t clock_id, int flags,
diff --git a/kernel/cobalt/posix/compat.c b/kernel/cobalt/posix/compat.c
index c7fc4fc33..710cde638 100644
--- a/kernel/cobalt/posix/compat.c
+++ b/kernel/cobalt/posix/compat.c
@@ -21,6 +21,7 @@
 #include <cobalt/kernel/compat.h>
 #include <asm/xenomai/syscall.h>
 #include <xenomai/posix/mqueue.h>
+#include <xenomai/posix/thread.h>
 
 int sys32_get_timespec(struct timespec64 *ts,
 		       const struct old_timespec32 __user *u_cts)
@@ -207,7 +208,7 @@ int sys32_put_fdset(compat_fd_set __user *cfds, const fd_set *fds,
 }
 
 int sys32_get_param_ex(int policy,
-		       struct sched_param_ex *p,
+		       struct sched_param_ex64 *p,
 		       const struct compat_sched_param_ex __user *u_cp)
 {
 	struct compat_sched_param_ex cpex;
@@ -244,7 +245,7 @@ EXPORT_SYMBOL_GPL(sys32_get_param_ex);
 
 int sys32_put_param_ex(int policy,
 		       struct compat_sched_param_ex __user *u_cp,
-		       const struct sched_param_ex *p)
+		       const struct sched_param_ex64 *p)
 {
 	struct compat_sched_param_ex cpex;
 
diff --git a/kernel/cobalt/posix/sched.c b/kernel/cobalt/posix/sched.c
index 994ee88d9..1c3a7de61 100644
--- a/kernel/cobalt/posix/sched.c
+++ b/kernel/cobalt/posix/sched.c
@@ -24,7 +24,7 @@
 
 struct xnsched_class *
 cobalt_sched_policy_param(union xnsched_policy_param *param,
-			  int u_policy, const struct sched_param_ex *param_ex,
+			  int u_policy, const struct sched_param_ex64 *param_ex,
 			  xnticks_t *tslice_r)
 {
 	struct xnsched_class *sched_class;
@@ -73,7 +73,7 @@ cobalt_sched_policy_param(union xnsched_policy_param *param,
 		break;
 	case SCHED_RR:
 		/* if unspecified, use current one. */
-		tslice = u_ts2ns(&param_ex->sched_rr_quantum);
+		tslice = kts2ns(&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 = u_ts2ns(&param_ex->sched_ss_init_budget);
-		param->pss.repl_period = u_ts2ns(&param_ex->sched_ss_repl_period);
+		param->pss.init_budget = kts2ns(&param_ex->sched_ss_init_budget);
+		param->pss.repl_period = kts2ns(&param_ex->sched_ss_repl_period);
 		param->pss.max_repl = param_ex->sched_ss_max_repl;
 		sched_class = &xnsched_class_sporadic;
 		break;
@@ -707,7 +707,7 @@ COBALT_SYSCALL(sched_getconfig_np, conforming,
 }
 
 int __cobalt_sched_weightprio(int policy,
-			      const struct sched_param_ex *param_ex)
+			      const struct sched_param_ex64 *param_ex)
 {
 	struct xnsched_class *sched_class;
 	union xnsched_policy_param param;
@@ -728,17 +728,19 @@ int __cobalt_sched_weightprio(int policy,
 COBALT_SYSCALL(sched_weightprio, current,
 	       (int policy, const struct sched_param_ex __user *u_param))
 {
-	struct sched_param_ex param_ex;
+	struct sched_param_ex64 param_ex;
+	int ret;
 
-	if (cobalt_copy_from_user(&param_ex, u_param, sizeof(param_ex)))
-		return -EFAULT;
+	ret = cobalt_thread_get_schedparam_ex(&param_ex, u_param, policy);
+	if (ret)
+		return ret;
 
 	return __cobalt_sched_weightprio(policy, &param_ex);
 }
 
 int cobalt_sched_setscheduler_ex(pid_t pid,
 				 int policy,
-				 const struct sched_param_ex *param_ex,
+				 const struct sched_param_ex64 *param_ex,
 				 __u32 __user *u_winoff,
 				 int __user *u_promoted)
 {
@@ -781,10 +783,12 @@ COBALT_SYSCALL(sched_setscheduler_ex, conforming,
 		__u32 __user *u_winoff,
 		int __user *u_promoted))
 {
-	struct sched_param_ex param_ex;
+	struct sched_param_ex64 param_ex;
+	int ret;
 
-	if (cobalt_copy_from_user(&param_ex, u_param, sizeof(param_ex)))
-		return -EFAULT;
+	ret = cobalt_thread_get_schedparam_ex(&param_ex, u_param, policy);
+	if (ret)
+		return ret;
 
 	return cobalt_sched_setscheduler_ex(pid, policy, &param_ex,
 					    u_winoff, u_promoted);
@@ -792,7 +796,7 @@ COBALT_SYSCALL(sched_setscheduler_ex, conforming,
 
 int cobalt_sched_getscheduler_ex(pid_t pid,
 				 int *policy_r,
-				 struct sched_param_ex *param_ex)
+				 struct sched_param_ex64 *param_ex)
 {
 	struct cobalt_thread *thread;
 	spl_t s;
@@ -817,15 +821,18 @@ COBALT_SYSCALL(sched_getscheduler_ex, current,
 		int __user *u_policy,
 		struct sched_param_ex __user *u_param))
 {
-	struct sched_param_ex param_ex;
+	struct sched_param_ex64 param_ex;
 	int ret, policy;
 
 	ret = cobalt_sched_getscheduler_ex(pid, &policy, &param_ex);
 	if (ret)
 		return ret;
 
-	if (cobalt_copy_to_user(u_param, &param_ex, sizeof(param_ex)) ||
-	    cobalt_copy_to_user(u_policy, &policy, sizeof(policy)))
+	ret = cobalt_thread_put_schedparam_ex(u_param, &param_ex, policy);
+	if (ret)
+		return ret;
+
+	if (cobalt_copy_to_user(u_policy, &policy, sizeof(policy)))
 		return -EFAULT;
 
 	return 0;
diff --git a/kernel/cobalt/posix/sched.h b/kernel/cobalt/posix/sched.h
index 2b23be0a6..e8b9f9113 100644
--- a/kernel/cobalt/posix/sched.h
+++ b/kernel/cobalt/posix/sched.h
@@ -35,7 +35,7 @@ struct cobalt_sched_group {
 };
 
 int __cobalt_sched_weightprio(int policy,
-			      const struct sched_param_ex *param_ex);
+			      const struct sched_param_ex64 *param_ex);
 
 int __cobalt_sched_setconfig_np(int cpu, int policy,
 				void __user *u_config,
@@ -59,17 +59,17 @@ ssize_t __cobalt_sched_getconfig_np(int cpu, int policy,
 							  size_t len));
 int cobalt_sched_setscheduler_ex(pid_t pid,
 				 int policy,
-				 const struct sched_param_ex *param_ex,
+				 const struct sched_param_ex64 *param_ex,
 				 __u32 __user *u_winoff,
 				 int __user *u_promoted);
 
 int cobalt_sched_getscheduler_ex(pid_t pid,
 				 int *policy_r,
-				 struct sched_param_ex *param_ex);
+				 struct sched_param_ex64 *param_ex);
 
 struct xnsched_class *
 cobalt_sched_policy_param(union xnsched_policy_param *param,
-			  int u_policy, const struct sched_param_ex *param_ex,
+			  int u_policy, const struct sched_param_ex64 *param_ex,
 			  xnticks_t *tslice_r);
 
 COBALT_SYSCALL_DECL(sched_yield, (void));
diff --git a/kernel/cobalt/posix/syscall32.c b/kernel/cobalt/posix/syscall32.c
index 780d276b1..9b09d734d 100644
--- a/kernel/cobalt/posix/syscall32.c
+++ b/kernel/cobalt/posix/syscall32.c
@@ -44,7 +44,7 @@ COBALT_SYSCALL32emu(thread_create, init,
 		     int xid,
 		     __u32 __user *u_winoff))
 {
-	struct sched_param_ex param_ex;
+	struct sched_param_ex64 param_ex;
 	int ret;
 
 	ret = sys32_get_param_ex(policy, &param_ex, u_param_ex);
@@ -61,7 +61,7 @@ COBALT_SYSCALL32emu(thread_setschedparam_ex, conforming,
 		     __u32 __user *u_winoff,
 		     int __user *u_promoted))
 {
-	struct sched_param_ex param_ex;
+	struct sched_param_ex64 param_ex;
 	int ret;
 
 	ret = sys32_get_param_ex(policy, &param_ex, u_param_ex);
@@ -77,7 +77,7 @@ COBALT_SYSCALL32emu(thread_getschedparam_ex, current,
 		     int __user *u_policy,
 		     struct compat_sched_param_ex __user *u_param))
 {
-	struct sched_param_ex param_ex;
+	struct sched_param_ex64 param_ex;
 	int ret, policy;
 
 	ret = cobalt_thread_getschedparam_ex(pth, &policy, &param_ex);
@@ -343,7 +343,7 @@ COBALT_SYSCALL32emu(sched_weightprio, current,
 		    (int policy,
 		     const struct compat_sched_param_ex __user *u_param))
 {
-	struct sched_param_ex param_ex;
+	struct sched_param_ex64 param_ex;
 	int ret;
 
 	ret = sys32_get_param_ex(policy, &param_ex, u_param);
@@ -492,7 +492,7 @@ COBALT_SYSCALL32emu(sched_setscheduler_ex, conforming,
 		     __u32 __user *u_winoff,
 		     int __user *u_promoted))
 {
-	struct sched_param_ex param_ex;
+	struct sched_param_ex64 param_ex;
 	int ret;
 
 	ret = sys32_get_param_ex(policy, &param_ex, u_param_ex);
@@ -508,7 +508,7 @@ COBALT_SYSCALL32emu(sched_getscheduler_ex, current,
 		     int __user *u_policy,
 		     struct compat_sched_param_ex __user *u_param))
 {
-	struct sched_param_ex param_ex;
+	struct sched_param_ex64 param_ex;
 	int ret, policy;
 
 	ret = cobalt_sched_getscheduler_ex(pid, &policy, &param_ex);
diff --git a/kernel/cobalt/posix/thread.c b/kernel/cobalt/posix/thread.c
index 94a6e394e..2fa8a9e6a 100644
--- a/kernel/cobalt/posix/thread.c
+++ b/kernel/cobalt/posix/thread.c
@@ -240,7 +240,7 @@ struct xnthread_personality *cobalt_thread_finalize(struct xnthread *zombie)
 }
 
 int __cobalt_thread_setschedparam_ex(struct cobalt_thread *thread, int policy,
-				     const struct sched_param_ex *param_ex)
+				     const struct sched_param_ex64 *param_ex)
 {
 	struct xnsched_class *sched_class;
 	union xnsched_policy_param param;
@@ -278,7 +278,7 @@ out:
 
 int __cobalt_thread_getschedparam_ex(struct cobalt_thread *thread,
 				     int *policy_r,
-				     struct sched_param_ex *param_ex)
+				     struct sched_param_ex64 *param_ex)
 {
 	struct xnsched_class *base_class;
 	struct xnthread *base_thread;
@@ -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)) {
-			u_ns2ts(&param_ex->sched_rr_quantum, base_thread->rrperiod);
+			ns2kts(&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;
-		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);
+		ns2kts(&param_ex->sched_ss_repl_period, base_thread->pss->param.repl_period);
+		ns2kts(&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;
 	}
@@ -346,7 +346,7 @@ out:
 
 static int pthread_create(struct cobalt_thread **thread_p,
 			  int policy,
-			  const struct sched_param_ex *param_ex,
+			  const struct sched_param_ex64 *param_ex,
 			  struct task_struct *task)
 {
 	struct cobalt_process *process = cobalt_current_process();
@@ -479,9 +479,87 @@ static struct cobalt_thread *thread_lookup_or_shadow(unsigned long pth,
 	return thread;
 }
 
+int cobalt_thread_get_schedparam_ex(struct sched_param_ex64 *out,
+				    const struct sched_param_ex *in, int policy)
+{
+	struct sched_param_ex tmp;
+
+	if (in == NULL || cobalt_copy_from_user(&tmp, in, sizeof(tmp)))
+		return -EFAULT;
+
+	out->sched_priority = tmp.sched_priority;
+
+	switch (policy) {
+	case SCHED_SPORADIC:
+		out->sched_ss_low_priority = tmp.sched_ss_low_priority;
+		out->sched_ss_max_repl = tmp.sched_ss_max_repl;
+		out->sched_ss_repl_period.tv_sec =
+			tmp.sched_ss_repl_period.tv_sec;
+		out->sched_ss_repl_period.tv_nsec =
+			tmp.sched_ss_repl_period.tv_nsec;
+		out->sched_ss_init_budget.tv_sec =
+			tmp.sched_ss_init_budget.tv_sec;
+		out->sched_ss_init_budget.tv_nsec =
+			tmp.sched_ss_init_budget.tv_nsec;
+		break;
+	case SCHED_RR:
+		out->sched_rr_quantum.tv_sec = tmp.sched_rr_quantum.tv_sec;
+		out->sched_rr_quantum.tv_nsec = tmp.sched_rr_quantum.tv_nsec;
+		break;
+	case SCHED_TP:
+		out->sched_tp_partition = tmp.sched_tp_partition;
+		break;
+	case SCHED_QUOTA:
+		out->sched_quota_group = tmp.sched_quota_group;
+		break;
+	default:
+		break;
+	}
+
+	return 0;
+}
+
+int cobalt_thread_put_schedparam_ex(struct sched_param_ex *out,
+				    const struct sched_param_ex64 *in,
+				    int policy)
+{
+	struct sched_param_ex tmp;
+
+	tmp.sched_priority = in->sched_priority;
+
+	switch (policy) {
+	case SCHED_SPORADIC:
+		tmp.sched_ss_low_priority = in->sched_ss_low_priority;
+		tmp.sched_ss_max_repl = in->sched_ss_max_repl;
+		tmp.sched_ss_repl_period.tv_sec =
+			in->sched_ss_repl_period.tv_sec;
+		tmp.sched_ss_repl_period.tv_nsec =
+			in->sched_ss_repl_period.tv_nsec;
+		tmp.sched_ss_init_budget.tv_sec =
+			in->sched_ss_init_budget.tv_sec;
+		tmp.sched_ss_init_budget.tv_nsec =
+			in->sched_ss_init_budget.tv_nsec;
+		break;
+	case SCHED_RR:
+		tmp.sched_rr_quantum.tv_sec = in->sched_rr_quantum.tv_sec;
+		tmp.sched_rr_quantum.tv_nsec = in->sched_rr_quantum.tv_nsec;
+		break;
+	case SCHED_TP:
+		tmp.sched_tp_partition = in->sched_tp_partition;
+		break;
+	case SCHED_QUOTA:
+		tmp.sched_quota_group = in->sched_quota_group;
+		break;
+	default:
+		break;
+	}
+
+	return cobalt_copy_to_user(out, &tmp, sizeof(tmp));
+}
+
 int cobalt_thread_setschedparam_ex(unsigned long pth,
 				   int policy,
-				   const struct sched_param_ex *param_ex,
+				   const struct sched_param_ex64 *param_ex,
 				   __u32 __user *u_winoff,
 				   int __user *u_promoted)
 {
@@ -508,18 +586,22 @@ COBALT_SYSCALL(thread_setschedparam_ex, conforming,
 		__u32 __user *u_winoff,
 		int __user *u_promoted))
 {
-	struct sched_param_ex param_ex;
+	struct sched_param_ex64 param_ex;
+	int ret;
 
-	if (cobalt_copy_from_user(&param_ex, u_param, sizeof(param_ex)))
-		return -EFAULT;
+	ret = cobalt_thread_get_schedparam_ex(&param_ex, u_param, policy);
+	if (ret)
+		return ret;
 
-	return cobalt_thread_setschedparam_ex(pth, policy, &param_ex,
-					      u_winoff, u_promoted);
+	ret = cobalt_thread_setschedparam_ex(pth, policy, &param_ex, u_winoff,
+					     u_promoted);
+
+	return ret;
 }
 
 int cobalt_thread_getschedparam_ex(unsigned long pth,
 				   int *policy_r,
-				   struct sched_param_ex *param_ex)
+				   struct sched_param_ex64 *param_ex)
 {
 	struct cobalt_local_hkey hkey;
 	struct cobalt_thread *thread;
@@ -545,7 +627,7 @@ COBALT_SYSCALL(thread_getschedparam_ex, current,
 		int __user *u_policy,
 		struct sched_param_ex __user *u_param))
 {
-	struct sched_param_ex param_ex;
+	struct sched_param_ex64 param_ex;
 	int ret, policy;
 
 	ret = cobalt_thread_getschedparam_ex(pth, &policy, &param_ex);
@@ -556,7 +638,7 @@ COBALT_SYSCALL(thread_getschedparam_ex, current,
 	if (ret)
 		return ret;
 
-	return cobalt_copy_to_user(u_param, &param_ex, sizeof(param_ex));
+	return cobalt_thread_put_schedparam_ex(u_param, &param_ex, policy);
 }
 
 int cobalt_thread_setschedprio(unsigned long pth,
@@ -564,7 +646,7 @@ int cobalt_thread_setschedprio(unsigned long pth,
 			       __u32 __user *u_winoff,
 			       int __user *u_promoted)
 {
-	struct sched_param_ex param_ex;
+	struct sched_param_ex64 param_ex;
 	struct cobalt_thread *thread;
 	int ret, policy, promoted;
 
@@ -597,7 +679,7 @@ COBALT_SYSCALL(thread_setschedprio, conforming,
 }
 
 int __cobalt_thread_create(unsigned long pth, int policy,
-			   struct sched_param_ex *param_ex,
+			   struct sched_param_ex64 *param_ex,
 			   int xid, __u32 __user *u_winoff)
 {
 	struct cobalt_thread *thread = NULL;
@@ -650,10 +732,10 @@ COBALT_SYSCALL(thread_create, init,
 		int xid,
 		__u32 __user *u_winoff))
 {
-	struct sched_param_ex param_ex;
+	struct sched_param_ex64 param_ex;
 	int ret;
 
-	ret = cobalt_copy_from_user(&param_ex, u_param, sizeof(param_ex));
+	ret = cobalt_thread_get_schedparam_ex(&param_ex, u_param, policy);
 	if (ret)
 		return ret;
 
@@ -665,7 +747,7 @@ cobalt_thread_shadow(struct cobalt_local_hkey *hkey,
 		     __u32 __user *u_winoff)
 {
 	struct cobalt_thread *thread = NULL;
-	struct sched_param_ex param_ex;
+	struct sched_param_ex64 param_ex;
 	int ret;
 
 	if (xnthread_current())
@@ -911,7 +993,7 @@ EXPORT_SYMBOL_GPL(cobalt_thread_restrict);
 #endif /* !CONFIG_XENO_OPT_COBALT_EXTENSION */
 
 const char *cobalt_trace_parse_sched_params(struct trace_seq *p, int policy,
-					    struct sched_param_ex *params)
+					    struct sched_param_ex64 *params)
 {
 	const char *ret = trace_seq_buffer_ptr(p);
 
@@ -930,7 +1012,7 @@ const char *cobalt_trace_parse_sched_params(struct trace_seq *p, int policy,
 		break;
 	case SCHED_SPORADIC:
 		trace_seq_printf(p, "priority=%d, low_priority=%d, "
-				 "budget=(%ld.%09ld), period=(%ld.%09ld), "
+				 "budget=(%lld.%09lld), period=(%lld.%09lld), "
 				 "maxrepl=%d",
 				 params->sched_priority,
 				 params->sched_ss_low_priority,
diff --git a/kernel/cobalt/posix/thread.h b/kernel/cobalt/posix/thread.h
index 0959ff6d7..8916d05b9 100644
--- a/kernel/cobalt/posix/thread.h
+++ b/kernel/cobalt/posix/thread.h
@@ -112,6 +112,27 @@ struct cobalt_sigwait_context {
 	struct siginfo *si;
 };
 
+struct __sched_ss_param64 {
+	int __sched_low_priority;
+	struct __kernel_timespec __sched_repl_period;
+	struct __kernel_timespec __sched_init_budget;
+	int __sched_max_repl;
+};
+
+struct __sched_rr_param64 {
+	struct __kernel_timespec __sched_rr_quantum;
+};
+
+struct sched_param_ex64 {
+	int sched_priority;
+	union {
+		struct __sched_ss_param64 ss;
+		struct __sched_rr_param64 rr;
+		struct __sched_tp_param tp;
+		struct __sched_quota_param quota;
+	} sched_u;
+};
+
 static inline struct cobalt_thread *cobalt_current_thread(void)
 {
 	struct xnthread *curr = xnthread_current();
@@ -119,25 +140,33 @@ static inline struct cobalt_thread *cobalt_current_thread(void)
 }
 
 int __cobalt_thread_create(unsigned long pth, int policy,
-			   struct sched_param_ex __user *u_param,
+			   struct sched_param_ex64 __user *u_param,
 			   int xid, __u32 __user *u_winoff);
 
+int cobalt_thread_get_schedparam_ex(struct sched_param_ex64 *out,
+				    const struct sched_param_ex *in,
+				    int policy);
+
+int cobalt_thread_put_schedparam_ex(struct sched_param_ex *out,
+				    const struct sched_param_ex64 *in,
+				    int policy);
+
 int __cobalt_thread_setschedparam_ex(struct cobalt_thread *thread, int policy,
-				     const struct sched_param_ex *param_ex);
+				     const struct sched_param_ex64 *param_ex);
 
 int cobalt_thread_setschedparam_ex(unsigned long pth,
 				   int policy,
-				   const struct sched_param_ex *param_ex,
+				   const struct sched_param_ex64 *param_ex,
 				   __u32 __user *u_winoff,
 				   int __user *u_promoted);
 
 int cobalt_thread_getschedparam_ex(unsigned long pth,
 				   int *policy_r,
-				   struct sched_param_ex *param_ex);
+				   struct sched_param_ex64 *param_ex);
 
 int __cobalt_thread_getschedparam_ex(struct cobalt_thread *thread,
 				     int *policy_r,
-				     struct sched_param_ex *param_ex);
+				     struct sched_param_ex64 *param_ex);
 
 int cobalt_thread_setschedprio(unsigned long pth,
 			       int prio,
diff --git a/kernel/cobalt/trace/cobalt-posix.h b/kernel/cobalt/trace/cobalt-posix.h
index 47dc77e1c..c6c430cff 100644
--- a/kernel/cobalt/trace/cobalt-posix.h
+++ b/kernel/cobalt/trace/cobalt-posix.h
@@ -217,21 +217,21 @@ DECLARE_EVENT_CLASS(cobalt_syscall_exit,
 			 {SCHED_WEAK, "weak"})
 
 const char *cobalt_trace_parse_sched_params(struct trace_seq *, int,
-					    struct sched_param_ex *);
+					    struct sched_param_ex64 *);
 
 #define __parse_sched_params(policy, params)			\
 	cobalt_trace_parse_sched_params(p, policy,		\
-					(struct sched_param_ex *)(params))
+					(struct sched_param_ex64 *)(params))
 
 DECLARE_EVENT_CLASS(cobalt_posix_schedparam,
 	TP_PROTO(unsigned long pth, int policy,
-		 const struct sched_param_ex *param_ex),
+		 const struct sched_param_ex64 *param_ex),
 	TP_ARGS(pth, policy, param_ex),
 
 	TP_STRUCT__entry(
 		__field(unsigned long, pth)
 		__field(int, policy)
-		__dynamic_array(char, param_ex, sizeof(struct sched_param_ex))
+		__dynamic_array(char, param_ex, sizeof(struct sched_param_ex64))
 	),
 
 	TP_fast_assign(
@@ -250,13 +250,13 @@ DECLARE_EVENT_CLASS(cobalt_posix_schedparam,
 
 DECLARE_EVENT_CLASS(cobalt_posix_scheduler,
 	TP_PROTO(pid_t pid, int policy,
-		 const struct sched_param_ex *param_ex),
+		 const struct sched_param_ex64 *param_ex),
 	TP_ARGS(pid, policy, param_ex),
 
 	TP_STRUCT__entry(
 		__field(pid_t, pid)
 		__field(int, policy)
-		__dynamic_array(char, param_ex, sizeof(struct sched_param_ex))
+		__dynamic_array(char, param_ex, sizeof(struct sched_param_ex64))
 	),
 
 	TP_fast_assign(
@@ -307,19 +307,19 @@ DEFINE_EVENT(cobalt_syscall_exit, cobalt_root_sysexit,
 
 DEFINE_EVENT(cobalt_posix_schedparam, cobalt_pthread_create,
 	TP_PROTO(unsigned long pth, int policy,
-		 const struct sched_param_ex *param_ex),
+		 const struct sched_param_ex64 *param_ex),
 	TP_ARGS(pth, policy, param_ex)
 );
 
 DEFINE_EVENT(cobalt_posix_schedparam, cobalt_pthread_setschedparam,
 	TP_PROTO(unsigned long pth, int policy,
-		 const struct sched_param_ex *param_ex),
+		 const struct sched_param_ex64 *param_ex),
 	TP_ARGS(pth, policy, param_ex)
 );
 
 DEFINE_EVENT(cobalt_posix_schedparam, cobalt_pthread_getschedparam,
 	TP_PROTO(unsigned long pth, int policy,
-		 const struct sched_param_ex *param_ex),
+		 const struct sched_param_ex64 *param_ex),
 	TP_ARGS(pth, policy, param_ex)
 );
 
@@ -501,7 +501,7 @@ TRACE_EVENT(cobalt_sched_get_config,
 
 DEFINE_EVENT(cobalt_posix_scheduler, cobalt_sched_setscheduler,
 	TP_PROTO(pid_t pid, int policy,
-		 const struct sched_param_ex *param_ex),
+		 const struct sched_param_ex64 *param_ex),
 	TP_ARGS(pid, policy, param_ex)
 );
 

-- 
2.39.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 02/12] y2038: cobalt: Introduce sched_config64 and use it internally
  2023-07-05  6:38 [PATCH 00/12] y2038: Add time64_t support to scheduler and thread APIs Florian Bezdeka
  2023-07-05  6:38 ` [PATCH 01/12] y2038: cobalt: Introduce sched_param_ex64 and use it internally Florian Bezdeka
@ 2023-07-05  6:38 ` Florian Bezdeka
  2023-07-05  6:38 ` [PATCH 03/12] y2038: cobalt/posix/{sched,thread}: Add time64_t based syscalls Florian Bezdeka
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 28+ messages in thread
From: Florian Bezdeka @ 2023-07-05  6:38 UTC (permalink / raw)
  To: jan.kiszka, xenomai; +Cc: Florian Bezdeka

Introducing a new type sched_config64. All members are (always) based
on time64_t. All internal APIs have been migrated. Existing compat
and native system call entry points do the necessary translation.

This is a preparation step for introducing time64_t based cobalt sched
cobalt services.

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 kernel/cobalt/posix/clock.h     |  27 ++-----
 kernel/cobalt/posix/sched.c     | 172 ++++++++++++++++++++++++++++++----------
 kernel/cobalt/posix/sched.h     |  30 ++++++-
 kernel/cobalt/posix/syscall32.c |  12 +--
 4 files changed, 171 insertions(+), 70 deletions(-)

diff --git a/kernel/cobalt/posix/clock.h b/kernel/cobalt/posix/clock.h
index b0fc84396..294b1bf02 100644
--- a/kernel/cobalt/posix/clock.h
+++ b/kernel/cobalt/posix/clock.h
@@ -34,11 +34,6 @@ static inline void ns2ts(struct timespec64 *ts, xnticks_t nsecs)
 	ts->tv_sec = xnclock_divrem_billion(nsecs, &ts->tv_nsec);
 }
 
-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 void ns2kts(struct __kernel_timespec *kts, xnticks_t ticks)
 {
 	unsigned long nsecs;
@@ -74,16 +69,6 @@ static inline xnticks_t kts2ns(const struct __kernel_timespec *ts)
 	return nsecs;
 }
 
-static inline xnticks_t u_ts2ns(const struct __user_old_timespec *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 tv2ns(const struct __kernel_old_timeval *tv)
 {
 	xnticks_t nsecs = tv->tv_usec * 1000;
@@ -137,34 +122,34 @@ int __cobalt_clock_nanosleep(clockid_t clock_id, int flags,
 			     struct timespec64 *rmt);
 
 COBALT_SYSCALL_DECL(clock_getres,
-		    (clockid_t clock_id, struct __kernel_old_timespec __user *u_ts));
+		    (clockid_t clock_id, struct __user_old_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(clock_getres64,
 		    (clockid_t clock_id, struct __kernel_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(clock_gettime,
-		    (clockid_t clock_id, struct __kernel_old_timespec __user *u_ts));
+		    (clockid_t clock_id, struct __user_old_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(clock_gettime64,
 		    (clockid_t clock_id, struct __kernel_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(clock_settime,
-		    (clockid_t clock_id, const struct __kernel_old_timespec __user *u_ts));
+		    (clockid_t clock_id, const struct __user_old_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(clock_settime64,
 		    (clockid_t clock_id,
 			 const struct __kernel_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(clock_adjtime,
-		    (clockid_t clock_id, struct old_timex32 __user *u_tx));
+		    (clockid_t clock_id, struct __user_old_timex __user *u_tx));
 
 COBALT_SYSCALL_DECL(clock_adjtime64,
 		    (clockid_t clock_id, struct __kernel_timex __user *u_tx));
 
 COBALT_SYSCALL_DECL(clock_nanosleep,
 		    (clockid_t clock_id, int flags,
-		     const struct __kernel_old_timespec __user *u_rqt,
-		     struct __kernel_old_timespec __user *u_rmt));
+		     const struct __user_old_timespec __user *u_rqt,
+		     struct __user_old_timespec __user *u_rmt));
 
 COBALT_SYSCALL_DECL(clock_nanosleep64,
 		    (clockid_t clock_id, int flags,
diff --git a/kernel/cobalt/posix/sched.c b/kernel/cobalt/posix/sched.c
index 1c3a7de61..5163863c2 100644
--- a/kernel/cobalt/posix/sched.c
+++ b/kernel/cobalt/posix/sched.c
@@ -229,13 +229,13 @@ COBALT_SYSCALL(sched_yield, primary, (void))
 
 #ifdef CONFIG_XENO_OPT_SCHED_TP
 
-static inline
-int set_tp_config(int cpu, union sched_config *config, size_t len)
+static inline int set_tp_config(int cpu, union sched_config64 *config,
+				size_t len)
 {
 	xnticks_t offset, duration, next_offset;
 	struct xnsched_tp_schedule *gps, *ogps;
 	struct xnsched_tp_window *w;
-	struct sched_tp_window *p;
+	struct sched_tp_window64 *p;
 	struct xnsched *sched;
 	spl_t s;
 	int n;
@@ -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 = u_ts2ns(&p->offset);
+		offset = kts2ns(&p->offset);
 		if (offset != next_offset)
 			goto cleanup_and_fail;
 
-		duration = u_ts2ns(&p->duration);
+		duration = kts2ns(&p->duration);
 		if (duration <= 0)
 			goto cleanup_and_fail;
 
@@ -318,18 +318,15 @@ cleanup_and_fail:
 
 static inline
 ssize_t get_tp_config(int cpu, void __user *u_config, size_t len,
-		      union sched_config *(*fetch_config)
-		      (int policy, const void __user *u_config,
-		       size_t *len),
 		      ssize_t (*put_config)(int policy, void __user *u_config,
 					    size_t u_len,
-					    const union sched_config *config,
+					    const union sched_config64 *config,
 					    size_t len))
 {
 	struct xnsched_tp_window *pw, *w;
 	struct xnsched_tp_schedule *gps;
-	struct sched_tp_window *pp, *p;
-	union sched_config *config;
+	struct sched_tp_window64 *pp, *p;
+	union sched_config64 *config;
 	struct xnsched *sched;
 	ssize_t ret, elen;
 	spl_t s;
@@ -346,9 +343,9 @@ ssize_t get_tp_config(int cpu, void __user *u_config, size_t len,
 
 	xnlock_put_irqrestore(&nklock, s);
 
-	elen = sched_tp_confsz(gps->pwin_nr);
+	elen = sched_tp_confsz64(gps->pwin_nr);
 	config = xnmalloc(elen);
-	if (config == NULL) {
+	if (!config) {
 		ret = -ENOMEM;
 		goto out;
 	}
@@ -357,11 +354,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++) {
-		u_ns2ts(&p->offset, w->w_offset);
-		u_ns2ts(&pp->duration, w->w_offset - pw->w_offset);
+		ns2kts(&p->offset, w->w_offset);
+		ns2kts(&pp->duration, w->w_offset - pw->w_offset);
 		p->ptid = w->w_part;
 	}
-	u_ns2ts(&pp->duration, gps->tf_duration - pw->w_offset);
+	ns2kts(&pp->duration, gps->tf_duration - pw->w_offset);
 	ret = put_config(SCHED_TP, u_config, len, config, elen);
 	xnfree(config);
 out:
@@ -380,12 +377,9 @@ set_tp_config(int cpu, union sched_config *config, size_t len)
 
 static inline ssize_t
 get_tp_config(int cpu, union sched_config __user *u_config, size_t len,
-	      union sched_config *(*fetch_config)
-	      (int policy, const void __user *u_config,
-	       size_t *len),
 	      ssize_t (*put_config)(int policy, void __user *u_config,
 				    size_t u_len,
-				    const union sched_config *config,
+				    const union sched_config64 *config,
 				    size_t len))
 {
 	return -EINVAL;
@@ -396,7 +390,7 @@ get_tp_config(int cpu, union sched_config __user *u_config, size_t len,
 #ifdef CONFIG_XENO_OPT_SCHED_QUOTA
 
 static inline
-int set_quota_config(int cpu, union sched_config *config, size_t len)
+int set_quota_config(int cpu, union sched_config64 *config, size_t len)
 {
 	struct __sched_config_quota *p = &config->quota;
 	struct __sched_quota_info *iq = &p->info;
@@ -484,17 +478,17 @@ bad_tgid:
 
 static inline
 ssize_t get_quota_config(int cpu, void __user *u_config, size_t len,
-			 union sched_config *(*fetch_config)
+			 union sched_config64 *(*fetch_config)
 			 (int policy, const void __user *u_config,
 			  size_t *len),
 			 ssize_t (*put_config)(int policy, void __user *u_config,
 					       size_t u_len,
-					       const union sched_config *config,
+					       const union sched_config64 *config,
 					       size_t len))
 {
 	struct cobalt_sched_group *group;
 	struct xnsched_quota_group *tg;
-	union sched_config *config;
+	union sched_config64 *config;
 	struct xnsched *sched;
 	ssize_t ret;
 	spl_t s;
@@ -533,7 +527,7 @@ bad_tgid:
 #else /* !CONFIG_XENO_OPT_SCHED_QUOTA */
 
 static inline
-int set_quota_config(int cpu, union sched_config *config, size_t len)
+int set_quota_config(int cpu, union sched_config64 *config, size_t len)
 {
 	return -EINVAL;
 }
@@ -541,7 +535,7 @@ int set_quota_config(int cpu, union sched_config *config, size_t len)
 static inline
 ssize_t get_quota_config(int cpu, void __user *u_config,
 			 size_t len,
-			 union sched_config *(*fetch_config)
+			 union sched_config64 *(*fetch_config)
 			 (int policy, const void __user *u_config,
 			  size_t *len),
 			 ssize_t (*put_config)(int policy, void __user *u_config,
@@ -554,10 +548,76 @@ ssize_t get_quota_config(int cpu, void __user *u_config,
 
 #endif /* !CONFIG_XENO_OPT_SCHED_QUOTA */
 
-static union sched_config *
+static union sched_config64 *
 sched_fetch_config(int policy, const void __user *u_config, size_t *len)
 {
-	union sched_config *buf;
+	union sched_config64 *buf;
+	union sched_config *sbuf;
+	int ret;
+	int n;
+
+	if (u_config == NULL)
+		return ERR_PTR(-EFAULT);
+
+	if (policy == SCHED_QUOTA && *len < sizeof(buf->quota))
+		return ERR_PTR(-EINVAL);
+
+	sbuf = xnmalloc(*len);
+	if (!sbuf)
+		return ERR_PTR(-ENOMEM);
+
+	ret = cobalt_copy_from_user(sbuf, u_config, *len);
+	if (ret) {
+		buf = ERR_PTR(ret);
+		goto out;
+	}
+
+	switch (policy) {
+	case SCHED_TP:
+		*len = sched_tp_confsz64(sbuf->tp.nr_windows);
+		break;
+	case SCHED_QUOTA:
+		break;
+	default:
+		buf = ERR_PTR(-EINVAL);
+		goto out;
+	}
+
+	buf = xnmalloc(*len);
+	if (buf == NULL) {
+		buf = ERR_PTR(-ENOMEM);
+		goto out;
+	}
+
+	if (policy == SCHED_QUOTA) {
+		memcpy(&buf->quota, &sbuf->quota, sizeof(sbuf->quota));
+		goto out;
+	}
+
+	buf->tp.op = sbuf->tp.op;
+	buf->tp.nr_windows = sbuf->tp.nr_windows;
+	for (n = 0, ret = 0; n < buf->tp.nr_windows; n++) {
+		buf->tp.windows[n].ptid = sbuf->tp.windows[n].ptid;
+		buf->tp.windows[n].offset.tv_sec =
+			sbuf->tp.windows[n].offset.tv_sec;
+		buf->tp.windows[n].offset.tv_nsec =
+			sbuf->tp.windows[n].offset.tv_nsec;
+		buf->tp.windows[n].duration.tv_sec =
+			sbuf->tp.windows[n].duration.tv_sec;
+		buf->tp.windows[n].duration.tv_nsec =
+			sbuf->tp.windows[n].duration.tv_nsec;
+	}
+
+out:
+	xnfree(sbuf);
+
+	return buf;
+}
+
+static union sched_config64 *
+sched_fetch_config64(int policy, const void __user *u_config, size_t *len)
+{
+	union sched_config64 *buf;
 	int ret;
 
 	if (u_config == NULL)
@@ -579,7 +639,7 @@ sched_fetch_config(int policy, const void __user *u_config, size_t *len)
 	return buf;
 }
 
-static int sched_ack_config(int policy, const union sched_config *config,
+static int sched_ack_config(int policy, const union sched_config64 *config,
 			    void __user *u_config)
 {
 	union sched_config __user *u_p = u_config;
@@ -587,16 +647,18 @@ static int sched_ack_config(int policy, const union sched_config *config,
 	if (policy != SCHED_QUOTA)
 		return 0;
 
+	/* SCHED_QUOTA does not need special time64_t handling */
 	return u_p == NULL ? -EFAULT :
 		cobalt_copy_to_user(&u_p->quota.info, &config->quota.info,
 				       sizeof(u_p->quota.info));
 }
 
-static ssize_t sched_put_config(int policy,
-				void __user *u_config, size_t u_len,
-				const union sched_config *config, size_t len)
+static ssize_t sched_put_config(int policy, void __user *u_config, size_t u_len,
+				const union sched_config64 *config, size_t len)
 {
 	union sched_config *u_p = u_config;
+	struct __kernel_old_timespec ts;
+	int ret, n;
 
 	if (u_config == NULL)
 		return -EFAULT;
@@ -609,20 +671,51 @@ static ssize_t sched_put_config(int policy,
 			sizeof(u_p->quota.info);
 	}
 
-	return cobalt_copy_to_user(u_config, config, len) ?: len;
+	if (u_len < sched_tp_confsz(config->tp.nr_windows))
+		return -ENOSPC;
+
+	__xn_put_user(config->tp.op, &u_p->tp.op);
+	__xn_put_user(config->tp.nr_windows, &u_p->tp.nr_windows);
+
+	for (n = 0, ret = 0; n < config->tp.nr_windows; n++) {
+		ret |= __xn_put_user(config->tp.windows[n].ptid,
+				     &u_p->tp.windows[n].ptid);
+
+		/* Write offset */
+		ts.tv_sec = config->tp.windows[n].offset.tv_sec;
+		ts.tv_nsec = config->tp.windows[n].offset.tv_nsec;
+		ret |= __xn_put_user(ts.tv_sec,
+				     &u_p->tp.windows[n].offset.tv_sec);
+		ret |= __xn_put_user(ts.tv_nsec,
+				     &u_p->tp.windows[n].offset.tv_nsec);
+		if (ret)
+			break;
+
+		/* Write duration */
+		ts.tv_sec = config->tp.windows[n].duration.tv_sec;
+		ts.tv_nsec = config->tp.windows[n].duration.tv_nsec;
+		ret |= __xn_put_user(ts.tv_sec,
+				     &u_p->tp.windows[n].duration.tv_sec);
+		ret |= __xn_put_user(ts.tv_nsec,
+				     &u_p->tp.windows[n].duration.tv_nsec);
+		if (ret)
+			break;
+	}
+
+	return ret ?: u_len;
 }
 
 int __cobalt_sched_setconfig_np(int cpu, int policy,
 				void __user *u_config,
 				size_t len,
-				union sched_config *(*fetch_config)
+				union sched_config64 *(*fetch_config)
 				(int policy, const void __user *u_config,
 				 size_t *len),
 				int (*ack_config)(int policy,
-						  const union sched_config *config,
+						  const union sched_config64 *config,
 						  void __user *u_config))
 {
-	union sched_config *buf;
+	union sched_config64 *buf;
 	int ret;
 
 	trace_cobalt_sched_setconfig(cpu, policy, len);
@@ -668,21 +761,20 @@ COBALT_SYSCALL(sched_setconfig_np, conforming,
 ssize_t __cobalt_sched_getconfig_np(int cpu, int policy,
 				    void __user *u_config,
 				    size_t len,
-				    union sched_config *(*fetch_config)
+				    union sched_config64 *(*fetch_config)
 				    (int policy, const void __user *u_config,
 				     size_t *len),
 				    ssize_t (*put_config)(int policy,
 							  void __user *u_config,
 							  size_t u_len,
-							  const union sched_config *config,
+							  const union sched_config64 *config,
 							  size_t len))
 {
 	ssize_t ret;
 
 	switch (policy)	{
 	case SCHED_TP:
-		ret = get_tp_config(cpu, u_config, len,
-				    fetch_config, put_config);
+		ret = get_tp_config(cpu, u_config, len, put_config);
 		break;
 	case SCHED_QUOTA:
 		ret = get_quota_config(cpu, u_config, len,
diff --git a/kernel/cobalt/posix/sched.h b/kernel/cobalt/posix/sched.h
index e8b9f9113..a226c39d3 100644
--- a/kernel/cobalt/posix/sched.h
+++ b/kernel/cobalt/posix/sched.h
@@ -34,28 +34,50 @@ struct cobalt_sched_group {
 	struct list_head next;
 };
 
+struct sched_tp_window64 {
+	struct __kernel_timespec offset;
+	struct __kernel_timespec duration;
+	int ptid;
+	int: 32;
+};
+
+struct __sched_config_tp64 {
+	int op;
+	int nr_windows;
+	struct sched_tp_window64 windows[0];
+};
+
+union sched_config64 {
+	struct __sched_config_tp64 tp;
+	struct __sched_config_quota quota;
+};
+
+#define sched_tp_confsz64(nr_win)             \
+	(sizeof(struct __sched_config_tp64) + \
+	 (nr_win) * sizeof(struct sched_tp_window64))
+
 int __cobalt_sched_weightprio(int policy,
 			      const struct sched_param_ex64 *param_ex);
 
 int __cobalt_sched_setconfig_np(int cpu, int policy,
 				void __user *u_config,
 				size_t len,
-				union sched_config *(*fetch_config)
+				union sched_config64 *(*fetch_config)
 				(int policy, const void __user *u_config,
 				 size_t *len),
 				int (*ack_config)(int policy,
-						  const union sched_config *config,
+						  const union sched_config64 *config,
 						  void __user *u_config));
 
 ssize_t __cobalt_sched_getconfig_np(int cpu, int policy,
 				    void __user *u_config,
 				    size_t len,
-				    union sched_config *(*fetch_config)
+				    union sched_config64 *(*fetch_config)
 				    (int policy, const void __user *u_config,
 				     size_t *len),
 				    ssize_t (*put_config)(int policy,
 							  void __user *u_config, size_t u_len,
-							  const union sched_config *config,
+							  const union sched_config64 *config,
 							  size_t len));
 int cobalt_sched_setscheduler_ex(pid_t pid,
 				 int policy,
diff --git a/kernel/cobalt/posix/syscall32.c b/kernel/cobalt/posix/syscall32.c
index 9b09d734d..6914173c0 100644
--- a/kernel/cobalt/posix/syscall32.c
+++ b/kernel/cobalt/posix/syscall32.c
@@ -353,11 +353,11 @@ COBALT_SYSCALL32emu(sched_weightprio, current,
 	return __cobalt_sched_weightprio(policy, &param_ex);
 }
 
-static union sched_config *
+static union sched_config64 *
 sys32_fetch_config(int policy, const void __user *u_config, size_t *len)
 {
 	union compat_sched_config *cbuf;
-	union sched_config *buf;
+	union sched_config64 *buf;
 	int ret, n;
 
 	if (u_config == NULL)
@@ -378,7 +378,7 @@ sys32_fetch_config(int policy, const void __user *u_config, size_t *len)
 
 	switch (policy) {
 	case SCHED_TP:
-		*len = sched_tp_confsz(cbuf->tp.nr_windows);
+		*len = sched_tp_confsz64(cbuf->tp.nr_windows);
 		break;
 	case SCHED_QUOTA:
 		break;
@@ -412,7 +412,7 @@ out:
 	return buf;
 }
 
-static int sys32_ack_config(int policy, const union sched_config *config,
+static int sys32_ack_config(int policy, const union sched_config64 *config,
 			    void __user *u_config)
 {
 	union compat_sched_config __user *u_p = u_config;
@@ -420,6 +420,7 @@ static int sys32_ack_config(int policy, const union sched_config *config,
 	if (policy != SCHED_QUOTA)
 		return 0;
 
+	/* SCHED_QUOTA does not need special time64_t handling */
 	return u_config == NULL ? -EFAULT :
 		cobalt_copy_to_user(&u_p->quota.info, &config->quota.info,
 				       sizeof(u_p->quota.info));
@@ -427,7 +428,7 @@ static int sys32_ack_config(int policy, const union sched_config *config,
 
 static ssize_t sys32_put_config(int policy,
 				void __user *u_config, size_t u_len,
-				const union sched_config *config, size_t len)
+				const union sched_config64 *config, size_t len)
 {
 	union compat_sched_config __user *u_p = u_config;
 	int n, ret;
@@ -435,6 +436,7 @@ static ssize_t sys32_put_config(int policy,
 	if (u_config == NULL)
 		return -EFAULT;
 
+	/* SCHED_QUOTA does not need special time64_t handling */
 	if (policy == SCHED_QUOTA) {
 		if (u_len < sizeof(u_p->quota))
 			return -EINVAL;

-- 
2.39.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 03/12] y2038: cobalt/posix/{sched,thread}: Add time64_t based syscalls
  2023-07-05  6:38 [PATCH 00/12] y2038: Add time64_t support to scheduler and thread APIs Florian Bezdeka
  2023-07-05  6:38 ` [PATCH 01/12] y2038: cobalt: Introduce sched_param_ex64 and use it internally Florian Bezdeka
  2023-07-05  6:38 ` [PATCH 02/12] y2038: cobalt: Introduce sched_config64 " Florian Bezdeka
@ 2023-07-05  6:38 ` Florian Bezdeka
  2023-07-05  6:38 ` [PATCH 04/12] y2038: lib/cobalt/{sched,thread}: Dispatch time64_t related services Florian Bezdeka
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 28+ messages in thread
From: Florian Bezdeka @ 2023-07-05  6:38 UTC (permalink / raw)
  To: jan.kiszka, xenomai; +Cc: Florian Bezdeka

The following syscalls have been added, they are all necessary to make
the cobalt thread and sched implementation y2038 safe:
  - thread_create64
  - thread_setschedparam_ex64
  - thread_getschedparam_ex64
  - sched_setconfig_np64
  - sched_getconfig_np64
  - sched_setscheduler_ex64
  - sched_getscheduler_ex64

All services are dealing with the struct sched_param(64) data structure
which is affected due to nested struct timespecs.

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 include/cobalt/uapi/syscall.h      |  7 ++++
 kernel/cobalt/posix/sched.c        | 82 ++++++++++++++++++++++++++++++++++++++
 kernel/cobalt/posix/sched.h        | 17 ++++++++
 kernel/cobalt/posix/thread.c       | 50 +++++++++++++++++++++++
 kernel/cobalt/posix/thread.h       | 13 ++++++
 kernel/cobalt/trace/cobalt-posix.h |  9 ++++-
 6 files changed, 177 insertions(+), 1 deletion(-)

diff --git a/include/cobalt/uapi/syscall.h b/include/cobalt/uapi/syscall.h
index 3e65efaab..15ad88fa7 100644
--- a/include/cobalt/uapi/syscall.h
+++ b/include/cobalt/uapi/syscall.h
@@ -141,6 +141,13 @@
 #define sc_cobalt_timerfd_settime64		118
 #define sc_cobalt_timerfd_gettime64		119
 #define sc_cobalt_pselect64			120
+#define sc_cobalt_thread_create64		121
+#define sc_cobalt_thread_setschedparam_ex64	122
+#define sc_cobalt_thread_getschedparam_ex64	123
+#define sc_cobalt_sched_setconfig_np64		124
+#define sc_cobalt_sched_getconfig_np64		125
+#define sc_cobalt_sched_setscheduler_ex64	126
+#define sc_cobalt_sched_getscheduler_ex64	127
 
 #define __NR_COBALT_SYSCALLS			128 /* Power of 2 */
 
diff --git a/kernel/cobalt/posix/sched.c b/kernel/cobalt/posix/sched.c
index 5163863c2..11920faff 100644
--- a/kernel/cobalt/posix/sched.c
+++ b/kernel/cobalt/posix/sched.c
@@ -705,6 +705,32 @@ static ssize_t sched_put_config(int policy, void __user *u_config, size_t u_len,
 	return ret ?: u_len;
 }
 
+static ssize_t sched_put_config64(int policy, void __user *u_config,
+				  size_t u_len, const union sched_config64 *cfg,
+				  size_t len)
+{
+	union sched_config64 *u_cfg = u_config;
+	int ret;
+
+	if (u_cfg == NULL)
+		return -EFAULT;
+
+	if (policy == SCHED_QUOTA) {
+		if (u_len < sizeof(cfg->quota))
+			return -EINVAL;
+		return cobalt_copy_to_user(&u_cfg->quota.info, &cfg->quota.info,
+					   sizeof(u_cfg->quota.info)) ?:
+			       sizeof(u_cfg->quota.info);
+	}
+
+	if (u_len < len)
+		return -ENOSPC;
+
+	ret = cobalt_copy_to_user(u_cfg, cfg, len);
+
+	return ret ?: u_len;
+}
+
 int __cobalt_sched_setconfig_np(int cpu, int policy,
 				void __user *u_config,
 				size_t len,
@@ -758,6 +784,15 @@ COBALT_SYSCALL(sched_setconfig_np, conforming,
 					   sched_fetch_config, sched_ack_config);
 }
 
+COBALT_SYSCALL(sched_setconfig_np64, conforming,
+	       (int cpu, int policy, union sched_config64 __user *u_config,
+		size_t len))
+{
+	return __cobalt_sched_setconfig_np(cpu, policy, u_config, len,
+					   sched_fetch_config64,
+					   sched_ack_config);
+}
+
 ssize_t __cobalt_sched_getconfig_np(int cpu, int policy,
 				    void __user *u_config,
 				    size_t len,
@@ -798,6 +833,16 @@ COBALT_SYSCALL(sched_getconfig_np, conforming,
 					   sched_fetch_config, sched_put_config);
 }
 
+COBALT_SYSCALL(sched_getconfig_np64, conforming,
+	       (int cpu, int policy,
+		union sched_config64 __user *u_config,
+		size_t len))
+{
+	return __cobalt_sched_getconfig_np(cpu, policy, u_config, len,
+					   sched_fetch_config64,
+					   sched_put_config64);
+}
+
 int __cobalt_sched_weightprio(int policy,
 			      const struct sched_param_ex64 *param_ex)
 {
@@ -886,6 +931,22 @@ COBALT_SYSCALL(sched_setscheduler_ex, conforming,
 					    u_winoff, u_promoted);
 }
 
+COBALT_SYSCALL(sched_setscheduler_ex64, conforming,
+	       (pid_t pid, int policy,
+		const struct sched_param_ex64 __user *u_param,
+		__u32 __user *u_winoff, int __user *u_promoted))
+{
+	struct sched_param_ex64 param_ex;
+	int ret;
+
+	ret = cobalt_copy_from_user(&param_ex, u_param, sizeof(param_ex));
+	if (ret)
+		return ret;
+
+	return cobalt_sched_setscheduler_ex(pid, policy, &param_ex, u_winoff,
+					    u_promoted);
+}
+
 int cobalt_sched_getscheduler_ex(pid_t pid,
 				 int *policy_r,
 				 struct sched_param_ex64 *param_ex)
@@ -930,6 +991,27 @@ COBALT_SYSCALL(sched_getscheduler_ex, current,
 	return 0;
 }
 
+COBALT_SYSCALL(sched_getscheduler_ex64, current,
+	       (pid_t pid, int __user *u_policy,
+		struct sched_param_ex64 __user *u_param))
+{
+	struct sched_param_ex64 param_ex;
+	int ret, policy;
+
+	ret = cobalt_sched_getscheduler_ex(pid, &policy, &param_ex);
+	if (ret)
+		return ret;
+
+	ret = cobalt_copy_to_user(u_param, &param_ex, sizeof(*u_param));
+	if (ret)
+		return ret;
+
+	if (cobalt_copy_to_user(u_policy, &policy, sizeof(policy)))
+		return -EFAULT;
+
+	return 0;
+}
+
 void cobalt_sched_reclaim(struct cobalt_process *process)
 {
 	struct cobalt_resources *p = &process->resources;
diff --git a/kernel/cobalt/posix/sched.h b/kernel/cobalt/posix/sched.h
index a226c39d3..34c14bd91 100644
--- a/kernel/cobalt/posix/sched.h
+++ b/kernel/cobalt/posix/sched.h
@@ -109,11 +109,19 @@ COBALT_SYSCALL_DECL(sched_setconfig_np,
 		     union sched_config __user *u_config,
 		     size_t len));
 
+COBALT_SYSCALL_DECL(sched_setconfig_np64,
+		    (int cpu, int policy, union sched_config64 __user *u_config,
+		     size_t len));
+
 COBALT_SYSCALL_DECL(sched_getconfig_np,
 		    (int cpu, int policy,
 		     union sched_config __user *u_config,
 		     size_t len));
 
+COBALT_SYSCALL_DECL(sched_getconfig_np64,
+		    (int cpu, int policy, union sched_config64 __user *u_config,
+		     size_t len));
+
 COBALT_SYSCALL_DECL(sched_setscheduler_ex,
 		    (pid_t pid,
 		     int policy,
@@ -121,11 +129,20 @@ COBALT_SYSCALL_DECL(sched_setscheduler_ex,
 		     __u32 __user *u_winoff,
 		     int __user *u_promoted));
 
+COBALT_SYSCALL_DECL(sched_setscheduler_ex64,
+		    (pid_t pid, int policy,
+		     const struct sched_param_ex64 __user *u_param,
+		     __u32 __user *u_winoff, int __user *u_promoted));
+
 COBALT_SYSCALL_DECL(sched_getscheduler_ex,
 		    (pid_t pid,
 		     int __user *u_policy,
 		     struct sched_param_ex __user *u_param));
 
+COBALT_SYSCALL_DECL(sched_getscheduler_ex64,
+		    (pid_t pid, int __user *u_policy,
+		     struct sched_param_ex64 __user *u_param));
+
 void cobalt_sched_reclaim(struct cobalt_process *process);
 
 #endif /* !_COBALT_POSIX_SCHED_H */
diff --git a/kernel/cobalt/posix/thread.c b/kernel/cobalt/posix/thread.c
index 2fa8a9e6a..9853e6924 100644
--- a/kernel/cobalt/posix/thread.c
+++ b/kernel/cobalt/posix/thread.c
@@ -16,6 +16,7 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
+#include <linux/compat.h>
 #include <linux/types.h>
 #include <linux/cred.h>
 #include <linux/jhash.h>
@@ -599,6 +600,22 @@ COBALT_SYSCALL(thread_setschedparam_ex, conforming,
 	return ret;
 }
 
+COBALT_SYSCALL(thread_setschedparam_ex64, conforming,
+	       (unsigned long pth, int policy,
+		const struct sched_param_ex64 __user *u_param,
+		__u32 __user *u_winoff, int __user *u_promoted))
+{
+	struct sched_param_ex64 param_ex;
+	int ret;
+
+	ret = cobalt_copy_from_user(&param_ex, u_param, sizeof(param_ex));
+	if (ret)
+		return ret;
+
+	return cobalt_thread_setschedparam_ex(pth, policy, &param_ex, u_winoff,
+					      u_promoted);
+}
+
 int cobalt_thread_getschedparam_ex(unsigned long pth,
 				   int *policy_r,
 				   struct sched_param_ex64 *param_ex)
@@ -641,6 +658,24 @@ COBALT_SYSCALL(thread_getschedparam_ex, current,
 	return cobalt_thread_put_schedparam_ex(u_param, &param_ex, policy);
 }
 
+COBALT_SYSCALL(thread_getschedparam_ex64, current,
+	       (unsigned long pth, int __user *u_policy,
+		struct sched_param_ex64 __user *u_param))
+{
+	struct sched_param_ex64 param_ex;
+	int ret, policy;
+
+	ret = cobalt_thread_getschedparam_ex(pth, &policy, &param_ex);
+	if (ret)
+		return ret;
+
+	ret = cobalt_copy_to_user(u_policy, &policy, sizeof(policy));
+	if (ret)
+		return ret;
+
+	return cobalt_copy_to_user(u_param, &param_ex, sizeof(param_ex));
+}
+
 int cobalt_thread_setschedprio(unsigned long pth,
 			       int prio,
 			       __u32 __user *u_winoff,
@@ -742,6 +777,21 @@ COBALT_SYSCALL(thread_create, init,
 	return __cobalt_thread_create(pth, policy, &param_ex, xid, u_winoff);
 }
 
+COBALT_SYSCALL(thread_create64, init,
+	       (unsigned long pth, int policy,
+		struct sched_param_ex64 __user *u_param, int xid,
+		__u32 __user *u_winoff))
+{
+	struct sched_param_ex64 param_ex;
+	int ret;
+
+	ret = cobalt_copy_from_user(&param_ex, u_param, sizeof(param_ex));
+	if (ret)
+		return ret;
+
+	return __cobalt_thread_create(pth, policy, &param_ex, xid, u_winoff);
+}
+
 struct cobalt_thread *
 cobalt_thread_shadow(struct cobalt_local_hkey *hkey,
 		     __u32 __user *u_winoff)
diff --git a/kernel/cobalt/posix/thread.h b/kernel/cobalt/posix/thread.h
index 8916d05b9..fb4306351 100644
--- a/kernel/cobalt/posix/thread.h
+++ b/kernel/cobalt/posix/thread.h
@@ -184,6 +184,10 @@ COBALT_SYSCALL_DECL(thread_create,
 		     struct sched_param_ex __user *u_param,
 		     int xid, __u32 __user *u_winoff));
 
+COBALT_SYSCALL_DECL(thread_create64, (unsigned long pth, int policy,
+				      struct sched_param_ex64 __user *u_param,
+				      int xid, __u32 __user *u_winoff));
+
 struct cobalt_thread *
 cobalt_thread_shadow(struct cobalt_local_hkey *lhkey,
 		     __u32 __user *u_winoff);
@@ -210,11 +214,20 @@ COBALT_SYSCALL_DECL(thread_setschedparam_ex,
 		     __u32 __user *u_winoff,
 		     int __user *u_promoted));
 
+COBALT_SYSCALL_DECL(thread_setschedparam_ex64,
+		    (unsigned long pth, int policy,
+		     const struct sched_param_ex64 __user *u_param,
+		     __u32 __user *u_winoff, int __user *u_promoted));
+
 COBALT_SYSCALL_DECL(thread_getschedparam_ex,
 		    (unsigned long pth,
 		     int __user *u_policy,
 		     struct sched_param_ex __user *u_param));
 
+COBALT_SYSCALL_DECL(thread_getschedparam_ex64,
+		    (unsigned long pth, int __user *u_policy,
+		     struct sched_param_ex64 __user *u_param));
+
 COBALT_SYSCALL_DECL(thread_setschedprio,
 		    (unsigned long pth,
 		     int prio,
diff --git a/kernel/cobalt/trace/cobalt-posix.h b/kernel/cobalt/trace/cobalt-posix.h
index c6c430cff..449bd1818 100644
--- a/kernel/cobalt/trace/cobalt-posix.h
+++ b/kernel/cobalt/trace/cobalt-posix.h
@@ -173,7 +173,14 @@
 		__cobalt_symbolic_syscall(timer_gettime64),		\
 		__cobalt_symbolic_syscall(timerfd_settime64),		\
 		__cobalt_symbolic_syscall(timerfd_gettime64),		\
-		__cobalt_symbolic_syscall(pselect64))
+		__cobalt_symbolic_syscall(pselect64),			\
+		__cobalt_symbolic_syscall(thread_create64),		\
+		__cobalt_symbolic_syscall(thread_setschedparam_ex64),	\
+		__cobalt_symbolic_syscall(thread_getschedparam_ex64),	\
+		__cobalt_symbolic_syscall(sched_setconfig_np64),	\
+		__cobalt_symbolic_syscall(sched_getconfig_np64),	\
+		__cobalt_symbolic_syscall(sched_setscheduler_ex64),	\
+		__cobalt_symbolic_syscall(sched_getscheduler_ex64))
 
 DECLARE_EVENT_CLASS(cobalt_syscall_entry,
 	TP_PROTO(unsigned int nr),

-- 
2.39.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 04/12] y2038: lib/cobalt/{sched,thread}: Dispatch time64_t related services
  2023-07-05  6:38 [PATCH 00/12] y2038: Add time64_t support to scheduler and thread APIs Florian Bezdeka
                   ` (2 preceding siblings ...)
  2023-07-05  6:38 ` [PATCH 03/12] y2038: cobalt/posix/{sched,thread}: Add time64_t based syscalls Florian Bezdeka
@ 2023-07-05  6:38 ` Florian Bezdeka
  2023-07-05  6:38 ` [PATCH 05/12] y2038: cobalt/uapi: Introduce xntimespec for struct sched_param_ex API Florian Bezdeka
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 28+ messages in thread
From: Florian Bezdeka @ 2023-07-05  6:38 UTC (permalink / raw)
  To: jan.kiszka, xenomai; +Cc: Florian Bezdeka

If libc reports time64_t support all y2038 related services are now
dispatched to the time64_t based syscall.

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 lib/cobalt/sched.c  | 38 +++++++++++++++++++++++++++++---------
 lib/cobalt/thread.c | 29 +++++++++++++++++++++--------
 2 files changed, 50 insertions(+), 17 deletions(-)

diff --git a/lib/cobalt/sched.c b/lib/cobalt/sched.c
index bdb8603da..d44cab70a 100644
--- a/lib/cobalt/sched.c
+++ b/lib/cobalt/sched.c
@@ -304,9 +304,13 @@ int sched_setscheduler_ex(pid_t pid,
 			return errno;
 	}
 
-	ret = -XENOMAI_SYSCALL5(sc_cobalt_sched_setscheduler_ex,
-				pid, policy, param_ex,
-				&u_winoff, &promoted);
+#if __USE_TIME_BITS64
+	ret = -XENOMAI_SYSCALL5(sc_cobalt_sched_setscheduler_ex64, pid, policy,
+				param_ex, &u_winoff, &promoted);
+#else
+	ret = -XENOMAI_SYSCALL5(sc_cobalt_sched_setscheduler_ex, pid, policy,
+				param_ex, &u_winoff, &promoted);
+#endif
 
 	/*
 	 * If the kernel has no reference to the target thread, let glibc
@@ -360,8 +364,14 @@ COBALT_IMPL(int, sched_getscheduler, (pid_t pid))
 		return -1;
 	}
 
-	ret = XENOMAI_SYSCALL3(sc_cobalt_sched_getscheduler_ex,
-			       pid, &policy, &param_ex);
+#if __USE_TIME_BITS64
+	ret = XENOMAI_SYSCALL3(sc_cobalt_sched_getscheduler_ex64, pid, &policy,
+			       &param_ex);
+#else
+	ret = XENOMAI_SYSCALL3(sc_cobalt_sched_getscheduler_ex, pid, &policy,
+			       &param_ex);
+#endif
+
 	if (ret == -ESRCH)
 		return __STD(sched_getscheduler(pid));
 
@@ -562,8 +572,13 @@ int sched_get_priority_max_ex(int policy)
 int sched_setconfig_np(int cpu, int policy,
 		       const union sched_config *config, size_t len)
 {
-	return -XENOMAI_SYSCALL4(sc_cobalt_sched_setconfig_np,
-				 cpu, policy, config, len);
+#ifdef __USE_TIME_BITS64
+	return -XENOMAI_SYSCALL4(sc_cobalt_sched_setconfig_np64, cpu, policy,
+				 config, len);
+#else
+	return -XENOMAI_SYSCALL4(sc_cobalt_sched_setconfig_np, cpu, policy,
+				 config, len);
+#endif
 }
 
 /**
@@ -621,8 +636,13 @@ ssize_t sched_getconfig_np(int cpu, int policy,
 {
 	ssize_t ret;
 
-	ret = XENOMAI_SYSCALL4(sc_cobalt_sched_getconfig_np,
-			       cpu, policy, config, *len_r);
+#ifdef __USE_TIME_BITS64
+	ret = XENOMAI_SYSCALL4(sc_cobalt_sched_getconfig_np64, cpu, policy,
+			       config, *len_r);
+#else
+	ret = XENOMAI_SYSCALL4(sc_cobalt_sched_getconfig_np, cpu, policy,
+			       config, *len_r);
+#endif
 	if (ret < 0)
 		return -ret;
 
diff --git a/lib/cobalt/thread.c b/lib/cobalt/thread.c
index bb23cdcb9..b68c11709 100644
--- a/lib/cobalt/thread.c
+++ b/lib/cobalt/thread.c
@@ -93,8 +93,13 @@ static void *cobalt_thread_trampoline(void *p)
 	 * Do _not_ inline the call to pthread_self() in the syscall
 	 * macro: this trashes the syscall regs on some archs.
 	 */
-	ret = -XENOMAI_SYSCALL5(sc_cobalt_thread_create, ptid,
-				policy, &param_ex, personality, &u_winoff);
+#ifdef __USE_TIME_BITS64
+	ret = -XENOMAI_SYSCALL5(sc_cobalt_thread_create64, ptid, policy,
+				&param_ex, personality, &u_winoff);
+#else
+	ret = -XENOMAI_SYSCALL5(sc_cobalt_thread_create, ptid, policy,
+				&param_ex, personality, &u_winoff);
+#endif
 	if (ret == 0)
 		cobalt_set_tsd(u_winoff);
 
@@ -640,10 +645,13 @@ int pthread_setschedparam_ex(pthread_t thread,
 	/* only request promotion when this targets the current thread */
 	u_winoff_ptr = thread == pthread_self() ? &u_winoff : NULL;
 
-	ret = -XENOMAI_SYSCALL5(sc_cobalt_thread_setschedparam_ex,
-				thread, policy, param_ex,
-				u_winoff_ptr, &promoted);
-
+#ifdef __USE_TIME_BITS64
+	ret = -XENOMAI_SYSCALL5(sc_cobalt_thread_setschedparam_ex64, thread,
+				policy, param_ex, u_winoff_ptr, &promoted);
+#else
+	ret = -XENOMAI_SYSCALL5(sc_cobalt_thread_setschedparam_ex, thread,
+				policy, param_ex, u_winoff_ptr, &promoted);
+#endif
 	/*
 	 * If the kernel has no reference to the target thread. let glibc
 	 * handle the call.
@@ -774,8 +782,13 @@ int pthread_getschedparam_ex(pthread_t thread,
 	struct sched_param short_param;
 	int ret;
 
-	ret = -XENOMAI_SYSCALL3(sc_cobalt_thread_getschedparam_ex,
-				thread, policy_r, param_ex);
+#ifdef __USE_TIME_BITS64
+	ret = -XENOMAI_SYSCALL3(sc_cobalt_thread_getschedparam_ex64, thread,
+				policy_r, param_ex);
+#else
+	ret = -XENOMAI_SYSCALL3(sc_cobalt_thread_getschedparam_ex, thread,
+				policy_r, param_ex);
+#endif
 	if (ret == ESRCH) {
 		ret = __STD(pthread_getschedparam(thread, policy_r, &short_param));
 		if (ret == 0)

-- 
2.39.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 05/12] y2038: cobalt/uapi: Introduce xntimespec for struct sched_param_ex API
  2023-07-05  6:38 [PATCH 00/12] y2038: Add time64_t support to scheduler and thread APIs Florian Bezdeka
                   ` (3 preceding siblings ...)
  2023-07-05  6:38 ` [PATCH 04/12] y2038: lib/cobalt/{sched,thread}: Dispatch time64_t related services Florian Bezdeka
@ 2023-07-05  6:38 ` Florian Bezdeka
  2023-07-05  6:38 ` [PATCH 06/12] y2038: cobalt/uapi: Align memory layout for time64 related types Florian Bezdeka
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 28+ messages in thread
From: Florian Bezdeka @ 2023-07-05  6:38 UTC (permalink / raw)
  To: jan.kiszka, xenomai; +Cc: Florian Bezdeka

We have to deal with several aspects that come together here:
  - We are at uapi level here, so contract between Cobalt (Xenomai
    kernel part) and libcobalt (userspace)

  - Both worlds include this header file. The kernel is not allowed to
    use any type definition coming from libc (struct timespec included).
    For userspace we have to use struct timespec because we want to
    turn on y2038 support with compile time switches.

    To fulfill this requirement the xntimespec macro is introduced.
    For userland it's struct timespec, for kernel space it's struct
    __kernel_old_timespec, which is binary compatible to the previously
    used struct __user_old_timespec.

    struct __user_old_timespec is a Xenomai specific type and will be
    removed and cleaned up as a follow-up.

  - All struct sched_param_ex related types are not usable for time64
    related services (kernel part). Related entry points are using types
    around struct sched_param_ex64 already.

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 include/cobalt/uapi/sched.h | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/include/cobalt/uapi/sched.h b/include/cobalt/uapi/sched.h
index 14095870f..730456d89 100644
--- a/include/cobalt/uapi/sched.h
+++ b/include/cobalt/uapi/sched.h
@@ -31,17 +31,23 @@
 #define sched_ss_max_repl	sched_u.ss.__sched_max_repl
 #endif	/* !SCHED_SPORADIC */
 
+#ifdef __KERNEL__
+#define xntimespec	__kernel_old_timespec
+#else
+#define xntimespec	timespec
+#endif
+
 struct __sched_ss_param {
 	int __sched_low_priority;
-	struct __user_old_timespec __sched_repl_period;
-	struct __user_old_timespec __sched_init_budget;
+	struct xntimespec __sched_repl_period;
+	struct xntimespec __sched_init_budget;
 	int __sched_max_repl;
 };
 
 #define sched_rr_quantum	sched_u.rr.__sched_rr_quantum
 
 struct __sched_rr_param {
-	struct __user_old_timespec __sched_rr_quantum;
+	struct xntimespec __sched_rr_quantum;
 };
 
 #ifndef SCHED_TP
@@ -54,8 +60,8 @@ struct __sched_tp_param {
 };
 
 struct sched_tp_window {
-	struct __user_old_timespec offset;
-	struct __user_old_timespec duration;
+	struct xntimespec offset;
+	struct xntimespec duration;
 	int ptid;
 };
 

-- 
2.39.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 06/12] y2038: cobalt/uapi: Align memory layout for time64 related types
  2023-07-05  6:38 [PATCH 00/12] y2038: Add time64_t support to scheduler and thread APIs Florian Bezdeka
                   ` (4 preceding siblings ...)
  2023-07-05  6:38 ` [PATCH 05/12] y2038: cobalt/uapi: Introduce xntimespec for struct sched_param_ex API Florian Bezdeka
@ 2023-07-05  6:38 ` Florian Bezdeka
  2023-07-06  7:23   ` Jan Kiszka
  2023-07-05  6:38 ` [PATCH 07/12] y2038: cobalt/uapi: Remove __user_old_{timespec,itimerspec,timeval,timex} Florian Bezdeka
                   ` (6 subsequent siblings)
  12 siblings, 1 reply; 28+ messages in thread
From: Florian Bezdeka @ 2023-07-05  6:38 UTC (permalink / raw)
  To: jan.kiszka, xenomai; +Cc: Florian Bezdeka

When turning on time64 support the memory layout of
struct sched_param_ex (used by userspace in any case) and the "shadow
type" (struct sched_param_ex64, used by time64 related entry points)
have to match.

Simplified example for different memory layout (offsets) of
struct sched_param_ex:

                                           offset 32 bit   offset 64 bit
struct sched_param_ex {
	int               sched_prio;           0                0
	struct timespec   __sched_ss_param;     4                8
	...
};

With padding we get

struct sched_param_ex {
	int               sched_prio;           0                0
	struct timespec   __sched_ss_param;     8                8
	...
};

This is a backward compatibility breaking change. Incrementing the
Xenomai ABI revision on all supported architectures to express that.

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 include/cobalt/kernel/compat.h                               | 4 ++++
 include/cobalt/uapi/sched.h                                  | 4 ++++
 kernel/cobalt/arch/arm/include/asm/xenomai/uapi/features.h   | 2 +-
 kernel/cobalt/arch/arm64/include/asm/xenomai/uapi/features.h | 2 +-
 kernel/cobalt/arch/x86/include/asm/xenomai/uapi/features.h   | 2 +-
 kernel/cobalt/posix/thread.h                                 | 3 +++
 6 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/include/cobalt/kernel/compat.h b/include/cobalt/kernel/compat.h
index f2dce74b4..71010e3a9 100644
--- a/include/cobalt/kernel/compat.h
+++ b/include/cobalt/kernel/compat.h
@@ -30,9 +30,11 @@ struct sched_param_ex64;
 
 struct __compat_sched_ss_param {
 	int __sched_low_priority;
+	int: 32;
 	struct old_timespec32 __sched_repl_period;
 	struct old_timespec32 __sched_init_budget;
 	int __sched_max_repl;
+	int: 32;
 };
 
 struct __compat_sched_rr_param {
@@ -41,6 +43,7 @@ struct __compat_sched_rr_param {
 
 struct compat_sched_param_ex {
 	int sched_priority;
+	int: 32;
 	union {
 		struct __compat_sched_ss_param ss;
 		struct __compat_sched_rr_param rr;
@@ -60,6 +63,7 @@ struct compat_sched_tp_window {
 	struct old_timespec32 offset;
 	struct old_timespec32 duration;
 	int ptid;
+	int: 32;
 };
 
 struct __compat_sched_config_tp {
diff --git a/include/cobalt/uapi/sched.h b/include/cobalt/uapi/sched.h
index 730456d89..4081fbc0e 100644
--- a/include/cobalt/uapi/sched.h
+++ b/include/cobalt/uapi/sched.h
@@ -39,9 +39,11 @@
 
 struct __sched_ss_param {
 	int __sched_low_priority;
+	int: 32;
 	struct xntimespec __sched_repl_period;
 	struct xntimespec __sched_init_budget;
 	int __sched_max_repl;
+	int: 32;
 };
 
 #define sched_rr_quantum	sched_u.rr.__sched_rr_quantum
@@ -63,6 +65,7 @@ struct sched_tp_window {
 	struct xntimespec offset;
 	struct xntimespec duration;
 	int ptid;
+	int: 32;
 };
 
 enum {
@@ -128,6 +131,7 @@ struct __sched_config_quota {
 
 struct sched_param_ex {
 	int sched_priority;
+	int: 32;
 	union {
 		struct __sched_ss_param ss;
 		struct __sched_rr_param rr;
diff --git a/kernel/cobalt/arch/arm/include/asm/xenomai/uapi/features.h b/kernel/cobalt/arch/arm/include/asm/xenomai/uapi/features.h
index 43b7afb10..fdd5c0e32 100644
--- a/kernel/cobalt/arch/arm/include/asm/xenomai/uapi/features.h
+++ b/kernel/cobalt/arch/arm/include/asm/xenomai/uapi/features.h
@@ -22,7 +22,7 @@
 #define _COBALT_ARM_ASM_UAPI_FEATURES_H
 
 /* The ABI revision level we use on this arch. */
-#define XENOMAI_ABI_REV   18UL
+#define XENOMAI_ABI_REV   19UL
 
 #define XENOMAI_FEAT_DEP (__xn_feat_generic_mask)
 
diff --git a/kernel/cobalt/arch/arm64/include/asm/xenomai/uapi/features.h b/kernel/cobalt/arch/arm64/include/asm/xenomai/uapi/features.h
index b98a96392..301797748 100644
--- a/kernel/cobalt/arch/arm64/include/asm/xenomai/uapi/features.h
+++ b/kernel/cobalt/arch/arm64/include/asm/xenomai/uapi/features.h
@@ -22,7 +22,7 @@
 #define _COBALT_ARM64_ASM_UAPI_FEATURES_H
 
 /* The ABI revision level we use on this arch. */
-#define XENOMAI_ABI_REV   2UL
+#define XENOMAI_ABI_REV   3UL
 
 #define XENOMAI_FEAT_DEP (__xn_feat_generic_mask)
 
diff --git a/kernel/cobalt/arch/x86/include/asm/xenomai/uapi/features.h b/kernel/cobalt/arch/x86/include/asm/xenomai/uapi/features.h
index 65f8164a0..045adf0c1 100644
--- a/kernel/cobalt/arch/x86/include/asm/xenomai/uapi/features.h
+++ b/kernel/cobalt/arch/x86/include/asm/xenomai/uapi/features.h
@@ -19,7 +19,7 @@
 #define _COBALT_X86_ASM_UAPI_FEATURES_H
 
 /* The ABI revision level we use on this arch. */
-#define XENOMAI_ABI_REV   18UL
+#define XENOMAI_ABI_REV   19UL
 
 #define XENOMAI_FEAT_DEP  __xn_feat_generic_mask
 
diff --git a/kernel/cobalt/posix/thread.h b/kernel/cobalt/posix/thread.h
index fb4306351..f663acde7 100644
--- a/kernel/cobalt/posix/thread.h
+++ b/kernel/cobalt/posix/thread.h
@@ -114,9 +114,11 @@ struct cobalt_sigwait_context {
 
 struct __sched_ss_param64 {
 	int __sched_low_priority;
+	int: 32;
 	struct __kernel_timespec __sched_repl_period;
 	struct __kernel_timespec __sched_init_budget;
 	int __sched_max_repl;
+	int: 32;
 };
 
 struct __sched_rr_param64 {
@@ -125,6 +127,7 @@ struct __sched_rr_param64 {
 
 struct sched_param_ex64 {
 	int sched_priority;
+	int: 32;
 	union {
 		struct __sched_ss_param64 ss;
 		struct __sched_rr_param64 rr;

-- 
2.39.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 07/12] y2038: cobalt/uapi: Remove __user_old_{timespec,itimerspec,timeval,timex}
  2023-07-05  6:38 [PATCH 00/12] y2038: Add time64_t support to scheduler and thread APIs Florian Bezdeka
                   ` (5 preceding siblings ...)
  2023-07-05  6:38 ` [PATCH 06/12] y2038: cobalt/uapi: Align memory layout for time64 related types Florian Bezdeka
@ 2023-07-05  6:38 ` Florian Bezdeka
  2023-07-05  6:38 ` [PATCH 08/12] y2038: testsuite/smokey/y2038: Fix reporting of thread return status Florian Bezdeka
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 28+ messages in thread
From: Florian Bezdeka @ 2023-07-05  6:38 UTC (permalink / raw)
  To: jan.kiszka, xenomai; +Cc: Florian Bezdeka

The types below were "native" types representing 64 bit time_t on 64
bit systems and 32 bit time_t on 32 bit systems. As those types were
xenomai specific types they could not be used for "auto y2038 support"
enablement by using compile time flags.

1:1 type replacements:
  __user_old_timespec    ->  __kernel_old_timespec (still "native")
  __user_old_timeval     ->  __kernel_old_timeval  (still "native")

Type migrations to "32 bit always":
  __user_old_itimerspec  ->  old_itimerspec32
  __user_old_timex       ->  old_timex32

  Affected syscalls will only be used by 32 bit applications. The
  "native" variant will be routed to 64 bit services.

Renamed functions:
  cobalt_get_u_itimerspec -> cobalt_get_itimerspec32
  cobalt_put_u_itimerspec -> cobalt_put_itimerspec32

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 include/cobalt/uapi/kernel/types.h                 | 53 ----------------------
 .../cobalt/include/asm-generic/xenomai/syscall.h   | 20 ++++----
 kernel/cobalt/posix/clock.c                        | 13 +++---
 kernel/cobalt/posix/clock.h                        | 12 ++---
 kernel/cobalt/posix/cond.c                         |  2 +-
 kernel/cobalt/posix/cond.h                         |  2 +-
 kernel/cobalt/posix/event.c                        |  2 +-
 kernel/cobalt/posix/event.h                        |  2 +-
 kernel/cobalt/posix/io.c                           |  2 +-
 kernel/cobalt/posix/io.h                           |  2 +-
 kernel/cobalt/posix/monitor.c                      |  2 +-
 kernel/cobalt/posix/monitor.h                      |  2 +-
 kernel/cobalt/posix/mqueue.c                       |  4 +-
 kernel/cobalt/posix/mqueue.h                       |  4 +-
 kernel/cobalt/posix/mutex.c                        |  2 +-
 kernel/cobalt/posix/mutex.h                        |  2 +-
 kernel/cobalt/posix/sem.c                          |  2 +-
 kernel/cobalt/posix/sem.h                          |  2 +-
 kernel/cobalt/posix/signal.c                       |  2 +-
 kernel/cobalt/posix/signal.h                       |  2 +-
 kernel/cobalt/posix/timer.c                        | 14 +++---
 kernel/cobalt/posix/timer.h                        |  6 +--
 kernel/cobalt/posix/timerfd.c                      | 14 +++---
 kernel/cobalt/posix/timerfd.h                      |  6 +--
 lib/cobalt/clock.c                                 |  2 +-
 lib/cobalt/internal.h                              |  5 ++
 lib/cobalt/timer.c                                 |  4 +-
 lib/cobalt/timerfd.c                               |  4 +-
 28 files changed, 73 insertions(+), 116 deletions(-)

diff --git a/include/cobalt/uapi/kernel/types.h b/include/cobalt/uapi/kernel/types.h
index 2c931c29c..ee5bbadca 100644
--- a/include/cobalt/uapi/kernel/types.h
+++ b/include/cobalt/uapi/kernel/types.h
@@ -57,57 +57,4 @@ static inline xnhandle_t xnhandle_get_id(xnhandle_t handle)
 	return handle & ~XN_HANDLE_TRANSIENT_MASK;
 }
 
-/*
- * Our representation of time specs at the kernel<->user interface
- * boundary at the moment, until we have fully transitioned to a
- * y2038-safe implementation in libcobalt. Once done, those legacy
- * types will be removed.
- */
-struct __user_old_timespec {
-	long  tv_sec;
-	long  tv_nsec;
-};
-
-struct __user_old_itimerspec {
-	struct __user_old_timespec it_interval;
-	struct __user_old_timespec it_value;
-};
-
-struct __user_old_timeval {
-	long  tv_sec;
-	long  tv_usec;
-};
-
-/* Lifted from include/uapi/linux/timex.h. */
-struct __user_old_timex {
-	unsigned int modes;	/* mode selector */
-	__kernel_long_t offset;	/* time offset (usec) */
-	__kernel_long_t freq;	/* frequency offset (scaled ppm) */
-	__kernel_long_t maxerror;/* maximum error (usec) */
-	__kernel_long_t esterror;/* estimated error (usec) */
-	int status;		/* clock command/status */
-	__kernel_long_t constant;/* pll time constant */
-	__kernel_long_t precision;/* clock precision (usec) (read only) */
-	__kernel_long_t tolerance;/* clock frequency tolerance (ppm)
-				   * (read only)
-				   */
-	struct __user_old_timeval time;	/* (read only, except for ADJ_SETOFFSET) */
-	__kernel_long_t tick;	/* (modified) usecs between clock ticks */
-
-	__kernel_long_t ppsfreq;/* pps frequency (scaled ppm) (ro) */
-	__kernel_long_t jitter; /* pps jitter (us) (ro) */
-	int shift;              /* interval duration (s) (shift) (ro) */
-	__kernel_long_t stabil;            /* pps stability (scaled ppm) (ro) */
-	__kernel_long_t jitcnt; /* jitter limit exceeded (ro) */
-	__kernel_long_t calcnt; /* calibration intervals (ro) */
-	__kernel_long_t errcnt; /* calibration errors (ro) */
-	__kernel_long_t stbcnt; /* stability limit exceeded (ro) */
-
-	int tai;		/* TAI offset (ro) */
-
-	int  :32; int  :32; int  :32; int  :32;
-	int  :32; int  :32; int  :32; int  :32;
-	int  :32; int  :32; int  :32;
-};
-
 #endif /* !_COBALT_UAPI_KERNEL_TYPES_H */
diff --git a/kernel/cobalt/include/asm-generic/xenomai/syscall.h b/kernel/cobalt/include/asm-generic/xenomai/syscall.h
index d61b985fb..a3bdc2018 100644
--- a/kernel/cobalt/include/asm-generic/xenomai/syscall.h
+++ b/kernel/cobalt/include/asm-generic/xenomai/syscall.h
@@ -74,9 +74,9 @@ static inline int cobalt_strncpy_from_user(char *dst, const char __user *src,
  */
 
 static inline int cobalt_get_u_timespec(struct timespec64 *dst,
-			const struct __user_old_timespec __user *src)
+			const struct __kernel_old_timespec __user *src)
 {
-	struct __user_old_timespec u_ts;
+	struct __kernel_old_timespec u_ts;
 	int ret;
 
 	ret = cobalt_copy_from_user(&u_ts, src, sizeof(u_ts));
@@ -90,10 +90,10 @@ static inline int cobalt_get_u_timespec(struct timespec64 *dst,
 }
 
 static inline int cobalt_put_u_timespec(
-	struct __user_old_timespec __user *dst,
+	struct __kernel_old_timespec __user *dst,
 	const struct timespec64 *src)
 {
-	struct __user_old_timespec u_ts;
+	struct __kernel_old_timespec u_ts;
 	int ret;
 
 	u_ts.tv_sec = src->tv_sec;
@@ -106,10 +106,10 @@ static inline int cobalt_put_u_timespec(
 	return 0;
 }
 
-static inline int cobalt_get_u_itimerspec(struct itimerspec64 *dst,
-			const struct __user_old_itimerspec __user *src)
+static inline int cobalt_get_itimerspec32(struct itimerspec64 *dst,
+			const struct old_itimerspec32 __user *src)
 {
-	struct __user_old_itimerspec u_its;
+	struct old_itimerspec32 u_its;
 	int ret;
 
 	ret = cobalt_copy_from_user(&u_its, src, sizeof(u_its));
@@ -124,11 +124,11 @@ static inline int cobalt_get_u_itimerspec(struct itimerspec64 *dst,
 	return 0;
 }
 
-static inline int cobalt_put_u_itimerspec(
-	struct __user_old_itimerspec __user *dst,
+static inline int cobalt_put_itimerspec32(
+	struct old_itimerspec32 __user *dst,
 	const struct itimerspec64 *src)
 {
-	struct __user_old_itimerspec u_its;
+	struct old_itimerspec32 u_its;
 
 	u_its.it_interval.tv_sec = src->it_interval.tv_sec;
 	u_its.it_interval.tv_nsec = src->it_interval.tv_nsec;
diff --git a/kernel/cobalt/posix/clock.c b/kernel/cobalt/posix/clock.c
index 48cd87aef..c48526751 100644
--- a/kernel/cobalt/posix/clock.c
+++ b/kernel/cobalt/posix/clock.c
@@ -76,7 +76,7 @@ int __cobalt_clock_getres(clockid_t clock_id, struct timespec64 *ts)
 }
 
 COBALT_SYSCALL(clock_getres, current,
-	       (clockid_t clock_id, struct __user_old_timespec __user *u_ts))
+	       (clockid_t clock_id, struct __kernel_old_timespec __user *u_ts))
 {
 	struct timespec64 ts;
 	int ret;
@@ -141,7 +141,7 @@ int __cobalt_clock_gettime(clockid_t clock_id, struct timespec64 *ts)
 }
 
 COBALT_SYSCALL(clock_gettime, current,
-	       (clockid_t clock_id, struct __user_old_timespec __user *u_ts))
+	       (clockid_t clock_id, struct __kernel_old_timespec __user *u_ts))
 {
 	struct timespec64 ts;
 	int ret;
@@ -216,7 +216,7 @@ int __cobalt_clock_adjtime(clockid_t clock_id, struct __kernel_timex *tx)
 }
 
 COBALT_SYSCALL(clock_settime, current,
-	       (clockid_t clock_id, const struct __user_old_timespec __user *u_ts))
+	       (clockid_t clock_id, const struct __kernel_old_timespec __user *u_ts))
 {
 	struct timespec64 ts;
 
@@ -238,8 +238,9 @@ COBALT_SYSCALL(clock_settime64, current,
 	return __cobalt_clock_settime(clock_id, &ts64);
 }
 
+/* Only used by 32 bit applications without time64_t support */
 COBALT_SYSCALL(clock_adjtime, current,
-	       (clockid_t clock_id, struct __user_old_timex __user *u_tx))
+	       (clockid_t clock_id, struct old_timex32 __user *u_tx))
 {
 	struct __kernel_timex tx;
 	int ret;
@@ -349,8 +350,8 @@ int __cobalt_clock_nanosleep(clockid_t clock_id, int flags,
 
 COBALT_SYSCALL(clock_nanosleep, primary,
 	       (clockid_t clock_id, int flags,
-		const struct __user_old_timespec __user *u_rqt,
-		struct __user_old_timespec __user *u_rmt))
+		const struct __kernel_old_timespec __user *u_rqt,
+		struct __kernel_old_timespec __user *u_rmt))
 {
 	struct timespec64 rqt, rmt, *rmtp = NULL;
 	int ret;
diff --git a/kernel/cobalt/posix/clock.h b/kernel/cobalt/posix/clock.h
index 294b1bf02..e70d88000 100644
--- a/kernel/cobalt/posix/clock.h
+++ b/kernel/cobalt/posix/clock.h
@@ -122,34 +122,34 @@ int __cobalt_clock_nanosleep(clockid_t clock_id, int flags,
 			     struct timespec64 *rmt);
 
 COBALT_SYSCALL_DECL(clock_getres,
-		    (clockid_t clock_id, struct __user_old_timespec __user *u_ts));
+		    (clockid_t clock_id, struct __kernel_old_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(clock_getres64,
 		    (clockid_t clock_id, struct __kernel_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(clock_gettime,
-		    (clockid_t clock_id, struct __user_old_timespec __user *u_ts));
+		    (clockid_t clock_id, struct __kernel_old_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(clock_gettime64,
 		    (clockid_t clock_id, struct __kernel_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(clock_settime,
-		    (clockid_t clock_id, const struct __user_old_timespec __user *u_ts));
+		    (clockid_t clock_id, const struct __kernel_old_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(clock_settime64,
 		    (clockid_t clock_id,
 			 const struct __kernel_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(clock_adjtime,
-		    (clockid_t clock_id, struct __user_old_timex __user *u_tx));
+		    (clockid_t clock_id, struct old_timex32 __user *u_tx));
 
 COBALT_SYSCALL_DECL(clock_adjtime64,
 		    (clockid_t clock_id, struct __kernel_timex __user *u_tx));
 
 COBALT_SYSCALL_DECL(clock_nanosleep,
 		    (clockid_t clock_id, int flags,
-		     const struct __user_old_timespec __user *u_rqt,
-		     struct __user_old_timespec __user *u_rmt));
+		     const struct __kernel_old_timespec __user *u_rqt,
+		     struct __kernel_old_timespec __user *u_rmt));
 
 COBALT_SYSCALL_DECL(clock_nanosleep64,
 		    (clockid_t clock_id, int flags,
diff --git a/kernel/cobalt/posix/cond.c b/kernel/cobalt/posix/cond.c
index 7b87fe908..690242e61 100644
--- a/kernel/cobalt/posix/cond.c
+++ b/kernel/cobalt/posix/cond.c
@@ -360,7 +360,7 @@ COBALT_SYSCALL(cond_wait_prologue, nonrestartable,
 		struct cobalt_mutex_shadow __user *u_mx,
 		int __user *u_err,
 		unsigned int timed,
-		struct __user_old_timespec __user *u_ts))
+		struct __kernel_old_timespec __user *u_ts))
 {
 	return __cobalt_cond_wait_prologue(u_cnd, u_mx, u_err, u_ts,
 					   timed ? cond_fetch_timeout : NULL);
diff --git a/kernel/cobalt/posix/cond.h b/kernel/cobalt/posix/cond.h
index c2fdd40e0..1eab5d26b 100644
--- a/kernel/cobalt/posix/cond.h
+++ b/kernel/cobalt/posix/cond.h
@@ -58,7 +58,7 @@ COBALT_SYSCALL_DECL(cond_wait_prologue,
 		     struct cobalt_mutex_shadow __user *u_mx,
 		     int __user *u_err,
 		     unsigned int timed,
-		     struct __user_old_timespec __user *u_ts));
+		     struct __kernel_old_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(cond_wait_prologue64,
 		    (struct cobalt_cond_shadow __user *u_cnd,
diff --git a/kernel/cobalt/posix/event.c b/kernel/cobalt/posix/event.c
index a5fa45db8..01975b022 100644
--- a/kernel/cobalt/posix/event.c
+++ b/kernel/cobalt/posix/event.c
@@ -194,7 +194,7 @@ 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 __user_old_timespec __user *u_ts))
+		int mode, const struct __kernel_old_timespec __user *u_ts))
 {
 	struct timespec64 ts, *tsp = NULL;
 	int ret;
diff --git a/kernel/cobalt/posix/event.h b/kernel/cobalt/posix/event.h
index a67141f2b..d8c83ed75 100644
--- a/kernel/cobalt/posix/event.h
+++ b/kernel/cobalt/posix/event.h
@@ -51,7 +51,7 @@ COBALT_SYSCALL_DECL(event_wait,
 		     unsigned int bits,
 		     unsigned int __user *u_bits_r,
 		     int mode,
-		     const struct __user_old_timespec __user *u_ts));
+		     const struct __kernel_old_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(event_wait64,
 		    (struct cobalt_event_shadow __user *u_evtsh,
diff --git a/kernel/cobalt/posix/io.c b/kernel/cobalt/posix/io.c
index 9e6f3edfa..05c4b298d 100644
--- a/kernel/cobalt/posix/io.c
+++ b/kernel/cobalt/posix/io.c
@@ -116,7 +116,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 __user_old_timespec __user *u_timeout))
+		unsigned int flags, struct __kernel_old_timespec __user *u_timeout))
 {
 	return __rtdm_fd_recvmmsg(fd, u_msgvec, vlen, flags, u_timeout,
 				  get_mmsg, put_mmsg, get_timespec);
diff --git a/kernel/cobalt/posix/io.h b/kernel/cobalt/posix/io.h
index ca46aa309..106e2d523 100644
--- a/kernel/cobalt/posix/io.h
+++ b/kernel/cobalt/posix/io.h
@@ -51,7 +51,7 @@ COBALT_SYSCALL_DECL(recvmsg,
 
 COBALT_SYSCALL_DECL(recvmmsg,
 		    (int fd, struct mmsghdr __user *u_msgvec, unsigned int vlen,
-		     unsigned int flags, struct __user_old_timespec __user *u_timeout));
+		     unsigned int flags, struct __kernel_old_timespec __user *u_timeout));
 
 COBALT_SYSCALL_DECL(recvmmsg64,
 		    (int fd, struct mmsghdr __user *u_msgvec, unsigned int vlen,
diff --git a/kernel/cobalt/posix/monitor.c b/kernel/cobalt/posix/monitor.c
index c266b8b3b..eb37fe4f2 100644
--- a/kernel/cobalt/posix/monitor.c
+++ b/kernel/cobalt/posix/monitor.c
@@ -296,7 +296,7 @@ out:
 
 COBALT_SYSCALL(monitor_wait, nonrestartable,
 	       (struct cobalt_monitor_shadow __user *u_mon,
-	       int event, const struct __user_old_timespec __user *u_ts,
+	       int event, const struct __kernel_old_timespec __user *u_ts,
 	       int __user *u_ret))
 {
 	struct timespec64 ts, *tsp = NULL;
diff --git a/kernel/cobalt/posix/monitor.h b/kernel/cobalt/posix/monitor.h
index 3c76a036b..0cf53c768 100644
--- a/kernel/cobalt/posix/monitor.h
+++ b/kernel/cobalt/posix/monitor.h
@@ -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 __user_old_timespec __user *u_ts,
+		     int event, const struct __kernel_old_timespec __user *u_ts,
 		     int __user *u_ret));
 
 COBALT_SYSCALL_DECL(monitor_wait64,
diff --git a/kernel/cobalt/posix/mqueue.c b/kernel/cobalt/posix/mqueue.c
index 4487e23de..ed26344e4 100644
--- a/kernel/cobalt/posix/mqueue.c
+++ b/kernel/cobalt/posix/mqueue.c
@@ -976,7 +976,7 @@ out:
 
 COBALT_SYSCALL(mq_timedsend, primary,
 	       (mqd_t uqd, const void __user *u_buf, size_t len,
-		unsigned int prio, const struct __user_old_timespec __user *u_ts))
+		unsigned int prio, const struct __kernel_old_timespec __user *u_ts))
 {
 	return __cobalt_mq_timedsend(uqd, u_buf, len, prio,
 				     u_ts, u_ts ? mq_fetch_timeout : NULL);
@@ -1054,7 +1054,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 __user_old_timespec __user *u_ts))
+		const struct __kernel_old_timespec __user *u_ts))
 {
 	ssize_t len;
 	int ret;
diff --git a/kernel/cobalt/posix/mqueue.h b/kernel/cobalt/posix/mqueue.h
index 755623f47..7cf45c3dc 100644
--- a/kernel/cobalt/posix/mqueue.h
+++ b/kernel/cobalt/posix/mqueue.h
@@ -66,7 +66,7 @@ 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 __user_old_timespec __user *u_ts));
+		     unsigned int prio, const struct __kernel_old_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(mq_timedsend64,
 		    (mqd_t uqd, const void __user *u_buf, size_t len,
@@ -76,7 +76,7 @@ COBALT_SYSCALL_DECL(mq_timedsend64,
 COBALT_SYSCALL_DECL(mq_timedreceive,
 		    (mqd_t uqd, void __user *u_buf, ssize_t __user *u_len,
 		     unsigned int __user *u_prio,
-		     const struct __user_old_timespec __user *u_ts));
+		     const struct __kernel_old_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(mq_timedreceive64,
 		    (mqd_t uqd, void __user *u_buf, ssize_t __user *u_len,
diff --git a/kernel/cobalt/posix/mutex.c b/kernel/cobalt/posix/mutex.c
index 2bdb66d17..34767e4ba 100644
--- a/kernel/cobalt/posix/mutex.c
+++ b/kernel/cobalt/posix/mutex.c
@@ -366,7 +366,7 @@ static inline int mutex_fetch_timeout64(struct timespec64 *ts,
 
 COBALT_SYSCALL(mutex_timedlock, primary,
 	       (struct cobalt_mutex_shadow __user *u_mx,
-		const struct __user_old_timespec __user *u_ts))
+		const struct __kernel_old_timespec __user *u_ts))
 {
 	return __cobalt_mutex_timedlock_break(u_mx, u_ts, mutex_fetch_timeout);
 }
diff --git a/kernel/cobalt/posix/mutex.h b/kernel/cobalt/posix/mutex.h
index 800515a69..4e977fd07 100644
--- a/kernel/cobalt/posix/mutex.h
+++ b/kernel/cobalt/posix/mutex.h
@@ -62,7 +62,7 @@ COBALT_SYSCALL_DECL(mutex_lock,
 
 COBALT_SYSCALL_DECL(mutex_timedlock,
 		    (struct cobalt_mutex_shadow __user *u_mx,
-		     const struct __user_old_timespec __user *u_ts));
+		     const struct __kernel_old_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(mutex_timedlock64,
 		    (struct cobalt_mutex_shadow __user *u_mx,
diff --git a/kernel/cobalt/posix/sem.c b/kernel/cobalt/posix/sem.c
index aca03a555..2b20bf6e5 100644
--- a/kernel/cobalt/posix/sem.c
+++ b/kernel/cobalt/posix/sem.c
@@ -458,7 +458,7 @@ COBALT_SYSCALL(sem_wait, primary,
 
 COBALT_SYSCALL(sem_timedwait, primary,
 	       (struct cobalt_sem_shadow __user *u_sem,
-		const struct __user_old_timespec __user *u_ts))
+		const struct __kernel_old_timespec __user *u_ts))
 {
 	struct timespec64 ts64;
 	int ret = 1;
diff --git a/kernel/cobalt/posix/sem.h b/kernel/cobalt/posix/sem.h
index e1e4d68f0..ae0d929e0 100644
--- a/kernel/cobalt/posix/sem.h
+++ b/kernel/cobalt/posix/sem.h
@@ -89,7 +89,7 @@ COBALT_SYSCALL_DECL(sem_wait,
 
 COBALT_SYSCALL_DECL(sem_timedwait,
 		    (struct cobalt_sem_shadow __user *u_sem,
-		     const struct __user_old_timespec __user *u_ts));
+		     const struct __kernel_old_timespec __user *u_ts));
 
 COBALT_SYSCALL_DECL(sem_timedwait64,
 		    (struct cobalt_sem_shadow __user *u_sem,
diff --git a/kernel/cobalt/posix/signal.c b/kernel/cobalt/posix/signal.c
index ced534079..1842aa5e8 100644
--- a/kernel/cobalt/posix/signal.c
+++ b/kernel/cobalt/posix/signal.c
@@ -426,7 +426,7 @@ int __cobalt_sigtimedwait(sigset_t *set,
 COBALT_SYSCALL(sigtimedwait, nonrestartable,
 	       (const sigset_t __user *u_set,
 		struct siginfo __user *u_si,
-		const struct __user_old_timespec __user *u_timeout))
+		const struct __kernel_old_timespec __user *u_timeout))
 {
 	struct timespec64 timeout;
 	sigset_t set;
diff --git a/kernel/cobalt/posix/signal.h b/kernel/cobalt/posix/signal.h
index 0b5d11e81..227086756 100644
--- a/kernel/cobalt/posix/signal.h
+++ b/kernel/cobalt/posix/signal.h
@@ -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 __user_old_timespec __user *u_timeout));
+		     const struct __kernel_old_timespec __user *u_timeout));
 
 COBALT_SYSCALL_DECL(sigtimedwait64,
 		    (const sigset_t __user *u_set,
diff --git a/kernel/cobalt/posix/timer.c b/kernel/cobalt/posix/timer.c
index 0f111a42c..3107698ca 100644
--- a/kernel/cobalt/posix/timer.c
+++ b/kernel/cobalt/posix/timer.c
@@ -469,10 +469,11 @@ COBALT_SYSCALL(timer_create, current,
 	return __cobalt_timer_create(clock, evp, u_tm);
 }
 
+/* Only used by 32 bit applications without time64_t support */
 COBALT_SYSCALL(timer_settime, primary,
 	       (timer_t tm, int flags,
-		const struct __user_old_itimerspec __user *u_newval,
-		struct __user_old_itimerspec __user *u_oldval))
+		const struct old_itimerspec32 __user *u_newval,
+		struct old_itimerspec32 __user *u_oldval))
 {
 	struct itimerspec64 newv, oldv, *oldvp = &oldv;
 	int ret;
@@ -480,14 +481,14 @@ COBALT_SYSCALL(timer_settime, primary,
 	if (u_oldval == NULL)
 		oldvp = NULL;
 
-	if (cobalt_get_u_itimerspec(&newv, u_newval))
+	if (cobalt_get_itimerspec32(&newv, u_newval))
 		return -EFAULT;
 
 	ret = __cobalt_timer_settime(tm, flags, &newv, oldvp);
 	if (ret)
 		return ret;
 
-	if (oldvp && cobalt_put_u_itimerspec(u_oldval, oldvp)) {
+	if (oldvp && cobalt_put_itimerspec32(u_oldval, oldvp)) {
 		__cobalt_timer_settime(tm, flags, oldvp, NULL);
 		return -EFAULT;
 	}
@@ -521,8 +522,9 @@ COBALT_SYSCALL(timer_settime64, primary,
 	return 0;
 }
 
+/* Only used by 32 bit applications without time64_t support */
 COBALT_SYSCALL(timer_gettime, current,
-	       (timer_t tm, struct __user_old_itimerspec __user *u_val))
+	       (timer_t tm, struct old_itimerspec32 __user *u_val))
 {
 	struct itimerspec64 val;
 	int ret;
@@ -531,7 +533,7 @@ COBALT_SYSCALL(timer_gettime, current,
 	if (ret)
 		return ret;
 
-	return cobalt_put_u_itimerspec(u_val, &val);
+	return cobalt_put_itimerspec32(u_val, &val);
 }
 
 COBALT_SYSCALL(timer_gettime64, current,
diff --git a/kernel/cobalt/posix/timer.h b/kernel/cobalt/posix/timer.h
index 864c780e8..96df80334 100644
--- a/kernel/cobalt/posix/timer.h
+++ b/kernel/cobalt/posix/timer.h
@@ -75,8 +75,8 @@ COBALT_SYSCALL_DECL(timer_delete, (timer_t tm));
 
 COBALT_SYSCALL_DECL(timer_settime,
 		    (timer_t tm, int flags,
-		     const struct __user_old_itimerspec __user *u_newval,
-		     struct __user_old_itimerspec __user *u_oldval));
+		     const struct old_itimerspec32 __user *u_newval,
+		     struct old_itimerspec32 __user *u_oldval));
 
 COBALT_SYSCALL_DECL(timer_settime64,
 		    (timer_t tm, int flags,
@@ -84,7 +84,7 @@ COBALT_SYSCALL_DECL(timer_settime64,
 		     struct __kernel_itimerspec __user *u_oldval));
 
 COBALT_SYSCALL_DECL(timer_gettime,
-		    (timer_t tm, struct __user_old_itimerspec __user *u_val));
+		    (timer_t tm, struct old_itimerspec32 __user *u_val));
 
 COBALT_SYSCALL_DECL(timer_gettime64,
 		    (timer_t tm, struct __kernel_itimerspec __user *u_val));
diff --git a/kernel/cobalt/posix/timerfd.c b/kernel/cobalt/posix/timerfd.c
index ae7578d29..4839a0861 100644
--- a/kernel/cobalt/posix/timerfd.c
+++ b/kernel/cobalt/posix/timerfd.c
@@ -279,15 +279,16 @@ out:
 	return ret;
 }
 
+/* Only used by 32 bit applications without time64_t support */
 COBALT_SYSCALL(timerfd_settime, primary,
 	       (int fd, int flags,
-		const struct __user_old_itimerspec __user *new_value,
-		struct __user_old_itimerspec __user *old_value))
+		const struct old_itimerspec32 __user *new_value,
+		struct old_itimerspec32 __user *old_value))
 {
 	struct itimerspec64 ovalue, value;
 	int ret;
 
-	ret = cobalt_get_u_itimerspec(&value, new_value);
+	ret = cobalt_get_itimerspec32(&value, new_value);
 	if (ret)
 		return ret;
 
@@ -296,7 +297,7 @@ COBALT_SYSCALL(timerfd_settime, primary,
 		return ret;
 
 	if (old_value) {
-		ret = cobalt_put_u_itimerspec(old_value, &ovalue);
+		ret = cobalt_put_itimerspec32(old_value, &ovalue);
 		value.it_value.tv_sec = 0;
 		value.it_value.tv_nsec = 0;
 		__cobalt_timerfd_settime(fd, flags, &value, NULL);
@@ -349,15 +350,16 @@ int __cobalt_timerfd_gettime(int fd, struct itimerspec64 *value)
 	return 0;
 }
 
+/* Only used by 32 bit applications without time64_t support */
 COBALT_SYSCALL(timerfd_gettime, current,
-	       (int fd, struct __user_old_itimerspec __user *curr_value))
+	       (int fd, struct old_itimerspec32 __user *curr_value))
 {
 	struct itimerspec64 value;
 	int ret;
 
 	ret = __cobalt_timerfd_gettime(fd, &value);
 
-	return ret ?: cobalt_put_u_itimerspec(curr_value, &value);
+	return ret ?: cobalt_put_itimerspec32(curr_value, &value);
 }
 
 COBALT_SYSCALL(timerfd_gettime64, current,
diff --git a/kernel/cobalt/posix/timerfd.h b/kernel/cobalt/posix/timerfd.h
index b82dac748..004985f46 100644
--- a/kernel/cobalt/posix/timerfd.h
+++ b/kernel/cobalt/posix/timerfd.h
@@ -33,8 +33,8 @@ COBALT_SYSCALL_DECL(timerfd_create,
 
 COBALT_SYSCALL_DECL(timerfd_settime,
 		    (int fd, int flags,
-		     const struct __user_old_itimerspec __user *new_value,
-		     struct __user_old_itimerspec __user *old_value));
+		     const struct old_itimerspec32 __user *new_value,
+		     struct old_itimerspec32 __user *old_value));
 
 COBALT_SYSCALL_DECL(timerfd_settime64,
 		    (int fd, int flags,
@@ -42,7 +42,7 @@ COBALT_SYSCALL_DECL(timerfd_settime64,
 		     struct __kernel_itimerspec __user *old_value));
 
 COBALT_SYSCALL_DECL(timerfd_gettime,
-		    (int fd, struct __user_old_itimerspec __user *curr_value));
+		    (int fd, struct old_itimerspec32 __user *curr_value));
 
 COBALT_SYSCALL_DECL(timerfd_gettime64,
 		    (int fd, struct __kernel_itimerspec __user *curr_value));
diff --git a/lib/cobalt/clock.c b/lib/cobalt/clock.c
index 490426499..dbfcd4d76 100644
--- a/lib/cobalt/clock.c
+++ b/lib/cobalt/clock.c
@@ -309,7 +309,7 @@ COBALT_IMPL(int, clock_adjtime, (clockid_t clock_id, struct timex *tx))
 {
 	int ret;
 
-#ifdef __USE_TIME_BITS64
+#ifdef XN_USE_TIME64_SYSCALL
 	ret = -XENOMAI_SYSCALL2(sc_cobalt_clock_adjtime64, clock_id, tx);
 #else
 	ret = -XENOMAI_SYSCALL2(sc_cobalt_clock_adjtime, clock_id, tx);
diff --git a/lib/cobalt/internal.h b/lib/cobalt/internal.h
index acb3989f1..00f51fa23 100644
--- a/lib/cobalt/internal.h
+++ b/lib/cobalt/internal.h
@@ -25,6 +25,11 @@
 #include <cobalt/sys/cobalt.h>
 #include "current.h"
 
+#if defined(__USE_TIME_BITS64) || __WORDSIZE == 64 ||                          \
+	(defined(__SYSCALL_WORDSIZE) && __SYSCALL_WORDSIZE == 64)
+#define XN_USE_TIME64_SYSCALL
+#endif
+
 extern void *cobalt_umm_private;
 
 extern void *cobalt_umm_shared;
diff --git a/lib/cobalt/timer.c b/lib/cobalt/timer.c
index d8955832e..d86d01417 100644
--- a/lib/cobalt/timer.c
+++ b/lib/cobalt/timer.c
@@ -166,7 +166,7 @@ COBALT_IMPL(int, timer_settime, (timer_t timerid,
 {
 	int ret;
 
-#ifdef __USE_TIME_BITS64
+#ifdef XN_USE_TIME64_SYSCALL
 	long sc_nr = sc_cobalt_timer_settime64;
 #else
 	long sc_nr = sc_cobalt_timer_settime;
@@ -214,7 +214,7 @@ COBALT_IMPL(int, timer_gettime, (timer_t timerid, struct itimerspec *value))
 {
 	int ret;
 
-#ifdef __USE_TIME_BITS64
+#ifdef XN_USE_TIME64_SYSCALL
 	long sc_nr = sc_cobalt_timer_gettime64;
 #else
 	long sc_nr = sc_cobalt_timer_gettime;
diff --git a/lib/cobalt/timerfd.c b/lib/cobalt/timerfd.c
index c0e64929a..5e7db928f 100644
--- a/lib/cobalt/timerfd.c
+++ b/lib/cobalt/timerfd.c
@@ -41,7 +41,7 @@ COBALT_IMPL(int, timerfd_settime,
 {
 	int ret;
 
-#ifdef __USE_TIME_BITS64
+#ifdef XN_USE_TIME64_SYSCALL
 	long sc_nr = sc_cobalt_timerfd_settime64;
 #else
 	long sc_nr = sc_cobalt_timerfd_settime;
@@ -59,7 +59,7 @@ COBALT_IMPL(int, timerfd_gettime, (int fd, struct itimerspec *curr_value))
 {
 	int ret;
 
-#ifdef __USE_TIME_BITS64
+#ifdef XN_USE_TIME64_SYSCALL
 	long sc_nr = sc_cobalt_timerfd_gettime64;
 #else
 	long sc_nr = sc_cobalt_timerfd_gettime;

-- 
2.39.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 08/12] y2038: testsuite/smokey/y2038: Fix reporting of thread return status
  2023-07-05  6:38 [PATCH 00/12] y2038: Add time64_t support to scheduler and thread APIs Florian Bezdeka
                   ` (6 preceding siblings ...)
  2023-07-05  6:38 ` [PATCH 07/12] y2038: cobalt/uapi: Remove __user_old_{timespec,itimerspec,timeval,timex} Florian Bezdeka
@ 2023-07-05  6:38 ` Florian Bezdeka
  2023-07-06  7:27   ` Jan Kiszka
  2023-07-05  6:38 ` [PATCH 09/12] y2038: testsuite/smokey/y2038: Add tests for sched_param_ex related syscalls Florian Bezdeka
                   ` (4 subsequent siblings)
  12 siblings, 1 reply; 28+ messages in thread
From: Florian Bezdeka @ 2023-07-05  6:38 UTC (permalink / raw)
  To: jan.kiszka, xenomai; +Cc: Florian Bezdeka

run_thread was not reporting back the thread exit status but the result
of pthread_join, which is normally a success, even if the thread itself
was not successful.

That revealed some wrong exit status checks inside the y2038 tests.

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 testsuite/smokey/y2038/syscall-tests.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/testsuite/smokey/y2038/syscall-tests.c b/testsuite/smokey/y2038/syscall-tests.c
index af27f2bce..d5ab2e8b1 100644
--- a/testsuite/smokey/y2038/syscall-tests.c
+++ b/testsuite/smokey/y2038/syscall-tests.c
@@ -155,7 +155,7 @@ static int run_thread(void *(*thread)(void *), void *arg, int exp_result)
 
 	res = (long)status;
 
-	return (res == exp_result) ? 0 : ret;
+	return (res == exp_result) ? 0 : res;
 }
 
 static int test_sc_cobalt_sem_timedwait64(void)
@@ -528,13 +528,13 @@ static int test_sc_cobalt_mutex_timedlock64(void)
 		return ret;
 
 	/*
-	 * mutex still locked, second thread has to fail with -EINVAL when
+	 * mutex still locked, second thread has to fail with -EFAULT when
 	 * submitting NULL as timeout
 	 */
 	ctx.sc_nr = sc_nr;
 	ctx.mutex = &mutex;
 	ctx.ts = NULL;
-	if (!__T(ret, run_thread(timedlock64_thread, &ctx, -EINVAL)))
+	if (!__T(ret, run_thread(timedlock64_thread, &ctx, -EFAULT)))
 		return ret;
 
 	/*
@@ -546,12 +546,12 @@ static int test_sc_cobalt_mutex_timedlock64(void)
 		return ret;
 
 	/*
-	 * mutex still locked, second thread has to fail with -EFAULT when
+	 * mutex still locked, second thread has to fail with -EINVAL when
 	 * submitting an invalid timeout (while the address is valid)
 	 */
 	ts64.tv_sec = -1;
 	ctx.ts = &ts64;
-	if (!__T(ret, run_thread(timedlock64_thread, &ctx, -EFAULT)))
+	if (!__T(ret, run_thread(timedlock64_thread, &ctx, -EINVAL)))
 		return ret;
 
 	/*

-- 
2.39.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 09/12] y2038: testsuite/smokey/y2038: Add tests for sched_param_ex related syscalls
  2023-07-05  6:38 [PATCH 00/12] y2038: Add time64_t support to scheduler and thread APIs Florian Bezdeka
                   ` (7 preceding siblings ...)
  2023-07-05  6:38 ` [PATCH 08/12] y2038: testsuite/smokey/y2038: Fix reporting of thread return status Florian Bezdeka
@ 2023-07-05  6:38 ` Florian Bezdeka
  2023-07-05  6:38 ` [PATCH 10/12] y2038: testsuite/smokey/y2038: Fix a race in the pselect interruption test Florian Bezdeka
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 28+ messages in thread
From: Florian Bezdeka @ 2023-07-05  6:38 UTC (permalink / raw)
  To: jan.kiszka, xenomai; +Cc: Florian Bezdeka

Extend the smokey testsuite to do some tests for the recently added
time64_t based syscalls:
  - thread_setschedparam_ex64
  - thread_getschedparam_ex64
  - sched_setscheduler_ex64
  - sched_getscheduler_ex64

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 testsuite/smokey/y2038/syscall-tests.c | 322 +++++++++++++++++++++++++++++++++
 1 file changed, 322 insertions(+)

diff --git a/testsuite/smokey/y2038/syscall-tests.c b/testsuite/smokey/y2038/syscall-tests.c
index d5ab2e8b1..ab7c3bb4c 100644
--- a/testsuite/smokey/y2038/syscall-tests.c
+++ b/testsuite/smokey/y2038/syscall-tests.c
@@ -1601,6 +1601,316 @@ out:
 	return test_pselect64_interruption();
 }
 
+static void *cobalt_getset_schedparam_ex64_thread(void *arg)
+{
+	long sc_set = sc_cobalt_thread_setschedparam_ex64;
+	long sc_get = sc_cobalt_thread_getschedparam_ex64;
+	pthread_t thread = pthread_self();
+	int promoted;
+	int policy;
+	int ret;
+
+	/* ABI compatible to struct sched_param_ex64. */
+	struct {
+		int sched_priority;
+		int: 32;
+		union {
+			struct {
+				struct xn_timespec64 __sched_rr_quantum;
+			} rr;
+			struct {
+				int sched_low_priority;
+				int: 32;
+				struct xn_timespec64 sched_repl_period;
+				struct xn_timespec64 sched_init_budget;
+				int sched_max_repl;
+				int: 32;
+			} ss;
+		} sched_u;
+	} p;
+
+	/* get: Make sure we don't crash because of NULL pointers */
+	ret = XENOMAI_SYSCALL5(sc_get, 0, 0, NULL, NULL, NULL);
+	if (ret == -ENOSYS) {
+		smokey_note(
+			"cobalt_thread_getschedparam_ex64: skipped. (no kernel support)");
+		ret = 0;
+		goto out; // Not implemented, nothing to test, success
+	}
+
+	/* set: Make sure we don't crash because of NULL pointers */
+	ret = XENOMAI_SYSCALL5(sc_set, 0, 0, NULL, NULL, NULL);
+	if (ret == -ENOSYS) {
+		smokey_note(
+			"cobalt_thread_setschedparam_ex64: skipped. (no kernel support)");
+		ret = 0;
+		goto out; // Not implemented, nothing to test, success
+	}
+	if (!smokey_assert(ret == -EFAULT)) {
+		ret = ret ? ret : -EINVAL;
+		goto out;
+	}
+
+	/* Overwrite */
+	policy = SCHED_RR;
+	p.sched_priority = 50;
+	p.sched_rr_quantum.tv_sec = 12345;
+	p.sched_rr_quantum.tv_nsec = 67890123;
+	ret = XENOMAI_SYSCALL5(sc_set, thread, policy, &p, NULL, &promoted);
+	if (!smokey_assert(!ret)) {
+		ret = ret ? ret : -EINVAL;
+		goto out;
+	}
+
+	/* Fetch again and compare, reset compare values first */
+	p.sched_priority = 0;
+	p.sched_rr_quantum.tv_sec = 0;
+	p.sched_rr_quantum.tv_nsec = 0;
+	ret = XENOMAI_SYSCALL5(sc_get, thread, &policy, &p, NULL, &promoted);
+	if (!smokey_assert(!ret)) {
+		ret = ret ? ret : -EINVAL;
+		goto out;
+	}
+
+	ret = 1;
+	ret &= smokey_assert(policy == SCHED_RR);
+	ret &= smokey_assert(p.sched_priority == 50);
+	ret &= smokey_assert(p.sched_rr_quantum.tv_sec == 12345);
+	ret &= smokey_assert(p.sched_rr_quantum.tv_nsec == 67890123);
+	if (!ret)
+		ret = -EINVAL;
+	else
+		ret = 0;
+out:
+	return (void *)(long)ret;
+}
+
+static int test_sc_cobalt_thread_set_and_getschedparam_ex64(void)
+{
+	struct sched_param param = { .sched_priority = 1 };
+	pthread_attr_t attr;
+	pthread_t t;
+	void *res;
+	int ret;
+
+	ret = smokey_check_status(pthread_attr_init(&attr));
+	ret |= smokey_check_status(
+		pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE));
+	ret |= smokey_check_status(
+		pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED));
+	ret |= smokey_check_status(
+		pthread_attr_setschedpolicy(&attr, SCHED_RR));
+	ret |= smokey_check_status(pthread_attr_setschedparam(&attr, &param));
+	if (ret)
+		return ret;
+
+	ret = smokey_check_status(pthread_create(
+		&t, &attr, cobalt_getset_schedparam_ex64_thread, NULL));
+	if (ret)
+		return ret;
+
+	ret = smokey_check_status(pthread_join(t, &res));
+	if (ret)
+		return ret;
+
+	if (res)
+		return (int)(long)res;
+
+	return smokey_check_status(pthread_attr_destroy(&attr));
+}
+
+static void *cobalt_sched_setandget_config_np64_thread(void *arg)
+{
+#define WINDOWS 2
+	long sc_nr_set = sc_cobalt_sched_setconfig_np64;
+	long sc_nr_get = sc_cobalt_sched_getconfig_np64;
+	size_t len_out;
+	size_t len_in;
+	int avail;
+	int ret;
+
+	/* ABI compatible to union sched_config64 */
+	union {
+		struct {
+			int op;
+			int nr_windows;
+			struct {
+				struct xn_timespec64 offset;
+				struct xn_timespec64 duration;
+				int ptid;
+				int: 32;
+			} windows[WINDOWS];
+		} tp;
+
+	} cfg_in = { 0 }, cfg_out = { 0 };
+
+	ret = cobalt_corectl(_CC_COBALT_GET_POLICIES, &avail, sizeof(avail));
+	if (ret || (avail & _CC_COBALT_SCHED_TP) == 0)
+		return (void *)(long)-ENOSYS;
+
+	len_in = sizeof(cfg_in);
+
+	cfg_in.tp.op = sched_tp_install;
+	cfg_in.tp.nr_windows = WINDOWS;
+	cfg_in.tp.windows[0].offset.tv_sec = 0;
+	cfg_in.tp.windows[0].offset.tv_nsec = 0;
+	cfg_in.tp.windows[0].duration.tv_sec = 0;
+	cfg_in.tp.windows[0].duration.tv_nsec = 100000000;
+	cfg_in.tp.windows[0].ptid = 1;
+	cfg_in.tp.windows[1].offset.tv_sec = 0;
+	cfg_in.tp.windows[1].offset.tv_nsec = 100000000;
+	cfg_in.tp.windows[1].duration.tv_sec = 0;
+	cfg_in.tp.windows[1].duration.tv_nsec = 100000000;
+	cfg_in.tp.windows[1].ptid = 1;
+
+	ret = XENOMAI_SYSCALL4(sc_nr_set, 0, SCHED_TP, &cfg_in, len_in);
+	if (ret == -ENOSYS) {
+		smokey_note(
+			"cobalt_sched_setconfig_np64: skipped. (no kernel support)");
+		ret = 0;
+		goto out; // Not implemented, nothing to test, success
+	}
+	if (!smokey_assert(!ret)) {
+		ret = ret ? ret : -EINVAL;
+		goto out;
+	}
+
+	len_out = len_in;
+	ret = XENOMAI_SYSCALL4(sc_nr_get, 0, SCHED_TP, &cfg_out, len_out);
+	if (ret == -ENOSYS) {
+		smokey_note(
+			"cobalt_sched_getconfig_np64: skipped. (no kernel support)");
+		ret = 0;
+		goto out; // Not implemented, nothing to test, success
+	}
+	if (!smokey_assert(ret == len_in)) {
+		ret = ret ?: -EINVAL;
+		goto out;
+	}
+
+	/* We can't use memcmp() here, the padding will be uninitialized */
+	ret = 1;
+	ret &= smokey_assert(cfg_in.tp.op == cfg_out.tp.op);
+	ret &= smokey_assert(cfg_in.tp.nr_windows == cfg_out.tp.nr_windows);
+	for (int i = 0; i < WINDOWS; i++) {
+		ret &= smokey_assert(cfg_in.tp.windows[i].offset.tv_sec ==
+				     cfg_out.tp.windows[i].offset.tv_sec);
+		ret &= smokey_assert(cfg_in.tp.windows[i].offset.tv_nsec ==
+				     cfg_out.tp.windows[i].offset.tv_nsec);
+		ret &= smokey_assert(cfg_in.tp.windows[i].duration.tv_sec ==
+				     cfg_out.tp.windows[i].duration.tv_sec);
+		ret &= smokey_assert(cfg_in.tp.windows[i].duration.tv_nsec ==
+				     cfg_out.tp.windows[i].duration.tv_nsec);
+		ret &= smokey_assert(cfg_in.tp.windows[i].ptid ==
+				     cfg_out.tp.windows[i].ptid);
+		if (!ret)
+			break;
+	}
+
+	if (ret)
+		ret = 0;
+	else
+		ret = -EINVAL;
+
+out:
+	return (void *)(long)ret;
+}
+
+static int test_sc_cobalt_sched_set_and_getconfig_np64(void)
+{
+	return run_thread(cobalt_sched_setandget_config_np64_thread, NULL, 0);
+}
+
+static void *cobalt_sched_setandget_ex64_thread(void *arg)
+{
+	long sc_nr_set = sc_cobalt_sched_setscheduler_ex64;
+	long sc_nr_get = sc_cobalt_sched_getscheduler_ex64;
+	int avail, policy, promoted;
+	uint32_t winoff;
+	int ret;
+
+	/* ABI compatible to sched_param_ex64 */
+	struct {
+		int sched_priority;
+		int: 32;
+		union {
+			struct {
+				int __sched_low_priority;
+				int: 32;
+				struct xn_timespec64 __sched_repl_period;
+				struct xn_timespec64 __sched_init_budget;
+				int __sched_max_repl;
+				int: 32;
+			} ss;
+		} sched_u;
+	} in, out;
+
+	ret = cobalt_corectl(_CC_COBALT_GET_POLICIES, &avail, sizeof(avail));
+	if (ret || (avail & _CC_COBALT_SCHED_SPORADIC) == 0)
+		return (void *)(long)-ENOSYS;
+
+	policy = SCHED_SPORADIC;
+	in.sched_priority = 50;
+	in.sched_ss_low_priority = 40;
+	in.sched_ss_repl_period.tv_sec = 0;
+	in.sched_ss_repl_period.tv_nsec = 100000;
+	in.sched_ss_init_budget.tv_sec = 0;
+	in.sched_ss_init_budget.tv_nsec = 100000;
+	in.sched_ss_max_repl = 5;
+
+	ret = XENOMAI_SYSCALL5(sc_nr_set, 0, policy, &in, &winoff, &promoted);
+	if (ret == -ENOSYS) {
+		smokey_note(
+			"cobalt_sched_setparam_ex64: skipped. (no kernel support)");
+		ret = 0;
+		goto out; // Not implemented, nothing to test, success
+	}
+	if (!smokey_assert(!ret)) {
+		ret = ret ? ret : -EINVAL;
+		goto out;
+	}
+
+	ret = XENOMAI_SYSCALL5(sc_nr_get, 0, &policy, &out, &winoff, &promoted);
+	if (ret == -ENOSYS) {
+		smokey_note(
+			"cobalt_sched_getparam_ex64: skipped. (no kernel support)");
+		ret = 0;
+		goto out; // Not implemented, nothing to test, success
+	}
+	if (!smokey_assert(!ret)) {
+		ret = ret ? ret : -EINVAL;
+		goto out;
+	}
+
+	/* We can't use memcmp() here as the padding will be uninitialized */
+	ret = 1;
+	ret &= smokey_assert(policy == SCHED_SPORADIC);
+	ret &= smokey_assert(in.sched_priority == out.sched_priority);
+	ret &= smokey_assert(in.sched_ss_low_priority ==
+			     out.sched_ss_low_priority);
+	ret &= smokey_assert(in.sched_ss_repl_period.tv_sec ==
+			     out.sched_ss_repl_period.tv_sec);
+	ret &= smokey_assert(in.sched_ss_repl_period.tv_nsec ==
+			     out.sched_ss_repl_period.tv_nsec);
+	ret &= smokey_assert(in.sched_ss_init_budget.tv_sec ==
+			     out.sched_ss_init_budget.tv_sec);
+	ret &= smokey_assert(in.sched_ss_init_budget.tv_nsec ==
+			     out.sched_ss_init_budget.tv_nsec);
+	ret &= smokey_assert(in.sched_ss_max_repl == out.sched_ss_max_repl);
+	if (ret)
+		ret = 0;
+	else
+		ret = -EINVAL;
+
+out:
+	return (void *)(long)ret;
+}
+
+static int test_sc_cobalt_sched_set_and_get_scheduler_ex64(void)
+{
+	return run_thread(cobalt_sched_setandget_ex64_thread, NULL, 0);
+}
+
 static int check_kernel_version(void)
 {
 	int ret, major, minor;
@@ -1710,5 +2020,17 @@ static int run_y2038(struct smokey_test *t, int argc, char *const argv[])
 	if (ret)
 		return ret;
 
+	ret = test_sc_cobalt_thread_set_and_getschedparam_ex64();
+	if (ret)
+		return ret;
+
+	ret = test_sc_cobalt_sched_set_and_getconfig_np64();
+	if (ret)
+		return ret;
+
+	ret = test_sc_cobalt_sched_set_and_get_scheduler_ex64();
+	if (ret)
+		return ret;
+
 	return 0;
 }

-- 
2.39.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 10/12] y2038: testsuite/smokey/y2038: Fix a race in the pselect interruption test
  2023-07-05  6:38 [PATCH 00/12] y2038: Add time64_t support to scheduler and thread APIs Florian Bezdeka
                   ` (8 preceding siblings ...)
  2023-07-05  6:38 ` [PATCH 09/12] y2038: testsuite/smokey/y2038: Add tests for sched_param_ex related syscalls Florian Bezdeka
@ 2023-07-05  6:38 ` Florian Bezdeka
  2023-07-05  7:15   ` Jan Kiszka
  2023-07-05  6:38 ` [PATCH 11/12] y2038: testsuite/smokey/y2038: Fix normalization of struct xn_timespec64 Florian Bezdeka
                   ` (2 subsequent siblings)
  12 siblings, 1 reply; 28+ messages in thread
From: Florian Bezdeka @ 2023-07-05  6:38 UTC (permalink / raw)
  To: jan.kiszka, xenomai; +Cc: Florian Bezdeka

It might have happened that the signal was sent and handled before
we reached the blocking point inside the pselect syscall. Adding
another synchronization point right before the context switch should
fix that.

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 testsuite/smokey/y2038/syscall-tests.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/testsuite/smokey/y2038/syscall-tests.c b/testsuite/smokey/y2038/syscall-tests.c
index ab7c3bb4c..0ee0bc48c 100644
--- a/testsuite/smokey/y2038/syscall-tests.c
+++ b/testsuite/smokey/y2038/syscall-tests.c
@@ -124,6 +124,7 @@ static inline bool ts_less(const struct xn_timespec64 *a,
 struct thread_context {
 	int sc_nr;
 	int sock;
+	sem_t *sem;
 	pthread_mutex_t *mutex;
 	struct xn_timespec64 *ts;
 	bool timedwait_timecheck;
@@ -1472,6 +1473,7 @@ static void *pselect64_waiting_thread(void *arg)
 	/* Waiting for 1sec should be enough to get a signal */
 	ts.tv_sec = 1;
 	ts.tv_nsec = 0;
+	sem_post(ctx->sem);
 	ret = XENOMAI_SYSCALL5(ctx->sc_nr, sock + 1, &rfds, NULL, NULL, &ts);
 	if (!smokey_assert(ret == -EINTR)) {
 		ret = ret ?: -EINVAL;
@@ -1494,6 +1496,7 @@ static int test_pselect64_interruption(void)
 	struct thread_context ctx = { 0 };
 	void *w_ret = NULL;
 	pthread_t w;
+	sem_t sem;
 	int sock;
 	int ret;
 
@@ -1505,14 +1508,22 @@ static int test_pselect64_interruption(void)
 	if (sock < 0)
 		return sock;
 
+	ret = smokey_check_errno(sem_init(&sem, 0, 0));
+	if (ret)
+		return ret;
+
 	ctx.sock = sock;
 	ctx.sc_nr = sc_cobalt_pselect64;
+	ctx.sem = &sem;
 
 	ret = smokey_check_status(
 		pthread_create(&w, NULL, pselect64_waiting_thread, &ctx));
 	if (ret)
 		goto out_sock;
 
+	/* Wait for the waiting thread to be ready */
+	sem_wait(&sem);
+
 	/* Allow the waiting thread to enter the pselect64() syscall */
 	nanosleep(&ts, NULL);
 
@@ -1528,6 +1539,7 @@ static int test_pselect64_interruption(void)
 		w_ret = NULL;
 
 out_sock:
+	sem_destroy(&sem);
 	close(sock);
 	return (int)(long)w_ret;
 }

-- 
2.39.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 11/12] y2038: testsuite/smokey/y2038: Fix normalization of struct xn_timespec64
  2023-07-05  6:38 [PATCH 00/12] y2038: Add time64_t support to scheduler and thread APIs Florian Bezdeka
                   ` (9 preceding siblings ...)
  2023-07-05  6:38 ` [PATCH 10/12] y2038: testsuite/smokey/y2038: Fix a race in the pselect interruption test Florian Bezdeka
@ 2023-07-05  6:38 ` Florian Bezdeka
  2023-07-06  7:27   ` Jan Kiszka
  2023-07-05  6:38 ` [PATCH 12/12] testsuite/smokey: Fix unconditional unloads of the xeno_rtdmtest module Florian Bezdeka
  2023-07-05  6:54 ` [PATCH 00/12] y2038: Add time64_t support to scheduler and thread APIs Jan Kiszka
  12 siblings, 1 reply; 28+ messages in thread
From: Florian Bezdeka @ 2023-07-05  6:38 UTC (permalink / raw)
  To: jan.kiszka, xenomai; +Cc: Florian Bezdeka

We have to increment the seconds if the nanosecond field got too big.

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 testsuite/smokey/y2038/syscall-tests.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/testsuite/smokey/y2038/syscall-tests.c b/testsuite/smokey/y2038/syscall-tests.c
index 0ee0bc48c..0b908f3ac 100644
--- a/testsuite/smokey/y2038/syscall-tests.c
+++ b/testsuite/smokey/y2038/syscall-tests.c
@@ -69,7 +69,7 @@ struct xn_timex64 {
 static void ts_normalise(struct xn_timespec64 *ts)
 {
 	while (ts->tv_nsec >= NSEC_PER_SEC) {
-		ts->tv_nsec += 1;
+		ts->tv_sec += 1;
 		ts->tv_nsec -= NSEC_PER_SEC;
 	}
 

-- 
2.39.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 12/12] testsuite/smokey: Fix unconditional unloads of the xeno_rtdmtest module
  2023-07-05  6:38 [PATCH 00/12] y2038: Add time64_t support to scheduler and thread APIs Florian Bezdeka
                   ` (10 preceding siblings ...)
  2023-07-05  6:38 ` [PATCH 11/12] y2038: testsuite/smokey/y2038: Fix normalization of struct xn_timespec64 Florian Bezdeka
@ 2023-07-05  6:38 ` Florian Bezdeka
  2023-07-06  7:27   ` Jan Kiszka
  2023-07-05  6:54 ` [PATCH 00/12] y2038: Add time64_t support to scheduler and thread APIs Jan Kiszka
  12 siblings, 1 reply; 28+ messages in thread
From: Florian Bezdeka @ 2023-07-05  6:38 UTC (permalink / raw)
  To: jan.kiszka, xenomai; +Cc: Florian Bezdeka

The cpu-affinity and the rtdm test unloaded the xeno_rtdmtest module
even if it was not loaded by the test upfront. In addition, such tests
failed if the module was already loaded. That made partially re-running
the testsuite after a failed run harder.

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 testsuite/smokey/cpu-affinity/cpu-affinity.c | 13 +++++--------
 testsuite/smokey/rtdm/rtdm.c                 |  7 ++++---
 2 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/testsuite/smokey/cpu-affinity/cpu-affinity.c b/testsuite/smokey/cpu-affinity/cpu-affinity.c
index 4a59ff6f5..cbc877182 100644
--- a/testsuite/smokey/cpu-affinity/cpu-affinity.c
+++ b/testsuite/smokey/cpu-affinity/cpu-affinity.c
@@ -73,10 +73,10 @@ out:
 static int load_test_module(void)
 {
 	int fd, status;
-	
-	status = system("modprobe -q xeno_rtdmtest");
-	if (status < 0 || WEXITSTATUS(status))
-		return -ENOSYS;
+
+	status = smokey_modprobe("xeno_rtdmtest", true);
+	if (status)
+		return status;
 
 	/* Open the RTDM actor device. */
 	fd = open("/dev/rtdm/rtdmx", O_RDWR);
@@ -88,11 +88,8 @@ static int load_test_module(void)
 
 static void unload_test_module(int fd)
 {
-	int status;
-	
 	close(fd);
-	status = system("rmmod xeno_rtdmtest");
-	(void)status;
+	smokey_rmmod("xeno_rtdmtest");
 }
 
 static void *__run_cpu_affinity(void *arg)
diff --git a/testsuite/smokey/rtdm/rtdm.c b/testsuite/smokey/rtdm/rtdm.c
index 0b89228fc..6ad0d6d7a 100644
--- a/testsuite/smokey/rtdm/rtdm.c
+++ b/testsuite/smokey/rtdm/rtdm.c
@@ -153,8 +153,8 @@ static int run_rtdm(struct smokey_test *t, int argc, char *const argv[])
 {
 	int dev, dev2, status;
 
-	status = system("modprobe -q xeno_rtdmtest");
-	if (status < 0 || WEXITSTATUS(status))
+	status = smokey_modprobe("xeno_rtdmtest", true);
+	if (status)
 		return -ENOSYS;
 
 	if (access(devname, 0) < 0 && errno == ENOENT)
@@ -195,7 +195,8 @@ static int run_rtdm(struct smokey_test *t, int argc, char *const argv[])
 	check("ioctl", ioctl(dev, RTTST_RTIOC_RTDM_DEFER_CLOSE,
 			     RTTST_RTDM_DEFER_CLOSE_CONTEXT), 0);
 	check("close", close(dev), 0);
-	check("rmmod", system("rmmod xeno_rtdmtest"), 0);
+
+	smokey_rmmod("xeno_rtdmtest");
 
 	return 0;
 }

-- 
2.39.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* Re: [PATCH 00/12] y2038: Add time64_t support to scheduler and thread APIs
  2023-07-05  6:38 [PATCH 00/12] y2038: Add time64_t support to scheduler and thread APIs Florian Bezdeka
                   ` (11 preceding siblings ...)
  2023-07-05  6:38 ` [PATCH 12/12] testsuite/smokey: Fix unconditional unloads of the xeno_rtdmtest module Florian Bezdeka
@ 2023-07-05  6:54 ` Jan Kiszka
  2023-07-05  7:05   ` Bezdeka, Florian
  12 siblings, 1 reply; 28+ messages in thread
From: Jan Kiszka @ 2023-07-05  6:54 UTC (permalink / raw)
  To: Florian Bezdeka, xenomai

On 05.07.23 08:38, Florian Bezdeka wrote:
> Hi all,
> 
> this is hopefully the last preparation series necessary to turn on
> time64_t support (a.k.a. y2038 support). 
> 
> With this series applied the Xenomai specific APIs around scheduler and
> thread APIs will support time64_t when requested. The final "turn on by
> default" switch will be part of the final y2038 series (which is hopefully
> the next one).
> 
> The remaining stuff can be found in my y2038 queue at [1].
> The Xenomai hackerspace wiki is up to date and represents the current
> state of the y2038 work. See [2].

Which of the fixes from patch 8 onward should be merged first so that
the problems with the in-tree tests are addressed first?

Thanks,
Jan

-- 
Siemens AG, Technology
Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 00/12] y2038: Add time64_t support to scheduler and thread APIs
  2023-07-05  6:54 ` [PATCH 00/12] y2038: Add time64_t support to scheduler and thread APIs Jan Kiszka
@ 2023-07-05  7:05   ` Bezdeka, Florian
  2023-07-05  7:14     ` Jan Kiszka
  0 siblings, 1 reply; 28+ messages in thread
From: Bezdeka, Florian @ 2023-07-05  7:05 UTC (permalink / raw)
  To: Kiszka, Jan, xenomai

On Wed, 2023-07-05 at 08:54 +0200, Jan Kiszka wrote:
> On 05.07.23 08:38, Florian Bezdeka wrote:
> > Hi all,
> > 
> > this is hopefully the last preparation series necessary to turn on
> > time64_t support (a.k.a. y2038 support). 
> > 
> > With this series applied the Xenomai specific APIs around scheduler
> > and
> > thread APIs will support time64_t when requested. The final "turn
> > on by
> > default" switch will be part of the final y2038 series (which is
> > hopefully
> > the next one).
> > 
> > The remaining stuff can be found in my y2038 queue at [1].
> > The Xenomai hackerspace wiki is up to date and represents the
> > current
> > state of the y2038 work. See [2].
> 
> Which of the fixes from patch 8 onward should be merged first so that
> the problems with the in-tree tests are addressed first?

That would be Patch 10 only. I never saw this problem on internal CI
test runs, so I'm not 100% sure if that fixes the issue. But I think
it's worth giving it a try.

I can try to move it to the front of the series. Should be easy but the
QA CI run will take some time.

Florian

> Thanks,
> Jan
> 


^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 00/12] y2038: Add time64_t support to scheduler and thread APIs
  2023-07-05  7:05   ` Bezdeka, Florian
@ 2023-07-05  7:14     ` Jan Kiszka
  0 siblings, 0 replies; 28+ messages in thread
From: Jan Kiszka @ 2023-07-05  7:14 UTC (permalink / raw)
  To: Bezdeka, Florian (T CED SES-DE), xenomai

On 05.07.23 09:05, Bezdeka, Florian (T CED SES-DE) wrote:
> On Wed, 2023-07-05 at 08:54 +0200, Jan Kiszka wrote:
>> On 05.07.23 08:38, Florian Bezdeka wrote:
>>> Hi all,
>>>
>>> this is hopefully the last preparation series necessary to turn on
>>> time64_t support (a.k.a. y2038 support). 
>>>
>>> With this series applied the Xenomai specific APIs around scheduler
>>> and
>>> thread APIs will support time64_t when requested. The final "turn
>>> on by
>>> default" switch will be part of the final y2038 series (which is
>>> hopefully
>>> the next one).
>>>
>>> The remaining stuff can be found in my y2038 queue at [1].
>>> The Xenomai hackerspace wiki is up to date and represents the
>>> current
>>> state of the y2038 work. See [2].
>>
>> Which of the fixes from patch 8 onward should be merged first so that
>> the problems with the in-tree tests are addressed first?
> 
> That would be Patch 10 only. I never saw this problem on internal CI
> test runs, so I'm not 100% sure if that fixes the issue. But I think
> it's worth giving it a try.
> 
> I can try to move it to the front of the series. Should be easy but the
> QA CI run will take some time.
> 

I just did that in next, let's see...

Jan

-- 
Siemens AG, Technology
Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 10/12] y2038: testsuite/smokey/y2038: Fix a race in the pselect interruption test
  2023-07-05  6:38 ` [PATCH 10/12] y2038: testsuite/smokey/y2038: Fix a race in the pselect interruption test Florian Bezdeka
@ 2023-07-05  7:15   ` Jan Kiszka
  0 siblings, 0 replies; 28+ messages in thread
From: Jan Kiszka @ 2023-07-05  7:15 UTC (permalink / raw)
  To: Florian Bezdeka, xenomai

On 05.07.23 08:38, Florian Bezdeka wrote:
> It might have happened that the signal was sent and handled before
> we reached the blocking point inside the pselect syscall. Adding
> another synchronization point right before the context switch should
> fix that.
> 
> Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
> ---
>  testsuite/smokey/y2038/syscall-tests.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/testsuite/smokey/y2038/syscall-tests.c b/testsuite/smokey/y2038/syscall-tests.c
> index ab7c3bb4c..0ee0bc48c 100644
> --- a/testsuite/smokey/y2038/syscall-tests.c
> +++ b/testsuite/smokey/y2038/syscall-tests.c
> @@ -124,6 +124,7 @@ static inline bool ts_less(const struct xn_timespec64 *a,
>  struct thread_context {
>  	int sc_nr;
>  	int sock;
> +	sem_t *sem;
>  	pthread_mutex_t *mutex;
>  	struct xn_timespec64 *ts;
>  	bool timedwait_timecheck;
> @@ -1472,6 +1473,7 @@ static void *pselect64_waiting_thread(void *arg)
>  	/* Waiting for 1sec should be enough to get a signal */
>  	ts.tv_sec = 1;
>  	ts.tv_nsec = 0;
> +	sem_post(ctx->sem);
>  	ret = XENOMAI_SYSCALL5(ctx->sc_nr, sock + 1, &rfds, NULL, NULL, &ts);
>  	if (!smokey_assert(ret == -EINTR)) {
>  		ret = ret ?: -EINVAL;
> @@ -1494,6 +1496,7 @@ static int test_pselect64_interruption(void)
>  	struct thread_context ctx = { 0 };
>  	void *w_ret = NULL;
>  	pthread_t w;
> +	sem_t sem;
>  	int sock;
>  	int ret;
>  
> @@ -1505,14 +1508,22 @@ static int test_pselect64_interruption(void)
>  	if (sock < 0)
>  		return sock;
>  
> +	ret = smokey_check_errno(sem_init(&sem, 0, 0));
> +	if (ret)
> +		return ret;
> +
>  	ctx.sock = sock;
>  	ctx.sc_nr = sc_cobalt_pselect64;
> +	ctx.sem = &sem;
>  
>  	ret = smokey_check_status(
>  		pthread_create(&w, NULL, pselect64_waiting_thread, &ctx));
>  	if (ret)
>  		goto out_sock;
>  
> +	/* Wait for the waiting thread to be ready */
> +	sem_wait(&sem);
> +
>  	/* Allow the waiting thread to enter the pselect64() syscall */
>  	nanosleep(&ts, NULL);
>  
> @@ -1528,6 +1539,7 @@ static int test_pselect64_interruption(void)
>  		w_ret = NULL;
>  
>  out_sock:
> +	sem_destroy(&sem);
>  	close(sock);
>  	return (int)(long)w_ret;
>  }
> 

Applied to next already, thanks.

Jan

-- 
Siemens AG, Technology
Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 01/12] y2038: cobalt: Introduce sched_param_ex64 and use it internally
  2023-07-05  6:38 ` [PATCH 01/12] y2038: cobalt: Introduce sched_param_ex64 and use it internally Florian Bezdeka
@ 2023-07-06  7:13   ` Jan Kiszka
  2023-07-06  7:48     ` Florian Bezdeka
  2023-07-06  7:14   ` Jan Kiszka
  1 sibling, 1 reply; 28+ messages in thread
From: Jan Kiszka @ 2023-07-06  7:13 UTC (permalink / raw)
  To: Florian Bezdeka, xenomai

On 05.07.23 08:38, Florian Bezdeka wrote:
> Introducing a new type sched_param_ex64. All members are (always) based
> on time64_t. All internal APIs have been migrated now. Existing compat
> and native system call entry points will do the necessary translation.
> 
> This is a preparation step for introducing time64_t based cobalt thread
> cobalt services.
> 
> Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
> ---
>  include/cobalt/kernel/compat.h     |   5 +-
>  kernel/cobalt/posix/clock.h        |  38 +++++++++--
>  kernel/cobalt/posix/compat.c       |   5 +-
>  kernel/cobalt/posix/sched.c        |  39 +++++++-----
>  kernel/cobalt/posix/sched.h        |   8 +--
>  kernel/cobalt/posix/syscall32.c    |  12 ++--
>  kernel/cobalt/posix/thread.c       | 126 ++++++++++++++++++++++++++++++-------
>  kernel/cobalt/posix/thread.h       |  39 ++++++++++--
>  kernel/cobalt/trace/cobalt-posix.h |  20 +++---
>  9 files changed, 219 insertions(+), 73 deletions(-)
> 
> diff --git a/include/cobalt/kernel/compat.h b/include/cobalt/kernel/compat.h
> index 275735df5..f2dce74b4 100644
> --- a/include/cobalt/kernel/compat.h
> +++ b/include/cobalt/kernel/compat.h
> @@ -26,6 +26,7 @@
>  #include <cobalt/uapi/sched.h>
>  
>  struct mq_attr;
> +struct sched_param_ex64;
>  
>  struct __compat_sched_ss_param {
>  	int __sched_low_priority;
> @@ -117,12 +118,12 @@ int sys32_put_fdset(compat_fd_set __user *cfds, const fd_set *fds,
>  		    size_t fdsize);
>  
>  int sys32_get_param_ex(int policy,
> -		       struct sched_param_ex *p,
> +		       struct sched_param_ex64 *p,
>  		       const struct compat_sched_param_ex __user *u_cp);
>  
>  int sys32_put_param_ex(int policy,
>  		       struct compat_sched_param_ex __user *u_cp,
> -		       const struct sched_param_ex *p);
> +		       const struct sched_param_ex64 *p);
>  
>  int sys32_get_mqattr(struct mq_attr *ap,
>  		     const struct compat_mq_attr __user *u_cap);
> diff --git a/kernel/cobalt/posix/clock.h b/kernel/cobalt/posix/clock.h
> index 38b59e24f..b0fc84396 100644
> --- a/kernel/cobalt/posix/clock.h
> +++ b/kernel/cobalt/posix/clock.h
> @@ -18,6 +18,7 @@
>  #ifndef _COBALT_POSIX_CLOCK_H
>  #define _COBALT_POSIX_CLOCK_H
>  
> +#include <linux/compat.h>
>  #include <linux/types.h>
>  #include <linux/time.h>
>  #include <linux/cpumask.h>
> @@ -38,6 +39,14 @@ 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 void ns2kts(struct __kernel_timespec *kts, xnticks_t ticks)
> +{
> +	unsigned long nsecs;
> +
> +	kts->tv_sec = xnclock_divrem_billion(ticks, &nsecs);
> +	kts->tv_nsec = (long long)nsecs;
> +}
> +
>  static inline xnticks_t ts2ns(const struct timespec64 *ts)
>  {
>  	xnticks_t nsecs = ts->tv_nsec;
> @@ -48,6 +57,23 @@ static inline xnticks_t ts2ns(const struct timespec64 *ts)
>  	return nsecs;
>  }
>  
> +static inline xnticks_t kts2ns(const struct __kernel_timespec *ts)
> +{
> +	xnticks_t nsecs = ts->tv_nsec;
> +
> +	/* zero out padding in compat mode */
> +	if (in_compat_syscall())
> +		nsecs &= 0xFFFFFFFFUL;
> +
> +	/* In 32-bit mode, this drops the padding */
> +	nsecs = (long)nsecs;

These two look strange: nsecs > 1,000,000,000 (which already fits into
32-bits) is a bug, if ts came from userspace, an userspace bug. Why
don't we need to catch that? When could the higher bits be undefined,
and why don't we initialize them properly at the point ts is filled?

Jan

-- 
Siemens AG, Technology
Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 01/12] y2038: cobalt: Introduce sched_param_ex64 and use it internally
  2023-07-05  6:38 ` [PATCH 01/12] y2038: cobalt: Introduce sched_param_ex64 and use it internally Florian Bezdeka
  2023-07-06  7:13   ` Jan Kiszka
@ 2023-07-06  7:14   ` Jan Kiszka
  2023-07-06  7:48     ` Florian Bezdeka
  1 sibling, 1 reply; 28+ messages in thread
From: Jan Kiszka @ 2023-07-06  7:14 UTC (permalink / raw)
  To: Florian Bezdeka, xenomai

On 05.07.23 08:38, Florian Bezdeka wrote:
> Introducing a new type sched_param_ex64. All members are (always) based
> on time64_t. All internal APIs have been migrated now. Existing compat
> and native system call entry points will do the necessary translation.
> 
> This is a preparation step for introducing time64_t based cobalt thread
> cobalt services.

One "cobalt" too much here, I would say.

Jan

-- 
Siemens AG, Technology
Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 06/12] y2038: cobalt/uapi: Align memory layout for time64 related types
  2023-07-05  6:38 ` [PATCH 06/12] y2038: cobalt/uapi: Align memory layout for time64 related types Florian Bezdeka
@ 2023-07-06  7:23   ` Jan Kiszka
  2023-07-06  7:50     ` Florian Bezdeka
  0 siblings, 1 reply; 28+ messages in thread
From: Jan Kiszka @ 2023-07-06  7:23 UTC (permalink / raw)
  To: Florian Bezdeka, xenomai

On 05.07.23 08:38, Florian Bezdeka wrote:
> When turning on time64 support the memory layout of
> struct sched_param_ex (used by userspace in any case) and the "shadow
> type" (struct sched_param_ex64, used by time64 related entry points)
> have to match.
> 
> Simplified example for different memory layout (offsets) of
> struct sched_param_ex:
> 
>                                            offset 32 bit   offset 64 bit
> struct sched_param_ex {
> 	int               sched_prio;           0                0
> 	struct timespec   __sched_ss_param;     4                8
> 	...
> };
> 
> With padding we get
> 
> struct sched_param_ex {
> 	int               sched_prio;           0                0
> 	struct timespec   __sched_ss_param;     8                8
> 	...
> };
> 
> This is a backward compatibility breaking change. Incrementing the
> Xenomai ABI revision on all supported architectures to express that.
> 
> Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
> ---
>  include/cobalt/kernel/compat.h                               | 4 ++++
>  include/cobalt/uapi/sched.h                                  | 4 ++++
>  kernel/cobalt/arch/arm/include/asm/xenomai/uapi/features.h   | 2 +-
>  kernel/cobalt/arch/arm64/include/asm/xenomai/uapi/features.h | 2 +-
>  kernel/cobalt/arch/x86/include/asm/xenomai/uapi/features.h   | 2 +-
>  kernel/cobalt/posix/thread.h                                 | 3 +++
>  6 files changed, 14 insertions(+), 3 deletions(-)
> 
> diff --git a/include/cobalt/kernel/compat.h b/include/cobalt/kernel/compat.h
> index f2dce74b4..71010e3a9 100644
> --- a/include/cobalt/kernel/compat.h
> +++ b/include/cobalt/kernel/compat.h
> @@ -30,9 +30,11 @@ struct sched_param_ex64;
>  
>  struct __compat_sched_ss_param {
>  	int __sched_low_priority;
> +	int: 32;
>  	struct old_timespec32 __sched_repl_period;
>  	struct old_timespec32 __sched_init_budget;
>  	int __sched_max_repl;
> +	int: 32;

Why not u32? And why not using that type for the other int fields as
well? Same below.

Jan

>  };
>  
>  struct __compat_sched_rr_param {
> @@ -41,6 +43,7 @@ struct __compat_sched_rr_param {
>  
>  struct compat_sched_param_ex {
>  	int sched_priority;
> +	int: 32;
>  	union {
>  		struct __compat_sched_ss_param ss;
>  		struct __compat_sched_rr_param rr;
> @@ -60,6 +63,7 @@ struct compat_sched_tp_window {
>  	struct old_timespec32 offset;
>  	struct old_timespec32 duration;
>  	int ptid;
> +	int: 32;
>  };
>  
>  struct __compat_sched_config_tp {
> diff --git a/include/cobalt/uapi/sched.h b/include/cobalt/uapi/sched.h
> index 730456d89..4081fbc0e 100644
> --- a/include/cobalt/uapi/sched.h
> +++ b/include/cobalt/uapi/sched.h
> @@ -39,9 +39,11 @@
>  
>  struct __sched_ss_param {
>  	int __sched_low_priority;
> +	int: 32;
>  	struct xntimespec __sched_repl_period;
>  	struct xntimespec __sched_init_budget;
>  	int __sched_max_repl;
> +	int: 32;
>  };
>  
>  #define sched_rr_quantum	sched_u.rr.__sched_rr_quantum
> @@ -63,6 +65,7 @@ struct sched_tp_window {
>  	struct xntimespec offset;
>  	struct xntimespec duration;
>  	int ptid;
> +	int: 32;
>  };
>  
>  enum {
> @@ -128,6 +131,7 @@ struct __sched_config_quota {
>  
>  struct sched_param_ex {
>  	int sched_priority;
> +	int: 32;
>  	union {
>  		struct __sched_ss_param ss;
>  		struct __sched_rr_param rr;
> diff --git a/kernel/cobalt/arch/arm/include/asm/xenomai/uapi/features.h b/kernel/cobalt/arch/arm/include/asm/xenomai/uapi/features.h
> index 43b7afb10..fdd5c0e32 100644
> --- a/kernel/cobalt/arch/arm/include/asm/xenomai/uapi/features.h
> +++ b/kernel/cobalt/arch/arm/include/asm/xenomai/uapi/features.h
> @@ -22,7 +22,7 @@
>  #define _COBALT_ARM_ASM_UAPI_FEATURES_H
>  
>  /* The ABI revision level we use on this arch. */
> -#define XENOMAI_ABI_REV   18UL
> +#define XENOMAI_ABI_REV   19UL
>  
>  #define XENOMAI_FEAT_DEP (__xn_feat_generic_mask)
>  
> diff --git a/kernel/cobalt/arch/arm64/include/asm/xenomai/uapi/features.h b/kernel/cobalt/arch/arm64/include/asm/xenomai/uapi/features.h
> index b98a96392..301797748 100644
> --- a/kernel/cobalt/arch/arm64/include/asm/xenomai/uapi/features.h
> +++ b/kernel/cobalt/arch/arm64/include/asm/xenomai/uapi/features.h
> @@ -22,7 +22,7 @@
>  #define _COBALT_ARM64_ASM_UAPI_FEATURES_H
>  
>  /* The ABI revision level we use on this arch. */
> -#define XENOMAI_ABI_REV   2UL
> +#define XENOMAI_ABI_REV   3UL
>  
>  #define XENOMAI_FEAT_DEP (__xn_feat_generic_mask)
>  
> diff --git a/kernel/cobalt/arch/x86/include/asm/xenomai/uapi/features.h b/kernel/cobalt/arch/x86/include/asm/xenomai/uapi/features.h
> index 65f8164a0..045adf0c1 100644
> --- a/kernel/cobalt/arch/x86/include/asm/xenomai/uapi/features.h
> +++ b/kernel/cobalt/arch/x86/include/asm/xenomai/uapi/features.h
> @@ -19,7 +19,7 @@
>  #define _COBALT_X86_ASM_UAPI_FEATURES_H
>  
>  /* The ABI revision level we use on this arch. */
> -#define XENOMAI_ABI_REV   18UL
> +#define XENOMAI_ABI_REV   19UL
>  
>  #define XENOMAI_FEAT_DEP  __xn_feat_generic_mask
>  
> diff --git a/kernel/cobalt/posix/thread.h b/kernel/cobalt/posix/thread.h
> index fb4306351..f663acde7 100644
> --- a/kernel/cobalt/posix/thread.h
> +++ b/kernel/cobalt/posix/thread.h
> @@ -114,9 +114,11 @@ struct cobalt_sigwait_context {
>  
>  struct __sched_ss_param64 {
>  	int __sched_low_priority;
> +	int: 32;
>  	struct __kernel_timespec __sched_repl_period;
>  	struct __kernel_timespec __sched_init_budget;
>  	int __sched_max_repl;
> +	int: 32;
>  };
>  
>  struct __sched_rr_param64 {
> @@ -125,6 +127,7 @@ struct __sched_rr_param64 {
>  
>  struct sched_param_ex64 {
>  	int sched_priority;
> +	int: 32;
>  	union {
>  		struct __sched_ss_param64 ss;
>  		struct __sched_rr_param64 rr;
> 

-- 
Siemens AG, Technology
Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 08/12] y2038: testsuite/smokey/y2038: Fix reporting of thread return status
  2023-07-05  6:38 ` [PATCH 08/12] y2038: testsuite/smokey/y2038: Fix reporting of thread return status Florian Bezdeka
@ 2023-07-06  7:27   ` Jan Kiszka
  0 siblings, 0 replies; 28+ messages in thread
From: Jan Kiszka @ 2023-07-06  7:27 UTC (permalink / raw)
  To: Florian Bezdeka, xenomai

On 05.07.23 08:38, Florian Bezdeka wrote:
> run_thread was not reporting back the thread exit status but the result
> of pthread_join, which is normally a success, even if the thread itself
> was not successful.
> 
> That revealed some wrong exit status checks inside the y2038 tests.
> 
> Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
> ---
>  testsuite/smokey/y2038/syscall-tests.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/testsuite/smokey/y2038/syscall-tests.c b/testsuite/smokey/y2038/syscall-tests.c
> index af27f2bce..d5ab2e8b1 100644
> --- a/testsuite/smokey/y2038/syscall-tests.c
> +++ b/testsuite/smokey/y2038/syscall-tests.c
> @@ -155,7 +155,7 @@ static int run_thread(void *(*thread)(void *), void *arg, int exp_result)
>  
>  	res = (long)status;
>  
> -	return (res == exp_result) ? 0 : ret;
> +	return (res == exp_result) ? 0 : res;
>  }
>  
>  static int test_sc_cobalt_sem_timedwait64(void)
> @@ -528,13 +528,13 @@ static int test_sc_cobalt_mutex_timedlock64(void)
>  		return ret;
>  
>  	/*
> -	 * mutex still locked, second thread has to fail with -EINVAL when
> +	 * mutex still locked, second thread has to fail with -EFAULT when
>  	 * submitting NULL as timeout
>  	 */
>  	ctx.sc_nr = sc_nr;
>  	ctx.mutex = &mutex;
>  	ctx.ts = NULL;
> -	if (!__T(ret, run_thread(timedlock64_thread, &ctx, -EINVAL)))
> +	if (!__T(ret, run_thread(timedlock64_thread, &ctx, -EFAULT)))
>  		return ret;
>  
>  	/*
> @@ -546,12 +546,12 @@ static int test_sc_cobalt_mutex_timedlock64(void)
>  		return ret;
>  
>  	/*
> -	 * mutex still locked, second thread has to fail with -EFAULT when
> +	 * mutex still locked, second thread has to fail with -EINVAL when
>  	 * submitting an invalid timeout (while the address is valid)
>  	 */
>  	ts64.tv_sec = -1;
>  	ctx.ts = &ts64;
> -	if (!__T(ret, run_thread(timedlock64_thread, &ctx, -EFAULT)))
> +	if (!__T(ret, run_thread(timedlock64_thread, &ctx, -EINVAL)))
>  		return ret;
>  
>  	/*
> 

Applying this to next as well already.

Thanks,
Jan

-- 
Siemens AG, Technology
Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 11/12] y2038: testsuite/smokey/y2038: Fix normalization of struct xn_timespec64
  2023-07-05  6:38 ` [PATCH 11/12] y2038: testsuite/smokey/y2038: Fix normalization of struct xn_timespec64 Florian Bezdeka
@ 2023-07-06  7:27   ` Jan Kiszka
  0 siblings, 0 replies; 28+ messages in thread
From: Jan Kiszka @ 2023-07-06  7:27 UTC (permalink / raw)
  To: Florian Bezdeka, xenomai

On 05.07.23 08:38, Florian Bezdeka wrote:
> We have to increment the seconds if the nanosecond field got too big.
> 
> Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
> ---
>  testsuite/smokey/y2038/syscall-tests.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/testsuite/smokey/y2038/syscall-tests.c b/testsuite/smokey/y2038/syscall-tests.c
> index 0ee0bc48c..0b908f3ac 100644
> --- a/testsuite/smokey/y2038/syscall-tests.c
> +++ b/testsuite/smokey/y2038/syscall-tests.c
> @@ -69,7 +69,7 @@ struct xn_timex64 {
>  static void ts_normalise(struct xn_timespec64 *ts)
>  {
>  	while (ts->tv_nsec >= NSEC_PER_SEC) {
> -		ts->tv_nsec += 1;
> +		ts->tv_sec += 1;
>  		ts->tv_nsec -= NSEC_PER_SEC;
>  	}
>  
> 

...and applying this.

Thanks,
Jan

-- 
Siemens AG, Technology
Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 12/12] testsuite/smokey: Fix unconditional unloads of the xeno_rtdmtest module
  2023-07-05  6:38 ` [PATCH 12/12] testsuite/smokey: Fix unconditional unloads of the xeno_rtdmtest module Florian Bezdeka
@ 2023-07-06  7:27   ` Jan Kiszka
  0 siblings, 0 replies; 28+ messages in thread
From: Jan Kiszka @ 2023-07-06  7:27 UTC (permalink / raw)
  To: Florian Bezdeka, xenomai

On 05.07.23 08:38, Florian Bezdeka wrote:
> The cpu-affinity and the rtdm test unloaded the xeno_rtdmtest module
> even if it was not loaded by the test upfront. In addition, such tests
> failed if the module was already loaded. That made partially re-running
> the testsuite after a failed run harder.
> 
> Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
> ---
>  testsuite/smokey/cpu-affinity/cpu-affinity.c | 13 +++++--------
>  testsuite/smokey/rtdm/rtdm.c                 |  7 ++++---
>  2 files changed, 9 insertions(+), 11 deletions(-)
> 
> diff --git a/testsuite/smokey/cpu-affinity/cpu-affinity.c b/testsuite/smokey/cpu-affinity/cpu-affinity.c
> index 4a59ff6f5..cbc877182 100644
> --- a/testsuite/smokey/cpu-affinity/cpu-affinity.c
> +++ b/testsuite/smokey/cpu-affinity/cpu-affinity.c
> @@ -73,10 +73,10 @@ out:
>  static int load_test_module(void)
>  {
>  	int fd, status;
> -	
> -	status = system("modprobe -q xeno_rtdmtest");
> -	if (status < 0 || WEXITSTATUS(status))
> -		return -ENOSYS;
> +
> +	status = smokey_modprobe("xeno_rtdmtest", true);
> +	if (status)
> +		return status;
>  
>  	/* Open the RTDM actor device. */
>  	fd = open("/dev/rtdm/rtdmx", O_RDWR);
> @@ -88,11 +88,8 @@ static int load_test_module(void)
>  
>  static void unload_test_module(int fd)
>  {
> -	int status;
> -	
>  	close(fd);
> -	status = system("rmmod xeno_rtdmtest");
> -	(void)status;
> +	smokey_rmmod("xeno_rtdmtest");
>  }
>  
>  static void *__run_cpu_affinity(void *arg)
> diff --git a/testsuite/smokey/rtdm/rtdm.c b/testsuite/smokey/rtdm/rtdm.c
> index 0b89228fc..6ad0d6d7a 100644
> --- a/testsuite/smokey/rtdm/rtdm.c
> +++ b/testsuite/smokey/rtdm/rtdm.c
> @@ -153,8 +153,8 @@ static int run_rtdm(struct smokey_test *t, int argc, char *const argv[])
>  {
>  	int dev, dev2, status;
>  
> -	status = system("modprobe -q xeno_rtdmtest");
> -	if (status < 0 || WEXITSTATUS(status))
> +	status = smokey_modprobe("xeno_rtdmtest", true);
> +	if (status)
>  		return -ENOSYS;
>  
>  	if (access(devname, 0) < 0 && errno == ENOENT)
> @@ -195,7 +195,8 @@ static int run_rtdm(struct smokey_test *t, int argc, char *const argv[])
>  	check("ioctl", ioctl(dev, RTTST_RTIOC_RTDM_DEFER_CLOSE,
>  			     RTTST_RTDM_DEFER_CLOSE_CONTEXT), 0);
>  	check("close", close(dev), 0);
> -	check("rmmod", system("rmmod xeno_rtdmtest"), 0);
> +
> +	smokey_rmmod("xeno_rtdmtest");
>  
>  	return 0;
>  }
> 

...and also applying this earlier.

Thanks,
Jan

-- 
Siemens AG, Technology
Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 01/12] y2038: cobalt: Introduce sched_param_ex64 and use it internally
  2023-07-06  7:13   ` Jan Kiszka
@ 2023-07-06  7:48     ` Florian Bezdeka
  0 siblings, 0 replies; 28+ messages in thread
From: Florian Bezdeka @ 2023-07-06  7:48 UTC (permalink / raw)
  To: Jan Kiszka, xenomai

On Thu, 2023-07-06 at 09:13 +0200, Jan Kiszka wrote:
> On 05.07.23 08:38, Florian Bezdeka wrote:
> > Introducing a new type sched_param_ex64. All members are (always) based
> > on time64_t. All internal APIs have been migrated now. Existing compat
> > and native system call entry points will do the necessary translation.
> > 
> > This is a preparation step for introducing time64_t based cobalt thread
> > cobalt services.
> > 
> > Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
> > ---
> >  include/cobalt/kernel/compat.h     |   5 +-
> >  kernel/cobalt/posix/clock.h        |  38 +++++++++--
> >  kernel/cobalt/posix/compat.c       |   5 +-
> >  kernel/cobalt/posix/sched.c        |  39 +++++++-----
> >  kernel/cobalt/posix/sched.h        |   8 +--
> >  kernel/cobalt/posix/syscall32.c    |  12 ++--
> >  kernel/cobalt/posix/thread.c       | 126 ++++++++++++++++++++++++++++++-------
> >  kernel/cobalt/posix/thread.h       |  39 ++++++++++--
> >  kernel/cobalt/trace/cobalt-posix.h |  20 +++---
> >  9 files changed, 219 insertions(+), 73 deletions(-)
> > 
> > diff --git a/include/cobalt/kernel/compat.h b/include/cobalt/kernel/compat.h
> > index 275735df5..f2dce74b4 100644
> > --- a/include/cobalt/kernel/compat.h
> > +++ b/include/cobalt/kernel/compat.h
> > @@ -26,6 +26,7 @@
> >  #include <cobalt/uapi/sched.h>
> >  
> >  struct mq_attr;
> > +struct sched_param_ex64;
> >  
> >  struct __compat_sched_ss_param {
> >  	int __sched_low_priority;
> > @@ -117,12 +118,12 @@ int sys32_put_fdset(compat_fd_set __user *cfds, const fd_set *fds,
> >  		    size_t fdsize);
> >  
> >  int sys32_get_param_ex(int policy,
> > -		       struct sched_param_ex *p,
> > +		       struct sched_param_ex64 *p,
> >  		       const struct compat_sched_param_ex __user *u_cp);
> >  
> >  int sys32_put_param_ex(int policy,
> >  		       struct compat_sched_param_ex __user *u_cp,
> > -		       const struct sched_param_ex *p);
> > +		       const struct sched_param_ex64 *p);
> >  
> >  int sys32_get_mqattr(struct mq_attr *ap,
> >  		     const struct compat_mq_attr __user *u_cap);
> > diff --git a/kernel/cobalt/posix/clock.h b/kernel/cobalt/posix/clock.h
> > index 38b59e24f..b0fc84396 100644
> > --- a/kernel/cobalt/posix/clock.h
> > +++ b/kernel/cobalt/posix/clock.h
> > @@ -18,6 +18,7 @@
> >  #ifndef _COBALT_POSIX_CLOCK_H
> >  #define _COBALT_POSIX_CLOCK_H
> >  
> > +#include <linux/compat.h>
> >  #include <linux/types.h>
> >  #include <linux/time.h>
> >  #include <linux/cpumask.h>
> > @@ -38,6 +39,14 @@ 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 void ns2kts(struct __kernel_timespec *kts, xnticks_t ticks)
> > +{
> > +	unsigned long nsecs;
> > +
> > +	kts->tv_sec = xnclock_divrem_billion(ticks, &nsecs);
> > +	kts->tv_nsec = (long long)nsecs;
> > +}
> > +
> >  static inline xnticks_t ts2ns(const struct timespec64 *ts)
> >  {
> >  	xnticks_t nsecs = ts->tv_nsec;
> > @@ -48,6 +57,23 @@ static inline xnticks_t ts2ns(const struct timespec64 *ts)
> >  	return nsecs;
> >  }
> >  
> > +static inline xnticks_t kts2ns(const struct __kernel_timespec *ts)
> > +{
> > +	xnticks_t nsecs = ts->tv_nsec;
> > +
> > +	/* zero out padding in compat mode */
> > +	if (in_compat_syscall())
> > +		nsecs &= 0xFFFFFFFFUL;
> > +
> > +	/* In 32-bit mode, this drops the padding */
> > +	nsecs = (long)nsecs;
> 
> These two look strange: nsecs > 1,000,000,000 (which already fits into
> 32-bits) is a bug, if ts came from userspace, an userspace bug. Why
> don't we need to catch that? When could the higher bits be undefined,
> and why don't we initialize them properly at the point ts is filled?

Here is the struct timespec definition from libc, so the userspace part
used by applications:

struct timespec
{
#ifdef __USE_TIME_BITS64
  __time64_t tv_sec;		/* Seconds.  */
#endif
#if __WORDSIZE == 64 \
  || (defined __SYSCALL_WORDSIZE && __SYSCALL_WORDSIZE == 64) \
  || (__TIMESIZE == 32 && !defined __USE_TIME_BITS64)
  __syscall_slong_t tv_nsec;	/* Nanoseconds.  */
#else
# if __BYTE_ORDER == __BIG_ENDIAN
  int: 32;           /* Padding.  */
  long int tv_nsec;  /* Nanoseconds.  */
# else
  long int tv_nsec;  /* Nanoseconds.  */
  int: 32;           /* Padding.  */
# endif
#endif
};

The tv_nsec field of compat applications (and native 32bit
applications) is still 32 bit and some padding is used to fill it up to
64 bit - in order to match struct __kernel_timespec on kernel side.

IOW: For compat (or native 32 bit applications) the upper bits will be
undefined.

An other option of doing this "auto correction" is converting to struct
timespec64, which we do on some other places as well. But that would
require us to read each struct __kernel_timespec on it's own. So no
single cobalt_copy_from_user() but several cobalt_get_timespec64()
calls instead. I considered that to be more efficient.

Does that make sense now? Any leftovers?

Florian

> 
> Jan
> 
> -- 
> Siemens AG, Technology
> Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 01/12] y2038: cobalt: Introduce sched_param_ex64 and use it internally
  2023-07-06  7:14   ` Jan Kiszka
@ 2023-07-06  7:48     ` Florian Bezdeka
  0 siblings, 0 replies; 28+ messages in thread
From: Florian Bezdeka @ 2023-07-06  7:48 UTC (permalink / raw)
  To: Jan Kiszka, xenomai

On Thu, 2023-07-06 at 09:14 +0200, Jan Kiszka wrote:
> On 05.07.23 08:38, Florian Bezdeka wrote:
> > Introducing a new type sched_param_ex64. All members are (always) based
> > on time64_t. All internal APIs have been migrated now. Existing compat
> > and native system call entry points will do the necessary translation.
> > 
> > This is a preparation step for introducing time64_t based cobalt thread
> > cobalt services.
> 
> One "cobalt" too much here, I would say.

Grml. Yes! Something for v2.

> 
> Jan
> 
> -- 
> Siemens AG, Technology
> Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 06/12] y2038: cobalt/uapi: Align memory layout for time64 related types
  2023-07-06  7:23   ` Jan Kiszka
@ 2023-07-06  7:50     ` Florian Bezdeka
  2023-07-07 11:37       ` Jan Kiszka
  0 siblings, 1 reply; 28+ messages in thread
From: Florian Bezdeka @ 2023-07-06  7:50 UTC (permalink / raw)
  To: Jan Kiszka, xenomai

On Thu, 2023-07-06 at 09:23 +0200, Jan Kiszka wrote:
> On 05.07.23 08:38, Florian Bezdeka wrote:
> > When turning on time64 support the memory layout of
> > struct sched_param_ex (used by userspace in any case) and the "shadow
> > type" (struct sched_param_ex64, used by time64 related entry points)
> > have to match.
> > 
> > Simplified example for different memory layout (offsets) of
> > struct sched_param_ex:
> > 
> >                                            offset 32 bit   offset 64 bit
> > struct sched_param_ex {
> > 	int               sched_prio;           0                0
> > 	struct timespec   __sched_ss_param;     4                8
> > 	...
> > };
> > 
> > With padding we get
> > 
> > struct sched_param_ex {
> > 	int               sched_prio;           0                0
> > 	struct timespec   __sched_ss_param;     8                8
> > 	...
> > };
> > 
> > This is a backward compatibility breaking change. Incrementing the
> > Xenomai ABI revision on all supported architectures to express that.
> > 
> > Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
> > ---
> >  include/cobalt/kernel/compat.h                               | 4 ++++
> >  include/cobalt/uapi/sched.h                                  | 4 ++++
> >  kernel/cobalt/arch/arm/include/asm/xenomai/uapi/features.h   | 2 +-
> >  kernel/cobalt/arch/arm64/include/asm/xenomai/uapi/features.h | 2 +-
> >  kernel/cobalt/arch/x86/include/asm/xenomai/uapi/features.h   | 2 +-
> >  kernel/cobalt/posix/thread.h                                 | 3 +++
> >  6 files changed, 14 insertions(+), 3 deletions(-)
> > 
> > diff --git a/include/cobalt/kernel/compat.h b/include/cobalt/kernel/compat.h
> > index f2dce74b4..71010e3a9 100644
> > --- a/include/cobalt/kernel/compat.h
> > +++ b/include/cobalt/kernel/compat.h
> > @@ -30,9 +30,11 @@ struct sched_param_ex64;
> >  
> >  struct __compat_sched_ss_param {
> >  	int __sched_low_priority;
> > +	int: 32;
> >  	struct old_timespec32 __sched_repl_period;
> >  	struct old_timespec32 __sched_init_budget;
> >  	int __sched_max_repl;
> > +	int: 32;
> 
> Why not u32? And why not using that type for the other int fields as
> well? Same below.

I just followed the glibc way of defining such paddings. Is there any
significant difference?

> 
> Jan
> 
> >  };
> >  
> >  struct __compat_sched_rr_param {
> > @@ -41,6 +43,7 @@ struct __compat_sched_rr_param {
> >  
> >  struct compat_sched_param_ex {
> >  	int sched_priority;
> > +	int: 32;
> >  	union {
> >  		struct __compat_sched_ss_param ss;
> >  		struct __compat_sched_rr_param rr;
> > @@ -60,6 +63,7 @@ struct compat_sched_tp_window {
> >  	struct old_timespec32 offset;
> >  	struct old_timespec32 duration;
> >  	int ptid;
> > +	int: 32;
> >  };
> >  
> >  struct __compat_sched_config_tp {
> > diff --git a/include/cobalt/uapi/sched.h b/include/cobalt/uapi/sched.h
> > index 730456d89..4081fbc0e 100644
> > --- a/include/cobalt/uapi/sched.h
> > +++ b/include/cobalt/uapi/sched.h
> > @@ -39,9 +39,11 @@
> >  
> >  struct __sched_ss_param {
> >  	int __sched_low_priority;
> > +	int: 32;
> >  	struct xntimespec __sched_repl_period;
> >  	struct xntimespec __sched_init_budget;
> >  	int __sched_max_repl;
> > +	int: 32;
> >  };
> >  
> >  #define sched_rr_quantum	sched_u.rr.__sched_rr_quantum
> > @@ -63,6 +65,7 @@ struct sched_tp_window {
> >  	struct xntimespec offset;
> >  	struct xntimespec duration;
> >  	int ptid;
> > +	int: 32;
> >  };
> >  
> >  enum {
> > @@ -128,6 +131,7 @@ struct __sched_config_quota {
> >  
> >  struct sched_param_ex {
> >  	int sched_priority;
> > +	int: 32;
> >  	union {
> >  		struct __sched_ss_param ss;
> >  		struct __sched_rr_param rr;
> > diff --git a/kernel/cobalt/arch/arm/include/asm/xenomai/uapi/features.h b/kernel/cobalt/arch/arm/include/asm/xenomai/uapi/features.h
> > index 43b7afb10..fdd5c0e32 100644
> > --- a/kernel/cobalt/arch/arm/include/asm/xenomai/uapi/features.h
> > +++ b/kernel/cobalt/arch/arm/include/asm/xenomai/uapi/features.h
> > @@ -22,7 +22,7 @@
> >  #define _COBALT_ARM_ASM_UAPI_FEATURES_H
> >  
> >  /* The ABI revision level we use on this arch. */
> > -#define XENOMAI_ABI_REV   18UL
> > +#define XENOMAI_ABI_REV   19UL
> >  
> >  #define XENOMAI_FEAT_DEP (__xn_feat_generic_mask)
> >  
> > diff --git a/kernel/cobalt/arch/arm64/include/asm/xenomai/uapi/features.h b/kernel/cobalt/arch/arm64/include/asm/xenomai/uapi/features.h
> > index b98a96392..301797748 100644
> > --- a/kernel/cobalt/arch/arm64/include/asm/xenomai/uapi/features.h
> > +++ b/kernel/cobalt/arch/arm64/include/asm/xenomai/uapi/features.h
> > @@ -22,7 +22,7 @@
> >  #define _COBALT_ARM64_ASM_UAPI_FEATURES_H
> >  
> >  /* The ABI revision level we use on this arch. */
> > -#define XENOMAI_ABI_REV   2UL
> > +#define XENOMAI_ABI_REV   3UL
> >  
> >  #define XENOMAI_FEAT_DEP (__xn_feat_generic_mask)
> >  
> > diff --git a/kernel/cobalt/arch/x86/include/asm/xenomai/uapi/features.h b/kernel/cobalt/arch/x86/include/asm/xenomai/uapi/features.h
> > index 65f8164a0..045adf0c1 100644
> > --- a/kernel/cobalt/arch/x86/include/asm/xenomai/uapi/features.h
> > +++ b/kernel/cobalt/arch/x86/include/asm/xenomai/uapi/features.h
> > @@ -19,7 +19,7 @@
> >  #define _COBALT_X86_ASM_UAPI_FEATURES_H
> >  
> >  /* The ABI revision level we use on this arch. */
> > -#define XENOMAI_ABI_REV   18UL
> > +#define XENOMAI_ABI_REV   19UL
> >  
> >  #define XENOMAI_FEAT_DEP  __xn_feat_generic_mask
> >  
> > diff --git a/kernel/cobalt/posix/thread.h b/kernel/cobalt/posix/thread.h
> > index fb4306351..f663acde7 100644
> > --- a/kernel/cobalt/posix/thread.h
> > +++ b/kernel/cobalt/posix/thread.h
> > @@ -114,9 +114,11 @@ struct cobalt_sigwait_context {
> >  
> >  struct __sched_ss_param64 {
> >  	int __sched_low_priority;
> > +	int: 32;
> >  	struct __kernel_timespec __sched_repl_period;
> >  	struct __kernel_timespec __sched_init_budget;
> >  	int __sched_max_repl;
> > +	int: 32;
> >  };
> >  
> >  struct __sched_rr_param64 {
> > @@ -125,6 +127,7 @@ struct __sched_rr_param64 {
> >  
> >  struct sched_param_ex64 {
> >  	int sched_priority;
> > +	int: 32;
> >  	union {
> >  		struct __sched_ss_param64 ss;
> >  		struct __sched_rr_param64 rr;
> > 
> 
> -- 
> Siemens AG, Technology
> Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 06/12] y2038: cobalt/uapi: Align memory layout for time64 related types
  2023-07-06  7:50     ` Florian Bezdeka
@ 2023-07-07 11:37       ` Jan Kiszka
  2023-07-10  7:29         ` Florian Bezdeka
  0 siblings, 1 reply; 28+ messages in thread
From: Jan Kiszka @ 2023-07-07 11:37 UTC (permalink / raw)
  To: Florian Bezdeka, xenomai

On 06.07.23 09:50, Florian Bezdeka wrote:
> On Thu, 2023-07-06 at 09:23 +0200, Jan Kiszka wrote:
>> On 05.07.23 08:38, Florian Bezdeka wrote:
>>> When turning on time64 support the memory layout of
>>> struct sched_param_ex (used by userspace in any case) and the "shadow
>>> type" (struct sched_param_ex64, used by time64 related entry points)
>>> have to match.
>>>
>>> Simplified example for different memory layout (offsets) of
>>> struct sched_param_ex:
>>>
>>>                                            offset 32 bit   offset 64 bit
>>> struct sched_param_ex {
>>> 	int               sched_prio;           0                0
>>> 	struct timespec   __sched_ss_param;     4                8
>>> 	...
>>> };
>>>
>>> With padding we get
>>>
>>> struct sched_param_ex {
>>> 	int               sched_prio;           0                0
>>> 	struct timespec   __sched_ss_param;     8                8
>>> 	...
>>> };
>>>
>>> This is a backward compatibility breaking change. Incrementing the
>>> Xenomai ABI revision on all supported architectures to express that.
>>>
>>> Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
>>> ---
>>>  include/cobalt/kernel/compat.h                               | 4 ++++
>>>  include/cobalt/uapi/sched.h                                  | 4 ++++
>>>  kernel/cobalt/arch/arm/include/asm/xenomai/uapi/features.h   | 2 +-
>>>  kernel/cobalt/arch/arm64/include/asm/xenomai/uapi/features.h | 2 +-
>>>  kernel/cobalt/arch/x86/include/asm/xenomai/uapi/features.h   | 2 +-
>>>  kernel/cobalt/posix/thread.h                                 | 3 +++
>>>  6 files changed, 14 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/include/cobalt/kernel/compat.h b/include/cobalt/kernel/compat.h
>>> index f2dce74b4..71010e3a9 100644
>>> --- a/include/cobalt/kernel/compat.h
>>> +++ b/include/cobalt/kernel/compat.h
>>> @@ -30,9 +30,11 @@ struct sched_param_ex64;
>>>  
>>>  struct __compat_sched_ss_param {
>>>  	int __sched_low_priority;
>>> +	int: 32;
>>>  	struct old_timespec32 __sched_repl_period;
>>>  	struct old_timespec32 __sched_init_budget;
>>>  	int __sched_max_repl;
>>> +	int: 32;
>>
>> Why not u32? And why not using that type for the other int fields as
>> well? Same below.
> 
> I just followed the glibc way of defining such paddings. Is there any
> significant difference?
> 

OK, if they do it this way...

But I was also wondering, as we are breaking ABIs here, if we shouldn't
use types of static width for all the touched structures.

Jan

-- 
Siemens AG, Technology
Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 06/12] y2038: cobalt/uapi: Align memory layout for time64 related types
  2023-07-07 11:37       ` Jan Kiszka
@ 2023-07-10  7:29         ` Florian Bezdeka
  0 siblings, 0 replies; 28+ messages in thread
From: Florian Bezdeka @ 2023-07-10  7:29 UTC (permalink / raw)
  To: Jan Kiszka, xenomai

On Fri, 2023-07-07 at 13:37 +0200, Jan Kiszka wrote:
> On 06.07.23 09:50, Florian Bezdeka wrote:
> > On Thu, 2023-07-06 at 09:23 +0200, Jan Kiszka wrote:
> > > On 05.07.23 08:38, Florian Bezdeka wrote:
> > > > When turning on time64 support the memory layout of
> > > > struct sched_param_ex (used by userspace in any case) and the "shadow
> > > > type" (struct sched_param_ex64, used by time64 related entry points)
> > > > have to match.
> > > > 
> > > > Simplified example for different memory layout (offsets) of
> > > > struct sched_param_ex:
> > > > 
> > > >                                            offset 32 bit   offset 64 bit
> > > > struct sched_param_ex {
> > > > 	int               sched_prio;           0                0
> > > > 	struct timespec   __sched_ss_param;     4                8
> > > > 	...
> > > > };
> > > > 
> > > > With padding we get
> > > > 
> > > > struct sched_param_ex {
> > > > 	int               sched_prio;           0                0
> > > > 	struct timespec   __sched_ss_param;     8                8
> > > > 	...
> > > > };
> > > > 
> > > > This is a backward compatibility breaking change. Incrementing the
> > > > Xenomai ABI revision on all supported architectures to express that.
> > > > 
> > > > Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
> > > > ---
> > > >  include/cobalt/kernel/compat.h                               | 4 ++++
> > > >  include/cobalt/uapi/sched.h                                  | 4 ++++
> > > >  kernel/cobalt/arch/arm/include/asm/xenomai/uapi/features.h   | 2 +-
> > > >  kernel/cobalt/arch/arm64/include/asm/xenomai/uapi/features.h | 2 +-
> > > >  kernel/cobalt/arch/x86/include/asm/xenomai/uapi/features.h   | 2 +-
> > > >  kernel/cobalt/posix/thread.h                                 | 3 +++
> > > >  6 files changed, 14 insertions(+), 3 deletions(-)
> > > > 
> > > > diff --git a/include/cobalt/kernel/compat.h b/include/cobalt/kernel/compat.h
> > > > index f2dce74b4..71010e3a9 100644
> > > > --- a/include/cobalt/kernel/compat.h
> > > > +++ b/include/cobalt/kernel/compat.h
> > > > @@ -30,9 +30,11 @@ struct sched_param_ex64;
> > > >  
> > > >  struct __compat_sched_ss_param {
> > > >  	int __sched_low_priority;
> > > > +	int: 32;
> > > >  	struct old_timespec32 __sched_repl_period;
> > > >  	struct old_timespec32 __sched_init_budget;
> > > >  	int __sched_max_repl;
> > > > +	int: 32;
> > > 
> > > Why not u32? And why not using that type for the other int fields as
> > > well? Same below.
> > 
> > I just followed the glibc way of defining such paddings. Is there any
> > significant difference?
> > 
> 
> OK, if they do it this way...
> 
> But I was also wondering, as we are breaking ABIs here, if we shouldn't
> use types of static width for all the touched structures.

I was asking me the same... That would have saved a lot of compat
specific handling right from the beginning. My feeling was that for
some reason struct timespec was preferred / chosen to be the way to go.

Is there a POSIX like API that we tried to follow as close as possible?

> 
> Jan
> 
> -- 
> Siemens AG, Technology
> Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2023-07-10  7:29 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-05  6:38 [PATCH 00/12] y2038: Add time64_t support to scheduler and thread APIs Florian Bezdeka
2023-07-05  6:38 ` [PATCH 01/12] y2038: cobalt: Introduce sched_param_ex64 and use it internally Florian Bezdeka
2023-07-06  7:13   ` Jan Kiszka
2023-07-06  7:48     ` Florian Bezdeka
2023-07-06  7:14   ` Jan Kiszka
2023-07-06  7:48     ` Florian Bezdeka
2023-07-05  6:38 ` [PATCH 02/12] y2038: cobalt: Introduce sched_config64 " Florian Bezdeka
2023-07-05  6:38 ` [PATCH 03/12] y2038: cobalt/posix/{sched,thread}: Add time64_t based syscalls Florian Bezdeka
2023-07-05  6:38 ` [PATCH 04/12] y2038: lib/cobalt/{sched,thread}: Dispatch time64_t related services Florian Bezdeka
2023-07-05  6:38 ` [PATCH 05/12] y2038: cobalt/uapi: Introduce xntimespec for struct sched_param_ex API Florian Bezdeka
2023-07-05  6:38 ` [PATCH 06/12] y2038: cobalt/uapi: Align memory layout for time64 related types Florian Bezdeka
2023-07-06  7:23   ` Jan Kiszka
2023-07-06  7:50     ` Florian Bezdeka
2023-07-07 11:37       ` Jan Kiszka
2023-07-10  7:29         ` Florian Bezdeka
2023-07-05  6:38 ` [PATCH 07/12] y2038: cobalt/uapi: Remove __user_old_{timespec,itimerspec,timeval,timex} Florian Bezdeka
2023-07-05  6:38 ` [PATCH 08/12] y2038: testsuite/smokey/y2038: Fix reporting of thread return status Florian Bezdeka
2023-07-06  7:27   ` Jan Kiszka
2023-07-05  6:38 ` [PATCH 09/12] y2038: testsuite/smokey/y2038: Add tests for sched_param_ex related syscalls Florian Bezdeka
2023-07-05  6:38 ` [PATCH 10/12] y2038: testsuite/smokey/y2038: Fix a race in the pselect interruption test Florian Bezdeka
2023-07-05  7:15   ` Jan Kiszka
2023-07-05  6:38 ` [PATCH 11/12] y2038: testsuite/smokey/y2038: Fix normalization of struct xn_timespec64 Florian Bezdeka
2023-07-06  7:27   ` Jan Kiszka
2023-07-05  6:38 ` [PATCH 12/12] testsuite/smokey: Fix unconditional unloads of the xeno_rtdmtest module Florian Bezdeka
2023-07-06  7:27   ` Jan Kiszka
2023-07-05  6:54 ` [PATCH 00/12] y2038: Add time64_t support to scheduler and thread APIs Jan Kiszka
2023-07-05  7:05   ` Bezdeka, Florian
2023-07-05  7:14     ` Jan Kiszka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).