From patchwork Mon Aug 7 12:18:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13344113 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9227C001B0 for ; Mon, 7 Aug 2023 12:37:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B70E68D0002; Mon, 7 Aug 2023 08:37:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 974528E0002; Mon, 7 Aug 2023 08:37:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A4D5900003; Mon, 7 Aug 2023 08:37:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 10C128D0002 for ; Mon, 7 Aug 2023 08:37:10 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D344C160A37 for ; Mon, 7 Aug 2023 12:37:09 +0000 (UTC) X-FDA: 81097258578.11.03F1E03 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf06.hostedemail.com (Postfix) with ESMTP id CF3E5180002 for ; Mon, 7 Aug 2023 12:37:07 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=KqO2kuHf; spf=none (imf06.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691411828; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:references:dkim-signature; bh=Xi18wbHB7VNHKYqwwPbXtDuzrsECrr9c5XSVyiI+TAw=; b=7+wXp4nTtvEqvQy399cuLGiL+2SVmhZFlB0/kDowJLBh1NCrIhtvGeW1HGjgLrgMDe2S80 7OusQuDCB7zn7Hop3Z4Ss8VBcp5jV73FiNt6HPGeJyVY85PTOejafQKHyMCSE3ljRMc6v/ LkXI2jivTgaVqBukiKfSH0a7rWoT4a4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691411828; a=rsa-sha256; cv=none; b=F0Z+SkOKKJfaVvRYQcJKU1aL7ALz/FkTK+rCqtr+UA2ZVNrZXxrH2krkwTOjf5czbthJ+Q k1x052nRHUlxsa4Oe5Y3DXr7IcVZzub1HCvX5J28M4tCFXueVVON51BCnJJb5lRmL618/B eIvIhDwvhfwbwIBNN/Hp4wtoITH3t04= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=KqO2kuHf; spf=none (imf06.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=Xi18wbHB7VNHKYqwwPbXtDuzrsECrr9c5XSVyiI+TAw=; b=KqO2kuHfKLrv5u2OY576yuyqTS MpbOyrVFRvo7ba296aw60KiAk4fzQqtj8P72vWN0T9Hc1gT0+aqIWFhqLtPjy5vx0RzYrpumAIOG/ Aek+ye7WtBQr+4HWa5BCSjSCLXADV6kA8mvRfog3zxySGaAosFLdQH4qVcVj/HMrnrwcm+msHG8EC SbcijN7kTPA+UjQ9oTgsiSnlToZ4gjGygc+kq3ct6wQXAoIbErA5zu4gYUNuHSB7VDf7yhdnBnpOd yBQagzYNZhTMX0CGgF0nOZVyjZajZX9sDU6NaMQtsXEEShakqKKrGTlx5US3CXnxVos3p5Kx7zVd9 0aOFqbDA==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qSzTl-00AxGN-Ho; Mon, 07 Aug 2023 12:36:57 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 287AA30334C; Mon, 7 Aug 2023 14:36:56 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id B074B2021C3DC; Mon, 7 Aug 2023 14:36:54 +0200 (CEST) Message-ID: <20230807123323.366498604@infradead.org> User-Agent: quilt/0.66 Date: Mon, 07 Aug 2023 14:18:52 +0200 From: Peter Zijlstra 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 , urezki@gmail.com, hch@infradead.org, lstoakes@gmail.com, Arnd Bergmann , linux-api@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, malteskarupke@web.de, Geert Uytterhoeven Subject: [PATCH v2 09/14] futex: Add sys_futex_requeue() References: <20230807121843.710612856@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: CF3E5180002 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: hrigg1wyfg44tngmkx6wgqz5853ijher X-HE-Tag: 1691411827-122153 X-HE-Meta: U2FsdGVkX19J3se0WZB5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9QMhiVPV+sECRxG6rMW4LuFmBX+aer5NTPe6mWfrgjeP8u6pV4iOenEWCwljyAWUytVy41shVkSSMr15tQ9y19CobS1pDS7HjvW+2lZZHKqFp+9S2S2JV0ZjkMBwi53yXouRJ/tlF1PKl/hOOf44tR7rDYzO2duNXdHGGxVnJ6WoxGcXWcjkAQCsTg0L3omNkirlD+tUDMvdky5rtRU99QOrfwmhGLAe0tZRZKKZvadQEXim0uiQiGQ+LwiJ2CzOad+4+ZCEMReztuCT X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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) Acked-by: Geert Uytterhoeven Reviewed-by: Thomas Gleixner --- 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);