Skip to contentSkip to conversation

y2038: Adding event_wait64()

PATCH Superseded Florian Bezdeka 1 participant 4 messages Aug 11, 2021

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover y2038: Adding event_wait64()

Hi!

Just another y2038 related syscall, once again based on v1 sent out by Song and rebased to current next with some code- and test-cleanups applied.

@Song:
This one was the last one in my inbox. Please make sure that all following patches are based on next. IIRC there are 3 or 4 syscalls remaining. We should take care of [1] as well. We need something in the CI that tests the full implementation, i.e. including the glibc wrappers (proper syscall delegation). Recent glibc should allow us to use 64bit time_t.

[1]: https://gitlab.com/Xenomai/xenomai-hacker-space/-/issues/21

Best regards,
Florian

Changes in v3:
- None. git send-mail folded two different series together. Resending to allow maintainers to pick this series at once. Sorry for that.

Florian Bezdeka (1):
y2038: testsuite/smokey/y2038: Adding tests for event_wait64

Song Chen (2):
y2038: cobalt/posix/event: Adding event_wait64
y2038: lib/cobalt/internal: dispatch event_wait

 include/cobalt/uapi/syscall.h          |  1 +
 kernel/cobalt/posix/event.c            | 34 ++++++++++-
 kernel/cobalt/posix/event.h            | 12 ++++
 kernel/cobalt/posix/syscall32.c        |  9 +++
 kernel/cobalt/posix/syscall32.h        |  7 +++
 kernel/cobalt/trace/cobalt-posix.h     |  3 +-
 lib/cobalt/internal.c                  |  5 ++
 testsuite/smokey/y2038/syscall-tests.c | 78 +++++++++++++++++++++++---
 8 files changed, 136 insertions(+), 13 deletions(-)
Signature · 1 line
2.30.2
#1 lore raw

PATCH v3 1/3 y2038: cobalt/posix/event: Adding event_wait64

From: Song Chen <[email protected]>

Add a syscall specific for event_wait with 64bit time_t.

[Florian: Tracing, reformatting/rebasing]
---
 include/cobalt/uapi/syscall.h      |  1 +
 kernel/cobalt/posix/event.c        | 34 +++++++++++++++++++++++++++---
 kernel/cobalt/posix/event.h        | 12 +++++++++++
 kernel/cobalt/posix/syscall32.c    |  9 ++++++++
 kernel/cobalt/posix/syscall32.h    |  7 ++++++
 kernel/cobalt/trace/cobalt-posix.h |  3 ++-
 6 files changed, 62 insertions(+), 4 deletions(-)
include/cobalt/uapi/syscall.h +1 -0
index e49110f5d..16edce15d 100644
@@ -133,6 +133,7 @@
 #define sc_cobalt_mq_timedreceive64		110
 #define sc_cobalt_sigtimedwait64		111
 #define sc_cobalt_monitor_wait64		112
+#define sc_cobalt_event_wait64			113
 
 #define __NR_COBALT_SYSCALLS			128 /* Power of 2 */
 
kernel/cobalt/posix/event.c +31 -3
index 3712154f5..052c68605 100644
@@ -20,6 +20,7 @@
 #include "clock.h"
 #include "event.h"
 #include <trace/events/cobalt-posix.h>
