futex: Add sys_futex_wake()
authorpeterz@infradead.org <peterz@infradead.org>
Thu, 21 Sep 2023 10:45:10 +0000 (12:45 +0200)
committerPeter Zijlstra <peterz@infradead.org>
Thu, 21 Sep 2023 17:22:07 +0000 (19:22 +0200)
To complement sys_futex_waitv() add sys_futex_wake(). This syscall
implements what was previously known as FUTEX_WAKE_BITSET except it
uses 'unsigned long' for the bitmask and takes FUTEX2 flags.

The 'unsigned long' allows FUTEX2_SIZE_U64 on 64bit platforms.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
Link: https://lore.kernel.org/r/20230921105247.936205525@noisy.programming.kicks-ass.net
22 files changed:
arch/alpha/kernel/syscalls/syscall.tbl
arch/arm/tools/syscall.tbl
arch/arm64/include/asm/unistd.h
arch/arm64/include/asm/unistd32.h
arch/ia64/kernel/syscalls/syscall.tbl
arch/m68k/kernel/syscalls/syscall.tbl
arch/microblaze/kernel/syscalls/syscall.tbl
arch/mips/kernel/syscalls/syscall_n32.tbl
arch/mips/kernel/syscalls/syscall_n64.tbl
arch/mips/kernel/syscalls/syscall_o32.tbl
arch/parisc/kernel/syscalls/syscall.tbl
arch/powerpc/kernel/syscalls/syscall.tbl
arch/s390/kernel/syscalls/syscall.tbl
arch/sh/kernel/syscalls/syscall.tbl
arch/sparc/kernel/syscalls/syscall.tbl
arch/x86/entry/syscalls/syscall_32.tbl
arch/x86/entry/syscalls/syscall_64.tbl
arch/xtensa/kernel/syscalls/syscall.tbl
include/linux/syscalls.h
include/uapi/asm-generic/unistd.h
kernel/futex/syscalls.c
kernel/sys_ni.c

index ad37569d05072acf431c55e4270843b05d315a72..3b86519d68e430346855f45ea18fdd45696cc108 100644 (file)
 560    common  set_mempolicy_home_node         sys_ni_syscall
 561    common  cachestat                       sys_cachestat
 562    common  fchmodat2                       sys_fchmodat2
+563    common  futex_wake                      sys_futex_wake
index c572d6c3dee0fd0f6370a9181099ed0840a0b8cd..714abeb1e6fa3925ece07b707ed3d67d6c1156d7 100644 (file)
 450    common  set_mempolicy_home_node         sys_set_mempolicy_home_node
 451    common  cachestat                       sys_cachestat
 452    common  fchmodat2                       sys_fchmodat2
+454    common  futex_wake                      sys_futex_wake
index bd77253b62e01c051bcaed6425013b95db82a29a..63a8a9c4abc16741221e80e7db5b489b1557b98e 100644 (file)
@@ -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           453
+#define __NR_compat_syscalls           455
 #endif
 
 #define __ARCH_WANT_SYS_CLONE
index 78b68311ec8192c2afb6d10ba92ebf5556a34b54..68974683737bffce97b993a0bfe933fe64acd19e 100644 (file)
@@ -911,6 +911,8 @@ __SYSCALL(__NR_set_mempolicy_home_node, sys_set_mempolicy_home_node)
 __SYSCALL(__NR_cachestat, sys_cachestat)
 #define __NR_fchmodat2 452
 __SYSCALL(__NR_fchmodat2, sys_fchmodat2)
