Commit 0f4b5f97 authored by peterz@infradead.org's avatar peterz@infradead.org Committed by Peter Zijlstra

futex: Add sys_futex_requeue()

Finish off 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: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: default avatarThomas Gleixner <tglx@linutronix.de>
Acked-by: default avatarGeert Uytterhoeven <geert@linux-m68k.org>
Link: https://lore.kernel.org/r/20230921105248.511860556@noisy.programming.kicks-ass.net
parent 27b88f35
...@@ -494,3 +494,4 @@ ...@@ -494,3 +494,4 @@
562 common fchmodat2 sys_fchmodat2 562 common fchmodat2 sys_fchmodat2
563 common futex_wake sys_futex_wake 563 common futex_wake sys_futex_wake
564 common futex_wait sys_futex_wait 564 common futex_wait sys_futex_wait
565 common futex_requeue sys_futex_requeue
...@@ -468,3 +468,4 @@ ...@@ -468,3 +468,4 @@
452 common fchmodat2 sys_fchmodat2 452 common fchmodat2 sys_fchmodat2
454 common futex_wake sys_futex_wake 454 common futex_wake sys_futex_wake
455 common futex_wait sys_futex_wait 455 common futex_wait sys_futex_wait
456 common futex_requeue sys_futex_requeue
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
#define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE + 5) #define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE + 5)
#define __ARM_NR_COMPAT_END (__ARM_NR_COMPAT_BASE + 0x800) #define __ARM_NR_COMPAT_END (__ARM_NR_COMPAT_BASE + 0x800)
#define __NR_compat_syscalls 456 #define __NR_compat_syscalls 457
#endif #endif
#define __ARCH_WANT_SYS_CLONE #define __ARCH_WANT_SYS_CLONE
......
...@@ -915,6 +915,8 @@ __SYSCALL(__NR_fchmodat2, sys_fchmodat2) ...@@ -915,6 +915,8 @@ __SYSCALL(__NR_fchmodat2, sys_fchmodat2)
__SYSCALL(__NR_futex_wake, sys_futex_wake) __SYSCALL(__NR_futex_wake, sys_futex_wake)
#define __NR_futex_wait 455 #define __NR_futex_wait 455
__SYSCALL(__NR_futex_wait, sys_futex_wait) __SYSCALL(__NR_futex_wait, sys_futex_wait)
#define __NR_futex_requeue 456
__SYSCALL(__NR_futex_requeue, sys_futex_requeue)
/* /*
* Please add new compat syscalls above this comment and update * Please add new compat syscalls above this comment and update
......
...@@ -375,3 +375,4 @@ ...@@ -375,3 +375,4 @@
452 common fchmodat2 sys_fchmodat2 452 common fchmodat2 sys_fchmodat2
454 common futex_wake sys_futex_wake 454 common futex_wake sys_futex_wake
455 common futex_wait sys_futex_wait 455 common futex_wait sys_futex_wait
456 common futex_requeue sys_futex_requeue
...@@ -454,3 +454,4 @@ ...@@ -454,3 +454,4 @@
452 common fchmodat2 sys_fchmodat2 452 common fchmodat2 sys_fchmodat2
454 common futex_wake sys_futex_wake 454 common futex_wake sys_futex_wake
455 common futex_wait sys_futex_wait 455 common futex_wait sys_futex_wait
456 common futex_requeue sys_futex_requeue
...@@ -460,3 +460,4 @@ ...@@ -460,3 +460,4 @@
452 common fchmodat2 sys_fchmodat2 452 common fchmodat2 sys_fchmodat2
454 common futex_wake sys_futex_wake 454 common futex_wake sys_futex_wake
455 common futex_wait sys_futex_wait 455 common futex_wait sys_futex_wait
456 common futex_requeue sys_futex_requeue
...@@ -393,3 +393,4 @@ ...@@ -393,3 +393,4 @@
452 n32 fchmodat2 sys_fchmodat2 452 n32 fchmodat2 sys_fchmodat2
454 n32 futex_wake sys_futex_wake 454 n32 futex_wake sys_futex_wake
455 n32 futex_wait sys_futex_wait 455 n32 futex_wait sys_futex_wait
456 n32 futex_requeue sys_futex_requeue
...@@ -369,3 +369,4 @@ ...@@ -369,3 +369,4 @@
452 n64 fchmodat2 sys_fchmodat2 452 n64 fchmodat2 sys_fchmodat2
454 n64 futex_wake sys_futex_wake 454 n64 futex_wake sys_futex_wake
455 n64 futex_wait sys_futex_wait 455 n64 futex_wait sys_futex_wait
456 n64 futex_requeue sys_futex_requeue
...@@ -442,3 +442,4 @@ ...@@ -442,3 +442,4 @@
452 o32 fchmodat2 sys_fchmodat2 452 o32 fchmodat2 sys_fchmodat2
454 o32 futex_wake sys_futex_wake 454 o32 futex_wake sys_futex_wake
455 o32 futex_wait sys_futex_wait 455 o32 futex_wait sys_futex_wait
456 o32 futex_requeue sys_futex_requeue
...@@ -453,3 +453,4 @@ ...@@ -453,3 +453,4 @@
452 common fchmodat2 sys_fchmodat2 452 common fchmodat2 sys_fchmodat2
454 common futex_wake sys_futex_wake 454 common futex_wake sys_futex_wake
455 common futex_wait sys_futex_wait 455 common futex_wait sys_futex_wait
456 common futex_requeue sys_futex_requeue
...@@ -541,3 +541,4 @@ ...@@ -541,3 +541,4 @@
452 common fchmodat2 sys_fchmodat2 452 common fchmodat2 sys_fchmodat2
454 common futex_wake sys_futex_wake 454 common futex_wake sys_futex_wake
455 common futex_wait sys_futex_wait 455 common futex_wait sys_futex_wait
456 common futex_requeue sys_futex_requeue
...@@ -457,3 +457,4 @@ ...@@ -457,3 +457,4 @@
452 common fchmodat2 sys_fchmodat2 sys_fchmodat2 452 common fchmodat2 sys_fchmodat2 sys_fchmodat2
454 common futex_wake sys_futex_wake sys_futex_wake 454 common futex_wake sys_futex_wake sys_futex_wake
455 common futex_wait sys_futex_wait sys_futex_wait 455 common futex_wait sys_futex_wait sys_futex_wait
456 common futex_requeue sys_futex_requeue sys_futex_requeue
...@@ -457,3 +457,4 @@ ...@@ -457,3 +457,4 @@
452 common fchmodat2 sys_fchmodat2 452 common fchmodat2 sys_fchmodat2
454 common futex_wake sys_futex_wake 454 common futex_wake sys_futex_wake
455 common futex_wait sys_futex_wait 455 common futex_wait sys_futex_wait
456 common futex_requeue sys_futex_requeue
...@@ -500,3 +500,4 @@ ...@@ -500,3 +500,4 @@
452 common fchmodat2 sys_fchmodat2 452 common fchmodat2 sys_fchmodat2
454 common futex_wake sys_futex_wake 454 common futex_wake sys_futex_wake
455 common futex_wait sys_futex_wait 455 common futex_wait sys_futex_wait
456 common futex_requeue sys_futex_requeue
...@@ -459,3 +459,4 @@ ...@@ -459,3 +459,4 @@
452 i386 fchmodat2 sys_fchmodat2 452 i386 fchmodat2 sys_fchmodat2
454 i386 futex_wake sys_futex_wake 454 i386 futex_wake sys_futex_wake
455 i386 futex_wait sys_futex_wait 455 i386 futex_wait sys_futex_wait
456 i386 futex_requeue sys_futex_requeue
...@@ -377,6 +377,7 @@ ...@@ -377,6 +377,7 @@
453 64 map_shadow_stack sys_map_shadow_stack 453 64 map_shadow_stack sys_map_shadow_stack
454 common futex_wake sys_futex_wake 454 common futex_wake sys_futex_wake
455 common futex_wait sys_futex_wait 455 common futex_wait sys_futex_wait
456 common futex_requeue sys_futex_requeue
# #
# Due to a historical design error, certain syscalls are numbered differently # Due to a historical design error, certain syscalls are numbered differently
......
...@@ -425,3 +425,4 @@ ...@@ -425,3 +425,4 @@
452 common fchmodat2 sys_fchmodat2 452 common fchmodat2 sys_fchmodat2
454 common futex_wake sys_futex_wake 454 common futex_wake sys_futex_wake
455 common futex_wait sys_futex_wait 455 common futex_wait sys_futex_wait
456 common futex_requeue sys_futex_requeue
...@@ -556,6 +556,9 @@ asmlinkage long sys_futex_wait(void __user *uaddr, unsigned long val, unsigned l ...@@ -556,6 +556,9 @@ asmlinkage long sys_futex_wait(void __user *uaddr, unsigned long val, unsigned l
unsigned int flags, struct __kernel_timespec __user *timespec, unsigned int flags, struct __kernel_timespec __user *timespec,
clockid_t clockid); 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, asmlinkage long sys_nanosleep(struct __kernel_timespec __user *rqtp,
struct __kernel_timespec __user *rmtp); struct __kernel_timespec __user *rmtp);
asmlinkage long sys_nanosleep_time32(struct old_timespec32 __user *rqtp, asmlinkage long sys_nanosleep_time32(struct old_timespec32 __user *rqtp,
......
...@@ -826,9 +826,11 @@ __SYSCALL(__NR_fchmodat2, sys_fchmodat2) ...@@ -826,9 +826,11 @@ __SYSCALL(__NR_fchmodat2, sys_fchmodat2)
__SYSCALL(__NR_futex_wake, sys_futex_wake) __SYSCALL(__NR_futex_wake, sys_futex_wake)
#define __NR_futex_wait 455 #define __NR_futex_wait 455
__SYSCALL(__NR_futex_wait, sys_futex_wait) __SYSCALL(__NR_futex_wait, sys_futex_wait)
#define __NR_futex_requeue 456
__SYSCALL(__NR_futex_requeue, sys_futex_requeue)
#undef __NR_syscalls #undef __NR_syscalls
#define __NR_syscalls 456 #define __NR_syscalls 457
/* /*
* 32 bit systems traditionally used different * 32 bit systems traditionally used different
......
...@@ -396,6 +396,44 @@ SYSCALL_DEFINE6(futex_wait, ...@@ -396,6 +396,44 @@ SYSCALL_DEFINE6(futex_wait,
return ret; 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 #ifdef CONFIG_COMPAT
COMPAT_SYSCALL_DEFINE2(set_robust_list, COMPAT_SYSCALL_DEFINE2(set_robust_list,
struct compat_robust_list_head __user *, head, struct compat_robust_list_head __user *, head,
......
...@@ -89,6 +89,7 @@ COND_SYSCALL_COMPAT(get_robust_list); ...@@ -89,6 +89,7 @@ COND_SYSCALL_COMPAT(get_robust_list);
COND_SYSCALL(futex_waitv); COND_SYSCALL(futex_waitv);
COND_SYSCALL(futex_wake); COND_SYSCALL(futex_wake);
COND_SYSCALL(futex_wait); COND_SYSCALL(futex_wait);
COND_SYSCALL(futex_requeue);
COND_SYSCALL(kexec_load); COND_SYSCALL(kexec_load);
COND_SYSCALL_COMPAT(kexec_load); COND_SYSCALL_COMPAT(kexec_load);
COND_SYSCALL(init_module); COND_SYSCALL(init_module);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment