xenomai.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 00/14] y2038: Part two - timer and timerfd support
@ 2023-05-15 14:50 Florian Bezdeka
  2023-05-15 14:50 ` [PATCH v2 01/14] y2038: cobalt: Introduce some itimerspec64 related helpers Florian Bezdeka
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: Florian Bezdeka @ 2023-05-15 14:50 UTC (permalink / raw)
  To: xenomai, jan.kiszka; +Cc: Florian Bezdeka

Hi all,

I'm trying to bring the remaining patches from my y2038 queue into Xenomai 
next/master branches. The full queue [1] holds ~20 patches. I'm trying to 
split that up to keep reviewing efforts low.

This series brings y2038 support for
  - timer_settime
  - timer_gettime
  - timerfd_settime
  - timerfd_gettime

Best regards,
Florian

[1] https://gitlab.com/Xenomai/xenomai-hacker-space/-/tree/florian/y2038

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
Changes in v2:
- Patch 1: Remove unnecessary NULL check
- Patch 2: Split timespec validation into separate patch (now Patch 3)
- Patch 3: New patch
- Link to v1: https://lore.kernel.org/r/20230508-florian-y2038-part-two-v1-0-a417812fba85@siemens.com

---
Florian Bezdeka (14):
      y2038: cobalt: Introduce some itimerspec64 related helpers
      y2038: cobalt/posix/timer: Adding timer_settime64
      y2038: cobalt/posix/timer: Use timespec64_valid() for validation
      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

 include/cobalt/kernel/time.h           |  21 +++
 include/cobalt/uapi/syscall.h          |   4 +
 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/time.c                   |  35 +++++
 kernel/cobalt/trace/cobalt-posix.h     |   6 +-
 lib/cobalt/timer.c                     |  17 ++-
 lib/cobalt/timerfd.c                   |  27 ++--
 testsuite/smokey/y2038/syscall-tests.c | 247 +++++++++++++++++++++++++++++++++
 11 files changed, 442 insertions(+), 16 deletions(-)
---
base-commit: 2a60f423f269539f1af0d261810644ed09ee494d
change-id: 20230508-florian-y2038-part-two-7d7864dadd71

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


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

* [PATCH v2 01/14] y2038: cobalt: Introduce some itimerspec64 related helpers
  2023-05-15 14:50 [PATCH v2 00/14] y2038: Part two - timer and timerfd support Florian Bezdeka
@ 2023-05-15 14:50 ` Florian Bezdeka
  2023-05-15 14:50 ` [PATCH v2 02/14] y2038: cobalt/posix/timer: Adding timer_settime64 Florian Bezdeka
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Florian Bezdeka @ 2023-05-15 14:50 UTC (permalink / raw)
  To: xenomai, jan.kiszka; +Cc: Florian Bezdeka

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

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 include/cobalt/kernel/time.h | 21 +++++++++++++++++++++
 kernel/cobalt/time.c         | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+)

diff --git a/include/cobalt/kernel/time.h b/include/cobalt/kernel/time.h
index a55398068..e348cf9b8 100644
--- a/include/cobalt/kernel/time.h
+++ b/include/cobalt/kernel/time.h
@@ -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
diff --git a/kernel/cobalt/time.c b/kernel/cobalt/time.c
index 27dbf8290..d88f2efd8 100644
--- a/kernel/cobalt/time.c
+++ b/kernel/cobalt/time.c
@@ -36,3 +36,38 @@ 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;
+
+	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));
+}

-- 
2.39.2


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

* [PATCH v2 02/14] y2038: cobalt/posix/timer: Adding timer_settime64
  2023-05-15 14:50 [PATCH v2 00/14] y2038: Part two - timer and timerfd support Florian Bezdeka
  2023-05-15 14:50 ` [PATCH v2 01/14] y2038: cobalt: Introduce some itimerspec64 related helpers Florian Bezdeka
