From: Peter Zijlstra <peterz@infradead.org>
To: tglx@linutronix.de, axboe@kernel.dk
Cc: linux-kernel@vger.kernel.org, peterz@infradead.org,
mingo@redhat.com, dvhart@infradead.org, dave@stgolabs.net,
andrealmeid@igalia.com, Andrew Morton <akpm@linux-foundation.org>,
urezki@gmail.com, hch@infradead.org, lstoakes@gmail.com,
Arnd Bergmann <arnd@arndb.de>,
linux-api@vger.kernel.org, linux-mm@kvack.org,
linux-arch@vger.kernel.org, malteskarupke@web.de,
Geert Uytterhoeven <geert@linux-m68k.org>
Subject: [PATCH v2 09/14] futex: Add sys_futex_requeue()
Date: Mon, 07 Aug 2023 14:18:52 +0200 [thread overview]
Message-ID: <20230807123323.366498604@infradead.org> (raw)
In-Reply-To: 20230807121843.710612856@infradead.org
Finish of the 'simple' futex2 syscall group by adding
sys_futex_requeue(). Unlike sys_futex_{wait,wake}() its arguments are
too numerous to fit into a regular syscall. As such, use struct
futex_waitv to pass the 'source' and 'destination' futexes to the
syscall.
This syscall implements what was previously known as FUTEX_CMP_REQUEUE
and uses {val, uaddr, flags} for source and {uaddr, flags} for
destination.
This design explicitly allows requeueing between different types of
futex by having a different flags word per uaddr.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
arch/alpha/kernel/syscalls/syscall.tbl | 1
arch/arm/tools/syscall.tbl | 1
arch/arm64/include/asm/unistd.h | 2 -
arch/arm64/include/asm/unistd32.h | 2 +
arch/ia64/kernel/syscalls/syscall.tbl | 1
arch/m68k/kernel/syscalls/syscall.tbl | 1
arch/microblaze/kernel/syscalls/syscall.tbl | 1
arch/mips/kernel/syscalls/syscall_n32.tbl | 1
arch/mips/kernel/syscalls/syscall_n64.tbl | 1
arch/mips/kernel/syscalls/syscall_o32.tbl | 1
arch/parisc/kernel/syscalls/syscall.tbl | 1
arch/powerpc/kernel/syscalls/syscall.tbl | 1
arch/s390/kernel/syscalls/syscall.tbl | 1
arch/sh/kernel/syscalls/syscall.tbl | 1
arch/sparc/kernel/syscalls/syscall.tbl | 1
arch/x86/entry/syscalls/syscall_32.tbl | 1
arch/x86/entry/syscalls/syscall_64.tbl | 1
arch/xtensa/kernel/syscalls/syscall.tbl | 1
include/linux/syscalls.h | 3 ++
include/uapi/asm-generic/unistd.h | 4 ++
kernel/futex/syscalls.c | 38 ++++++++++++++++++++++++++++
kernel/sys_ni.c | 1
22 files changed, 64 insertions(+), 2 deletions(-)
--- a/arch/alpha/kernel/syscalls/syscall.tbl
+++ b/arch/alpha/kernel/syscalls/syscall.tbl
@@ -493,3 +493,4 @@
561 common cachestat sys_cachestat
562 common futex_wake sys_futex_wake
563 common futex_wait sys_futex_wait
+564 common futex_requeue sys_futex_requeue
--- a/arch/arm/tools/syscall.tbl
+++ b/arch/arm/tools/syscall.tbl
@@ -467,3 +467,4 @@
451 common cachestat sys_cachestat
452 common futex_wake sys_futex_wake
453 common futex_wait sys_futex_wait
+454 common futex_requeue sys_futex_requeue
--- a/arch/arm64/include/asm/unistd.h
+++ b/arch/arm64/include/asm/unistd.h
@@ -39,7 +39,7 @@
#define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE + 5)
#define __ARM_NR_COMPAT_END (__ARM_NR_COMPAT_BASE + 0x800)
-#define __NR_compat_syscalls 454
+#define __NR_compat_syscalls 455
#endif
#define __ARCH_WANT_SYS_CLONE
--- a/arch/arm64/include/asm/unistd32.h
+++ b/arch/arm64/include/asm/unistd32.h
@@ -913,6 +913,8 @@ __SYSCALL(__NR_cachestat, sys_cachestat)
__SYSCALL(__NR_futex_wake, sys_futex_wake)
#define __NR_futex_wait 453
__SYSCALL(__NR_futex_wait, sys_futex_wait)
+#define __NR_futex_requeue 454
+__SYSCALL(__NR_futex_requeue, sys_futex_requeue)
/*
* Please add new compat syscalls above this comment and update
--- a/arch/ia64/kernel/syscalls/syscall.tbl
+++ b/arch/ia64/kernel/syscalls/syscall.tbl
@@ -374,3 +374,4 @@
451 common cachestat sys_cachestat
452 common futex_wake sys_futex_wake
453 common futex_wait sys_futex_wait
+454 common futex_requeue sys_futex_requeue
--- a/arch/m68k/kernel/syscalls/syscall.tbl
+++ b/arch/m68k/kernel/syscalls/syscall.tbl
@@ -453,3 +453,4 @@
451 common cachestat sys_cachestat
452 common futex_wake sys_futex_wake
453 common futex_wait sys_futex_wait
+454 common futex_requeue sys_futex_requeue
--- a/arch/microblaze/kernel/syscalls/syscall.tbl
+++ b/arch/microblaze/kernel/syscalls/syscall.tbl
@@ -459,3 +459,4 @@
451 common cachestat sys_cachestat
452 common futex_wake sys_futex_wake
453 common futex_wait sys_futex_wait
+454 common futex_requeue sys_futex_requeue
--- a/arch/mips/kernel/syscalls/syscall_n32.tbl
+++ b/arch/mips/kernel/syscalls/syscall_n32.tbl
@@ -392,3 +392,4 @@
451 n32 cachestat sys_cachestat
452 n32 futex_wake sys_futex_wake
453 n32 futex_wait sys_futex_wait
+454 n32 futex_requeue sys_futex_requeue
--- a/arch/mips/kernel/syscalls/syscall_n64.tbl
+++ b/arch/mips/kernel/syscalls/syscall_n64.tbl
@@ -368,3 +368,4 @@
451 n64 cachestat sys_cachestat
452 n64 futex_wake sys_futex_wake
453 n64 futex_wait sys_futex_wait
+454 n64 futex_requeue sys_futex_requeue
--- a/arch/mips/kernel/syscalls/syscall_o32.tbl
+++ b/arch/mips/kernel/syscalls/syscall_o32.tbl
@@ -441,3 +441,4 @@
451 o32 cachestat sys_cachestat
452 o32 futex_wake sys_futex_wake
453 o32 futex_wait sys_futex_wait
+454 o32 futex_requeue sys_futex_requeue
--- a/arch/parisc/kernel/syscalls/syscall.tbl
+++ b/arch/parisc/kernel/syscalls/syscall.tbl
@@ -452,3 +452,4 @@
451 common cachestat sys_cachestat
452 common futex_wake sys_futex_wake
453 common futex_wait sys_futex_wait
+454 common futex_requeue sys_futex_requeue
--- a/arch/powerpc/kernel/syscalls/syscall.tbl
+++ b/arch/powerpc/kernel/syscalls/syscall.tbl
@@ -540,3 +540,4 @@
451 common cachestat sys_cachestat
452 common futex_wake sys_futex_wake
453 common futex_wait sys_futex_wait
+454 common futex_requeue sys_futex_requeue
--- a/arch/s390/kernel/syscalls/syscall.tbl
+++ b/arch/s390/kernel/syscalls/syscall.tbl
@@ -456,3 +456,4 @@
451 common cachestat sys_cachestat sys_cachestat
452 common futex_wake sys_futex_wake sys_futex_wake
453 common futex_wait sys_futex_wait sys_futex_wait
+454 common futex_requeue sys_futex_requeue sys_futex_requeue
--- a/arch/sh/kernel/syscalls/syscall.tbl
+++ b/arch/sh/kernel/syscalls/syscall.tbl
@@ -456,3 +456,4 @@
451 common cachestat sys_cachestat
452 common futex_wake sys_futex_wake
453 common futex_wait sys_futex_wait
+454 common futex_requeue sys_futex_requeue
--- a/arch/sparc/kernel/syscalls/syscall.tbl
+++ b/arch/sparc/kernel/syscalls/syscall.tbl
@@ -499,3 +499,4 @@
451 common cachestat sys_cachestat
452 common futex_wake sys_futex_wake
453 common futex_wait sys_futex_wait
+454 common futex_requeue sys_futex_requeue
--- a/arch/x86/entry/syscalls/syscall_32.tbl
+++ b/arch/x86/entry/syscalls/syscall_32.tbl
@@ -458,3 +458,4 @@
451 i386 cachestat sys_cachestat
452 i386 futex_wake sys_futex_wake
453 i386 futex_wait sys_futex_wait
+454 i386 futex_requeue sys_futex_requeue
--- a/arch/x86/entry/syscalls/syscall_64.tbl
+++ b/arch/x86/entry/syscalls/syscall_64.tbl
@@ -375,6 +375,7 @@
451 common cachestat sys_cachestat
452 common futex_wake sys_futex_wake
453 common futex_wait sys_futex_wait
+454 common futex_requeue sys_futex_requeue
#
# Due to a historical design error, certain syscalls are numbered differently
--- a/arch/xtensa/kernel/syscalls/syscall.tbl
+++ b/arch/xtensa/kernel/syscalls/syscall.tbl
@@ -424,3 +424,4 @@
451 common cachestat sys_cachestat
452 common futex_wake sys_futex_wake
453 common futex_wait sys_futex_wait
+454 common futex_requeue sys_futex_requeue
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -570,6 +570,9 @@ asmlinkage long sys_futex_wait(void __us
unsigned int flags, struct __kernel_timespec __user *timespec,
clockid_t clockid);
+asmlinkage long sys_futex_requeue(struct futex_waitv __user *waiters,
+ unsigned int flags, int nr_wake, int nr_requeue);
+
asmlinkage long sys_nanosleep(struct __kernel_timespec __user *rqtp,
struct __kernel_timespec __user *rmtp);
asmlinkage long sys_nanosleep_time32(struct old_timespec32 __user *rqtp,
--- a/include/uapi/asm-generic/unistd.h
+++ b/include/uapi/asm-generic/unistd.h
@@ -822,9 +822,11 @@ __SYSCALL(__NR_cachestat, sys_cachestat)
__SYSCALL(__NR_futex_wake, sys_futex_wake)
#define __NR_futex_wait 453
__SYSCALL(__NR_futex_wait, sys_futex_wait)
+#define __NR_futex_requeue 454
+__SYSCALL(__NR_futex_requeue, sys_futex_requeue)
#undef __NR_syscalls
-#define __NR_syscalls 454
+#define __NR_syscalls 455
/*
* 32 bit systems traditionally used different
--- a/kernel/futex/syscalls.c
+++ b/kernel/futex/syscalls.c
@@ -396,6 +396,44 @@ SYSCALL_DEFINE6(futex_wait,
return ret;
}
+/*
+ * sys_futex_requeue - Requeue a waiter from one futex to another
+ * @waiters: array describing the source and destination futex
+ * @flags: unused
+ * @nr_wake: number of futexes to wake
+ * @nr_requeue: number of futexes to requeue
+ *
+ * Identical to the traditional FUTEX_CMP_REQUEUE op, except it is part of the
+ * futex2 family of calls.
+ */
+
+SYSCALL_DEFINE4(futex_requeue,
+ struct futex_waitv __user *, waiters,
+ unsigned int, flags,
+ int, nr_wake,
+ int, nr_requeue)
+{
+ struct futex_vector futexes[2];
+ u32 cmpval;
+ int ret;
+
+ if (flags)
+ return -EINVAL;
+
+ if (!waiters)
+ return -EINVAL;
+
+ ret = futex_parse_waitv(futexes, waiters, 2);
+ if (ret)
+ return ret;
+
+ cmpval = futexes[0].w.val;
+
+ return futex_requeue(u64_to_user_ptr(futexes[0].w.uaddr), futexes[0].w.flags,
+ u64_to_user_ptr(futexes[1].w.uaddr), futexes[1].w.flags,
+ nr_wake, nr_requeue, &cmpval, 0);
+}
+
#ifdef CONFIG_COMPAT
COMPAT_SYSCALL_DEFINE2(set_robust_list,
struct compat_robust_list_head __user *, head,
--- a/kernel/sys_ni.c
+++ b/kernel/sys_ni.c
@@ -89,6 +89,7 @@ COND_SYSCALL_COMPAT(get_robust_list);
COND_SYSCALL(futex_waitv);
COND_SYSCALL(futex_wake);
COND_SYSCALL(futex_wait);
+COND_SYSCALL(futex_requeue);
COND_SYSCALL(kexec_load);
COND_SYSCALL_COMPAT(kexec_load);
COND_SYSCALL(init_module);
next prev parent reply other threads:[~2023-08-07 12:38 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-07 12:18 [PATCH v2 00/14] futex: More futex2 bits Peter Zijlstra
2023-08-07 12:18 ` [PATCH v2 01/14] futex: Clarify FUTEX2 flags Peter Zijlstra
2023-08-07 23:51 ` André Almeida
2023-08-07 12:18 ` [PATCH v2 02/14] futex: Extend the " Peter Zijlstra
2023-08-07 18:56 ` Thomas Gleixner
2023-08-08 0:02 ` André Almeida
2023-08-07 12:18 ` [PATCH v2 03/14] futex: Flag conversion Peter Zijlstra
2023-08-07 18:58 ` Thomas Gleixner
2023-08-08 0:52 ` André Almeida
2023-08-07 12:18 ` [PATCH v2 04/14] futex: Validate futex value against futex size Peter Zijlstra
2023-08-07 12:18 ` [PATCH v2 05/14] futex: Add sys_futex_wake() Peter Zijlstra
2023-08-07 19:00 ` Thomas Gleixner
2023-08-09 22:25 ` André Almeida
2023-08-10 12:13 ` Peter Zijlstra
2023-08-10 17:01 ` André Almeida
2023-08-07 12:18 ` [PATCH v2 06/14] futex: Add sys_futex_wait() Peter Zijlstra
2023-08-07 12:18 ` [PATCH v2 07/14] futex: Propagate flags into get_futex_key() Peter Zijlstra
2023-08-07 12:18 ` [PATCH v2 08/14] futex: Add flags2 argument to futex_requeue() Peter Zijlstra
2023-08-07 19:01 ` Thomas Gleixner
2023-08-07 12:18 ` Peter Zijlstra [this message]
2023-08-07 19:05 ` [PATCH v2 09/14] futex: Add sys_futex_requeue() Thomas Gleixner
2023-08-07 12:18 ` [PATCH v2 10/14] mm: Add vmalloc_huge_node() Peter Zijlstra
2023-08-07 12:18 ` [PATCH v2 11/14] futex: Implement FUTEX2_NUMA Peter Zijlstra
2023-08-07 21:11 ` Thomas Gleixner
2023-08-08 8:54 ` Peter Zijlstra
2023-08-08 9:12 ` Thomas Gleixner
2023-08-07 12:18 ` [PATCH v2 12/14] futex: Propagate flags into futex_get_value_locked() Peter Zijlstra
2023-08-07 21:12 ` Thomas Gleixner
2023-08-07 12:18 ` [PATCH v2 13/14] futex: Enable FUTEX2_{8,16} Peter Zijlstra
2023-08-07 21:15 ` Thomas Gleixner
2023-08-07 12:18 ` [PATCH v2 14/14] futex,selftests: Extend the futex selftests Peter Zijlstra
2023-08-08 20:32 ` [PATCH v2 00/14] futex: More futex2 bits Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230807123323.366498604@infradead.org \
--to=peterz@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=andrealmeid@igalia.com \
--cc=arnd@arndb.de \
--cc=axboe@kernel.dk \
--cc=dave@stgolabs.net \
--cc=dvhart@infradead.org \
--cc=geert@linux-m68k.org \
--cc=hch@infradead.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lstoakes@gmail.com \
--cc=malteskarupke@web.de \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=urezki@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.