+#include <cobalt/kernel/time.h>
 
 /*
  * Cobalt event notification services
@@ -119,9 +120,9 @@ int __cobalt_event_wait(struct cobalt_event_shadow __user *u_event,
 	handle = cobalt_get_handle_from_user(&u_event->handle);
 
 	if (ts) {
-		if ((unsigned long)ts->tv_nsec >= ONE_BILLION)
+		if (!timespec64_valid(ts))
 			return -EINVAL;
-	
+
 		timeout = ts2ns(ts);
 		if (timeout) {
 			timeout++;
@@ -189,6 +190,24 @@ 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)
+{
+	struct timespec64 ts, *tsp = NULL;
+	int ret;
+
+	if (u_ts) {
+		tsp = &ts;
+		ret = cobalt_get_timespec64(&ts, u_ts);
+		if (ret)
+			return ret;
+	}
+
+	return __cobalt_event_wait(u_event, bits, u_bits_r, mode, tsp);
+}
+
 COBALT_SYSCALL(event_wait, primary,
 	       (struct cobalt_event_shadow __user *u_event,
 		unsigned int bits,
@@ -208,6 +227,15 @@ 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))
 {
@@ -278,7 +306,7 @@ COBALT_SYSCALL(event_destroy, current,
 	}
 
 	cobalt_event_reclaim(&event->resnode, s); /* drops lock */
-	
+
 	return 0;
 }
 
kernel/cobalt/posix/event.h +12 -0
index ef592f72c..919774c9a 100644
@@ -41,6 +41,11 @@ 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,
@@ -53,6 +58,13 @@ COBALT_SYSCALL_DECL(event_wait,
 		     int mode,
 		     const struct __user_old_timespec __user *u_ts));
 
+COBALT_SYSCALL_DECL(event_wait64,
+		    (struct cobalt_event_shadow __user *u_evtsh,
+		     unsigned int bits,
+		     unsigned int __user *u_bits_r,
+		     int mode,
+		     const struct __kernel_timespec __user *u_ts));
+
 COBALT_SYSCALL_DECL(event_sync,
 		    (struct cobalt_event_shadow __user *u_evtsh));
 
kernel/cobalt/posix/syscall32.c +9 -0
index e6c9831b9..2d88fac83 100644
@@ -795,6 +795,15 @@ 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 +7 -0
index a2ef67808..3eb66571b 100644
@@ -230,6 +230,13 @@ 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,
kernel/cobalt/trace/cobalt-posix.h +2 -1
index 221e25037..45e3cbcf7 100644
@@ -165,7 +165,8 @@
 		__cobalt_symbolic_syscall(mq_timedsend64),  		\
 		__cobalt_symbolic_syscall(mq_timedreceive64),		\
 		__cobalt_symbolic_syscall(sigtimedwait64),		\