@ 2023-05-15 14:50 ` Florian Bezdeka
  2023-05-15 14:50 ` [PATCH v2 03/14] y2038: cobalt/posix/timer: Use timespec64_valid() for validation Florian Bezdeka
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Florian Bezdeka @ 2023-05-15 14:50 UTC (permalink / raw)
  To: xenomai, jan.kiszka; +Cc: Florian Bezdeka

Add a syscall specific for timer_settime with 64bit time_t.

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 include/cobalt/uapi/syscall.h      |  1 +
 kernel/cobalt/posix/timer.c        | 27 +++++++++++++++++++++++++++
 kernel/cobalt/posix/timer.h        |  5 +++++
 kernel/cobalt/trace/cobalt-posix.h |  3 ++-
 4 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/include/cobalt/uapi/syscall.h b/include/cobalt/uapi/syscall.h
index 9646a0d97..77184bd22 100644
--- a/include/cobalt/uapi/syscall.h
+++ b/include/cobalt/uapi/syscall.h
@@ -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 */
 
diff --git a/kernel/cobalt/posix/timer.c b/kernel/cobalt/posix/timer.c
index a115ded53..09843bcfb 100644
--- a/kernel/cobalt/posix/timer.c
+++ b/kernel/cobalt/posix/timer.c
@@ -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>
@@ -495,6 +496,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))
 {
diff --git a/kernel/cobalt/posix/timer.h b/kernel/cobalt/posix/timer.h
index 3b580d470..16d3a572a 100644
--- a/kernel/cobalt/posix/timer.h
+++ b/kernel/cobalt/posix/timer.h
@@ -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));
 
diff --git a/kernel/cobalt/trace/cobalt-posix.h b/kernel/cobalt/trace/cobalt-posix.h
index c7eef7fba..5f99b1162 100644
--- a/kernel/cobalt/trace/cobalt-posix.h
+++ b/kernel/cobalt/trace/cobalt-posix.h
@@ -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),

-- 
2.39.2


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

* [PATCH v2 03/14] y2038: cobalt/posix/timer: Use timespec64_valid() for validation
  2023-05-15 14:50 [PATCH v2 00/14] y2038: Part two - timer and timerfd support Florian Bezdeka
  2023-05-15 14:50 ` [PATCH v2 01/14] y2038: cobalt: Introduce some itimerspec64 related helpers Florian Bezdeka
  2023-05-15 14:50 ` [PATCH v2 02/14] y2038: cobalt/posix/timer: Adding timer_settime64 Florian Bezdeka
@ 2023-05-15 14:50 ` Florian Bezdeka
  2023-05-15 14:50 ` [PATCH v2 04/14] y2038: lib/cobalt: Dispatch timer_settime Florian Bezdeka
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Florian Bezdeka @ 2023-05-15 14:50 UTC (permalink / raw)
  To: xenomai, jan.kiszka; +Cc: Florian Bezdeka

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

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 kernel/cobalt/posix/timer.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/kernel/cobalt/posix/timer.c b/kernel/cobalt/posix/timer.c
index 09843bcfb..3c7579def 100644
--- a/kernel/cobalt/posix/timer.c
+++ b/kernel/cobalt/posix/timer.c
@@ -296,9 +296,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;

-- 
2.39.2


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

* [PATCH v2 04/14] y2038: lib/cobalt: Dispatch timer_settime
  2023-05-15 14:50 [PATCH v2 00/14] y2038: Part two - timer and timerfd support Florian Bezdeka
                   ` (2 preceding siblings ...)
  2023-05-15 14:50 ` [PATCH v2 03/14] y2038: cobalt/posix/timer: Use timespec64_valid() for validation Florian Bezdeka
@ 2023-05-15 14:50 ` Florian Bezdeka
  2023-05-15 14:50 ` [PATCH v2 05/14] y2038: testsuite/smokey/y2038: Adding tests for timer_settime Florian Bezdeka
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Florian Bezdeka @ 2023-05-15 14:50 UTC (permalink / raw)
  To: xenomai, jan.kiszka; +Cc: Florian Bezdeka

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

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 lib/cobalt/timer.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/lib/cobalt/timer.c b/lib/cobalt/timer.c
index e3a1e88c2..4a57623c2 100644
--- a/lib/cobalt/timer.c
+++ b/lib/cobalt/timer.c
@@ -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;
 

