diff mbox series

[5/6] uapi: futex: Add a futex waitv syscall

Message ID 20221028095632.1081262-6-alistair.francis@opensource.wdc.com (mailing list archive)
State Not Applicable
Headers show
Series Fixup perf tests for 32-bit systems with 64-bit time_t | expand

Checks

Context Check Description
conchuod/cover_letter success Series has a cover letter
conchuod/tree_selection success Guessed tree name to be for-next
conchuod/patch_count success Link
conchuod/fixes_present success Fixes tag not required for -next series
conchuod/verify_signedoff success Signed-off-by tag matches author and committer
conchuod/header_inline success No static functions without inline keyword in header files
conchuod/verify_fixes success No Fixes tag
conchuod/checkpatch warning CHECK: Alignment should match open parenthesis CHECK: Unbalanced braces around else statement CHECK: braces {} should be used on all arms of this statement WARNING: Use of volatile is usually wrong: see Documentation/process/volatile-considered-harmful.rst WARNING: line length of 92 exceeds 80 columns WARNING: line length of 95 exceeds 80 columns
conchuod/kdoc fail Errors and warnings before: 0 this patch: 1
conchuod/source_inline success Was 0 now: 0
conchuod/cc_maintainers warning 4 maintainers not CCed: paul.walmsley@sifive.com aou@eecs.berkeley.edu palmer@dabbelt.com conor.dooley@microchip.com
conchuod/build_warn_rv64 fail Errors and warnings before: 0 this patch: 0
conchuod/module_param success Was 0 now: 0

Commit Message

Alistair Francis Oct. 28, 2022, 9:56 a.m. UTC
From: Alistair Francis <alistair.francis@wdc.com>

This commit adds a futex waitv syscall wrapper that is exposed to
userspace.

Neither the kernel or glibc currently expose a futex wrapper, so
userspace is left performing raw syscalls. As the futex_waitv syscall
always expects a 64-bit time_t this can be tricky for 32-bit systems to
get correct.

In order to avoid userspace incorrectly passing the wrong timeouts let's
expose a public helper function that ensures the kernel is passed the
correct timeout struct.

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Message-Id: <20211209235857.423773-5-alistair.francis@opensource.wdc.com>
---
 include/uapi/linux/futex_syscall.h | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
diff mbox series

Patch

diff --git a/include/uapi/linux/futex_syscall.h b/include/uapi/linux/futex_syscall.h
index bac621eb319c..f637f05a3be0 100644
--- a/include/uapi/linux/futex_syscall.h
+++ b/include/uapi/linux/futex_syscall.h
@@ -89,4 +89,31 @@  __kernel_futex_syscall_nr_requeue(volatile uint32_t *uaddr, int op, uint32_t val
 	return -1;
 }
 
+/**
+ * __kernel_futex_syscall_waitv - Wait at multiple futexes, wake on any
+ * @waiters:    Array of waiters
+ * @nr_waiters: Length of waiters array
+ * @flags: Operation flags
+ * @timo:  Optional timeout for operation
+ */
+static inline int
+__kernel_futex_syscall_waitv(volatile struct futex_waitv *waiters, unsigned long nr_waiters,
+			      unsigned long flags, struct timespec *timo, clockid_t clockid)
+{
+	/* futex_waitv expects a 64-bit time_t */
+	if (sizeof(*timo) == sizeof(struct __kernel_timespec))
+		return syscall(__NR_futex_waitv, waiters, nr_waiters, flags, timo, clockid);
+
+	/* If the caller supplied a 32-bit time_t, convert it to 64-bit */
+	if (timo) {
+		struct __kernel_timespec ts_new;
+
+		ts_new.tv_sec = timo->tv_sec;
+		ts_new.tv_nsec = timo->tv_nsec;
+
+		return syscall(__NR_futex_waitv, waiters, nr_waiters, flags, &ts_new, clockid);
+	} else
+		return syscall(__NR_futex_waitv, waiters, nr_waiters, flags, NULL, clockid);
+}
+
 #endif /* _UAPI_LINUX_FUTEX_SYSCALL_H */