All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] y2038: sigtimedwait64
@ 2021-08-10 15:27 Florian Bezdeka
  2021-08-10 15:27 ` [PATCH v2 1/3] y2038: cobalt/posix/signal: Adding sigtimedwait64 Florian Bezdeka
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Florian Bezdeka @ 2021-08-10 15:27 UTC (permalink / raw)
  To: xenomai

Hi!

Here comes the next y2038 related syscall implementation. Once again
based on v1 sent out by Song. I had to rework the patches a bit, mostly
to stay POSIX compatible (EAGAIN vs. ETIMEOUT) and necessary test
adjustments and improvements.

Best regards,
Florian

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

Song Chen (2):
  y2038: cobalt/posix/signal: Adding sigtimedwait64
  y2038: lib/cobalt/signal: dispatch sigtimedwait

 include/cobalt/uapi/syscall.h          |  1 +
 kernel/cobalt/posix/signal.c           | 21 ++++++-
 kernel/cobalt/posix/signal.h           |  5 ++
 kernel/cobalt/posix/syscall32.c        | 21 +++++++
 kernel/cobalt/posix/syscall32.h        |  5 ++
 kernel/cobalt/trace/cobalt-posix.h     |  4 +-
 lib/cobalt/signal.c                    |  4 ++
 testsuite/smokey/y2038/syscall-tests.c | 80 ++++++++++++++++++++++++++
 8 files changed, 137 insertions(+), 4 deletions(-)

-- 
2.30.2



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

* [PATCH v2 1/3] y2038: cobalt/posix/signal: Adding sigtimedwait64
  2021-08-10 15:27 [PATCH v2 0/3] y2038: sigtimedwait64 Florian Bezdeka
@ 2021-08-10 15:27 ` Florian Bezdeka
  2021-08-10 15:27 ` [PATCH v2 2/3] y2038: lib/cobalt/signal: dispatch sigtimedwait Florian Bezdeka
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Florian Bezdeka @ 2021-08-10 15:27 UTC (permalink / raw)
  To: xenomai

From: Song Chen <chensong_2000@189.cn>

Add a syscall specific for sigtimedwait with 64bit
time_t.

Signed-off-by: Song Chen <chensong_2000@189.cn>
[Florian: Tracing, fix return value EAGAIN vs. ETIMEOUT]
Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 include/cobalt/uapi/syscall.h      |  1 +
 kernel/cobalt/posix/signal.c       | 21 +++++++++++++++++++--
 kernel/cobalt/posix/signal.h       |  5 +++++
 kernel/cobalt/posix/syscall32.c    | 21 +++++++++++++++++++++
 kernel/cobalt/posix/syscall32.h    |  5 +++++
 kernel/cobalt/trace/cobalt-posix.h |  4 ++--
 6 files changed, 53 insertions(+), 4 deletions(-)

diff --git a/include/cobalt/uapi/syscall.h b/include/cobalt/uapi/syscall.h
index c27d6d044..4de7e59d0 100644
--- a/include/cobalt/uapi/syscall.h
+++ b/include/cobalt/uapi/syscall.h
@@ -131,6 +131,7 @@
 #define sc_cobalt_mutex_timedlock64		108
 #define sc_cobalt_mq_timedsend64		109
 #define sc_cobalt_mq_timedreceive64		110
+#define sc_cobalt_sigtimedwait64		111
 
 #define __NR_COBALT_SYSCALLS			128 /* Power of 2 */
 
diff --git a/kernel/cobalt/posix/signal.c b/kernel/cobalt/posix/signal.c
index 0b43b5fcf..e3ba3abcf 100644
--- a/kernel/cobalt/posix/signal.c
+++ b/kernel/cobalt/posix/signal.c
@@ -18,6 +18,7 @@
 #include <linux/sched.h>
 #include <cobalt/kernel/assert.h>
 #include <cobalt/kernel/compat.h>
+#include <cobalt/kernel/time.h>
 #include "internal.h"
 #include "signal.h"
 #include "thread.h"
@@ -413,9 +414,8 @@ int __cobalt_sigtimedwait(sigset_t *set,
 {
 	xnticks_t ticks;
 
-	if ((unsigned long)timeout->tv_nsec >= ONE_BILLION)
+	if (!timespec64_valid(timeout))
 		return -EINVAL;
-
 	ticks = ts2ns(timeout);
 	if (ticks++ == 0)
 		ticks = XN_NONBLOCK;
@@ -440,6 +440,23 @@ COBALT_SYSCALL(sigtimedwait, nonrestartable,
 	return __cobalt_sigtimedwait(&set, &timeout, u_si, false);
 }
 
+COBALT_SYSCALL(sigtimedwait64, nonrestartable,
+	       (const sigset_t __user *u_set,
+		struct siginfo __user *u_si,
+		const struct __kernel_timespec __user *u_timeout))
+{
+	struct timespec64 timeout;
+	sigset_t set;
+
+	if (cobalt_copy_from_user(&set, u_set, sizeof(set)))
+		return -EFAULT;
+
+	if (cobalt_get_timespec64(&timeout, u_timeout))
+		return -EFAULT;
+
+	return __cobalt_sigtimedwait(&set, &timeout, u_si, false);
+}
+
 int __cobalt_sigwaitinfo(sigset_t *set,
 			 void __user *u_si,
 			 bool compat)
diff --git a/kernel/cobalt/posix/signal.h b/kernel/cobalt/posix/signal.h
index fc26ad065..121db8f9b 100644
--- a/kernel/cobalt/posix/signal.h
+++ b/kernel/cobalt/posix/signal.h
@@ -96,6 +96,11 @@ COBALT_SYSCALL_DECL(sigtimedwait,
 		     struct siginfo __user *u_si,
 		     const struct __user_old_timespec __user *u_timeout));
 
+COBALT_SYSCALL_DECL(sigtimedwait64,
+		    (const sigset_t __user *u_set,
+		     struct siginfo __user *u_si,
+		     const struct __kernel_timespec __user *u_timeout));
+
 COBALT_SYSCALL_DECL(sigwaitinfo,
 		    (const sigset_t __user *u_set,
 		     struct siginfo __user *u_si));
diff --git a/kernel/cobalt/posix/syscall32.c b/kernel/cobalt/posix/syscall32.c
index d52be0207..79fc365fc 100644
--- a/kernel/cobalt/posix/syscall32.c
+++ b/kernel/cobalt/posix/syscall32.c
@@ -18,6 +18,7 @@
 #include <linux/types.h>
 #include <linux/err.h>
 #include <cobalt/uapi/syscall.h>
+#include <cobalt/kernel/time.h>
 #include <xenomai/rtdm/internal.h>
 #include "internal.h"
 #include "syscall32.h"
@@ -696,6 +697,26 @@ COBALT_SYSCALL32emu(sigtimedwait, nonrestartable,
 	return __cobalt_sigtimedwait(&set, &timeout, u_si, true);
 }
 
+COBALT_SYSCALL32emu(sigtimedwait64, nonrestartable,
+		    (const compat_sigset_t __user *u_set,
+		     struct compat_siginfo __user *u_si,
+		     const struct __kernel_timespec __user *u_timeout))
+{
+	struct timespec64 timeout;
+	sigset_t set;
+	int ret;
+
+	ret = sys32_get_sigset(&set, u_set);
+	if (ret)
+		return ret;
+
+	ret = cobalt_get_timespec64(&timeout, u_timeout);
+	if (ret)
+		return ret;
+
+	return __cobalt_sigtimedwait(&set, &timeout, u_si, true);
+}
+
 COBALT_SYSCALL32emu(sigwaitinfo, nonrestartable,
 		    (const compat_sigset_t __user *u_set,
 		     struct compat_siginfo __user *u_si))
diff --git a/kernel/cobalt/posix/syscall32.h b/kernel/cobalt/posix/syscall32.h
index 006054e85..cf295ed5e 100644
--- a/kernel/cobalt/posix/syscall32.h
+++ b/kernel/cobalt/posix/syscall32.h
@@ -197,6 +197,11 @@ COBALT_SYSCALL32emu_DECL(sigtimedwait,
 			  struct compat_siginfo __user *u_si,
 			  const struct old_timespec32 __user *u_timeout));
 
+COBALT_SYSCALL32emu_DECL(sigtimedwait64,
+			 (const compat_sigset_t __user *u_set,
+			  struct compat_siginfo __user *u_si,
+			  const struct __kernel_timespec __user *u_timeout));
+
 COBALT_SYSCALL32emu_DECL(sigwaitinfo,
 			 (const compat_sigset_t __user *u_set,
 			  struct compat_siginfo __user *u_si));
diff --git a/kernel/cobalt/trace/cobalt-posix.h b/kernel/cobalt/trace/cobalt-posix.h
index b046c8a0e..5d14d851f 100644
--- a/kernel/cobalt/trace/cobalt-posix.h
+++ b/kernel/cobalt/trace/cobalt-posix.h
@@ -163,8 +163,8 @@
 		__cobalt_symbolic_syscall(clock_adjtime64),		\
 		__cobalt_symbolic_syscall(mutex_timedlock64),		\
 		__cobalt_symbolic_syscall(mq_timedsend64),  		\
-		__cobalt_symbolic_syscall(mq_timedreceive64))
-
+		__cobalt_symbolic_syscall(mq_timedreceive64),		\
+		__cobalt_symbolic_syscall(sigtimedwait64))
 
 DECLARE_EVENT_CLASS(cobalt_syscall_entry,
 	TP_PROTO(unsigned int nr),
-- 
2.30.2



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

* [PATCH v2 2/3] y2038: lib/cobalt/signal: dispatch sigtimedwait
  2021-08-10 15:27 [PATCH v2 0/3] y2038: sigtimedwait64 Florian Bezdeka
  2021-08-10 15:27 ` [PATCH v2 1/3] y2038: cobalt/posix/signal: Adding sigtimedwait64 Florian Bezdeka