-- 
2.39.2


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

* [PATCH v2 05/14] y2038: testsuite/smokey/y2038: Adding tests for timer_settime
  2023-05-15 14:50 [PATCH v2 00/14] y2038: Part two - timer and timerfd support Florian Bezdeka
                   ` (3 preceding siblings ...)
  2023-05-15 14:50 ` [PATCH v2 04/14] y2038: lib/cobalt: Dispatch timer_settime Florian Bezdeka
@ 2023-05-15 14:50 ` Florian Bezdeka
  2023-05-15 14:50 ` [PATCH v2 06/14] y2038: cobalt/posix/timer: Adding timer_gettime64 Florian Bezdeka
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Florian Bezdeka @ 2023-05-15 14:50 UTC (permalink / raw)
  To: xenomai, jan.kiszka; +Cc: Florian Bezdeka

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

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

diff --git a/testsuite/smokey/y2038/syscall-tests.c b/testsuite/smokey/y2038/syscall-tests.c
index ef8c72225..312d1b041 100644
--- a/testsuite/smokey/y2038/syscall-tests.c
+++ b/testsuite/smokey/y2038/syscall-tests.c
@@ -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;
@@ -1301,5 +1369,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;
 }

-- 
2.39.2


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

* [PATCH v2 06/14] y2038: cobalt/posix/timer: Adding timer_gettime64
  2023-05-15 14:50 [PATCH v2 00/14] y2038: Part two - timer and timerfd support Florian Bezdeka
                   ` (4 preceding siblings ...)
  2023-05-15 14:50 ` [PATCH v2 05/14] y2038: testsuite/smokey/y2038: Adding tests for timer_settime Florian Bezdeka
@ 2023-05-15 14:50 ` Florian Bezdeka
  2023-05-15 14:50 ` [PATCH v2 07/14] y2038: lib/cobalt: Dispatch timer_gettime Florian Bezdeka
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Florian Bezdeka @ 2023-05-15 14:50 UTC (permalink / raw)
  To: xenomai, jan.kiszka; +Cc: Florian Bezdeka

Add a syscall specific for timer_gettime with 64bit time_t.

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 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(-)

diff --git a/include/cobalt/uapi/syscall.h b/include/cobalt/uapi/syscall.h
index 77184bd22..24e759eef 100644
--- a/include/cobalt/uapi/syscall.h
+++ b/include/cobalt/uapi/syscall.h
@@ -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 */
 
diff --git a/kernel/cobalt/posix/timer.c b/kernel/cobalt/posix/timer.c
index 3c7579def..0f111a42c 100644
--- a/kernel/cobalt/posix/timer.c
+++ b/kernel/cobalt/posix/timer.c
@@ -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;
diff --git a/kernel/cobalt/posix/timer.h b/kernel/cobalt/posix/timer.h
index 16d3a572a..864c780e8 100644
--- a/kernel/cobalt/posix/timer.h
+++ b/kernel/cobalt/posix/timer.h
@@ -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 */
diff --git a/kernel/cobalt/trace/cobalt-posix.h b/kernel/cobalt/trace/cobalt-posix.h
index 5f99b1162..dc4f53a5a 100644
--- a/kernel/cobalt/trace/cobalt-posix.h
+++ b/kernel/cobalt/trace/cobalt-posix.h
@@ -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),

-- 
2.39.2


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

* [PATCH v2 07/14] y2038: lib/cobalt: Dispatch timer_gettime
  2023-05-15 14:50 [PATCH v2 00/14] y2038: Part two - timer and timerfd support Florian Bezdeka
                   ` (5 preceding siblings ...)
  2023-05-15 14:50 ` [PATCH v2 06/14] y2038: cobalt/posix/timer: Adding timer_gettime64 Florian Bezdeka
