From patchwork Fri Jul 21 10:22:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13321855 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 04201C001DC for ; Fri, 21 Jul 2023 10:58:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BDB3B2801B5; Fri, 21 Jul 2023 06:58:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B8BCB2801A0; Fri, 21 Jul 2023 06:58:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8CA7E2801B5; Fri, 21 Jul 2023 06:58:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6D87A2801B6 for ; Fri, 21 Jul 2023 06:58:52 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 3B6BA12011F for ; Fri, 21 Jul 2023 10:58:52 +0000 (UTC) X-FDA: 81035321304.02.2BB6AD8 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf18.hostedemail.com (Postfix) with ESMTP id 561591C000D for ; Fri, 21 Jul 2023 10:58:49 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=lFE5dOaG; dmarc=none; spf=none (imf18.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689937130; 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=QqRA1A/aeG7Vp+frAisWOweSXHDCgPVqvl/Ov07GdYA=; b=XSqABfDSg7CpbZUYjtE0SoRmY/PgIzg7fdq61l7mHfEplqwnC1wuvIDHSTsR6GHYe+e47T AX6JrDf6mLjXP2vRYH3G9SHa1JuhISgql0B6l+FoXllDh+NodhUDszZWiUKZAjKMzA4okU +35UfgTvKJ4lO7vnAWReVC64ZB2sRDM= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=lFE5dOaG; dmarc=none; spf=none (imf18.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689937130; a=rsa-sha256; cv=none; b=oqUop+7x5Wc92Te25BC4youhPa2HtfVrjsKM3r0Kg4sgmIsCGJ2Cm3NQglJc1VAKCV5S0c mf2P/DeIWqr0MgbdfDjkKoPexVeayUDTDv2JlGP310X9CyxFSka2CPLudbNQ6m5e8RgwPy 1BPZ/ghu1MstspkaBDH0v+7hGkCAkog= 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=QqRA1A/aeG7Vp+frAisWOweSXHDCgPVqvl/Ov07GdYA=; b=lFE5dOaGAlq2HalXhGp6uGQIwK esgYEROcz1Z6gk7Ytrd5tH8FRsG5OraXU5DaAG3mohup4EZtz2C7uGTEdDJgwGcFd5YlPZVSDnapP 8QsC1JaNsIo2SS6rv3zyjqt5LbwmVZrhtzE5D+QvYdUoWmP9/8NZ+Twmb4Wx6kxVG2goXOQC3OmiQ idJezFWYDjADNhx1Iz2iXmcLZu6awhOdlZQYjsThacLzjLe9IZTXsqtzsnBnp5cN2I2ueP48gmbk/ a5aYgcIuyM6UEqCwnWWBb4kn6f8E7y1Cuu6lR4NT7wYYwfmpd1zQPV6iWAagupMEQsDaARZ48MD5H bIcqw28A==; 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 1qMnqJ-0012OV-Jo; 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) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 2E5DF300513; Fri, 21 Jul 2023 12:58:38 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id E9077314E02E1; Fri, 21 Jul 2023 12:58:37 +0200 (CEST) Message-ID: <20230721105743.751364377@infradead.org> User-Agent: quilt/0.66 Date: Fri, 21 Jul 2023 12:22:38 +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 01/14] futex: Clarify FUTEX2 flags References: <20230721102237.268073801@infradead.org> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: rdgyuh7aheozi8mmtrhd9yywphohaac3 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 561591C000D X-HE-Tag: 1689937129-108297 X-HE-Meta: U2FsdGVkX19T1XmbN6QqjPyDWJ1FZMmfcyPK2cT7GqlzMSS6eNzXs5QtBHkGvXvXPVVr763xEoRSEHPTLv+hUJsqKFY5a4C/Ibin84NRxNIfF8B+Niz0ZdqG39DuEcCETAsZOZbJKePBO8sRiaoObEHxaNQ0oysBNJRzQ2GUxOsmipohKrqXAojbMmqkbLPmS24lDLW7XiGhiNRnNtDV/LdWirZ5nglc1ihIYyshDT4e6XrbYdTxRlFRRVMXhX44IPSgbT8L2Dcu7UYfJWszr3eW9ERAzaEHbghUrwv/9VeOxY8hTg6es+rlE/62l8CIGCD1oyZyJpSvqEvKLH/26rbID8YrB2vdLEhPKKbQmlKtxCAxxL8b8XkGBkGYjBV4qp7YYZn7I5X2XDWJBfTdTEtKm+LulRoSgOqiefluKtjw8iQ6EipQ2RlbONbjogU7Izzga0Y5MD/HkgPfUrdlnrxlnikIvsyjEo4+7seqr0HAHv8irl5lEiO/OAX1mqyOFiMzJ94JG/Po0BDJ59fS9VlKO50riiIRXhfafgR8B2yF/zjjbN5LpMMe+heR+395jNVD2k33/uG2Sx1uPW+LENtntlu7XRebLM7KjmZeG31e3908d1IJV0UIpy1vA8nnfbHvn3sV6JdI8kQXJO9OwUxMhYFIJkBKOyl7kBcII+i77aw5l3zF2RGbqGOdQxTFihhT4a5i6PjKGoXRoUCR7uUvg1sqDUP9uiAljheQu3ARmgDBLPHIF1f1/lDlek8oh+vI73cedwHLdtd14UEqNMqzN5vOiYZzxxHfbYOQkAdvjkHkORmSQWxtUgx7/1YbTZL8AKyuU4ArTWgTooJlmpCPQjO2BNXdiPnt4oSf1rW0qkUBqlMl2ar+2fmyY87mH9vfMIBmQh7dCw/WxGVhqx8srVCLpvb5xmVouHzBKOpSG1IAWYZUUsKZu0dmvUpno7yWTceXESdz5wvmmN1 kDp7XeQ5 gfP/tOUch4i6YFxxtJ+04hdRLvxmfJ9OuRiFPo6f+5jP0X0OyWQCUZgxuEXogVR+0DJZIOy8XiVbqF/vDqHxxOa+fw0eA018mh433wPTfdxYViUxek7YjdG8BNxA6jIaNxMo8VOVvOVmBBuEGcB7oU3byfPZCgWUu2UHEBQJheGbuRoLg1npKoRSCX2R8G2rtAXojCtFllUtEmD4MMIE7hq1OziKxacoVGNpvy+e699mL/ibWETKa4HOs+XTw94CkPVlsNSx+jQJifz0Vzjhlr2T1yQ== 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: sys_futex_waitv() is part of the futex2 series (the first and only so far) of syscalls and has a flags field per futex (as opposed to flags being encoded in the futex op). This new flags field has a new namespace, which unfortunately isn't super explicit. Notably it currently takes FUTEX_32 and FUTEX_PRIVATE_FLAG. Introduce the FUTEX2 namespace to clarify this Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Thomas Gleixner --- include/uapi/linux/futex.h | 16 +++++++++++++--- kernel/futex/syscalls.c | 7 +++---- 2 files changed, 16 insertions(+), 7 deletions(-) --- a/include/uapi/linux/futex.h +++ b/include/uapi/linux/futex.h @@ -44,10 +44,20 @@ FUTEX_PRIVATE_FLAG) /* - * Flags to specify the bit length of the futex word for futex2 syscalls. - * Currently, only 32 is supported. + * Flags for futex2 syscalls. */ -#define FUTEX_32 2 + /* 0x00 */ + /* 0x01 */ +#define FUTEX2_32 0x02 + /* 0x04 */ + /* 0x08 */ + /* 0x10 */ + /* 0x20 */ + /* 0x40 */ +#define FUTEX2_PRIVATE FUTEX_PRIVATE_FLAG + +/* do not use */ +#define FUTEX_32 FUTEX2_32 /* historical accident :-( */ /* * Max numbers of elements in a futex_waitv array --- a/kernel/futex/syscalls.c +++ b/kernel/futex/syscalls.c @@ -183,8 +183,7 @@ SYSCALL_DEFINE6(futex, u32 __user *, uad return do_futex(uaddr, op, val, tp, uaddr2, (unsigned long)utime, val3); } -/* Mask of available flags for each futex in futex_waitv list */ -#define FUTEXV_WAITER_MASK (FUTEX_32 | FUTEX_PRIVATE_FLAG) +#define FUTEX2_MASK (FUTEX2_32 | FUTEX2_PRIVATE) /** * futex_parse_waitv - Parse a waitv array from userspace @@ -205,10 +204,10 @@ static int futex_parse_waitv(struct fute if (copy_from_user(&aux, &uwaitv[i], sizeof(aux))) return -EFAULT; - if ((aux.flags & ~FUTEXV_WAITER_MASK) || aux.__reserved) + if ((aux.flags & ~FUTEX2_MASK) || aux.__reserved) return -EINVAL; - if (!(aux.flags & FUTEX_32)) + if (!(aux.flags & FUTEX2_32)) return -EINVAL; futexv[i].w.flags = aux.flags; From patchwork Fri Jul 21 10:22:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13321864 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 9D6DAC001DC for ; Fri, 21 Jul 2023 10:59:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B44822801C1; Fri, 21 Jul 2023 06:58:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B15E12801BE; 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 744862801C2; 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 54FCC2801BD for ; Fri, 21 Jul 2023 06:58:56 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 329C71A023C for ; Fri, 21 Jul 2023 10:58:56 +0000 (UTC) X-FDA: 81035321472.03.132F98A Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf29.hostedemail.com (Postfix) with ESMTP id 20DBA12001A for ; Fri, 21 Jul 2023 10:58:53 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=i2Up1YJc; spf=none (imf29.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=0OvZxrAbgKVueqnrMDc9zKBhn7N/Qfvk936XgBKJyzg=; b=EHxz3pU3ZHyivHf3/sLm+K3KA3kZJ6jTb/80n5MHVxpZR1pAMWX/JOtxgPLaq+aV52LwaI iPwpXTeFgMHgi/JOdJGB9Stg4XCetEysTqM+ChPk3xpQ1X06McY+KpVDMf885An1EchWqW BYCVBVI88so6MFvlCIE/sAoqKShBV+0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689937134; a=rsa-sha256; cv=none; b=NQLHd/H1iHsU3Ma/V6g8tK6Owc/5HVlmfK2xCdQZW9d9yEGaI4FucHNwB9k4NMxOcKz7qQ 2XRa3umvMXhSgUeaCybPMrkb5ft/j2La5c1X3J3vH2NKrtMYXtT5dvR1rsrlUd3KI84Cxd rf19sPPirIkICX+FcrQ6kS15QOtG8Oc= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=i2Up1YJc; spf=none (imf29.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=0OvZxrAbgKVueqnrMDc9zKBhn7N/Qfvk936XgBKJyzg=; b=i2Up1YJcKcROlG2uFhIm/PX3JM XmlM0nBGqzdATbwc0H09VZ4Cnh28vJg3gQOTltByte8iuH6Doc2RaXszR9lHG4kvFIGJJ7W8H5u/e bFZXkUBflexyC8HwKIqTbUu/hCXdg+ZR4N7D+3IhTuTXVMXpw/H5F+Y4sFf3mGjPs8gV+Wg/wXPQU auZ5VYpTsbYWOiqTa9O8AQdfIMeuFhCgw0ckRubRkc2RdCsKMQJOvA8lWutJRkeIHIFfq+UWvjmHB WRe2YxzC3uS4F95VTLdcSyWaobmiuIWCw3CI75xItB4KbRIk0Bx9vSmZ7/5xQGQg6WGzQCoDF2zPY PznX7d1g==; 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-0000Kz-0r; 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) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 31D30300886; Fri, 21 Jul 2023 12:58:38 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id EB8D2314E02F2; Fri, 21 Jul 2023 12:58:37 +0200 (CEST) Message-ID: <20230721105743.819362688@infradead.org> User-Agent: quilt/0.66 Date: Fri, 21 Jul 2023 12:22:39 +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 02/14] futex: Extend the FUTEX2 flags References: <20230721102237.268073801@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 20DBA12001A X-Rspam-User: X-Stat-Signature: fm4id8juyxzun5np9xw619isqxycsegx X-Rspamd-Server: rspam03 X-HE-Tag: 1689937133-352470 X-HE-Meta: U2FsdGVkX1+t9DViixGgwkYaoAKSc6hTfEeSRIMJT5nzC0Xtp0K32m+GGgQSR5jlyRYmJT4zWp9cSVk5imje7+XcVEfvkdRqhGhQ5DUyFuKiHXB2IfATjhfH4W9G0phBcLNzQMf4WCVhYk4DyLeLwk60iS81sND6MlKavxCrSPSyRkXDjNZBE/orRBYJ7E34a8bmB8ezsoBn1fK7MEGmSlQWqNe7ZjFVVYR9woi9Ms7t1xA0r7wTJAs/dIeRd5djl+rAWibHNBGgbprcuEE8YKzfMDtkr7GSfO8DJcjSAW1HqRnJhPtBHsUqxDVZTHbVmeUajSjANFUGa74Jztzi8t0yDxMUI27BKA2xCFOiaSpIRBFsF1qThYmoZNg2NyMFM3deg0HqhmydqGJk/Q26zX2hKiFDcvwqqRFgXkoA4iGclt5YAQC/6bbrwqXyXHRE6edulLP7nEC8DavAtMcodANQr7E4i2GJRb6mqQEOz9ek9w491w0ehhqm5O0CELie+rIsnrUOa4e/YP/vUsPKp4Q3BtpNUgaVhnkXOTHmILMUWtUJL6v8JdHU99i+h6+elCscUncul7SRLj0ZlDCrFZlEG+qyrCDGCZwWBUky2NPlmz0HuxZrfQFJNetKvGQWtTj1R+w4YxHWLKFX8filSYbUlionrbNO+TM/Z2QNQBTny/zvQ7jtl1Z2Ocu5wvMJlIIVCVUVL8OzDo9PmVukgB5IYlCQse/aMSYERuvBZg16uXqRhwXSNZ+kw4QT/VHn7Db7/0pc5BkEMol8t652f6MzC57aKo3h809tkxibDi2NsVctQLnA4mzrLX3FMxIhoWpQGX6WduIsmZ6rDvuufoqzppD5K0J5QHvtDtUWqgWly/J5DmYtsny2spQW6lZb0R9wxd5YH28HDMWHWEYKU9FKwo8f4lUoKkN6i58RZvppduLtDLaE6upXcisOO18sDiKor+jaYjJTINwCXkN VDZtw4mJ e4vVegQjnuaIAotoM+888ZFnGoVkAuH/D3M7+zPQafNbullaS+3dsKl2UmXG7Mbkh8tYylrC9yAjA9uC+8380uhZX+LDPUiocuYgpX0GyNNHL1GwC2XG6OEw1l8lcmfxQXeD6TbmFhje2t7bWYhNz75UiguG9L/odYJA1pEloZmRSY9QdSWetP6oTPue3y9IkvkmubaQaKR19IHUkTw3DzxtblcH4zPdCkuNnf4ZBrQA+LjWbSuJ9mvPYPQH02kV6ZCkfs9jA7YgpIGeTldY9Enh16Q== 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: Add the definition for the missing but always intended extra sizes, and add a NUMA flag for the planned numa extention. Signed-off-by: Peter Zijlstra (Intel) --- include/uapi/linux/futex.h | 7 ++++--- kernel/futex/syscalls.c | 9 +++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) --- a/include/uapi/linux/futex.h +++ b/include/uapi/linux/futex.h @@ -46,10 +46,11 @@ /* * Flags for futex2 syscalls. */ - /* 0x00 */ - /* 0x01 */ +#define FUTEX2_8 0x00 +#define FUTEX2_16 0x01 #define FUTEX2_32 0x02 - /* 0x04 */ +#define FUTEX2_64 0x03 +#define FUTEX2_NUMA 0x04 /* 0x08 */ /* 0x10 */ /* 0x20 */ --- a/kernel/futex/syscalls.c +++ b/kernel/futex/syscalls.c @@ -183,7 +183,7 @@ SYSCALL_DEFINE6(futex, u32 __user *, uad return do_futex(uaddr, op, val, tp, uaddr2, (unsigned long)utime, val3); } -#define FUTEX2_MASK (FUTEX2_32 | FUTEX2_PRIVATE) +#define FUTEX2_MASK (FUTEX2_64 | FUTEX2_PRIVATE) /** * futex_parse_waitv - Parse a waitv array from userspace @@ -207,7 +207,12 @@ static int futex_parse_waitv(struct fute if ((aux.flags & ~FUTEX2_MASK) || aux.__reserved) return -EINVAL; - if (!(aux.flags & FUTEX2_32)) + if (!IS_ENABLED(CONFIG_64BIT) || in_compat_syscall()) { + if ((aux.flags & FUTEX2_64) == FUTEX2_64) + return -EINVAL; + } + + if ((aux.flags & FUTEX2_64) != FUTEX2_32) return -EINVAL; futexv[i].w.flags = aux.flags; From patchwork Fri Jul 21 10:22:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13321865 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 B5B7BEB64DC for ; Fri, 21 Jul 2023 10:59:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E6EE92801BE; Fri, 21 Jul 2023 06:58:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DACCD2801C5; 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 919612801C4; Fri, 21 Jul 2023 06:58:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 5E2712801C0 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 332E2A022D for ; Fri, 21 Jul 2023 10:58:56 +0000 (UTC) X-FDA: 81035321472.07.E5660B7 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf26.hostedemail.com (Postfix) with ESMTP id 1169414001E for ; Fri, 21 Jul 2023 10:58:53 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=C7i2naEt; dmarc=none; spf=none (imf26.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org 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=SORtMlf6AQ8aFXAtXEB5iMu/bkrYMuTpcyv7hAzIkB0=; b=McziUCteZnj3oIsbwIKNhJNT6et42VmAXq0d4H6t6Fp/CR1YPrx8K2vPJWTAxRpGgZ1FEQ 3ZB41zF3V8rjEY/xhMT0XssJv5KeiTsdp0CdGDBnMH3mJVJjvxGhDFnEMFWIW9Ug9znE+N 79UXtz4o2qmC8PJOre9r4IAFCNq+Ids= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=C7i2naEt; dmarc=none; spf=none (imf26.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689937134; a=rsa-sha256; cv=none; b=jzCRJL1AK76LSXghcoT3nV4s6ZPuwvE3+Jjnq1UireqfuBV/z71SsSZtBKaZgQ/6c5hKX8 RTBfQY4E6eU21l1BLbvYEnMlAlSN5ofeIgW1mjt2HY4p0qK4ljZ4co1ZM64GAHNQyaIIIO S+u/xswR4ApNGg93Bv3NKqoemyebwMQ= 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=SORtMlf6AQ8aFXAtXEB5iMu/bkrYMuTpcyv7hAzIkB0=; b=C7i2naEtXB9PgOtkFyyD1IzI3C 9aIziC4VcH7AzunWf3zawU5TgSmHegDHfjYHDsdbBOcybREbz8Vrrl3Kx3BYHtkrHQOT3GioEQXD6 2WnojWFweddsKJprJPiwjRyQfQhZLIrKa67xiG11UAG694EvfKe1sc9LOCMpLy9j3rO7Wug//JpRq rVdiqDTuEXeRA84KUzdCYKCOx2oxkRZlk06UU5uzIwLog5GZ3QLxrGqlua8XmcAyzilhwndfdboRy 03qi9MYO17P+6tvHDsLaUzB5cwRNOKIgebn1XXInDS7DudxcciIQmX98jPfajh2nGdyjCRzC31eR3 jsJPM9ig==; 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-0000Ky-0r; 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 33B583008AC; Fri, 21 Jul 2023 12:58:38 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id F190A3157E61C; Fri, 21 Jul 2023 12:58:37 +0200 (CEST) Message-ID: <20230721105743.887106899@infradead.org> User-Agent: quilt/0.66 Date: Fri, 21 Jul 2023 12:22:40 +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 03/14] futex: Flag conversion References: <20230721102237.268073801@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 1169414001E X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: oc6b7tizxgzg3uihh68wm17b9eb3qpcp X-HE-Tag: 1689937133-265859 X-HE-Meta: U2FsdGVkX19LZhh1+Gil0ngkXiT8PobibPEcVreghxipdP2DNCxZtPqAytncgNLgvD4U7CBTjFKiTdT95jNgZVc6Z3ZkNpCW1JQy4HriZNwoqwIpZjUypl7oSCsIZgeULvhslugHj84ZEl5cMdS65jDdweXixojQaIiEhzaUic9SANKK6/pE4cOzJa3CicFs5xcDvgKkV8KEp37JJAiz3kq7A86KrF9ettpp/W6DnK/mgCvIbDmHl9geaANMHGNM9ACf+uTszS7kiy+le0YsfXa91DwbzcACf8JxjCMe5zSHDdsBM4+EW4/v/wMfJ5dvWM+EkQ/n9hZSTLRuM7nWvFatGqAD3QjL+BYqssYWrf1xz4CT3gmT4X0niaL0CSofYjL7lwucgwqo9cwjG5ofZuzsvLBY6UXIUpDj7j6x0XfFM2qGEuqAcU2c+YQ3SBd0wjqoy2GWCm8Fq5icxk7OxBVJjfj0ty4C9jBsVVM+HGCFazeKBjcRoTKH7ZnuplKHcPxiykz2IG4E7YllbhTKXtMqrMf2RrAvsdZmTfkd0uaGMlfgoHATLzr/C/7HN7gbPwOQS7vrgtAIA05hISsteiLmbxAVJ67j2eyNFuR53ujNddYLYHKiVEl01f2XIB5LdgOoh27emYnHaM7M7CLsrFSh1ukL9nz0exRKqnh5V+YHMUIxKr44h9p/zB4/grEa8/gsZeNdX7O1O5YqG4kEPAwqvflIHbOPg21rVjaoiq0TIpLBnsJxDCyNE6ABMdHJJAafr28gEaN1CTh9ssZ+AfMuNVNb/LwXQTo/G3J7kVJUXa1XMAUnNBl8BNQYW9pj/RA0sAdp/Cy2+stmONOmUH3bSo/nbdURQjTo1VLxGB78Xi2xZ5c7ZXqxe8QqaztTb4ycJtm/mc5QmneQPrPf40URSiJMw5o1uWJVubLbohjREm+Akj3/KESx66JdStbGcgm2O8oWr9JBZ7bbNtN 8j+Rk+Dm Z/LWF8cZVVpA4Eq+akdBpE9tUAlRQ8yPkk2NmvBprP0/Zo+ZS30GP2V6UdeAmX45AnrC5rCGOqREBK86AKjp3HbRD+ADMInqDO4NPid1ptPP7eHJN+smhYOyHKMBNYKsdKyYlJP+gV6FIR2m4RxxDdy6trlgqMeFa8MEw+rcsvzJRHP8656orzCDFxTEXfegDMM0XQ0Rv8HAhFgQHDzS2yR0wQ+ihy/WAsca//Wu4vXUoZKlPAbCMM1ojboqPb+inV9haEwHDyNs46tS/XyZQK4Y5KA== 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: Futex has 3 sets of flags: - legacy futex op bits - futex2 flags - internal flags Add a few helpers to convert from the API flags into the internal flags. Signed-off-by: Peter Zijlstra (Intel) --- kernel/futex/futex.h | 64 +++++++++++++++++++++++++++++++++++++++++++++--- kernel/futex/syscalls.c | 24 ++++++------------ kernel/futex/waitwake.c | 4 +-- 3 files changed, 72 insertions(+), 20 deletions(-) --- a/kernel/futex/futex.h +++ b/kernel/futex/futex.h @@ -5,6 +5,7 @@ #include #include #include +#include #ifdef CONFIG_PREEMPT_RT #include @@ -16,8 +17,15 @@ * Futex flags used to encode options to functions and preserve them across * restarts. */ +#define FLAGS_SIZE_8 0x00 +#define FLAGS_SIZE_16 0x01 +#define FLAGS_SIZE_32 0x02 +#define FLAGS_SIZE_64 0x03 + +#define FLAGS_SIZE_MASK 0x03 + #ifdef CONFIG_MMU -# define FLAGS_SHARED 0x01 +# define FLAGS_SHARED 0x10 #else /* * NOMMU does not have per process address space. Let the compiler optimize @@ -25,8 +33,58 @@ */ # define FLAGS_SHARED 0x00 #endif -#define FLAGS_CLOCKRT 0x02 -#define FLAGS_HAS_TIMEOUT 0x04 +#define FLAGS_CLOCKRT 0x20 +#define FLAGS_HAS_TIMEOUT 0x40 +#define FLAGS_NUMA 0x80 + +/* FUTEX_ to FLAGS_ */ +static inline unsigned int futex_to_flags(unsigned int op) +{ + unsigned int flags = FLAGS_SIZE_32; + + if (!(op & FUTEX_PRIVATE_FLAG)) + flags |= FLAGS_SHARED; + + if (op & FUTEX_CLOCK_REALTIME) + flags |= FLAGS_CLOCKRT; + + return flags; +} + +/* FUTEX2_ to FLAGS_ */ +static inline unsigned int futex2_to_flags(unsigned int flags2) +{ + unsigned int flags = flags2 & FUTEX2_64; + + if (!(flags2 & FUTEX2_PRIVATE)) + flags |= FLAGS_SHARED; + + if (flags2 & FUTEX2_NUMA) + flags |= FLAGS_NUMA; + + return flags; +} + +static inline bool futex_flags_valid(unsigned int flags) +{ + /* Only 64bit futexes for 64bit code */ + if (!IS_ENABLED(CONFIG_64BIT) || in_compat_syscall()) { + if ((flags & FLAGS_SIZE_MASK) == FLAGS_SIZE_64) + return false; + } + + /* Only 32bit futexes are implemented -- for now */ + if ((flags & FLAGS_SIZE_MASK) != FLAGS_SIZE_32) + return false; + + return true; +} + +static inline unsigned int futex_size(unsigned int flags) +{ + unsigned int size = flags & FLAGS_SIZE_MASK; + return 1 << size; /* {0,1,2,3} -> {1,2,4,8} */ +} #ifdef CONFIG_FAIL_FUTEX extern bool should_fail_futex(bool fshared); --- a/kernel/futex/syscalls.c +++ b/kernel/futex/syscalls.c @@ -1,6 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-or-later -#include #include #include @@ -85,15 +84,12 @@ SYSCALL_DEFINE3(get_robust_list, int, pi long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout, u32 __user *uaddr2, u32 val2, u32 val3) { + unsigned int flags = futex_to_flags(op); int cmd = op & FUTEX_CMD_MASK; - unsigned int flags = 0; - if (!(op & FUTEX_PRIVATE_FLAG)) - flags |= FLAGS_SHARED; - - if (op & FUTEX_CLOCK_REALTIME) { - flags |= FLAGS_CLOCKRT; - if (cmd != FUTEX_WAIT_BITSET && cmd != FUTEX_WAIT_REQUEUE_PI && + if (flags & FLAGS_CLOCKRT) { + if (cmd != FUTEX_WAIT_BITSET && + cmd != FUTEX_WAIT_REQUEUE_PI && cmd != FUTEX_LOCK_PI2) return -ENOSYS; } @@ -201,21 +197,19 @@ static int futex_parse_waitv(struct fute unsigned int i; for (i = 0; i < nr_futexes; i++) { + unsigned int flags; + if (copy_from_user(&aux, &uwaitv[i], sizeof(aux))) return -EFAULT; if ((aux.flags & ~FUTEX2_MASK) || aux.__reserved) return -EINVAL; - if (!IS_ENABLED(CONFIG_64BIT) || in_compat_syscall()) { - if ((aux.flags & FUTEX2_64) == FUTEX2_64) - return -EINVAL; - } - - if ((aux.flags & FUTEX2_64) != FUTEX2_32) + flags = futex2_to_flags(aux.flags); + if (!futex_flags_valid(flags)) return -EINVAL; - futexv[i].w.flags = aux.flags; + futexv[i].w.flags = flags; futexv[i].w.val = aux.val; futexv[i].w.uaddr = aux.uaddr; futexv[i].q = futex_q_init; --- a/kernel/futex/waitwake.c +++ b/kernel/futex/waitwake.c @@ -419,11 +419,11 @@ static int futex_wait_multiple_setup(str */ retry: for (i = 0; i < count; i++) { - if ((vs[i].w.flags & FUTEX_PRIVATE_FLAG) && retry) + if (!(vs[i].w.flags & FLAGS_SHARED) && retry) continue; ret = get_futex_key(u64_to_user_ptr(vs[i].w.uaddr), - !(vs[i].w.flags & FUTEX_PRIVATE_FLAG), + vs[i].w.flags & FLAGS_SHARED, &vs[i].q.key, FUTEX_READ); if (unlikely(ret)) From patchwork Fri Jul 21 10:22:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13321857 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 B292DEB64DC for ; Fri, 21 Jul 2023 10:58:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6358B2801B9; Fri, 21 Jul 2023 06:58:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 60BE62801B7; Fri, 21 Jul 2023 06:58:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 326922801B7; Fri, 21 Jul 2023 06:58:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 126722801BB for ; Fri, 21 Jul 2023 06:58:53 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id D6CC3A022D for ; Fri, 21 Jul 2023 10:58:52 +0000 (UTC) X-FDA: 81035321304.02.6E03EC1 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf04.hostedemail.com (Postfix) with ESMTP id 20D8B40011 for ; Fri, 21 Jul 2023 10:58:49 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=RjOze5I0; spf=none (imf04.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689937130; a=rsa-sha256; cv=none; b=FrJrJOr/0b3xIUPz8ciLsoMLiG2bF4AGkaK26VU3Fdq4ciP39xIVWZYAIOXny91hMizWBi y8mGN4Gpa/s4qaWc0Mkj+3EJyn13/4Qua3SMFoZehkt96nrILdK3/yHEK0dPefKHDsVaQh ZEW6uN7PYCuwYdd5S0HdtIuJFLSnFts= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=RjOze5I0; spf=none (imf04.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=1689937130; 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=Url1S2KkTliaPbsKSfxxrI3LXJILvuEJ2CRpOdAeZx4=; b=W3xQ76zEuoo5IglEri0CinFhH/dsoH4afWScsaCvhDFdPatFSc9xVT6QVnCZ4NvJxe+oGJ 0ydGsYiVqcdCgg07QDN+yaaTJf6QWhWDcbwnnumm9ycR9ZS7sUXOx7ZDYZagZSr7PkapJ+ dTFn6IBc6r50V5icUVEhyqBFVKxtgTM= 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=Url1S2KkTliaPbsKSfxxrI3LXJILvuEJ2CRpOdAeZx4=; b=RjOze5I06m1EPmRzvNMOw4h7zJ 10p45BmFIxxQzO/qLwTkFJsFTB0PrU576kmq0IyFHIfRA75xAexc2xh4dIaNRLa9Y5LNrafe+Y2HU XYyyFWUYwG1XdG7GwrQ8X4aBV8FeMN9VtfhlEzqZaTTa234TXbfT/mP2/kEwc5dwzows9j7EO/zTP 51+OgjfvYfrt/+bUwB908HZKFKqXxSPH9Bxt5Vx+8/i0uds+40kFe/jiU8oYpZzOG2lVwthSuPRLl awEwZyTRVb/2zt01EAaLdTRESfjSw9Qsmle/lZskaj31xN2PyMnVDsz78EP0+awx5ayhv/lILMr2+ U+nM8rUg==; 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 1qMnqJ-0012OU-K0; 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 35687300911; Fri, 21 Jul 2023 12:58:38 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 020DE3157E61D; Fri, 21 Jul 2023 12:58:37 +0200 (CEST) Message-ID: <20230721105743.954526690@infradead.org> User-Agent: quilt/0.66 Date: Fri, 21 Jul 2023 12:22:41 +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 04/14] futex: Validate futex value against futex size References: <20230721102237.268073801@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 20D8B40011 X-Stat-Signature: gft7a6kgf1trs3obz1qwzjnbs4zz89by X-Rspam-User: X-HE-Tag: 1689937129-217362 X-HE-Meta: U2FsdGVkX1/aoMUpGzo/1sOeu3SGM5VCmp6qbY+pltu3vzBC3nAzLeCglo+VEbgQzD91GEF46wyzeTgjrbZ7IcdQ3at64WYngEgSI+tocIqlruFMR0i1YLtzrooMak+O2IDPYrgC2ndbAtyAeSoJ8n4Xq9aheQr6R/TaEtqk9SRyMJL+h0rNiGT8FAdM+gQZC0E7CYDIjPS9ayUGS16TAaoPOdKK4jCcZSciYWkbHeYQECkRQVwfJlPmA9+/LyvEOBsW7eVK1sFUAT3jci4pPUAeV6QyZBAEsX//PEd8rdtMxuG1MBE7opFqHmK+Q2KkN41aHn6X07JIscCMiMhlScyqs3M+5lMZU5LQr7iIsMhOSdOxgpq+IYpzXCoYLzgikHl+2A0yxfTxEOLj1i0fQs6i0RnyWz4K0Y30180Pt9BAKXUY5KJTDhftrC+855cSxZYHbsQdud2bQJoYVLVTiqr+G1iJdWH3gOU7M9AS/Xb2oMXbLAY9h+DLvvJeyqLjg61vWiEZsctllNu9G4l5StnTqB7Jl1PXnG35zMWv9Y6EWluNdX1ZxtVbTHDN2MCub9WIVquNrYjhIZx8b/kUMEgCRsHgKhIor9V6BhyUg5SHmDBjuwdMzd8bDeQ/t8v36wGp+ZeBBraOdPlMBZAyDOhWDYe1yxVbK8HUQUMv0Ynm5lfg6sQCMpVSKKns5AC8vtaY/stj1hIcqU46jY5z9jhViuCq7Sd358LkUUFitE6PCuLbhTM5mHrV2HVjr7HtZCwIoMhYoWBVnROa+GFM6YlIUfDjVyZ0uxo1XmBau5muFtqloWyvKdquSRgdatTfjA3gbMsqMXttcezEeA705KUBCAJyFyhNI9uC3DQPTqUBnTz9SGbIIMm9Q80n/3oJxplc/f3XTj4xJYQZCeas/x+gmPiWv5lDqQGZFvarm6aeknS/VWJ4axGYcsM7DFH8O1QqffbifrDsVux4lia CvVu7MCo 7Ly2UGncuyzBMqDv3IX0+Q5unct0hsqL893CsEMaTJKervlyreSd+ArSNGXS9b/H67opu1NEJiFyRlAYNrAecuYZO3w89FS7F6IICVXanXpYNDUzito+4CaxW3B/5HAp4PI+Ffhr5D7SDA9ybuXMYqJr2AGMBG6D0jYZPFlXFD7grUJ5qqgo9X0BbVvJr4ATifjpmncYG7WOr8zGYZxx0UWa1/W+9vaE2kjhmBI66LYPstsKO8IW0JX+zotqybTQYMegJwwgl6ug4VN7FJ3nZRIHdNQ== 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: Ensure the futex value fits in the given futex size. Since this adds a constraint to an existing syscall, it might possibly change behaviour. Currently the value would be truncated to a u32 and any high bits would get silently lost. Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Thomas Gleixner --- kernel/futex/futex.h | 8 ++++++++ kernel/futex/syscalls.c | 3 +++ 2 files changed, 11 insertions(+) --- a/kernel/futex/futex.h +++ b/kernel/futex/futex.h @@ -86,6 +86,14 @@ static inline unsigned int futex_size(un return 1 << size; /* {0,1,2,3} -> {1,2,4,8} */ } +static inline bool futex_validate_input(unsigned int flags, u64 val) +{ + int bits = 8 * futex_size(flags); + if (bits < 64 && (val >> bits)) + return false; + return true; +} + #ifdef CONFIG_FAIL_FUTEX extern bool should_fail_futex(bool fshared); #else --- a/kernel/futex/syscalls.c +++ b/kernel/futex/syscalls.c @@ -209,6 +209,9 @@ static int futex_parse_waitv(struct fute if (!futex_flags_valid(flags)) return -EINVAL; + if (!futex_validate_input(flags, aux.val)) + return -EINVAL; + futexv[i].w.flags = flags; futexv[i].w.val = aux.val; futexv[i].w.uaddr = aux.uaddr; From patchwork Fri Jul 21 10:22:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13321856 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 B1898EB64DD for ; Fri, 21 Jul 2023 10:58:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EA6572801A0; Fri, 21 Jul 2023 06:58:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DFBB72801B7; Fri, 21 Jul 2023 06:58:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A79E22801B6; Fri, 21 Jul 2023 06:58:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 659DD2801A0 for ; Fri, 21 Jul 2023 06:58:52 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 3E1E71A0227 for ; Fri, 21 Jul 2023 10:58:52 +0000 (UTC) X-FDA: 81035321304.08.5E8741F Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf05.hostedemail.com (Postfix) with ESMTP id 17139100012 for ; Fri, 21 Jul 2023 10:58:49 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=lSsRZMc9; spf=none (imf05.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689937130; a=rsa-sha256; cv=none; b=wwYLRuznUmdjQ5MVIz1Cg0pEXhxIr2QGLfu3Vcw7R9vi67jMwxYtlZpqzZZKYpEABGQq6/ Jr3/87+DHOFDJL+ByqkTtw2Qo/VMjdAReoMV9E94/Kl002kh4fBHDHAFzjMOkzNziJw6W+ egdRu4sCYWMLaZrozPhUPN998dOQbaU= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=lSsRZMc9; spf=none (imf05.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=1689937130; 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=MbiyL9h+1k5eBqWcaS863zQjxcb9GdsKTgaiCBDYOPw=; b=NuzFp9maumMM5B5vYmwp/0zxVVIw+bPholLtknU1smV3hdeED8MH/pn8kpt5rXHqL3sXlt IT8QRMopXh/grXFLDfgUvN5Molru6eiN5LQtEVe8f+rQ9HEmh912ULyPmeVCWjU4WossJ7 XnJb+wZ86JrILRwU4xxA30Y2tSEYE3k= 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=MbiyL9h+1k5eBqWcaS863zQjxcb9GdsKTgaiCBDYOPw=; b=lSsRZMc9T3tGB9Ieux+7hvkxfF Vnz5Lsvm2DYmHmKQq3w/c4FK8AjTU2Bn7kUeQQhdbWn3QC7/C19EOf9rMc1/nPR5qOXneVXZbRsq1 An6V+XSLXnXUzrTm6QDiDdqrn7CA+eNyOilPo535fQwcD2Uqn8nAFnL0Jk58B4Rm2X2DaXC+KGlHy e+/4vpaEz7u1OpNNH/QRx5XJ3ZTNTHG7OgWZs30fD+Q9Db443cfgxgP8iWplL4EkKCrhxYRcZcqf7 i2rJlSJHM/XGAFME3I/tS1FmavMMFlmDe/UQBu4NlDwPbDDB88QOQvq0znfdtwO856yNKhRC21CKZ rETTZ9zg==; 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 1qMnqK-0012Oc-7m; 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 2DAD9300C24; Fri, 21 Jul 2023 12:58:39 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 064873157E61E; Fri, 21 Jul 2023 12:58:38 +0200 (CEST) Message-ID: <20230721105744.022509272@infradead.org> User-Agent: quilt/0.66 Date: Fri, 21 Jul 2023 12:22:42 +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 05/14] futex: Add sys_futex_wake() References: <20230721102237.268073801@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 17139100012 X-Stat-Signature: 7imrq9mba88pr7xn89inhra4mhzdyuea X-Rspam-User: X-HE-Tag: 1689937129-990785 X-HE-Meta: U2FsdGVkX1+qGKAGEvw7X97bmz1KCqkOsUYpy/nux74x0jNozeHhiDPCtI4tLXmrjOqIhjzBhkA/CG+ZXiZldevCkGoiX0fjQiQFx1tAMA/pAsKCK9Kbn5DPIVs/YEF8uVF8s7HZ8WZKLw1q/8Yr7LFfHY2u6wsg8g03PnV8bsS4X426EDiVKiJo4gkW3cX5wlYCC/jd85JTzECuwWgXMylWQc75A92wiotzHG+anzpYbqD4bxQahdvHmi/PJZYLfjjSHXOfWd7CHEgyEJ7vOroerQhvPPNF1Pl16jGNlwivu2OGas6Yfd+wsaNCaLq/O4u+91w/tMtdVmj/VyyEFiYnqz8yYdiGKNXoUzDgrMCwMBatgt19h5c/8kiSxjR1OoAxktcfUChKOLltkSz805EEbf8b9tCJRXVLRF6auPg2Tzs9tg/Ppd8rCn0HB9HDz6isc8Bs/6atWD/aA5ffzsqFfrLczClyr0S32yBRkiC1QNR04IlFNCLeI6BznyTcOoP6hYjWru8/gb4IkE60Rwnk2ZGfBq5CRctt91OqBLTHqlLcj4Fj9WLAMP3qOnHNubNhCFArufAdW1uBcsec1e+lf0gW2bKvZErt2EOXFFajAMktfxRXYb+yWVIO4l8EhOkD9Q4uT5smWJMGlv0kCa0QdLAb/bMc1vPVMKwmuN1DJkM/vAh7vrp/56BNomkl1pqYJbjOzymOtd4WgshgJQ8iw4FVYmXAn1RdUY7yA8A+P+PMHxAhJjd4ZdmA0YNAeKqOtCeIhRmZ2e/0WWzosmernU1v5DX7DTW3j8d1f2gqqSxckOOAjtjwisjhHXAZg5Pz5H4YerRJwLY5S3y5wQu23zsCJFzYNCfgyJYJZwHXQR/L4Fn0/XrfVTLvBPlUabrkXA2PP+Rteydedf3a6rnKkm+BvXqwWU4YCOEeT7lgDXGXzPy7s1zi/EpcOdLgvPlFT2KJmOiLRkqsxdS E9uSUXPF 20FyFGcQLIzFWjaDWgIq2cXHsb7YcjddZ9fNFup0dSbu7BZV1ilAmMw6fzrRfovlf5KO/uH57Hp7PAIxpLFoyicq41cpf4/t2WrwGoTyB4MOzO1U6m0SqPobMHrqWx0/QYUeufn+peVXzHtoKgsMJsnTFO/8iveeKJP+65SzX99XQTq8NE3OgTY3aGqa1aTL7r6hPEHxNsYQv/wXICnfVPKb859Xjmd06HhF349AxGqzK5fhB2kt2ru7vD5dy9MlSWzBtQqZMFcRk5Ko4E9/L1ALxCRE2W5D/ZLe4p3MVFqAgZ+iSEZsklLzQIgywh+3DgsAl 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: 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_64 on 64bit platforms. 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 | 5 ++-- kernel/futex/syscalls.c | 30 ++++++++++++++++++++++++++++ kernel/sys_ni.c | 1 21 files changed, 55 insertions(+), 2 deletions(-) --- a/arch/alpha/kernel/syscalls/syscall.tbl +++ b/arch/alpha/kernel/syscalls/syscall.tbl @@ -491,3 +491,4 @@ 559 common futex_waitv sys_futex_waitv 560 common set_mempolicy_home_node sys_ni_syscall 561 common cachestat sys_cachestat +562 common futex_wake sys_futex_wake --- a/arch/arm/tools/syscall.tbl +++ b/arch/arm/tools/syscall.tbl @@ -465,3 +465,4 @@ 449 common futex_waitv sys_futex_waitv 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat +452 common futex_wake sys_futex_wake --- a/arch/arm64/include/asm/unistd32.h +++ b/arch/arm64/include/asm/unistd32.h @@ -909,6 +909,8 @@ __SYSCALL(__NR_futex_waitv, sys_futex_wa __SYSCALL(__NR_set_mempolicy_home_node, sys_set_mempolicy_home_node) #define __NR_cachestat 451 __SYSCALL(__NR_cachestat, sys_cachestat) +#define __NR_futex_wake 452 +__SYSCALL(__NR_futex_wake, sys_futex_wake) /* * Please add new compat syscalls above this comment and update --- a/arch/ia64/kernel/syscalls/syscall.tbl +++ b/arch/ia64/kernel/syscalls/syscall.tbl @@ -372,3 +372,4 @@ 449 common futex_waitv sys_futex_waitv 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat +452 common futex_wake sys_futex_wake --- a/arch/m68k/kernel/syscalls/syscall.tbl +++ b/arch/m68k/kernel/syscalls/syscall.tbl @@ -451,3 +451,4 @@ 449 common futex_waitv sys_futex_waitv 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat +452 common futex_wake sys_futex_wake --- a/arch/microblaze/kernel/syscalls/syscall.tbl +++ b/arch/microblaze/kernel/syscalls/syscall.tbl @@ -457,3 +457,4 @@ 449 common futex_waitv sys_futex_waitv 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat +452 common futex_wake sys_futex_wake --- a/arch/mips/kernel/syscalls/syscall_n32.tbl +++ b/arch/mips/kernel/syscalls/syscall_n32.tbl @@ -390,3 +390,4 @@ 449 n32 futex_waitv sys_futex_waitv 450 n32 set_mempolicy_home_node sys_set_mempolicy_home_node 451 n32 cachestat sys_cachestat +452 n32 futex_wake sys_futex_wake --- a/arch/mips/kernel/syscalls/syscall_n64.tbl +++ b/arch/mips/kernel/syscalls/syscall_n64.tbl @@ -366,3 +366,4 @@ 449 n64 futex_waitv sys_futex_waitv 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 n64 cachestat sys_cachestat +452 n64 futex_wake sys_futex_wake --- a/arch/mips/kernel/syscalls/syscall_o32.tbl +++ b/arch/mips/kernel/syscalls/syscall_o32.tbl @@ -439,3 +439,4 @@ 449 o32 futex_waitv sys_futex_waitv 450 o32 set_mempolicy_home_node sys_set_mempolicy_home_node 451 o32 cachestat sys_cachestat +452 o32 futex_wake sys_futex_wake --- a/arch/parisc/kernel/syscalls/syscall.tbl +++ b/arch/parisc/kernel/syscalls/syscall.tbl @@ -450,3 +450,4 @@ 449 common futex_waitv sys_futex_waitv 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat +452 common futex_wake sys_futex_wake --- a/arch/powerpc/kernel/syscalls/syscall.tbl +++ b/arch/powerpc/kernel/syscalls/syscall.tbl @@ -538,3 +538,4 @@ 449 common futex_waitv sys_futex_waitv 450 nospu set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat +452 common futex_wake sys_futex_wake --- a/arch/s390/kernel/syscalls/syscall.tbl +++ b/arch/s390/kernel/syscalls/syscall.tbl @@ -454,3 +454,4 @@ 449 common futex_waitv sys_futex_waitv sys_futex_waitv 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 futex_wake sys_futex_wake sys_futex_wake --- a/arch/sh/kernel/syscalls/syscall.tbl +++ b/arch/sh/kernel/syscalls/syscall.tbl @@ -454,3 +454,4 @@ 449 common futex_waitv sys_futex_waitv 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat +452 common futex_wake sys_futex_wake --- a/arch/sparc/kernel/syscalls/syscall.tbl +++ b/arch/sparc/kernel/syscalls/syscall.tbl @@ -497,3 +497,4 @@ 449 common futex_waitv sys_futex_waitv 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat +452 common futex_wake sys_futex_wake --- a/arch/x86/entry/syscalls/syscall_32.tbl +++ b/arch/x86/entry/syscalls/syscall_32.tbl @@ -456,3 +456,4 @@ 449 i386 futex_waitv sys_futex_waitv 450 i386 set_mempolicy_home_node sys_set_mempolicy_home_node 451 i386 cachestat sys_cachestat +452 i386 futex_wake sys_futex_wake --- a/arch/x86/entry/syscalls/syscall_64.tbl +++ b/arch/x86/entry/syscalls/syscall_64.tbl @@ -373,6 +373,7 @@ 449 common futex_waitv sys_futex_waitv 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat +452 common futex_wake sys_futex_wake # # 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 @@ -422,3 +422,4 @@ 449 common futex_waitv sys_futex_waitv 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat +452 common futex_wake sys_futex_wake --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -563,6 +563,9 @@ asmlinkage long sys_set_robust_list(stru 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, --- a/include/uapi/asm-generic/unistd.h +++ b/include/uapi/asm-generic/unistd.h @@ -816,12 +816,13 @@ __SYSCALL(__NR_process_mrelease, sys_pro __SYSCALL(__NR_futex_waitv, sys_futex_waitv) #define __NR_set_mempolicy_home_node 450 __SYSCALL(__NR_set_mempolicy_home_node, sys_set_mempolicy_home_node) - #define __NR_cachestat 451 __SYSCALL(__NR_cachestat, sys_cachestat) +#define __NR_futex_wake 452 +__SYSCALL(__NR_futex_wake, sys_futex_wake) #undef __NR_syscalls -#define __NR_syscalls 452 +#define __NR_syscalls 453 /* * 32 bit systems traditionally used different --- a/kernel/futex/syscalls.c +++ b/kernel/futex/syscalls.c @@ -306,6 +306,36 @@ SYSCALL_DEFINE5(futex_waitv, struct fute 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_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, --- a/kernel/sys_ni.c +++ b/kernel/sys_ni.c @@ -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); From patchwork Fri Jul 21 10:22:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13321862 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 F11D3EB64DD for ; Fri, 21 Jul 2023 10:59:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6600E2801BB; Fri, 21 Jul 2023 06:58:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 598BC2801BD; Fri, 21 Jul 2023 06:58:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EE7692801BF; Fri, 21 Jul 2023 06:58:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 3ABE72801BB for ; Fri, 21 Jul 2023 06:58:53 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 0B0FAA022E for ; Fri, 21 Jul 2023 10:58:53 +0000 (UTC) X-FDA: 81035321346.26.261789F Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf28.hostedemail.com (Postfix) with ESMTP id 0D390C0002 for ; Fri, 21 Jul 2023 10:58:49 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=hnDWoXCa; spf=none (imf28.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=1689937130; 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=xf4WT4JOrxBpPgZcQNC7XwGoGvueCItGycQfB8Iiox0=; b=EHkcVBgkYz/SDRaEWaCKJbnX8sR9+e9uFNO3RCCB/rDFKQUTHRTg/WgySIkbBFIdsAp4sE 0A53nsybuG8Um8SZ93eMUgLlhVgfwpmdQAUFRRAUEa6pzWlbZnN0rMCmqsNYLvbfJUzEU3 QUrzknuqHCzdvBtDYUMNzCf+4DpehN0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689937130; a=rsa-sha256; cv=none; b=Ner+2+A8QQTGFOwC97Y/5KR1BM/RxGZSh3j9AAV7TPJO7E6VWOcE0nOvstT1yph3GQ9LSC U+bxDIwwQBFG9SFTopXVMNiRA/vyH3XJfuqAm31BCiRW+M7T7Ad2MzU2LWoZIl2IIVFLLw b6Z21eLwKq/OifDWph+6De56HIYWMHY= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=hnDWoXCa; spf=none (imf28.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=xf4WT4JOrxBpPgZcQNC7XwGoGvueCItGycQfB8Iiox0=; b=hnDWoXCakc2b8ceWUHPozWVDoK 8qVyEtrc26zUIbHqsUlaqk8aT0x9L9gIG0pQRqB7tRxLNq1wwa9C6OvkTfzUbtMbwq/cLhtEIrJvE gO8XdSuDpskn3qGh6An1tLbZpnr4AEwRQ3/ykzuvuk3ZH2YBF1Egy/uX/xP97qTmz8OTrHZaqWg4p NGzX4Xozm0CyP4egmR3O1RUHyJ8iMvKF1yQr0Q101D0VxORnESKt8n4zjR0EnmJDAhoP0FJcu5e9/ ad+bu5SySZJFGPptulkXvs9jBJM0CGZ1A6V4iE+Li12J9FtcUI+p8Tk2HV3yy7iQZBfAPKexBXwQ/ dTzxTeeg==; 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 1qMnqK-0012Od-8v; 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 2DA01300A72; Fri, 21 Jul 2023 12:58:39 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 092B8315765B2; Fri, 21 Jul 2023 12:58:38 +0200 (CEST) Message-ID: <20230721105744.090372309@infradead.org> User-Agent: quilt/0.66 Date: Fri, 21 Jul 2023 12:22:43 +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 06/14] futex: Add sys_futex_wait() References: <20230721102237.268073801@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 0D390C0002 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: ys9w4ndae34catxbm8dyu5ksiejf4d9d X-HE-Tag: 1689937129-824471 X-HE-Meta: U2FsdGVkX19TlbFypBc8dGvFJIuKrOjayaZtl4iOkRkUlM2dXKIEDLrTZsm57GDUWdWQbtomz4rUIk2fRwww119LLC7gi6CiSVhF4YvPp1LmH7Hb+enrzBGQvC2WXrCmI8K/2iF1zhoEJU3CIsdPh8p08pMcu/e94l6nxxUbaDq9uM//k1tyVxBE8bu7K06kzIKT/USOuwR9Xcu9wdjZcIG9P1493gyTj4mlnAjWdPxhHYL+NDFowb3hQIuyjd2ajcROlGIm9Ld/QgQB9T++uLrT8nCTlCZkiVn4d68z/JVMhIg1bTkYMWP9hQaPEBzFKb8PL3ucqRd12QxiI9hfMH4bPFZj8XtvXRGeJ0dsUm8DQPYmEP4U/zN7TDdVFsgrIOts2SmT9AUtl8t1gRUkIvq4zMvIY8SScwLLCY+/MHPoVb1FgE3GuwHsxypDe8Lv2WJ111dD5WjoGYBQatOu+3b0ZvspmZ6pGKObKSImkxWXR7SvUeRIuPURi7sxVBJh2eq6hgpY07q9gBC3LTmHtb0qIof50oXxmVjOt6rtD68DUG0j1HBqWeW1cijbBV9lS98w7HPOXbnijAmxLFq74DahOgQTQq3p7s/sefe+fDqbDLS7LqdPhpKueMWHlEWf2I4uDoKxGGDUc6tvL1S6WYO1/Rx9fWsTiau0jyenxZZm+VyXr+oKQpX9J/6fnjttGA1wbJ9c2nTTQAItFtSXNmFYPaVGeOhSvSsrw+k4gZgHpjdL+wk04ekAaVpO1r7f1w+IpTWrj/s1//lNl+vmh0x5SmFL7YpMWSKdbNdHITIwPjG4vyP5hqXXDVMEvkEu0xwSW1QfK3JOSxQUbqouJrQG4Kg6EPZL6xSz+QbgD+8qkcuYTKMs3goyn45KyuwZR+UGkNKoUYZNE6KFHuLq2E9BBcZ7UGMuRQJgPBGR7CZn9Ai7epYEoy5WG8ozBzZYV9yXUlhkkcgIHJf6WAG ue6p4GfL iLmF+DOjrEtoz4wfvwKX5jGBEjMmzQEm2ZIP7jERTSdCSz0xtE3cuB/p+i53x0FG5pOQO0VOlHq2F2jZi9bmGE0t/LzI1o4bcWJFVPPy9JzJWW2STZUaUbTLg3boF6AS2QHq2b+E8uUAkWNquaMFinBk5EwtG+kuj+eswoA6XmQJRRyWCqcqGrpNRh1vDiE55v0PqJ7uaa8O6ttYUQeDq3x2JtwJfVuDVGJKYZYG+pgJbrU1lWYY8RT8PJ2A43+q58vhnA2Z2/O1Doq0eI26/sy29FT+HI0BZOUQZcI3abkWf4boWg1oGA+WB+6i8xjI56KHC 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: To complement sys_futex_waitv()/wake(), add sys_futex_wait(). This syscall implements what was previously known as FUTEX_WAIT_BITSET except it uses 'unsigned long' for the value and bitmask arguments, takes timespec and clockid_t arguments for the absolute timeout and uses FUTEX2 flags. The 'unsigned long' allows FUTEX2_64 on 64bit platforms. 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 | 4 include/uapi/asm-generic/unistd.h | 4 kernel/futex/futex.h | 3 kernel/futex/syscalls.c | 120 +++++++++++++++++++++------- kernel/futex/waitwake.c | 65 ++++++++------- kernel/sys_ni.c | 1 23 files changed, 156 insertions(+), 59 deletions(-) --- a/arch/alpha/kernel/syscalls/syscall.tbl +++ b/arch/alpha/kernel/syscalls/syscall.tbl @@ -492,3 +492,4 @@ 560 common set_mempolicy_home_node sys_ni_syscall 561 common cachestat sys_cachestat 562 common futex_wake sys_futex_wake +563 common futex_wait sys_futex_wait --- a/arch/arm/tools/syscall.tbl +++ b/arch/arm/tools/syscall.tbl @@ -466,3 +466,4 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common futex_wake sys_futex_wake +453 common futex_wait sys_futex_wait --- a/arch/arm64/include/asm/unistd32.h +++ b/arch/arm64/include/asm/unistd32.h @@ -911,6 +911,8 @@ __SYSCALL(__NR_set_mempolicy_home_node, __SYSCALL(__NR_cachestat, sys_cachestat) #define __NR_futex_wake 452 __SYSCALL(__NR_futex_wake, sys_futex_wake) +#define __NR_futex_wait 453 +__SYSCALL(__NR_futex_wait, sys_futex_wait) /* * Please add new compat syscalls above this comment and update --- a/arch/ia64/kernel/syscalls/syscall.tbl +++ b/arch/ia64/kernel/syscalls/syscall.tbl @@ -373,3 +373,4 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common futex_wake sys_futex_wake +453 common futex_wait sys_futex_wait --- a/arch/m68k/kernel/syscalls/syscall.tbl +++ b/arch/m68k/kernel/syscalls/syscall.tbl @@ -452,3 +452,4 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common futex_wake sys_futex_wake +453 common futex_wait sys_futex_wait --- a/arch/microblaze/kernel/syscalls/syscall.tbl +++ b/arch/microblaze/kernel/syscalls/syscall.tbl @@ -458,3 +458,4 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common futex_wake sys_futex_wake +453 common futex_wait sys_futex_wait --- a/arch/mips/kernel/syscalls/syscall_n32.tbl +++ b/arch/mips/kernel/syscalls/syscall_n32.tbl @@ -391,3 +391,4 @@ 450 n32 set_mempolicy_home_node sys_set_mempolicy_home_node 451 n32 cachestat sys_cachestat 452 n32 futex_wake sys_futex_wake +453 n32 futex_wait sys_futex_wait --- a/arch/mips/kernel/syscalls/syscall_n64.tbl +++ b/arch/mips/kernel/syscalls/syscall_n64.tbl @@ -367,3 +367,4 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 n64 cachestat sys_cachestat 452 n64 futex_wake sys_futex_wake +453 n64 futex_wait sys_futex_wait --- a/arch/mips/kernel/syscalls/syscall_o32.tbl +++ b/arch/mips/kernel/syscalls/syscall_o32.tbl @@ -440,3 +440,4 @@ 450 o32 set_mempolicy_home_node sys_set_mempolicy_home_node 451 o32 cachestat sys_cachestat 452 o32 futex_wake sys_futex_wake +453 o32 futex_wait sys_futex_wait --- a/arch/parisc/kernel/syscalls/syscall.tbl +++ b/arch/parisc/kernel/syscalls/syscall.tbl @@ -451,3 +451,4 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common futex_wake sys_futex_wake +453 common futex_wait sys_futex_wait --- a/arch/powerpc/kernel/syscalls/syscall.tbl +++ b/arch/powerpc/kernel/syscalls/syscall.tbl @@ -539,3 +539,4 @@ 450 nospu set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common futex_wake sys_futex_wake +453 common futex_wait sys_futex_wait --- a/arch/s390/kernel/syscalls/syscall.tbl +++ b/arch/s390/kernel/syscalls/syscall.tbl @@ -455,3 +455,4 @@ 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 futex_wake sys_futex_wake sys_futex_wake +453 common futex_wait sys_futex_wait sys_futex_wait --- a/arch/sh/kernel/syscalls/syscall.tbl +++ b/arch/sh/kernel/syscalls/syscall.tbl @@ -455,3 +455,4 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common futex_wake sys_futex_wake +453 common futex_wait sys_futex_wait --- a/arch/sparc/kernel/syscalls/syscall.tbl +++ b/arch/sparc/kernel/syscalls/syscall.tbl @@ -498,3 +498,4 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common futex_wake sys_futex_wake +453 common futex_wait sys_futex_wait --- a/arch/x86/entry/syscalls/syscall_32.tbl +++ b/arch/x86/entry/syscalls/syscall_32.tbl @@ -457,3 +457,4 @@ 450 i386 set_mempolicy_home_node sys_set_mempolicy_home_node 451 i386 cachestat sys_cachestat 452 i386 futex_wake sys_futex_wake +453 i386 futex_wait sys_futex_wait --- a/arch/x86/entry/syscalls/syscall_64.tbl +++ b/arch/x86/entry/syscalls/syscall_64.tbl @@ -374,6 +374,7 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common futex_wake sys_futex_wake +453 common futex_wait sys_futex_wait # # 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 @@ -423,3 +423,4 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common futex_wake sys_futex_wake +453 common futex_wait sys_futex_wait --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -566,6 +566,10 @@ asmlinkage long sys_futex_waitv(struct f asmlinkage long sys_futex_wake(void __user *uaddr, unsigned long mask, int nr, unsigned int flags); +asmlinkage long sys_futex_wait(void __user *uaddr, unsigned long val, unsigned long mask, + unsigned int flags, struct __kernel_timespec __user *timespec, + clockid_t clockid); + 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 @@ -820,9 +820,11 @@ __SYSCALL(__NR_set_mempolicy_home_node, __SYSCALL(__NR_cachestat, sys_cachestat) #define __NR_futex_wake 452 __SYSCALL(__NR_futex_wake, sys_futex_wake) +#define __NR_futex_wait 453 +__SYSCALL(__NR_futex_wait, sys_futex_wait) #undef __NR_syscalls -#define __NR_syscalls 453 +#define __NR_syscalls 454 /* * 32 bit systems traditionally used different --- a/kernel/futex/futex.h +++ b/kernel/futex/futex.h @@ -330,6 +330,9 @@ extern int futex_requeue(u32 __user *uad u32 __user *uaddr2, int nr_wake, int nr_requeue, u32 *cmpval, int requeue_pi); +extern int __futex_wait(u32 __user *uaddr, unsigned int flags, u32 val, + struct hrtimer_sleeper *to, u32 bitset); + extern int futex_wait(u32 __user *uaddr, unsigned int flags, u32 val, ktime_t *abs_time, u32 bitset); --- a/kernel/futex/syscalls.c +++ b/kernel/futex/syscalls.c @@ -221,6 +221,46 @@ static int futex_parse_waitv(struct fute return 0; } +static int futex2_setup_timeout(struct __kernel_timespec __user *timeout, + clockid_t clockid, struct hrtimer_sleeper *to) +{ + int flag_clkid = 0, flag_init = 0; + struct timespec64 ts; + ktime_t time; + int ret; + + if (!timeout) + return 0; + + if (clockid == CLOCK_REALTIME) { + flag_clkid = FLAGS_CLOCKRT; + flag_init = FUTEX_CLOCK_REALTIME; + } + + if (clockid != CLOCK_REALTIME && clockid != CLOCK_MONOTONIC) + return -EINVAL; + + if (get_timespec64(&ts, timeout)) + return -EFAULT; + + /* + * Since there's no opcode for futex_waitv, use + * FUTEX_WAIT_BITSET that uses absolute timeout as well + */ + ret = futex_init_timeout(FUTEX_WAIT_BITSET, flag_init, &ts, &time); + if (ret) + return ret; + + futex_setup_timer(&time, to, flag_clkid, 0); + return 0; +} + +static inline void futex2_destroy_timeout(struct hrtimer_sleeper *to) +{ + hrtimer_cancel(&to->timer); + destroy_hrtimer_on_stack(&to->timer); +} + /** * sys_futex_waitv - Wait on a list of futexes * @waiters: List of futexes to wait on @@ -250,8 +290,6 @@ SYSCALL_DEFINE5(futex_waitv, struct fute { struct hrtimer_sleeper to; struct futex_vector *futexv; - struct timespec64 ts; - ktime_t time; int ret; /* This syscall supports no flags for now */ @@ -261,30 +299,8 @@ SYSCALL_DEFINE5(futex_waitv, struct fute if (!nr_futexes || nr_futexes > FUTEX_WAITV_MAX || !waiters) return -EINVAL; - if (timeout) { - int flag_clkid = 0, flag_init = 0; - - if (clockid == CLOCK_REALTIME) { - flag_clkid = FLAGS_CLOCKRT; - flag_init = FUTEX_CLOCK_REALTIME; - } - - if (clockid != CLOCK_REALTIME && clockid != CLOCK_MONOTONIC) - return -EINVAL; - - if (get_timespec64(&ts, timeout)) - return -EFAULT; - - /* - * Since there's no opcode for futex_waitv, use - * FUTEX_WAIT_BITSET that uses absolute timeout as well - */ - ret = futex_init_timeout(FUTEX_WAIT_BITSET, flag_init, &ts, &time); - if (ret) - return ret; - - futex_setup_timer(&time, &to, flag_clkid, 0); - } + if (timeout && (ret = futex2_setup_timeout(timeout, clockid, &to))) + return ret; futexv = kcalloc(nr_futexes, sizeof(*futexv), GFP_KERNEL); if (!futexv) { @@ -299,10 +315,8 @@ SYSCALL_DEFINE5(futex_waitv, struct fute kfree(futexv); destroy_timer: - if (timeout) { - hrtimer_cancel(&to.timer); - destroy_hrtimer_on_stack(&to.timer); - } + if (timeout) + futex2_destroy_timeout(&to); return ret; } @@ -336,6 +350,52 @@ SYSCALL_DEFINE4(futex_wake, return futex_wake(uaddr, flags, nr, mask); } +/* + * sys_futex_wait - Wait on a futex + * @uaddr: Address of the futex to wait on + * @val: Value of @uaddr + * @mask: bitmask + * @flags: FUTEX2 flags + * @timeout: Optional absolute timeout + * @clockid: Clock to be used for the timeout, realtime or monotonic + * + * Identical to the traditional FUTEX_WAIT_BITSET op, except it is part of the + * futex2 familiy of calls. + */ + +SYSCALL_DEFINE6(futex_wait, + void __user *, uaddr, + unsigned long, val, + unsigned long, mask, + unsigned int, flags, + struct __kernel_timespec __user *, timeout, + clockid_t, clockid) +{ + struct hrtimer_sleeper to; + int ret; + + if (flags & ~FUTEX2_MASK) + return -EINVAL; + + flags = futex2_to_flags(flags); + if (!futex_flags_valid(flags)) + return -EINVAL; + + if (!futex_validate_input(flags, val) || + !futex_validate_input(flags, mask)) + return -EINVAL; + + if (timeout && (ret = futex2_setup_timeout(timeout, clockid, &to))) + return ret; + + ret = __futex_wait(uaddr, flags, val, timeout ? &to : NULL, mask); + + if (timeout) + futex2_destroy_timeout(&to); + + return ret; +} + #ifdef CONFIG_COMPAT COMPAT_SYSCALL_DEFINE2(set_robust_list, struct compat_robust_list_head __user *, head, --- a/kernel/futex/waitwake.c +++ b/kernel/futex/waitwake.c @@ -629,20 +629,18 @@ int futex_wait_setup(u32 __user *uaddr, return ret; } -int futex_wait(u32 __user *uaddr, unsigned int flags, u32 val, ktime_t *abs_time, u32 bitset) +int __futex_wait(u32 __user *uaddr, unsigned int flags, u32 val, + struct hrtimer_sleeper *to, u32 bitset) { - struct hrtimer_sleeper timeout, *to; - struct restart_block *restart; - struct futex_hash_bucket *hb; struct futex_q q = futex_q_init; + struct futex_hash_bucket *hb; int ret; if (!bitset) return -EINVAL; + q.bitset = bitset; - to = futex_setup_timer(abs_time, &timeout, flags, - current->timer_slack_ns); retry: /* * Prepare to wait on uaddr. On success, it holds hb->lock and q @@ -650,18 +648,17 @@ int futex_wait(u32 __user *uaddr, unsign */ ret = futex_wait_setup(uaddr, val, flags, &q, &hb); if (ret) - goto out; + return ret; /* futex_queue and wait for wakeup, timeout, or a signal. */ futex_wait_queue(hb, &q, to); /* If we were woken (and unqueued), we succeeded, whatever. */ - ret = 0; if (!futex_unqueue(&q)) - goto out; - ret = -ETIMEDOUT; + return 0; + if (to && !to->task) - goto out; + return -ETIMEDOUT; /* * We expect signal_pending(current), but we might be the @@ -670,24 +667,36 @@ int futex_wait(u32 __user *uaddr, unsign if (!signal_pending(current)) goto retry; - ret = -ERESTARTSYS; - if (!abs_time) - goto out; - - restart = ¤t->restart_block; - restart->futex.uaddr = uaddr; - restart->futex.val = val; - restart->futex.time = *abs_time; - restart->futex.bitset = bitset; - restart->futex.flags = flags | FLAGS_HAS_TIMEOUT; - - ret = set_restart_fn(restart, futex_wait_restart); - -out: - if (to) { - hrtimer_cancel(&to->timer); - destroy_hrtimer_on_stack(&to->timer); + return -ERESTARTSYS; +} + +int futex_wait(u32 __user *uaddr, unsigned int flags, u32 val, ktime_t *abs_time, u32 bitset) +{ + struct hrtimer_sleeper timeout, *to; + struct restart_block *restart; + int ret; + + to = futex_setup_timer(abs_time, &timeout, flags, + current->timer_slack_ns); + + ret = __futex_wait(uaddr, flags, val, to, bitset); + if (!to) + return ret; + + hrtimer_cancel(&to->timer); + destroy_hrtimer_on_stack(&to->timer); + + if (ret == -ERESTARTSYS) { + restart = ¤t->restart_block; + restart->futex.uaddr = uaddr; + restart->futex.val = val; + restart->futex.time = *abs_time; + restart->futex.bitset = bitset; + restart->futex.flags = flags | FLAGS_HAS_TIMEOUT; + + return set_restart_fn(restart, futex_wait_restart); } + return ret; } --- a/kernel/sys_ni.c +++ b/kernel/sys_ni.c @@ -88,6 +88,7 @@ COND_SYSCALL(get_robust_list); COND_SYSCALL_COMPAT(get_robust_list); COND_SYSCALL(futex_waitv); COND_SYSCALL(futex_wake); +COND_SYSCALL(futex_wait); COND_SYSCALL(kexec_load); COND_SYSCALL_COMPAT(kexec_load); COND_SYSCALL(init_module); From patchwork Fri Jul 21 10:22:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13321858 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 E80A3EB64DD for ; Fri, 21 Jul 2023 10:58:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A52BC2801B6; Fri, 21 Jul 2023 06:58:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B5C62801BF; Fri, 21 Jul 2023 06:58:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5BFA12801B6; Fri, 21 Jul 2023 06:58:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 0E2282801B9 for ; Fri, 21 Jul 2023 06:58:53 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id CFB3E1A0218 for ; Fri, 21 Jul 2023 10:58:52 +0000 (UTC) X-FDA: 81035321304.30.480ACEF Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf17.hostedemail.com (Postfix) with ESMTP id 01D404000F for ; Fri, 21 Jul 2023 10:58:49 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=RogQX4xl; dmarc=none; spf=none (imf17.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689937130; 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=H3IuBL/KhSJX21OO6AiJ3KfnhO+mCUPBKJXcGuyHGe8=; b=pSjcd29o/n5kbQrqNBFeRtRt8PcJHOt6f6Vt3QUCkX+l58dHZxaE5BwRlD7j6Qy48tCUUb L6WC5K03GOhL8uKyLxZy3zfz68tzjQwaq0S0ta8YbzObxhgAV3qvZn4fiOtYgv4n+6m/LX yWflPT/ps5KvRSJevt2F1dV+jVHIgUQ= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=RogQX4xl; dmarc=none; spf=none (imf17.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689937130; a=rsa-sha256; cv=none; b=eUGNyYf6WKAtFRQ+/u5VdaMglspP8MqChMEu1d3axWd6XB7KDYKtwZGMcgIQusCHuVIjLl 54OzTksS0REd6NPFjnBdPOFHSlsle+oWqpULKFcajZd0w5Q2Rs5+TdyOrE0g3qDOmdbfpS SbGm9VPQhPGwKqmZW13auK5OxkYrwqI= 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=H3IuBL/KhSJX21OO6AiJ3KfnhO+mCUPBKJXcGuyHGe8=; b=RogQX4xlshgL4qH6+2IxiMjVjS +1zhOSoNai85Vc5KaSqAdmQ8hx6mqVYEi06LEIs9ExdwhwgOgQ5AV2GlBZNRiGNafNdMa2JeXx8wP bAEA3DJ1HNEOMdCTa89fuzMXV/BqYjh1x8FhuhlNxg2xyWM6OZporL66lCtpn22CtO7JPaHbkCQ+V CAoxA8taEPfPlpJ3AKecQLkqX/lcp46V1jJLAXLuCfwD+NYc8kULtAqEW6o1yYx6l/hBlAjlj+zkx USo5PoEwlYSbyzWuqJd61gExzfqRe9jHwsSmmHrU1u5AYp7t4b/iMC9V2XxoLTse+5N/amDAttAQl ZDRvVWFw==; 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 1qMnqK-0012Ob-6Y; 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 2DA2A300A7E; Fri, 21 Jul 2023 12:58:39 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 0F0DF3157E61F; Fri, 21 Jul 2023 12:58:38 +0200 (CEST) Message-ID: <20230721105744.160298443@infradead.org> User-Agent: quilt/0.66 Date: Fri, 21 Jul 2023 12:22:44 +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 07/14] futex: Propagate flags into get_futex_key() References: <20230721102237.268073801@infradead.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 01D404000F X-Stat-Signature: bq9edxou4oma8bigd1gg1k68h9kczijd X-HE-Tag: 1689937129-178931 X-HE-Meta: U2FsdGVkX1/e087SXPe+hJ8IXZe1IcosZwCmPmNPePwIesMzbwME9Ey/qDLFDVgGWLl2LlZmq3aMx/G6o4yNBRwdHqIhFBO2/J6xaRD5ocqWLD3Hqev9YcPjTL4z4RrkaGt67M/xOE+RJozteKLBuOMdJ8CjVvePfQwtEedFNwgnkuecdnH1vc2knUc95sCf/yly9MvPfVTen5oOVvbcZcCvPa6SzhxUscbsoJc1/cRtLU414CVWF8+V6OrMa2mpPY+YE9ZLKPlITzk4V3YaSgP4nowXPXUlagt0++Mz3EVbDzcmSQOeE3Nz4VcpiR6cfqh/NhjV5x8vBfFbwvbr3cCyGHgOAuRaOWOIF62HZqA9lWud/q/O0jjpa7RBgqucredyIbrxblYqtoldTvQ6235YOjBtkqlFtpYHkvYT/GTgXK0VxewBbMewVD12zWgH4Qsg8ctD/N4q0rLI/87B8mnqJGh/WIDBOOHsWDrhLKM3zZCVUMQ/6z6wRrxQNSVTYgafe8+3SGaSvBGZCfJkSsWrM0PjStVpKb8LJ5dd7sCdG2a3/22R3avW2Mh+BkolWvMqIxHyyUHMmBVH2ImAJP5/CPJz6HJBh1Wps2s25nmFZnyepoEGTRpFOAgmYnAmxtB5MWf2MzayZR5mzzcbhyvpkBuHvbzOo0mvDogpQvcVe2dmgXmU0g0i9kohaymZFc+O0SyzjyBfWuX6TSTVWLu0alKrbwCQMhTTOGdSh3nuSxvzyw26gu6YozcQ3PJwHclLE78QwrNInQ5IjHkvWgUg0bx8brWEVKPli2ijC87WBWc0OvpLh9a9rnmQWYFkJYW1aPVjn8ia2zeZHQvWnYIU9GTbHGBreltTMV1C/eZqDG9eYImqK6QLb1hikYbUi7rUUeJ8XrAiedspXwKShkBAisSv2oqVzc8t6lYV4eVdB8sHLhLzwZWHWqu7Q90bBurDcZhP62hIektWm1M Xhv2LpQu byatOPtv5SW9LIfbyTvquH+SjE1IQDQf3JHRY7xDB2ddLVvl6kTHpPO6UIn0e3IoLje/UirpplbPrEI/dgWKoeFerAfIAEyn2Iq9AE/yPu9Cu1qvp6N7cll6Gw1zwnaH1tbgp+F17d0Cj7oD+gm9hcaCG+GpJPTiMXE7wEFfMmZfFU27J7jMfdeWswzOhJALfDRM1tBifMHpQ3ATg0Dg6z7aCKwoMFC+b+/6r6XiJAZCTT5Kw76huttQIeKm7w0ovW0zhx7WlZF9yZMbGtXxVEtIlzMI2C1sOPE4Bk4iUnF/yNgNafqc4XXCnuGjhoJ8oBxZo 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: Instead of only passing FLAGS_SHARED as a boolean, pass down flags as a whole. Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Thomas Gleixner --- kernel/futex/core.c | 5 ++++- kernel/futex/futex.h | 2 +- kernel/futex/pi.c | 4 ++-- kernel/futex/requeue.c | 6 +++--- kernel/futex/waitwake.c | 14 +++++++------- 5 files changed, 17 insertions(+), 14 deletions(-) --- a/kernel/futex/core.c +++ b/kernel/futex/core.c @@ -217,7 +217,7 @@ static u64 get_inode_sequence_number(str * * lock_page() might sleep, the caller should not hold a spinlock. */ -int get_futex_key(u32 __user *uaddr, bool fshared, union futex_key *key, +int get_futex_key(u32 __user *uaddr, unsigned int flags, union futex_key *key, enum futex_access rw) { unsigned long address = (unsigned long)uaddr; @@ -225,6 +225,9 @@ int get_futex_key(u32 __user *uaddr, boo struct page *page, *tail; struct address_space *mapping; int err, ro = 0; + bool fshared; + + fshared = flags & FLAGS_SHARED; /* * The futex address must be "naturally" aligned. --- a/kernel/futex/futex.h +++ b/kernel/futex/futex.h @@ -174,7 +174,7 @@ enum futex_access { FUTEX_WRITE }; -extern int get_futex_key(u32 __user *uaddr, bool fshared, union futex_key *key, +extern int get_futex_key(u32 __user *uaddr, unsigned int flags, union futex_key *key, enum futex_access rw); extern struct hrtimer_sleeper * --- a/kernel/futex/pi.c +++ b/kernel/futex/pi.c @@ -945,7 +945,7 @@ int futex_lock_pi(u32 __user *uaddr, uns to = futex_setup_timer(time, &timeout, flags, 0); retry: - ret = get_futex_key(uaddr, flags & FLAGS_SHARED, &q.key, FUTEX_WRITE); + ret = get_futex_key(uaddr, flags, &q.key, FUTEX_WRITE); if (unlikely(ret != 0)) goto out; @@ -1117,7 +1117,7 @@ int futex_unlock_pi(u32 __user *uaddr, u if ((uval & FUTEX_TID_MASK) != vpid) return -EPERM; - ret = get_futex_key(uaddr, flags & FLAGS_SHARED, &key, FUTEX_WRITE); + ret = get_futex_key(uaddr, flags, &key, FUTEX_WRITE); if (ret) return ret; --- a/kernel/futex/requeue.c +++ b/kernel/futex/requeue.c @@ -424,10 +424,10 @@ int futex_requeue(u32 __user *uaddr1, un } retry: - ret = get_futex_key(uaddr1, flags & FLAGS_SHARED, &key1, FUTEX_READ); + ret = get_futex_key(uaddr1, flags, &key1, FUTEX_READ); if (unlikely(ret != 0)) return ret; - ret = get_futex_key(uaddr2, flags & FLAGS_SHARED, &key2, + ret = get_futex_key(uaddr2, flags, &key2, requeue_pi ? FUTEX_WRITE : FUTEX_READ); if (unlikely(ret != 0)) return ret; @@ -789,7 +789,7 @@ int futex_wait_requeue_pi(u32 __user *ua */ rt_mutex_init_waiter(&rt_waiter); - ret = get_futex_key(uaddr2, flags & FLAGS_SHARED, &key2, FUTEX_WRITE); + ret = get_futex_key(uaddr2, flags, &key2, FUTEX_WRITE); if (unlikely(ret != 0)) goto out; --- a/kernel/futex/waitwake.c +++ b/kernel/futex/waitwake.c @@ -145,13 +145,13 @@ int futex_wake(u32 __user *uaddr, unsign struct futex_hash_bucket *hb; struct futex_q *this, *next; union futex_key key = FUTEX_KEY_INIT; - int ret; DEFINE_WAKE_Q(wake_q); + int ret; if (!bitset) return -EINVAL; - ret = get_futex_key(uaddr, flags & FLAGS_SHARED, &key, FUTEX_READ); + ret = get_futex_key(uaddr, flags, &key, FUTEX_READ); if (unlikely(ret != 0)) return ret; @@ -245,10 +245,10 @@ int futex_wake_op(u32 __user *uaddr1, un DEFINE_WAKE_Q(wake_q); retry: - ret = get_futex_key(uaddr1, flags & FLAGS_SHARED, &key1, FUTEX_READ); + ret = get_futex_key(uaddr1, flags, &key1, FUTEX_READ); if (unlikely(ret != 0)) return ret; - ret = get_futex_key(uaddr2, flags & FLAGS_SHARED, &key2, FUTEX_WRITE); + ret = get_futex_key(uaddr2, flags, &key2, FUTEX_WRITE); if (unlikely(ret != 0)) return ret; @@ -423,7 +423,7 @@ static int futex_wait_multiple_setup(str continue; ret = get_futex_key(u64_to_user_ptr(vs[i].w.uaddr), - vs[i].w.flags & FLAGS_SHARED, + vs[i].w.flags, &vs[i].q.key, FUTEX_READ); if (unlikely(ret)) @@ -435,7 +435,7 @@ static int futex_wait_multiple_setup(str for (i = 0; i < count; i++) { u32 __user *uaddr = (u32 __user *)(unsigned long)vs[i].w.uaddr; struct futex_q *q = &vs[i].q; - u32 val = (u32)vs[i].w.val; + u32 val = vs[i].w.val; hb = futex_q_lock(q); ret = futex_get_value_locked(&uval, uaddr); @@ -599,7 +599,7 @@ int futex_wait_setup(u32 __user *uaddr, * while the syscall executes. */ retry: - ret = get_futex_key(uaddr, flags & FLAGS_SHARED, &q->key, FUTEX_READ); + ret = get_futex_key(uaddr, flags, &q->key, FUTEX_READ); if (unlikely(ret != 0)) return ret; From patchwork Fri Jul 21 10:22:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13321863 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 D8158EB64DC for ; Fri, 21 Jul 2023 10:59:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6D3A42801BF; Fri, 21 Jul 2023 06:58:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 685692801C1; 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 4AC552801BF; Fri, 21 Jul 2023 06:58:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 343B62801BD for ; Fri, 21 Jul 2023 06:58:56 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 0C8101A0184 for ; Fri, 21 Jul 2023 10:58:56 +0000 (UTC) X-FDA: 81035321472.03.EEDE9AF Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf11.hostedemail.com (Postfix) with ESMTP id 1369C40011 for ; Fri, 21 Jul 2023 10:58:53 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=Fa5dxOO4; spf=none (imf11.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=ekXqtC1cKYuJXn8nysEA+SD5q+TsqkX8YtXOKX5T0FM=; b=K+S3qOkuzkHC/WriyzTdvsiIQqD48zajdQYm6PMQdcyk2eE1kyK/zb2ebvhsELDdoJV10+ 3aMh0ZM2erWmGrOPkSB0aPXPimj+9vp69Dufrd5WT17dfWND61vUaV5FnEn6s5pz1M/mYJ W/c+ir1J2TB2gzY3T6hU72fjrdyWCFM= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=Fa5dxOO4; spf=none (imf11.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689937134; a=rsa-sha256; cv=none; b=z2m3QPVeKR2iNRJpFzQ8K4P7eANd19KmLplGbqA+aIma36DrS7HFzJB5y4g9KoCu5LEJ2z E2hvFhD1jYOlwVpQ9LtXPvakS+FR6xViXSEBek0fBky4HxY7Xr7IalJmiNYPflJwtbHHjm d+5u7G1JA5bB9C+xy2JiO22HgQi2E4Q= 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=ekXqtC1cKYuJXn8nysEA+SD5q+TsqkX8YtXOKX5T0FM=; b=Fa5dxOO4e2QQkLwyeK3dnY1aeK 7iaNB5JB3mRq/5DQP6CzxsVLnKXAI0SJy8X9vse68YwSFLXZxRByF5v9sab6LNK73OX6nPWPPQynh W7V1dCh6n03ENTDnme6s54GRfWobi/S1AmAL55l2xvbqHrHGPWudDhV5dwYG5j0i7lYtmyYt8No9i c7YEDi4+jhIAXBbcJqt7x+B1MSjsUI8VZNPZaLJld2zlW1S6m0K3AaSnLudY0+9ObjbjHhn8lklID fYg1jJ+Upul8ozJoo+SihFCFeR2cLk2yy8v599otecXZLwptsmNMkp/semwQTOMhkkRnzlTxZZv1j /sejBVLw==; 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-0000L8-1j; Fri, 21 Jul 2023 10:58:41 +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 2D9E5300A46; Fri, 21 Jul 2023 12:58:39 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 14A033157E621; Fri, 21 Jul 2023 12:58:38 +0200 (CEST) Message-ID: <20230721105744.230243724@infradead.org> User-Agent: quilt/0.66 Date: Fri, 21 Jul 2023 12:22:45 +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 08/14] futex: Add flags2 argument to futex_requeue() References: <20230721102237.268073801@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 1369C40011 X-Rspam-User: X-Stat-Signature: utcnhis888o5pakqfcfbinxrds44m4jc X-Rspamd-Server: rspam01 X-HE-Tag: 1689937133-38131 X-HE-Meta: U2FsdGVkX18/6xOldU7TOJsINP/gXBOIsACP1PHY3YkkSIPbvKkbnEiB6gidbeXgJXikxqCLIyl/Wpqecze9K33wKh1no6mmu6AUCX+JYFY1HzonnmdS+9+rQwEDc/3nINrbYHoXOldX7EYCbM3sI6c3BtLtVAdoQPWLkdvOcUrs8Ymb1VaF5JAVbQX1f6veDXZic6dc3lN1Boyr7rQUQ5XfX5qLF2lbXqiOtWLhfWSIZw+/r3nmDr5tDJ8SfLRv6a54q6DYUfbJzZy9WvBgOrWwSY4hBUTCm0nLx417OMJTXqvlOkD9X+sDBOyOiNKkkwSC/4gaiNHyOVMXwvhu4+dyYjxVYeL3mYkFGl1fmEl3XBtyuup233QhtsiZEdxKG1sLpNz5dudXrvWZj0xBH58v7OnvaVvXdjWVpkZhAqorNaEpUcWjWK/JdGhET86yV5Mv+/eGZeiQqUy8X1QfoBhoJSJzVFgvLOe6v/pS2eYfFrMZAshCe6ZU2wPxXq0c655sl98kS7GmYShxwA51MsVZLntMDP8uLslnUsFZDK3CCWptLsJMMkyf2Ykk7bgeXagVmaWdK5TfcJWI3xApihnci1x2gQD21XkaD/X6aauYDtf5OYZ78Db6plVz0M9SmKdwbwjeoFtlB4x7ZxmE8vRXBNLg9vCj/ERRMZZRxl+/j+hGAMZUgDe2xbp72JWqshhjHX45aPYzJYAcZBIBXVvPnqp07oT9W/9NQGTi/k6QECd4S346eRaufWKVl/Ut7vdt90MuWWDJnv2AOFJbXvNUkl0S8v/izNq9bqNXVaR9RsqqDv0rMY281jTuBtyt1h5lOuUM1NWMGPQG5ltJP4L9/qTIpqI0vRbGR92+5Wda4HYoQvYD8UblBtncxEVvj//H+W5m630Q2qmOut9m6IqVV5TRWe40qCA7q9FslXIJDuSDdm4s9gVKx6/3D4vS83CQ/aj5yDSOJC0NGK9 pAF1jSIN fxjr7asUWPiJsbreQazKZdGXhX892x6TCXdHUps123V+XvDABg9o9ba9wsyL7J8WEDAgGxFYspv0+O5ajyX/kq5GGjsdj2p3WkQOYf+ca3CvDlegQe48n8lmvbHBr7d5m2mla9u/2OjGc18O5RnlqrPPF0W8POYePZQ7c/5BbOtiMfqJ7mrFCWU0Skqqe0viZPe3oPm1zzz8G/y2pbv6ov93XUvB6BsHYhqT0z4nYqmDgL/Q6HPCM6vfRPToXjvaADLJ8PN9I8XWxtyVWovgyh1j9Zqa69yyPHMoqA9LQsiQ72URhZQI7qHGGU22dVEpehYHQ 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: In order to support mixed size requeue, add a second flags argument to the internal futex_requeue() function. Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Thomas Gleixner --- kernel/futex/futex.h | 5 +++-- kernel/futex/requeue.c | 12 +++++++----- kernel/futex/syscalls.c | 6 +++--- 3 files changed, 13 insertions(+), 10 deletions(-) --- a/kernel/futex/futex.h +++ b/kernel/futex/futex.h @@ -318,8 +318,9 @@ extern int futex_wait_requeue_pi(u32 __u val, ktime_t *abs_time, u32 bitset, u32 __user *uaddr2); -extern int futex_requeue(u32 __user *uaddr1, unsigned int flags, - u32 __user *uaddr2, int nr_wake, int nr_requeue, +extern int futex_requeue(u32 __user *uaddr1, unsigned int flags1, + u32 __user *uaddr2, unsigned int flags2, + int nr_wake, int nr_requeue, u32 *cmpval, int requeue_pi); extern int __futex_wait(u32 __user *uaddr, unsigned int flags, u32 val, --- a/kernel/futex/requeue.c +++ b/kernel/futex/requeue.c @@ -346,8 +346,9 @@ futex_proxy_trylock_atomic(u32 __user *p /** * futex_requeue() - Requeue waiters from uaddr1 to uaddr2 * @uaddr1: source futex user address - * @flags: futex flags (FLAGS_SHARED, etc.) + * @flags1: futex flags (FLAGS_SHARED, etc.) * @uaddr2: target futex user address + * @flags2: futex flags (FLAGS_SHARED, etc.) * @nr_wake: number of waiters to wake (must be 1 for requeue_pi) * @nr_requeue: number of waiters to requeue (0-INT_MAX) * @cmpval: @uaddr1 expected value (or %NULL) @@ -361,7 +362,8 @@ futex_proxy_trylock_atomic(u32 __user *p * - >=0 - on success, the number of tasks requeued or woken; * - <0 - on error */ -int futex_requeue(u32 __user *uaddr1, unsigned int flags, u32 __user *uaddr2, +int futex_requeue(u32 __user *uaddr1, unsigned int flags1, + u32 __user *uaddr2, unsigned int flags2, int nr_wake, int nr_requeue, u32 *cmpval, int requeue_pi) { union futex_key key1 = FUTEX_KEY_INIT, key2 = FUTEX_KEY_INIT; @@ -424,10 +426,10 @@ int futex_requeue(u32 __user *uaddr1, un } retry: - ret = get_futex_key(uaddr1, flags, &key1, FUTEX_READ); + ret = get_futex_key(uaddr1, flags1, &key1, FUTEX_READ); if (unlikely(ret != 0)) return ret; - ret = get_futex_key(uaddr2, flags, &key2, + ret = get_futex_key(uaddr2, flags2, &key2, requeue_pi ? FUTEX_WRITE : FUTEX_READ); if (unlikely(ret != 0)) return ret; @@ -459,7 +461,7 @@ int futex_requeue(u32 __user *uaddr1, un if (ret) return ret; - if (!(flags & FLAGS_SHARED)) + if (!(flags1 & FLAGS_SHARED)) goto retry_private; goto retry; --- a/kernel/futex/syscalls.c +++ b/kernel/futex/syscalls.c @@ -106,9 +106,9 @@ long do_futex(u32 __user *uaddr, int op, case FUTEX_WAKE_BITSET: return futex_wake(uaddr, flags, val, val3); case FUTEX_REQUEUE: - return futex_requeue(uaddr, flags, uaddr2, val, val2, NULL, 0); + return futex_requeue(uaddr, flags, uaddr2, flags, val, val2, NULL, 0); case FUTEX_CMP_REQUEUE: - return futex_requeue(uaddr, flags, uaddr2, val, val2, &val3, 0); + return futex_requeue(uaddr, flags, uaddr2, flags, val, val2, &val3, 0); case FUTEX_WAKE_OP: return futex_wake_op(uaddr, flags, uaddr2, val, val2, val3); case FUTEX_LOCK_PI: @@ -125,7 +125,7 @@ long do_futex(u32 __user *uaddr, int op, return futex_wait_requeue_pi(uaddr, flags, val, timeout, val3, uaddr2); case FUTEX_CMP_REQUEUE_PI: - return futex_requeue(uaddr, flags, uaddr2, val, val2, &val3, 1); + return futex_requeue(uaddr, flags, uaddr2, flags, val, val2, &val3, 1); } return -ENOSYS; } 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: U2FsdGVkX18JikcvODtvQovk4wF1j33FEblLb+Zs18O40yuY/BURs1mqc8cD146wfgdESwOgWDerHbZD68fE7oN03HqgfQDryFmEYPYkJOuVea2DL2PtUYY4U4Lfm4QFv8HUeCX/4Ou5K4xul+G9c93gg+lQeZZHUNGAv/GNi/ebmvOv0OydG/vv0xgWBhySdESPds1q0/QrqlpQExvhREwy5Q/2yyK7Ilhem+lX1BK35oXby+lQGvSoQUCceWQfOWB9nmCQxzJjSNHsx42M5eL3kYRPUADNtbzr9kCJXjm70Ak4tQ5B+aGFg7aTj6xNtBwbyAe9V2YuYUfT8iBqRsMHywx/pxk0FMWkpM9PBVWxC25e9o7fvInycFMgYWjk3hRSDJlyPeXhDdihWfTbcMufpUkoHhsWP2+EOHBVwykJLSD7M98oEkAzZudDL1KsAy3Qb9lPQ61h9xmrX+Kb+khk3/v+RAWSWkwTmxTeFVAnCgFs3txgLi9pDT3GZO6xTedYJE8guoERR+jVAmL/IkmE3soygunWRdwv8n8VCaeVJp1Pxi5yRwgEPoAUGSp/uTg2snXqnY9QOWzoksjXn1fLKmo7a3+SIvn/gGQFpqO2UDc5Ir+JiAc2oACJdTg4bOlhCj7lf8nODraJLZEdUCQy952VqOsjFFUfyqNYoYHROCb21VD8bFkm7+xj7rseXv6954jdbzQFBT4UxWdTRPD8oR0MrN+9nmjaJC/oT5JI14x8LLE+0jMLGTnAuRYuID+eIyZ+8iestyVkHhTt/LMMoLj3wvm0mzahHnkEv+v3kWzAux3CmyC2982sjr40BQ6nOuBvqJ9baBBXTVZz9gWDkAVZIFsT6H9He4S/uJaNpitOTJcNx+MqM08IYOACaO7zeqSQyFQE7Fc5Ek3qgxWoC2TwkR5RNWgGGV8nUrzkAAeNptkf3n8TW7+Msb5ae9tgKRb84CKq1nlWhuw vDA6RYJk IBuPdRptumkAIJqOtFX88wjCfr6bFbKD6HWlJCDNIF8ypLnkd8Qke4BrO1v2wuhiSyorUUnw2x4t+EyeCxlfq98LMUJgfE1kbFkakiLVWQGxIpKYHAZ422XcZj1H1bRdgB20IQjmrFqCXLhCqhR4U2zolVBmFjMmRA+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); From patchwork Fri Jul 21 10:22:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13321859 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 206FAEB64DC for ; Fri, 21 Jul 2023 10:59:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C5D7A2801B7; Fri, 21 Jul 2023 06:58:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 946242801BA; Fri, 21 Jul 2023 06:58:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 486D82801BD; Fri, 21 Jul 2023 06:58:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 06CBD2801B6 for ; Fri, 21 Jul 2023 06:58:53 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id CB78740244 for ; Fri, 21 Jul 2023 10:58:52 +0000 (UTC) X-FDA: 81035321304.30.5A5DA1A Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf30.hostedemail.com (Postfix) with ESMTP id 05D6880010 for ; Fri, 21 Jul 2023 10:58:49 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=tGS8FVZV; spf=none (imf30.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=1689937130; 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=60hbAcuR558zERq3nmTHmGZxZzuSde/KCKqPvfvDN0A=; b=ZVz2lN+aMqB9YiZmJdanCBcr8EOst1VjGezQY9h32/EqY3PVfjWSp0Sr87P43+eHl6ys90 nztcN4ULZNaCOTLErb2ZR2WghQYd0f2TgrnVp53OTNTvelEG8s/u6SsvSlkReMGnSKwhoh VuskvB1EI7R1hlkbWniMSa/ndbz2Ybs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689937130; a=rsa-sha256; cv=none; b=Qfcn1MWLQ1IDO8L8CYBKLv7yysDghXDAKD79+DbAX4MIdoOi4vODI0rFqCHVNgr1bkb9m4 O5mGeDgatjjJHO3OUOTrxdgRGHh+C7I2ndVcOJU0Zp8bVyAYTlFKJqyIkRoiRwQoHSD0rH sjiY+fPtRMxjqln2j+zaAG7BxobsSZc= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=tGS8FVZV; spf=none (imf30.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=60hbAcuR558zERq3nmTHmGZxZzuSde/KCKqPvfvDN0A=; b=tGS8FVZVVED29+j6zj5HEaAOxI SRQRgFzFoSu6P04KeweOXTANw3a3x3jrYY4ys1Yzf9d4Ze6qmx2YYCypunggIFUg1HeXufmpQBzxS V/ldVoPSOQXOO0yg/aTBWAbreEC5bvBZ6CHMEkaKT9g5zpYPSSQ59osGECCXJ6t6FDoUrXYKhY2LA m2VONQr27kHBHr41Xis4HXsWrHdZH9K0eHK2UAOW82fwq1o6Mm1hd2k9G4QNYGa6WgbPlhl9b3uEQ wkv9AhQJWztan5osPkJb5qMdFvdObWwYdH68icSIwW2KMjbCl5Yz3bNkk8G5X+M7yMLoLd7nQL41p 65Vf054A==; 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 1qMnqK-0012Oe-90; 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 3486F300C65; Fri, 21 Jul 2023 12:58:39 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 1CC153157E624; Fri, 21 Jul 2023 12:58:38 +0200 (CEST) Message-ID: <20230721105744.367616679@infradead.org> User-Agent: quilt/0.66 Date: Fri, 21 Jul 2023 12:22:47 +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 10/14] mm: Add vmalloc_huge_node() References: <20230721102237.268073801@infradead.org> MIME-Version: 1.0 X-Stat-Signature: q8dpcxw3fr68sbfbi3a7osmtiq766oey X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 05D6880010 X-Rspam-User: X-HE-Tag: 1689937129-906263 X-HE-Meta: U2FsdGVkX18UU0ObJGMRfnhAde25qkfS03zJfOxBxKWkc0z4YhmMWHELzmAIZxAtxfcXY/cjDM8s+amd/ipEaFn57teZ7em4ZWGp2uJgQp9Zmu1Zn3xXBVp//69r5kGczeq6AaaQdUYpJ5FLt72FgNihqIVhcoE8UHRtfFpW86u6mjiEMCtJ7+nGP/zxCNcJkj0Dh4rERmlj6cc34lR5680fpXxG5+0KZNexuh3ogQJGO1S35DI+/6y/l1neVcibDeI4b7t2PBC2OggGI5FcJHMy9t793oDnyUJAfzeLaGhuAY7K6T4YvMBnnlouuoLk1sYayfoMw6dXX8L69vsgUYqm+x02I8JOKjDsNGVpXdDt9sPNsA4xHuBMKBiEx+oi9lIJqbNTxhmPwF574ms5FvKr9ExC4PVDsH1Ap2zvfxDVCR7IyAzW3pn+ikKzZ9TLIPa0Na+Tl6+GUwQ0c8SlV6l7RT/6dxGorxJs0pX56VeUXt45BAl3DsxUVCoH0nF+PAgTbN3UmAgu3cRY/5vT8w4ZEA0ALMlyqpGVuoBhxp8o81fm0D4FPooz0sg2/Py7lkH39cHNH/LeikEfV8S5VBEJHl4dqWSAuxv6IVVMZ3RXet0vc1SOFZGu75jaqNBa8NFPoU9ZyJTBpdytXtX48rET1ijyq4QQb0Lnvg6Yk4jAz+ZFoOxiyuS02L5Yhj2GkE9y94HdyjU0hdYR2PLuBH5s34Mpn2TRdrzkDIBRpwuhsX30HDPmPS0X398CDrc39PhQ0nHOSXB0r8Gd1Hn1qi/tLiepgGlTZEMpzMHrZksBFqZf17/t6VNWbp7Y8K5u5/xVNk5vB35T5Aa2I8DsYVHyijBzVcriLOx2tNlti8PA9RtQcj3zoN+QPsoFPKeHk5/CpFgt8juQyZqMUkxmPmrmefOREjQH4bp6PUpLem1+sRwFjakFzlhOcDyaob1kOm7uGwocF+hJq3Rk7zP JQ/Rz5ug FpvGYAky3408oQ+papvsouWgjjyka3kPcya7dznRhvgjou8bk2DPampSKzM53MoPMo0ThArTtT4ojc9mm4rVThdFkRROPYBG01kCpYU1s6VaiJCy81TeVK3y6wVUTKrEVCLtrSYgrf53HVhgycveWvENwD0GMjQRIeCd0F4Ner5tsWdukTowuLcNBfEtktuHfp0vifSSLoYlfrNubm/eNtsDSjn4t/GTPMcsnpeAMt+q+cufSUb3fD5LnJkhUQbcE48FCBW419GlejgG3Zgy3wRU1zLts+eMu9ierrnkCI7bisu63hoVk4CaaWDrZVL7ruH5/ 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: To enable node specific hash-tables. Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Christoph Hellwig --- include/linux/vmalloc.h | 1 + mm/vmalloc.c | 7 +++++++ 2 files changed, 8 insertions(+) --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -152,6 +152,7 @@ extern void *__vmalloc_node_range(unsign void *__vmalloc_node(unsigned long size, unsigned long align, gfp_t gfp_mask, int node, const void *caller) __alloc_size(1); void *vmalloc_huge(unsigned long size, gfp_t gfp_mask) __alloc_size(1); +void *vmalloc_huge_node(unsigned long size, gfp_t gfp_mask, int node) __alloc_size(1); extern void *__vmalloc_array(size_t n, size_t size, gfp_t flags) __alloc_size(1, 2); extern void *vmalloc_array(size_t n, size_t size) __alloc_size(1, 2); --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3416,6 +3416,13 @@ void *vmalloc(unsigned long size) } EXPORT_SYMBOL(vmalloc); +void *vmalloc_huge_node(unsigned long size, gfp_t gfp_mask, int node) +{ + return __vmalloc_node_range(size, 1, VMALLOC_START, VMALLOC_END, + gfp_mask, PAGE_KERNEL, VM_ALLOW_HUGE_VMAP, + node, __builtin_return_address(0)); +} + /** * vmalloc_huge - allocate virtually contiguous memory, allow huge pages * @size: allocation size From patchwork Fri Jul 21 10:22:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13321860 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 1B947EB64DD for ; Fri, 21 Jul 2023 10:59:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 048402801BA; Fri, 21 Jul 2023 06:58:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E79032801BC; Fri, 21 Jul 2023 06:58:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 769362801BE; Fri, 21 Jul 2023 06:58:53 -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 1155F2801BA for ; Fri, 21 Jul 2023 06:58:53 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id D18ACA022B for ; Fri, 21 Jul 2023 10:58:52 +0000 (UTC) X-FDA: 81035321304.28.BF5EA70 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf11.hostedemail.com (Postfix) with ESMTP id 0CEA84000A for ; Fri, 21 Jul 2023 10:58:49 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=o8AkDmj7; dmarc=none; spf=none (imf11.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689937130; 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=InZAoNtajhobmNQr05yuJ5qrK1sLTRyFZ+Ldl4K0hzA=; b=kv4ATIXzj6yIjSGWgt8h32ZJRfYBWfXOsNVlbiXKyBtuvfY9AvT9wYKqtS/16WqUSkwy6R S5k/rog0ulVGENz2S0X83JqVk21x8pe2BP0Fyt2ETO/kff8X2LoCIsrh74qQmJiR2NxW6D 9M6s5an0ekcx8vqA3ukRJHeMUfpKOEM= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=o8AkDmj7; dmarc=none; spf=none (imf11.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689937130; a=rsa-sha256; cv=none; b=GBizjKrUOL6//hrwWD1O7q3J9+wCDYuy3+yKqNvF3jq8yw/CeqzuZ4jpojC7HPE1NnDLEl Q21bh1j8MKKakz1o6Zqq8Blo5qmeC+0ihAzggWUge5QCyTk/58VEl+AMRBXPMs4yRJxhKZ cWpk+DA9TPtpgUpiVbUYZ30uH8GmvDc= 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=InZAoNtajhobmNQr05yuJ5qrK1sLTRyFZ+Ldl4K0hzA=; b=o8AkDmj7r0mUmpFMO60PLZYV4r HtXarlzhK6C/dHCGMo9Qnq0pyb5vTNo2RlTgbPe4tloAZCGKM8R5aWOn+SNQTr5QnN8gv9DIygdzO mUY8lNkYNqRL7oUB02O8lReJ/iHKTsXqQ/mAGmOvp0pOzXV9fEefXjRCf6mB55ajfZfEAondNBqah ZbYzhHP+aCWnujIf+yKZBaoysIhQ4fZPnrhYcwxHOfHq3b87eSLeKKlW3hfY7OKW4eI+dDht8eHsv OCtV6uKqQhL3LqTorpnelT+Yr6XwyANEmxA+MRSN0p2qnbKJ7Z5PYyPCllJLGrjdhGMkrimVodxle T+kkUv1A==; 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 1qMnqK-0012Og-OI; Fri, 21 Jul 2023 10:58:41 +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 3679F301C41; Fri, 21 Jul 2023 12:58:39 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 210923157E625; Fri, 21 Jul 2023 12:58:38 +0200 (CEST) Message-ID: <20230721105744.434742902@infradead.org> User-Agent: quilt/0.66 Date: Fri, 21 Jul 2023 12:22:48 +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 11/14] futex: Implement FUTEX2_NUMA References: <20230721102237.268073801@infradead.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 0CEA84000A X-Stat-Signature: u6zybfij4idgseh4n91yww9q8uos88p4 X-HE-Tag: 1689937129-77977 X-HE-Meta: U2FsdGVkX1/WQI23o8UAZl0VLHjl73Eryz+BRpTKql+I4Ze3AOYmP2SswPoOOSrz/LdyuSe5YjLr70lKzpDGxu+yug5ImTgvjRoNiOBkKZfrjSBq0hEycBvjSFZp1KfrlBRm364t2U6F8YqBvrJuwuiKAHvAIjYz7AP8Q0ydlSlrPZlbg0tM6N1VAz7ST+sqcHrOSk7Wl/N8r6am0bNyad7Mty4MpeDm/MQtOH0nVRpFoImPlNfJWE9wDIuWM4ryvDORZyA9MqMsUq4M14JKtt4qYZW5SabHdEwhxzpiKaLtmjIqTLbzwnvNwuRbfSfC9bqt8wvpokYsUagFb4W7xSLHCfxnq4SkV3n2qrgoOM1Ifgk9oyHBt98tV6kaBaDBfhxoCQmqpPKvosuha2XOiBVnq86vGQGWUtVz17Rq0Y5OEW/I5Mai9QW1spiVxKd/FaFKRc6lD2DL1ZFPzbbmyS0BntAgeffvbzOm0Zp/Vo6VXkIIGB6JYZCG8nkeVagRDwZmG/EhThzfcCXF7wB/Q8S8kKdtVbv8DZZRqqjDjvksIj0VOAsdnoq9w/z4wnJo0wzMJ5ckgYQLcVtDMfpvVl9wQBdtz+K4uOaYsz9W0KlWHco+yjPu2VRDIlpykmY6Ey2x0sv0J+x0tH8b0cffyuIbPG+WY9GK4MG47CgoRzOB4kskJWrY0hHCX2WQG8S/T44Q/w6sNKzlErCKij5zd1nyI4FqD2krsx//METgZkwUhAFcuKHpGPjk9ATlnIKcCTORalm0shonbZSc2R8nIp2PJZ05HHl6s/ix0QlQ8FrEGBPYDI7sWzSR8gi4pcc03p2UXIDb9JHK1bgDpdRT+KkdTj8Z3EuEZ7ZlRlHie8LGvBupyphKFQOe6WuOMuZoLg2xAC7HVXUOD2CmnoSX56cVx63g3hus68dA382KMeLhstZLFvqFa6M7hD5HbG/8XQHsYMz5efqlWiykzoE tKnTl13O +EjLgYBY54Z/rMj7CFVUc2e9NWALTS+G9/BPHQXPwx5rdB9PAsuflCfler82pgYU9eMunsXjMuZyzqFE0sinZZmvEvFS/t5o3a1nZTjN/+DMW38Wlq7PlHqJA5pewVmW7qhMzvhuy1kk+dk6myFLcGv+dy+TxrExeByLgSLKCFbQ8vP9+hm2ZOXZKjpdNacRlj4IEZ0V4AsRRgR4rpi+1cYnIHo2/SZpSSJi8JedMq1khaWjUo/vFPMGy4KmxvX4/OwlIPigJgwGsKhAwrPBvinz92CfNf2IM+pH+Ne5UhwuLW8/CIIbKp0rv4xfS6wLaAG3i 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: Extend the futex2 interface to be numa aware. When FUTEX2_NUMA is specified for a futex, the user value is extended to two words (of the same size). The first is the user value we all know, the second one will be the node to place this futex on. struct futex_numa_32 { u32 val; u32 node; }; When node is set to ~0, WAIT will set it to the current node_id such that WAKE knows where to find it. If userspace corrupts the node value between WAIT and WAKE, the futex will not be found and no wakeup will happen. When FUTEX2_NUMA is not set, the node is simply an extention of the hash, such that traditional futexes are still interleaved over the nodes. This is done to avoid having to have a separate !numa hash-table. Signed-off-by: Peter Zijlstra (Intel) --- include/linux/futex.h | 3 + kernel/futex/core.c | 128 +++++++++++++++++++++++++++++++++++++++--------- kernel/futex/futex.h | 26 +++++++-- kernel/futex/syscalls.c | 2 4 files changed, 127 insertions(+), 32 deletions(-) --- a/include/linux/futex.h +++ b/include/linux/futex.h @@ -34,6 +34,7 @@ union futex_key { u64 i_seq; unsigned long pgoff; unsigned int offset; + /* unsigned int node; */ } shared; struct { union { @@ -42,11 +43,13 @@ union futex_key { }; unsigned long address; unsigned int offset; + /* unsigned int node; */ } private; struct { u64 ptr; unsigned long word; unsigned int offset; + unsigned int node; /* NOT hashed! */ } both; }; --- a/kernel/futex/core.c +++ b/kernel/futex/core.c @@ -34,7 +34,8 @@ #include #include #include -#include +#include +#include #include #include @@ -47,12 +48,14 @@ * reside in the same cacheline. */ static struct { - struct futex_hash_bucket *queues; unsigned long hashsize; + unsigned int hashshift; + struct futex_hash_bucket *queues[MAX_NUMNODES]; } __futex_data __read_mostly __aligned(2*sizeof(long)); -#define futex_queues (__futex_data.queues) -#define futex_hashsize (__futex_data.hashsize) +#define futex_hashsize (__futex_data.hashsize) +#define futex_hashshift (__futex_data.hashshift) +#define futex_queues (__futex_data.queues) /* * Fault injections for futexes. @@ -105,6 +108,26 @@ late_initcall(fail_futex_debugfs); #endif /* CONFIG_FAIL_FUTEX */ +static int futex_get_value(u32 *val, u32 __user *from, unsigned int flags) +{ + switch (futex_size(flags)) { + case 1: return __get_user(*val, (u8 __user *)from); + case 2: return __get_user(*val, (u16 __user *)from); + case 4: return __get_user(*val, (u32 __user *)from); + default: BUG(); + } +} + +static int futex_put_value(u32 val, u32 __user *to, unsigned int flags) +{ + switch (futex_size(flags)) { + case 1: return __put_user(val, (u8 __user *)to); + case 2: return __put_user(val, (u16 __user *)to); + case 4: return __put_user(val, (u32 __user *)to); + default: BUG(); + } +} + /** * futex_hash - Return the hash bucket in the global hash * @key: Pointer to the futex key for which the hash is calculated @@ -114,10 +137,29 @@ late_initcall(fail_futex_debugfs); */ struct futex_hash_bucket *futex_hash(union futex_key *key) { - u32 hash = jhash2((u32 *)key, offsetof(typeof(*key), both.offset) / 4, + u32 hash = jhash2((u32 *)key, + offsetof(typeof(*key), both.offset) / sizeof(u32), key->both.offset); + int node = key->both.node; - return &futex_queues[hash & (futex_hashsize - 1)]; + if (node == -1) { + /* + * In case of !FLAGS_NUMA, use some unused hash bits to pick a + * node -- this ensures regular futexes are interleaved across + * the nodes and avoids having to allocate multiple + * hash-tables. + * + * NOTE: this isn't perfectly uniform, but it is fast and + * handles sparse node masks. + */ + node = (hash >> futex_hashshift) % nr_node_ids; + if (!node_possible(node)) { + node = find_next_bit_wrap(node_possible_map.bits, + nr_node_ids, node); + } + } + + return &futex_queues[node][hash & (futex_hashsize - 1)]; } @@ -217,32 +259,55 @@ static u64 get_inode_sequence_number(str * * lock_page() might sleep, the caller should not hold a spinlock. */ -int get_futex_key(u32 __user *uaddr, unsigned int flags, union futex_key *key, +int get_futex_key(void __user *uaddr, unsigned int flags, union futex_key *key, enum futex_access rw) { unsigned long address = (unsigned long)uaddr; struct mm_struct *mm = current->mm; struct page *page, *tail; struct address_space *mapping; - int err, ro = 0; + int node, err, size, ro = 0; bool fshared; fshared = flags & FLAGS_SHARED; + size = futex_size(flags); /* * The futex address must be "naturally" aligned. */ key->both.offset = address % PAGE_SIZE; - if (unlikely((address % sizeof(u32)) != 0)) + if (unlikely((address % size) != 0)) return -EINVAL; address -= key->both.offset; - if (unlikely(!access_ok(uaddr, sizeof(u32)))) + if (flags & FLAGS_NUMA) + size *= 2; + + if (unlikely(!access_ok(uaddr, size))) return -EFAULT; if (unlikely(should_fail_futex(fshared))) return -EFAULT; + key->both.node = -1; + if (flags & FLAGS_NUMA) { + void __user *naddr = uaddr + size/2; + + if (futex_get_value(&node, naddr, flags)) + return -EFAULT; + + if (node == -1) { + node = numa_node_id(); + if (futex_put_value(node, naddr, flags)) + return -EFAULT; + } + + if (node >= MAX_NUMNODES || !node_possible(node)) + return -EINVAL; + + key->both.node = node; + } + /* * PROCESS_PRIVATE futexes are fast. * As the mm cannot disappear under us and the 'key' only needs @@ -1125,27 +1190,42 @@ void futex_exit_release(struct task_stru static int __init futex_init(void) { - unsigned int futex_shift; - unsigned long i; + unsigned int order, n; + unsigned long size, i; #if CONFIG_BASE_SMALL futex_hashsize = 16; #else - futex_hashsize = roundup_pow_of_two(256 * num_possible_cpus()); + futex_hashsize = 256 * num_possible_cpus(); + futex_hashsize /= num_possible_nodes(); + futex_hashsize = roundup_pow_of_two(futex_hashsize); #endif + futex_hashshift = ilog2(futex_hashsize); + size = sizeof(struct futex_hash_bucket) * futex_hashsize; + order = get_order(size); + + for_each_node(n) { + struct futex_hash_bucket *table; + + if (order > MAX_ORDER) + table = vmalloc_huge_node(size, GFP_KERNEL, n); + else + table = alloc_pages_exact_nid(n, size, GFP_KERNEL); + + BUG_ON(!table); + + for (i = 0; i < futex_hashsize; i++) { + atomic_set(&table[i].waiters, 0); + spin_lock_init(&table[i].lock); + plist_head_init(&table[i].chain); + } - futex_queues = alloc_large_system_hash("futex", sizeof(*futex_queues), - futex_hashsize, 0, - futex_hashsize < 256 ? HASH_SMALL : 0, - &futex_shift, NULL, - futex_hashsize, futex_hashsize); - futex_hashsize = 1UL << futex_shift; - - for (i = 0; i < futex_hashsize; i++) { - atomic_set(&futex_queues[i].waiters, 0); - plist_head_init(&futex_queues[i].chain); - spin_lock_init(&futex_queues[i].lock); + futex_queues[n] = table; } + pr_info("futex hash table, %d nodes, %ld entries (order: %d, %lu bytes)\n", + num_possible_nodes(), + futex_hashsize, order, + sizeof(struct futex_hash_bucket) * futex_hashsize); return 0; } --- a/kernel/futex/futex.h +++ b/kernel/futex/futex.h @@ -65,6 +65,12 @@ static inline unsigned int futex2_to_fla return flags; } +static inline unsigned int futex_size(unsigned int flags) +{ + unsigned int size = flags & FLAGS_SIZE_MASK; + return 1 << size; /* {0,1,2,3} -> {1,2,4,8} */ +} + static inline bool futex_flags_valid(unsigned int flags) { /* Only 64bit futexes for 64bit code */ @@ -77,13 +83,19 @@ static inline bool futex_flags_valid(uns if ((flags & FLAGS_SIZE_MASK) != FLAGS_SIZE_32) return false; - return true; -} + /* + * Must be able to represent both NUMA_NO_NODE and every valid nodeid + * in a futex word. + */ + if (flags & FLAGS_NUMA) { + int bits = 8 * futex_size(flags); + u64 max = ~0ULL; + max >>= 64 - bits; + if (nr_node_ids >= max) + return false; + } -static inline unsigned int futex_size(unsigned int flags) -{ - unsigned int size = flags & FLAGS_SIZE_MASK; - return 1 << size; /* {0,1,2,3} -> {1,2,4,8} */ + return true; } static inline bool futex_validate_input(unsigned int flags, u64 val) @@ -182,7 +194,7 @@ enum futex_access { FUTEX_WRITE }; -extern int get_futex_key(u32 __user *uaddr, unsigned int flags, union futex_key *key, +extern int get_futex_key(void __user *uaddr, unsigned int flags, union futex_key *key, enum futex_access rw); extern struct hrtimer_sleeper * --- a/kernel/futex/syscalls.c +++ b/kernel/futex/syscalls.c @@ -179,7 +179,7 @@ SYSCALL_DEFINE6(futex, u32 __user *, uad return do_futex(uaddr, op, val, tp, uaddr2, (unsigned long)utime, val3); } -#define FUTEX2_MASK (FUTEX2_64 | FUTEX2_PRIVATE) +#define FUTEX2_MASK (FUTEX2_64 | FUTEX2_NUMA | FUTEX2_PRIVATE) /** * futex_parse_waitv - Parse a waitv array from userspace From patchwork Fri Jul 21 10:22:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13321867 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 E65BDEB64DD for ; Fri, 21 Jul 2023 10:59:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 59A142801BD; Fri, 21 Jul 2023 06:58:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4AC2D2801C4; Fri, 21 Jul 2023 06:58:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D5D232801C2; Fri, 21 Jul 2023 06:58:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 892C22801C3 for ; Fri, 21 Jul 2023 06:58:56 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6A62F12011F for ; Fri, 21 Jul 2023 10:58:56 +0000 (UTC) X-FDA: 81035321472.04.B933AA5 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf03.hostedemail.com (Postfix) with ESMTP id 1CDC720006 for ; Fri, 21 Jul 2023 10:58:53 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=h01MkGfW; spf=none (imf03.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=9NhyLnlAfopWgGOSWESIH0/PnobLNBtkaRYsiDDWMnA=; b=uivosdgp8foEbxfg9X+0uxvMGkY9yDnik6dd0G6FHnY2qG9ZZOA6n1uDpzHm7LsM03gDAa AboWYRByJ0I53AUrOd+awQqG/jhiYg61y8SehZdhTh/u7qaIx1ZIyuyISOczce8IVrc0+a 9TVGMEcMCVWtIGsKJtadwv2MIsfQD54= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689937134; a=rsa-sha256; cv=none; b=t6/PCid4k6uhGCF2rEmIaZzPrU1iAPxskFrof55ybBlrQh1w5PEgJBlCwJwc5rd69afk+b TvYLNrqK+5e7O9XGLrzX0WLwaU8r9I1hGWwSeetz5V2/2iGHyEyx/lgYC23oPGDx9yjp8p rhWOuUCz4V22TOqN26xmN5Rr97anS9A= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=h01MkGfW; spf=none (imf03.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=9NhyLnlAfopWgGOSWESIH0/PnobLNBtkaRYsiDDWMnA=; b=h01MkGfWiYpijGplIfpSuhTaay R4NdiugUbV+PWB/rXSW9+YSUbaIPv2WnlxJJrr5YIMAmxOzExLKqkEyqymN1nw9mzZjYWXsIDHanC Ozfo+c3Ji22VzxtffJVDwAhO/NftW5uSFZDZhV1Vkh3slUUdvKG9SSBL9DSTkm3xCO9zy8l8wb2q1 bfM7YyS1+B9jy6NKsyhANThpKn2r4NAf3GPXkDstxGzFGNQxy2e24aI4UCmXmH4c/FMgZbHqnHQO6 d/alwl24Cf/5O0jP3ErAMwjD6uqZSnL7IpHJNauz0+4lU9AFE1TUF2dvNMVXYg5CjSyj6oculDmQQ TjOWc8bA==; 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 1qMnqL-0000LE-0S; Fri, 21 Jul 2023 10:58:41 +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 3B671301C47; Fri, 21 Jul 2023 12:58:39 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 2507D3157E626; Fri, 21 Jul 2023 12:58:38 +0200 (CEST) Message-ID: <20230721105744.503233222@infradead.org> User-Agent: quilt/0.66 Date: Fri, 21 Jul 2023 12:22:49 +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 12/14] futex: Propagate flags into futex_get_value_locked() References: <20230721102237.268073801@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 1CDC720006 X-Rspam-User: X-Stat-Signature: 8o7niiqx1pdka7gsiiy78dqq9n8ztgoz X-Rspamd-Server: rspam03 X-HE-Tag: 1689937133-877485 X-HE-Meta: U2FsdGVkX19m5U3Ce0kBD9roZ8Z9B8KNcESkjxrR4cAs56Wintwp10OCKDCrdaHVu4xpAszn0tHb2tfVo+2R8aTyNhGDjG2TzNXPqCzboik59TiV0lNN55yoNQ+8pSYQFlaQQKGnZYtn/kHISfL2fwXHdWbx0rTidCvrEahQFOP1RoWj/aggm/O5OxchaXC6oyBKvYKaGImw/3MbNpnch2pIOSq4H0VdCDWN+dSIwagkMxCGC2XDa90qqmDlAZUX0+QX9UdPPJoeOjlsMbYIcM2IeGzYQDHGWWgDdT4qm2u8n3TqdonUr8GI+DZ5hxfy7cSRHZ88oZYS8Nt8iz9mEFVMbBXDTyDvGrmeZFQeX8appZnLT5Gwo9WcLX+/o8dCRuTbttjfkhTanw8xX87aHgX5JWvYpaZFRg3ZZMM5JG71n+uMeySrddf+QWVibMu0AcFu+F9NNXsFYIx3U92QrO7ffWGTxP3bWJzCE5mbZSm709FwAoDlTAciXlno/TVSTzxVnqce/QXBG8biLre35IwqWCCU4jhxPkWQwJkJ79bY1BToGICsnP3KLjw0PDT11e9Oqf12xPmGhHbpmp18XMlfmS5Vt8YaUnXUgkV38MVtB1GLgrC2lJvyDWfmBRb0bBJXo/qC9Rvbz9BWiSUktKDOYXmcvCCWGceSxOFB3y0R9yFCF1XgmihbTImPOR73hDJWIOvt780N4OLLqB6O4u9AwOX4a/xjOi4ABUBXezfitURFOFXkRQV35+cl/FoUOWe5o8k26oC/nrw5LAvhCsPzqc4GR+nQVZKlZKmq7wCZrz1ZBmCdgTZJqELNmzORoxdt2Ysa6cae0PrpHXCSx/A0by7eeIbJwq6d3/602qlfyR6m2FJWeac+vu564clVZRMjytIQqhhFUBJtN06Uf9PQ570GlNUrSSX+BYWt76epmbDfJrSsJwC/12WUuGJqme1BMsB8oE/0YvQA6kn fzU/45Lx 6NMh+arL50mRsuvhBF/XxJYy5k9S3fEPVmHlYN+n3/cGRts1iFJIs1lLpaolfzRT6q54zYWJqoURoDKE0QLF8MaxEmgNVyNQnuL92iZPPxilhfPicLyeGOOBt5CTgRrd2ltH56pqalRTh0G03YR9NkZJKYD8ykVULjZY2F9oVOteiGijfAAG1AhT6bsalrqi23o0Z/vK9lQSFpnz/B+oDvyXJKNICeNV0P1BKSk/m6htJvYtH9INzo14tq5XPVeoKGoM4KVx653FaGVAsfQqc3E36Jv+19uP4MbUSa00sHzbsx7UqUeTUQAAOfpM/MRK2lkkx 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: In order to facilitate variable sized futexes propagate the flags into futex_get_value_locked(). Signed-off-by: Peter Zijlstra (Intel) --- kernel/futex/core.c | 4 ++-- kernel/futex/futex.h | 2 +- kernel/futex/pi.c | 8 ++++---- kernel/futex/requeue.c | 4 ++-- kernel/futex/waitwake.c | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) --- a/kernel/futex/core.c +++ b/kernel/futex/core.c @@ -515,12 +515,12 @@ int futex_cmpxchg_value_locked(u32 *curv return ret; } -int futex_get_value_locked(u32 *dest, u32 __user *from) +int futex_get_value_locked(u32 *dest, u32 __user *from, unsigned int flags) { int ret; pagefault_disable(); - ret = __get_user(*dest, from); + ret = futex_get_value(dest, from, flags); pagefault_enable(); return ret ? -EFAULT : 0; --- a/kernel/futex/futex.h +++ b/kernel/futex/futex.h @@ -218,7 +218,7 @@ extern void futex_wake_mark(struct wake_ extern int fault_in_user_writeable(u32 __user *uaddr); extern int futex_cmpxchg_value_locked(u32 *curval, u32 __user *uaddr, u32 uval, u32 newval); -extern int futex_get_value_locked(u32 *dest, u32 __user *from); +extern int futex_get_value_locked(u32 *dest, u32 __user *from, unsigned int flags); extern struct futex_q *futex_top_waiter(struct futex_hash_bucket *hb, union futex_key *key); extern void __futex_unqueue(struct futex_q *q); --- a/kernel/futex/pi.c +++ b/kernel/futex/pi.c @@ -239,7 +239,7 @@ static int attach_to_pi_state(u32 __user * still is what we expect it to be, otherwise retry the entire * operation. */ - if (futex_get_value_locked(&uval2, uaddr)) + if (futex_get_value_locked(&uval2, uaddr, FLAGS_SIZE_32)) goto out_efault; if (uval != uval2) @@ -358,7 +358,7 @@ static int handle_exit_race(u32 __user * * The same logic applies to the case where the exiting task is * already gone. */ - if (futex_get_value_locked(&uval2, uaddr)) + if (futex_get_value_locked(&uval2, uaddr, FLAGS_SIZE_32)) return -EFAULT; /* If the user space value has changed, try again. */ @@ -526,7 +526,7 @@ int futex_lock_pi_atomic(u32 __user *uad * Read the user space value first so we can validate a few * things before proceeding further. */ - if (futex_get_value_locked(&uval, uaddr)) + if (futex_get_value_locked(&uval, uaddr, FLAGS_SIZE_32)) return -EFAULT; if (unlikely(should_fail_futex(true))) @@ -762,7 +762,7 @@ static int __fixup_pi_state_owner(u32 __ if (!pi_state->owner) newtid |= FUTEX_OWNER_DIED; - err = futex_get_value_locked(&uval, uaddr); + err = futex_get_value_locked(&uval, uaddr, FLAGS_SIZE_32); if (err) goto handle_err; --- a/kernel/futex/requeue.c +++ b/kernel/futex/requeue.c @@ -273,7 +273,7 @@ futex_proxy_trylock_atomic(u32 __user *p u32 curval; int ret; - if (futex_get_value_locked(&curval, pifutex)) + if (futex_get_value_locked(&curval, pifutex, FLAGS_SIZE_32)) return -EFAULT; if (unlikely(should_fail_futex(true))) @@ -451,7 +451,7 @@ int futex_requeue(u32 __user *uaddr1, un if (likely(cmpval != NULL)) { u32 curval; - ret = futex_get_value_locked(&curval, uaddr1); + ret = futex_get_value_locked(&curval, uaddr1, FLAGS_SIZE_32); if (unlikely(ret)) { double_unlock_hb(hb1, hb2); --- a/kernel/futex/waitwake.c +++ b/kernel/futex/waitwake.c @@ -438,7 +438,7 @@ static int futex_wait_multiple_setup(str u32 val = vs[i].w.val; hb = futex_q_lock(q); - ret = futex_get_value_locked(&uval, uaddr); + ret = futex_get_value_locked(&uval, uaddr, FLAGS_SIZE_32); if (!ret && uval == val) { /* @@ -606,7 +606,7 @@ int futex_wait_setup(u32 __user *uaddr, retry_private: *hb = futex_q_lock(q); - ret = futex_get_value_locked(&uval, uaddr); + ret = futex_get_value_locked(&uval, uaddr, FLAGS_SIZE_32); if (ret) { futex_q_unlock(*hb); From patchwork Fri Jul 21 10:22:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13321868 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 4B115EB64DC for ; Fri, 21 Jul 2023 10:59:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E95D2801C3; Fri, 21 Jul 2023 06:58:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 74D2E2801C2; Fri, 21 Jul 2023 06:58:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 10BC32801C3; Fri, 21 Jul 2023 06:58:57 -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 74CD32801BD for ; Fri, 21 Jul 2023 06:58:56 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 2BEC61C8BE5 for ; Fri, 21 Jul 2023 10:58:56 +0000 (UTC) X-FDA: 81035321472.07.1879683 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf09.hostedemail.com (Postfix) with ESMTP id 15FFB140009 for ; Fri, 21 Jul 2023 10:58:53 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=UhkHzgo2; dmarc=none; spf=none (imf09.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org 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=+GPeC+b0X/r2JxaFmk2Vd0m0Q7Mcvnivdsn9xJjP8Rw=; b=urEb1g6Zc+zP4GyYSIFQ10iqkdPxWEndkyTWLAn5D5LGUP0TeBN/FEbx27bz694DUwT3gr YaSYL3d0l9bbh/cvahoq0YqGLgTmhweIAFfuizQbwGyWgJRD3Q6kFaJ8lRkzf5kMp/sdXO SB7MdlN8qQRkXFfwt6HX1t9mSjuR6Xs= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=UhkHzgo2; dmarc=none; spf=none (imf09.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689937134; a=rsa-sha256; cv=none; b=79B+dYkEjOPqM3Gdh8sfT3K6II0pqvJXBDh3heCcuMliQ+fjfSP7jgqfhoBMJHoq9OgxBW JTHRsu8p3i343fR0uZ//Fr6YE4eUriBATPWDLQ9Z5ix6VoN2vfS8xyfe0W5fLM4X7orsui PUrBhigUw0jUUA3hK5iRClc4F+AVwgw= 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=+GPeC+b0X/r2JxaFmk2Vd0m0Q7Mcvnivdsn9xJjP8Rw=; b=UhkHzgo2Hvp0CRLk+p6vRsrvw7 YgKgzf/XCyoOSRLPIKtpnbjTY6nadJlG2LCSkDKGPR7qb8qcgzOyFbOuaRcYAAaKiLE+s/2Wch+VQ egzMeJsCik0LwJptN4u7633AsD1TZrbo6CKJXqjOeIy8/4hE26m1ZmKYamWi7UZxxexcUsslTRml/ 1v13/bZNfkaqUAEObRAD9RWkVA6+HiuEfzeNV118iLAl2qc4vpbNNPPXVPHhKO4TLaLeVwUrWOCmP stLfJlSL/fiD3SQ7WN7OuuSX53eIVavOdM2+oaaizUSGHhfpaZS+fWd+w4ZeXu0qnqvhUCB930wgL hhHazrSg==; 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 1qMnqL-0000LF-0i; Fri, 21 Jul 2023 10:58:41 +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 404B3301C81; Fri, 21 Jul 2023 12:58:39 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 287DF3157E620; Fri, 21 Jul 2023 12:58:38 +0200 (CEST) Message-ID: <20230721105744.571094000@infradead.org> User-Agent: quilt/0.66 Date: Fri, 21 Jul 2023 12:22:50 +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 13/14] futex: Enable FUTEX2_{8,16} References: <20230721102237.268073801@infradead.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 15FFB140009 X-Stat-Signature: ycas7kj1bo1erfi5nazarbupbeackq4s X-HE-Tag: 1689937133-345454 X-HE-Meta: U2FsdGVkX1/Ercag1z2J+Ha0WckTrEwlfL9ZYzhyms4Py+PR6UL16wTJYaEIiDh7CzcJ+bIIM2wVqLOebu0mkArzibwmUqGtunNbByBpEcICzYtm6tjkeqFhxA0aG+6BYmz/BwYjwpBhqhTIxRRME0YhiO/Pw/guuQQ86LCTE+Tg4L+9jycJWjZP961aQkhtU5zXuPX/WGi/ukdUt7OAYcvHMPyCWqgN+yHpQVT4+OHoLaB5jj26amky2iI89UbQG/Jhf5lz5xS9kmwIfMZnR+0pG2zDcxKZ/EUWVXhpJWYL1tjX7GbMCf2Y5U3Lgqv/Xr11A0GQjB8MrNXOHGz9WXtwZ+Qg84lkVGCLr1Lf2YjHqMHpN0s3nx+6rvSZPbRi6o+mXLRpaqMRe1c2EU0gKrwfsBTLwwOmDwelF6T8OqSljN1a+/SJM9QdDJLCbb5n1vgDr8HRt7D3jkTugd4U0rYwFYw4jncAf7jXitejUCFC3S+YYa5/5YIw3uxTDqWIJYDmm/0ST1o/Q5gYKXbywwHlrkQbvBfQHl1Ba/ls/cMLhIUbrkAl+3SRYN++JoWJr3YPsuGPWIRcBrXSH10fHYWuyFOw/DhV+Y5fitJZXrmKaQOX/B/HFEL6ifQmKSLWDLADvn0PC8I8yD1LO+bPTeV6Iz7c6W0YhyTo7/xC4H2dSYK1BfIzRD2aybHJ88rQaZGzIQJFNqFP0NOwJSjxdj1HzUHn2n7bx7+zNiUZWw1d2Wf/ret6SfywrQfTyKduMgLWcJBgOCCscQK2Y+Vr5V0MXYvh5+DtZ2Jn0McW96GG0FGL3QqK5hxKkvot66RnJhyVBfcM5PAEMT7BfNfXB4Rfc2BsbnjFU8USP1PqjVSe1QqbWLnkD+Hp8LNsrQn4YLBEVB5DD3pehyLsLiwgw1wCVynsIgLLtYHel823vwNGcsiI1icHnXKdBVL1BBfjZvOM8IuNZa+qbjJAGMl /uMzX0O1 8swfDyRGOvyBw7ZWR74xSrksbMvKUiKcISMmzToKiVYPOsEx9RK4gNbib6LXS+yKNhc1LRceYYK9nh2NqHzS/tCdAnk78yZZwHs/hTmNwoEEk7kBTmDyfhcvi9/Zpe/Pedny1mB1j0/EuBocdBPEFPbcZKLzLyHCE9UEj1VZXP9Y3JwOexxXQ104Mxl5RmsYs79X0IVQi8hq49EkSRkIpQu9W6Lb+alzQ+HK9bIVEHetBFJ20aEDgEAs0NquNYmD1PEu4cKQhQVYbRAwrZEgimiD3nKSqJA0DtTUkMcBC3FQ7YkEh/EEAdoJLj4cT1bzJ6/lj 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: When futexes are no longer u32 aligned, the lower offset bits are no longer available to put type info in. However, since offset is the offset within a page, there are plenty bits available on the top end. After that, pass flags into futex_get_value_locked() for WAIT and disallow FUTEX2_64 instead of mandating FUTEX2_32. Signed-off-by: Peter Zijlstra (Intel) --- include/linux/futex.h | 11 ++++++----- kernel/futex/core.c | 9 +++++++++ kernel/futex/futex.h | 4 ++-- kernel/futex/waitwake.c | 5 +++-- 4 files changed, 20 insertions(+), 9 deletions(-) --- a/include/linux/futex.h +++ b/include/linux/futex.h @@ -16,18 +16,19 @@ struct task_struct; * The key type depends on whether it's a shared or private mapping. * Don't rearrange members without looking at hash_futex(). * - * offset is aligned to a multiple of sizeof(u32) (== 4) by definition. - * We use the two low order bits of offset to tell what is the kind of key : + * offset is the position within a page and is in the range [0, PAGE_SIZE). + * The high bits of the offset indicate what kind of key this is: * 00 : Private process futex (PTHREAD_PROCESS_PRIVATE) * (no reference on an inode or mm) * 01 : Shared futex (PTHREAD_PROCESS_SHARED) * mapped on a file (reference on the underlying inode) * 10 : Shared futex (PTHREAD_PROCESS_SHARED) * (but private mapping on an mm, and reference taken on it) -*/ + */ -#define FUT_OFF_INODE 1 /* We set bit 0 if key has a reference on inode */ -#define FUT_OFF_MMSHARED 2 /* We set bit 1 if key has a reference on mm */ +#define FUT_OFF_INODE (PAGE_SIZE << 0) +#define FUT_OFF_MMSHARED (PAGE_SIZE << 1) +#define FUT_OFF_SIZE (PAGE_SIZE << 2) union futex_key { struct { --- a/kernel/futex/core.c +++ b/kernel/futex/core.c @@ -308,6 +308,15 @@ int get_futex_key(void __user *uaddr, un } /* + * Encode the futex size in the offset. This makes cross-size + * wake-wait fail -- see futex_match(). + * + * NOTE that cross-size wake-wait is fundamentally broken wrt + * FLAGS_NUMA but could possibly work for !NUMA. + */ + key->both.offset |= FUT_OFF_SIZE * (flags & FLAGS_SIZE_MASK); + + /* * PROCESS_PRIVATE futexes are fast. * As the mm cannot disappear under us and the 'key' only needs * virtual address, we dont even have to find the underlying vma. --- a/kernel/futex/futex.h +++ b/kernel/futex/futex.h @@ -79,8 +79,8 @@ static inline bool futex_flags_valid(uns return false; } - /* Only 32bit futexes are implemented -- for now */ - if ((flags & FLAGS_SIZE_MASK) != FLAGS_SIZE_32) + /* 64bit futexes aren't implemented -- yet */ + if ((flags & FLAGS_SIZE_MASK) == FLAGS_SIZE_64) return false; /* --- a/kernel/futex/waitwake.c +++ b/kernel/futex/waitwake.c @@ -434,11 +434,12 @@ static int futex_wait_multiple_setup(str for (i = 0; i < count; i++) { u32 __user *uaddr = (u32 __user *)(unsigned long)vs[i].w.uaddr; + unsigned int flags = vs[i].w.flags; struct futex_q *q = &vs[i].q; u32 val = vs[i].w.val; hb = futex_q_lock(q); - ret = futex_get_value_locked(&uval, uaddr, FLAGS_SIZE_32); + ret = futex_get_value_locked(&uval, uaddr, flags); if (!ret && uval == val) { /* @@ -606,7 +607,7 @@ int futex_wait_setup(u32 __user *uaddr, retry_private: *hb = futex_q_lock(q); - ret = futex_get_value_locked(&uval, uaddr, FLAGS_SIZE_32); + ret = futex_get_value_locked(&uval, uaddr, flags); if (ret) { futex_q_unlock(*hb); From patchwork Fri Jul 21 10:22:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13321861 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 6F982C001DC for ; Fri, 21 Jul 2023 10:59:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 350A62801BC; Fri, 21 Jul 2023 06:58:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 263A12801BB; Fri, 21 Jul 2023 06:58:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 98DC62801BD; Fri, 21 Jul 2023 06:58:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 1F15E2801BC for ; Fri, 21 Jul 2023 06:58:53 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id DFB1040247 for ; Fri, 21 Jul 2023 10:58:52 +0000 (UTC) X-FDA: 81035321304.02.51298BE Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf02.hostedemail.com (Postfix) with ESMTP id CBBB980016 for ; Fri, 21 Jul 2023 10:58:49 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=tfiqQ1Hh; spf=none (imf02.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=1689937130; 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=nGKNufgMab+OEMeymkv4TIdRF4Fx9shzOVCw+VBNFEE=; b=zT14/Dqr/xpg36ev1HWYYmgs/RLXZ7DSIjMv+Js+3MwOQk1JrQ9kb5tqsT8L2NgmlWS9FJ NWUUHHoxcA2nj3Di/g5tzzazVjP5J2jTHtTvPvt+Qf0F05aoakfGAp+c06Ej1+sqqlElsh QiMNhqG3EjgkwD5mVeOQffi7Juzr3hA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689937130; a=rsa-sha256; cv=none; b=Ljj1SkyAzvjYWQeu2k5zCX6r7uMhEel4OloU78bPEvwAqunsNwpcqMX8hZe3Vb+0d3a38M gRYLPoIX3yU4ieemmJgKV9Kblafc4bQNwn3wI0nNfYX/DUN0Wsn9ymNJoK3STQR+Y5AChV WR/s77Vhu6WLDSU2zyA+MCks0VFX/ig= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=tfiqQ1Hh; spf=none (imf02.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=nGKNufgMab+OEMeymkv4TIdRF4Fx9shzOVCw+VBNFEE=; b=tfiqQ1Hhwfdex9G8QX5VLPRhv2 juMqhwCJy9asEDhdqQ90LbGg1sUBMSQls1JGgtSs2p3AakRnJH4AfZjQUyYzMEttFU3QA2ty1J1lB ybu8hDw5yJo1zs81OERJPIwDHqEIVYRtDNs8GooA4p1aMMIqzFPkQbrF7gFXrO0XHJ6lbZ0FNrXuh lOjL8kiSXwmWwHAOoKUcbOe0bv9a8UxZ4Xz+k1b9yApdwZZ2kS6Bpyp0vVVCdikhnJl7UqEEjryQC 2DjnHH+c5hUrhG2fbkyy8v10kAKVGb/d9Kme5kxUMK9qtzAYDMKdK3rJSiZtOXSAkEAINt5eBCibv qprTb5pQ==; 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 1qMnqK-0012Ok-Re; Fri, 21 Jul 2023 10:58:41 +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 42276301CF2; Fri, 21 Jul 2023 12:58:39 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 2F0BC3157E628; Fri, 21 Jul 2023 12:58:38 +0200 (CEST) Message-ID: <20230721105744.639139412@infradead.org> User-Agent: quilt/0.66 Date: Fri, 21 Jul 2023 12:22:51 +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 14/14] futex,selftests: Extend the futex selftests References: <20230721102237.268073801@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: CBBB980016 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: usn91zc4b5b4xs8h8shhdzw4m8qm9mxd X-HE-Tag: 1689937129-325340 X-HE-Meta: U2FsdGVkX19WLMlOa8G3ZaW1DrcA1qThZ5OTIOxLaveZ1AZso0jso5jW+pKGFgDDxnWI8nYJxUT0Rv//6MxWmHeUWbI/dYJxE9q6qp/bwDNy96t18KvuaJCxO5XFQyUw9EvNxVwsJG9VCovJ/hQHyUwbUbE+sBBi0JKXU15nAvqJt2wumR4D0lipBRvSH07SuOm8xcCKCj/WiIZNH2CDFEdf0wKElWYr2Jc3zvkut+9WXZybRC86utsivDVoH8l9jtoEs0gGG8W99YkPggme0rU71G3rz+nDQDrGo003yZbb4CzSx4nbvBp5qv5CAt2t/UDmBUVlK/R5zgxKdSbp1yjs/TaQNa9hQGbR/nbLH92AR859qc+mws4TUWNXOmlkAL8ENwXKvvDePR1oHX/aIEwgE9MEtqs0DmDi/2RpBtMvDEPbfRgBbzWbCZFJqPlp4zP7z91wMnkUiRAB41Ieru9ydaNZ987iM8Z+iaBUwzQDgU3HzkUtxx9C6PKsZ1+yaRlNsZeTHcOzytInuq6lOJwQYzSPlY5kKmeoYnP4S/mA9WKJ/Kb59hJSi+jU8UPD7OCqFtx3HlHR3ajPIk/mofuWXc4D0Z4s1NS//fm/yh3jeNb53uDCZjc+LxwYJs+oSskhxqCdZ/4ES5+HnTYluFKZLLonoFroW359H8ML1EkjfTcbPGFo+/jn5eOhy0GGVxdIuK+CPOJgLK2X4X85TaChOZejfXSb6ZlpwDSlz4JAmqL57wM1hsLRdgl5Q9xG8J8R9YbRtfLJfNiSbnGhrodfdcGkmA8VzAEgKaLo46SuKgvvfZWYAqoVn/xNSB8vHtG1xkY8XY/TDSz58pcWZEfs7BWECChmfPC7+crBYISdA71Y1hUt+3DljBMhe5JQ41NEmZL0w1hlBZSKTklhVz4QOs2RvkXThKw7EkGCVAkVpppucb3Zuukq9N6LCBc2SuUuUmCFibs+ORk7o3w yEi+6rUf ROmGY46XADO0s0ZkTzIZaWWQmucQINPHREazLUjB+NqW8siyNa+G7Ogdzp4d9pBkICHVJd5x1AwHXVULzX9YjbHjObcStT5jZjEtJebmwHkuSGnHbe3Hjn5HFidEC35UlovUTtCl2z2pm4iBxetJ2hCSUThJr47etu2mDJW2syU/Xa+VRh2FnhdJnB7mbtPVOSwdszsTWS1RMUyp0nhTF2TNdYZoO9uZQvBuZuNLAASerxS1lGIPRf6IFcdmb0igYVWKN0U5CQMSmO55k0lJddv9Brw== 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: Extend the wait/requeue selftests to also cover the futex2 syscalls. Signed-off-by: Peter Zijlstra (Intel) --- tools/testing/selftests/futex/functional/futex_requeue.c | 100 +++++++++- tools/testing/selftests/futex/functional/futex_wait.c | 56 ++++- tools/testing/selftests/futex/functional/futex_wait_timeout.c | 14 + tools/testing/selftests/futex/functional/futex_wait_wouldblock.c | 28 ++ tools/testing/selftests/futex/functional/futex_waitv.c | 15 - tools/testing/selftests/futex/functional/run.sh | 6 tools/testing/selftests/futex/include/futex2test.h | 39 +++ 7 files changed, 229 insertions(+), 29 deletions(-) --- a/tools/testing/selftests/futex/functional/futex_requeue.c +++ b/tools/testing/selftests/futex/functional/futex_requeue.c @@ -7,8 +7,10 @@ #include #include +#include #include "logging.h" #include "futextest.h" +#include "futex2test.h" #define TEST_NAME "futex-requeue" #define timeout_ns 30000000 @@ -16,24 +18,58 @@ volatile futex_t *f1; +bool futex2 = 0; +bool mixed = 0; + void usage(char *prog) { printf("Usage: %s\n", prog); printf(" -c Use color\n"); + printf(" -n Use futex2 interface\n"); + printf(" -x Use mixed size futex\n"); printf(" -h Display this help message\n"); printf(" -v L Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n", VQUIET, VCRITICAL, VINFO); } -void *waiterfn(void *arg) +static void *waiterfn(void *arg) { + unsigned int flags = 0; struct timespec to; - to.tv_sec = 0; - to.tv_nsec = timeout_ns; + if (futex2) { + unsigned long mask; + + if (clock_gettime(CLOCK_MONOTONIC, &to)) { + printf("clock_gettime() failed errno %d", errno); + return NULL; + } + + to.tv_nsec += timeout_ns; + if (to.tv_nsec >= 1000000000) { + to.tv_sec++; + to.tv_nsec -= 1000000000; + } + + if (mixed) { + flags |= FUTEX2_16; + mask = (unsigned short)(~0U); + } else { + flags |= FUTEX2_32; + mask = (unsigned int)(~0U); + } + + if (futex2_wait(f1, *f1, mask, flags, + &to, CLOCK_MONOTONIC)) + printf("waiter failed errno %d\n", errno); + } else { + + to.tv_sec = 0; + to.tv_nsec = timeout_ns; - if (futex_wait(f1, *f1, &to, 0)) - printf("waiter failed errno %d\n", errno); + if (futex_wait(f1, *f1, &to, flags)) + printf("waiter failed errno %d\n", errno); + } return NULL; } @@ -48,7 +84,7 @@ int main(int argc, char *argv[]) f1 = &_f1; - while ((c = getopt(argc, argv, "cht:v:")) != -1) { + while ((c = getopt(argc, argv, "xncht:v:")) != -1) { switch (c) { case 'c': log_color(1); @@ -59,6 +95,12 @@ int main(int argc, char *argv[]) case 'v': log_verbosity(atoi(optarg)); break; + case 'x': + mixed=1; + /* fallthrough */ + case 'n': + futex2=1; + break; default: usage(basename(argv[0])); exit(1); @@ -79,7 +121,22 @@ int main(int argc, char *argv[]) usleep(WAKE_WAIT_US); info("Requeuing 1 futex from f1 to f2\n"); - res = futex_cmp_requeue(f1, 0, &f2, 0, 1, 0); + if (futex2) { + struct futex_waitv futexes[2] = { + { + .val = 0, + .uaddr = (unsigned long)f1, + .flags = mixed ? FUTEX2_16 : FUTEX2_32, + }, + { + .uaddr = (unsigned long)&f2, + .flags = FUTEX2_32, + }, + }; + res = futex2_requeue(futexes, 0, 0, 1); + } else { + res = futex_cmp_requeue(f1, 0, &f2, 0, 1, 0); + } if (res != 1) { ksft_test_result_fail("futex_requeue simple returned: %d %s\n", res ? errno : res, @@ -89,7 +146,11 @@ int main(int argc, char *argv[]) info("Waking 1 futex at f2\n"); - res = futex_wake(&f2, 1, 0); + if (futex2) { + res = futex2_wake(&f2, ~0U, 1, FUTEX2_32); + } else { + res = futex_wake(&f2, 1, 0); + } if (res != 1) { ksft_test_result_fail("futex_requeue simple returned: %d %s\n", res ? errno : res, @@ -112,7 +173,22 @@ int main(int argc, char *argv[]) usleep(WAKE_WAIT_US); info("Waking 3 futexes at f1 and requeuing 7 futexes from f1 to f2\n"); - res = futex_cmp_requeue(f1, 0, &f2, 3, 7, 0); + if (futex2) { + struct futex_waitv futexes[2] = { + { + .val = 0, + .uaddr = (unsigned long)f1, + .flags = mixed ? FUTEX2_16 : FUTEX2_32, + }, + { + .uaddr = (unsigned long)&f2, + .flags = FUTEX2_32, + }, + }; + res = futex2_requeue(futexes, 0, 3, 7); + } else { + res = futex_cmp_requeue(f1, 0, &f2, 3, 7, 0); + } if (res != 10) { ksft_test_result_fail("futex_requeue many returned: %d %s\n", res ? errno : res, @@ -121,7 +197,11 @@ int main(int argc, char *argv[]) } info("Waking INT_MAX futexes at f2\n"); - res = futex_wake(&f2, INT_MAX, 0); + if (futex2) { + res = futex2_wake(&f2, ~0U, INT_MAX, FUTEX2_32); + } else { + res = futex_wake(&f2, INT_MAX, 0); + } if (res != 7) { ksft_test_result_fail("futex_requeue many returned: %d %s\n", res ? errno : res, --- a/tools/testing/selftests/futex/functional/futex_wait.c +++ b/tools/testing/selftests/futex/functional/futex_wait.c @@ -9,8 +9,10 @@ #include #include #include +#include #include "logging.h" #include "futextest.h" +#include "futex2test.h" #define TEST_NAME "futex-wait" #define timeout_ns 30000000 @@ -19,10 +21,13 @@ void *futex; +bool futex2 = 0; + void usage(char *prog) { printf("Usage: %s\n", prog); printf(" -c Use color\n"); + printf(" -n Use futex2 interface\n"); printf(" -h Display this help message\n"); printf(" -v L Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n", VQUIET, VCRITICAL, VINFO); @@ -30,17 +35,35 @@ void usage(char *prog) static void *waiterfn(void *arg) { - struct timespec to; unsigned int flags = 0; + struct timespec to; if (arg) flags = *((unsigned int *) arg); - to.tv_sec = 0; - to.tv_nsec = timeout_ns; + if (futex2) { + if (clock_gettime(CLOCK_MONOTONIC, &to)) { + printf("clock_gettime() failed errno %d", errno); + return NULL; + } - if (futex_wait(futex, 0, &to, flags)) - printf("waiter failed errno %d\n", errno); + to.tv_nsec += timeout_ns; + if (to.tv_nsec >= 1000000000) { + to.tv_sec++; + to.tv_nsec -= 1000000000; + } + + if (futex2_wait(futex, 0, ~0U, flags | FUTEX2_32, + &to, CLOCK_MONOTONIC)) + printf("waiter failed errno %d\n", errno); + } else { + + to.tv_sec = 0; + to.tv_nsec = timeout_ns; + + if (futex_wait(futex, 0, &to, flags)) + printf("waiter failed errno %d\n", errno); + } return NULL; } @@ -55,7 +78,7 @@ int main(int argc, char *argv[]) futex = &f_private; - while ((c = getopt(argc, argv, "cht:v:")) != -1) { + while ((c = getopt(argc, argv, "ncht:v:")) != -1) { switch (c) { case 'c': log_color(1); @@ -66,6 +89,9 @@ int main(int argc, char *argv[]) case 'v': log_verbosity(atoi(optarg)); break; + case 'n': + futex2=1; + break; default: usage(basename(argv[0])); exit(1); @@ -84,7 +110,11 @@ int main(int argc, char *argv[]) usleep(WAKE_WAIT_US); info("Calling private futex_wake on futex: %p\n", futex); - res = futex_wake(futex, 1, FUTEX_PRIVATE_FLAG); + if (futex2) { + res = futex2_wake(futex, ~0U, 1, FUTEX2_32 | FUTEX2_PRIVATE); + } else { + res = futex_wake(futex, 1, FUTEX_PRIVATE_FLAG); + } if (res != 1) { ksft_test_result_fail("futex_wake private returned: %d %s\n", errno, strerror(errno)); @@ -112,7 +142,11 @@ int main(int argc, char *argv[]) usleep(WAKE_WAIT_US); info("Calling shared (page anon) futex_wake on futex: %p\n", futex); - res = futex_wake(futex, 1, 0); + if (futex2) { + res = futex2_wake(futex, ~0U, 1, FUTEX2_32); + } else { + res = futex_wake(futex, 1, 0); + } if (res != 1) { ksft_test_result_fail("futex_wake shared (page anon) returned: %d %s\n", errno, strerror(errno)); @@ -151,7 +185,11 @@ int main(int argc, char *argv[]) usleep(WAKE_WAIT_US); info("Calling shared (file backed) futex_wake on futex: %p\n", futex); - res = futex_wake(shm, 1, 0); + if (futex2) { + res = futex2_wake(shm, ~0U, 1, FUTEX2_32); + } else { + res = futex_wake(shm, 1, 0); + } if (res != 1) { ksft_test_result_fail("futex_wake shared (file backed) returned: %d %s\n", errno, strerror(errno)); --- a/tools/testing/selftests/futex/functional/futex_wait_timeout.c +++ b/tools/testing/selftests/futex/functional/futex_wait_timeout.c @@ -125,7 +125,7 @@ int main(int argc, char *argv[]) } ksft_print_header(); - ksft_set_plan(9); + ksft_set_plan(11); ksft_print_msg("%s: Block on a futex and wait for timeout\n", basename(argv[0])); ksft_print_msg("\tArguments: timeout=%ldns\n", timeout_ns); @@ -194,6 +194,18 @@ int main(int argc, char *argv[]) res = futex_waitv(&waitv, 1, 0, &to, CLOCK_REALTIME); test_timeout(res, &ret, "futex_waitv realtime", ETIMEDOUT); + /* futex2_wait with CLOCK_MONOTONIC */ + if (futex_get_abs_timeout(CLOCK_MONOTONIC, &to, timeout_ns)) + return RET_FAIL; + res = futex2_wait(&f1, f1, 1, FUTEX2_32, &to, CLOCK_MONOTONIC); + test_timeout(res, &ret, "futex2_wait monotonic", ETIMEDOUT); + + /* futex2_wait with CLOCK_REALTIME */ + if (futex_get_abs_timeout(CLOCK_REALTIME, &to, timeout_ns)) + return RET_FAIL; + res = futex2_wait(&f1, f1, 1, FUTEX2_32, &to, CLOCK_REALTIME); + test_timeout(res, &ret, "futex2_wait realtime", ETIMEDOUT); + ksft_print_cnts(); return ret; } --- a/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c +++ b/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c @@ -46,7 +46,7 @@ int main(int argc, char *argv[]) struct futex_waitv waitv = { .uaddr = (uintptr_t)&f1, .val = f1+1, - .flags = FUTEX_32, + .flags = FUTEX2_32 | FUTEX2_PRIVATE, .__reserved = 0 }; @@ -68,7 +68,7 @@ int main(int argc, char *argv[]) } ksft_print_header(); - ksft_set_plan(2); + ksft_set_plan(3); ksft_print_msg("%s: Test the unexpected futex value in FUTEX_WAIT\n", basename(argv[0])); @@ -106,6 +106,30 @@ int main(int argc, char *argv[]) ksft_test_result_pass("futex_waitv\n"); } + if (clock_gettime(CLOCK_MONOTONIC, &to)) { + error("clock_gettime failed\n", errno); + return errno; + } + + to.tv_nsec += timeout_ns; + + if (to.tv_nsec >= 1000000000) { + to.tv_sec++; + to.tv_nsec -= 1000000000; + } + + info("Calling futex2_wait on f1: %u @ %p with val=%u\n", f1, &f1, f1+1); + res = futex2_wait(&f1, f1+1, ~0U, FUTEX2_32 | FUTEX2_PRIVATE, + &to, CLOCK_MONOTONIC); + if (!res || errno != EWOULDBLOCK) { + ksft_test_result_pass("futex2_wait returned: %d %s\n", + res ? errno : res, + res ? strerror(errno) : ""); + ret = RET_FAIL; + } else { + ksft_test_result_pass("futex2_wait\n"); + } + ksft_print_cnts(); return ret; } --- a/tools/testing/selftests/futex/functional/futex_waitv.c +++ b/tools/testing/selftests/futex/functional/futex_waitv.c @@ -88,7 +88,7 @@ int main(int argc, char *argv[]) for (i = 0; i < NR_FUTEXES; i++) { waitv[i].uaddr = (uintptr_t)&futexes[i]; - waitv[i].flags = FUTEX_32 | FUTEX_PRIVATE_FLAG; + waitv[i].flags = FUTEX2_32 | FUTEX2_PRIVATE; waitv[i].val = 0; waitv[i].__reserved = 0; } @@ -99,7 +99,8 @@ int main(int argc, char *argv[]) usleep(WAKE_WAIT_US); - res = futex_wake(u64_to_ptr(waitv[NR_FUTEXES - 1].uaddr), 1, FUTEX_PRIVATE_FLAG); + res = futex2_wake(u64_to_ptr(waitv[NR_FUTEXES - 1].uaddr), ~0U, 1, + FUTEX2_PRIVATE | FUTEX2_32); if (res != 1) { ksft_test_result_fail("futex_wake private returned: %d %s\n", res ? errno : res, @@ -122,7 +123,7 @@ int main(int argc, char *argv[]) *shared_data = 0; waitv[i].uaddr = (uintptr_t)shared_data; - waitv[i].flags = FUTEX_32; + waitv[i].flags = FUTEX2_32; waitv[i].val = 0; waitv[i].__reserved = 0; } @@ -145,8 +146,8 @@ int main(int argc, char *argv[]) for (i = 0; i < NR_FUTEXES; i++) shmdt(u64_to_ptr(waitv[i].uaddr)); - /* Testing a waiter without FUTEX_32 flag */ - waitv[0].flags = FUTEX_PRIVATE_FLAG; + /* Testing a waiter without FUTEX2_32 flag */ + waitv[0].flags = FUTEX2_PRIVATE; if (clock_gettime(CLOCK_MONOTONIC, &to)) error("gettime64 failed\n", errno); @@ -160,11 +161,11 @@ int main(int argc, char *argv[]) res ? strerror(errno) : ""); ret = RET_FAIL; } else { - ksft_test_result_pass("futex_waitv without FUTEX_32\n"); + ksft_test_result_pass("futex_waitv without FUTEX2_32\n"); } /* Testing a waiter with an unaligned address */ - waitv[0].flags = FUTEX_PRIVATE_FLAG | FUTEX_32; + waitv[0].flags = FUTEX2_PRIVATE | FUTEX2_32; waitv[0].uaddr = 1; if (clock_gettime(CLOCK_MONOTONIC, &to)) --- a/tools/testing/selftests/futex/functional/run.sh +++ b/tools/testing/selftests/futex/functional/run.sh @@ -76,9 +76,15 @@ echo echo ./futex_wait $COLOR +echo +./futex_wait -n $COLOR echo ./futex_requeue $COLOR +echo +./futex_requeue -n $COLOR +echo +./futex_requeue -x $COLOR echo ./futex_waitv $COLOR --- a/tools/testing/selftests/futex/include/futex2test.h +++ b/tools/testing/selftests/futex/include/futex2test.h @@ -8,6 +8,28 @@ #define u64_to_ptr(x) ((void *)(uintptr_t)(x)) +#ifndef __NR_futex_wake +#define __NR_futex_wake 452 +#define __NR_futex_wait 453 +#define __NR_futex_requeue 454 +#endif + +#ifndef FUTEX2_8 +/* + * Flags for futex2 syscalls. + */ +#define FUTEX2_8 0x00 +#define FUTEX2_16 0x01 +#define FUTEX2_32 0x02 +#define FUTEX2_64 0x03 +#define FUTEX2_NUMA 0x04 + /* 0x08 */ + /* 0x10 */ + /* 0x20 */ + /* 0x40 */ +#define FUTEX2_PRIVATE FUTEX_PRIVATE_FLAG +#endif + /** * futex_waitv - Wait at multiple futexes, wake on any * @waiters: Array of waiters @@ -20,3 +42,20 @@ static inline int futex_waitv(volatile s { return syscall(__NR_futex_waitv, waiters, nr_waiters, flags, timo, clockid); } + +static inline int futex2_wake(volatile void *uaddr, unsigned long mask, int nr, unsigned int flags) +{ + return syscall(__NR_futex_wake, uaddr, mask, nr, flags); +} + +static inline int futex2_wait(volatile void *uaddr, unsigned long val, unsigned long mask, + unsigned int flags, struct timespec *timo, clockid_t clockid) +{ + return syscall(__NR_futex_wait, uaddr, val, mask, flags, timo, clockid); +} + +static inline int futex2_requeue(struct futex_waitv *futexes, unsigned int flags, + int nr_wake, int nr_requeue) +{ + return syscall(__NR_futex_requeue, futexes, flags, nr_wake, nr_requeue); +}