-		__cobalt_symbolic_syscall(monitor_wait64))
+		__cobalt_symbolic_syscall(monitor_wait64),		\
+		__cobalt_symbolic_syscall(event_wait64))
 
 DECLARE_EVENT_CLASS(cobalt_syscall_entry,
 	TP_PROTO(unsigned int nr),
Signature · 1 line
2.30.2
#2 lore raw

PATCH v3 2/3 y2038: lib/cobalt/internal: dispatch event_wait

In reply to Florian Bezdeka

From: Song Chen <[email protected]>

If sizeof time_t bigger than 4, which means glibc supports 64bit timespec, go to event_wait64.

otherwise, go to original event_wait.

---
 lib/cobalt/internal.c | 5 +++++
 1 file changed, 5 insertions(+)
lib/cobalt/internal.c +5 -0
index 75933a830..bf1e940b7 100644
@@ -483,8 +483,13 @@ int cobalt_event_wait(cobalt_event_t *event,
 
 	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
 
+#ifdef __USE_TIME_BITS64
+	ret = XENOMAI_SYSCALL5(sc_cobalt_event_wait64,
+			       event, bits, bits_r, mode, timeout);
+#else
 	ret = XENOMAI_SYSCALL5(sc_cobalt_event_wait,
 			       event, bits, bits_r, mode, timeout);
+#endif
 
 	pthread_setcanceltype(oldtype, NULL);
 
Signature · 1 line
2.30.2
#3 lore raw

PATCH v3 3/3 y2038: testsuite/smokey/y2038: Adding tests for event_wait64

In reply to Florian Bezdeka

Based on the tests provided by Song, slightly adjusted, #includes cleaned up and making sure all resources used during tests have been cleaned up as well.

---
 testsuite/smokey/y2038/syscall-tests.c | 80 +++++++++++++++++++++++---
 1 file changed, 71 insertions(+), 9 deletions(-)
testsuite/smokey/y2038/syscall-tests.c +71 -9
index 839a50e07..7add1c454 100644
@@ -10,17 +10,8 @@
  * Released under the terms of GPLv2.
  */
 #include <asm/xenomai/syscall.h>
-#include <cobalt/uapi/syscall.h>
 #include <smokey/smokey.h>
-#include <semaphore.h>
-#include <unistd.h>
-#include <stdint.h>
-#include <stdbool.h>
-#include <errno.h>
 #include <mqueue.h>
-#include <signal.h>
-#include <cobalt/uapi/monitor.h>
-#include <sys/cobalt.h>
 
 smokey_test_plugin(y2038, SMOKEY_NOARGS, "Validate correct y2038 support");
 
@@ -916,6 +907,73 @@ static int test_sc_cobalt_monitor_wait64(void)
 	return 0;
 }
 
+static int test_sc_cobalt_event_wait64(void)
+{
+	int ret;
+	int sc_nr = sc_cobalt_event_wait64;
+	struct xn_timespec64 t1, t2;
+	struct timespec ts_nat;
+	struct cobalt_event_shadow evt;
+	unsigned int flags;
+
+	ret = cobalt_event_init(&evt, 0, COBALT_EVENT_FIFO);
+	if (ret)
+		return -errno;
+
+	/* Make sure we don't crash because of NULL pointers */
+	ret = XENOMAI_SYSCALL5(sc_nr, NULL, NULL, NULL, NULL, NULL);
+	if (ret == -ENOSYS) {
+		smokey_note("event_wait64: skipped. (no kernel support)");
+		return 0; // Not implemented, nothing to test, success
+	}
+	if (!smokey_assert(ret == -EINVAL))
+		return ret ? ret : -EINVAL;
+
+	/* Providing an invalid address has to deliver EFAULT */
+	ret = XENOMAI_SYSCALL5(sc_nr, &evt, 0x1, &flags, 0,
+			       (void *)0xdeadbeefUL);
+	if (!smokey_assert(ret == -EFAULT))
+		return ret ? ret : -EINVAL;
+
+	/* providing an invalid timeout has to deliver EINVAL */
+	t1.tv_sec = -1;
+	ret = XENOMAI_SYSCALL5(sc_nr, &evt, 0x1, &flags, 0, &t1);
+	if (!smokey_assert(ret == -EINVAL))
+		return ret ? ret : -EINVAL;
+
+	/*
+	 * Providing a valid timeout, waiting for it to time out and check
+	 * that we didn't come back to early.
+	 */
+	ret = clock_gettime(CLOCK_REALTIME, &ts_nat);
+	if (ret)
+		return -errno;
+
+	t1.tv_sec = 0;
+	t1.tv_nsec = 500000;
+
+	ret = XENOMAI_SYSCALL5(sc_nr, &evt, 0x1, &flags, 0, &t1);
+	if (!smokey_assert(ret == -ETIMEDOUT))
+		return ret;
+
+	ret = clock_gettime(CLOCK_REALTIME, &ts_nat);
+	if (ret)
+		return -errno;
+
+	t2.tv_sec = ts_nat.tv_sec;
+	t2.tv_nsec = ts_nat.tv_nsec;
+
+	if (ts_less(&t2, &t1))
+		smokey_warning("event_wait64 returned too 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);
+
+	cobalt_event_destroy(&evt);
+
+	return 0;
+}
+
 static int run_y2038(struct smokey_test *t, int argc, char *const argv[])
 {
 	int ret;
@@ -964,5 +1022,9 @@ static int run_y2038(struct smokey_test *t, int argc, char *const argv[])
 	if (ret)
 		return ret;
 
+	ret = test_sc_cobalt_event_wait64();
+	if (ret)
+		return ret;
+
 	return 0;
 }
Signature · 1 line
2.30.2