@ 2023-05-15 14:50 ` Florian Bezdeka
  2023-05-15 14:50 ` [PATCH v2 08/14] y2038: testsuite/smokey/y2038: Adding tests for timer_gettime Florian Bezdeka
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Florian Bezdeka @ 2023-05-15 14:50 UTC (permalink / raw)
  To: xenomai, jan.kiszka; +Cc: Florian Bezdeka

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

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 lib/cobalt/timer.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/cobalt/timer.c b/lib/cobalt/timer.c
index 4a57623c2..d8955832e 100644
--- a/lib/cobalt/timer.c
+++ b/lib/cobalt/timer.c
@@ -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;
 

-- 
2.39.2


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

* [PATCH v2 08/14] y2038: testsuite/smokey/y2038: Adding tests for timer_gettime
  2023-05-15 14:50 [PATCH v2 00/14] y2038: Part two - timer and timerfd support Florian Bezdeka
                   ` (6 preceding siblings ...)
  2023-05-15 14:50 ` [PATCH v2 07/14] y2038: lib/cobalt: Dispatch timer_gettime Florian Bezdeka
@ 2023-05-15 14:50 ` Florian Bezdeka
  2023-05-15 14:50 ` [PATCH v2 09/14] y2038: cobalt/posix/timerfd: Adding timerfd_settime64 Florian Bezdeka
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Florian Bezdeka @ 2023-05-15 14:50 UTC (permalink / raw)
  To: xenomai, jan.kiszka; +Cc: Florian Bezdeka

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

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

diff --git a/testsuite/smokey/y2038/syscall-tests.c b/testsuite/smokey/y2038/syscall-tests.c
index 312d1b041..069553f37 100644
--- a/testsuite/smokey/y2038/syscall-tests.c
+++ b/testsuite/smokey/y2038/syscall-tests.c
@@ -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;
@@ -1373,5 +1432,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;
 }

-- 
2.39.2


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

* [PATCH v2 09/14] y2038: cobalt/posix/timerfd: Adding timerfd_settime64
  2023-05-15 14:50 [PATCH v2 00/14] y2038: Part two - timer and timerfd support Florian Bezdeka
                   ` (7 preceding siblings ...)
  2023-05-15 14:50 ` [PATCH v2 08/14] y2038: testsuite/smokey/y2038: Adding tests for timer_gettime Florian Bezdeka
@ 2023-05-15 14:50 ` Florian Bezdeka
  2023-05-15 14:50 ` [PATCH v2 10/14] y2038: lib/cobalt: Dispatch timerfd_settime Florian Bezdeka
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Florian Bezdeka @ 2023-05-15 14:50 UTC (permalink / raw)
  To: xenomai, jan.kiszka; +Cc: Florian Bezdeka

Add a syscall specific for timerfd_settime with 64bit time_t.

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 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(-)

diff --git a/include/cobalt/uapi/syscall.h b/include/cobalt/uapi/syscall.h
index 24e759eef..b8271618f 100644
--- a/include/cobalt/uapi/syscall.h
+++ b/include/cobalt/uapi/syscall.h
@@ -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 */
 
diff --git a/kernel/cobalt/posix/timerfd.c b/kernel/cobalt/posix/timerfd.c
index 2fbe152a5..9b2683ad9 100644
--- a/kernel/cobalt/posix/timerfd.c
+++ b/kernel/cobalt/posix/timerfd.c
@@ -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);
diff --git a/kernel/cobalt/posix/timerfd.h b/kernel/cobalt/posix/timerfd.h
index 245b8698b..ae9945152 100644
--- a/kernel/cobalt/posix/timerfd.h
+++ b/kernel/cobalt/posix/timerfd.h
@@ -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));
 
diff --git a/kernel/cobalt/trace/cobalt-posix.h b/kernel/cobalt/trace/cobalt-posix.h
index dc4f53a5a..3d396674c 100644
--- a/kernel/cobalt/trace/cobalt-posix.h
+++ b/kernel/cobalt/trace/cobalt-posix.h
@@ -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),

-- 
2.39.2


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

