Skip to contentSkip to conversation

selftests/futex: Convert 32bit timespec struct to 64bit version for 32bit compatibility mode

PATCH Superseded Terry Tritton 3 participants 3 messages Jul 2, 2025 – Jul 3, 2025

Subsystems (2)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 selftests/futex: Convert 32bit timespec struct to 64bit version for 32bit compatibility mode

Futex_waitv can not accept old_timespec32 struct, so userspace should convert it from 32bit to 64bit before syscall in 32bit compatible mode.

This fix is based off [1]

---
Changes in v3:
- Fix signed-off-by chain but for real this time

Changes in v2:
- Fix signed-off-by chain

 .../testing/selftests/futex/include/futex2test.h  | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
tools/testing/selftests/futex/include/futex2test.h +15 -0
index ea79662405bc..6780e51eb2d6 100644
@@ -55,6 +55,13 @@ struct futex32_numa {
 	futex_t numa;
 };
 
+#if !defined(__LP64__)
+struct timespec64 {
+	int64_t tv_sec;
+	int64_t tv_nsec;
+};
+#endif
+
 /**
  * futex_waitv - Wait at multiple futexes, wake on any
  * @waiters:    Array of waiters
@@ -65,7 +72,15 @@ struct futex32_numa {
 static inline int futex_waitv(volatile struct futex_waitv *waiters, unsigned long nr_waiters,
 			      unsigned long flags, struct timespec *timo, clockid_t clockid)
 {
+#if !defined(__LP64__)
+	struct timespec64 timo64 = {0};
+
+	timo64.tv_sec = timo->tv_sec;
+	timo64.tv_nsec = timo->tv_nsec;
+	return syscall(__NR_futex_waitv, waiters, nr_waiters, flags, &timo64, clockid);
+#else
 	return syscall(__NR_futex_waitv, waiters, nr_waiters, flags, timo, clockid);
+#endif
 }
 
 /*
Signature · 1 line
2.39.5
#1 lore raw
Quoted 1 line · Terry Tritton

Futex_waitv can not accept old_timespec32 struct, so userspace should

sys_futex_wait()

Quoted 23 lines

convert it from 32bit to 64bit before syscall in 32bit compatible mode.

This fix is based off [1]

---
Changes in v3:
- Fix signed-off-by chain but for real this time

Changes in v2:
- Fix signed-off-by chain

 .../testing/selftests/futex/include/futex2test.h  | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
tools/testing/selftests/futex/include/futex2test.h +0 -0
index ea79662405bc..6780e51eb2d6 100644

tools/testing/selftests/futex/include/futex2test.h struct futex32_numa { · line 63

Quoted 9 lines
tools/testing/selftests/futex/include/futex2test.h +6 -0
@@ -55,6 +55,13 @@ struct futex32_numa {
 	futex_t numa;
 };
 
+#if !defined(__LP64__)
+struct timespec64 {
+	int64_t tv_sec;
+	int64_t tv_nsec;
+};
+#endif

Why not use __kernel_timespec which is the actual data type that syscall requests?

Quoted 7 lines
tools/testing/selftests/futex/include/futex2test.h +1 -0
+
 /**
  * futex_waitv - Wait at multiple futexes, wake on any
  * @waiters:    Array of waiters
@@ -65,7 +72,15 @@ struct futex32_numa {
 static inline int futex_waitv(volatile struct futex_waitv *waiters, unsigned long nr_waiters,
 			      unsigned long flags, struct timespec *timo, clockid_t clockid)

tools/testing/selftests/futex/include/futex2test.h struct futex32_numa { · line 83

Quoted 10 lines
tools/testing/selftests/futex/include/futex2test.h +8 -0
 {
+#if !defined(__LP64__)
+	struct timespec64 timo64 = {0};
+
+	timo64.tv_sec = timo->tv_sec;
+	timo64.tv_nsec = timo->tv_nsec;
+	return syscall(__NR_futex_waitv, waiters, nr_waiters, flags, &timo64, clockid);
+#else
 	return syscall(__NR_futex_waitv, waiters, nr_waiters, flags, timo, clockid);
+#endif

You simply can do

        struct __kernel_timespec ts = {
        	.tv_sec = timo->tv_sec,
                .tv_nsec = timo->tv_nsec,
        };
  	return syscall(__NR_futex_waitv, waiters, nr_waiters, flags, &ts, clockid);

unconditionally. No?

Thanks,

tglx

#2 lore raw
Quoted 62 lines · Thomas Gleixner
Quoted 1 line · Terry Tritton

Futex_waitv can not accept old_timespec32 struct, so userspace should

sys_futex_wait()

Quoted 23 lines

convert it from 32bit to 64bit before syscall in 32bit compatible mode.

This fix is based off [1]

---
Changes in v3:
- Fix signed-off-by chain but for real this time

Changes in v2:
- Fix signed-off-by chain

 .../testing/selftests/futex/include/futex2test.h  | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
tools/testing/selftests/futex/include/futex2test.h +0 -0
index ea79662405bc..6780e51eb2d6 100644

tools/testing/selftests/futex/include/futex2test.h struct futex32_numa { · line 63

Quoted 9 lines
tools/testing/selftests/futex/include/futex2test.h +6 -0
@@ -55,6 +55,13 @@ struct futex32_numa {
 	futex_t numa;
 };
 
+#if !defined(__LP64__)
+struct timespec64 {
+	int64_t tv_sec;
+	int64_t tv_nsec;
+};
+#endif

Why not use __kernel_timespec which is the actual data type that syscall requests?

Quoted 7 lines
tools/testing/selftests/futex/include/futex2test.h +1 -0
+
 /**
  * futex_waitv - Wait at multiple futexes, wake on any
  * @waiters:    Array of waiters
@@ -65,7 +72,15 @@ struct futex32_numa {
 static inline int futex_waitv(volatile struct futex_waitv *waiters, unsigned long nr_waiters,
 			      unsigned long flags, struct timespec *timo, clockid_t clockid)

tools/testing/selftests/futex/include/futex2test.h struct futex32_numa { · line 83

Quoted 10 lines
tools/testing/selftests/futex/include/futex2test.h +8 -0
 {
+#if !defined(__LP64__)
+	struct timespec64 timo64 = {0};
+
+	timo64.tv_sec = timo->tv_sec;
+	timo64.tv_nsec = timo->tv_nsec;
+	return syscall(__NR_futex_waitv, waiters, nr_waiters, flags, &timo64, clockid);
+#else
 	return syscall(__NR_futex_waitv, waiters, nr_waiters, flags, timo, clockid);
+#endif

You simply can do

Quoted 8 lines
        struct __kernel_timespec ts = {
        	.tv_sec = timo->tv_sec,
                .tv_nsec = timo->tv_nsec,
        };
  	return syscall(__NR_futex_waitv, waiters, nr_waiters, flags, &ts, clockid);

unconditionally. No?

Thanks for your valuable comments.
Your change has more directly interacts with system calls and simplifies the code without conditional compilation.
Only concern from my side is test on very old kernel(But i think this is not problem for kself test)

Quoted 4 lines

Thanks,

tglx