@ 2021-08-10 15:27 ` Florian Bezdeka
  2021-08-10 15:27 ` [PATCH v2 3/3] y2038: testsuite/smokey/y2038: Adding tests for sigtimedwait64 Florian Bezdeka
  2021-08-10 16:46 ` [PATCH v2 0/3] y2038: sigtimedwait64 Jan Kiszka
  3 siblings, 0 replies; 5+ messages in thread
From: Florian Bezdeka @ 2021-08-10 15:27 UTC (permalink / raw)
  To: xenomai

From: Song Chen <chensong_2000@189.cn>

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

otherwise, go to original sigtimedwait.

Signed-off-by: Song Chen <chensong_2000@189.cn>
Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 lib/cobalt/signal.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/cobalt/signal.c b/lib/cobalt/signal.c
index 7e033019a..40d315ebb 100644
--- a/lib/cobalt/signal.c
+++ b/lib/cobalt/signal.c
@@ -62,7 +62,11 @@ COBALT_IMPL(int, sigtimedwait, (const sigset_t *set, siginfo_t *si,
 
 	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
 
+#ifdef __USE_TIME_BITS64
+	ret = XENOMAI_SYSCALL3(sc_cobalt_sigtimedwait64, set, si, timeout);
+#else
 	ret = XENOMAI_SYSCALL3(sc_cobalt_sigtimedwait, set, si, timeout);
+#endif
 	if (ret < 0) {
 		errno = -ret;
 		ret = -1;
-- 
2.30.2



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

* [PATCH v2 3/3] y2038: testsuite/smokey/y2038: Adding tests for sigtimedwait64
  2021-08-10 15:27 [PATCH v2 0/3] y2038: sigtimedwait64 Florian Bezdeka
  2021-08-10 15:27 ` [PATCH v2 1/3] y2038: cobalt/posix/signal: Adding sigtimedwait64 Florian Bezdeka
  2021-08-10 15:27 ` [PATCH v2 2/3] y2038: lib/cobalt/signal: dispatch sigtimedwait Florian Bezdeka
@ 2021-08-10 15:27 ` Florian Bezdeka
  2021-08-10 16:46 ` [PATCH v2 0/3] y2038: sigtimedwait64 Jan Kiszka
  3 siblings, 0 replies; 5+ messages in thread
From: Florian Bezdeka @ 2021-08-10 15:27 UTC (permalink / raw)
  To: xenomai

Heavily inspired by the tests sent from Song but with the following
modifications:
  - return -EAGAIN instead of -ETIMEOUT (posix spec) in case of a
    timeout
  - Fix time calculations for timeout detection

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

diff --git a/testsuite/smokey/y2038/syscall-tests.c b/testsuite/smokey/y2038/syscall-tests.c
index d30794fba..427117038 100644
--- a/testsuite/smokey/y2038/syscall-tests.c
+++ b/testsuite/smokey/y2038/syscall-tests.c
@@ -18,6 +18,7 @@
 #include <stdbool.h>
 #include <errno.h>
 #include <mqueue.h>
+#include <signal.h>
 
 smokey_test_plugin(y2038, SMOKEY_NOARGS, "Validate correct y2038 support");
 
@@ -768,6 +769,81 @@ static int test_sc_cobalt_mq_timedreceive64(void)
 	return 0;
 }
 
+static int test_sc_cobalt_sigtimedwait64(void)
+{
+	int ret;
+	int sc_nr = sc_cobalt_sigtimedwait64;
+	struct xn_timespec64 t1, t2;
+	struct timespec ts_nat;
+	sigset_t set;
+
+	sigaddset(&set, SIGINT);
+
+	/* Make sure we don't crash because of NULL pointers */
+	ret = XENOMAI_SYSCALL3(sc_nr, NULL, NULL, NULL);
+	if (ret == -ENOSYS) {
+		smokey_note("sigtimedwait64: skipped. (no kernel support)");
+		return 0; // Not implemented, nothing to test, success
+	}
+	if (!smokey_assert(ret == -EFAULT))
+		return ret ? ret : -EINVAL;
+
+	/* Providing an invalid address has to deliver EFAULT */
+	ret = XENOMAI_SYSCALL3(sc_nr, &set, NULL, (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_SYSCALL3(sc_nr, &set, NULL, &t1);
+	if (!smokey_assert(ret == -EINVAL))
+		return ret ? ret : -EINVAL;
+
+	/*
+	 * Providing a zero timeout, should come back immediately, no signal
+	 * will be received
+	 */
+	t1.tv_sec = 0;
+	t1.tv_nsec = 0;
+	ret = XENOMAI_SYSCALL3(sc_nr, &set, NULL, &t1);
+	if (!smokey_assert(ret == -EAGAIN))
+		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_SYSCALL3(sc_nr, &set, NULL, &t1);
+	if (!smokey_assert(ret == -EAGAIN))
+		return ret;
+
+	t1.tv_sec = ts_nat.tv_sec;
+	t1.tv_nsec = ts_nat.tv_nsec;
+	ts_add_ns(&t1, 500000);
+
+	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("sigtimedwait64 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);
+
+	return 0;
+}
+
 static int run_y2038(struct smokey_test *t, int argc, char *const argv[])
 {
 	int ret;
@@ -808,5 +884,9 @@ static int run_y2038(struct smokey_test *t, int argc, char *const argv[])
 	if (ret)
 		return ret;
 
+	ret = test_sc_cobalt_sigtimedwait64();
+	if (ret)
+		return ret;
+
 	return 0;
 }
-- 
2.30.2



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

* Re: [PATCH v2 0/3] y2038: sigtimedwait64
  2021-08-10 15:27 [PATCH v2 0/3] y2038: sigtimedwait64 Florian Bezdeka
                   ` (2 preceding siblings ...)
  2021-08-10 15:27 ` [PATCH v2 3/3] y2038: testsuite/smokey/y2038: Adding tests for sigtimedwait64 Florian Bezdeka
@ 2021-08-10 16:46 ` Jan Kiszka
  3 siblings, 0 replies; 5+ messages in thread
