Skip to contentSkip to conversation

y2038: Add mutex_timedlock64() support

PATCH Superseded Florian Bezdeka 1 participant 4 messages Jul 30, 2021

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover y2038: Add mutex_timedlock64() support

Hi!

This series is based on the series posted by Song some time ago. The testing part has been heavily reworked. Details are mentioned in the description of the last patch.

@Jan: Patch 1 and 2 are re-sends. They are not directly related to the y2038 stuff but the testsuite might fail if they are not applied.

Testing was done on x86 only so far, internal CI is still running but no problems expected.

Best regards,
Florian

Florian Bezdeka (3):
smokey: posix_mutex: Fix mutex/smokey_barrier leak cobalt/posix/mutex: Harmonize pthread_mutex_timedlock() and
sem_timedwait()
testsuite/smokey/y2038: Adding test cases for mutex_timedlock64()

Song Chen (2):
y2038: cobalt/posix/mutex: Adding mutex_timedlock64
y2038: lib/cobalt/mutex: dispatch mutex_timedlock

 include/cobalt/uapi/syscall.h              |   1 +
 kernel/cobalt/posix/mutex.c                |  28 ++-
 kernel/cobalt/posix/mutex.h                |   7 +
 kernel/cobalt/posix/syscall32.c            |   7 +
 kernel/cobalt/posix/syscall32.h            |   4 +
 lib/cobalt/mutex.c                         |   4 +
 testsuite/smokey/posix-mutex/posix-mutex.c |  62 +++++++
 testsuite/smokey/y2038/syscall-tests.c     | 187 +++++++++++++++++++++
 8 files changed, 299 insertions(+), 1 deletion(-)
Signature · 1 line
2.30.2
#1 lore raw

PATCH v2 1/5 smokey: posix_mutex: Fix mutex/smokey_barrier leak

The mutex of the smokey_barrier used inside protect_handover() was never destroyed. This had side effects when trying to extend the test suite with an additional function that had a mutex located on the same address than the never cleaned up smokey_barrier lock.

---
 testsuite/smokey/posix-mutex/posix-mutex.c | 2 ++
 1 file changed, 2 insertions(+)
testsuite/smokey/posix-mutex/posix-mutex.c +2 -0
index 9a55d0973..e5793c42c 100644
@@ -997,6 +997,8 @@ static int protect_handover(void)
 	if (!__T(ret, pthread_mutex_destroy(&mutex)))
 		return ret;
 
+	smokey_barrier_destroy(&barrier);
+
 	return 0;
 }
 
Signature · 1 line
2.30.2
#2 lore raw

PATCH v2 2/5 cobalt/posix/mutex: Harmonize pthread_mutex_timedlock() and sem_timedwait()

In reply to Florian Bezdeka

According to the POSIX spec the value of the timeout parameter needs not to be validated if the mutex/semaphore could be taken immediately.

While the implementation of the semaphore timedwait (sem_timedwait()) allowed an invalid timeout pthread_mutex_timedlock() was failing with -EFAULT in case the mutex could be taken immediately.

---
 kernel/cobalt/posix/mutex.c                |  5 ++
 testsuite/smokey/posix-mutex/posix-mutex.c | 60 ++++++++++++++++++++++
 2 files changed, 65 insertions(+)
kernel/cobalt/posix/mutex.c +5 -0
index 70fe7960a..01478978e 100644
@@ -167,6 +167,11 @@ redo:
 	xnthread_commit_ceiling(curr);
 
 	if (xnsynch_owner_check(&mutex->synchbase, curr)) {
+		/* Check if we can take the mutex immediately */
+		ret = xnsynch_try_acquire(&mutex->synchbase);
+		if (ret != -EBUSY)
+			goto out;
+
 		if (fetch_timeout) {
 			xnlock_put_irqrestore(&nklock, s);
 			ret = fetch_timeout(&ts, u_ts);
testsuite/smokey/posix-mutex/posix-mutex.c +60 -0

72 lines not on this page · raw message

Signature · 1 line
2.30.2
#3 lore raw

PATCH v2 3/5 y2038: cobalt/posix/mutex: Adding mutex_timedlock64

In reply to Florian Bezdeka

From: Song Chen <[email protected]>

Add a syscall specific for mutex_timedlock with 64bit time_t.

[Florian: Rearranged code, coding style fixes]
---
 include/cobalt/uapi/syscall.h   |  1 +
 kernel/cobalt/posix/mutex.c     | 23 ++++++++++++++++++++++-
 kernel/cobalt/posix/mutex.h     |  7 +++++++
 kernel/cobalt/posix/syscall32.c |  7 +++++++
 kernel/cobalt/posix/syscall32.h |  4 ++++
 5 files changed, 41 insertions(+), 1 deletion(-)
include/cobalt/uapi/syscall.h +1 -0
index a2795a364..6fe57c7e8 100644
@@ -128,6 +128,7 @@
 #define sc_cobalt_clock_nanosleep64		105
 #define sc_cobalt_clock_getres64		106
 #define sc_cobalt_clock_adjtime64		107
+#define sc_cobalt_mutex_timedlock64		108
 
 #define __NR_COBALT_SYSCALLS			128 /* Power of 2 */
 
kernel/cobalt/posix/mutex.c +22 -1
index 01478978e..0f1c01851 100644
@@ -21,6 +21,7 @@
 #include "mutex.h"
 #include "cond.h"
 #include "clock.h"
+#include <cobalt/kernel/time.h>
 
 static int cobalt_mutex_init_inner(struct cobalt_mutex_shadow *shadow,
 				   struct cobalt_mutex *mutex,
@@ -76,7 +77,7 @@ int __cobalt_mutex_acquire_unchecked(struct xnthread *cur,
 	int ret;
 
 	if (ts) {
-		if (ts->tv_nsec >= ONE_BILLION)
+		if (!timespec64_valid(ts))
 			return -EINVAL;
 		ret = xnsynch_acquire(&mutex->synchbase, ts2ns(ts) + 1, XN_REALTIME);
 	} else
@@ -357,6 +358,19 @@ static inline int mutex_fetch_timeout(struct timespec64 *ts,
 	return u_ts == NULL ? -EFAULT : cobalt_get_u_timespec(ts, u_ts);
 }
 
+static inline int mutex_fetch_timeout64(struct timespec64 *ts,
+					const void __user *u_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))
@@ -364,6 +378,13 @@ COBALT_SYSCALL(mutex_timedlock, primary,
 	return __cobalt_mutex_timedlock_break(u_mx, u_ts, mutex_fetch_timeout);
 }
 
+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);
+}
+
 COBALT_SYSCALL(mutex_unlock, nonrestartable,
 	       (struct cobalt_mutex_shadow __user *u_mx))
 {
kernel/cobalt/posix/mutex.h +7 -0
index d76f2a9ea..d7d43219e 100644
@@ -40,6 +40,9 @@ 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);
@@ -64,6 +67,10 @@ COBALT_SYSCALL_DECL(mutex_timedlock,
 		    (struct cobalt_mutex_shadow __user *u_mx,
 		     const struct __user_old_timespec __user *u_ts));
 
+COBALT_SYSCALL(mutex_timedlock64, primary,
+	       (struct cobalt_mutex_shadow __user *u_mx,
+		const struct __kernel_timespec __user *u_ts));
+
 COBALT_SYSCALL_DECL(mutex_unlock,
 		    (struct cobalt_mutex_shadow __user *u_mx));
 
kernel/cobalt/posix/syscall32.c +7 -0
index a37478f3f..bd30decce 100644
@@ -267,6 +267,13 @@ 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 +4 -0
index 64f6e4931..d464d967f 100644
@@ -98,6 +98,10 @@ 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.30.2