y2038: Add mutex_timedlock64() support
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
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
@@ -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
PATCH v2 2/5 cobalt/posix/mutex: Harmonize pthread_mutex_timedlock() and sem_timedwait()
In reply to Florian BezdekaAccording 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
@@ -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
PATCH v2 3/5 y2038: cobalt/posix/mutex: Adding mutex_timedlock64
In reply to Florian BezdekaFrom: Song Chen <[email protected]>
Add a syscall specific for mutex_timedlock with 64bit time_t.
--- 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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