+#define __NR_futex_wake 454
+__SYSCALL(__NR_futex_wake, sys_futex_wake)
 
 /*
  * Please add new compat syscalls above this comment and update
index 83d8609aec030fb6596c47cdf59b2d4ad6bab820..cd50247508e62696951702b91087329b0d3f7094 100644 (file)
 450    common  set_mempolicy_home_node         sys_set_mempolicy_home_node
 451    common  cachestat                       sys_cachestat
 452    common  fchmodat2                       sys_fchmodat2
+454    common  futex_wake                      sys_futex_wake
index 259ceb125367d45a5ce5fef4b8171e663ffff533..21eb35c693e12ebab49e59b803723cd14997bda3 100644 (file)
 450    common  set_mempolicy_home_node         sys_set_mempolicy_home_node
 451    common  cachestat                       sys_cachestat
 452    common  fchmodat2                       sys_fchmodat2
+454    common  futex_wake                      sys_futex_wake
index a3798c2637fd197605fbd773c433a9c144b9f10a..3a4e8513a8e16dc82943729172561ea96aa8ea88 100644 (file)
 450    common  set_mempolicy_home_node         sys_set_mempolicy_home_node
 451    common  cachestat                       sys_cachestat
 452    common  fchmodat2                       sys_fchmodat2
+454    common  futex_wake                      sys_futex_wake
index 152034b8e0a0f3166a8b9e92e9edea56b80c0a32..6883ea3b830da6864423471274dd800aa9c3b84f 100644 (file)
 450    n32     set_mempolicy_home_node         sys_set_mempolicy_home_node
 451    n32     cachestat                       sys_cachestat
 452    n32     fchmodat2                       sys_fchmodat2
+454    n32     futex_wake                      sys_futex_wake
index cb5e757f6621c885f441e3f258591b0f32ffb84b..48bc0fb4e3dc20a74a839ed03e9a6985119d3679 100644 (file)
 450    common  set_mempolicy_home_node         sys_set_mempolicy_home_node
 451    n64     cachestat                       sys_cachestat
 452    n64     fchmodat2                       sys_fchmodat2
+454    n64     futex_wake                      sys_futex_wake
index 1a646813afdca4b128443b8c364a018365f35cd7..a92625f5bad83a544206bb69224b6c8af84baa4a 100644 (file)
 450    o32     set_mempolicy_home_node         sys_set_mempolicy_home_node
 451    o32     cachestat                       sys_cachestat
 452    o32     fchmodat2                       sys_fchmodat2
+454    o32     futex_wake                      sys_futex_wake
index e97c175b56f965156bdfd680128f1b78e40f5999..57faa9786ffe7421ddb56374e13810fe05961917 100644 (file)
 450    common  set_mempolicy_home_node         sys_set_mempolicy_home_node
 451    common  cachestat                       sys_cachestat
 452    common  fchmodat2                       sys_fchmodat2
+454    common  futex_wake                      sys_futex_wake
index 20e50586e8a26c345b89682b7078e929034edfa5..e6c6ed6b30ee6afb1cfed7abedc0bfa2c4adf26a 100644 (file)
 450    nospu   set_mempolicy_home_node         sys_set_mempolicy_home_node
 451    common  cachestat                       sys_cachestat
 452    common  fchmodat2                       sys_fchmodat2
+454    common  futex_wake                      sys_futex_wake
index 0122cc156952cf55b630584a983702d12eddcc62..754720154dc1231b1d4a34a3b6a04030d3172318 100644 (file)
 450  common    set_mempolicy_home_node sys_set_mempolicy_home_node     sys_set_mempolicy_home_node
 451  common    cachestat               sys_cachestat                   sys_cachestat
 452  common    fchmodat2               sys_fchmodat2                   sys_fchmodat2
+454  common    futex_wake              sys_futex_wake                  sys_futex_wake
index e90d585c4d3e739011d596ced9b2dc19a6e2c0c1..902a997e7ec6ecb39a68aca3554f75c889ba3fff 100644 (file)
 450    common  set_mempolicy_home_node         sys_set_mempolicy_home_node
 451    common  cachestat                       sys_cachestat
 452    common  fchmodat2                       sys_fchmodat2
+454    common  futex_wake                      sys_futex_wake
index 4ed06c71c43fb76db32882217172f3b4baa2976d..8a1f887c8be66143925d5112c45f49b031bfd93c 100644 (file)
 450    common  set_mempolicy_home_node         sys_set_mempolicy_home_node
 451    common  cachestat                       sys_cachestat
 452    common  fchmodat2                       sys_fchmodat2
+454    common  futex_wake                      sys_futex_wake
index 2d0b1bd866ead6738e40f8b21cf2808ef66ae857..9e81323979b00f9d4485179c4d82cb0c8a137480 100644 (file)
 450    i386    set_mempolicy_home_node         sys_set_mempolicy_home_node
 451    i386    cachestat               sys_cachestat
 452    i386    fchmodat2               sys_fchmodat2
+454    i386    futex_wake              sys_futex_wake
index 1d6eee30eceb22abb1b9f7916a91b25823579e24..d10a6003a7c9f1e0adc8c908afa45524fdaccda6 100644 (file)
 451    common  cachestat               sys_cachestat
 452    common  fchmodat2               sys_fchmodat2
 453    64      map_shadow_stack        sys_map_shadow_stack
+454    common  futex_wake              sys_futex_wake
 
 #
 # Due to a historical design error, certain syscalls are numbered differently
index fc1a4f3c81d9b7e6c5cb0b698e251fad31534c4d..4e511bfd4b8f5fd56a05758b879da2d21a0f4267 100644 (file)
 450    common  set_mempolicy_home_node         sys_set_mempolicy_home_node
 451    common  cachestat                       sys_cachestat
 452    common  fchmodat2                       sys_fchmodat2
+454    common  futex_wake                      sys_futex_wake
index 22bc6bc147f899d1af6434d9695369b156ebc410..e174ed86da1da47baae01d709b675a7a9d124c2f 100644 (file)
@@ -549,6 +549,9 @@ asmlinkage long sys_set_robust_list(struct robust_list_head __user *head,
 asmlinkage long sys_futex_waitv(struct futex_waitv *waiters,
                                unsigned int nr_futexes, unsigned int flags,
                                struct __kernel_timespec __user *timeout, clockid_t clockid);
+
+asmlinkage long sys_futex_wake(void __user *uaddr, unsigned long mask, int nr, unsigned int flags);
+
 asmlinkage long sys_nanosleep(struct __kernel_timespec __user *rqtp,
                              struct __kernel_timespec __user *rmtp);
 asmlinkage long sys_nanosleep_time32(struct old_timespec32 __user *rqtp,
index abe087c53b4b04348431716c1cb638b99d5a788a..f5454e6f4c6ff3e02b35b7bdb7d4a2027159448b 100644 (file)
@@ -822,9 +822,11 @@ __SYSCALL(__NR_cachestat, sys_cachestat)
 
 #define __NR_fchmodat2 452
 __SYSCALL(__NR_fchmodat2, sys_fchmodat2)
+#define __NR_futex_wake 454
+__SYSCALL(__NR_futex_wake, sys_futex_wake)
 
 #undef __NR_syscalls
-#define __NR_syscalls 453
+#define __NR_syscalls 455
 
 /*
  * 32 bit systems traditionally used different
index 2339f9ccee7f6ab9c5ca0441e8d147ac0cbfd9e0..7049a52ef68e0ff9d34ca4738a76200efbedb7ff 100644 (file)
@@ -306,6 +306,36 @@ destroy_timer:
        return ret;
 }
 
+/*
+ * sys_futex_wake - Wake a number of futexes
+ * @uaddr:     Address of the futex(es) to wake
+ * @mask:      bitmask
+ * @nr:                Number of the futexes to wake
+ * @flags:     FUTEX2 flags
+ *
+ * Identical to the traditional FUTEX_WAKE_BITSET op, except it is part of the
+ * futex2 family of calls.
+ */
+
+SYSCALL_DEFINE4(futex_wake,
+               void __user *, uaddr,
+               unsigned long, mask,
+               int, nr,
+               unsigned int, flags)
+{
+       if (flags & ~FUTEX2_VALID_MASK)
+               return -EINVAL;
+
+       flags = futex2_to_flags(flags);
+       if (!futex_flags_valid(flags))
+               return -EINVAL;
+
+       if (!futex_validate_input(flags, mask))
+               return -EINVAL;
+
+       return futex_wake(uaddr, flags, nr, mask);
+}
+
 #ifdef CONFIG_COMPAT
 COMPAT_SYSCALL_DEFINE2(set_robust_list,
                struct compat_robust_list_head __user *, head,
index e137c1385c569ee573d5234dbe2fc59d036a715b..983c0583c627c9baf1f90161587bb1ee1291c4f8 100644 (file)
@@ -87,6 +87,7 @@ COND_SYSCALL_COMPAT(set_robust_list);
 COND_SYSCALL(get_robust_list);
 COND_SYSCALL_COMPAT(get_robust_list);
 COND_SYSCALL(futex_waitv);
+COND_SYSCALL(futex_wake);
 COND_SYSCALL(kexec_load);
 COND_SYSCALL_COMPAT(kexec_load);
 COND_SYSCALL(init_module);