* [PATCH v2 10/14] y2038: lib/cobalt: Dispatch timerfd_settime
  2023-05-15 14:50 [PATCH v2 00/14] y2038: Part two - timer and timerfd support Florian Bezdeka
                   ` (8 preceding siblings ...)
  2023-05-15 14:50 ` [PATCH v2 09/14] y2038: cobalt/posix/timerfd: Adding timerfd_settime64 Florian Bezdeka
@ 2023-05-15 14:50 ` Florian Bezdeka
  2023-05-15 14:50 ` [PATCH v2 11/14] y2038: testsuite/smokey/y2038: Adding tests for timerfd_settime Florian Bezdeka
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Florian Bezdeka @ 2023-05-15 14:50 UTC (permalink / raw)
  To: xenomai, jan.kiszka; +Cc: Florian Bezdeka

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

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 lib/cobalt/timerfd.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/lib/cobalt/timerfd.c b/lib/cobalt/timerfd.c
index 417e3aad1..a564d5076 100644
--- a/lib/cobalt/timerfd.c
+++ b/lib/cobalt/timerfd.c
@@ -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;
 	

-- 
2.39.2


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

* [PATCH v2 11/14] y2038: testsuite/smokey/y2038: Adding tests for timerfd_settime
  2023-05-15 14:50 [PATCH v2 00/14] y2038: Part two - timer and timerfd support Florian Bezdeka
                   ` (9 preceding siblings ...)
  2023-05-15 14:50 ` [PATCH v2 10/14] y2038: lib/cobalt: Dispatch timerfd_settime Florian Bezdeka
@ 2023-05-15 14:50 ` Florian Bezdeka
  2023-05-15 14:50 ` [PATCH v2 12/14] y2038: cobalt/posix/timerfd: Adding timerfd_gettime64 Florian Bezdeka
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Florian Bezdeka @ 2023-05-15 14:50 UTC (permalink / raw)
  To: xenomai, jan.kiszka; +Cc: Florian Bezdeka

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

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

diff --git a/testsuite/smokey/y2038/syscall-tests.c b/testsuite/smokey/y2038/syscall-tests.c
index 069553f37..87d85b9df 100644
--- a/testsuite/smokey/y2038/syscall-tests.c
+++ b/testsuite/smokey/y2038/syscall-tests.c
@@ -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;
@@ -1436,5 +1494,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;
 }

-- 
2.39.2


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

* [PATCH v2 12/14] y2038: cobalt/posix/timerfd: Adding timerfd_gettime64
  2023-05-15 14:50 [PATCH v2 00/14] y2038: Part two - timer and timerfd support Florian Bezdeka
                   ` (10 preceding siblings ...)
  2023-05-15 14:50 ` [PATCH v2 11/14] y2038: testsuite/smokey/y2038: Adding tests for timerfd_settime Florian Bezdeka
@ 2023-05-15 14:50 ` Florian Bezdeka
  2023-05-15 14:50 ` [PATCH v2 13/14] y2038: lib/cobalt: Dispatch timerfd_gettime Florian Bezdeka
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Florian Bezdeka @ 2023-05-15 14:50 UTC (permalink / raw)
  To: xenomai, jan.kiszka; +Cc: Florian Bezdeka

Add a syscall specific for timerfd_gettime with 64bit time_t.

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 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(-)

diff --git a/include/cobalt/uapi/syscall.h b/include/cobalt/uapi/syscall.h
index b8271618f..2dca90071 100644
--- a/include/cobalt/uapi/syscall.h
+++ b/include/cobalt/uapi/syscall.h
@@ -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 */
 
diff --git a/kernel/cobalt/posix/timerfd.c b/kernel/cobalt/posix/timerfd.c
index 9b2683ad9..ae7578d29 100644
--- a/kernel/cobalt/posix/timerfd.c
+++ b/kernel/cobalt/posix/timerfd.c
@@ -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);
+}
diff --git a/kernel/cobalt/posix/timerfd.h b/kernel/cobalt/posix/timerfd.h
index ae9945152..b82dac748 100644
--- a/kernel/cobalt/posix/timerfd.h
+++ b/kernel/cobalt/posix/timerfd.h
@@ -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 */
diff --git a/kernel/cobalt/trace/cobalt-posix.h b/kernel/cobalt/trace/cobalt-posix.h
index 3d396674c..f2ffdb3a2 100644
--- a/kernel/cobalt/trace/cobalt-posix.h
+++ b/kernel/cobalt/trace/cobalt-posix.h
@@ -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),

