Skip to contentSkip to conversation

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

PATCH Applied Terry Tritton 2 participants 2 messages Jul 4, 2025 – Jul 6, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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

sys_futex_wait() can not accept old_timespec32 struct, so userspace should convert it from 32bit to 64bit before syscall to support 32bit compatible mode.

This fix is based off [1]

---
Changes in v5:
- Fixed checkpatch errors

Changes in v4:
- Change to use __kernel_timespec as suggested by tglx

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

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

 tools/testing/selftests/futex/include/futex2test.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/testing/selftests/futex/include/futex2test.h +7 -1
index ea79662405bc..ff9eebcc270c 100644
@@ -5,6 +5,7 @@
  * Copyright 2021 Collabora Ltd.
  */
 #include <stdint.h>
+#include <linux/time_types.h>
 
 #define u64_to_ptr(x) ((void *)(uintptr_t)(x))
 
@@ -65,7 +66,12 @@ 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)
 {
-	return syscall(__NR_futex_waitv, waiters, nr_waiters, flags, timo, clockid);
+		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);
 }
 
 /*
Signature · 1 line
2.39.5
merge bot Applied
#1 lore raw

[tip: locking/urgent] selftests/futex: Convert 32-bit timespec to 64-bit version for 32-bit compatibility mode

The following commit has been merged into the locking/urgent branch of tip:

The following commit has been merged into the locking/urgent branch of tip:

Commit-ID:     d0a48dc4df5c986bf8c3caf4d8fc15c480273052
Gitweb:        https://git.kernel.org/tip/d0a48dc4df5c986bf8c3caf4d8fc15c480273052
Author:        Terry Tritton <[email protected]>
AuthorDate:    Fri, 04 Jul 2025 20:02:34 +01:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Sun, 06 Jul 2025 11:15:29 +02:00

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

sys_futex_wait() expects a struct __kernel_timespec pointer for the timeout, but the provided struct timespec pointer is of type struct old_timespec32 when compiled for 32-bit architectures, unless they use 64-bit timespecs already.

Make it work for all variants by converting the provided timespec value into a local struct __kernel_timespec and provide a pointer to it to the syscall. This is a pointless operation for 64-bit, but this is not a hotpath operation, so keep it simple.

This fix is based off [1]

---
 tools/testing/selftests/futex/include/futex2test.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/testing/selftests/futex/include/futex2test.h +7 -1
index ea79662..1f625b3 100644
@@ -4,6 +4,7 @@
  *
  * Copyright 2021 Collabora Ltd.
  */
+#include <linux/time_types.h>
 #include <stdint.h>
 
 #define u64_to_ptr(x) ((void *)(uintptr_t)(x))
@@ -65,7 +66,12 @@ 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)
 {
-	return syscall(__NR_futex_waitv, waiters, nr_waiters, flags, timo, clockid);
+		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);
 }
 
 /*