From: Jan Kiszka @ 2021-08-10 16:46 UTC (permalink / raw)
  To: Florian Bezdeka, xenomai

On 10.08.21 17:27, Florian Bezdeka wrote:
> Hi!
> 
> Here comes the next y2038 related syscall implementation. Once again
> based on v1 sent out by Song. I had to rework the patches a bit, mostly
> to stay POSIX compatible (EAGAIN vs. ETIMEOUT) and necessary test
> adjustments and improvements.
> 
> Best regards,
> Florian
> 
> Florian Bezdeka (1):
>   y2038: testsuite/smokey/y2038: Adding tests for sigtimedwait64
> 
> Song Chen (2):
>   y2038: cobalt/posix/signal: Adding sigtimedwait64
>   y2038: lib/cobalt/signal: dispatch sigtimedwait
> 
>  include/cobalt/uapi/syscall.h          |  1 +
>  kernel/cobalt/posix/signal.c           | 21 ++++++-
>  kernel/cobalt/posix/signal.h           |  5 ++
>  kernel/cobalt/posix/syscall32.c        | 21 +++++++
>  kernel/cobalt/posix/syscall32.h        |  5 ++
>  kernel/cobalt/trace/cobalt-posix.h     |  4 +-
>  lib/cobalt/signal.c                    |  4 ++
>  testsuite/smokey/y2038/syscall-tests.c | 80 ++++++++++++++++++++++++++
>  8 files changed, 137 insertions(+), 4 deletions(-)
> 

Thanks, applied to next.

Jan

-- 
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux


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

end of thread, other threads:[~2021-08-10 16:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-10 15:27 [PATCH v2 0/3] y2038: sigtimedwait64 Florian Bezdeka
2021-08-10 15:27 ` [PATCH v2 1/3] y2038: cobalt/posix/signal: Adding sigtimedwait64 Florian Bezdeka
2021-08-10 15:27 ` [PATCH v2 2/3] y2038: lib/cobalt/signal: dispatch sigtimedwait Florian Bezdeka
2021-08-10 15:27 ` [PATCH v2 3/3] y2038: testsuite/smokey/y2038: Adding tests for sigtimedwait64 Florian Bezdeka
2021-08-10 16:46 ` [PATCH v2 0/3] y2038: sigtimedwait64 Jan Kiszka

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.