-- 
2.39.2


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

* [PATCH v2 13/14] y2038: lib/cobalt: Dispatch timerfd_gettime
  2023-05-15 14:50 [PATCH v2 00/14] y2038: Part two - timer and timerfd support Florian Bezdeka
                   ` (11 preceding siblings ...)
  2023-05-15 14:50 ` [PATCH v2 12/14] y2038: cobalt/posix/timerfd: Adding timerfd_gettime64 Florian Bezdeka
@ 2023-05-15 14:50 ` Florian Bezdeka
  2023-05-15 14:50 ` [PATCH v2 14/14] y2038: testsuite/smokey/y2038: Adding tests for timerfd_gettime Florian Bezdeka
  2023-05-16  6:43 ` [PATCH v2 00/14] y2038: Part two - timer and timerfd support Jan Kiszka
  14 siblings, 0 replies; 16+ messages in thread
From: Florian Bezdeka @ 2023-05-15 14:50 UTC (permalink / raw)
  To: xenomai, jan.kiszka; +Cc: Florian Bezdeka

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

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 lib/cobalt/timerfd.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/lib/cobalt/timerfd.c b/lib/cobalt/timerfd.c
index a564d5076..c0e64929a 100644
--- a/lib/cobalt/timerfd.c
+++ b/lib/cobalt/timerfd.c
@@ -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;
 	

-- 
2.39.2


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

* [PATCH v2 14/14] y2038: testsuite/smokey/y2038: Adding tests for timerfd_gettime
  2023-05-15 14:50 [PATCH v2 00/14] y2038: Part two - timer and timerfd support Florian Bezdeka
                   ` (12 preceding siblings ...)
  2023-05-15 14:50 ` [PATCH v2 13/14] y2038: lib/cobalt: Dispatch timerfd_gettime Florian Bezdeka
@ 2023-05-15 14:50 ` Florian Bezdeka
  2023-05-16  6:43 ` [PATCH v2 00/14] y2038: Part two - timer and timerfd support Jan Kiszka
  14 siblings, 0 replies; 16+ messages in thread
From: Florian Bezdeka @ 2023-05-15 14:50 UTC (permalink / raw)
  To: xenomai, jan.kiszka; +Cc: Florian Bezdeka

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

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

diff --git a/testsuite/smokey/y2038/syscall-tests.c b/testsuite/smokey/y2038/syscall-tests.c
index 87d85b9df..2e3b81e0c 100644
--- a/testsuite/smokey/y2038/syscall-tests.c
+++ b/testsuite/smokey/y2038/syscall-tests.c
@@ -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;
@@ -1498,5 +1544,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;
 }

-- 
2.39.2


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

* Re: [PATCH v2 00/14] y2038: Part two - timer and timerfd support
  2023-05-15 14:50 [PATCH v2 00/14] y2038: Part two - timer and timerfd support Florian Bezdeka
                   ` (13 preceding siblings ...)
  2023-05-15 14:50 ` [PATCH v2 14/14] y2038: testsuite/smokey/y2038: Adding tests for timerfd_gettime Florian Bezdeka
@ 2023-05-16  6:43 ` Jan Kiszka
  14 siblings, 0 replies; 16+ messages in thread
From: Jan Kiszka @ 2023-05-16  6:43 UTC (permalink / raw)
  To: Florian Bezdeka, xenomai

