Skip to contentSkip to conversation

y2038: Allow building and running somkey with y2038 support enabled

PATCH In review Florian Bezdeka 2 participants 45 messages Aug 9, 2022 – Aug 17, 2022

lore
Share & tools
lore
#0 lore raw

cover y2038: Allow building and running somkey with y2038 support enabled

Hi all,

it has been a while... I made some progress regarding y2038 support in Xenomai:

With that series applied I'm able to build and run Xenomai including smokey testsuite without any test failures or skipped tests with y2038 support enabled!

Preconditions:
--------------
- glibc: You're glibc has to provide y2038 support. glibc >= 2.34 has that.

- Xenomai: There is a new --enable-y2038 option to enable y2038 support. This option is off per default to keep things disabled for now and avoid breaking any existing application.

When --enable-y2038 is supplied all userspace parts (libcobalt, smokey, ...) will be compiled with y2038 support if glibc supports that. If there is no support in glibc the option will be ignored.

Structure of this series:
-------------------------
We start with some cleanups and drive-by fixes followed by adding the missing timer and timerfd support. Finally it cares about select() and some drivers (ioctls) that were missing compat and/or y2038 support.

Patches 1-12: Cleanup some compat code. As long as there is no
difference between the compat and native syscall entry we do not have to declare them again. The syscall machinery will care about that by placing the native entry point at the compat offset into the syscall table again.

Patches 15-17: Add gcc 12 support, drive by fixes

Patches 18-34: Add y2038 support to timer and timerfd APIs.

Patches 34-37: Add y2038 support to select()
There is no y2038 safe select() out there. Modern applications should switch to modern APIs like pselect().

Implementing pselect() was not easy:
- We have no support for waiting for signals and fds at the same time inside the xnsynch infrastructure
- We already reached the maximum number of syscall parameters
Solution taken: Implement pselect64() without the sigmask parameter. We do not wrap pselect() in userspace and only use it for select() where the sigmask would be NULL anyhow. So no additional pselect() in our API but select() is now y2038 safe.

Patch 38: Switch VDSO to __vdso_clock_gettime64 in case y2038
support was requested.

Patches 39-41: Enable/Fix compat support for drivers covered by the
smokey testsuite.

Patch 42: Add/Enable all additional glibc wrappers necessary for
building with y2038 support enabled.

Testing:
--------
I used Xenomai images for testing but had to switch the distribution from Debian to Ubuntu. There is no Debian version yet that ships an adequate glibc version.

Switching the distribution was not that easy. Ubuntu packages are now compressed using xz which is not yet supported by the Debian package manager. You have to prepare your host environment (kas, kas-container) accordingly.

As Ubuntu ships a newer python version some ISAR patching was necessary as well. If someone is interested in such changes: Let me know.

Open topics:
------------
- Testing: Integration of compat tests to CI (not really a y2038 topic) See https://gitlab.com/Xenomai/xenomai-hacker-space/-/issues/21

- Testing: Once compat tests are enabled, try to enable y2038 support

- TCP: The rt_tcp driver does not have compat support yet and is not
covered by the smokey testsuite

- y2038: Re-visit some y2038 related syscalls like
- sc_cobalt_thread_setschedparam_ex
- sc_cobalt_thread_getschedparam_ex
There is a struct timespec deeply nested in the API. Seems not covered by smokey.

If someone is interested in helping in those topics: Let us/me know!

With that: Happy reviewing!

The xenomai CI was regularly triggered. I do not expect any build or testing issues.

Best regards,
Florian

Florian Bezdeka (42):
y2038: cobalt: posix/sem: Remove compat syscall for sem_timedwait64
y2038: cobalt: posix/clock: Remove compat syscall for clock_gettime64
y2038: cobalt: posix/clock: Remove compat syscall for clock_settime64
y2038: cobalt: posix/clock: Remove compat syscall for
clock_nanosleep64
y2038: cobalt: posix/clock: Remove compat syscall for clock_getres64
y2038: cobalt: posix/clock: Remove compat syscall for clock_adjtime64
y2038: cobalt: posix/mutex: Remove compat syscall for
mutex_timedlock64
y2038: cobalt: posix/mqueue: Remove compat syscall for mq_timedsend64
y2038: cobalt: posix/monitor: Remove compat syscall for monitor_wait64
y2038: cobalt: posix/event: Remove compat syscall for event_wait64
y2038: cobalt: posix/cond: Remove compat syscall for
cond_wait_prologue64
y2038: cobalt: Cleanup code style of time.{c,h}
y2038: posix/mq: Fix mq_timedsend syscall routing lib/cobalt: Fix possible fd leak in __map_umm testsuite/smokey/sched-quota: Allow building with gcc 12
y2038: posix/mq: Harmonize mq_receive and mq_timedreceive
y2038: testsuite/smokey/y2038: Fix a very unlikely resource leak
y2038: cobalt/posix/clock: Use timespec64_valid() for validation
y2038: Prepare code base for 64bit time_t
y2038: build: Introduce new build parameter --enable-y2038
y2038: cobalt: Introduce some itimerspec64 related helpers
y2038: cobalt/posix/timer: Adding timer_settime64
y2038: lib/cobalt: Dispatch timer_settime
y2038: testsuite/smokey/y2038: Adding tests for timer_settime
y2038: cobalt/posix/timer: Adding timer_gettime64
y2038: lib/cobalt: Dispatch timer_gettime
y2038: testsuite/smokey/y2038: Adding tests for timer_gettime
y2038: cobalt/posix/timerfd: Adding timerfd_settime64
y2038: lib/cobalt: Dispatch timerfd_settime
y2038: testsuite/smokey/y2038: Adding tests for timerfd_settime
y2038: cobalt/posix/timerfd: Adding timerfd_gettime64
y2038: lib/cobalt: Dispatch timerfd_gettime
y2038: testsuite/smokey/y2038: Adding tests for timerfd_gettime
y2038: cobalt/posix/select: Refactor __cobalt_select()
y2038: cobalt/posix/select: Adding pselect64
y2038: testsuite/smokey/y2038: Adding tests for pselect64
y2038: kernel/drivers: Implement SO_RCVTIMEO_NEW and SO_SNDTIMEO_NEW
y2038: lib/cobalt: Switch vdso to gettime64
rtnet: Enable compat ioctl interface
drivers/rtcan: Implement compat support for the rtcan driver drivers/net/stack/ipv4/udp/udp.c: Add compat support
y2038: lib/cobalt: Add additional time64_t related function wrappers

 configure.ac                                  |  64 +++-
 demo/alchemy/altency.c                        |  26 +-
 include/cobalt/kernel/rtdm/fd.h               |  16 +
 include/cobalt/kernel/time.h                  |  23 +-
 include/cobalt/uapi/syscall.h                 |   5 +
 .../include/asm-generic/xenomai/syscall.h     |  22 ++
 kernel/cobalt/posix/clock.c                   |  59 +---
 kernel/cobalt/posix/clock.h                   |  22 +-
 kernel/cobalt/posix/cond.c                    |  12 +-
 kernel/cobalt/posix/cond.h                    |   5 -
 kernel/cobalt/posix/event.c                   |  26 +-
 kernel/cobalt/posix/event.h                   |   5 -
 kernel/cobalt/posix/io.c                      |  94 +++--
 kernel/cobalt/posix/io.h                      |   8 +-
 kernel/cobalt/posix/monitor.c                 |  26 +-
 kernel/cobalt/posix/monitor.h                 |   5 -
 kernel/cobalt/posix/mqueue.c                  |  10 +-
 kernel/cobalt/posix/mqueue.h                  |   3 -
 kernel/cobalt/posix/mutex.c                   |  10 +-
 kernel/cobalt/posix/mutex.h                   |   3 -
 kernel/cobalt/posix/sem.c                     |  20 +-
 kernel/cobalt/posix/sem.h                     |   3 -
 kernel/cobalt/posix/syscall32.c               | 110 ++----
 kernel/cobalt/posix/syscall32.h               |  55 ---
 kernel/cobalt/posix/timer.c                   |  45 ++-
 kernel/cobalt/posix/timer.h                   |   8 +
 kernel/cobalt/posix/timerfd.c                 |  40 ++-
 kernel/cobalt/posix/timerfd.h                 |   8 +
 kernel/cobalt/rtdm/drvlib.c                   |  17 +-
 kernel/cobalt/rtdm/fd.c                       | 122 +++++++
 kernel/cobalt/time.c                          |  42 ++-
 kernel/cobalt/trace/cobalt-posix.h            |   7 +-
 kernel/drivers/can/rtcan_raw.c                |  42 +--
 kernel/drivers/ipc/bufp.c                     |  34 ++
 kernel/drivers/ipc/iddp.c                     |  34 ++
 kernel/drivers/ipc/internal.h                 |  27 ++
 kernel/drivers/ipc/rtipc.c                    |  29 ++
 kernel/drivers/ipc/xddp.c                     |  18 +
 kernel/drivers/net/stack/ipv4/tcp/tcp.c       |  31 ++
 kernel/drivers/net/stack/ipv4/udp/udp.c       |  29 +-
 kernel/drivers/net/stack/rtnet_chrdev.c       |   1 +
 lib/cobalt/Makefile.am                        |   7 +
 .../arch/x86/include/asm/xenomai/time.h       |   5 +
 lib/cobalt/cobalt-y2038-glibc.wrappers        |  20 ++
 lib/cobalt/mq.c                               |  47 ++-
 lib/cobalt/timer.c                            |  17 +-
 lib/cobalt/timerfd.c                          |  27 +-
 lib/cobalt/umm.c                              |   1 +
 lib/cobalt/wrappers_y2038.c                   | 187 ++++++++++
 scripts/xeno-config-cobalt.in                 |   5 +
 testsuite/latency/latency.c                   |  34 +-
 testsuite/smokey/sched-quota/sched-quota.c    |   4 +-
 testsuite/smokey/y2038/syscall-tests.c        | 324 +++++++++++++++++-
 testsuite/spitest/spitest.c                   |   6 +-
 54 files changed, 1384 insertions(+), 466 deletions(-)
 create mode 100644 lib/cobalt/cobalt-y2038-glibc.wrappers
 create mode 100644 lib/cobalt/wrappers_y2038.c
Signature · 1 line
2.37.1
#1 lore raw

PATCH 1/42 y2038: cobalt: posix/sem: Remove compat syscall for sem_timedwait64

There is no difference between the native and the compat entry point, so let's keep it simple. The native entrypoint is already linked into the syscall table at the right offset.

---
 kernel/cobalt/posix/sem.c       | 20 +++++++-------------
 kernel/cobalt/posix/sem.h       |  3 ---
 kernel/cobalt/posix/syscall32.c |  7 -------
 kernel/cobalt/posix/syscall32.h |  4 ----
 4 files changed, 7 insertions(+), 27 deletions(-)
kernel/cobalt/posix/sem.c +7 -13
index 71b8c52f5..869260924 100644
@@ -360,18 +360,6 @@ int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem,
 	return ret;
 }
 
