Skip to contentSkip to conversation

Futex_waitv: Convert 32bit timespec struct to 64bit version for 32bit compatibility mode

PATCH Superseded Wei Gao via ltp 2 participants 5 messages Dec 3, 2023 – Feb 9, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Futex_waitv: 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.

Detail info you can refer following email thread:
https://lkml.org/lkml/2023/11/23/13

---
 testcases/kernel/syscalls/futex/futex2test.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
testcases/kernel/syscalls/futex/futex2test.h +16 -0
index ce97f47c1..f9a031e11 100644
@@ -13,6 +13,13 @@
 #include "lapi/syscalls.h"
 #include "futextest.h"
 
+#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
@@ -24,7 +31,16 @@ 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 tst_syscall(__NR_futex_waitv, waiters, nr_waiters, flags, &timo64, clockid);
+#else
 	return tst_syscall(__NR_futex_waitv, waiters, nr_waiters, flags, timo, clockid);
+
+#endif
 }
 
 #endif /* _FUTEX2TEST_H */
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi!

Quoted 16 lines · Wei Gao via ltp

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

Detail info you can refer following email thread:
https://lkml.org/lkml/2023/11/23/13

---
  testcases/kernel/syscalls/futex/futex2test.h | 16 ++++++++++++++++
  1 file changed, 16 insertions(+)
testcases/kernel/syscalls/futex/futex2test.h +0 -0
index ce97f47c1..f9a031e11 100644

testcases/kernel/syscalls/futex/futex2test.h line 16

Quoted 4 lines
testcases/kernel/syscalls/futex/futex2test.h +1 -0
@@ -13,6 +13,13 @@
  #include "lapi/syscalls.h"
  #include "futextest.h"
 
+#if !defined(__LP64__)

Here you can use "lapi/abisize.h" header. The TST_ABI32 definition is provided when we are running on a 32-bits system.

Quoted 16 lines
testcases/kernel/syscalls/futex/futex2test.h +9 -0
+struct timespec64 {
+	int64_t tv_sec;
+	int64_t tv_nsec;
+};
+#endif
+
  /**
   * futex_waitv - Wait at multiple futexes, wake on any
   * @waiters:    Array of waiters
@@ -24,7 +31,16 @@ 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};
+

testcases/kernel/syscalls/futex/futex2test.h static inline int futex_waitv(volatile struct futex_waitv *waiters, · line 46

Quoted 10 lines
testcases/kernel/syscalls/futex/futex2test.h +6 -0
+	timo64.tv_sec = timo->tv_sec;
+	timo64.tv_nsec = timo->tv_nsec;
+	return tst_syscall(__NR_futex_waitv, waiters, nr_waiters, flags, &timo64, clockid);
+#else
  	return tst_syscall(__NR_futex_waitv, waiters, nr_waiters, flags, timo, clockid);
+
+#endif
  }
 
  #endif /* _FUTEX2TEST_H */

Regards,
Andrea Cervesato

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

PATCH v2 1/1 Futex_waitv: Convert 32bit timespec struct to 64bit version for 32bit compatibility mode

In reply to Wei Gao via ltp

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

Detail info you can refer following email thread:
https://lkml.org/lkml/2023/11/23/13

---
 testcases/kernel/syscalls/futex/futex2test.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
testcases/kernel/syscalls/futex/futex2test.h +17 -0
index ce97f47c1..a3cd0ef5c 100644
@@ -12,6 +12,14 @@
 #include <stdint.h>
 #include "lapi/syscalls.h"
 #include "futextest.h"
+#include "lapi/abisize.h"
+
+#ifdef TST_ABI32
+struct timespec64 {
+	int64_t tv_sec;
+	int64_t tv_nsec;
+};
+#endif
 
 /**
  * futex_waitv - Wait at multiple futexes, wake on any
@@ -24,7 +32,16 @@ static inline int futex_waitv(volatile struct futex_waitv *waiters,
 			      unsigned long nr_waiters, unsigned long flags,
 			      struct timespec *timo, clockid_t clockid)
 {
+#ifdef TST_ABI32
+	struct timespec64 timo64 = {0};
+
+	timo64.tv_sec = timo->tv_sec;
+	timo64.tv_nsec = timo->tv_nsec;
+	return tst_syscall(__NR_futex_waitv, waiters, nr_waiters, flags, &timo64, clockid);
+#else
 	return tst_syscall(__NR_futex_waitv, waiters, nr_waiters, flags, timo, clockid);
+
+#endif
 }
 
 #endif /* _FUTEX2TEST_H */
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author Reviewed-by Andrea Cervesato on v2 1/1
#3 lore raw

Hi!
LGTM

Reviewed-by Andrea Cervesato <andrea.cervesato.suse.com>
Quoted 47 lines · Wei Gao via ltp

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

Detail info you can refer following email thread:
https://lkml.org/lkml/2023/11/23/13

---
  testcases/kernel/syscalls/futex/futex2test.h | 17 +++++++++++++++++
  1 file changed, 17 insertions(+)
testcases/kernel/syscalls/futex/futex2test.h +17 -0
index ce97f47c1..a3cd0ef5c 100644
@@ -12,6 +12,14 @@
  #include <stdint.h>
  #include "lapi/syscalls.h"
  #include "futextest.h"
+#include "lapi/abisize.h"
+
+#ifdef TST_ABI32
+struct timespec64 {
+	int64_t tv_sec;
+	int64_t tv_nsec;
+};
+#endif
 
  /**
   * futex_waitv - Wait at multiple futexes, wake on any
@@ -24,7 +32,16 @@ static inline int futex_waitv(volatile struct futex_waitv *waiters,
  			      unsigned long nr_waiters, unsigned long flags,
  			      struct timespec *timo, clockid_t clockid)
  {
+#ifdef TST_ABI32
+	struct timespec64 timo64 = {0};
+
+	timo64.tv_sec = timo->tv_sec;
+	timo64.tv_nsec = timo->tv_nsec;
+	return tst_syscall(__NR_futex_waitv, waiters, nr_waiters, flags, &timo64, clockid);
+#else
  	return tst_syscall(__NR_futex_waitv, waiters, nr_waiters, flags, timo, clockid);
+
+#endif
  }
 
  #endif /* _FUTEX2TEST_H */
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

Hi Wei, Andrea,

merged (with some Suggested-by: tags), thanks!

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp