Skip to contentSkip to conversation

kernel/cobalt/posix: Stop supporting timeout parameter in recvmmsg by default

PATCH New Jan Kiszka 1 participant 1 message Apr 7, 2025

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH v2 1/1 kernel/cobalt/posix: Stop supporting timeout parameter in recvmmsg by default

From: Jan Kiszka <[email protected]>

This is a conditional backport of 3d6121a5f5dc to stable, allowing users to keep the pre-existing support enabled during build-time if they believe they are safe and need it. Default is off.

---

Changes in v2:
- fold in https://lore.kernel.org/xenomai/[email protected]/T/#u

 kernel/cobalt/Kconfig                  | 11 +++++++
 kernel/cobalt/rtdm/fd.c                |  8 ++++++
 testsuite/smokey/y2038/syscall-tests.c | 40 +++-----------------------
 3 files changed, 23 insertions(+), 36 deletions(-)
kernel/cobalt/Kconfig +11 -0
index 6ba4cdc5db..b7bce8914a 100644
@@ -217,6 +217,17 @@ config XENO_OPT_VFILE
        depends on PROC_FS
        default y
 
+config XENO_OPT_BROKEN_RECVMMSG_TIMEOUT
+	bool "Provide support for broken recvmmsg timeout parameter"
+	help
+	  The implementation of the timeout parameter for recvmmsg may
+	  cause infinit blocking even if not requested. If your workload
+	  is relying on this parameter AND can rule out being affecting
+	  by the race, you may keep this feature enabled. Note, though,
+	  that later major releases will likely remove it completely.
+
+	  See also https://source.denx.de/Xenomai/xenomai/-/commit/3d6121a5f5dc5eee80945856fccadc6dd9e2e104
+
 endmenu
 
 menu "Sizes and static limits"
kernel/cobalt/rtdm/fd.c +8 -0
index d5813a16c2..eac577f73a 100644
@@ -697,6 +697,14 @@ int __rtdm_fd_recvmmsg(int ufd, void __user *u_msgvec, unsigned int vlen,
 		if (timeout == 0)
 			flags |= MSG_DONTWAIT;
 		else {
+			if (!IS_ENABLED(CONFIG_XENO_OPT_BROKEN_RECVMMSG_TIMEOUT)) {
+				/*
+				 * The timeout parameter is not supported.
+				 * Use recvmsg timeouts instead.
+				 */
+				ret = -EINVAL;
+				goto fail;
+			}
 			timeout += xnclock_read_monotonic(&nkclock);
 			rq.waiter = xnthread_current();
 			xntimer_init(&rq.timer, &nkclock,
testsuite/smokey/y2038/syscall-tests.c +4 -36
index 135f230dca..9a1060ef08 100644
@@ -974,9 +974,8 @@ static int test_sc_cobalt_recvmmsg64(void)
 {
 	int sc_nr = sc_cobalt_recvmmsg64;
 	struct rtipc_port_label plabel;
-	struct xn_timespec64 t1, t2;
+	struct xn_timespec64 t1;
 	struct sockaddr_ipc saddr;
-	struct timespec ts_nat;
 	int ret = 0;
 	long data;
 	int sock;
@@ -1036,9 +1035,9 @@ static int test_sc_cobalt_recvmmsg64(void)
 	}
 
 	/*
-	 * providing an invalid timeout has to deliver EINVAL
+	 * providing a non-zero timeout has to deliver EINVAL
 	 */
-	t1.tv_sec = -1;
+	t1.tv_nsec = 1;
 	ret = XENOMAI_SYSCALL5(sc_nr, sock, &msg, sizeof(msg), 0, &t1);
 	if (!smokey_assert(ret == -EINVAL)) {
 		ret = ret ? ret : -EINVAL;
@@ -1057,38 +1056,7 @@ static int test_sc_cobalt_recvmmsg64(void)
 		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, sock, &msg, sizeof(msg), 0, &t1);
-	if (!smokey_assert(ret == -ETIMEDOUT)) {
-		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("recvmmsg64 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);
+	ret = 0;
 
 out:
 	close(sock);
Signature · 1 line
2.43.0