-int __cobalt_sem_timedwait64(struct cobalt_sem_shadow __user *u_sem,
-			     const struct __kernel_timespec __user *u_ts)
-{
-	int ret = 1;
-	struct timespec64 ts64;
-
-	if (u_ts)
-		ret = cobalt_get_timespec64(&ts64, u_ts);
-
-	return __cobalt_sem_timedwait(u_sem, ret ? NULL : &ts64);
-}
-
 static int sem_post(xnhandle_t handle)
 {
 	struct cobalt_sem *sem;
@@ -485,7 +473,13 @@ COBALT_SYSCALL(sem_timedwait64, primary,
 	       (struct cobalt_sem_shadow __user *u_sem,
 		const struct __kernel_timespec __user *u_ts))
 {
-	return __cobalt_sem_timedwait64(u_sem, u_ts);
+	int ret = 1;
+	struct timespec64 ts64;
+
+	if (u_ts)
+		ret = cobalt_get_timespec64(&ts64, u_ts);
+
+	return __cobalt_sem_timedwait(u_sem, ret ? NULL : &ts64);
 }
 
 COBALT_SYSCALL(sem_trywait, primary,
kernel/cobalt/posix/sem.h +0 -3
index d7dbb9098..e1e4d68f0 100644
@@ -66,9 +66,6 @@ __cobalt_sem_open(struct cobalt_sem_shadow __user *usm,
 int __cobalt_sem_timedwait(struct cobalt_sem_shadow __user *u_sem,
 			   const struct timespec64 *ts);
 
-int __cobalt_sem_timedwait64(struct cobalt_sem_shadow __user *u_sem,
-			     const struct __kernel_timespec __user *u_ts);
-
 int __cobalt_sem_destroy(xnhandle_t handle);
 
 void cobalt_nsem_reclaim(struct cobalt_process *process);
kernel/cobalt/posix/syscall32.c +0 -7
index b65a0a760..2b4911c59 100644
@@ -137,13 +137,6 @@ COBALT_SYSCALL32emu(sem_timedwait, primary,
 	return __cobalt_sem_timedwait(u_sem, ret ? NULL : &ts64);
 }
 
-COBALT_SYSCALL32emu(sem_timedwait64, primary,
-		    (struct cobalt_sem_shadow __user *u_sem,
-		     const struct __kernel_timespec __user *u_ts))
-{
-	return __cobalt_sem_timedwait64(u_sem, u_ts);
-}
-
 COBALT_SYSCALL32emu(clock_getres, current,
 		    (clockid_t clock_id,
 		     struct old_timespec32 __user *u_ts))
kernel/cobalt/posix/syscall32.h +0 -4
index 55f08121c..f36fff272 100644
@@ -293,8 +293,4 @@ COBALT_SYSCALL32emu_DECL(sem_timedwait,
 			 (struct cobalt_sem_shadow __user *u_sem,
 			  const struct old_timespec32 __user *u_ts));
 
-COBALT_SYSCALL32emu_DECL(sem_timedwait64,
-			 (struct cobalt_sem_shadow __user *u_sem,
-			  const struct __kernel_timespec __user *u_ts));
-
 #endif /* !_COBALT_POSIX_SYSCALL32_H */
Signature · 1 line
2.37.1
#2 lore raw

PATCH 2/42 y2038: cobalt: posix/clock: Remove compat syscall for clock_gettime64

In reply to Florian Bezdeka

There is no difference between the native and the compat entry point, so let's keep it simple. The native entrypoint is already linked into the syscall table at the right offset.

---
 kernel/cobalt/posix/clock.c     | 10 ++--------
 kernel/cobalt/posix/clock.h     |  3 ---
 kernel/cobalt/posix/syscall32.c |  7 -------
 kernel/cobalt/posix/syscall32.h |  4 ----
 4 files changed, 2 insertions(+), 22 deletions(-)
kernel/cobalt/posix/clock.c +2 -8
index 16cc8b20a..bd393bb11 100644
@@ -162,8 +162,8 @@ COBALT_SYSCALL(clock_gettime, current,
 	return 0;
 }
 
-int __cobalt_clock_gettime64(clockid_t clock_id,
-			struct __kernel_timespec __user *u_ts)
+COBALT_SYSCALL(clock_gettime64, current,
+	       (clockid_t clock_id, struct __kernel_timespec __user *u_ts))
 {
 	struct timespec64 ts;
 	int ret;
@@ -178,12 +178,6 @@ int __cobalt_clock_gettime64(clockid_t clock_id,
 	return 0;
 }
 
-COBALT_SYSCALL(clock_gettime64, current,
-	       (clockid_t clock_id, struct __kernel_timespec __user *u_ts))
-{
-	return __cobalt_clock_gettime64(clock_id, u_ts);
-}
-
 int __cobalt_clock_settime(clockid_t clock_id, const struct timespec64 *ts)
 {
 	int _ret, ret = 0;
kernel/cobalt/posix/clock.h +0 -3
index e18373979..169d51e62 100644
@@ -103,9 +103,6 @@ int __cobalt_clock_getres64(clockid_t clock_id,
 int __cobalt_clock_gettime(clockid_t clock_id,
 			   struct timespec64 *ts);
 
-int __cobalt_clock_gettime64(clockid_t clock_id,
-			struct __kernel_timespec __user *u_ts);
-
 int __cobalt_clock_settime(clockid_t clock_id,
 			   const struct timespec64 *ts);
 
kernel/cobalt/posix/syscall32.c +0 -7
index 2b4911c59..917a67625 100644
@@ -172,13 +172,6 @@ COBALT_SYSCALL32emu(clock_gettime, current,
 	return sys32_put_timespec(u_ts, &ts);
 }
 
-COBALT_SYSCALL32emu(clock_gettime64, current,
-		    (clockid_t clock_id,
-		     struct __kernel_timespec __user *u_ts))
-{
-	return __cobalt_clock_gettime64(clock_id, u_ts);
-}
-
 COBALT_SYSCALL32emu(clock_settime, current,
 		    (clockid_t clock_id,
 		     const struct old_timespec32 __user *u_ts))
kernel/cobalt/posix/syscall32.h +0 -4
index f36fff272..7d448d0ef 100644
@@ -63,10 +63,6 @@ COBALT_SYSCALL32emu_DECL(clock_gettime,
 			 (clockid_t clock_id,
 			  struct old_timespec32 __user *u_ts));
 
-COBALT_SYSCALL32emu_DECL(clock_gettime64,
-			 (clockid_t clock_id,
-			  struct __kernel_timespec __user *u_ts));
-
 COBALT_SYSCALL32emu_DECL(clock_settime,
 			 (clockid_t clock_id,
 			  const struct old_timespec32 __user *u_ts));
Signature · 1 line
2.37.1
#3 lore raw

PATCH 3/42 y2038: cobalt: posix/clock: Remove compat syscall for clock_settime64

In reply to Florian Bezdeka

There is no difference between the native and the compat entry point, so let's keep it simple. The native entrypoint is already linked into the syscall table at the right offset.

---
 kernel/cobalt/posix/clock.c     | 11 +++--------
 kernel/cobalt/posix/clock.h     |  3 ---
 kernel/cobalt/posix/syscall32.c |  7 -------
 kernel/cobalt/posix/syscall32.h |  4 ----
 4 files changed, 3 insertions(+), 22 deletions(-)
kernel/cobalt/posix/clock.c +3 -8
index bd393bb11..c4457b6c9 100644
@@ -232,8 +232,9 @@ COBALT_SYSCALL(clock_settime, current,
 	return __cobalt_clock_settime(clock_id, &ts);
 }
 
-int __cobalt_clock_settime64(clockid_t clock_id,
-			const struct __kernel_timespec __user *u_ts)
+COBALT_SYSCALL(clock_settime64, current,
+	       (clockid_t clock_id,
+		const struct __kernel_timespec __user *u_ts))
 {
 	struct timespec64 ts64;
 
@@ -243,12 +244,6 @@ int __cobalt_clock_settime64(clockid_t clock_id,
 	return __cobalt_clock_settime(clock_id, &ts64);
 }
 
-COBALT_SYSCALL(clock_settime64, current,
-	       (clockid_t clock_id, const struct __kernel_timespec __user *u_ts))
-{
-	return __cobalt_clock_settime64(clock_id, u_ts);
-}
-
 COBALT_SYSCALL(clock_adjtime, current,
 	       (clockid_t clock_id, struct __user_old_timex __user *u_tx))
 {
kernel/cobalt/posix/clock.h +0 -3
index 169d51e62..2607522e8 100644
@@ -106,9 +106,6 @@ int __cobalt_clock_gettime(clockid_t clock_id,
 int __cobalt_clock_settime(clockid_t clock_id,
 			   const struct timespec64 *ts);
 
-int __cobalt_clock_settime64(clockid_t clock_id,
-			const struct __kernel_timespec __user *u_ts);
-
 int __cobalt_clock_adjtime(clockid_t clock_id,
 			   struct __kernel_timex *tx);
 
kernel/cobalt/posix/syscall32.c +0 -7
index 917a67625..30d7e1bcd 100644
@@ -186,13 +186,6 @@ COBALT_SYSCALL32emu(clock_settime, current,
 	return __cobalt_clock_settime(clock_id, &ts);
 }
 
-COBALT_SYSCALL32emu(clock_settime64, current,
-		    (clockid_t clock_id,
-		     const struct __kernel_timespec __user *u_ts))
-{
-	return __cobalt_clock_settime64(clock_id, u_ts);
-}
-
 COBALT_SYSCALL32emu(clock_adjtime, current,
 		    (clockid_t clock_id, struct old_timex32 __user *u_tx))
 {
kernel/cobalt/posix/syscall32.h +0 -4
index 7d448d0ef..c016c904c 100644
@@ -67,10 +67,6 @@ COBALT_SYSCALL32emu_DECL(clock_settime,
 			 (clockid_t clock_id,
 			  const struct old_timespec32 __user *u_ts));
 
-COBALT_SYSCALL32emu_DECL(clock_settime64,
-			 (clockid_t clock_id,
-			  const struct __kernel_timespec __user *u_ts));
-
 COBALT_SYSCALL32emu_DECL(clock_adjtime,
 			 (clockid_t clock_id,
 			  struct old_timex32 __user *u_tx));
Signature · 1 line
2.37.1
#4 lore raw

PATCH 4/42 y2038: cobalt: posix/clock: Remove compat syscall for clock_nanosleep64

In reply to Florian Bezdeka

There is no difference between the native and the compat entry point, so let's keep it simple. The native entrypoint is already linked into the syscall table at the right offset.

---
 kernel/cobalt/posix/clock.c     | 13 +++----------
 kernel/cobalt/posix/clock.h     |  4 ----
 kernel/cobalt/posix/syscall32.c |  9 ---------
 kernel/cobalt/posix/syscall32.h |  6 ------
 4 files changed, 3 insertions(+), 29 deletions(-)
kernel/cobalt/posix/clock.c +3 -10
index c4457b6c9..7b1693612 100644
@@ -385,9 +385,10 @@ COBALT_SYSCALL(clock_nanosleep, primary,
 	return ret;
 }
 
-int __cobalt_clock_nanosleep64(clockid_t clock_id, int flags,
+COBALT_SYSCALL(clock_nanosleep64, primary,
+	       (clockid_t clock_id, int flags,
 		const struct __kernel_timespec __user *u_rqt,
-		struct __kernel_timespec __user *u_rmt)
+		struct __kernel_timespec __user *u_rmt))
 {
 	struct timespec64 rqt, rmt, *rmtp = NULL;
 	int ret;
@@ -407,14 +408,6 @@ int __cobalt_clock_nanosleep64(clockid_t clock_id, int flags,
 	return ret;
 }
 
-COBALT_SYSCALL(clock_nanosleep64, primary,
-	       (clockid_t clock_id, int flags,
-		const struct __kernel_timespec __user *u_rqt,
-		struct __kernel_timespec __user *u_rmt))
-{
-	return __cobalt_clock_nanosleep64(clock_id, flags, u_rqt, u_rmt);
-}
-
 int cobalt_clock_register(struct xnclock *clock, const cpumask_t *affinity,
 			  clockid_t *clk_id)
 {
kernel/cobalt/posix/clock.h +0 -4
index 2607522e8..b5ab39b44 100644
@@ -116,10 +116,6 @@ int __cobalt_clock_nanosleep(clockid_t clock_id, int flags,
 			     const struct timespec64 *rqt,
 			     struct timespec64 *rmt);
 
-int __cobalt_clock_nanosleep64(clockid_t clock_id, int flags,
-		const struct __kernel_timespec __user *u_rqt,
-		struct __kernel_timespec __user *u_rmt);
-
 COBALT_SYSCALL_DECL(clock_getres,
 		    (clockid_t clock_id, struct __user_old_timespec __user *u_ts));
 
kernel/cobalt/posix/syscall32.c +0 -9
index 30d7e1bcd..a245e91af 100644
@@ -232,15 +232,6 @@ COBALT_SYSCALL32emu(clock_nanosleep, primary,
 	return ret;
 }
 
-COBALT_SYSCALL32emu(clock_nanosleep64, nonrestartable,
-		    (clockid_t clock_id, int flags,
-		     const struct __kernel_timespec __user *u_rqt,
-		     struct __kernel_timespec __user *u_rmt))
-{
-	return __cobalt_clock_nanosleep64(clock_id, flags, u_rqt, u_rmt);
-}
-
-
 COBALT_SYSCALL32emu(mutex_timedlock, primary,
 		    (struct cobalt_mutex_shadow __user *u_mx,
 		     const struct old_timespec32 __user *u_ts))
kernel/cobalt/posix/syscall32.h +0 -6
index c016c904c..0e06e12c1 100644
@@ -80,12 +80,6 @@ COBALT_SYSCALL32emu_DECL(clock_nanosleep,
 			  const struct old_timespec32 __user *u_rqt,
 			  struct old_timespec32 __user *u_rmt));
 
-COBALT_SYSCALL32emu_DECL(clock_nanosleep64,
-			 (clockid_t clock_id, int flags,
-			  const struct __kernel_timespec __user *u_rqt,
-			  struct __kernel_timespec __user *u_rmt));
-
-
 COBALT_SYSCALL32emu_DECL(mutex_timedlock,
 			 (struct cobalt_mutex_shadow __user *u_mx,
 			  const struct old_timespec32 __user *u_ts));
Signature · 1 line
2.37.1
#5 lore raw

PATCH 5/42 y2038: cobalt: posix/clock: Remove compat syscall for clock_getres64

In reply to Florian Bezdeka

There is no difference between the native and the compat entry point, so let's keep it simple. The native entrypoint is already linked into the syscall table at the right offset.

---
 kernel/cobalt/posix/clock.c     | 10 ++--------
 kernel/cobalt/posix/clock.h     |  3 ---
 kernel/cobalt/posix/syscall32.c |  7 -------
 kernel/cobalt/posix/syscall32.h |  4 ----
 4 files changed, 2 insertions(+), 22 deletions(-)
kernel/cobalt/posix/clock.c +2 -8
index 7b1693612..9de90c728 100644
@@ -93,8 +93,8 @@ COBALT_SYSCALL(clock_getres, current,
 	return 0;
 }
 
-int __cobalt_clock_getres64(clockid_t clock_id,
-			struct __kernel_timespec __user *u_ts)
+COBALT_SYSCALL(clock_getres64, current,
+	       (clockid_t clock_id, struct __kernel_timespec __user *u_ts))
 {
 	struct timespec64 ts;
 	int ret;
@@ -111,12 +111,6 @@ int __cobalt_clock_getres64(clockid_t clock_id,
 	return 0;
 }
 
-COBALT_SYSCALL(clock_getres64, current,
-	       (clockid_t clock_id, struct __kernel_timespec __user *u_ts))
-{
-	return __cobalt_clock_getres64(clock_id, u_ts);
-}
-
 int __cobalt_clock_gettime(clockid_t clock_id, struct timespec64 *ts)
 {
 	xnticks_t ns;
kernel/cobalt/posix/clock.h +0 -3
index b5ab39b44..305400148 100644
@@ -97,9 +97,6 @@ static inline int clock_flag(int flag, clockid_t clock_id)
 int __cobalt_clock_getres(clockid_t clock_id,
 			  struct timespec64 *ts);
 
-int __cobalt_clock_getres64(clockid_t clock_id,
-			struct __kernel_timespec __user *u_ts);
-
 int __cobalt_clock_gettime(clockid_t clock_id,
 			   struct timespec64 *ts);
 
kernel/cobalt/posix/syscall32.c +0 -7
index a245e91af..2e7c2fc93 100644
@@ -151,13 +151,6 @@ COBALT_SYSCALL32emu(clock_getres, current,
 	return u_ts ? sys32_put_timespec(u_ts, &ts) : 0;
 }
 
-COBALT_SYSCALL32emu(clock_getres64, current,
-		    (clockid_t clock_id,
-		     struct __kernel_timespec __user *u_ts))
-{
-	return __cobalt_clock_getres64(clock_id, u_ts);
-}
-
 COBALT_SYSCALL32emu(clock_gettime, current,
 		    (clockid_t clock_id,
 		     struct old_timespec32 __user *u_ts))
kernel/cobalt/posix/syscall32.h +0 -4
index 0e06e12c1..2711fb2c8 100644
@@ -55,10 +55,6 @@ COBALT_SYSCALL32emu_DECL(clock_getres,
 			 (clockid_t clock_id,
 			  struct old_timespec32 __user *u_ts));
 
-COBALT_SYSCALL32emu_DECL(clock_getres64,
-			 (clockid_t clock_id,
-			  struct __kernel_timespec __user *u_ts));
-
 COBALT_SYSCALL32emu_DECL(clock_gettime,
 			 (clockid_t clock_id,
 			  struct old_timespec32 __user *u_ts));
Signature · 1 line
2.37.1
#6 lore raw

PATCH 6/42 y2038: cobalt: posix/clock: Remove compat syscall for clock_adjtime64

In reply to Florian Bezdeka

There is no difference between the native and the compat entry point, so let's keep it simple. The native entrypoint is already linked into the syscall table at the right offset.

---
 kernel/cobalt/posix/clock.c     | 10 ++--------
 kernel/cobalt/posix/clock.h     |  3 ---
 kernel/cobalt/posix/syscall32.c |  7 -------
 kernel/cobalt/posix/syscall32.h |  4 ----
 4 files changed, 2 insertions(+), 22 deletions(-)
kernel/cobalt/posix/clock.c +2 -8
index 9de90c728..266ccef52 100644
@@ -254,8 +254,8 @@ COBALT_SYSCALL(clock_adjtime, current,
 	return cobalt_copy_to_user(u_tx, &tx, sizeof(tx));
 }
 
-int __cobalt_clock_adjtime64(clockid_t clock_id,
-			struct __kernel_timex __user *u_tx)
+COBALT_SYSCALL(clock_adjtime64, current,
+	       (clockid_t clock_id, struct __kernel_timex __user *u_tx))
 {
 	struct __kernel_timex tx;
 	int ret;
@@ -270,12 +270,6 @@ int __cobalt_clock_adjtime64(clockid_t clock_id,
 	return cobalt_copy_to_user(u_tx, &tx, sizeof(tx));
 }
 
-COBALT_SYSCALL(clock_adjtime64, current,
-	       (clockid_t clock_id, struct __kernel_timex __user *u_tx))
-{
-	return __cobalt_clock_adjtime64(clock_id, u_tx);
-}
-
 int __cobalt_clock_nanosleep(clockid_t clock_id, int flags,
 			     const struct timespec64 *rqt,
 			     struct timespec64 *rmt)
kernel/cobalt/posix/clock.h +0 -3
index 305400148..dbaabbc5d 100644
@@ -106,9 +106,6 @@ int __cobalt_clock_settime(clockid_t clock_id,
 int __cobalt_clock_adjtime(clockid_t clock_id,
 			   struct __kernel_timex *tx);
 
-int __cobalt_clock_adjtime64(clockid_t clock_id,
-			struct __kernel_timex __user *u_tx);
-
 int __cobalt_clock_nanosleep(clockid_t clock_id, int flags,
 			     const struct timespec64 *rqt,
 			     struct timespec64 *rmt);
kernel/cobalt/posix/syscall32.c +0 -7
index 2e7c2fc93..245ddb2f0 100644
@@ -196,13 +196,6 @@ COBALT_SYSCALL32emu(clock_adjtime, current,
 	return sys32_put_timex(u_tx, &tx);
 }
 
-COBALT_SYSCALL32emu(clock_adjtime64, current,
-		    (clockid_t clock_id, struct __kernel_timex __user *u_tx))
-{
-	return __cobalt_clock_adjtime64(clock_id, u_tx);
-}
-
-
 COBALT_SYSCALL32emu(clock_nanosleep, primary,
 		    (clockid_t clock_id, int flags,
 		     const struct old_timespec32 __user *u_rqt,
kernel/cobalt/posix/syscall32.h +0 -4
index 2711fb2c8..b7baee94d 100644
@@ -67,10 +67,6 @@ COBALT_SYSCALL32emu_DECL(clock_adjtime,
 			 (clockid_t clock_id,
 			  struct old_timex32 __user *u_tx));
 
-COBALT_SYSCALL32emu_DECL(clock_adjtime64,
-			 (clockid_t clock_id,
-			  struct __kernel_timex __user *u_tx));
-
 COBALT_SYSCALL32emu_DECL(clock_nanosleep,
 			 (clockid_t clock_id, int flags,
 			  const struct old_timespec32 __user *u_rqt,
Signature · 1 line
2.37.1
#7 lore raw

PATCH 7/42 y2038: cobalt: posix/mutex: Remove compat syscall for mutex_timedlock64

In reply to Florian Bezdeka

There is no difference between the native and the compat entry point, so let's keep it simple. The native entrypoint is already linked into the syscall table at the right offset.

---
 kernel/cobalt/posix/mutex.c     | 10 ++--------
 kernel/cobalt/posix/mutex.h     |  3 ---
 kernel/cobalt/posix/syscall32.c |  7 -------
 kernel/cobalt/posix/syscall32.h |  4 ----
 4 files changed, 2 insertions(+), 22 deletions(-)
kernel/cobalt/posix/mutex.c +2 -8
index 0f1c01851..2bdb66d17 100644
@@ -364,13 +364,6 @@ static inline int mutex_fetch_timeout64(struct timespec64 *ts,
 	return u_ts == NULL ? -EFAULT : cobalt_get_timespec64(ts, u_ts);
 }
 
-int __cobalt_mutex_timedlock64(struct cobalt_mutex_shadow __user *u_mx,
-			       const void __user *u_ts)
-{
-	return __cobalt_mutex_timedlock_break(u_mx, u_ts,
-					      mutex_fetch_timeout64);
-}
-
 COBALT_SYSCALL(mutex_timedlock, primary,
 	       (struct cobalt_mutex_shadow __user *u_mx,
 		const struct __user_old_timespec __user *u_ts))
@@ -382,7 +375,8 @@ COBALT_SYSCALL(mutex_timedlock64, primary,
 	       (struct cobalt_mutex_shadow __user *u_mx,
 		const struct __kernel_timespec __user *u_ts))
 {
-	return __cobalt_mutex_timedlock64(u_mx, u_ts);
+	return __cobalt_mutex_timedlock_break(u_mx, u_ts,
+					      mutex_fetch_timeout64);
 }
 
 COBALT_SYSCALL(mutex_unlock, nonrestartable,
kernel/cobalt/posix/mutex.h +0 -3
index d7fede27d..800515a69 100644
@@ -40,9 +40,6 @@ int __cobalt_mutex_timedlock_break(struct cobalt_mutex_shadow __user *u_mx,
 				   int (*fetch_timeout)(struct timespec64 *ts,
 							const void __user *u_ts));
 
-int __cobalt_mutex_timedlock64(struct cobalt_mutex_shadow __user *u_mx,
-				   const void __user *u_ts);
-
 int __cobalt_mutex_acquire_unchecked(struct xnthread *cur,
 				     struct cobalt_mutex *mutex,
 				     const struct timespec64 *ts);
kernel/cobalt/posix/syscall32.c +0 -7
index 245ddb2f0..d3cc79878 100644
@@ -225,13 +225,6 @@ COBALT_SYSCALL32emu(mutex_timedlock, primary,
 	return __cobalt_mutex_timedlock_break(u_mx, u_ts, sys32_fetch_timeout);
 }
 
-COBALT_SYSCALL32emu(mutex_timedlock64, primary,
-		    (struct cobalt_mutex_shadow __user *u_mx,
-		     const struct __kernel_timespec __user *u_ts))
-{
-	return __cobalt_mutex_timedlock64(u_mx, u_ts);
-}
-
 COBALT_SYSCALL32emu(cond_wait_prologue, nonrestartable,
 		    (struct cobalt_cond_shadow __user *u_cnd,
 		     struct cobalt_mutex_shadow __user *u_mx,
kernel/cobalt/posix/syscall32.h +0 -4
index b7baee94d..ab7dbb945 100644
@@ -76,10 +76,6 @@ COBALT_SYSCALL32emu_DECL(mutex_timedlock,
 			 (struct cobalt_mutex_shadow __user *u_mx,
 			  const struct old_timespec32 __user *u_ts));
 
-COBALT_SYSCALL32emu_DECL(mutex_timedlock64,
-			 (struct cobalt_mutex_shadow __user *u_mx,
-			  const struct __kernel_timespec __user *u_ts));
-
 COBALT_SYSCALL32emu_DECL(cond_wait_prologue,
 			 (struct cobalt_cond_shadow __user *u_cnd,
 			  struct cobalt_mutex_shadow __user *u_mx,
Signature · 1 line
2.37.1
#8 lore raw

PATCH 8/42 y2038: cobalt: posix/mqueue: Remove compat syscall for mq_timedsend64

In reply to Florian Bezdeka

There is no difference between the native and the compat entry point, so let's keep it simple. The native entrypoint is already linked into the syscall table at the right offset.

---
 kernel/cobalt/posix/mqueue.c    | 10 ++--------
 kernel/cobalt/posix/mqueue.h    |  3 ---
 kernel/cobalt/posix/syscall32.c |  8 --------
 kernel/cobalt/posix/syscall32.h |  5 -----
 4 files changed, 2 insertions(+), 24 deletions(-)
kernel/cobalt/posix/mqueue.c +2 -8
index 3514ba1b0..4487e23de 100644
@@ -974,13 +974,6 @@ out:
 	return ret;
 }
 
-int __cobalt_mq_timedsend64(mqd_t uqd, const void __user *u_buf, size_t len,
-			    unsigned int prio, const void __user *u_ts)
-{
-	return __cobalt_mq_timedsend(uqd, u_buf, len, prio, u_ts,
-				     u_ts ? mq_fetch_timeout64 : NULL);
-}
-
 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))
@@ -993,7 +986,8 @@ COBALT_SYSCALL(mq_timedsend64, primary,
 	       (mqd_t uqd, const void __user *u_buf, size_t len,
 		unsigned int prio, const struct __kernel_timespec __user *u_ts))
 {
-	return __cobalt_mq_timedsend64(uqd, u_buf, len, prio, u_ts);
+	return __cobalt_mq_timedsend(uqd, u_buf, len, prio, u_ts,
+				     u_ts ? mq_fetch_timeout64 : NULL);
 }
 
 int __cobalt_mq_timedreceive(mqd_t uqd, void __user *u_buf,
kernel/cobalt/posix/mqueue.h +0 -3
index d9223866a..755623f47 100644
@@ -40,9 +40,6 @@ int __cobalt_mq_timedsend(mqd_t uqd, const void __user *u_buf, size_t len,
 			  int (*fetch_timeout)(struct timespec64 *ts,
 					       const void __user *u_ts));
 
-int __cobalt_mq_timedsend64(mqd_t uqd, const void __user *u_buf, size_t len,
-			    unsigned int prio, const void __user *u_ts);
-
 int __cobalt_mq_timedreceive(mqd_t uqd, void __user *u_buf,
 			     ssize_t *lenp,
 			     unsigned int __user *u_prio,
kernel/cobalt/posix/syscall32.c +0 -8
index d3cc79878..0197c749b 100644
@@ -285,14 +285,6 @@ COBALT_SYSCALL32emu(mq_timedsend, primary,
 				     u_ts, u_ts ? sys32_fetch_timeout : NULL);
 }
 
-COBALT_SYSCALL32emu(mq_timedsend64, primary,
-		    (mqd_t uqd, const void __user *u_buf, size_t len,
-		     unsigned int prio,
-		     const struct __kernel_timespec __user *u_ts))
-{
-	return __cobalt_mq_timedsend64(uqd, u_buf, len, prio, u_ts);
-}
-
 COBALT_SYSCALL32emu(mq_timedreceive, primary,
 		    (mqd_t uqd, void __user *u_buf,
 		     compat_ssize_t __user *u_len,
kernel/cobalt/posix/syscall32.h +0 -5
index ab7dbb945..5569af7d8 100644
@@ -102,11 +102,6 @@ COBALT_SYSCALL32emu_DECL(mq_timedsend,
 			  unsigned int prio,
 			  const struct old_timespec32 __user *u_ts));
 
-COBALT_SYSCALL32emu_DECL(mq_timedsend64,
-			 (mqd_t uqd, const void __user *u_buf, size_t len,
-			  unsigned int prio,
-			  const struct __kernel_timespec __user *u_ts));
-
 COBALT_SYSCALL32emu_DECL(mq_timedreceive,
 			 (mqd_t uqd, void __user *u_buf,
 			  compat_ssize_t __user *u_len,
Signature · 1 line
2.37.1
#9 lore raw

PATCH 9/42 y2038: cobalt: posix/monitor: Remove compat syscall for monitor_wait64

In reply to Florian Bezdeka

There is no difference between the native and the compat entry point, so let's keep it simple. The native entrypoint is already linked into the syscall table at the right offset.

---
 kernel/cobalt/posix/monitor.c   | 26 +++++++++-----------------
 kernel/cobalt/posix/monitor.h   |  5 -----
 kernel/cobalt/posix/syscall32.c |  8 --------
 kernel/cobalt/posix/syscall32.h |  6 ------
 4 files changed, 9 insertions(+), 36 deletions(-)
kernel/cobalt/posix/monitor.c +9 -17
index 1e7128352..c266b8b3b 100644
@@ -294,17 +294,17 @@ out:
 	return ret;
 }
 
-int __cobalt_monitor_wait64(struct cobalt_monitor_shadow __user *u_mon,
-			    int event,
-			    const struct __kernel_timespec __user *u_ts,
-			    int __user *u_ret)
+COBALT_SYSCALL(monitor_wait, nonrestartable,
+	       (struct cobalt_monitor_shadow __user *u_mon,
+	       int event, const struct __user_old_timespec __user *u_ts,
+	       int __user *u_ret))
 {
 	struct timespec64 ts, *tsp = NULL;
 	int ret;
 
 	if (u_ts) {
 		tsp = &ts;
-		ret = cobalt_get_timespec64(&ts, u_ts);
+		ret = cobalt_get_u_timespec(&ts, u_ts);
 		if (ret)
 			return ret;
 	}
@@ -312,17 +312,16 @@ int __cobalt_monitor_wait64(struct cobalt_monitor_shadow __user *u_mon,
 	return __cobalt_monitor_wait(u_mon, event, tsp, u_ret);
 }
 
-COBALT_SYSCALL(monitor_wait, nonrestartable,
-	       (struct cobalt_monitor_shadow __user *u_mon,
-	       int event, const struct __user_old_timespec __user *u_ts,
-	       int __user *u_ret))
+COBALT_SYSCALL(monitor_wait64, nonrestartable,
+	       (struct cobalt_monitor_shadow __user *u_mon, int event,
+		const struct __kernel_timespec __user *u_ts, int __user *u_ret))
 {
 	struct timespec64 ts, *tsp = NULL;
 	int ret;
 
 	if (u_ts) {
 		tsp = &ts;
-		ret = cobalt_get_u_timespec(&ts, u_ts);
+		ret = cobalt_get_timespec64(&ts, u_ts);
 		if (ret)
 			return ret;
 	}
@@ -330,13 +329,6 @@ COBALT_SYSCALL(monitor_wait, nonrestartable,
 	return __cobalt_monitor_wait(u_mon, event, tsp, u_ret);
 }
 
-COBALT_SYSCALL(monitor_wait64, nonrestartable,
-	       (struct cobalt_monitor_shadow __user *u_mon, int event,
-		const struct __kernel_timespec __user *u_ts, int __user *u_ret))
-{
-	return __cobalt_monitor_wait64(u_mon, event, u_ts, u_ret);
-}
-
 COBALT_SYSCALL(monitor_sync, nonrestartable,
 	       (struct cobalt_monitor_shadow __user *u_mon))
 {
kernel/cobalt/posix/monitor.h +0 -5
index bf8794e36..3c76a036b 100644
@@ -42,11 +42,6 @@ int __cobalt_monitor_wait(struct cobalt_monitor_shadow __user *u_mon,
 			  int event, const struct timespec64 *ts,
 			  int __user *u_ret);
 
-int __cobalt_monitor_wait64(struct cobalt_monitor_shadow __user *u_mon,
-			    int event,
-			    const struct __kernel_timespec __user *u_ts,
-			    int __user *u_ret);
-
 COBALT_SYSCALL_DECL(monitor_init,
 		    (struct cobalt_monitor_shadow __user *u_monsh,
 		     clockid_t clk_id,
kernel/cobalt/posix/syscall32.c +0 -8
index 0197c749b..dfa4d31ec 100644
@@ -733,14 +733,6 @@ COBALT_SYSCALL32emu(monitor_wait, nonrestartable,
 	return __cobalt_monitor_wait(u_mon, event, tsp, u_ret);
 }
 
-COBALT_SYSCALL32emu(monitor_wait64, nonrestartable,
-		    (struct cobalt_monitor_shadow __user *u_mon, int event,
-		     const struct __kernel_timespec __user *u_ts,
-		     int __user *u_ret))
-{
-	return __cobalt_monitor_wait64(u_mon, event, u_ts, u_ret);
-}
-
 COBALT_SYSCALL32emu(event_wait, primary,
 		    (struct cobalt_event_shadow __user *u_event,
 		     unsigned int bits,
kernel/cobalt/posix/syscall32.h +0 -6
index 5569af7d8..973a0befc 100644
@@ -195,12 +195,6 @@ COBALT_SYSCALL32emu_DECL(monitor_wait,
 			  int event, const struct old_timespec32 __user *u_ts,
 			  int __user *u_ret));
 
-COBALT_SYSCALL32emu_DECL(monitor_wait64,
-			 (struct cobalt_monitor_shadow __user *u_mon,
-			  int event,
-			  const struct __kernel_timespec __user *u_ts,
-			  int __user *u_ret));
-
 COBALT_SYSCALL32emu_DECL(event_wait,
 			 (struct cobalt_event_shadow __user *u_event,
 			  unsigned int bits,
Signature · 1 line
2.37.1
#10 lore raw

PATCH 10/42 y2038: cobalt: posix/event: Remove compat syscall for event_wait64

In reply to Florian Bezdeka

There is no difference between the native and the compat entry point, so let's keep it simple. The native entrypoint is already linked into the syscall table at the right offset.

---
 kernel/cobalt/posix/event.c     | 26 +++++++++-----------------
 kernel/cobalt/posix/event.h     |  5 -----
 kernel/cobalt/posix/syscall32.c |  9 ---------
 kernel/cobalt/posix/syscall32.h |  7 -------
 4 files changed, 9 insertions(+), 38 deletions(-)
kernel/cobalt/posix/event.c +9 -17
index 052c68605..a5fa45db8 100644
@@ -190,17 +190,18 @@ out:
 	return ret;
 }
 
-int __cobalt_event_wait64(struct cobalt_event_shadow __user *u_event,
-			  unsigned int bits,
-			  unsigned int __user *u_bits_r,
-			  int mode, const struct __kernel_timespec __user *u_ts)
+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))
 {
 	struct timespec64 ts, *tsp = NULL;
 	int ret;
 
 	if (u_ts) {
 		tsp = &ts;
-		ret = cobalt_get_timespec64(&ts, u_ts);
+		ret = cobalt_get_u_timespec(&ts, u_ts);
 		if (ret)
 			return ret;
 	}
@@ -208,18 +209,18 @@ int __cobalt_event_wait64(struct cobalt_event_shadow __user *u_event,
 	return __cobalt_event_wait(u_event, bits, u_bits_r, mode, tsp);
 }
 
-COBALT_SYSCALL(event_wait, primary,
+COBALT_SYSCALL(event_wait64, 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_timespec __user *u_ts))
 {
 	struct timespec64 ts, *tsp = NULL;
 	int ret;
 
 	if (u_ts) {
 		tsp = &ts;
-		ret = cobalt_get_u_timespec(&ts, u_ts);
+		ret = cobalt_get_timespec64(&ts, u_ts);
 		if (ret)
 			return ret;
 	}
@@ -227,15 +228,6 @@ COBALT_SYSCALL(event_wait, primary,
 	return __cobalt_event_wait(u_event, bits, u_bits_r, mode, tsp);
 }
 
-COBALT_SYSCALL(event_wait64, primary,
-	       (struct cobalt_event_shadow __user *u_event,
-		unsigned int bits,
-		unsigned int __user *u_bits_r,
-		int mode, const struct __kernel_timespec __user *u_ts))
-{
-	return __cobalt_event_wait64(u_event, bits, u_bits_r, mode, u_ts);
-}
-
 COBALT_SYSCALL(event_sync, current,
 	       (struct cobalt_event_shadow __user *u_event))
 {
kernel/cobalt/posix/event.h +0 -5
index 919774c9a..a67141f2b 100644
@@ -41,11 +41,6 @@ int __cobalt_event_wait(struct cobalt_event_shadow __user *u_event,
 			unsigned int __user *u_bits_r,
 			int mode, const struct timespec64 *ts);
 
-int __cobalt_event_wait64(struct cobalt_event_shadow __user *u_event,
-			  unsigned int bits, unsigned int __user *u_bits_r,
-			  int mode,
-			  const struct __kernel_timespec __user *u_ts);
-
 COBALT_SYSCALL_DECL(event_init,
 		    (struct cobalt_event_shadow __user *u_evtsh,
 		     unsigned int value,
kernel/cobalt/posix/syscall32.c +0 -9
index dfa4d31ec..97981bda9 100644
@@ -752,15 +752,6 @@ COBALT_SYSCALL32emu(event_wait, primary,
 	return __cobalt_event_wait(u_event, bits, u_bits_r, mode, tsp);
 }
 
-COBALT_SYSCALL32emu(event_wait64, primary,
-		    (struct cobalt_event_shadow __user *u_event,
-		     unsigned int bits,
-		     unsigned int __user *u_bits_r,
-		     int mode, const struct __kernel_timespec __user *u_ts))
-{
-	return __cobalt_event_wait64(u_event, bits, u_bits_r, mode, u_ts);
-}
-
 COBALT_SYSCALL32emu(select, primary,
 		    (int nfds,
 		     compat_fd_set __user *u_rfds,
kernel/cobalt/posix/syscall32.h +0 -7
index 973a0befc..c96fa1379 100644
@@ -201,13 +201,6 @@ COBALT_SYSCALL32emu_DECL(event_wait,
 			  unsigned int __user *u_bits_r,
 			  int mode, const struct old_timespec32 __user *u_ts));
 
-COBALT_SYSCALL32emu_DECL(event_wait64,
-			 (struct cobalt_event_shadow __user *u_event,
-			  unsigned int bits,
-			  unsigned int __user *u_bits_r,
-			  int mode,
-			  const struct __kernel_timespec __user *u_ts));
-
 COBALT_SYSCALL32emu_DECL(select,
 			 (int nfds,
 			  compat_fd_set __user *u_rfds,
Signature · 1 line
2.37.1
#11 lore raw

PATCH 11/42 y2038: cobalt: posix/cond: Remove compat syscall for cond_wait_prologue64

In reply to Florian Bezdeka

There is no difference between the native and the compat entry point, so let's keep it simple. The native entrypoint is already linked into the syscall table at the right offset.

---
 kernel/cobalt/posix/cond.c      | 12 ++----------
 kernel/cobalt/posix/cond.h      |  5 -----
 kernel/cobalt/posix/syscall32.c | 10 ----------
 kernel/cobalt/posix/syscall32.h |  7 -------
 4 files changed, 2 insertions(+), 32 deletions(-)
kernel/cobalt/posix/cond.c +2 -10
index 95d1e75bc..7b87fe908 100644
@@ -354,15 +354,6 @@ int __cobalt_cond_wait_prologue(struct cobalt_cond_shadow __user *u_cnd,
 	return err == 0 ? perr : err;
 }
 
-int __cobalt_cond_wait_prologue64(struct cobalt_cond_shadow __user *u_cnd,
-				  struct cobalt_mutex_shadow __user *u_mx,
-				  int __user *u_err, unsigned int timed,
-				  void __user *u_ts)
-{
-	return __cobalt_cond_wait_prologue(u_cnd, u_mx, u_err, u_ts,
-					   timed ? cond_fetch_timeout64 : NULL);
-}
-
 /* pthread_cond_wait_prologue(cond, mutex, count_ptr, timed, timeout) */
 COBALT_SYSCALL(cond_wait_prologue, nonrestartable,
 	       (struct cobalt_cond_shadow __user *u_cnd,
@@ -382,7 +373,8 @@ COBALT_SYSCALL(cond_wait_prologue64, nonrestartable,
 		unsigned int timed,
 		struct __kernel_timespec __user *u_ts))
 {
-	return __cobalt_cond_wait_prologue64(u_cnd, u_mx, u_err, timed, u_ts);
+	return __cobalt_cond_wait_prologue(u_cnd, u_mx, u_err, u_ts,
+					   timed ? cond_fetch_timeout64 : NULL);
 }
 
 COBALT_SYSCALL(cond_wait_epilogue, primary,
kernel/cobalt/posix/cond.h +0 -5
index 1fd4256ce..c2fdd40e0 100644
@@ -46,11 +46,6 @@ int __cobalt_cond_wait_prologue(struct cobalt_cond_shadow __user *u_cnd,
 				int (*fetch_timeout)(struct timespec64 *ts,
 						     const void __user *u_ts));
 
-int __cobalt_cond_wait_prologue64(struct cobalt_cond_shadow __user *u_cnd,
-				  struct cobalt_mutex_shadow __user *u_mx,
-				  int __user *u_err, unsigned int timed,
-				  void __user *u_ts);
-
 COBALT_SYSCALL_DECL(cond_init,
 		    (struct cobalt_cond_shadow __user *u_cnd,
 		     const struct cobalt_condattr __user *u_attr));
kernel/cobalt/posix/syscall32.c +0 -10
index 97981bda9..10b080dfd 100644
@@ -236,16 +236,6 @@ COBALT_SYSCALL32emu(cond_wait_prologue, nonrestartable,
 					   timed ? sys32_fetch_timeout : NULL);
 }
 
-COBALT_SYSCALL32emu(cond_wait_prologue64, nonrestartable,
-		    (struct cobalt_cond_shadow __user *u_cnd,
-		     struct cobalt_mutex_shadow __user *u_mx,
-		     int __user *u_err,
-		     unsigned int timed,
-		     struct __kernel_timespec __user *u_ts))
-{
-	return __cobalt_cond_wait_prologue64(u_cnd, u_mx, u_err, timed, u_ts);
-}
-
 COBALT_SYSCALL32emu(mq_open, lostage,
 		    (const char __user *u_name, int oflags,
 		     mode_t mode, struct compat_mq_attr __user *u_attr))
kernel/cobalt/posix/syscall32.h +0 -7
index c96fa1379..3df6224b7 100644
@@ -83,13 +83,6 @@ COBALT_SYSCALL32emu_DECL(cond_wait_prologue,
 			  unsigned int timed,
 			  struct old_timespec32 __user *u_ts));
 
-COBALT_SYSCALL32emu_DECL(cond_wait_prologue64,
-			 (struct cobalt_cond_shadow __user *u_cnd,
-			  struct cobalt_mutex_shadow __user *u_mx,
-			  int __user *u_err,
-			  unsigned int timed,
-			  struct __kernel_timespec __user *u_ts));
-
 COBALT_SYSCALL32emu_DECL(mq_open,
 			 (const char __user *u_name, int oflags,
 			  mode_t mode, struct compat_mq_attr __user *u_attr));
Signature · 1 line
2.37.1
#12 lore raw

PATCH 12/42 y2038: cobalt: Cleanup code style of time.{c,h}

In reply to Florian Bezdeka

No functional changes. Fixing some code style issues.

---
 include/cobalt/kernel/time.h | 2 +-
 kernel/cobalt/time.c         | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
include/cobalt/kernel/time.h +1 -1
index e48022f87..a55398068 100644
@@ -26,6 +26,6 @@ int cobalt_get_timespec64(struct timespec64 *ts,
  * @return 0 on success, -EFAULT otherwise
  */
 int cobalt_put_timespec64(const struct timespec64 *ts,
-			   struct __kernel_timespec __user *uts);
+			  struct __kernel_timespec __user *uts);
 
 #endif //_COBALT_KERNEL_TIME_H
kernel/cobalt/time.c +2 -2
index cb152fc7a..27dbf8290 100644
@@ -27,11 +27,11 @@ int cobalt_get_timespec64(struct timespec64 *ts,
 }
 
 int cobalt_put_timespec64(const struct timespec64 *ts,
-		   struct __kernel_timespec __user *uts)
+			  struct __kernel_timespec __user *uts)
 {
 	struct __kernel_timespec kts = {
 		.tv_sec = ts->tv_sec,
-		.tv_nsec = ts->tv_nsec
+		.tv_nsec = ts->tv_nsec,
 	};
 
 	return cobalt_copy_to_user(uts, &kts, sizeof(kts)) ? -EFAULT : 0;
Signature · 1 line
2.37.1
#13 lore raw

PATCH 13/42 y2038: posix/mq: Fix mq_timedsend syscall routing

In reply to Florian Bezdeka

The sc_cobalt_mq_timedsend syscall was used twice, once for the mq_timedsend service and once for the mq_send service which re-uses the same cobalt service without supplying a timeout.

The mq_timedsend case - which actually counts y2038 wise - has been overlooked by Song when introducing y2038 support for some reason.

Both services fall back to the same helper now, so we can handle them the same way.

---
 lib/cobalt/mq.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
lib/cobalt/mq.c +14 -9
index a8c88b406..88a74095b 100644
@@ -289,6 +289,18 @@ COBALT_IMPL(int, mq_setattr, (mqd_t mqd,
 	return -1;
 }
 
+static inline int __do_mq_timesend(mqd_t q, const char *buffer, size_t len,
+				   unsigned int prio, const struct timespec *to)
+{
+#ifdef __USE_TIME_BITS64
+	long sc_nr = sc_cobalt_mq_timedsend64;
+#else
+	long sc_nr = sc_cobalt_mq_timedsend;
+#endif
+
+	return XENOMAI_SYSCALL5(sc_nr, q, buffer, len, prio, to);
+}
+
 /**
  * Send a message to a message queue.
  *
@@ -332,13 +344,7 @@ COBALT_IMPL(int, mq_send, (mqd_t q, const char *buffer, size_t len, unsigned pri
 
 	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
 
-#ifdef __USE_TIME_BITS64
-	err = XENOMAI_SYSCALL5(sc_cobalt_mq_timedsend64,
-			       q, buffer, len, prio, NULL);
-#else
-	err = XENOMAI_SYSCALL5(sc_cobalt_mq_timedsend,
-			       q, buffer, len, prio, NULL);
-#endif
+	err = __do_mq_timesend(q, buffer, len, prio, NULL);
 
 	pthread_setcanceltype(oldtype, NULL);
 
@@ -397,8 +403,7 @@ COBALT_IMPL(int, mq_timedsend, (mqd_t q,
 
 	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
 
-	err = XENOMAI_SYSCALL5(sc_cobalt_mq_timedsend,
-			       q, buffer, len, prio, timeout);
+	err = __do_mq_timesend(q, buffer, len, prio, timeout);
 
 	pthread_setcanceltype(oldtype, NULL);
 
Signature · 1 line
2.37.1
#14 lore raw

PATCH 14/42 lib/cobalt: Fix possible fd leak in __map_umm

In reply to Florian Bezdeka

In case the MEMDEV_RTIOC_STAT fails we have to close the file descriptor.

---
 lib/cobalt/umm.c | 1 +
 1 file changed, 1 insertion(+)
lib/cobalt/umm.c +1 -0
index 944620fee..c30ada6a2 100644
@@ -59,6 +59,7 @@ static void *__map_umm(const char *name, uint32_t *size_r)
 
 	ret = __RT(ioctl(fd, MEMDEV_RTIOC_STAT, &statbuf));
 	if (ret) {
+		__RT(close(fd));
 		early_warning("failed getting status of %s: %s",
 			      name, strerror(errno));
 		return MAP_FAILED;
Signature · 1 line
2.37.1
#15 lore raw

PATCH 15/42 testsuite/smokey/sched-quota: Allow building with gcc 12

In reply to Florian Bezdeka

The build wich gcc 12 failed with two overflow warnings. gcc is more strict in checking specifier overflows now.

In this case %d alone would require up to 10 characters but only 8 where available.

The warning:

sched-quota.c: In function ‘calibrate’:
sched-quota.c:244:34: error: ‘%d’ directive writing between 1 and 10 bytes into a region of size 7 [-Werror=format-overflow=]
244 | sprintf(label, "t%d", n);
| ^~
sched-quota.c:244:32: note: directive argument in the range [0, 2147483646]
244 | sprintf(label, "t%d", n);
| ^~~~~
sched-quota.c:244:17: note: ‘sprintf’ output between 3 and 12 bytes into a destination of size 8
244 | sprintf(label, "t%d", n);

Fixed by migrating to snprintf and adding a limit to the actual buffer size.

---
 testsuite/smokey/sched-quota/sched-quota.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
testsuite/smokey/sched-quota/sched-quota.c +2 -2
index acb9055fd..093f7db43 100644
@@ -184,7 +184,7 @@ static double run_quota(int quota)
 		     tgid, cf.quota.info.quota_sum);
 
 	for (n = 0; n < nrthreads; n++) {
-		sprintf(label, "t%d", n);
+		snprintf(label, sizeof(label), "t%d", n);
 		create_quota_thread(threads[n], label, tgid, counts[n]);
 		sem_wait(&ready);
 	}
@@ -241,7 +241,7 @@ static unsigned long long calibrate(void)
 	crunch_per_sec = (unsigned long long)((double)ONE_BILLION / (double)ns * crunch_loops);
 
 	for (n = 0; n < nrthreads; n++) {
-		sprintf(label, "t%d", n);
+		snprintf(label, sizeof(label), "t%d", n);
 		create_fifo_thread(threads[n], label, counts[n]);
 		sem_wait(&ready);
 	}
Signature · 1 line
2.37.1
#16 lore raw

PATCH 16/42 y2038: posix/mq: Harmonize mq_receive and mq_timedreceive

In reply to Florian Bezdeka

Let both callers of the cobalt_mq_timedcreceive service care about y2038 safety. The old code was correct but confusing. The mq_receive service is not y2038 affected because it does not forward a timeout, but it still calls the same service.

---
 lib/cobalt/mq.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)
lib/cobalt/mq.c +15 -9
index 88a74095b..365a28e7a 100644
@@ -414,6 +414,19 @@ COBALT_IMPL(int, mq_timedsend, (mqd_t q,
 	return -1;
 }
 
+static inline int __do_mq_timedreceive(mqd_t q, char *buffer, ssize_t *len,
+				       unsigned int *prio,
+				       const struct timespec *timeout)
+{
+#ifdef __USE_TIME_BITS64
+	long sc_nr = sc_cobalt_mq_timedreceive64;
+#else
+	long sc_nr = sc_cobalt_mq_timedreceive;
+#endif
+
+	return XENOMAI_SYSCALL5(sc_nr, q, buffer, len, prio, timeout);
+}
+
 /**
  * Receive a message from a message queue.
  *
@@ -461,8 +474,7 @@ COBALT_IMPL(ssize_t, mq_receive, (mqd_t q, char *buffer, size_t len, unsigned *p
 
 	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
 
-	err = XENOMAI_SYSCALL5(sc_cobalt_mq_timedreceive,
-			       q, buffer, &rlen, prio, NULL);
+	err = __do_mq_timedreceive(q, buffer, &rlen, prio, NULL);
 
 	pthread_setcanceltype(oldtype, NULL);
 
@@ -526,13 +538,7 @@ COBALT_IMPL(ssize_t, mq_timedreceive, (mqd_t q,
 
 	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
 
-#ifdef __USE_TIME_BITS64
-	err = XENOMAI_SYSCALL5(sc_cobalt_mq_timedreceive64,
-			       q, buffer, &rlen, prio, timeout);
-#else
-	err = XENOMAI_SYSCALL5(sc_cobalt_mq_timedreceive,
-			       q, buffer, &rlen, prio, timeout);
-#endif
+	err = __do_mq_timedreceive(q, buffer, &rlen, prio, timeout);
 
 	pthread_setcanceltype(oldtype, NULL);
 
Signature · 1 line
2.37.1
#17 lore raw

PATCH 17/42 y2038: testsuite/smokey/y2038: Fix a very unlikely resource leak

In reply to Florian Bezdeka

In case we had no kernel support for the cond_wait_prologue64 service we would leak some thread resources. Fixed now.

While at it: Adding the "64" suffix to the test name. All other tests have it as well.

---
 testsuite/smokey/y2038/syscall-tests.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
testsuite/smokey/y2038/syscall-tests.c +4 -3
index 2f4041e51..6fcb97cac 100644
@@ -1117,7 +1117,7 @@ out:
 	return ret;
 }
 
-static int test_sc_cobalt_cond_wait_prologue(void)
+static int test_sc_cobalt_cond_wait_prologue64(void)
 {
 	int ret = 0;
 	int err = 0;
@@ -1142,7 +1142,8 @@ static int test_sc_cobalt_cond_wait_prologue(void)
 	if (ret == -ENOSYS) {
 		smokey_note(
 			"cond_wait_prologue64: skipped. (no kernel support)");
-		return 0; // Not implemented, nothing to test, success
+		ret = 0;
+		goto out; // Not implemented, nothing to test, success
 	}
 	if (!smokey_assert(ret == -EINVAL))
 		return ret ? ret : -EINVAL;
@@ -1293,7 +1294,7 @@ static int run_y2038(struct smokey_test *t, int argc, char *const argv[])
 	if (ret)
 		return ret;
 
-	ret = test_sc_cobalt_cond_wait_prologue();
+	ret = test_sc_cobalt_cond_wait_prologue64();
 	if (ret)
 		return ret;
 
Signature · 1 line
2.37.1
#18 lore raw

PATCH 18/42 y2038: cobalt/posix/clock: Use timespec64_valid() for validation

In reply to Florian Bezdeka

No need to re-code the timespec validation, we can just use the available helper.

---
 kernel/cobalt/posix/clock.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
kernel/cobalt/posix/clock.c +1 -4
index 266ccef52..48cd87aef 100644
@@ -286,10 +286,7 @@ int __cobalt_clock_nanosleep(clockid_t clock_id, int flags,
 	    clock_id != CLOCK_REALTIME)
 		return -EOPNOTSUPP;
 
-	if (rqt->tv_sec < 0)
-		return -EINVAL;
-
-	if ((unsigned long)rqt->tv_nsec >= ONE_BILLION)
+	if (!timespec64_valid(rqt))
 		return -EINVAL;
 
 	if (flags & ~TIMER_ABSTIME)
Signature · 1 line
2.37.1
#19 lore raw

PATCH 19/42 y2038: Prepare code base for 64bit time_t

In reply to Florian Bezdeka

Compiling the Xenomai code base with CFLAGS set to "-D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64" - which is the requirement for y2038 safety on 32 bit platforms - failed. We had some problems with printf format specifiers which are now too small when time_t is lifted to 64 bit.

Casting to (long long) should do it on all platforms we support.

---
 demo/alchemy/altency.c      | 26 +++++++++++++-------------
 testsuite/latency/latency.c | 34 ++++++++++++++++++----------------
 testsuite/spitest/spitest.c |  6 ++++--
 3 files changed, 35 insertions(+), 31 deletions(-)
demo/alchemy/altency.c +13 -13
index e7c31d7c1..b15930567 100644
@@ -258,12 +258,12 @@ static void display(void *cookie)
 				time_t now, dt;
 				time(&now);
 				dt = now - start - WARMUP_TIME;
-				printf
-				    ("RTT|  %.2ld:%.2ld:%.2ld  (%s, %Ld us period, "
-				     "priority %d)\n", dt / 3600,
-				     (dt / 60) % 60, dt % 60,
-				     test_mode_names[test_mode],
-				     period_ns / 1000, priority);
+				printf("RTT|  %.2lld:%.2lld:%.2lld  (%s, %lld us period, priority %d)\n",
+				       (long long)(dt / 3600),
+				       (long long)((dt / 60) % 60),
+				       (long long)(dt % 60),
+				       test_mode_names[test_mode],
+				       period_ns / 1000, priority);
 				printf("RTH|%11s|%11s|%11s|%8s|%6s|%11s|%11s\n",
 				       "----lat min", "----lat avg",
 				       "----lat max", "-overrun", "---msw",
@@ -413,13 +413,13 @@ static void cleanup(void)
 	if (!test_duration)
 		test_duration = actual_duration;
 
-	printf
-	    ("---|-----------|-----------|-----------|--------|------|-------------------------\n"
-	     "RTS|%11.3f|%11.3f|%11.3f|%8d|%6u|    %.2ld:%.2ld:%.2ld/%.2d:%.2d:%.2d\n",
-	     (double)gminj / 1000, (double)gavgj / 1000, (double)gmaxj / 1000,
-	     goverrun, max_relaxed, actual_duration / 3600, (actual_duration / 60) % 60,
-	     actual_duration % 60, test_duration / 3600,
-	     (test_duration / 60) % 60, test_duration % 60);
+	printf("---|-----------|-----------|-----------|--------|------|-------------------------\n"
+	       "RTS|%11.3f|%11.3f|%11.3f|%8d|%6u|    %.2lld:%.2lld:%.2lld/%.2d:%.2d:%.2d\n",
+	       (double)gminj / 1000, (double)gavgj / 1000, (double)gmaxj / 1000,
+	       goverrun, max_relaxed, (long long)(actual_duration / 3600),
+	       (long long)((actual_duration / 60) % 60),
+	       (long long)(actual_duration % 60), test_duration / 3600,
+	       (test_duration / 60) % 60, test_duration % 60);
 	if (max_relaxed > 0)
 		printf(
 "Warning! some latency peaks may have been due to involuntary mode switches.\n"
testsuite/latency/latency.c +18 -16
index 6cd3a28b4..7856b48b8 100644
@@ -322,12 +322,12 @@ static void *display(void *cookie)
 				time_t now, dt;
 				time(&now);
 				dt = now - start - WARMUP_TIME;
-				printf
-				    ("RTT|  %.2ld:%.2ld:%.2ld  (%s, %Ld us period, "
-				     "priority %d)\n", dt / 3600,
-				     (dt / 60) % 60, dt % 60,
-				     test_mode_names[test_mode],
-				     period_ns / 1000, priority);
+				printf("RTT|  %.2lld:%.2lld:%.2lld  (%s, %lld us period, priority %d)\n",
+				       (long long)(dt / 3600),
+				       (long long)((dt / 60) % 60),
+				       (long long)(dt % 60),
+				       test_mode_names[test_mode],
+				       period_ns / 1000, priority);
 				printf("RTH|%11s|%11s|%11s|%8s|%6s|%11s|%11s\n",
 				       "----lat min", "----lat avg",
 				       "----lat max", "-overrun", "---msw",
@@ -386,9 +386,10 @@ static void dump_histo_gnuplot(int32_t *histogram, time_t duration)
 			return;
 	}
 
-	fprintf(ofp, "# %.2ld:%.2ld:%.2ld (%s, %Ld us period, priority %d)\n",
-		duration / 3600, (duration / 60) % 60, duration % 60,
-		test_mode_names[test_mode],
+	fprintf(ofp,
+		"# %.2lld:%.2lld:%.2lld (%s, %lld us period, priority %d)\n",
+		(long long)duration / 3600, (long long)((duration / 60) % 60),
+		(long long)(duration % 60), test_mode_names[test_mode],
 		period_ns / 1000, priority);
 	fprintf(ofp, "# %11s|%11s|%11s|%8s|%6s|\n",
 		"----lat min", "----lat avg",
@@ -515,13 +516,14 @@ static void cleanup(void)
 	if (need_histo())
 		dump_hist_stats(actual_duration);
 
-	printf
-	    ("---|-----------|-----------|-----------|--------|------|-------------------------\n"
-	     "RTS|%11.3f|%11.3f|%11.3f|%8d|%6u|    %.2ld:%.2ld:%.2ld/%.2d:%.2d:%.2d\n",
-	     (double)gminjitter / 1000, (double)gavgjitter / 1000, (double)gmaxjitter / 1000,
-	     goverrun, max_relaxed, actual_duration / 3600, (actual_duration / 60) % 60,
-	     actual_duration % 60, test_duration / 3600,
-	     (test_duration / 60) % 60, test_duration % 60);
+	printf("---|-----------|-----------|-----------|--------|------|-------------------------\n"
+	       "RTS|%11.3f|%11.3f|%11.3f|%8d|%6u|    %.2lld:%.2lld:%.2lld/%.2d:%.2d:%.2d\n",
+	       (double)gminjitter / 1000, (double)gavgjitter / 1000,
+	       (double)gmaxjitter / 1000, goverrun, max_relaxed,
+	       (long long)(actual_duration / 3600),
+	       (long long)((actual_duration / 60) % 60),
+	       (long long)(actual_duration % 60), test_duration / 3600,
+	       (test_duration / 60) % 60, test_duration % 60);
 	if (max_relaxed > 0)
 		printf(
 "Warning! some latency peaks may have been due to involuntary mode switches.\n"
testsuite/spitest/spitest.c +4 -2
index 6163e54bf..99d609403 100644
@@ -233,8 +233,10 @@ static void *display_thread(void *arg)
 		if (data_lines && (n++ % data_lines) == 0) {
 			time(&now);
 			dt = now - start;
-			printf("RTT|  %.2ld:%.2ld:%.2ld  (%Ld us period)\n",
-			       dt / 3600, (dt / 60) % 60, dt % 60,
+			printf("RTT|  %.2lld:%.2lld:%.2lld  (%lld us period)\n",
+			       (long long)(dt / 3600),
+			       (long long)((dt / 60) % 60),
+			       (long long)(dt % 60),
 			       (long long)period_ns / 1000);
 			printf("RTH|%11s|%11s|%11s|%8s|%8s|%11s|%11s\n",
 			       "----lat min", "----lat avg",
Signature · 1 line
2.37.1
#20 lore raw

PATCH 20/42 y2038: build: Introduce new build parameter --enable-y2038

In reply to Florian Bezdeka

The new --enable-y2038 build parameter will be used to enable additional function wrapping when the architecture we build for is affected by the y2038 problem.

The default value (for now) is "no".

If --enable-y2038 is given for an architecture that is not affected it will be ignored. That allows us to flip the default value later unconditionally.

CONFIG_XENO_LIBS_Y2038 will be set to 1 if the following conditions are met:
- y2038 support was requested (--enable-y2038 given)
- the target platform is affected by the y2038 problem
- glibc is used as libc
- glibc has y2038 support (glibc >= 2.34)

CONFIG_XENO_LIBS_Y2038 will be used later to add necessary glibc wrappers.

If y2038 support was requested and is available in glibc the CFALAGS -D_TIME_BITS=64 and -D_FILE_OFFSET_BITS=64 will be added to affect all compile units.

---
 configure.ac | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
configure.ac +48 -0
index 3ce34048e..ce708a00b 100644
@@ -138,19 +138,23 @@ case "$build_for" in
 	use_tls=yes
 	target_cpu_arch=x86
 	CONFIG_XENO_DEFAULT_PERIOD=100000
+	y2038_affected=yes
 	;;
  arm*-*)
 	target_cpu_arch=arm
 	CONFIG_XENO_DEFAULT_PERIOD=1000000
+	y2038_affected=yes
 	;;
  aarch64-*)
 	target_cpu_arch=arm64
 	CONFIG_XENO_DEFAULT_PERIOD=1000000
+	y2038_affected=no
 	;;
  x86_64-*|amd64-*)
 	use_tls=yes
 	target_cpu_arch=x86
 	CONFIG_XENO_DEFAULT_PERIOD=100000
+	y2038_affected=no
 	;;
  *)
 	if test $rtcore_type = cobalt; then
@@ -781,6 +785,50 @@ AC_ARG_ENABLE([tls],
 	    [use_tls=$enableval])
 AC_MSG_RESULT($use_tls)
 
+AC_MSG_CHECKING(whether glibc has y2038 support)
+AC_TRY_COMPILE([#include <features.h>],
+	[
+		#if !(__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 34))
+			#error "No y2038 support"
+		#endif
+	],
+	glibc_has_y2038_support=yes,
+	glibc_has_y2038_support=no)
+AC_MSG_RESULT($glibc_has_y2038_support)
+
+AC_MSG_CHECKING(whether to enable y2038 support in Xenomai libraries)
+AC_ARG_ENABLE(y2038,
+	AC_HELP_STRING([--enable-y2038], [Enable y2038 support]),
+	[case "$enableval" in
+	y | yes)
+		if test "$y2038_affected" = "yes"; then
+			CONFIG_XENO_LIBS_Y2038="$glibc_has_y2038_support"
+		else
+			CONFIG_XENO_LIBS_Y2038=no
+		fi
+		;;
+	*)
+		CONFIG_XENO_LIBS_Y2038=no
+		;;
+	esac])
+AC_MSG_RESULT(${CONFIG_XENO_LIBS_Y2038:-no})
+if test "$CONFIG_XENO_LIBS_Y2038" = "yes"; then
+	AC_DEFINE(CONFIG_XENO_LIBS_Y2038,1,[config])
+	XENO_USER_CFLAGS="$XENO_USER_CFLAGS -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64"
+	AC_SUBST(CONFIG_XENO_LIBS_Y2038)
+else
+	if test "$y2038_affected" = "yes"; then
+		AC_MSG_WARN([You're affected by the time_t overflow in 2038])
+		if test "$glibc_has_y2038_support" = "yes"; then
+			AC_MSG_WARN([You should consider adding --enable-y2038])
+		else
+			AC_MSG_WARN([glibc has no y2038 support (--enable-y2038 ignored)])
+		fi
+	fi
+fi
+AM_CONDITIONAL(CONFIG_XENO_LIBS_Y2038,[test "$CONFIG_XENO_LIBS_Y2038" = "yes"])
+
+
 dnl Check whether the compiler supports the __thread keyword.
 if test "x$use_tls" != xno; then
 	AC_CACHE_CHECK([for __thread keyword], libc_cv_gcc_tls,
Signature · 1 line
2.37.1
#21 lore raw

PATCH 21/42 y2038: cobalt: Introduce some itimerspec64 related helpers

In reply to Florian Bezdeka

The introduced helpers will be used by the timer and timerfd y2038 related services for reading/writing itimerspec from/to userspace.

---
 include/cobalt/kernel/time.h | 21 ++++++++++++++++++++
 kernel/cobalt/time.c         | 38 ++++++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+)
include/cobalt/kernel/time.h +21 -0
index a55398068..e348cf9b8 100644
@@ -28,4 +28,25 @@ int cobalt_get_timespec64(struct timespec64 *ts,
 int cobalt_put_timespec64(const struct timespec64 *ts,
 			  struct __kernel_timespec __user *uts);
 
+/**
+ * Read struct __kernel_itimerspec from userspace and convert to
+ * struct itimerspec64
+ *
+ * @param dst The destination, will be filled
+ * @param src The source, provided by an application
+ * @return 0 on success, -EFAULT otherwise
+ */
+int cobalt_get_itimerspec64(struct itimerspec64 *dst,
+			    const struct __kernel_itimerspec __user *src);
+
+/**
+ * Convert struct itimerspec64 to struct __kernel_itimerspec and copy to user
+ * space
+ * @param dst The destination, will be filled, provided by an application
+ * @param src The source, provided by the kernel
+ * @return 0 un success, -EFAULT otherwise
+ */
+int cobalt_put_itimerspec64(struct __kernel_itimerspec __user *dst,
+			    const struct itimerspec64 *src);
+
 #endif //_COBALT_KERNEL_TIME_H
kernel/cobalt/time.c +38 -0
index 27dbf8290..716223dc5 100644
@@ -36,3 +36,41 @@ int cobalt_put_timespec64(const struct timespec64 *ts,
 
 	return cobalt_copy_to_user(uts, &kts, sizeof(kts)) ? -EFAULT : 0;
 }
+
+int cobalt_get_itimerspec64(struct itimerspec64 *dst,
+			    const struct __kernel_itimerspec __user *src)
+{
+	struct timespec64 interval, value;
+	int ret;
+
+	if (!src)
+		return -EFAULT;
+
+	ret = cobalt_get_timespec64(&interval, &src->it_interval);
+	if (ret)
+		return ret;
+
+	ret = cobalt_get_timespec64(&value, &src->it_value);
+	if (ret)
+		return ret;
+
+	dst->it_interval.tv_sec = interval.tv_sec;
+	dst->it_interval.tv_nsec = interval.tv_nsec;
+	dst->it_value.tv_sec = value.tv_sec;
+	dst->it_value.tv_nsec = value.tv_nsec;
+
+	return 0;
+}
+
+int cobalt_put_itimerspec64(struct __kernel_itimerspec __user *dst,
+			    const struct itimerspec64 *src)
+{
+	struct __kernel_itimerspec kits = {
+		.it_interval.tv_sec = src->it_interval.tv_sec,
+		.it_interval.tv_nsec = src->it_interval.tv_nsec,
+		.it_value.tv_sec = src->it_value.tv_sec,
+		.it_value.tv_nsec = src->it_value.tv_nsec
+	};
+
+	return cobalt_copy_to_user(dst, &kits, sizeof(kits));
+}
Signature · 1 line
2.37.1
#22 lore raw

PATCH 22/42 y2038: cobalt/posix/timer: Adding timer_settime64

In reply to Florian Bezdeka

Add a syscall specific for timer_settime with 64bit time_t.

---
 include/cobalt/uapi/syscall.h      |  1 +
 kernel/cobalt/posix/timer.c        | 32 +++++++++++++++++++++++++++---
 kernel/cobalt/posix/timer.h        |  5 +++++
 kernel/cobalt/trace/cobalt-posix.h |  3 ++-
 4 files changed, 37 insertions(+), 4 deletions(-)
include/cobalt/uapi/syscall.h +1 -0
index 9646a0d97..77184bd22 100644
@@ -136,6 +136,7 @@
 #define sc_cobalt_event_wait64			113
 #define sc_cobalt_recvmmsg64			114
 #define sc_cobalt_cond_wait_prologue64		115
+#define sc_cobalt_timer_settime64		116
 
 #define __NR_COBALT_SYSCALLS			128 /* Power of 2 */
 
kernel/cobalt/posix/timer.c +29 -3
index a58ea99a3..b888f1927 100644
@@ -16,6 +16,7 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
+#include <cobalt/kernel/time.h>
 #include <linux/module.h>
 #include <linux/cred.h>
 #include <linux/err.h>
@@ -296,9 +297,8 @@ int __cobalt_timer_setval(struct xntimer *__restrict__ timer, int clock_flag,
 		return 0;
 	}
 
-	if ((unsigned long)value->it_value.tv_nsec >= ONE_BILLION ||
-	    ((unsigned long)value->it_interval.tv_nsec >= ONE_BILLION &&
-	     (value->it_value.tv_sec != 0 || value->it_value.tv_nsec != 0)))
+	if (!timespec64_valid(&value->it_interval) ||
+	    !timespec64_valid(&value->it_value))
 		return -EINVAL;
 
 	start = ts2ns(&value->it_value) + 1;
@@ -495,6 +495,32 @@ COBALT_SYSCALL(timer_settime, primary,
 	return 0;
 }
 
+COBALT_SYSCALL(timer_settime64, primary,
+	       (timer_t tm, int flags,
+		const struct __kernel_itimerspec __user *u_newval,
+		struct __kernel_itimerspec __user *u_oldval))
+{
+	struct itimerspec64 newv, oldv, *oldvp = &oldv;
+	int ret;
+
+	if (u_oldval == NULL)
+		oldvp = NULL;
+
+	if (cobalt_get_itimerspec64(&newv, u_newval))
+		return -EFAULT;
+
+	ret = __cobalt_timer_settime(tm, flags, &newv, oldvp);
+	if (ret)
+		return ret;
+
+	if (oldvp && cobalt_put_itimerspec64(u_oldval, oldvp)) {
+		__cobalt_timer_settime(tm, flags, oldvp, NULL);
+		return -EFAULT;
+	}
+
+	return 0;
+}
+
 COBALT_SYSCALL(timer_gettime, current,
 	       (timer_t tm, struct __user_old_itimerspec __user *u_val))
 {
kernel/cobalt/posix/timer.h +5 -0
index 3b580d470..16d3a572a 100644
@@ -78,6 +78,11 @@ COBALT_SYSCALL_DECL(timer_settime,
 		     const struct __user_old_itimerspec __user *u_newval,
 		     struct __user_old_itimerspec __user *u_oldval));
 
+COBALT_SYSCALL_DECL(timer_settime64,
+		    (timer_t tm, int flags,
+		     const struct __kernel_itimerspec __user *u_newval,
+		     struct __kernel_itimerspec __user *u_oldval));
+
 COBALT_SYSCALL_DECL(timer_gettime,
 		    (timer_t tm, struct __user_old_itimerspec __user *u_val));
 
kernel/cobalt/trace/cobalt-posix.h +2 -1
index c7eef7fba..5f99b1162 100644
@@ -168,7 +168,8 @@
 		__cobalt_symbolic_syscall(monitor_wait64),		\
 		__cobalt_symbolic_syscall(event_wait64),		\
 		__cobalt_symbolic_syscall(recvmmsg64),			\
-		__cobalt_symbolic_syscall(cond_wait_prologue64))
+		__cobalt_symbolic_syscall(cond_wait_prologue64),	\
+		__cobalt_symbolic_syscall(timer_settime64))
 
 DECLARE_EVENT_CLASS(cobalt_syscall_entry,
 	TP_PROTO(unsigned int nr),
Signature · 1 line
2.37.1
#23 lore raw

PATCH 23/42 y2038: lib/cobalt: Dispatch timer_settime

In reply to Florian Bezdeka

If libc reports time64_t support, timer_settime is now dispatched to the time64_t based syscall.

---
 lib/cobalt/timer.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
lib/cobalt/timer.c +7 -2
index e3a1e88c2..4a57623c2 100644
@@ -166,8 +166,13 @@ COBALT_IMPL(int, timer_settime, (timer_t timerid,
 {
 	int ret;
 
-	ret = -XENOMAI_SYSCALL4(sc_cobalt_timer_settime, timerid,
-				flags, value, ovalue);
+#ifdef __USE_TIME_BITS64
+	long sc_nr = sc_cobalt_timer_settime64;
+#else
+	long sc_nr = sc_cobalt_timer_settime;
+#endif
+
+	ret = -XENOMAI_SYSCALL4(sc_nr, timerid, flags, value, ovalue);
 	if (ret == 0)
 		return 0;
 
Signature · 1 line
2.37.1
#24 lore raw

PATCH 24/42 y2038: testsuite/smokey/y2038: Adding tests for timer_settime

In reply to Florian Bezdeka

Extending the smokey testsuite to do some tests for the recently added timer_settime syscall.

---
 testsuite/smokey/y2038/syscall-tests.c | 72 ++++++++++++++++++++++++++
 1 file changed, 72 insertions(+)
testsuite/smokey/y2038/syscall-tests.c +72 -0
index 6fcb97cac..8cf533f7a 100644
@@ -25,6 +25,11 @@ struct xn_timespec64 {
 	int64_t tv_nsec;
 };
 
+struct xn_itimerspec64 {
+	struct xn_timespec64 interval;
+	struct xn_timespec64 value;
+};
+
 struct xn_timex_timeval {
 	int64_t tv_sec;
 	int64_t	tv_usec;
@@ -1212,6 +1217,69 @@ out_mutex:
 	return ret;
 }
 
+static int test_sc_cobalt_timer_settime64(void)
+{
+	long sc_nr = sc_cobalt_timer_settime64;
+	struct xn_itimerspec64 its;
+	struct sigevent sev;
+	sigset_t sigset;
+	timer_t t;
+	int sig;
+	int ret;
+
+	sig = SIGUSR1;
+	sigemptyset(&sigset);
+	sigaddset(&sigset, sig);
+
+	memset(&sev, 0, sizeof(sev));
+	memset(&its, 0, sizeof(its));
+
+	sev.sigev_signo = sig;
+	sev.sigev_notify = SIGEV_THREAD_ID | SIGEV_SIGNAL;
+	sev.sigev_notify_thread_id = gettid();
+
+	ret = smokey_check_errno(timer_create(CLOCK_REALTIME, &sev, &t));
+	if (ret)
+		return ret;
+
+	/* Make sure we don't crash because of NULL pointers */
+	ret = XENOMAI_SYSCALL4(sc_nr, t, 0, NULL, NULL);
+	if (ret == -ENOSYS) {
+		smokey_note(
+			"cobalt_timer_settime64: skipped. (no kernel support)");
+		ret = 0;
+		goto out; // Not implemented, nothing to test, success
+	}
+	if (!smokey_assert(ret == -EFAULT)) {
+		ret = ret ?: -EINVAL;
+		goto out;
+	}
+
+	its.value.tv_sec = -1;
+	its.value.tv_nsec = 100000;
+
+	/* Provide an invalid expiration time, should deliver -EINVAL */
+	ret = XENOMAI_SYSCALL4(sc_nr, t, 0, &its, NULL);
+	if (!smokey_assert(ret == -EINVAL)) {
+		ret = ret ?: -EINVAL;
+		goto out;
+	}
+
+	/* Provide a valid expiration time, should succeed */
+	its.value.tv_sec = 0;
+	ret = XENOMAI_SYSCALL4(sc_nr, t, 0, &its, NULL);
+	if (!smokey_assert(!ret))
+		goto out;
+
+	/* Wait for the timer to deliver the signal */
+	sigwait(&sigset, &sig);
+
+out:
+	timer_delete(t);
+
+	return ret;
+}
+
 static int check_kernel_version(void)
 {
 	int ret, major, minor;
@@ -1298,5 +1366,9 @@ static int run_y2038(struct smokey_test *t, int argc, char *const argv[])
 	if (ret)
 		return ret;
 
+	ret = test_sc_cobalt_timer_settime64();
+	if (ret)
+		return ret;
+
 	return 0;
 }
Signature · 1 line
2.37.1
#25 lore raw

PATCH 25/42 y2038: cobalt/posix/timer: Adding timer_gettime64

In reply to Florian Bezdeka

Add a syscall specific for timer_gettime with 64bit time_t.

---
 include/cobalt/uapi/syscall.h      |  1 +
 kernel/cobalt/posix/timer.c        | 13 +++++++++++++
 kernel/cobalt/posix/timer.h        |  3 +++
 kernel/cobalt/trace/cobalt-posix.h |  3 ++-
 4 files changed, 19 insertions(+), 1 deletion(-)
include/cobalt/uapi/syscall.h +1 -0
index 77184bd22..24e759eef 100644
@@ -137,6 +137,7 @@
 #define sc_cobalt_recvmmsg64			114
 #define sc_cobalt_cond_wait_prologue64		115
 #define sc_cobalt_timer_settime64		116
+#define sc_cobalt_timer_gettime64		117
 
 #define __NR_COBALT_SYSCALLS			128 /* Power of 2 */
 
kernel/cobalt/posix/timer.c +13 -0
index b888f1927..37baf7a4a 100644
@@ -534,6 +534,19 @@ COBALT_SYSCALL(timer_gettime, current,
 	return cobalt_put_u_itimerspec(u_val, &val);
 }
 
+COBALT_SYSCALL(timer_gettime64, current,
+	       (timer_t tm, struct __kernel_itimerspec __user *u_val))
+{
+	struct itimerspec64 val;
+	int ret;
+
+	ret = __cobalt_timer_gettime(tm, &val);
+	if (ret)
+		return ret;
+
+	return cobalt_put_itimerspec64(u_val, &val);
+}
+
 COBALT_SYSCALL(timer_getoverrun, current, (timer_t timerid))
 {
 	struct cobalt_timer *timer;
kernel/cobalt/posix/timer.h +3 -0
index 16d3a572a..864c780e8 100644
@@ -86,6 +86,9 @@ COBALT_SYSCALL_DECL(timer_settime64,
 COBALT_SYSCALL_DECL(timer_gettime,
 		    (timer_t tm, struct __user_old_itimerspec __user *u_val));
 
+COBALT_SYSCALL_DECL(timer_gettime64,
+		    (timer_t tm, struct __kernel_itimerspec __user *u_val));
+
 COBALT_SYSCALL_DECL(timer_getoverrun, (timer_t tm));
 
 #endif /* !_COBALT_POSIX_TIMER_H */
kernel/cobalt/trace/cobalt-posix.h +2 -1
index 5f99b1162..dc4f53a5a 100644
@@ -169,7 +169,8 @@
 		__cobalt_symbolic_syscall(event_wait64),		\
 		__cobalt_symbolic_syscall(recvmmsg64),			\
 		__cobalt_symbolic_syscall(cond_wait_prologue64),	\
-		__cobalt_symbolic_syscall(timer_settime64))
+		__cobalt_symbolic_syscall(timer_settime64),		\
+		__cobalt_symbolic_syscall(timer_gettime64))
 
 DECLARE_EVENT_CLASS(cobalt_syscall_entry,
 	TP_PROTO(unsigned int nr),
Signature · 1 line
2.37.1
#26 lore raw

PATCH 26/42 y2038: lib/cobalt: Dispatch timer_gettime

In reply to Florian Bezdeka

If glibc reports time64_t support, timer_gettime is now dispatched to the time64_t based syscall.

---
 lib/cobalt/timer.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
lib/cobalt/timer.c +7 -1
index 4a57623c2..d8955832e 100644
@@ -214,7 +214,13 @@ COBALT_IMPL(int, timer_gettime, (timer_t timerid, struct itimerspec *value))
 {
 	int ret;
 
-	ret = -XENOMAI_SYSCALL2(sc_cobalt_timer_gettime, timerid, value);
+#ifdef __USE_TIME_BITS64
+	long sc_nr = sc_cobalt_timer_gettime64;
+#else
+	long sc_nr = sc_cobalt_timer_gettime;
+#endif
+
+	ret = -XENOMAI_SYSCALL2(sc_nr, timerid, value);
 	if (ret == 0)
 		return 0;
 
Signature · 1 line
2.37.1
#27 lore raw

PATCH 27/42 y2038: testsuite/smokey/y2038: Adding tests for timer_gettime

In reply to Florian Bezdeka

Extending the smokey testsuite to do some tests for the recently added timer_gettime syscall.

---
 testsuite/smokey/y2038/syscall-tests.c | 63 ++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)
testsuite/smokey/y2038/syscall-tests.c +63 -0
index 8cf533f7a..b2cb9da61 100644
@@ -1280,6 +1280,65 @@ out:
 	return ret;
 }
 
+static int test_sc_cobalt_timer_gettime64(void)
+{
+	long sc_nr = sc_cobalt_timer_gettime64;
+	struct xn_itimerspec64 its;
+	struct sigevent sev;
+	sigset_t sigset;
+	timer_t t;
+	int sig;
+	int ret;
+
+	sig = SIGUSR1;
+	sigemptyset(&sigset);
+	sigaddset(&sigset, sig);
+
+	memset(&sev, 0, sizeof(sev));
+	memset(&its, 0, sizeof(its));
+
+	sev.sigev_signo = sig;
+	sev.sigev_notify = SIGEV_THREAD_ID | SIGEV_SIGNAL;
+	sev.sigev_notify_thread_id = gettid();
+
+	ret = smokey_check_errno(timer_create(CLOCK_REALTIME, &sev, &t));
+	if (ret)
+		return ret;
+
+	/* Make sure we don't crash because of NULL pointers */
+	ret = XENOMAI_SYSCALL2(sc_nr, t, NULL);
+	if (ret == -ENOSYS) {
+		smokey_note(
+			"cobalt_timer_gettime64: skipped. (no kernel support)");
+		ret = 0;
+		goto out; // Not implemented, nothing to test, success
+	}
+	if (!smokey_assert(ret == -EFAULT)) {
+		ret = ret ?: -EINVAL;
+		goto out;
+	}
+
+	/*
+	 * Init some random values, allows us to identify that the kernel has
+	 * written the time
+	 */
+	its.value.tv_sec = 123;
+	its.value.tv_nsec = 456;
+
+	/* Fetch the time from the timer, should succeed */
+	ret = XENOMAI_SYSCALL2(sc_nr, t, &its);
+	if (!smokey_assert(!ret))
+		goto out;
+
+	smokey_assert(its.value.tv_sec == 0);
+	smokey_assert(its.value.tv_nsec == 0);
+
+out:
+	timer_delete(t);
+
+	return ret;
+}
+
 static int check_kernel_version(void)
 {
 	int ret, major, minor;
@@ -1370,5 +1429,9 @@ static int run_y2038(struct smokey_test *t, int argc, char *const argv[])
 	if (ret)
 		return ret;
 
+	ret = test_sc_cobalt_timer_gettime64();
+	if (ret)
+		return ret;
+
 	return 0;
 }
Signature · 1 line
2.37.1
#28 lore raw

PATCH 28/42 y2038: cobalt/posix/timerfd: Adding timerfd_settime64

In reply to Florian Bezdeka

Add a syscall specific for timerfd_settime with 64bit time_t.

---
 include/cobalt/uapi/syscall.h      |  1 +
 kernel/cobalt/posix/timerfd.c      | 29 ++++++++++++++++++++++++++++-
 kernel/cobalt/posix/timerfd.h      |  5 +++++
 kernel/cobalt/trace/cobalt-posix.h |  3 ++-
 4 files changed, 36 insertions(+), 2 deletions(-)
include/cobalt/uapi/syscall.h +1 -0
index 24e759eef..b8271618f 100644
@@ -138,6 +138,7 @@
 #define sc_cobalt_cond_wait_prologue64		115
 #define sc_cobalt_timer_settime64		116
 #define sc_cobalt_timer_gettime64		117
+#define sc_cobalt_timerfd_settime64		118
 
 #define __NR_COBALT_SYSCALLS			128 /* Power of 2 */
 
kernel/cobalt/posix/timerfd.c +28 -1
index 2fbe152a5..9b2683ad9 100644
@@ -18,6 +18,7 @@
 
 #include <linux/timerfd.h>
 #include <linux/err.h>
+#include <cobalt/kernel/time.h>
 #include <cobalt/kernel/timer.h>
 #include <cobalt/kernel/select.h>
 #include <rtdm/fd.h>
@@ -295,7 +296,33 @@ COBALT_SYSCALL(timerfd_settime, primary,
 		return ret;
 
 	if (old_value) {
-		ret = cobalt_copy_to_user(old_value, &ovalue, sizeof(ovalue));
+		ret = cobalt_put_u_itimerspec(old_value, &ovalue);
+		value.it_value.tv_sec = 0;
+		value.it_value.tv_nsec = 0;
+		__cobalt_timerfd_settime(fd, flags, &value, NULL);
+	}
+
+	return ret;
+}
+
+COBALT_SYSCALL(timerfd_settime64, primary,
+	       (int fd, int flags,
+		const struct __kernel_itimerspec __user *new_value,
+		struct __kernel_itimerspec __user *old_value))
+{
+	struct itimerspec64 ovalue, value;
+	int ret;
+
+	ret = cobalt_get_itimerspec64(&value, new_value);
+	if (ret)
+		return ret;
+
+	ret = __cobalt_timerfd_settime(fd, flags, &value, &ovalue);
+	if (ret)
+		return ret;
+
+	if (old_value) {
+		ret = cobalt_put_itimerspec64(old_value, &ovalue);
 		value.it_value.tv_sec = 0;
 		value.it_value.tv_nsec = 0;
 		__cobalt_timerfd_settime(fd, flags, &value, NULL);
kernel/cobalt/posix/timerfd.h +5 -0
index 245b8698b..ae9945152 100644
@@ -36,6 +36,11 @@ COBALT_SYSCALL_DECL(timerfd_settime,
 		     const struct __user_old_itimerspec __user *new_value,
 		     struct __user_old_itimerspec __user *old_value));
 
+COBALT_SYSCALL_DECL(timerfd_settime64,
+		    (int fd, int flags,
+		     const struct __kernel_itimerspec __user *new_value,
+		     struct __kernel_itimerspec __user *old_value));
+
 COBALT_SYSCALL_DECL(timerfd_gettime,
 		    (int fd, struct __user_old_itimerspec __user *curr_value));
 
kernel/cobalt/trace/cobalt-posix.h +2 -1
index dc4f53a5a..3d396674c 100644
@@ -170,7 +170,8 @@
 		__cobalt_symbolic_syscall(recvmmsg64),			\
 		__cobalt_symbolic_syscall(cond_wait_prologue64),	\
 		__cobalt_symbolic_syscall(timer_settime64),		\
-		__cobalt_symbolic_syscall(timer_gettime64))
+		__cobalt_symbolic_syscall(timer_gettime64),		\
+		__cobalt_symbolic_syscall(timerfd_settime64))
 
 DECLARE_EVENT_CLASS(cobalt_syscall_entry,
 	TP_PROTO(unsigned int nr),
Signature · 1 line
2.37.1
#29 lore raw

PATCH 29/42 y2038: lib/cobalt: Dispatch timerfd_settime

In reply to Florian Bezdeka

If libc reports time64_t support, timerfd_settime is now dispatched to the time64_t based syscall.

---
 lib/cobalt/timerfd.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
lib/cobalt/timerfd.c +11 -6
index 417e3aad1..a564d5076 100644
@@ -35,14 +35,19 @@ COBALT_IMPL(int, timerfd_create, (int clockid, int flags))
 	return fd;
 }
 
-COBALT_IMPL(int, timerfd_settime, (int fd, int flags,
-		const struct itimerspec *new_value,
-		struct itimerspec *old_value))
+COBALT_IMPL(int, timerfd_settime,
+	    (int fd, int flags, const struct itimerspec *new_value,
+	     struct itimerspec *old_value))
 {
 	int ret;
-	
-	ret = -XENOMAI_SYSCALL4(sc_cobalt_timerfd_settime,
-				fd, flags, new_value, old_value);
+
+#ifdef __USE_TIME_BITS64
+	long sc_nr = sc_cobalt_timerfd_settime64;
+#else
+	long sc_nr = sc_cobalt_timerfd_settime;
+#endif
+
+	ret = -XENOMAI_SYSCALL4(sc_nr, fd, flags, new_value, old_value);
 	if (ret == 0)
 		return ret;
 	
Signature · 1 line
2.37.1
#30 lore raw

PATCH 30/42 y2038: testsuite/smokey/y2038: Adding tests for timerfd_settime

In reply to Florian Bezdeka

Extending the smokey testsuite to do some tests for the recently added timerfd_settime syscall.

---
 testsuite/smokey/y2038/syscall-tests.c | 62 ++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)
testsuite/smokey/y2038/syscall-tests.c +62 -0
index b2cb9da61..371c3a79a 100644
@@ -11,6 +11,7 @@
  */
 #include <asm/xenomai/syscall.h>
 #include <smokey/smokey.h>
+#include <sys/timerfd.h>
 #include <sys/utsname.h>
 #include <mqueue.h>
 #include <rtdm/ipc.h>
@@ -1339,6 +1340,63 @@ out:
 	return ret;
 }
 
+static int test_sc_cobalt_timerfd_settime64(void)
+{
+	long sc_nr = sc_cobalt_timerfd_settime64;
+	struct xn_itimerspec64 its = { 0 };
+	uint64_t buf = 0;
+	ssize_t sz;
+	int ret;
+	int fd;
+
+	fd = smokey_check_errno(timerfd_create(CLOCK_REALTIME, 0));
+	if (fd < 0)
+		return fd;
+
+	/* Make sure we don't crash because of NULL pointers */
+	ret = XENOMAI_SYSCALL4(sc_nr, fd, 0, NULL, NULL);
+	if (ret == -ENOSYS) {
+		smokey_note(
+			"cobalt_timerfd_settime64: skipped. (no kernel support)");
+		ret = 0;
+		goto out; // Not implemented, nothing to test, success
+	}
+	if (!smokey_assert(ret == -EFAULT)) {
+		ret = ret ?: -EINVAL;
+		goto out;
+	}
+
+	its.value.tv_sec = -1;
+	its.value.tv_nsec = 100000;
+
+	/* Provide an invalid expiration time, should deliver -EINVAL */
+	ret = XENOMAI_SYSCALL4(sc_nr, fd, 0, &its, NULL);
+	if (!smokey_assert(ret == -EINVAL)) {
+		ret = ret ?: -EINVAL;
+		goto out;
+	}
+
+	/* Provide a valid expiration time, should succeed */
+	its.value.tv_sec = 0;
+	ret = XENOMAI_SYSCALL4(sc_nr, fd, 0, &its, NULL);
+	if (!smokey_assert(!ret))
+		goto out;
+
+	ret = XENOMAI_SYSCALL4(sc_nr, fd, 0, &its, NULL);
+	if (!smokey_assert(!ret))
+		goto out;
+
+	sz = smokey_check_errno(read(fd, &buf, sizeof(buf)));
+	if (sz != sizeof(buf))
+		goto out;
+
+	smokey_assert(buf == 1);
+out:
+	smokey_check_errno(close(fd));
+
+	return ret;
+}
+
 static int check_kernel_version(void)
 {
 	int ret, major, minor;
@@ -1433,5 +1491,9 @@ static int run_y2038(struct smokey_test *t, int argc, char *const argv[])
 	if (ret)
 		return ret;
 
+	ret = test_sc_cobalt_timerfd_settime64();
+	if (ret)
+		return ret;
+
 	return 0;
 }
Signature · 1 line
2.37.1
#31 lore raw

PATCH 31/42 y2038: cobalt/posix/timerfd: Adding timerfd_gettime64

In reply to Florian Bezdeka

Add a syscall specific for timerfd_gettime with 64bit time_t.

---
 include/cobalt/uapi/syscall.h      |  1 +
 kernel/cobalt/posix/timerfd.c      | 11 +++++++++++
 kernel/cobalt/posix/timerfd.h      |  3 +++
 kernel/cobalt/trace/cobalt-posix.h |  3 ++-
 4 files changed, 17 insertions(+), 1 deletion(-)
include/cobalt/uapi/syscall.h +1 -0
index b8271618f..2dca90071 100644
@@ -139,6 +139,7 @@
 #define sc_cobalt_timer_settime64		116
 #define sc_cobalt_timer_gettime64		117
 #define sc_cobalt_timerfd_settime64		118
+#define sc_cobalt_timerfd_gettime64		119
 
 #define __NR_COBALT_SYSCALLS			128 /* Power of 2 */
 
kernel/cobalt/posix/timerfd.c +11 -0
index 9b2683ad9..ae7578d29 100644
@@ -359,3 +359,14 @@ COBALT_SYSCALL(timerfd_gettime, current,
 
 	return ret ?: cobalt_put_u_itimerspec(curr_value, &value);
 }
+
+COBALT_SYSCALL(timerfd_gettime64, current,
+	       (int fd, struct __kernel_itimerspec __user *curr_value))
+{
+	struct itimerspec64 value;
+	int ret;
+
+	ret = __cobalt_timerfd_gettime(fd, &value);
+
+	return ret ?: cobalt_put_itimerspec64(curr_value, &value);
+}
kernel/cobalt/posix/timerfd.h +3 -0
index ae9945152..b82dac748 100644
@@ -44,4 +44,7 @@ COBALT_SYSCALL_DECL(timerfd_settime64,
 COBALT_SYSCALL_DECL(timerfd_gettime,
 		    (int fd, struct __user_old_itimerspec __user *curr_value));
 
+COBALT_SYSCALL_DECL(timerfd_gettime64,
+		    (int fd, struct __kernel_itimerspec __user *curr_value));
+
 #endif /* TIMERFD_H */
kernel/cobalt/trace/cobalt-posix.h +2 -1
index 3d396674c..f2ffdb3a2 100644
@@ -171,7 +171,8 @@
 		__cobalt_symbolic_syscall(cond_wait_prologue64),	\
 		__cobalt_symbolic_syscall(timer_settime64),		\
 		__cobalt_symbolic_syscall(timer_gettime64),		\
-		__cobalt_symbolic_syscall(timerfd_settime64))
+		__cobalt_symbolic_syscall(timerfd_settime64),		\
+		__cobalt_symbolic_syscall(timerfd_gettime64))
 
 DECLARE_EVENT_CLASS(cobalt_syscall_entry,
 	TP_PROTO(unsigned int nr),
Signature · 1 line
2.37.1
#32 lore raw

PATCH 32/42 y2038: lib/cobalt: Dispatch timerfd_gettime

In reply to Florian Bezdeka

If libc reports time64_t support, timerfd_gettime is now dispatched to the time64_t based syscall.

---
 lib/cobalt/timerfd.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
lib/cobalt/timerfd.c +8 -2
index a564d5076..c0e64929a 100644
@@ -58,8 +58,14 @@ COBALT_IMPL(int, timerfd_settime,
 COBALT_IMPL(int, timerfd_gettime, (int fd, struct itimerspec *curr_value))
 {
 	int ret;
-	
-	ret = -XENOMAI_SYSCALL2(sc_cobalt_timerfd_gettime, fd, curr_value);
+
+#ifdef __USE_TIME_BITS64
+	long sc_nr = sc_cobalt_timerfd_gettime64;
+#else
+	long sc_nr = sc_cobalt_timerfd_gettime;
+#endif
+
+	ret = -XENOMAI_SYSCALL2(sc_nr, fd, curr_value);
 	if (ret == 0)
 		return ret;
 	
Signature · 1 line
2.37.1
#33 lore raw

PATCH 33/42 y2038: testsuite/smokey/y2038: Adding tests for timerfd_gettime

In reply to Florian Bezdeka

Extending the smokey testsuite to do some tests for the recently added timerfd_gettime syscall.

---
 testsuite/smokey/y2038/syscall-tests.c | 50 ++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
testsuite/smokey/y2038/syscall-tests.c +50 -0
index 371c3a79a..e3fa3eb9c 100644
@@ -1397,6 +1397,52 @@ out:
 	return ret;
 }
 
+static int test_sc_cobalt_timerfd_gettime64(void)
+{
+	long sc_nr = sc_cobalt_timerfd_gettime64;
+	struct xn_itimerspec64 its = { 0 };
+	uint64_t buf = 0;
+	int ret;
+	int fd;
+
+	fd = timerfd_create(CLOCK_REALTIME, 0);
+	if (fd == -1)
+		return -errno;
+
+	/* Make sure we don't crash because of NULL pointers */
+	ret = XENOMAI_SYSCALL2(sc_nr, fd, NULL);
+	if (ret == -ENOSYS) {
+		smokey_note(
+			"cobalt_timerfd_gettime64: skipped. (no kernel support)");
+		ret = 0;
+		goto out; // Not implemented, nothing to test, success
+	}
+	if (!smokey_assert(ret == -EFAULT)) {
+		ret = ret ?: -EINVAL;
+		goto out;
+	}
+
+	/*
+	 * Set some random values, allows us to detect that the kernel has
+	 * written the time
+	 */
+	its.value.tv_sec = 123;
+	its.value.tv_nsec = 456;
+
+	/* Fetch the time from the timer, should succeed */
+	ret = XENOMAI_SYSCALL2(sc_nr, fd, &its);
+	if (!smokey_assert(!ret))
+		goto out;
+
+	smokey_assert(buf == 0);
+	smokey_assert(its.value.tv_sec == 0);
+	smokey_assert(its.value.tv_nsec == 0);
+out:
+	smokey_check_errno(close(fd));
+
+	return ret;
+}
+
 static int check_kernel_version(void)
 {
 	int ret, major, minor;
@@ -1495,5 +1541,9 @@ static int run_y2038(struct smokey_test *t, int argc, char *const argv[])
 	if (ret)
 		return ret;
 
+	ret = test_sc_cobalt_timerfd_gettime64();
+	if (ret)
+		return ret;
+
 	return 0;
 }
Signature · 1 line
2.37.1
#34 lore raw

PATCH 34/42 y2038: cobalt/posix/select: Refactor __cobalt_select()

In reply to Florian Bezdeka

There is no y2038 safe select() syscall provided by the kernel. If y2038 safety is required the application should not use select() and move on to something like pselect().

As we still want to support select() for keeping backward compatibility
- even if y2038 safety is requested - an additional pselect() based entry will be introduced soon which will re-use __cobalt_select().

This patch moves all the timeout related userspace copy operations out of __cobalt_select() and migrates __cobalt_select() to struct timespec64. That will allow pselect64() to be based on __cobalt_select() as well.

---
 .../include/asm-generic/xenomai/syscall.h     | 22 +++++++
 kernel/cobalt/posix/clock.h                   |  6 +-
 kernel/cobalt/posix/io.c                      | 62 +++++++++----------
 kernel/cobalt/posix/syscall32.c               | 24 ++++++-
 4 files changed, 78 insertions(+), 36 deletions(-)
kernel/cobalt/include/asm-generic/xenomai/syscall.h +22 -0
index 70b3e68f9..d61b985fb 100644
@@ -138,6 +138,28 @@ static inline int cobalt_put_u_itimerspec(
 	return cobalt_copy_to_user(dst, &u_its, sizeof(*dst));
 }
 
+static inline struct timespec64
+cobalt_timeval_to_timespec64(const struct __kernel_old_timeval *src)
+{
+	struct timespec64 ts;
+
+	ts.tv_sec = src->tv_sec + (src->tv_usec / USEC_PER_SEC);
+	ts.tv_nsec = (src->tv_usec % USEC_PER_SEC) * NSEC_PER_USEC;
+
+	return ts;
+}
+
+static inline struct __kernel_old_timeval
+cobalt_timespec64_to_timeval(const struct timespec64 *src)
+{
+	struct __kernel_old_timeval tv;
+
+	tv.tv_sec = src->tv_sec + (src->tv_nsec / NSEC_PER_SEC);
+	tv.tv_usec = (src->tv_nsec % NSEC_PER_SEC) / NSEC_PER_USEC;
+
+	return tv;
+}
+
 /* 32bit syscall emulation */
 #define __COBALT_COMPAT_BIT	0x1
 /* 32bit syscall emulation - extended form */
kernel/cobalt/posix/clock.h +3 -3
index dbaabbc5d..38b59e24f 100644
@@ -68,12 +68,12 @@ static inline xnticks_t tv2ns(const struct __kernel_old_timeval *tv)
 	return nsecs;
 }
 
-static inline void ticks2tv(struct __kernel_old_timeval *tv, xnticks_t ticks)
+static inline void ticks2ts64(struct timespec64 *ts, xnticks_t ticks)
 {
 	unsigned long nsecs;
 
-	tv->tv_sec = xnclock_divrem_billion(ticks, &nsecs);
-	tv->tv_usec = nsecs / 1000;
+	ts->tv_sec = xnclock_divrem_billion(ticks, &nsecs);
+	ts->tv_nsec = nsecs;
 }
 
 static inline xnticks_t clock_get_ticks(clockid_t clock_id)
kernel/cobalt/posix/io.c +30 -32

101 lines not on this page · raw message

kernel/cobalt/posix/syscall32.c +23 -1
index 10b080dfd..af2365e78 100644
@@ -749,7 +749,29 @@ COBALT_SYSCALL32emu(select, primary,
 		     compat_fd_set __user *u_xfds,
 		     struct old_timeval32 __user *u_tv))
 {
-	return __cobalt_select(nfds, u_rfds, u_wfds, u_xfds, u_tv, true);
+	struct __kernel_old_timeval tv;
+	struct timespec64 ts64, *to = NULL;
+	int ret;
+
+	if (u_tv &&
+	    (!access_ok(u_tv, sizeof(tv)) || sys32_get_timeval(&tv, u_tv)))
+		return -EFAULT;
+
+	if (u_tv) {
+		ts64 = cobalt_timeval_to_timespec64(&tv);
+		to = &ts64;
+	}
+
+	ret = __cobalt_select(nfds, u_rfds, u_wfds, u_xfds, to, true);
+	if (ret)
+		return ret;
+
+	if (u_tv) {
+		tv = cobalt_timespec64_to_timeval(to);
+		ret = sys32_put_timeval(u_tv, &tv);
+	}
+
+	return ret;
 }
 
 COBALT_SYSCALL32emu(recvmsg, handover,
Signature · 1 line
2.37.1
#35 lore raw

PATCH 35/42 y2038: cobalt/posix/select: Adding pselect64

In reply to Florian Bezdeka

This is not a full implementation of pselect() as we do not support waiting for signals yet. The xnsynch infrastructure is not prepared for that.

We will not wrap pselect() in userspace. We will only use the new syscall for providing y2038 safety for select().

Another reason against a full pselec64 implementation is the fact that the XENOMAI_SYSCALLx() infrastructure ends at XENOMAI_SYSCALL5(), a real pselect64() implementation would require XENOMAI_SYSCALL6().

---
 include/cobalt/uapi/syscall.h      |  1 +
 kernel/cobalt/posix/io.c           | 32 ++++++++++++++++++++++++++++++
 kernel/cobalt/posix/io.h           |  8 +++++++-
 kernel/cobalt/trace/cobalt-posix.h |  3 ++-
 4 files changed, 42 insertions(+), 2 deletions(-)
include/cobalt/uapi/syscall.h +1 -0
index 2dca90071..3e65efaab 100644
@@ -140,6 +140,7 @@
 #define sc_cobalt_timer_gettime64		117
 #define sc_cobalt_timerfd_settime64		118
 #define sc_cobalt_timerfd_gettime64		119
+#define sc_cobalt_pselect64			120
 
 #define __NR_COBALT_SYSCALLS			128 /* Power of 2 */
 
kernel/cobalt/posix/io.c +32 -0
index 6709ef639..acfe03329 100644
@@ -390,3 +390,35 @@ COBALT_SYSCALL(select, primary,
 
 	return ret;
 }
+
+COBALT_SYSCALL(pselect64, primary,
+	       (int nfds,
+		fd_set __user *u_rfds,
+		fd_set __user *u_wfds,
+		fd_set __user *u_xfds,
+		struct __kernel_timespec __user *u_ts))
+{
+	struct timespec64 ts64, *to = NULL;
+	int ret = 0;
+
+	if (u_ts) {
+		ret = cobalt_get_timespec64(&ts64, u_ts);
+		to = &ts64;
+	}
+
+	if (ret)
+		return ret;
+
+	ret = __cobalt_select(nfds, u_rfds, u_wfds, u_xfds, to, false);
+	if (ret)
+		return ret;
+
+	/*
+	 * Normally pselect() would not write back the modified timeout. As we
+	 * only use it for keeping select() y2038 safe we do it here as well.
+	 */
+	if (u_ts)
+		ret = cobalt_put_timespec64(&ts64, u_ts);
+
+	return ret;
+}
kernel/cobalt/posix/io.h +7 -1
index 1d9ee0918..ca46aa309 100644
@@ -24,7 +24,7 @@
 #include <cobalt/kernel/select.h>
 
 int __cobalt_select(int nfds, void __user *u_rfds, void __user *u_wfds,
-		    void __user *u_xfds, void __user *u_tv, bool compat);
+		    void __user *u_xfds, struct timespec64 *to, bool compat);
 
 COBALT_SYSCALL_DECL(open,
 		    (const char __user *u_path, int oflag));
@@ -76,4 +76,10 @@ COBALT_SYSCALL_DECL(select,
 		     fd_set __user *u_xfds,
 		     struct __kernel_old_timeval __user *u_tv));
 
+COBALT_SYSCALL_DECL(pselect64, (int nfds,
+				fd_set __user *u_rfds,
+				fd_set __user *u_wfds,
+				fd_set __user *u_xfds,
+				struct __kernel_timespec __user *u_tv));
+
 #endif /* !_COBALT_POSIX_IO_H */
kernel/cobalt/trace/cobalt-posix.h +2 -1
index f2ffdb3a2..47dc77e1c 100644
@@ -172,7 +172,8 @@
 		__cobalt_symbolic_syscall(timer_settime64),		\
 		__cobalt_symbolic_syscall(timer_gettime64),		\
 		__cobalt_symbolic_syscall(timerfd_settime64),		\
-		__cobalt_symbolic_syscall(timerfd_gettime64))
+		__cobalt_symbolic_syscall(timerfd_gettime64),		\
+		__cobalt_symbolic_syscall(pselect64))
 
 DECLARE_EVENT_CLASS(cobalt_syscall_entry,
 	TP_PROTO(unsigned int nr),
Signature · 1 line
2.37.1
#36 lore raw

PATCH 36/42 y2038: testsuite/smokey/y2038: Adding tests for pselect64

In reply to Florian Bezdeka

Extending the smokey testsuite to do some tests for the recently added pselect64 syscall.

---
 testsuite/smokey/y2038/syscall-tests.c | 70 ++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)
testsuite/smokey/y2038/syscall-tests.c +70 -0
index e3fa3eb9c..4fd051932 100644
@@ -1443,6 +1443,72 @@ out:
 	return ret;
 }
 
+static int test_sc_cobalt_pelect64(void)
+{
+	long sc_nr = sc_cobalt_pselect64;
+	struct xn_timespec64 t1, t2;
+	struct timespec ts_nat;
+	int ret;
+
+	/* Supplying an invalid timeout should deliver -EINVAL */
+	t1.tv_sec = -1;
+	t1.tv_nsec = 0;
+	ret = XENOMAI_SYSCALL5(sc_nr, NULL, NULL, NULL, NULL, &t1);
+	if (ret == -ENOSYS) {
+		smokey_note("cobalt_pselect64: skipped. (no kernel support)");
+		ret = 0;
+		goto out; // Not implemented, nothing to test, success
+	}
+	if (!smokey_assert(ret == -EINVAL)) {
+		ret = ret ?: -EINVAL;
+		goto out;
+	}
+
+	/* Supplying an invalid address should deliver -EFAULT */
+	ret = XENOMAI_SYSCALL5(sc_nr, NULL, NULL, NULL, NULL,
+			       (void *)0xdeadbeefUL);
+	if (!smokey_assert(ret == -EFAULT)) {
+		ret = ret ?: -EINVAL;
+		goto out;
+	}
+
+	/*
+	 * Providing a valid timeout, waiting for it to time out and check
+	 * that we didn't come back to early.
+	 */
+	ret = smokey_check_errno(clock_gettime(CLOCK_MONOTONIC, &ts_nat));
+	if (ret)
+		goto out;
+
+	t1.tv_sec = 0;
+	t1.tv_nsec = 500000;
+
+	ret = XENOMAI_SYSCALL5(sc_nr, NULL, NULL, NULL, NULL, &t1);
+	if (!smokey_assert(!ret)) {
+		ret = ret ? ret : -EINVAL;
+		goto out;
+	}
+
+	t1.tv_sec = ts_nat.tv_sec;
+	t1.tv_nsec = ts_nat.tv_nsec;
+
+	ret = smokey_check_errno(clock_gettime(CLOCK_MONOTONIC, &ts_nat));
+	if (ret)
+		goto out;
+
+	t2.tv_sec = ts_nat.tv_sec;
+	t2.tv_nsec = ts_nat.tv_nsec;
+
+	if (ts_less(&t2, &t1))
+		smokey_warning("pselect64 returned to early!\n"
+			       "Expected wakeup at: %lld sec %lld nsec\n"
+			       "Back at           : %lld sec %lld nsec\n",
+			       t1.tv_sec, t1.tv_nsec, t2.tv_sec, t2.tv_nsec);
+
+out:
+	return ret;
+}
+
 static int check_kernel_version(void)
 {
 	int ret, major, minor;
@@ -1545,5 +1611,9 @@ static int run_y2038(struct smokey_test *t, int argc, char *const argv[])
 	if (ret)
 		return ret;
 
+	ret = test_sc_cobalt_pelect64();
+	if (ret)
+		return ret;
+
 	return 0;
 }
Signature · 1 line
2.37.1
#37 lore raw

PATCH 37/42 y2038: kernel/drivers: Implement SO_RCVTIMEO_NEW and SO_SNDTIMEO_NEW

In reply to Florian Bezdeka

When requesting y2038 support from recent glibc versions SO_RCVTIMEO and SO_SNDTIMEO will be auto-converted to the _NEW variants to make clear that we have to deal with a different (now y2038 safe) ABI.

Implementing SO_RCVTIMEO_NEW and SO_SNDTIMEO_NEW where necessary.

---
 kernel/drivers/ipc/bufp.c               | 34 +++++++++++++++++++++++++
 kernel/drivers/ipc/iddp.c               | 34 +++++++++++++++++++++++++
 kernel/drivers/ipc/internal.h           | 27 ++++++++++++++++++++
 kernel/drivers/ipc/rtipc.c              | 29 +++++++++++++++++++++
 kernel/drivers/ipc/xddp.c               | 18 +++++++++++++
 kernel/drivers/net/stack/ipv4/tcp/tcp.c | 31 ++++++++++++++++++++++
 6 files changed, 173 insertions(+)
kernel/drivers/ipc/bufp.c +34 -0
index 565409dd6..f1936d846 100644
@@ -824,6 +824,7 @@ static int __bufp_setsockopt(struct bufp_socket *sk,
 			     void *arg)
 {
 	struct _rtdm_setsockopt_args sopt;
+	struct __kernel_sock_timeval stv;
 	struct rtipc_port_label plabel;
 	struct __kernel_old_timeval tv;
 	rtdm_lockctx_t s;
@@ -844,6 +845,14 @@ static int __bufp_setsockopt(struct bufp_socket *sk,
 			sk->rx_timeout = rtipc_timeval_to_ns(&tv);
 			break;
 
+		case SO_RCVTIMEO_NEW:
+			ret = rtipc_get_sock_timeval(fd, &stv, sopt.optval,
+						     sopt.optlen);
+			if (ret)
+				return ret;
+			sk->rx_timeout = rtipc_sock_timeval_to_ns(&stv);
+			break;
+
 		case SO_SNDTIMEO_OLD:
 			ret = rtipc_get_timeval(fd, &tv, sopt.optval, sopt.optlen);
 			if (ret)
@@ -851,6 +860,14 @@ static int __bufp_setsockopt(struct bufp_socket *sk,
 			sk->tx_timeout = rtipc_timeval_to_ns(&tv);
 			break;
 
+		case SO_SNDTIMEO_NEW:
+			ret = rtipc_get_sock_timeval(fd, &stv, sopt.optval,
+						     sopt.optlen);
+			if (ret)
+				return ret;
+			sk->tx_timeout = rtipc_sock_timeval_to_ns(&stv);
+			break;
+
 		default:
 			ret = -EINVAL;
 		}
@@ -913,6 +930,7 @@ static int __bufp_getsockopt(struct bufp_socket *sk,
 			     void *arg)
 {
 	struct _rtdm_getsockopt_args sopt;
+	struct __kernel_sock_timeval stv;
 	struct rtipc_port_label plabel;
 	struct __kernel_old_timeval tv;
 	rtdm_lockctx_t s;
@@ -936,6 +954,14 @@ static int __bufp_getsockopt(struct bufp_socket *sk,
 				return ret;
 			break;
 
+		case SO_RCVTIMEO_NEW:
+			rtipc_ns_to_sock_timeval(&stv, sk->rx_timeout);
+			ret = rtipc_put_sock_timeval(fd, sopt.optval, &stv,
+						     len);
+			if (ret)
+				return ret;
+			break;
+
 		case SO_SNDTIMEO_OLD:
 			rtipc_ns_to_timeval(&tv, sk->tx_timeout);
 			ret = rtipc_put_timeval(fd, sopt.optval, &tv, len);
@@ -943,6 +969,14 @@ static int __bufp_getsockopt(struct bufp_socket *sk,
 				return ret;
 			break;
 
+		case SO_SNDTIMEO_NEW:
+			rtipc_ns_to_sock_timeval(&stv, sk->tx_timeout);
+			ret = rtipc_put_sock_timeval(fd, sopt.optval, &stv,
+						     len);
+			if (ret)
+				return ret;
+			break;
+
 		default:
 			ret = -EINVAL;
 		}
kernel/drivers/ipc/iddp.c +34 -0
index 05d019339..e4893a378 100644
@@ -704,6 +704,7 @@ static int __iddp_setsockopt(struct iddp_socket *sk,
 			     void *arg)
 {
 	struct _rtdm_setsockopt_args sopt;
+	struct __kernel_sock_timeval stv;
 	struct rtipc_port_label plabel;
 	struct __kernel_old_timeval tv;
 	rtdm_lockctx_t s;
@@ -724,6 +725,14 @@ static int __iddp_setsockopt(struct iddp_socket *sk,
 			sk->rx_timeout = rtipc_timeval_to_ns(&tv);
 			break;
 
+		case SO_RCVTIMEO_NEW:
+			ret = rtipc_get_sock_timeval(fd, &stv, sopt.optval,
+						     sopt.optlen);
+			if (ret)
+				return ret;
+			sk->rx_timeout = rtipc_sock_timeval_to_ns(&stv);
+			break;
+
 		case SO_SNDTIMEO_OLD:
 			ret = rtipc_get_timeval(fd, &tv, sopt.optval, sopt.optlen);
 			if (ret)
@@ -731,6 +740,14 @@ static int __iddp_setsockopt(struct iddp_socket *sk,
 			sk->tx_timeout = rtipc_timeval_to_ns(&tv);
 			break;
 
+		case SO_SNDTIMEO_NEW:
+			ret = rtipc_get_sock_timeval(fd, &stv, sopt.optval,
+						     sopt.optlen);
+			if (ret)
+				return ret;
+			sk->tx_timeout = rtipc_sock_timeval_to_ns(&stv);
+			break;
+
 		default:
 			ret = -EINVAL;
 		}
@@ -793,6 +810,7 @@ static int __iddp_getsockopt(struct iddp_socket *sk,
 			     void *arg)
 {
 	struct _rtdm_getsockopt_args sopt;
+	struct __kernel_sock_timeval stv;
 	struct rtipc_port_label plabel;
 	struct __kernel_old_timeval tv;
 	rtdm_lockctx_t s;
@@ -817,6 +835,14 @@ static int __iddp_getsockopt(struct iddp_socket *sk,
 				return ret;
 			break;
 
+		case SO_RCVTIMEO_NEW:
+			rtipc_ns_to_sock_timeval(&stv, sk->rx_timeout);
+			ret = rtipc_put_sock_timeval(fd, sopt.optval, &stv,
+						     len);
+			if (ret)
+				return ret;
+			break;
+
 		case SO_SNDTIMEO_OLD:
 			rtipc_ns_to_timeval(&tv, sk->tx_timeout);
 			ret = rtipc_put_timeval(fd, sopt.optval, &tv, len);
@@ -824,6 +850,14 @@ static int __iddp_getsockopt(struct iddp_socket *sk,
 				return ret;
 			break;
 
+		case SO_SNDTIMEO_NEW:
+			rtipc_ns_to_sock_timeval(&stv, sk->tx_timeout);
+			ret = rtipc_put_sock_timeval(fd, sopt.optval, &stv,
+						     len);
+			if (ret)
+				return ret;
+			break;
+
 		default:
 			ret = -EINVAL;
 		}
kernel/drivers/ipc/internal.h +27 -0
index 919a5d978..f29ba2204 100644
@@ -76,6 +76,17 @@ static inline nanosecs_rel_t rtipc_timeval_to_ns(const struct __kernel_old_timev
 	return ns;
 }
 
+static inline nanosecs_rel_t
+rtipc_sock_timeval_to_ns(const struct __kernel_sock_timeval *tv)
+{
+	nanosecs_rel_t ns = tv->tv_usec * 1000;
+
+	if (tv->tv_sec)
+		ns += (nanosecs_rel_t)tv->tv_sec * 1000000000UL;
+
+	return ns;
+}
+
 static inline void rtipc_ns_to_timeval(struct __kernel_old_timeval *tv, nanosecs_rel_t ns)
 {
 	unsigned long nsecs;
@@ -84,6 +95,15 @@ static inline void rtipc_ns_to_timeval(struct __kernel_old_timeval *tv, nanosecs
 	tv->tv_usec = nsecs / 1000;
 }
 
+static inline void rtipc_ns_to_sock_timeval(struct __kernel_sock_timeval *tv,
+					    nanosecs_rel_t ns)
+{
+	unsigned long nsecs;
+
+	tv->tv_sec = xnclock_divrem_billion(ns, &nsecs);
+	tv->tv_usec = nsecs / 1000;
+}
+
 int rtipc_get_sockaddr(struct rtdm_fd *fd,
 		       struct sockaddr_ipc **saddrp,
 		       const void *arg);
@@ -105,9 +125,16 @@ int rtipc_get_sockoptin(struct rtdm_fd *fd,
 int rtipc_get_timeval(struct rtdm_fd *fd, struct __kernel_old_timeval *tv,
 		      const void *arg, size_t arglen);
 
+int rtipc_get_sock_timeval(struct rtdm_fd *fd, struct __kernel_sock_timeval *tv,
+			   const void *arg, size_t arglen);
+
 int rtipc_put_timeval(struct rtdm_fd *fd, void *arg,
 		      const struct __kernel_old_timeval *tv, size_t arglen);
 
+int rtipc_put_sock_timeval(struct rtdm_fd *fd, void *arg,
+			   const struct __kernel_sock_timeval *tv,
+			   size_t arglen);
+
 int rtipc_get_length(struct rtdm_fd *fd, size_t *lenp,
 		     const void *arg, size_t arglen);
 
kernel/drivers/ipc/rtipc.c +29 -0
index 211b496ec..66176adad 100644
@@ -290,6 +290,20 @@ int rtipc_get_timeval(struct rtdm_fd *fd, struct __kernel_old_timeval *tv,
 	return rtdm_safe_copy_from_user(fd, tv, arg, sizeof(*tv));
 }
 
+int rtipc_get_sock_timeval(struct rtdm_fd *fd, struct __kernel_sock_timeval *tv,
+			   const void *arg, size_t arglen)
+{
+	if (arglen != sizeof(*tv))
+		return -EINVAL;
+
+	if (!rtdm_fd_is_user(fd)) {
+		*tv = *(struct __kernel_sock_timeval *)arg;
+		return 0;
+	}
+
+	return rtdm_safe_copy_from_user(fd, tv, arg, sizeof(*tv));
+}
+
 int rtipc_put_timeval(struct rtdm_fd *fd, void *arg,
 		      const struct __kernel_old_timeval *tv, size_t arglen)
 {
@@ -312,6 +326,21 @@ int rtipc_put_timeval(struct rtdm_fd *fd, void *arg,
 	return rtdm_safe_copy_to_user(fd, arg, tv, sizeof(*tv));
 }
 
+int rtipc_put_sock_timeval(struct rtdm_fd *fd, void *arg,
+			   const struct __kernel_sock_timeval *tv,
+			   size_t arglen)
+{
+	if (arglen != sizeof(*tv))
+		return -EINVAL;
+
+	if (!rtdm_fd_is_user(fd)) {
+		*(struct __kernel_sock_timeval *)arg = *tv;
+		return 0;
+	}
+
+	return rtdm_safe_copy_to_user(fd, arg, tv, sizeof(*tv));
+}
+
 int rtipc_get_length(struct rtdm_fd *fd, size_t *lenp,
 		     const void *arg, size_t arglen)
 {
kernel/drivers/ipc/xddp.c +18 -0
index 2ca0da5fd..864375d94 100644
@@ -861,6 +861,7 @@ static int __xddp_setsockopt(struct xddp_socket *sk,
 	struct _rtdm_setsockopt_args sopt;
 	struct rtipc_port_label plabel;
 	struct __kernel_old_timeval tv;
+	struct __kernel_sock_timeval stv;
 	rtdm_lockctx_t s;
 	size_t len;
 	int ret;
@@ -879,6 +880,14 @@ static int __xddp_setsockopt(struct xddp_socket *sk,
 			sk->timeout = rtipc_timeval_to_ns(&tv);
 			break;
 
+		case SO_RCVTIMEO_NEW:
+			ret = rtipc_get_sock_timeval(fd, &stv, sopt.optval,
+						     sopt.optlen);
+			if (ret)
+				return ret;
+
+			sk->timeout = rtipc_sock_timeval_to_ns(&stv);
+			break;
 		default:
 			ret = -EINVAL;
 		}
@@ -967,6 +976,7 @@ static int __xddp_getsockopt(struct xddp_socket *sk,
 	struct _rtdm_getsockopt_args sopt;
 	struct rtipc_port_label plabel;
 	struct __kernel_old_timeval tv;
+	struct __kernel_sock_timeval stv;
 	rtdm_lockctx_t s;
 	socklen_t len;
 	int ret;
@@ -988,6 +998,14 @@ static int __xddp_getsockopt(struct xddp_socket *sk,
 				return ret;
 			break;
 
+		case SO_RCVTIMEO_NEW:
+			rtipc_ns_to_sock_timeval(&stv, sk->timeout);
+			ret = rtipc_put_sock_timeval(fd, sopt.optval, &stv,
+						     len);
+			if (ret)
+				return ret;
+			break;
+
 		default:
 			ret = -EINVAL;
 		}
kernel/drivers/net/stack/ipv4/tcp/tcp.c +31 -0
index 71628ba03..5bd114530 100644
@@ -1743,6 +1743,7 @@ static int rt_tcp_setsockopt(struct rtdm_fd *fd, struct tcp_socket *ts,
 			     socklen_t optlen)
 {
 	/* uint64_t val; */
+	struct __kernel_sock_timeval stv;
 	struct __kernel_old_timeval tv;
 	rtdm_lockctx_t context;
 
@@ -1793,6 +1794,36 @@ static int rt_tcp_setsockopt(struct rtdm_fd *fd, struct tcp_socket *ts,
 
 		return 0;
 
+	case SO_SNDTIMEO_NEW:
+		if (optlen < sizeof(stv))
+			return -EINVAL;
+		if (rtdm_copy_from_user(fd, &stv, optval, sizeof(stv)))
+			return -EFAULT;
+		if (stv.tv_usec < 0 || stv.tv_usec >= 1000000)
+			return -EDOM;
+
+		rtdm_lock_get_irqsave(&ts->socket_lock, context);
+
+		if (stv.tv_sec < 0) {
+			ts->sk_sndtimeo = RTDM_TIMEOUT_NONE;
+			rtdm_lock_put_irqrestore(&ts->socket_lock, context);
+			return 0;
+		}
+
+		ts->sk_sndtimeo = RTDM_TIMEOUT_INFINITE;
+		if (stv.tv_sec == 0 && stv.tv_usec == 0) {
+			rtdm_lock_put_irqrestore(&ts->socket_lock, context);
+			return 0;
+		}
+
+		if (stv.tv_sec < (MAX_SCHEDULE_TIMEOUT / 1000000000ull - 1))
+			ts->sk_sndtimeo =
+				(stv.tv_sec * 1000000 + stv.tv_usec) * 1000;
+
+		rtdm_lock_put_irqrestore(&ts->socket_lock, context);
+
+		return 0;
+
 	case SO_REUSEADDR:
 		/* to implement */
 		return -EOPNOTSUPP;
Signature · 1 line
2.37.1
#38 lore raw

PATCH 38/42 y2038: lib/cobalt: Switch vdso to gettime64

In reply to Florian Bezdeka

In case y2038 support was requested we have to switch to the gettime64 variant of the vdso interface.

---
 lib/cobalt/arch/x86/include/asm/xenomai/time.h | 5 +++++
 1 file changed, 5 insertions(+)
lib/cobalt/arch/x86/include/asm/xenomai/time.h +5 -0
index 693be8736..18eb76697 100644
@@ -11,6 +11,11 @@
 #define _LIB_COBALT_X86_TIME_H
 
 #define COBALT_VDSO_VERSION	"LINUX_2.6"
+
+#ifdef __USE_TIME_BITS64
+#define COBALT_VDSO_GETTIME	"__vdso_clock_gettime64"
+#else
 #define COBALT_VDSO_GETTIME	"__vdso_clock_gettime"
+#endif
 
 #endif /* !_LIB_COBALT_X86_TIME_H */
Signature · 1 line
2.37.1
#39 lore raw

PATCH 39/42 rtnet: Enable compat ioctl interface

In reply to Florian Bezdeka

Running rtnet for compat applications failed because the compat ioctl interface was not activated.

---
 kernel/drivers/net/stack/rtnet_chrdev.c | 1 +
 1 file changed, 1 insertion(+)
kernel/drivers/net/stack/rtnet_chrdev.c +1 -0
index 9457661a1..fa859c3bc 100644
@@ -195,6 +195,7 @@ void rtnet_unregister_ioctls(struct rtnet_ioctls *ioctls)
 static struct file_operations rtnet_fops = {
 	.owner = THIS_MODULE,
 	.unlocked_ioctl = rtnet_ioctl,
+	.compat_ioctl = rtnet_ioctl,
 };
 
 static struct miscdevice rtnet_chr_misc_dev = {
Signature · 1 line
2.37.1
#40 lore raw

PATCH 40/42 drivers/rtcan: Implement compat support for the rtcan driver

In reply to Florian Bezdeka

Once Xenomai was running as compat application (=32bit applicaiton over 64bit kernel) the can smokey test failed. This patch fixes the test by implementing the necessary compat bits.

Affected ioctls:
- _RTIOC_BIND
- _RTIOC_SETSOCKOPT

Affected syscalls:
- recvmsg
- sendmsg

---
 include/cobalt/kernel/rtdm/fd.h |  16 +++++
 kernel/cobalt/rtdm/drvlib.c     |  17 +----
 kernel/cobalt/rtdm/fd.c         | 122 ++++++++++++++++++++++++++++++++
 kernel/drivers/can/rtcan_raw.c  |  42 +++++------
 4 files changed, 157 insertions(+), 40 deletions(-)
include/cobalt/kernel/rtdm/fd.h +16 -0
index 058a9c638..176c67e22 100644
@@ -29,6 +29,8 @@
 struct vm_area_struct;
 struct rtdm_fd;
 struct _rtdm_mmap_request;
+struct _rtdm_setsockaddr_args;
+struct _rtdm_setsockopt_args;
 struct xnselector;
 struct cobalt_ppd;
 struct rtdm_device;
@@ -403,6 +405,20 @@ int rtdm_fd_valid_p(int ufd);
 int rtdm_fd_select(int ufd, struct xnselector *selector,
 		   unsigned int type);
 
+int rtdm_fd_get_setsockaddr_args(struct rtdm_fd *fd,
+				 struct _rtdm_setsockaddr_args *dst,
+				 const void *src);
+
+int rtdm_fd_get_setsockopt_args(struct rtdm_fd *fd,
+				struct _rtdm_setsockopt_args *dst,
+				const void *src);
+
+int rtdm_fd_get_iovec(struct rtdm_fd *fd, struct iovec *iov,
+		      const struct user_msghdr *msg, bool rw);
+
+int rtdm_fd_put_iovec(struct rtdm_fd *fd, const struct iovec *iov,
+		      const struct user_msghdr *msg);
+
 int rtdm_device_new_fd(struct rtdm_fd *fd, int ufd,
 		struct rtdm_device *dev);
 
kernel/cobalt/rtdm/drvlib.c +2 -15
index 4eaf3a57c..30455c3d7 100644
@@ -2211,14 +2211,7 @@ int rtdm_get_iovec(struct rtdm_fd *fd, struct iovec **iovp,
 		return 0;
 	}
 
-#ifdef CONFIG_XENO_ARCH_SYS3264
-	if (rtdm_fd_is_compat(fd))
-		return sys32_get_iovec(iov,
-			       (struct compat_iovec __user *)msg->msg_iov,
-			       msg->msg_iovlen);
-#endif
-
-	return rtdm_copy_from_user(fd, iov, msg->msg_iov, len);
+	return rtdm_fd_get_iovec(fd, iov, msg, false);
 }
 EXPORT_SYMBOL_GPL(rtdm_get_iovec);
 
@@ -2233,13 +2226,7 @@ int rtdm_put_iovec(struct rtdm_fd *fd, struct iovec *iov,
 		memcpy(msg->msg_iov, iov, len);
 		ret = 0;
 	} else
-#ifdef CONFIG_XENO_ARCH_SYS3264
-		if (rtdm_fd_is_compat(fd))
-			ret = sys32_put_iovec((struct compat_iovec __user *)msg->msg_iov,
-					      iov, msg->msg_iovlen);
-		else
-#endif
-			ret = rtdm_copy_to_user(fd, msg->msg_iov, iov, len);
+		ret = rtdm_fd_put_iovec(fd, iov, msg);
 
 	if (iov != iov_fast)
 		xnfree(iov);
kernel/cobalt/rtdm/fd.c +122 -0

134 lines not on this page · raw message

kernel/drivers/can/rtcan_raw.c +17 -25

86 lines not on this page · raw message

Signature · 1 line
2.37.1
#41 lore raw

PATCH 41/42 drivers/net/stack/ipv4/udp/udp.c: Add compat support

In reply to Florian Bezdeka

The rtnet interface was lacking compat support for the following ioctl commands:
- _RTIOC_BIND
- _RTIOC_CONNECT

This patch is heavily inspired by Konstantin's proposal but migrated to some rtnet APIs that allow us to stay away from
#ifdef CONFIG_XENO_ARCH_SYS3264
sections.

---
 kernel/drivers/net/stack/ipv4/udp/udp.c | 29 ++++++++++++++-----------
 1 file changed, 16 insertions(+), 13 deletions(-)
kernel/drivers/net/stack/ipv4/udp/udp.c +16 -13
index 5977a3bc2..777c8a27a 100644
@@ -31,6 +31,7 @@
 #include <linux/tcp.h>
 #include <linux/list.h>
 
+#include <rtdm/compat.h>
 #include <rtskb.h>
 #include <rtnet_internal.h>
 #include <rtnet_checksum.h>
@@ -355,25 +356,27 @@ void rt_udp_close(struct rtdm_fd *fd)
 int rt_udp_ioctl(struct rtdm_fd *fd, unsigned int request, void __user *arg)
 {
 	struct rtsocket *sock = rtdm_fd_to_private(fd);
-	const struct _rtdm_setsockaddr_args *setaddr;
-	struct _rtdm_setsockaddr_args _setaddr;
+	struct _rtdm_setsockaddr_args args;
+	bool do_bind = false;
+	int ret;
 
 	/* fast path for common socket IOCTLs */
 	if (_IOC_TYPE(request) == RTIOC_TYPE_NETWORK)
 		return rt_socket_common_ioctl(fd, request, arg);
 
 	switch (request) {
-	case _RTIOC_BIND:
-	case _RTIOC_CONNECT:
-		setaddr = rtnet_get_arg(fd, &_setaddr, arg, sizeof(_setaddr));
-		if (IS_ERR(setaddr))
-			return PTR_ERR(setaddr);
-		if (request == _RTIOC_BIND)
-			return rt_udp_bind(fd, sock, setaddr->addr,
-					   setaddr->addrlen);
-
-		return rt_udp_connect(fd, sock, setaddr->addr,
-				      setaddr->addrlen);
+	COMPAT_CASE(_RTIOC_BIND):
+		do_bind = true;
+		fallthrough;
+	COMPAT_CASE(_RTIOC_CONNECT):
+		ret = rtdm_fd_get_setsockaddr_args(fd, &args, arg);
+		if (ret)
+			return ret;
+
+		if (do_bind)
+			return rt_udp_bind(fd, sock, args.addr, args.addrlen);
+
+		return rt_udp_connect(fd, sock, args.addr, args.addrlen);
 
 	default:
 		return rt_ip_ioctl(fd, request, arg);
Signature · 1 line
2.37.1
#42 lore raw

PATCH 42/42 y2038: lib/cobalt: Add additional time64_t related function wrappers

In reply to Florian Bezdeka

When requesting y2038 support from recent glibc versions some preprocessor magic will happen. clock_nanosleep will be replaced by __clock_nanosleep_time64 for example.

To fix up the necessary function wrapping that we need on linker level we have to wrap all the necessary glibc symbols/functions again.

---
 configure.ac                           |  16 ++-
 lib/cobalt/Makefile.am                 |   7 +
 lib/cobalt/cobalt-y2038-glibc.wrappers |  20 +++
 lib/cobalt/wrappers_y2038.c            | 187 +++++++++++++++++++++++++
 scripts/xeno-config-cobalt.in          |   5 +
 5 files changed, 232 insertions(+), 3 deletions(-)
 create mode 100644 lib/cobalt/cobalt-y2038-glibc.wrappers
 create mode 100644 lib/cobalt/wrappers_y2038.c
configure.ac +13 -3
index ce708a00b..2ab662032 100644
@@ -945,17 +945,27 @@ dnl in-tree executables which require POSIX symbol wrapping.
 
    modechk_wrappers="$topdir/lib/cobalt/modechk.wrappers"
    cobalt_wrappers="$topdir/lib/cobalt/cobalt.wrappers"
+   cobalt_wrappers_y2038_glibc="$topdir/lib/cobalt/cobalt-y2038-glibc.wrappers"
+   all_wrappers="$modechk_wrappers $cobalt_wrappers"
+
+   linker_flags="-Wl,@$modechk_wrappers -Wl,@$cobalt_wrappers"
+
+   if [[ "$CONFIG_XENO_LIBS_Y2038" = "yes" ]]; then
+      all_wrappers="$all_wrappers $cobalt_wrappers_y2038_glibc"
+      linker_flags="$linker_flags -Wl,@$cobalt_wrappers_y2038_glibc"
+   fi
+
    if [[ $ac_cv_ld_file_option = yes ]]; then
-	XENO_POSIX_WRAPPERS="-Wl,@$modechk_wrappers -Wl,@$cobalt_wrappers"
+	XENO_POSIX_WRAPPERS="$linker_flags"
    else
-	XENO_POSIX_WRAPPERS=`cat $modechk_wrappers $cobalt_wrappers | \
+	XENO_POSIX_WRAPPERS=`cat $all_wrappers | \
 			while read wrap_option symbol ; do \
 				echo -n "-Wl,$wrap_option,$symbol " ; \
 			done`
    fi
 
    AC_SUBST(XENO_POSIX_WRAPPERS)
-   AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ["$modechk_wrappers $cobalt_wrappers"])
+   AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ["$all_wrappers"])
 fi
 
 dnl Multi-library support.
lib/cobalt/Makefile.am +7 -0
index 3159695b3..2d9a87497 100644
@@ -38,6 +38,11 @@ libcobalt_la_SOURCES =		\
 	umm.c			\
 	wrappers.c
 
+if CONFIG_XENO_LIBS_Y2038
+libcobalt_la_SOURCES +=         \
+	wrappers_y2038.c
+endif
+
 libcobalt_la_CPPFLAGS =			\
 	@XENO_COBALT_CFLAGS@		\
 	-I$(top_srcdir)/include/cobalt	\
@@ -59,10 +64,12 @@ AM_LIBTOOLFLAGS = --silent
 install-data-local:
 	$(mkinstalldirs) $(DESTDIR)$(libdir)
 	$(INSTALL_DATA) $(srcdir)/cobalt.wrappers $(DESTDIR)$(libdir)
+	$(INSTALL_DATA) $(srcdir)/cobalt-y2038-glibc.wrappers $(DESTDIR)$(libdir)
 	$(INSTALL_DATA) $(srcdir)/modechk.wrappers $(DESTDIR)$(libdir)
 
 uninstall-local:
 	$(RM) $(DESTDIR)$(libdir)/cobalt.wrappers
+	$(RM) $(DESTDIR)$(libdir)/cobalt-y2038-glibc.wrappers
 	$(RM) $(DESTDIR)$(libdir)/modechk.wrappers
 
 EXTRA_DIST = cobalt.wrappers modechk.wrappers
lib/cobalt/cobalt-y2038-glibc.wrappers new file +20 -0
new file mode 100644
index 000000000..036bab044
@@ -0,0 +1,20 @@
+--wrap __sem_timedwait64
+--wrap __clock_gettime64
+--wrap __clock_settime64
+--wrap __clock_nanosleep_time64
+--wrap __clock_getres64
+--wrap __clock_adjtime64
+--wrap __pthread_mutex_timedlock64
+--wrap __mq_timedsend_time64
+--wrap __mq_timedreceive_time64
+--wrap __sigtimedwait64
+--wrap __recvmmsg64
+--wrap __pthread_cond_timedwait64
+--wrap __timer_settime64
+--wrap __timer_gettime64
+--wrap __timerfd_settime64
+--wrap __timerfd_gettime64
+--wrap __setsockopt64
+--wrap __getsockopt64
+--wrap __select64
+--wrap __ioctl_time64
lib/cobalt/wrappers_y2038.c new file +187 -0

187 lines not on this page · raw message

scripts/xeno-config-cobalt.in +5 -0
index a093779b9..ccbc17ccf 100644
@@ -20,6 +20,7 @@ XENO_COBALT_LDFLAGS="-L${staging}${libdir} -lcobalt"
 XENO_POSIX_LDFLAGS="-lpthread -lrt @XENO_USER_APP_LDFLAGS@"
 XENO_LIBRARY_DIR="${staging}${libdir}"
 LD_FILE_OPTION="@LD_FILE_OPTION@"
+CONFIG_XENO_LIBS_Y2038="@CONFIG_XENO_LIBS_Y2038@"
 
 unset skin_list compat codegen
 
@@ -252,6 +253,10 @@ if test x$do_ldflags = xy; then
 	case "$skin" in
 	    posix|rtdm)
 		ldflags="`dump_wrappers cobalt.wrappers` $ldflags"
+
+		if test "$CONFIG_XENO_LIBS_Y2038" = "yes"; then
+			ldflags="$(dump_wrappers cobalt-y2038-glibc.wrappers) $ldflags"
+		fi
 		;;
 	    cobalt)
 		# do NOT wrap POSIX symbols in application code with
Signature · 1 line
2.37.1
#43 lore raw
In reply to Florian Bezdeka
Quoted 8 lines · Florian Bezdeka

Hi all,

it has been a while... I made some progress regarding y2038 support in Xenomai:

With that series applied I'm able to build and run Xenomai including smokey testsuite without any test failures or skipped tests with y2038 support enabled!

Smokey or somkey? ;)

Quoted 6 lines

Preconditions:
--------------
- glibc: You're glibc has to provide y2038 support. glibc >= 2.34 has that.

Quoted 7 lines

- Xenomai: There is a new --enable-y2038 option to enable y2038 support. This option is off per default to keep things disabled for now and avoid breaking any existing application.

When --enable-y2038 is supplied all userspace parts (libcobalt, smokey, ...) will be compiled with y2038 support if glibc supports that. If there is no support in glibc the option will be ignored.

I think we should at least warn during configure of y2038 is available via the libc but not enabled by the user - to slowly push people towards migration.

Quoted 7 lines

Structure of this series:
-------------------------
We start with some cleanups and drive-by fixes followed by adding the missing timer and timerfd support. Finally it cares about select() and some drivers (ioctls) that were missing compat and/or y2038 support.

Quoted 5 lines

Patches 1-12: Cleanup some compat code. As long as there is no
difference between the compat and native syscall entry we do not have to declare them again. The syscall machinery will care about that by placing the native entry point at the compat offset into the syscall table again.

These cases aren't test-covered yet at that point, right? Can we ensure that first?

And what's 13/14 about? Something to pull to the front?

Quoted 2 lines

Patches 15-17: Add gcc 12 support, drive by fixes

Those look like early options as well. Or do they depends on anything in 1-12?

Quoted 7 lines

Patches 18-34: Add y2038 support to timer and timerfd APIs.

Patches 34-37: Add y2038 support to select()
There is no y2038 safe select() out there. Modern applications should switch to modern APIs like pselect().

Quoted 10 lines

Implementing pselect() was not easy:
- We have no support for waiting for signals and fds at the same time inside the xnsynch infrastructure
- We already reached the maximum number of syscall parameters
Solution taken: Implement pselect64() without the sigmask parameter. We do not wrap pselect() in userspace and only use it for select() where the sigmask would be NULL anyhow. So no additional pselect() in our API but select() is now y2038 safe.

So, regular Linux/POSIX application will use pselect when looking for a 2038-safe API, but Xenomai applications will continue to write "select"?

Quoted 6 lines

Patch 38: Switch VDSO to __vdso_clock_gettime64 in case y2038
support was requested.

Patches 39-41: Enable/Fix compat support for drivers covered by the
smokey testsuite.

Shouldn't we pull that to the front to enable compat testing before fiddling with it?

Quoted 16 lines

Patch 42: Add/Enable all additional glibc wrappers necessary for
building with y2038 support enabled.

Testing:
--------
I used Xenomai images for testing but had to switch the distribution from Debian to Ubuntu. There is no Debian version yet that ships an adequate glibc version.

Switching the distribution was not that easy. Ubuntu packages are now compressed using xz which is not yet supported by the Debian package manager. You have to prepare your host environment (kas, kas-container) accordingly.

Quoted 7 lines

As Ubuntu ships a newer python version some ISAR patching was necessary as well. If someone is interested in such changes: Let me know.

Open topics:
------------
- Testing: Integration of compat tests to CI (not really a y2038 topic) See https://gitlab.com/Xenomai/xenomai-hacker-space/-/issues/21

See above: I think this should be done first. Then we could also split the series along
- drive-by fixes
- compat testing, then cleanups
- 2038 finishing and testing

Quoted 5 lines

- Testing: Once compat tests are enabled, try to enable y2038 support

- TCP: The rt_tcp driver does not have compat support yet and is not
covered by the smokey testsuite

Maybe open an issue for that to track it. We have some users of that, though possibly only very few.

Quoted 7 lines

- y2038: Re-visit some y2038 related syscalls like
- sc_cobalt_thread_setschedparam_ex
- sc_cobalt_thread_getschedparam_ex
There is a struct timespec deeply nested in the API. Seems not covered by smokey.

Quoted 7 lines

If someone is interested in helping in those topics: Let us/me know!

With that: Happy reviewing!

The xenomai CI was regularly triggered. I do not expect any build or testing issues.

Thanks,
Jan

Signature · 2 lines
Siemens AG, Technology
Competence Center Embedded Linux
#44 lore raw

Hi Jan,

Quoted 22 lines · Jan Kiszka
Quoted 8 lines · Florian Bezdeka

Hi all,

it has been a while... I made some progress regarding y2038 support in Xenomai:

With that series applied I'm able to build and run Xenomai including smokey testsuite without any test failures or skipped tests with y2038 support enabled!

Smokey or somkey? ;)

Quoted 10 lines

Preconditions:
--------------
- glibc: You're glibc has to provide y2038 support. glibc >= 2.34 has that.

- Xenomai: There is a new --enable-y2038 option to enable y2038 support. This option is off per default to keep things disabled for now and avoid breaking any existing application.

Quoted 7 lines
Quoted 3 lines

When --enable-y2038 is supplied all userspace parts (libcobalt, smokey, ...) will be compiled with y2038 support if glibc supports that. If there is no support in glibc the option will be ignored.

I think we should at least warn during configure of y2038 is available via the libc but not enabled by the user - to slowly push people towards migration.

This is exactly how it is implemented. There will be a warning if y2038 support is available via libc but not enabled.

Quoted 8 lines
Quoted 8 lines

Structure of this series:
-------------------------
We start with some cleanups and drive-by fixes followed by adding the missing timer and timerfd support. Finally it cares about select() and some drivers (ioctls) that were missing compat and/or y2038 support.

Quoted 8 lines
Quoted 5 lines

Patches 1-12: Cleanup some compat code. As long as there is no
difference between the compat and native syscall entry we do not have to declare them again. The syscall machinery will care about that by placing the native entry point at the compat offset into the syscall table again.

These cases aren't test-covered yet at that point, right? Can we ensure that first?

That is tested by the y2038 test in smokey when running in compat mode. But there is no visible difference, it's just unnecessary code.

Quoted 2 lines

And what's 13/14 about? Something to pull to the front?

Patch 13 is a fix for mq_timedsend, Patch 14 fixes a possible resource leak in umm.c. Forgot to mention them, sorry. They are already located at the front, just after the previous cleanups. Reordering is possible, just tell me the order you want to have.

Quoted 6 lines
Quoted 3 lines

Patches 15-17: Add gcc 12 support, drive by fixes

Those look like early options as well. Or do they depends on anything in 1-12?

No, there are no dependencies.

Quoted 19 lines
Quoted 8 lines

Patches 18-34: Add y2038 support to timer and timerfd APIs.

Patches 34-37: Add y2038 support to select()
There is no y2038 safe select() out there. Modern applications should switch to modern APIs like pselect().

Quoted 10 lines

Implementing pselect() was not easy:
- We have no support for waiting for signals and fds at the same time inside the xnsynch infrastructure
- We already reached the maximum number of syscall parameters
Solution taken: Implement pselect64() without the sigmask parameter. We do not wrap pselect() in userspace and only use it for select() where the sigmask would be NULL anyhow. So no additional pselect() in our API but select() is now y2038 safe.

Quoted 2 lines

So, regular Linux/POSIX application will use pselect when looking for a 2038-safe API, but Xenomai applications will continue to write "select"?

My understanding is that select() is now called "legacy" because it uses struct timeval (not struct timespec) and therefore has no support of high time resolutions based on nanoseconds. If you need that (and modern applications are considered to need that) you move on to pselect().

It's not a y2038 topic at first glance, especially because struct timeval was used for relative timeouts.

To keep select() working with y2038 support enabled (ABI change) we have to care about proper function wrapping with proper kernel support.

The userspace part stays as is. select() is still supported (and still no pselect() support) and the kernel part is based on partial pselect().

Quoted 10 lines
Quoted 7 lines

Patch 38: Switch VDSO to __vdso_clock_gettime64 in case y2038
support was requested.

Patches 39-41: Enable/Fix compat support for drivers covered by the
smokey testsuite.

Shouldn't we pull that to the front to enable compat testing before fiddling with it?

The idea was to keep the pipeline green by first fixing the failing tests, then enable them. But yes, if you prefer the other way around, shouldn't be a problem. Reordering of patches should do it.

Quoted 25 lines
Quoted 17 lines

Patch 42: Add/Enable all additional glibc wrappers necessary for
building with y2038 support enabled.

Testing:
--------
I used Xenomai images for testing but had to switch the distribution from Debian to Ubuntu. There is no Debian version yet that ships an adequate glibc version.

Switching the distribution was not that easy. Ubuntu packages are now compressed using xz which is not yet supported by the Debian package manager. You have to prepare your host environment (kas, kas-container) accordingly.

Quoted 7 lines

As Ubuntu ships a newer python version some ISAR patching was necessary as well. If someone is interested in such changes: Let me know.

Open topics:
------------
- Testing: Integration of compat tests to CI (not really a y2038 topic) See https://gitlab.com/Xenomai/xenomai-hacker-space/-/issues/21

Quoted 5 lines

See above: I think this should be done first. Then we could also split the series along
- drive-by fixes
- compat testing, then cleanups
- 2038 finishing and testing

I'm currently looking into the enablement of compat tests. For now I will try to get next compat tested on x86. armhf over arm64 didn't work out of the box. Was that ever supported?

Quoted 9 lines
Quoted 6 lines

- Testing: Once compat tests are enabled, try to enable y2038 support

- TCP: The rt_tcp driver does not have compat support yet and is not
covered by the smokey testsuite

Maybe open an issue for that to track it. We have some users of that, though possibly only very few.

See https://gitlab.com/Xenomai/xenomai-hacker-space/-/issues/34

Quoted 19 lines
Quoted 8 lines

- y2038: Re-visit some y2038 related syscalls like
- sc_cobalt_thread_setschedparam_ex
- sc_cobalt_thread_getschedparam_ex
There is a struct timespec deeply nested in the API. Seems not covered by smokey.

Quoted 7 lines

If someone is interested in helping in those topics: Let us/me know!

With that: Happy reviewing!

The xenomai CI was regularly triggered. I do not expect any build or testing issues.

Thanks,
Jan