On 15.05.23 16:50, Florian Bezdeka wrote:
> Hi all,
> 
> I'm trying to bring the remaining patches from my y2038 queue into Xenomai 
> next/master branches. The full queue [1] holds ~20 patches. I'm trying to 
> split that up to keep reviewing efforts low.
> 
> This series brings y2038 support for
>   - timer_settime
>   - timer_gettime
>   - timerfd_settime
>   - timerfd_gettime
> 
> Best regards,
> Florian
> 
> [1] https://gitlab.com/Xenomai/xenomai-hacker-space/-/tree/florian/y2038
> 
> Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
> ---
> Changes in v2:
> - Patch 1: Remove unnecessary NULL check
> - Patch 2: Split timespec validation into separate patch (now Patch 3)
> - Patch 3: New patch
> - Link to v1: https://lore.kernel.org/r/20230508-florian-y2038-part-two-v1-0-a417812fba85@siemens.com
> 
> ---
> Florian Bezdeka (14):
>       y2038: cobalt: Introduce some itimerspec64 related helpers
>       y2038: cobalt/posix/timer: Adding timer_settime64
>       y2038: cobalt/posix/timer: Use timespec64_valid() for validation
>       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
> 
>  include/cobalt/kernel/time.h           |  21 +++
>  include/cobalt/uapi/syscall.h          |   4 +
>  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/time.c                   |  35 +++++
>  kernel/cobalt/trace/cobalt-posix.h     |   6 +-
>  lib/cobalt/timer.c                     |  17 ++-
>  lib/cobalt/timerfd.c                   |  27 ++--
>  testsuite/smokey/y2038/syscall-tests.c | 247 +++++++++++++++++++++++++++++++++
>  11 files changed, 442 insertions(+), 16 deletions(-)
> ---
> base-commit: 2a60f423f269539f1af0d261810644ed09ee494d
> change-id: 20230508-florian-y2038-part-two-7d7864dadd71
> 
> Best regards,

Thanks, applied.

Jan

-- 
Siemens AG, Technology
Competence Center Embedded Linux


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

end of thread, other threads:[~2023-05-16  6:44 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-15 14:50 [PATCH v2 00/14] y2038: Part two - timer and timerfd support Florian Bezdeka
2023-05-15 14:50 ` [PATCH v2 01/14] y2038: cobalt: Introduce some itimerspec64 related helpers Florian Bezdeka
2023-05-15 14:50 ` [PATCH v2 02/14] y2038: cobalt/posix/timer: Adding timer_settime64 Florian Bezdeka
2023-05-15 14:50 ` [PATCH v2 03/14] y2038: cobalt/posix/timer: Use timespec64_valid() for validation Florian Bezdeka
2023-05-15 14:50 ` [PATCH v2 04/14] y2038: lib/cobalt: Dispatch timer_settime Florian Bezdeka
2023-05-15 14:50 ` [PATCH v2 05/14] y2038: testsuite/smokey/y2038: Adding tests for timer_settime Florian Bezdeka
2023-05-15 14:50 ` [PATCH v2 06/14] y2038: cobalt/posix/timer: Adding timer_gettime64 Florian Bezdeka
2023-05-15 14:50 ` [PATCH v2 07/14] y2038: lib/cobalt: Dispatch timer_gettime Florian Bezdeka
2023-05-15 14:50 ` [PATCH v2 08/14] y2038: testsuite/smokey/y2038: Adding tests for timer_gettime Florian Bezdeka
2023-05-15 14:50 ` [PATCH v2 09/14] y2038: cobalt/posix/timerfd: Adding timerfd_settime64 Florian Bezdeka
2023-05-15 14:50 ` [PATCH v2 10/14] y2038: lib/cobalt: Dispatch timerfd_settime Florian Bezdeka
2023-05-15 14:50 ` [PATCH v2 11/14] y2038: testsuite/smokey/y2038: Adding tests for timerfd_settime Florian Bezdeka
2023-05-15 14:50 ` [PATCH v2 12/14] y2038: cobalt/posix/timerfd: Adding timerfd_gettime64 Florian Bezdeka
2023-05-15 14:50 ` [PATCH v2 13/14] y2038: lib/cobalt: Dispatch timerfd_gettime Florian Bezdeka
2023-05-15 14:50 ` [PATCH v2 14/14] y2038: testsuite/smokey/y2038: Adding tests for timerfd_gettime Florian Bezdeka
2023-05-16  6:43 ` [PATCH v2 00/14] y2038: Part two - timer and timerfd support Jan Kiszka

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