From patchwork Fri Jul 21 10:22:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13321866 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 8ED98C001DC for ; Fri, 21 Jul 2023 10:59:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2496D2801C0; Fri, 21 Jul 2023 06:58:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1ED912801BD; Fri, 21 Jul 2023 06:58:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA12E2801C0; Fri, 21 Jul 2023 06:58:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 4ABB22801BE for ; Fri, 21 Jul 2023 06:58:56 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 25EB8A022B for ; Fri, 21 Jul 2023 10:58:56 +0000 (UTC) X-FDA: 81035321472.07.8DC1E47 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf27.hostedemail.com (Postfix) with ESMTP id 11DB940015 for ; Fri, 21 Jul 2023 10:58:53 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=OTY0sIeG; spf=none (imf27.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) 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=1689937134; 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=Ig3IvWIPDNo35V2b21H7Fs7QX8J2CTYfRUu1uDDpQU0=; b=lKtuqq1+CQadGB5e64OSx9UjyK5MvgAPl2tM2x7qj0X4cUpxm6nUzdpvl7EqvdyAd2WAAz tB34DwSXSvD2IZEs3/qhZPcXn6/PStrj/6rZ2Kg/Amb2KvlMXEPSod1zj2sEzkcrmDbBTz 6CBc00qM2BhAfZdnidHiRBCcbsP+8Qc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689937134; a=rsa-sha256; cv=none; b=4FjJlPwdQYgUhxr9OqsY0Fzw3GBfW1IOWA2VCiqL4W+Ipe/L+4kTKW9IvznjAOkz6+5YTC waRONmpVV+BBfir9ZQiBh16qhU6lyytnqXn5S/Vz/lBo04EJ+Uog5SXkrCgY2mHfPjPAUq AAT/b4nYQD0ZB05APKOHPx8Jxue5J/0= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=OTY0sIeG; spf=none (imf27.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=Ig3IvWIPDNo35V2b21H7Fs7QX8J2CTYfRUu1uDDpQU0=; b=OTY0sIeG/A30Uddn/mZpQmAVr+ nHBklxGbArWRT9fKn3CEpycGefV3tU2tdMr2tgP3rGgR52soiFLjwm9UMmCMu0dQo1rEftQ606kAK FRY5ZJkq0mqFDSVor7h4dM3unSe87zDPSvy5SL2kYSTZtCGOmyIfKrjAYsy7hUYK8RWw+xCOgIzGq tCeIwUswoQ6vsd7/W+9qyLrPDYpoRg4Q7aohFOR9hDpOY6/dDXTrGqBaKZ5ZAKN/yAUC93w68LKzq 7OHgvMn/RmbE3U15Q0tPRi8px7I3kod3wcAXglpM+K9n4+o+jUbI8sR+C/sSOnick6eVF3RqS/HBa nw5uykJw==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qMnqK-0000L7-1l; Fri, 21 Jul 2023 10:58:40 +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 2DA76300C1D; Fri, 21 Jul 2023 12:58:39 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 18AD53157E622; Fri, 21 Jul 2023 12:58:38 +0200 (CEST) Message-ID: <20230721105744.298661259@infradead.org> User-Agent: quilt/0.66 Date: Fri, 21 Jul 2023 12:22:46 +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 Subject: [PATCH v1 09/14] futex: Add sys_futex_requeue() References: <20230721102237.268073801@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 11DB940015 X-Rspam-User: X-Stat-Signature: 54odbhhwn41gciwi59ckk37w66zwysdy X-Rspamd-Server: rspam03 X-HE-Tag: 1689937133-690932 X-HE-Meta: U2FsdGVkX18J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422XcZj1H1bRdgB20IQjmrFqCXLhCqhR4U2zolVBmFjMmRA+py/L011ZVtIFwZuQ0t9N/AmTsl1VxfP4x87mvCsyLPV/TR/w+c5c1T8VaqUzHF2S+6KO1WGB+HfaSi3rTqFS8/f9U6Ieq+q2rVS3lX0na90Gsfad4rLYY4e8AeWPisUM3TtXxJOihERzATdkzeooCtcIZUTfRIlp+D 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}() it's 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 --- arch/alpha/kernel/syscalls/syscall.tbl | 1 arch/arm/tools/syscall.tbl | 1 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 21 files changed, 63 insertions(+), 1 deletion(-) --- 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/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);