From patchwork Thu Sep 21 10:45:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13393850 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 3EA83E70718 for ; Thu, 21 Sep 2023 11:01:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E4BBC6B01B1; Thu, 21 Sep 2023 07:01:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BCDD86B0205; Thu, 21 Sep 2023 07:01:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E2F86B0204; Thu, 21 Sep 2023 07:01:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 79DA76B0203 for ; Thu, 21 Sep 2023 07:01:00 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 2268B16108F for ; Thu, 21 Sep 2023 11:01:00 +0000 (UTC) X-FDA: 81260312280.19.7E74AAE Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf27.hostedemail.com (Postfix) with ESMTP id 231424003B for ; Thu, 21 Sep 2023 11:00:57 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Ki2Us5Rj; spf=none (imf27.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=1695294058; 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=6GTmF/efpBOGxWpnxI0iv/95Tyn4hkFggwaK/r4v1Cs=; b=iIPai0SUuDpSQNkNXsWcOqgJ4lUj4VhTKMr6dRKNQuoXxeIhvul1v32vxXxNEhtp1XVNEV GwgpliUgz+5Pr1Yx/d8jzNI9ke+e5smV1/C6QHzo80iuMFswuistWX94ixQy52b26BID+G lyLVA1NmbrthTgWa9wtYQ8pME/SKSfw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695294058; a=rsa-sha256; cv=none; b=lb6kf679HRU85E1DICAK4NnDVXMnPtPtQhxi8rOnnUUoeM4oOyuxMRq8f3lsOlGQK3Z9eT Wq5pnI+FG0p99WyQUhUhYzbn2MVbf3c4RsIfNAEEZqkuxmmI+7N6PySKTECwT8ECCd1DtY Uh1RL7YKrV64qx1+hFwdkwk9/avZ78A= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Ki2Us5Rj; spf=none (imf27.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=6GTmF/efpBOGxWpnxI0iv/95Tyn4hkFggwaK/r4v1Cs=; b=Ki2Us5RjFjMzBWlTemJkP3UX3p W/3wvqAh8wv1uqDobl2b1SjQ/4ersxYbUlO1kRlPc1wRFouRy3wJERE1JiFS/ZLtuALMiA69orKw+ m9Wjq6CPh2D4vYXbzxoDWAM3BXnEjLxJpWXHGAPd5n0CLE/goezV6qBcsQvKPiUC3gqTBjhj/qtz/ Z8hZQbq0HFYvWOIpIUwV1Rn7IvT3I9s5kJnutBas7uarp+2Lsn32bIq/WwutCtvcsqX5Eq8MmYgjL G7+PTcedyhs6TbmN5IohIM4kbBJfa+rYMBTuYbRtN1IiAV8vXMBZML5ZOF6WnfxcoUvolY9WSId2n CID6vKUg==; 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 1qjHQK-00BToS-Ml; Thu, 21 Sep 2023 11:00:45 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id D77C53002F1; Thu, 21 Sep 2023 13:00:42 +0200 (CEST) Message-Id: <20230921105247.507327749@noisy.programming.kicks-ass.net> User-Agent: quilt/0.65 Date: Thu, 21 Sep 2023 12:45:06 +0200 From: peterz@infradead.org 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 v3 01/15] futex: Clarify FUTEX2 flags References: <20230921104505.717750284@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Disposition: inline; filename=peterz-futex2-flags-1.patch X-Rspamd-Queue-Id: 231424003B X-Rspam-User: X-Stat-Signature: aoodqgznzofbi1mjgmihqrm4ji8aq9dc X-Rspamd-Server: rspam03 X-HE-Tag: 1695294057-277361 X-HE-Meta: U2FsdGVkX1+BKIVTS88kLRxTVYON5ooUeD+PkeNKGwTuTla5UvBqJYpnEnnIk53RiQTv9GJAezRJJdxoA/pdQ/Bjd4NsDy51XESLJGlbdSr6DEHhwalk37ivfq/IT39CqDjc8yoFfuEKO+UDoJjVmbkKazxoHuuiZZoIc8MS5/yhcEmlzK5f9SMRz7uJKlocYUKAMz0wfXwyI2FEOMh9Oq3Xaq2GhiglvR9Y+SV5+7vErLeQw+jsU+fDTcPF83ubrAq4iRxS+VoP3AsQ9qZGcktW7b6CmKdEblX5vROArpXPcla9+VVUdl25dO0R77T/lyFSs1LiQ2VhnYTfR2QWHW5Nep7YLeEz1Yg5Dy3aJv3NKK+KaijdV/BdIWxNbt8FYb9pdJfU+8joHMmbXTtTglQ5eZl8S7fQgGrd65PiIbToqmr9J/2CmX4/w5Y/u3veVnn/v6YFkWMGmGhS7GRDsGz5PROnp/T2dEMI1Qf4YnVwPV2CDpXfl0cJ7/d0B1h/iQLJ8/UfcIbhv+fNV4EWxVgxzwZgAnHPDVCP2g8S9iqTCZY+h3Rp/QdJmIaAX+9EvrCJMNfgGeuSdccqzeU8hPB4S1wUP2ZLnolmRBXcQKznK2JhsdOeK9r2LdW37qHJ/F2pmzo0z2D3MCk1j7YkqQrmPBgy7PMymBjXdIqNqSaP/9JfI2XuXKuFGWhiDxX+CAJt/THtAagCz4anJ4NFcByHjFx66dSTbI/9fG1udCTtf+ft8WavCRHGZNTDb9oWIc8918p4DF14gE0A0YpiXfK+jnjYa6cNER41H4PpgbF76XS40E+0tRezDPiXu94tS0t8BW2AXHZVXDNpmuNWJ1H39tplvWEKevaN/dFiLu+lMxrle43A6Rh3OadrSVhNfdrjMa5P+/nPGz5KPo1uro/BtPIFAv10YMmdMP4JHp+rdil3naeUimPBjqNhVFBq1SXZ9JDjw2CAPKUCnJ7 q9ZTp3Xy uS1Hoo5yWUEVoixIDp6OtcZwPqoNhaRSYCcqbjBEjF1lusGQRSGDJnjhnsh6Dn6QmofW/c8RZ2Pd99F/l0D7OC0phVAHOe5tXJJNJVUnSK2ClZFeMPPrNFKpBk6L1lnDlyMsP4DhOkIFSLFT0DPbPa10L6mVH5VsvI784a73MiPpjInKStr5WjC6Uj2HiNedi9MRXaFCwDZ/ykYBWT5sWcggExJJIYY1jJmHpemZrRQUcKcu7jk9sKh5dBenZYu6j7nZXplSvZgLTF7WMSy2xszaDok5jQrEKe89gO6H65KEz8oE25jChDrMXwuhh+hYRO1frKB0+RYhMn0yDPNsxqZW19Q== 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 Reviewed-by: André Almeida --- 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_SIZE_U32 0x02 + /* 0x04 */ + /* 0x08 */ + /* 0x10 */ + /* 0x20 */ + /* 0x40 */ +#define FUTEX2_PRIVATE FUTEX_PRIVATE_FLAG + +/* do not use */ +#define FUTEX_32 FUTEX2_SIZE_U32 /* 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_VALID_MASK (FUTEX2_SIZE_U32 | 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_VALID_MASK) || aux.__reserved) return -EINVAL; - if (!(aux.flags & FUTEX_32)) + if (!(aux.flags & FUTEX2_SIZE_U32)) return -EINVAL; futexv[i].w.flags = aux.flags; From patchwork Thu Sep 21 10:45:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13393846 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 D1370E70718 for ; Thu, 21 Sep 2023 11:01:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 514F96B01FE; Thu, 21 Sep 2023 07:01:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 47DEF6B0203; Thu, 21 Sep 2023 07:01:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0F73B6B01B1; Thu, 21 Sep 2023 07:01:00 -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 D82436B01FE for ; Thu, 21 Sep 2023 07:00:59 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B3C201608C8 for ; Thu, 21 Sep 2023 11:00:59 +0000 (UTC) X-FDA: 81260312238.28.0D16F8A Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf11.hostedemail.com (Postfix) with ESMTP id EE84540004 for ; Thu, 21 Sep 2023 11:00:57 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=p5NRryUx; dmarc=none; 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695294058; 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=Leni2jABpH8gFx8eoWrGxi74yq+TZFYWjTk4xa5IXKs=; b=HZHZlqnbr9mebGi3Z8SI3bpFClTjy6lUR4DTgdnE0Z4x64jzhR7jbbPt4yJk7ATuilGOVy TZ9Z1uMr8y63o0irfk3m6WqNEXYcO2EkW7CkQDfh4c3vC1NarhVFYghU0atA6J3CsU9sv/ OOViIY4gYxVhF8q7dBsZQIAHkH0k+Xo= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=p5NRryUx; dmarc=none; 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695294058; a=rsa-sha256; cv=none; b=Ep/pFlx9+oU4EwnpkQcyVV83na3qCIuV3TSUtmRHUws3okCMKqwLni/ebVbd9OCMDq3zWP FdR9gWZGSKubUQ2JG7RF2mZ1NlcHaxi6F2cH/dPYW5Iu2+fScz6Jasb4lMORWtKibFU3HG DblgtxOxq6eE7YNAwnwFKrretCHNZQk= 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=Leni2jABpH8gFx8eoWrGxi74yq+TZFYWjTk4xa5IXKs=; b=p5NRryUxf/3ipjwh/+cFipr1tl Q0Eo1yrSCNeHQMxsgC1bVKRP9Tch3H1OKovd6RvaA+/24jMJpIzOmIjnA5asCBpapCTOO9s4c8zdB 0fpQXbtk3xm+spvtebHvCBwwEVso+UsVeLZYG14WZaThXCEwK7DIC1D6F+dEBJzl5OtLLJn2KgPyj SQBTWuSMfTPK6DOl6KeDYyoV6Id5gQZQ3I4ttIBzMWJUBOuBPzCiILjfj3cK2tlC+tNlbKV79rTqa 04lE917lCOEvORfQUZoFPA3YkCvHjkIcbY2+RgsD793YrtbrPlesBVvOkEZ1n1LPQNtRIxYrowm2E E1AOpBgA==; 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 1qjHQJ-00FJvi-0r; Thu, 21 Sep 2023 11:00:45 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id DB846300348; Thu, 21 Sep 2023 13:00:42 +0200 (CEST) Message-Id: <20230921105247.617057368@noisy.programming.kicks-ass.net> User-Agent: quilt/0.65 Date: Thu, 21 Sep 2023 12:45:07 +0200 From: peterz@infradead.org 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 v3 02/15] futex: Extend the FUTEX2 flags References: <20230921104505.717750284@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Disposition: inline; filename=peterz-futex2-flags-2.patch X-Rspamd-Queue-Id: EE84540004 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: puf1y876uon6wsj11n6oi1ub9i49x1pa X-HE-Tag: 1695294057-208799 X-HE-Meta: U2FsdGVkX19ftIMWK7Am/CJo+gR9U9tWe56ZdeuLGbzIinZnK2uuPEMdvJR60vPkol4qfWfAg0pS0PAJK21PKUxGXSZrO/mPfj5vbMrRDqRCGtuBt/a+gnhnyHT9nXfbnz/Zwwqy5YJ7XDLBVNR0pPAqs9fsmREB5xICPSlSB6QE2ousRBgmibVvG5DP4fbsHoMEh7rwh5cNbP43AF2Ol+WkqzSxb0PxEAH40X3x53S/kdLPNdMce3VAS/A/PQJS+q7XsRtnkkj6uPJ6wcq2AWS6VTxDFqgRfvq+7PJILEmfWVA/b1w7RJ2mnEw3KU+WnhUqYyr2DuzS/Qq2VhYP8UxXbbp+ZcJTLMUwBCgUgO1LSMpOcpcg7FRrw4C3Faz4qdb2ZpRJAsfrQDRF/jc9Amb5WsUy1z0nNGBJdKvgav14c6dACr7gWiaLOj9qewImyGivMy56MxaILnCUOuZApipCT/yf4vMQbGLHPmX2BZErXlBmqlGzmYCOKpciD9HpnwbN/V6xgqUqVvBORDi3ZBMexzTlmALVkeqk5FAct1Nto/i6L09rxKkYRWOvaJZ964oeTMkAASWkDPOaUtyfyTAo3Gh+2T5kgt7hA0bIUq7vBznGGvTVren1w7XSVrY5JBBgnGpaNLLTyU/K4Os2rcF5N8pxvEKyeuZyd0EOWBE3WWVPYwDeznP3ywZTU+dtiN7V4bsSbCGAGOoxuVAJ1ps12g1R8iNgtWXi4J1RtQxeEadTCbiPS6Jyv3b3txJ6JdjuBA+EtssH6k98OyVn0gS0eM9Fy5Eo/YCuQnjLctNaVfL9WCiYouRExB80oQlnGWovFBN/A7SP6+TsclWUDIvrkVAf4NWSUWsl/OKeQyjzBCl5xN8R0lnBzsaKaWIUj8h0pGsgq6WvPMTKpFTPGXcFuPOnKmt5Y1hMY23dDvIc1gPCoqx/+Zx8RXdh83T/lCHpODCsLQEAutdZDSt dTvNF+ZB MW4/EL8FmkfwcLwg9uYw6Djq9ZVsXWMFQSTXqQreoIKTo25A6kvEg8CQdrW7dx+ffD+luEqgWbw5RCEMZGDZUiZlj7hgwS455TGhPHM6n1D3RmPL0y0fEOjjmb1zG0+R7C8JVh6WcYojbUtcu4rgvVwBvvhtivPKcibX4MFs3/S/vkOJKhYqUneO46H4WZr4YkJGULEc6lBjckgMa9sTFqADOGmNUVdafMHHi1XLCNm9GPGBIeTTK5lrgJjjYqNa1F3fIbgWdY8zGVZyXF7kbZnGpJB0rnhhQQUC2wAcshrYs8JQ= 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) Reviewed-by: Thomas Gleixner Reviewed-by: André Almeida --- include/uapi/linux/futex.h | 21 ++++++++++++++++++--- kernel/futex/syscalls.c | 9 +++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) Index: linux-2.6/include/uapi/linux/futex.h =================================================================== --- linux-2.6.orig/include/uapi/linux/futex.h +++ linux-2.6/include/uapi/linux/futex.h @@ -45,17 +45,32 @@ /* * Flags for futex2 syscalls. + * + * NOTE: these are not pure flags, they can also be seen as: + * + * union { + * u32 flags; + * struct { + * u32 size : 2, + * numa : 1, + * : 4, + * private : 1; + * }; + * }; */ - /* 0x00 */ - /* 0x01 */ +#define FUTEX2_SIZE_U8 0x00 +#define FUTEX2_SIZE_U16 0x01 #define FUTEX2_SIZE_U32 0x02 - /* 0x04 */ +#define FUTEX2_SIZE_U64 0x03 +#define FUTEX2_NUMA 0x04 /* 0x08 */ /* 0x10 */ /* 0x20 */ /* 0x40 */ #define FUTEX2_PRIVATE FUTEX_PRIVATE_FLAG +#define FUTEX2_SIZE_MASK 0x03 + /* do not use */ #define FUTEX_32 FUTEX2_SIZE_U32 /* historical accident :-( */ Index: linux-2.6/kernel/futex/syscalls.c =================================================================== --- linux-2.6.orig/kernel/futex/syscalls.c +++ linux-2.6/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_VALID_MASK (FUTEX2_SIZE_U32 | FUTEX2_PRIVATE) +#define FUTEX2_VALID_MASK (FUTEX2_SIZE_MASK | 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_VALID_MASK) || aux.__reserved) return -EINVAL; - if (!(aux.flags & FUTEX2_SIZE_U32)) + if (!IS_ENABLED(CONFIG_64BIT) || in_compat_syscall()) { + if ((aux.flags & FUTEX2_SIZE_MASK) == FUTEX2_SIZE_U64) + return -EINVAL; + } + + if ((aux.flags & FUTEX2_SIZE_MASK) != FUTEX2_SIZE_U32) return -EINVAL; futexv[i].w.flags = aux.flags; From patchwork Thu Sep 21 10:45:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13393843 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 213F6E70714 for ; Thu, 21 Sep 2023 11:01:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 760DA6B0192; Thu, 21 Sep 2023 07:00:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7105D6B01A3; Thu, 21 Sep 2023 07:00:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5D70A6B01B1; Thu, 21 Sep 2023 07:00:59 -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 5092D6B0192 for ; Thu, 21 Sep 2023 07:00:59 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 05F051206FF for ; Thu, 21 Sep 2023 11:00:59 +0000 (UTC) X-FDA: 81260312238.12.17BF478 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf12.hostedemail.com (Postfix) with ESMTP id AF2814000C for ; Thu, 21 Sep 2023 11:00:56 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=MOTQE29V; dmarc=none; spf=none (imf12.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=1695294057; 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=fDLLIPxKgNNe6msDk3qSgIHXipfMYUECpW3VaKsBI+k=; b=iiiQXfDe2EFGbOemBfTds0cmnexcORPStRxYvKLkFIet8p2+EtLkELQxrCVgaKSGRm0rrU uzydSx5PZfSGXCJrpU08H/HhU5qVtumpbljnxHx3BGkinPpdD3R3ft6P6wBCMRv9Q2haIR LDwBptViWV2Nt/uN3OipQExmyXQ8gGo= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=MOTQE29V; dmarc=none; spf=none (imf12.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=1695294057; a=rsa-sha256; cv=none; b=iSa0veNu/IjiJWNM2nNE9RAU779M3ahuUKDSm60OoobSkCIp2+YE2NLXRT379KPUSLL3PF 7InDNZyRMeSlErf1Gvw2+WPBjXxrlwUvQiEZT1Oze5hZa9fPZ/9NplzSy4PekJRA2An7Pv eCFrZJa8n5YVktJj//HZi6wqRXin+08= 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=fDLLIPxKgNNe6msDk3qSgIHXipfMYUECpW3VaKsBI+k=; b=MOTQE29VqiTUi9P8xb2Y0PQrWR hJm1eIWIc3J2IkSm2yqpM0YckzGGETZBMhQo0n50cFRfEa7m0EGaaeIJ1BMKkM2+AZO/oGzyLR9xd WLa8/Tl53o6MTMGW+Ig5qTg0Y2qJ1dmcs6jmF7BsUJFqljcmHb5UuvlfPyk3QOOi6BBOaAh0UzeYv Z9BPbW0N+X/iLTJwwSFNocF4PEBu5CrI5oQYI6jr67VGsGDGqAeWVOTIgqxY944M94QGAM0foMnX2 kgzdMsQw2cta7lYUo1GinfKGD4W5c6KcAP6sXzfYl857YZTZ1KnUPtJMfAok5Y9E+59M2i6h7TjDo 0RSAcu4Q==; 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 1qjHQK-00BToT-Mn; Thu, 21 Sep 2023 11:00:45 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id DF69D30036C; Thu, 21 Sep 2023 13:00:42 +0200 (CEST) Message-Id: <20230921105247.722140574@noisy.programming.kicks-ass.net> User-Agent: quilt/0.65 Date: Thu, 21 Sep 2023 12:45:08 +0200 From: peterz@infradead.org 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 v3 03/15] futex: Flag conversion References: <20230921104505.717750284@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Disposition: inline; filename=peterz-futex2-flags.patch X-Rspamd-Queue-Id: AF2814000C X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: buacgeantk55inr67aqttsjq3p7y1ibg X-HE-Tag: 1695294056-61980 X-HE-Meta: U2FsdGVkX1/YpRrzs+nRjIOBFMVFi3ZIkMd/m5p9VGg4yJJbFo8YOBxLdifw2X8ZY+ZotvXI3HvvQY7MG28K7bp9ozU9a0TZLT/xHwXSXH+ZI8Sn8PzEhTqcVwAd53yeAzhb9OXEApvU1HnQ8ken9noPcdvAhIWnZvEMzHTBe6HANe8c1PZ7qmHaHhuorGLX9SFIGbfR7UXyMTjBEbdKORkyuo5dwZHZTr71epm8ZHnhGgt0+MPuq+bNEzL/2ZWDv6Phz3X1neUzgrhCo91McnbJw82QdedkuLm9Y+Cg7LQn8G1X+tsCgHRAWukU0bSsDVb2RGCOV5Snn3SgFeVq3yskn7jVd4XIQkBhU0TVHlxxb7IADWSO9RHDDgL8hoNckoXmnEPeovlMjMtC7gPCbeKHuaQ6QC+UoNE/5ebcxqlpPvHqeKQPqlRDArfnPfff1oIYm7rSh6M5cw11m7Cor3rCbS+G+5LA21vnwGfuIs44IdB9GrUwLigWNDGq8FWX/1FNitX8ui9WCEwHDkd1DYq+MXYM7hwSONAQNBUA+Pq5JY1p9K+jV9cf31RNyq6G+lvfnuWzZcaf84m9CWJgcLy8wMWXJjASofmxwzZfUvFelj+LdsTkuxCf8takzIhch5+TqLxHu/6BF8WbEG+xRjgxi0xoRD594V67A9gI1tqrGVCOUDrUREcodk5FA6pgsgxOsGCUX1nGfv8tsKqQbypGLprqkJW+U+UZuu/uFArqntXMVrf2mwDdz1RBfO7Ep6oUzLsjP34ceW9V9XXq4fv7JEmOV2WHGg2los3GkWf+QJdRS9nF7Jq73fxgagJpm95IH+HyWPnlvpTNXewbNldpra2F4VYeNyCXYLDl0+mJvIaweQdHSQlhsjNJ/hV6K2qV5wddl/iAVcSofjj73v5scmxg6G2H4KajlKo3g28H9sD45vVRMDpADN5EfAYdRs3yItyay9WKQ0ESQY3 TCcTVrza JXzWxes6vYwlO5CZMbA7ccI/4PkbAENam2SkoDVILvU91okVng097bZC+fb2k8Ry8ELVv9P9pzpNevz2CD6CmfWU5hgE9h2LjWJKWVIwnHJQNyzM7r3oYU1mSQp0SyrbhfTc1MuthKqfKp1ZBUJ9Y1YFf6xACJdv/wzb7QDFcBpNWZSF+cfABKdg7BnqUUCMCX0Ck53CDYnTVLOWnsputDrNNXTmfvqWu9q4LmAchb6XC+SI5OS7GJYdKuoAXdHcj5v4bDcD35cVdprtA7Hj2QDeGa4wo4a2bsGI3zKIlIsqO79qrV62EvWGkVvFL5PjD52afN/n5vbzxLEScrq987QuHqw== 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) Reviewed-by: Thomas Gleixner Reviewed-by: André Almeida --- kernel/futex/futex.h | 63 +++++++++++++++++++++++++++++++++++++++++++++--- kernel/futex/syscalls.c | 24 ++++++------------ kernel/futex/waitwake.c | 4 +-- 3 files changed, 71 insertions(+), 20 deletions(-) Index: linux-2.6/kernel/futex/futex.h =================================================================== --- linux-2.6.orig/kernel/futex/futex.h +++ linux-2.6/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,57 @@ */ # 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_SIZE_MASK; + + if (!(flags2 & FUTEX2_PRIVATE)) + flags |= FLAGS_SHARED; + + if (flags2 & FUTEX2_NUMA) + flags |= FLAGS_NUMA; + + return flags; +} + +static inline unsigned int futex_size(unsigned int flags) +{ + return 1 << (flags & FLAGS_SIZE_MASK); +} + +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; +} #ifdef CONFIG_FAIL_FUTEX extern bool should_fail_futex(bool fshared); Index: linux-2.6/kernel/futex/syscalls.c =================================================================== --- linux-2.6.orig/kernel/futex/syscalls.c +++ linux-2.6/kernel/futex/syscalls.c @@ -1,6 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-or-later -#include #include #include @@ -85,15 +84,12 @@ err_unlock: 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_VALID_MASK) || aux.__reserved) return -EINVAL; - if (!IS_ENABLED(CONFIG_64BIT) || in_compat_syscall()) { - if ((aux.flags & FUTEX2_SIZE_MASK) == FUTEX2_SIZE_U64) - return -EINVAL; - } - - if ((aux.flags & FUTEX2_SIZE_MASK) != FUTEX2_SIZE_U32) + 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; Index: linux-2.6/kernel/futex/waitwake.c =================================================================== --- linux-2.6.orig/kernel/futex/waitwake.c +++ linux-2.6/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 Thu Sep 21 10:45:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13393851 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 1DBC1E70718 for ; Thu, 21 Sep 2023 11:01:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 62D026B0203; Thu, 21 Sep 2023 07:01:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 49F216B0204; Thu, 21 Sep 2023 07:01:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 366E86B0205; Thu, 21 Sep 2023 07:01:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 219F96B0203 for ; Thu, 21 Sep 2023 07:01:01 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id DE6EA141061 for ; Thu, 21 Sep 2023 11:00:59 +0000 (UTC) X-FDA: 81260312238.18.DA13662 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf01.hostedemail.com (Postfix) with ESMTP id 034824002F for ; Thu, 21 Sep 2023 11:00:57 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=MFTg6cMl; dmarc=none; spf=none (imf01.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=1695294058; 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=yq6smcRh9Lt9PMXVlulhUee9kIX8B6TjEGtSPSAL3jI=; b=ND6LLZFmE47fiNY+N40AOkCmwqfcdLZCwFbR/zxce2cU8jqEi6qPvAyjuZ+ewOUOQugx7c DPQ9H3IL5F4YNysV4s1606BA1ZTmAw1uK10jL37VbEb2R4jTeXDuffESp0neVBmwu0y463 rSD1RiVhFf+Evxy7iGx4uRB3BL5r3dI= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=MFTg6cMl; dmarc=none; spf=none (imf01.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=1695294058; a=rsa-sha256; cv=none; b=MRgwmzS9CjHWv5HnfY3GzrtkFK2q9e/8AN12zx+1Xofm8Vo2fsQTBkF5shbsLJ4F/Z9hYP m9Fcf666G7qi+Ebv+hthXQZyIP0Wz/JUTRPhYyRQEK44xC+7JkTnpGKnXELzqpIm/eg0X4 teujLsGgtmxV20VA4j8QNUxgFqzcaKA= 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=yq6smcRh9Lt9PMXVlulhUee9kIX8B6TjEGtSPSAL3jI=; b=MFTg6cMl019oUQu6rDJgts+aeg 6Z+T8mLRp+uO7oQYQZw8Sm7/bPEVJfCOG+aED2yludqPec99o8HNyZPS/UwxNUu5ybxaL1HEhSQAn dbGtduFHWOeo64tStINJ7gZdIll94CL1nBUWrJCIh7duiDqXpGEwJDGf9UmYQHjclLEG2htYks1j2 k3TT1ZVJmPhNPbii9Vmr15VGN96F+S0BqQB8o5Be51SKNksVDbNp+cdAzrwSIkN9YnEHdQHtiZs0o FsdMmqM6DHVtTYVFoqyyPUjpMHPB4elIcHz6Lly3U5MtaUc3UieSMAgJP1uokBuXVd99H5hXDY8TC QnNwNEBg==; 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 1qjHQJ-00FJvh-0q; Thu, 21 Sep 2023 11:00:45 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id E37B2300513; Thu, 21 Sep 2023 13:00:42 +0200 (CEST) Message-Id: <20230921105247.828934099@noisy.programming.kicks-ass.net> User-Agent: quilt/0.65 Date: Thu, 21 Sep 2023 12:45:09 +0200 From: peterz@infradead.org 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 v3 04/15] futex: Validate futex value against futex size References: <20230921104505.717750284@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Disposition: inline; filename=peterz-futex2-enforce-bits.patch X-Rspamd-Queue-Id: 034824002F X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: mp7ayq867sj4q448fa3ncr7mg9etrkcb X-HE-Tag: 1695294057-337940 X-HE-Meta: U2FsdGVkX19mX0rDRIjGjzVOlUNS+4vJUxYufsV/UYZp13uLHo46eA8mSnjxYsZ3HuoUL4fT53JLRt5HJkw1daG1hAVCHASeVkuADxgIt8IAkot4fuHpJIoUUH5/4O2o4wIma4MW4oUrPs+B/ZAz9smDay34nYAU+H+kLVtW3UbNCZ9+EcaD6gj3zZkbuNbN++n6XnsKbHahBk4dWYLwq7OiTv7W4Th1j+y365lZTJ4VCGpwqEbx94EFpW8PyymLmXkSIol73QmNzh2rdmeaQY5GNNAAVDy+VBjaWJ6jgPKCFHoLG6h2pGvwtkimUzH6UkwGm6g8y16Qn4Nhdi+1WvQHpBMcubVE+ePn6kXymqQn68s8DCCKt+zJZuWpkHO8hHtSge4lw3P5bk68PMceMNit8tXM2p9wwMp/Pui20tPH/GLvVCO6MTbmLe7uN5eWnhPgjS9fO1OPyvuVi26nAGqIbCh4xV9sQx1AmxKzgj89ceOXl7LYpbGMWnN+sSMa5R3YUmRsJKMCeV8Y14ByD0e6DlvKdaBOYQ+HNZc3mTGDe7nCAMKNN4KbmXcFOnLL/EGx/h4bQ4/fffaGh1wtej9ZI+I+EQJGJM2jXZw3WJtrXKmbFRq2lrI039uxFeL/ioeMcLd4GX76Wf3JkjlkBYLs5zG298+6iTqqzn+3XENQ8B55ez1G+0GJaTYC012UaGFCRB+uvMYWDDpXMvcBfwWqVT8V+CzgVnF4E98kuZqOHugdiZ9O2W3/xozSqfiiWuhacV4T4Fw5RntTlObUXUTew85P/yLDjdJbfe3I8XzMNRCcE5VP5hFwnt/z8qm9/xBzYfYn/HjIF2Nr6gGJ8EhSiE+BtHwB+335+IHE1RekgE1zeVWZky+4CMBs8Hr0u18tgOG3sV+g0l9IBmFH9IGADcGRObBHuLu4tOVkezZWWpYEyvQqIHQyn26VD7c0vieF2etrmTbFyk/yuFk SkNC3BNK p+eBlycYHuMi3gTdwuAVtpjKGPHHNMgr4hstw4jqN8BTKUaBcYJwzacYTd+DpERBl/FV+dT0gF3qtWJp/yDcR4PVRtXkejbrSIUGDD/M5QqJlK5DSAVXRXriibG+dQY2O/O+5uTQEOtL/ljNE5ku3VsFurINxwr/nDiOjSTTgRwTo6x/rGbwpTZFUmLtNkiP/GR7Jn9TUwZuuTO8C7067c+YHyG+tHAWVoLfLeGVN9N06oDA= 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 | 10 ++++++++++ kernel/futex/syscalls.c | 3 +++ 2 files changed, 13 insertions(+) Index: linux-2.6/kernel/futex/futex.h =================================================================== --- linux-2.6.orig/kernel/futex/futex.h +++ linux-2.6/kernel/futex/futex.h @@ -85,6 +85,16 @@ static inline bool futex_flags_valid(uns return true; } +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 Index: linux-2.6/kernel/futex/syscalls.c =================================================================== --- linux-2.6.orig/kernel/futex/syscalls.c +++ linux-2.6/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 Thu Sep 21 10:45:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13393863 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 280F3E7071E for ; Thu, 21 Sep 2023 11:20:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B18ED6B01B1; Thu, 21 Sep 2023 07:20:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AC8C86B01F9; Thu, 21 Sep 2023 07:20:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9DED36B01FE; Thu, 21 Sep 2023 07:20:37 -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 8FC4D6B01B1 for ; Thu, 21 Sep 2023 07:20:37 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6954941052 for ; Thu, 21 Sep 2023 11:20:37 +0000 (UTC) X-FDA: 81260361714.30.A729B44 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf01.hostedemail.com (Postfix) with ESMTP id 3981E40014 for ; Thu, 21 Sep 2023 11:20:33 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=XtAFaLhm; spf=none (imf01.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=1695295235; 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=2DTgjumfpm1XkZ715bEL5OW+Lzt/Am5TA3vJOTBLXZU=; b=qbxRujyA05uCLiDj+86E/YUEr7M5mt69Ery+yP1wiSehsN41/5Jn6y5PAKl8tZa26kkQB5 CgHAmX0UpW13aGZvZqaH4yE0ycQSW8U4jYfLWcZykwEDs1ud7xoJX7tTdTf1b4vRCIHr8k ylAj8duL40OwnDt+2YIwhX5pVJKaDqU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695295235; a=rsa-sha256; cv=none; b=4MgU8UFTMoEV0VMJOVXC6KfZVgLF2HgPrh0i/+GI0KzxCAQNz6dkvvpT/8w9sF7qc+AQfX Rrn4GGQ6ZJnMq7Nr15J3b22aM0rcVs9TFpH1U6Q8ZjKI59HEpyEJ7J/sIqEZlm3nilI/iK DD3tbT5FIQXYeJXSBtdOHkxQQszMl5s= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=XtAFaLhm; spf=none (imf01.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=2DTgjumfpm1XkZ715bEL5OW+Lzt/Am5TA3vJOTBLXZU=; b=XtAFaLhmRfTSIAepdy7Z15s9Wy b1BqY+tCKhG7iyZKLYYRNBZJwy94StzYUTqTRb4lHlI1R2dX7EN+UPkoJULC5vToF96NtZbh7DJNr pTY0V1ZnfaiE7UbbbZJByPuN2HXlor7S6wiQ/LCk7IplNknLy93ZOB92k8zpLDFoFIiUeIsaRFSe0 +XpYMy8qnNT2sPEYPDdBo65fv2TLQ/McFO5r8jj1XGaBf5mkd6OJSbAm2arUAPFUaGHhGx0kK0UNg //TgiNaI26sQrDaKAHt9H9bCJt3yGOC9sNcWBcNm0DUfZlETWKVXDYWK3X05N72GmLWsjWXc9s9d4 Cfr8LB7Q==; 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 1qjHQO-00BTok-R7; Thu, 21 Sep 2023 11:00:48 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id E749B300585; Thu, 21 Sep 2023 13:00:42 +0200 (CEST) Message-Id: <20230921105247.936205525@noisy.programming.kicks-ass.net> User-Agent: quilt/0.65 Date: Thu, 21 Sep 2023 12:45:10 +0200 From: peterz@infradead.org To: tglx@linutronix.de, axboe@kernel.dk Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, dvhart@infradead.org, dave@stgolabs.net, andrealmeid@igalia.com, Andrew Morton , urezki@gmail.com, hch@infradead.org, lstoakes@gmail.com, Arnd Bergmann , linux-api@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, malteskarupke@web.de, Geert Uytterhoeven Subject: [PATCH v3 05/15] futex: Add sys_futex_wake() References: <20230921104505.717750284@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Disposition: inline; filename=peterz-futex2-wake.patch X-Stat-Signature: u14bt9dzyhk57a8kqds1bjcrqryhrw3d X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 3981E40014 X-Rspam-User: X-HE-Tag: 1695295233-497215 X-HE-Meta: U2FsdGVkX18mOnhvMkDej5GaK+9kKsbNvieFtAS0usqZNejwpTTkkoGlBJvIpD52gLGzBgSjwWt+Ons370/WfyuO1MRIOjuRhTT9eeKUxJ3aHDsprgFPkAqiKBZpIUf+YrU74dR5hDVnQLgAPYMoLCFKNisH7w/6IWjW782KSfc3/VGb8fPkLI5Wq6UW65vTRrB2wZa0YVFmfZHnPQeaTMnGczsGbnCF26pOtFs8t2fMHIyWR4qxaqN+vzui0Cyq+qobVUyCQwjl3crIr4BUFfHO1yFxeldT2Ybue32nHExLmBUdC655G5MUrQZeAIF81l0BD6TYrqnpyn1i6nSYlf7BfKSexvldd/wfZkwsGGtaoWp2zhD5o3Y0OCGGrjOwvOt2hJ836g3RAtaO2ZTQkWmXbFiybeeY5rt0D46Qqm8ckKe4pCNfRFUzngy39SOyXUQW0MRq6JRPediqIpA7vQEhWwA2EnCJrY0gC96PzCdpxYGZK8EQ6mNPI4jF/kuswVgQl723+0aoZ8fmSJRo4XYboQZSEV90KAIsaf88TznTwekJkELb6nIJO5Cd3KWDUORbqxpEIJp+lIT6x1vv62qj62A+6b2fi59H9CTrYDCLMt2bFb1fgh+iez84rg08p56RYFXxcjwZYkYrZUyt6yiwuySx/FJiuUYAHmukATv9n3ETvgeusUt/kkKBxE4ms1B4Hns9mxrLrQWvNyWCwUChq2PBtEeQoYjQj2F0mVGMM20PQorEUabG+oFZD/+wzLvzw1eRfpmbnsHVyhv5as8lkyz1FFaX1RLk1iqGM6GppPXGJdXGqa9Fnz4n9Pqj4rqI9ig8hJOaAK/jrflsgjMpgBBAExq53Hr/JrrWDI2JmhN2fCxTyl9zfmgr6snCPwZxmfH7cAGpus+wWTdKrpBJQ2CvBse8SLOIQqVccSKhXgPTWnXjFDsfjzgTa5TKYev6ygwMsuDhIdWf17n oBsb2Fkz ad8y5y+Ko/AcvCi6HP0zUYQDJjQ7VA8KTiVVWIUIp7cyst7Z5nj76o9iGSNVLjMJiWTNN9Zll4n88IqlPfdBKraGxuId/3/TO72f7ssz/5flTRMm+Vt4epN/e6g3JbjlCr4PRVfNoVaGglteeC6H1ElIXQMin0hcNN4700p+Nyv4NZih4PFZOw+cYTlafYVw7cf3uy+tqTNS/CgXqx1e8KaO9Vh7P8r/+zPVkhREHqRSBih49mxifvS8U6ShZMIFau8ZdY2BSYXNcXyBaeLT+YvGuCp/qg8oh84vV1DSbjj/M+Wk70Us4gEyoqPdlwsXzJ9Ico7iazpbVEehvQieJRxM0wA== 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_SIZE_U64 on 64bit platforms. Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Thomas Gleixner Acked-by: Geert Uytterhoeven --- arch/alpha/kernel/syscalls/syscall.tbl | 1 arch/arm/tools/syscall.tbl | 1 arch/arm64/include/asm/unistd.h | 2 - arch/arm64/include/asm/unistd32.h | 2 + arch/ia64/kernel/syscalls/syscall.tbl | 1 arch/m68k/kernel/syscalls/syscall.tbl | 1 arch/microblaze/kernel/syscalls/syscall.tbl | 1 arch/mips/kernel/syscalls/syscall_n32.tbl | 1 arch/mips/kernel/syscalls/syscall_n64.tbl | 1 arch/mips/kernel/syscalls/syscall_o32.tbl | 1 arch/parisc/kernel/syscalls/syscall.tbl | 1 arch/powerpc/kernel/syscalls/syscall.tbl | 1 arch/s390/kernel/syscalls/syscall.tbl | 1 arch/sh/kernel/syscalls/syscall.tbl | 1 arch/sparc/kernel/syscalls/syscall.tbl | 1 arch/x86/entry/syscalls/syscall_32.tbl | 1 arch/x86/entry/syscalls/syscall_64.tbl | 1 arch/xtensa/kernel/syscalls/syscall.tbl | 1 include/linux/syscalls.h | 3 ++ include/uapi/asm-generic/unistd.h | 5 ++-- kernel/futex/syscalls.c | 33 ++++++++++++++++++++++++++++ kernel/sys_ni.c | 1 22 files changed, 59 insertions(+), 3 deletions(-) Index: linux-2.6/arch/alpha/kernel/syscalls/syscall.tbl =================================================================== --- linux-2.6.orig/arch/alpha/kernel/syscalls/syscall.tbl +++ linux-2.6/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 fchmodat2 sys_fchmodat2 +563 common futex_wake sys_futex_wake Index: linux-2.6/arch/arm/tools/syscall.tbl =================================================================== --- linux-2.6.orig/arch/arm/tools/syscall.tbl +++ linux-2.6/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 fchmodat2 sys_fchmodat2 +454 common futex_wake sys_futex_wake Index: linux-2.6/arch/arm64/include/asm/unistd.h =================================================================== --- linux-2.6.orig/arch/arm64/include/asm/unistd.h +++ linux-2.6/arch/arm64/include/asm/unistd.h @@ -39,7 +39,7 @@ #define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE + 5) #define __ARM_NR_COMPAT_END (__ARM_NR_COMPAT_BASE + 0x800) -#define __NR_compat_syscalls 453 +#define __NR_compat_syscalls 455 #endif #define __ARCH_WANT_SYS_CLONE Index: linux-2.6/arch/arm64/include/asm/unistd32.h =================================================================== --- linux-2.6.orig/arch/arm64/include/asm/unistd32.h +++ linux-2.6/arch/arm64/include/asm/unistd32.h @@ -911,6 +911,8 @@ __SYSCALL(__NR_set_mempolicy_home_node, __SYSCALL(__NR_cachestat, sys_cachestat) #define __NR_fchmodat2 452 __SYSCALL(__NR_fchmodat2, sys_fchmodat2) +#define __NR_futex_wake 454 +__SYSCALL(__NR_futex_wake, sys_futex_wake) /* * Please add new compat syscalls above this comment and update Index: linux-2.6/arch/ia64/kernel/syscalls/syscall.tbl =================================================================== --- linux-2.6.orig/arch/ia64/kernel/syscalls/syscall.tbl +++ linux-2.6/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 fchmodat2 sys_fchmodat2 +454 common futex_wake sys_futex_wake Index: linux-2.6/arch/m68k/kernel/syscalls/syscall.tbl =================================================================== --- linux-2.6.orig/arch/m68k/kernel/syscalls/syscall.tbl +++ linux-2.6/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 fchmodat2 sys_fchmodat2 +454 common futex_wake sys_futex_wake Index: linux-2.6/arch/microblaze/kernel/syscalls/syscall.tbl =================================================================== --- linux-2.6.orig/arch/microblaze/kernel/syscalls/syscall.tbl +++ linux-2.6/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 fchmodat2 sys_fchmodat2 +454 common futex_wake sys_futex_wake Index: linux-2.6/arch/mips/kernel/syscalls/syscall_n32.tbl =================================================================== --- linux-2.6.orig/arch/mips/kernel/syscalls/syscall_n32.tbl +++ linux-2.6/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 fchmodat2 sys_fchmodat2 +454 n32 futex_wake sys_futex_wake Index: linux-2.6/arch/mips/kernel/syscalls/syscall_n64.tbl =================================================================== --- linux-2.6.orig/arch/mips/kernel/syscalls/syscall_n64.tbl +++ linux-2.6/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 fchmodat2 sys_fchmodat2 +454 n64 futex_wake sys_futex_wake Index: linux-2.6/arch/mips/kernel/syscalls/syscall_o32.tbl =================================================================== --- linux-2.6.orig/arch/mips/kernel/syscalls/syscall_o32.tbl +++ linux-2.6/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 fchmodat2 sys_fchmodat2 +454 o32 futex_wake sys_futex_wake Index: linux-2.6/arch/parisc/kernel/syscalls/syscall.tbl =================================================================== --- linux-2.6.orig/arch/parisc/kernel/syscalls/syscall.tbl +++ linux-2.6/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 fchmodat2 sys_fchmodat2 +454 common futex_wake sys_futex_wake Index: linux-2.6/arch/powerpc/kernel/syscalls/syscall.tbl =================================================================== --- linux-2.6.orig/arch/powerpc/kernel/syscalls/syscall.tbl +++ linux-2.6/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 fchmodat2 sys_fchmodat2 +454 common futex_wake sys_futex_wake Index: linux-2.6/arch/s390/kernel/syscalls/syscall.tbl =================================================================== --- linux-2.6.orig/arch/s390/kernel/syscalls/syscall.tbl +++ linux-2.6/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 fchmodat2 sys_fchmodat2 sys_fchmodat2 +454 common futex_wake sys_futex_wake sys_futex_wake Index: linux-2.6/arch/sh/kernel/syscalls/syscall.tbl =================================================================== --- linux-2.6.orig/arch/sh/kernel/syscalls/syscall.tbl +++ linux-2.6/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 fchmodat2 sys_fchmodat2 +454 common futex_wake sys_futex_wake Index: linux-2.6/arch/sparc/kernel/syscalls/syscall.tbl =================================================================== --- linux-2.6.orig/arch/sparc/kernel/syscalls/syscall.tbl +++ linux-2.6/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 fchmodat2 sys_fchmodat2 +454 common futex_wake sys_futex_wake Index: linux-2.6/arch/x86/entry/syscalls/syscall_32.tbl =================================================================== --- linux-2.6.orig/arch/x86/entry/syscalls/syscall_32.tbl +++ linux-2.6/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 fchmodat2 sys_fchmodat2 +454 i386 futex_wake sys_futex_wake Index: linux-2.6/arch/x86/entry/syscalls/syscall_64.tbl =================================================================== --- linux-2.6.orig/arch/x86/entry/syscalls/syscall_64.tbl +++ linux-2.6/arch/x86/entry/syscalls/syscall_64.tbl @@ -375,6 +375,7 @@ 451 common cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 453 64 map_shadow_stack sys_map_shadow_stack +454 common futex_wake sys_futex_wake # # Due to a historical design error, certain syscalls are numbered differently Index: linux-2.6/arch/xtensa/kernel/syscalls/syscall.tbl =================================================================== --- linux-2.6.orig/arch/xtensa/kernel/syscalls/syscall.tbl +++ linux-2.6/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 fchmodat2 sys_fchmodat2 +454 common futex_wake sys_futex_wake Index: linux-2.6/include/linux/syscalls.h =================================================================== --- linux-2.6.orig/include/linux/syscalls.h +++ linux-2.6/include/linux/syscalls.h @@ -549,6 +549,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, Index: linux-2.6/include/uapi/asm-generic/unistd.h =================================================================== --- linux-2.6.orig/include/uapi/asm-generic/unistd.h +++ linux-2.6/include/uapi/asm-generic/unistd.h @@ -822,9 +822,11 @@ __SYSCALL(__NR_cachestat, sys_cachestat) #define __NR_fchmodat2 452 __SYSCALL(__NR_fchmodat2, sys_fchmodat2) +#define __NR_futex_wake 454 +__SYSCALL(__NR_futex_wake, sys_futex_wake) #undef __NR_syscalls -#define __NR_syscalls 453 +#define __NR_syscalls 455 /* * 32 bit systems traditionally used different Index: linux-2.6/kernel/futex/syscalls.c =================================================================== --- linux-2.6.orig/kernel/futex/syscalls.c +++ linux-2.6/kernel/futex/syscalls.c @@ -306,6 +306,36 @@ destroy_timer: return ret; } +/* + * sys_futex_wake - Wake a number of futexes + * @uaddr: Address of the futex(es) to wake + * @mask: bitmask + * @nr: Number of the futexes to wake + * @flags: FUTEX2 flags + * + * Identical to the traditional FUTEX_WAKE_BITSET op, except it is part of the + * futex2 family of calls. + */ + +SYSCALL_DEFINE4(futex_wake, + void __user *, uaddr, + unsigned long, mask, + int, nr, + unsigned int, flags) +{ + if (flags & ~FUTEX2_VALID_MASK) + return -EINVAL; + + flags = futex2_to_flags(flags); + if (!futex_flags_valid(flags)) + return -EINVAL; + + if (!futex_validate_input(flags, mask)) + return -EINVAL; + + return futex_wake(uaddr, flags, nr, mask); +} + #ifdef CONFIG_COMPAT COMPAT_SYSCALL_DEFINE2(set_robust_list, struct compat_robust_list_head __user *, head, Index: linux-2.6/kernel/sys_ni.c =================================================================== --- linux-2.6.orig/kernel/sys_ni.c +++ linux-2.6/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 Thu Sep 21 10:45:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13393848 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 0226FE70718 for ; Thu, 21 Sep 2023 11:01:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A74396B01F9; Thu, 21 Sep 2023 07:01:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 849F76B01FF; Thu, 21 Sep 2023 07:01:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4EFF06B01B1; Thu, 21 Sep 2023 07:01:00 -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 211D26B01FF for ; Thu, 21 Sep 2023 07:01:00 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C48F41CADFA for ; Thu, 21 Sep 2023 11:00:59 +0000 (UTC) X-FDA: 81260312238.30.682A7F0 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf30.hostedemail.com (Postfix) with ESMTP id 4398A8003B for ; Thu, 21 Sep 2023 11:00:55 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=J3l9ojEs; spf=none (imf30.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=1695294056; 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=qZGXn0GjyOVEXezGJP51+kNBqwjTUdfIFaStjMYeBB0=; b=oYs6gHNxHgpXPSgq5hMmbz9k3pXaa3dJEBlYmTR2Ct1zlC5dMB4HGvSXF1dQhTmJ89yJJ7 gH2QIxF9k9+6orMDUma8zFS55jYRlOiaECgt4GKWopFo7jZjHZs5MSuQtXURkIqXERWdk+ 31UvuyuzE1pRtZX30ygmm+AMKSotdkk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695294056; a=rsa-sha256; cv=none; b=rY2KyAmc328+yrdSXodBUCWA4WHc64fdNznWrjZANFN7h1lPvuKhSlZElzfHG72GCx1DAE ebN9SB807xx+NQ0KrB3FNxzRYW1Yp9iR8H+hbNJwOziWLCPVzgwx3PGP+j6LJ8U2KsMl0D W8o841GIb30ESszTuKn5wJ7q1jU9ycc= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=J3l9ojEs; spf=none (imf30.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=qZGXn0GjyOVEXezGJP51+kNBqwjTUdfIFaStjMYeBB0=; b=J3l9ojEsbOGfPBtXP86sKEB8XD wbzSG4aPsf/4A5xghKK1aLECSnRsMOcpoiSnvd63aq9cUDsSIAj/CsSrKK09Hyk2kkvMgZfSQv7yH 7+qwuJMzgaS+VquY+Dk2C3nMddqvpeV0y/d+DUOy9f/1nYZc+BjX4LHbGCpWaG6O7dSib80z+sUbC XS1mZOT+TL4TFhx49AGJI5Bjf9VsLws4Ut1lv7OwVlt+aL1rUSMPKbGuSP6pS8Aj3Ot20JEMTVKa4 dfY4jjvCONrlqr6VrOFn17LlGeWlaVA0UV2Zp+ga08hbyJd+ITfLggX4wfh4/LCL/CqQ+3j6VXt5K A5s9FrlA==; 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 1qjHQN-00FJvs-1M; Thu, 21 Sep 2023 11:00:49 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id ED74230058C; Thu, 21 Sep 2023 13:00:42 +0200 (CEST) Message-Id: <20230921105248.048643656@noisy.programming.kicks-ass.net> User-Agent: quilt/0.65 Date: Thu, 21 Sep 2023 12:45:11 +0200 From: peterz@infradead.org 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 v3 06/15] futex: FLAGS_STRICT References: <20230921104505.717750284@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Disposition: inline; filename=peterz-futex2-wake-0.patch X-Stat-Signature: nrtihqg3gz9k41epeo3bwx9oosrcabie X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 4398A8003B X-Rspam-User: X-HE-Tag: 1695294055-448986 X-HE-Meta: U2FsdGVkX19HLySZ44cRHcCEIwXdA+3NOs5GTdOELFPr2nuRtxmpoNQ2CjY7Kr4j5ooVc9jqEk7ZXtbjXynFP29OtGfYoa61YfwzsJ3mGEPzKSBUVxvDQf+WmaE4z9pbU07r5s6nSutyJPj4/h/F9yijPvgLkCn49aLWCrci1gH4tRbF14+VnhG44t9PVBsz6HTEV+9l6jNdPKhJRBmngHZ7j51E9TTQ3almLvao+hgD0tZo9SPnkIriZfSych6p+kkcnP0101dt5ADsZgce+kQkMGH7OH0RMdMtuVemzNnLu1N7wvey0O+Dyxuy3kUI7DEwh6ZR6AXPcPjC/KmpTP0NQncqGvwT78wsu+ST4qqtPyvkZswBhcaCf25A+LbNHyJgt9owe6V26CxOTdU8QrRRZKRYHqSD3O7b4CJXgPA4shoolw0+LtgrTEPOBQDTfJ+pmjkXBotoxuapCa5KqeLlYrgaN0xtzdJPSXEqprhrkYgdJTNa/wUcju7B9LYTm+sM5a9XncIBjr9HSu1p/dA/5QJWtirUJdCC2cJNfDwsCEcfZqQNU+uLX2aXF2NAcx+Fd2+2dMDJ6QzSDSGO2R2RG/KXGMfZVEY/6OVjoO/XBYfTE8F4NJG6v/XD9Yee9Isoq5V/E+q+/vihmdfBTfO0z/PxW+ExLbzYeDRzRKXs4FdI1Iio+MARdMMURCDsyhXWdPWKZ0kw3bXD7m0vVqhVmYnZHZSQzOj2Dvzx3xiMdD5eSkqK34UZ6aGCaxlniANd8THEo/xt1TY9r4Grg/vtdmOwdsVv53EBIOgN5WqcOZnaEqd1ZjzG0ncrsGhdWQiUNhbeSv8XB/Ik4ejr/2vbyCpHAGd3+o/XsdGAHDK5C1cxvpAlCNKYwNX3kPNZqz8WOhoBqtjSxi6u2xZs5aPFhjK2d70bG0WysY+/ttjTGZX0sNC+NynFP9EZtLrkKhJ82oNbrTo1Zr+SWl2 zNKHCgqz TwtrJu3QtrzV/S6aRwRHk/sx0+3tCnf/82bCzHCmoioTRQfTcpthBNa1hzPvmZGDG+PJlWrWuxfJkRVGMfMUDbUN7wFEn34zBwvdQPCw06Z7JK7v0Sr9gQ5KmYbJf+WAjjHJUZLEBbbYSi2OY/T8LSDWG53gsfJOdY2ups5h47/ToTHR2BPgJo7C9HkaU9DpeV8fonIe3EKMi4uWEOBbeU+T83Y8QjxFJDvKnrOBa6kaIbyuoLRDn7+qdfhjNXCrUpCr1ofm8FKQyOISk3KO2OJlNzvpYenlz+Xz12caaqYE+gIq3lkTHHBUQjzFvLSyPkrucRuPG7mUr6Ab62Zs8pTKP83pr7Si5nBiIoUcGv1JPGM6k/X604o8vMtLgQ9scALH+ 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: The current semantics for futex_wake() are a bit loose, specifically asking for 0 futexes to be woken actually gets you 1. Adding a !nr check to sys_futex_wake() makes that it would return 0 for unaligned futex words, because that check comes in the shared futex_wake() function. Adding the !nr check there, would affect the legacy sys_futex() semantics. Hence frob a flag :-( Suggested-by: André Almeida Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Thomas Gleixner Index: linux-2.6/kernel/futex/futex.h =================================================================== --- linux-2.6.orig/kernel/futex/futex.h +++ linux-2.6/kernel/futex/futex.h @@ -17,25 +17,26 @@ * 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_8 0x0000 +#define FLAGS_SIZE_16 0x0001 +#define FLAGS_SIZE_32 0x0002 +#define FLAGS_SIZE_64 0x0003 -#define FLAGS_SIZE_MASK 0x03 +#define FLAGS_SIZE_MASK 0x0003 #ifdef CONFIG_MMU -# define FLAGS_SHARED 0x10 +# define FLAGS_SHARED 0x0010 #else /* * NOMMU does not have per process address space. Let the compiler optimize * code away. */ -# define FLAGS_SHARED 0x00 +# define FLAGS_SHARED 0x0000 #endif -#define FLAGS_CLOCKRT 0x20 -#define FLAGS_HAS_TIMEOUT 0x40 -#define FLAGS_NUMA 0x80 +#define FLAGS_CLOCKRT 0x0020 +#define FLAGS_HAS_TIMEOUT 0x0040 +#define FLAGS_NUMA 0x0080 +#define FLAGS_STRICT 0x0100 /* FUTEX_ to FLAGS_ */ static inline unsigned int futex_to_flags(unsigned int op) Index: linux-2.6/kernel/futex/syscalls.c =================================================================== --- linux-2.6.orig/kernel/futex/syscalls.c +++ linux-2.6/kernel/futex/syscalls.c @@ -333,7 +333,7 @@ SYSCALL_DEFINE4(futex_wake, if (!futex_validate_input(flags, mask)) return -EINVAL; - return futex_wake(uaddr, flags, nr, mask); + return futex_wake(uaddr, FLAGS_STRICT | flags, nr, mask); } #ifdef CONFIG_COMPAT Index: linux-2.6/kernel/futex/waitwake.c =================================================================== --- linux-2.6.orig/kernel/futex/waitwake.c +++ linux-2.6/kernel/futex/waitwake.c @@ -155,6 +155,9 @@ int futex_wake(u32 __user *uaddr, unsign if (unlikely(ret != 0)) return ret; + if ((flags & FLAGS_STRICT) && !nr_wake) + return 0; + hb = futex_hash(&key); /* Make sure we really have tasks to wakeup */ From patchwork Thu Sep 21 10:45:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13393852 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 54D81E70714 for ; Thu, 21 Sep 2023 11:01:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A216C6B0207; Thu, 21 Sep 2023 07:01:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9CFC56B0208; Thu, 21 Sep 2023 07:01:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7FBB86B0209; Thu, 21 Sep 2023 07:01:01 -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 560F16B0205 for ; Thu, 21 Sep 2023 07:01:01 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 15088141063 for ; Thu, 21 Sep 2023 11:01:00 +0000 (UTC) X-FDA: 81260312280.15.647959A Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf28.hostedemail.com (Postfix) with ESMTP id D68DEC0024 for ; Thu, 21 Sep 2023 11:00:56 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="Fo6P3/Mv"; 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=1695294057; 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=xsbwJJWQRl6v4i26c9uvT221icEnXzjXoYJDfVyH/TQ=; b=6M8QHZb5cZECgY2ZEPprAOBKHuwY67g/3Mho2NBn11tGE7gwZ/isqadh/AGfut2JIAh6WY 93gqEZz1E0KHABiIy5SR6hGHSIC66fUBOR/KPlv5J6IC7MiaI7se5HRMKRIJfZGL6bLSLL UsCkMrd+Nc+im3GtgOV7DQ5J7tABREc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695294057; a=rsa-sha256; cv=none; b=TNZ/RgCCfDsx/OPlRdt5Etyfm6f7F31cTV5OVrVViKKrCSm97oLJ2al+lFNww/AyGHjm0x WhrIjuSjlP559j8r5DsPnqW4DgMT3rA85DWsEqvjq1uS3FVHNmInOt8L37UQ0OdOtmw9SH oX7QMwPE2xwUIxdYldgmKaAcOhLMqMw= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="Fo6P3/Mv"; 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=xsbwJJWQRl6v4i26c9uvT221icEnXzjXoYJDfVyH/TQ=; b=Fo6P3/MvFvvR8pAfvb8nlrxdCk OnjgXIeagZ73bqEbOHv6sBpNm7aVbhIlfhvEUXSLSnY4lqUuTO+9u/I5QWw63Es2TmQoz5JwiWcz1 h5ceHTW6+tvyHmyl4oVHIM0R8pNJcJBfb/qeMYFMRCTx7WpeGf63PPlwkbUsmMJoWVCW7l+ri2x8v IK4+6rqRjm1NZGD/5ohORG+LiwpYxohmX1WOQkLzfuVBgizIDskFfDVqId6iY9Ue30gXrbnYxrbDJ vaUy+33vOL82TVWcuPuhVg8P8d1Aq2vITDIv3t2f7gpt0Z+r5aQJA5k2P68okHqmFMYru4zQXSqoj 76ytotLw==; 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 1qjHQO-00BTol-Tz; Thu, 21 Sep 2023 11:00:49 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 015323005AA; Thu, 21 Sep 2023 13:00:42 +0200 (CEST) Message-Id: <20230921105248.164324363@noisy.programming.kicks-ass.net> User-Agent: quilt/0.65 Date: Thu, 21 Sep 2023 12:45:12 +0200 From: peterz@infradead.org To: tglx@linutronix.de, axboe@kernel.dk Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, dvhart@infradead.org, dave@stgolabs.net, andrealmeid@igalia.com, Andrew Morton , urezki@gmail.com, hch@infradead.org, lstoakes@gmail.com, Arnd Bergmann , linux-api@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, malteskarupke@web.de, Geert Uytterhoeven Subject: [PATCH v3 07/15] futex: Add sys_futex_wait() References: <20230921104505.717750284@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Disposition: inline; filename=peterz-futex2-wait.patch X-Stat-Signature: qbizrae4jgi8h91s7yrzdcwjwaygud4q X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: D68DEC0024 X-Rspam-User: X-HE-Tag: 1695294056-485233 X-HE-Meta: U2FsdGVkX1+sTtv0K6pgH9znvfen28wH9ueJANlAG9Efrw0I4shO+nPhFFTqDwUGtm8Vc4mz1KP7SreqQ5ZOb5qj1p4qicWghbS5gDKfvVwqxrZSqVtfB330nkKB7XE6TOgH67/PuUBHO16t1ePfkYZ9P1rqdcpYwpdYcWRIGYjnzKV0ooumotT9/OOj6F/EFfOeuQS9urFgf6zKK+POIRqrgGDNe+hfuAx8PhUCJPZWik8VrsvUdj4YhIKGaVbv6JqStqKvX6LvEzFiAIWkaGNEwrT9Z1mfX3EOWzdzdVoL7IJLx+gblxlRunfs37CQ6SBWTmfZEhaTgz7nCFR96PayGYeSWALY5I2cvSfwDdR16DCPU2LSeFfxFu2Bo3Rqx6ymjkvaSp61FV/bV3iOh2mkgNBFRm5sG8WI2vK0ah8YRoc7qhI8CdjHJD5kKGXKQsmzR3+Fz7wV+L2G8NQawubBruKM3r/4EjHG5Re570qkySsW4ck5rJIcYXjzuul8ISqaW0R13mk4IURf7iVqNUlS9CopbauGo4Ky9c9rEUXvqkGpCquAvWBmcVlmVxpnIynXpAFdzYEcidAfSZsDRJuDfxwo0runtG4dVwOVYAX9ggKjUXg6II7FldYyn9cNpzWN1OGEW6TUHlbCMvli7hb5bZI2lSkI8+ABTRqGOgFVvpGiD+PqMK4ZJjiBslHK3a+EZzmLvfwnhp8wGcyry//5rKUKgQIbWWE6m596SCvO4vqIwzb4hlv39cKuRlRKket7I07dRyPvg5fcn8O2q4XFNxLWrt2wStja4niAr/zgqn079FvShJ7OhPtbWvnFKaKWJirpt8TmcAMRgvinGNF7c/fqM8+V1/LwGVhO6LH++wTVlqxSuuWrOXPuvhVcENILANaKmw3zf+E0bjT4fLbR+uAO8SaHkyYdAz/EiXNTThkO9itTNtyqa9ZW/5K3IiNwyhMdOfOOJjWzat0 ImG0g4rQ Nw8wYJNVAj5l0DcMiuq9ZiRA0dmjtsD40Q8tDuSIz2S/oi8fvwvjCWka0EI6N/GJWK0t6mPjMi4xlguiGLKGAldbLbIDEM5n+9UIoxNnW5l5JFz6afiSF93xPXJqLczamXuh6yJRW2L91/YP7Awxo37Lapj9XxLPU4MbUcinHTcj0U0I1WH6JSDIYLHbglmJiz68p+p2hhy21R+6ZRKy2aGs7uDWWJ5SM9yEwu6yFsFs00vUag/huHTvkxQBO7ibbHXOZkFRFGgmFSHyxafTtYtUqsP9I7wVlWtxbPncenCLKEQgsn02+MjzreeX5UMshPQjLtbeXeMrhILPNkfZ+nRuoGg== 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_SIZE_U64 on 64bit platforms. Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Thomas Gleixner Acked-by: Geert Uytterhoeven --- arch/alpha/kernel/syscalls/syscall.tbl | 1 arch/arm/tools/syscall.tbl | 1 arch/arm64/include/asm/unistd.h | 2 arch/arm64/include/asm/unistd32.h | 2 arch/ia64/kernel/syscalls/syscall.tbl | 1 arch/m68k/kernel/syscalls/syscall.tbl | 1 arch/microblaze/kernel/syscalls/syscall.tbl | 1 arch/mips/kernel/syscalls/syscall_n32.tbl | 1 arch/mips/kernel/syscalls/syscall_n64.tbl | 1 arch/mips/kernel/syscalls/syscall_o32.tbl | 1 arch/parisc/kernel/syscalls/syscall.tbl | 1 arch/powerpc/kernel/syscalls/syscall.tbl | 1 arch/s390/kernel/syscalls/syscall.tbl | 1 arch/sh/kernel/syscalls/syscall.tbl | 1 arch/sparc/kernel/syscalls/syscall.tbl | 1 arch/x86/entry/syscalls/syscall_32.tbl | 1 arch/x86/entry/syscalls/syscall_64.tbl | 1 arch/xtensa/kernel/syscalls/syscall.tbl | 1 include/linux/syscalls.h | 4 include/uapi/asm-generic/unistd.h | 4 kernel/futex/futex.h | 3 kernel/futex/syscalls.c | 120 +++++++++++++++++++++------- kernel/futex/waitwake.c | 67 +++++++++------ kernel/sys_ni.c | 1 24 files changed, 159 insertions(+), 60 deletions(-) Index: linux-2.6/arch/alpha/kernel/syscalls/syscall.tbl =================================================================== --- linux-2.6.orig/arch/alpha/kernel/syscalls/syscall.tbl +++ linux-2.6/arch/alpha/kernel/syscalls/syscall.tbl @@ -493,3 +493,4 @@ 561 common cachestat sys_cachestat 562 common fchmodat2 sys_fchmodat2 563 common futex_wake sys_futex_wake +564 common futex_wait sys_futex_wait Index: linux-2.6/arch/arm/tools/syscall.tbl =================================================================== --- linux-2.6.orig/arch/arm/tools/syscall.tbl +++ linux-2.6/arch/arm/tools/syscall.tbl @@ -467,3 +467,4 @@ 451 common cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 454 common futex_wake sys_futex_wake +455 common futex_wait sys_futex_wait Index: linux-2.6/arch/arm64/include/asm/unistd.h =================================================================== --- linux-2.6.orig/arch/arm64/include/asm/unistd.h +++ linux-2.6/arch/arm64/include/asm/unistd.h @@ -39,7 +39,7 @@ #define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE + 5) #define __ARM_NR_COMPAT_END (__ARM_NR_COMPAT_BASE + 0x800) -#define __NR_compat_syscalls 455 +#define __NR_compat_syscalls 456 #endif #define __ARCH_WANT_SYS_CLONE Index: linux-2.6/arch/arm64/include/asm/unistd32.h =================================================================== --- linux-2.6.orig/arch/arm64/include/asm/unistd32.h +++ linux-2.6/arch/arm64/include/asm/unistd32.h @@ -913,6 +913,8 @@ __SYSCALL(__NR_cachestat, sys_cachestat) __SYSCALL(__NR_fchmodat2, sys_fchmodat2) #define __NR_futex_wake 454 __SYSCALL(__NR_futex_wake, sys_futex_wake) +#define __NR_futex_wait 455 +__SYSCALL(__NR_futex_wait, sys_futex_wait) /* * Please add new compat syscalls above this comment and update Index: linux-2.6/arch/ia64/kernel/syscalls/syscall.tbl =================================================================== --- linux-2.6.orig/arch/ia64/kernel/syscalls/syscall.tbl +++ linux-2.6/arch/ia64/kernel/syscalls/syscall.tbl @@ -374,3 +374,4 @@ 451 common cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 454 common futex_wake sys_futex_wake +455 common futex_wait sys_futex_wait Index: linux-2.6/arch/m68k/kernel/syscalls/syscall.tbl =================================================================== --- linux-2.6.orig/arch/m68k/kernel/syscalls/syscall.tbl +++ linux-2.6/arch/m68k/kernel/syscalls/syscall.tbl @@ -453,3 +453,4 @@ 451 common cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 454 common futex_wake sys_futex_wake +455 common futex_wait sys_futex_wait Index: linux-2.6/arch/microblaze/kernel/syscalls/syscall.tbl =================================================================== --- linux-2.6.orig/arch/microblaze/kernel/syscalls/syscall.tbl +++ linux-2.6/arch/microblaze/kernel/syscalls/syscall.tbl @@ -459,3 +459,4 @@ 451 common cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 454 common futex_wake sys_futex_wake +455 common futex_wait sys_futex_wait Index: linux-2.6/arch/mips/kernel/syscalls/syscall_n32.tbl =================================================================== --- linux-2.6.orig/arch/mips/kernel/syscalls/syscall_n32.tbl +++ linux-2.6/arch/mips/kernel/syscalls/syscall_n32.tbl @@ -392,3 +392,4 @@ 451 n32 cachestat sys_cachestat 452 n32 fchmodat2 sys_fchmodat2 454 n32 futex_wake sys_futex_wake +455 n32 futex_wait sys_futex_wait Index: linux-2.6/arch/mips/kernel/syscalls/syscall_n64.tbl =================================================================== --- linux-2.6.orig/arch/mips/kernel/syscalls/syscall_n64.tbl +++ linux-2.6/arch/mips/kernel/syscalls/syscall_n64.tbl @@ -368,3 +368,4 @@ 451 n64 cachestat sys_cachestat 452 n64 fchmodat2 sys_fchmodat2 454 n64 futex_wake sys_futex_wake +455 n64 futex_wait sys_futex_wait Index: linux-2.6/arch/mips/kernel/syscalls/syscall_o32.tbl =================================================================== --- linux-2.6.orig/arch/mips/kernel/syscalls/syscall_o32.tbl +++ linux-2.6/arch/mips/kernel/syscalls/syscall_o32.tbl @@ -441,3 +441,4 @@ 451 o32 cachestat sys_cachestat 452 o32 fchmodat2 sys_fchmodat2 454 o32 futex_wake sys_futex_wake +455 o32 futex_wait sys_futex_wait Index: linux-2.6/arch/parisc/kernel/syscalls/syscall.tbl =================================================================== --- linux-2.6.orig/arch/parisc/kernel/syscalls/syscall.tbl +++ linux-2.6/arch/parisc/kernel/syscalls/syscall.tbl @@ -452,3 +452,4 @@ 451 common cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 454 common futex_wake sys_futex_wake +455 common futex_wait sys_futex_wait Index: linux-2.6/arch/powerpc/kernel/syscalls/syscall.tbl =================================================================== --- linux-2.6.orig/arch/powerpc/kernel/syscalls/syscall.tbl +++ linux-2.6/arch/powerpc/kernel/syscalls/syscall.tbl @@ -540,3 +540,4 @@ 451 common cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 454 common futex_wake sys_futex_wake +455 common futex_wait sys_futex_wait Index: linux-2.6/arch/s390/kernel/syscalls/syscall.tbl =================================================================== --- linux-2.6.orig/arch/s390/kernel/syscalls/syscall.tbl +++ linux-2.6/arch/s390/kernel/syscalls/syscall.tbl @@ -456,3 +456,4 @@ 451 common cachestat sys_cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 sys_fchmodat2 454 common futex_wake sys_futex_wake sys_futex_wake +455 common futex_wait sys_futex_wait sys_futex_wait Index: linux-2.6/arch/sh/kernel/syscalls/syscall.tbl =================================================================== --- linux-2.6.orig/arch/sh/kernel/syscalls/syscall.tbl +++ linux-2.6/arch/sh/kernel/syscalls/syscall.tbl @@ -456,3 +456,4 @@ 451 common cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 454 common futex_wake sys_futex_wake +455 common futex_wait sys_futex_wait Index: linux-2.6/arch/sparc/kernel/syscalls/syscall.tbl =================================================================== --- linux-2.6.orig/arch/sparc/kernel/syscalls/syscall.tbl +++ linux-2.6/arch/sparc/kernel/syscalls/syscall.tbl @@ -499,3 +499,4 @@ 451 common cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 454 common futex_wake sys_futex_wake +455 common futex_wait sys_futex_wait Index: linux-2.6/arch/x86/entry/syscalls/syscall_32.tbl =================================================================== --- linux-2.6.orig/arch/x86/entry/syscalls/syscall_32.tbl +++ linux-2.6/arch/x86/entry/syscalls/syscall_32.tbl @@ -458,3 +458,4 @@ 451 i386 cachestat sys_cachestat 452 i386 fchmodat2 sys_fchmodat2 454 i386 futex_wake sys_futex_wake +455 i386 futex_wait sys_futex_wait Index: linux-2.6/arch/x86/entry/syscalls/syscall_64.tbl =================================================================== --- linux-2.6.orig/arch/x86/entry/syscalls/syscall_64.tbl +++ linux-2.6/arch/x86/entry/syscalls/syscall_64.tbl @@ -376,6 +376,7 @@ 452 common fchmodat2 sys_fchmodat2 453 64 map_shadow_stack sys_map_shadow_stack 454 common futex_wake sys_futex_wake +455 common futex_wait sys_futex_wait # # Due to a historical design error, certain syscalls are numbered differently Index: linux-2.6/arch/xtensa/kernel/syscalls/syscall.tbl =================================================================== --- linux-2.6.orig/arch/xtensa/kernel/syscalls/syscall.tbl +++ linux-2.6/arch/xtensa/kernel/syscalls/syscall.tbl @@ -424,3 +424,4 @@ 451 common cachestat sys_cachestat 452 common fchmodat2 sys_fchmodat2 454 common futex_wake sys_futex_wake +455 common futex_wait sys_futex_wait Index: linux-2.6/include/linux/syscalls.h =================================================================== --- linux-2.6.orig/include/linux/syscalls.h +++ linux-2.6/include/linux/syscalls.h @@ -552,6 +552,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, Index: linux-2.6/include/uapi/asm-generic/unistd.h =================================================================== --- linux-2.6.orig/include/uapi/asm-generic/unistd.h +++ linux-2.6/include/uapi/asm-generic/unistd.h @@ -824,9 +824,11 @@ __SYSCALL(__NR_cachestat, sys_cachestat) __SYSCALL(__NR_fchmodat2, sys_fchmodat2) #define __NR_futex_wake 454 __SYSCALL(__NR_futex_wake, sys_futex_wake) +#define __NR_futex_wait 455 +__SYSCALL(__NR_futex_wait, sys_futex_wait) #undef __NR_syscalls -#define __NR_syscalls 455 +#define __NR_syscalls 456 /* * 32 bit systems traditionally used different Index: linux-2.6/kernel/futex/futex.h =================================================================== --- linux-2.6.orig/kernel/futex/futex.h +++ linux-2.6/kernel/futex/futex.h @@ -332,6 +332,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); Index: linux-2.6/kernel/futex/syscalls.c =================================================================== --- linux-2.6.orig/kernel/futex/syscalls.c +++ linux-2.6/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_STRICT | 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_VALID_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, Index: linux-2.6/kernel/futex/waitwake.c =================================================================== --- linux-2.6.orig/kernel/futex/waitwake.c +++ linux-2.6/kernel/futex/waitwake.c @@ -632,20 +632,18 @@ retry_private: 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 @@ -653,18 +651,17 @@ retry: */ 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 @@ -673,24 +670,38 @@ retry: 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); + + /* No timeout, nothing to clean up. */ + 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; } Index: linux-2.6/kernel/sys_ni.c =================================================================== --- linux-2.6.orig/kernel/sys_ni.c +++ linux-2.6/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 Thu Sep 21 10:45:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13393864 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 8267FE7071F for ; Thu, 21 Sep 2023 11:28:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DB9636B01B1; Thu, 21 Sep 2023 07:28:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D67156B01F9; Thu, 21 Sep 2023 07:28:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C7CFB6B01FE; Thu, 21 Sep 2023 07:28:58 -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 B71476B01B1 for ; Thu, 21 Sep 2023 07:28:58 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 8A4B7140DF4 for ; Thu, 21 Sep 2023 11:28:58 +0000 (UTC) X-FDA: 81260382756.05.8E880CB Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf19.hostedemail.com (Postfix) with ESMTP id CE7E51A0027 for ; Thu, 21 Sep 2023 11:28:56 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=D2+0fnUy; spf=none (imf19.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=1695295736; 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=UZPFE2ZScTicMie2LbY/rLHSb/ea3l5YRQ8Geimizx8=; b=Vn7DuF+Y12HTlLUUHaY38S84YA2ud8RaU1D76hYt+5OftfO7Fnl4S1Pl9c+FVy1SikA/wG IcMD88w3lR9mQltUVHXGOwFZdn/M8yu7G+4efEfwHzoDVYmrAlMQxcilSR0sd9+qGYJ5jQ jz8uNFkyFIUlBD8fv4VTRlI7e8m5tk0= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=D2+0fnUy; spf=none (imf19.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=1695295736; a=rsa-sha256; cv=none; b=ouGJvCzVJpZdMVnyz2j/KL4m+ZuamDGRu0qMlVwTVbcWQgWHhGVHqtL4DhmIauyL89/LCk 9cHKSPky2AaydFpRZYTF2/9LVOQb/C/CMGbfhVbQN4Yoso+FmS8QTjMIB5Vh78G2WqFddg R812GmM4e+76jVdyxVduRRwHDn1u0PE= 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=UZPFE2ZScTicMie2LbY/rLHSb/ea3l5YRQ8Geimizx8=; b=D2+0fnUyypGBp3tmehpApHtBuE RnJo83xqyajrpKhjalpbKvZ+nGASRjTehHdoMNEhFFbTcsMZXNEJLm5K1AwRxz7Hx/fTASdxtRhBO zohke4ebc70ACqv8Bs7aQndNOXz9ac9ZANpPzFBrOQ+RyKLLvLq/F29cabLPlXJbmlNe4x7U3YzAj CxhoAB6qRbKq148GeIUfQzuoCLGewVVsVQtiU45YMCM4+B7uyU9yU2RrlLxkSF/Fj0+YTFgao96V8 1zSsgA3Ssz8jktwFUDjRfiOf68jkKJufk5rw+2mIG7SIRiJkGC5VD+RKhcC+J5orR8ZLAEtgTlYUz zhFFmjAQ==; 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 1qjHQN-00FJvt-1M; Thu, 21 Sep 2023 11:00:49 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 058B53005B2; Thu, 21 Sep 2023 13:00:43 +0200 (CEST) Message-Id: <20230921105248.282857501@noisy.programming.kicks-ass.net> User-Agent: quilt/0.65 Date: Thu, 21 Sep 2023 12:45:13 +0200 From: peterz@infradead.org 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 v3 08/15] futex: Propagate flags into get_futex_key() References: <20230921104505.717750284@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Disposition: inline; filename=peterz-futex2-get_futex_key-flags.patch X-Rspamd-Queue-Id: CE7E51A0027 X-Rspam-User: X-Stat-Signature: 879r4roqoioasty9q1oko6fo7t9zo8hg X-Rspamd-Server: rspam01 X-HE-Tag: 1695295736-897283 X-HE-Meta: U2FsdGVkX19ggH8I27pdd7ru9LcVs6AJ44IGQMlCCo6ZoKG1BWna2Rhj57ahqbeGaEOUUc1yViWylDCrJ2JWCLia/w4kvdhkN6KrbxK0HZXiSuvDx6BEDR6EOlt2wHCSbP6zrW0vaKyMP1G4BpcQlGKTKc1HP8hx+qoQjFw7/ZBll6zeTPRs77RrLIfqLY6p5f+N1AhxfxW1e5j4habg6CN9fOdH0/Dk12lQRa7JL+HNuI/i28hSgEWsFjKmyI7NeoQOL0ap1JT303hSEuza17hTJZkQc+23gzhi1w4D5604jEaPuBvf7ixo2FBLE7wphHKP9LfY4b5Vv/0GdAOm7+Mzk2ehdttYEFWenU1C/BnJNLPTt+YEDdQioCFM7YJEs3F75m2mkEA5h/QHrd6Hq0RhcFTeZBF1S/G2i9ceoZdxQe4P24x9mPimJ4IeT3PJb9v3XOuE1n0MYJF5/BfmYrPqPDidw8XeBJJh0DEfdi5nkflVqORrR4/w0amyT1EkhQ08DwuiRo6SzR3OI5DTzAIV0d9JORKhNzcsstM4oL12cQQzsZ3IlO6JS9GHTpgwDiIjKJg2NG5tFCXz2sCvyyGQj/+Q1K8fwKCfvcZbHvkaO9xbLom3sxhiRo8ovKMGMlp7S4DcUB46mMTDrzShZtwXGEkuyH54LaGZgqw7GUwuoTfJHHuPbc+x+CCOeLZlZBTDg1eqoz9nT7001QrVn9u7G/sG3uDJN8UBX654Ktyw9CxOJvxxxnn4uJF7i79H3+cOpccMbIhzgTkt0nkbnT9hXhkm+qaXJVjnU694XN54Mctu9N+wllVe3bSWmplfdfE2lJPuBJ5s/uxP+lfImeoDRI5xsdX8wsgc3p0HBVGlnKX4agKlD2KIPkAzkbPHVXMLhnTnb0LN2t+L9EICulxC78qdYw8hW6iyxQkZ5/tvV6j4GrGFkveyWrtheNvXn8CwhJOQdQHSgxxPJ+V c/jbscyH Grw9mS/gWZ+P2AgkY3Ph+CzcqKi3nJAVGivAFOegecMgaMM7xmpixS1/5MZVom6POsRfl5IDcUgeh+R3P3jUYfjdEz9JTmrxELPpRFDT7hqBQGj7fEU0TTq8mbEQfeBRZ2fOG7ucBrOBROmAhszaKFgUYhz8vEYrUZNmjxFrKMsb/EJ54KXqQbTEVqQP6Z5QeHjdyyLi70h54BfgoQOCadZmQXCvLmbromQzGfSERtT83Ef4Vydquk/zwuA== 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. No functional change intended. 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(-) Index: linux-2.6/kernel/futex/core.c =================================================================== --- linux-2.6.orig/kernel/futex/core.c +++ linux-2.6/kernel/futex/core.c @@ -193,7 +193,7 @@ static u64 get_inode_sequence_number(str /** * get_futex_key() - Get parameters which are the keys for a futex * @uaddr: virtual address of the futex - * @fshared: false for a PROCESS_PRIVATE futex, true for PROCESS_SHARED + * @flags: FLAGS_* * @key: address where result is stored. * @rw: mapping needs to be read/write (values: FUTEX_READ, * FUTEX_WRITE) @@ -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; @@ -226,6 +226,9 @@ int get_futex_key(u32 __user *uaddr, boo struct folio *folio; struct address_space *mapping; int err, ro = 0; + bool fshared; + + fshared = flags & FLAGS_SHARED; /* * The futex address must be "naturally" aligned. Index: linux-2.6/kernel/futex/futex.h =================================================================== --- linux-2.6.orig/kernel/futex/futex.h +++ linux-2.6/kernel/futex/futex.h @@ -184,7 +184,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 * Index: linux-2.6/kernel/futex/pi.c =================================================================== --- linux-2.6.orig/kernel/futex/pi.c +++ linux-2.6/kernel/futex/pi.c @@ -933,7 +933,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; @@ -1129,7 +1129,7 @@ retry: 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; Index: linux-2.6/kernel/futex/requeue.c =================================================================== --- linux-2.6.orig/kernel/futex/requeue.c +++ linux-2.6/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; Index: linux-2.6/kernel/futex/waitwake.c =================================================================== --- linux-2.6.orig/kernel/futex/waitwake.c +++ linux-2.6/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; @@ -248,10 +248,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; @@ -426,7 +426,7 @@ retry: 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)) @@ -438,7 +438,7 @@ retry: 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); @@ -602,7 +602,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 Thu Sep 21 10:45:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13393845 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 3F1ADE70719 for ; Thu, 21 Sep 2023 11:01:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2B3D16B0200; Thu, 21 Sep 2023 07:01:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 206DA6B01FE; Thu, 21 Sep 2023 07:01:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 05AAD6B01FF; Thu, 21 Sep 2023 07:01:00 -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 D656B6B01F9 for ; Thu, 21 Sep 2023 07:00:59 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8A166C10A4 for ; Thu, 21 Sep 2023 11:00:59 +0000 (UTC) X-FDA: 81260312238.27.43C202E Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf29.hostedemail.com (Postfix) with ESMTP id 4F250120038 for ; Thu, 21 Sep 2023 11:00:55 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=eBZezOFZ; dmarc=none; 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695294056; 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=fjIRU4T5oPILBU1zZ/wxS7qhPtCXJYxpFVPOgrLAAA0=; b=76fBZDHOHvS075rM7BOmxoQ2Naqq4XguLINS8Uj8sSJ064f1NaA9+52gjA3Oil+zfu0rcj DP6gA3EnVwrILJ3eb4YVBGOeSzmwLFC/eSZSny4v1mVfDUTUVRHO3HSqIJQSDOsdOrQ0Us cbp2va3BavMkkDNfO+PcZv5vx8zA+zk= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=eBZezOFZ; dmarc=none; 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695294056; a=rsa-sha256; cv=none; b=plFxwQnSr/HH72LnLPxQM1D3S4nDbPMvE38diG7G+n2URW5Mb+PVevM/X/+WqDnzsR7gP0 jicXXukls7PFve5MO3bIJWRxRQliN0wNFAANSf2qE6cR0QSOBBTtK9ENE+R3sDZx3PvN5K 6DUapb93KvKoIbFSBVCHycVxD6Ixckk= 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=fjIRU4T5oPILBU1zZ/wxS7qhPtCXJYxpFVPOgrLAAA0=; b=eBZezOFZ4ppQ3c2LZZFjuO/bD8 21whfvNIaYL8MbYoA09p6cZMY0xa2zNuISVyyt31TCZQMlOL2jutHZQw5DV0UbkivdgvXS3N35Ecn vIbEoK/h0Be5VogafdT0PutUojkgclQdYFKDradWPI5BjIUJG7gRPS3JbBmbctKHbDK2ojQ9dxGgC 1iteJJ8zhfr+VbGovdVx3usUWCyGC//ajRFV+vQXW/HxStnQ1v8g3S1XR5LaOZrhqhx5Oa0CtmlSl qCksmgG5lRBLRCaymIvIwWUXwbSOxPlUU0xV5NxOIlLp8T4G/ARIoWsYIypPd/BkX2MbZ33POQ8YU PDpUBtGg==; 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 1qjHQN-00FJvw-1Z; Thu, 21 Sep 2023 11:00:49 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 0ABA13005F4; Thu, 21 Sep 2023 13:00:43 +0200 (CEST) Message-Id: <20230921105248.396780136@noisy.programming.kicks-ass.net> User-Agent: quilt/0.65 Date: Thu, 21 Sep 2023 12:45:14 +0200 From: peterz@infradead.org 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 v3 09/15] futex: Add flags2 argument to futex_requeue() References: <20230921104505.717750284@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Disposition: inline; filename=peterz-futex2-requeue-flags.patch X-Rspam-User: X-Stat-Signature: ykcaiyybe47s1z193etnwq1f7znbjkc5 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 4F250120038 X-HE-Tag: 1695294055-703269 X-HE-Meta: U2FsdGVkX1/8t57HVjtUB9RlSK+gbmM38qLb7sVJXaA5rLu585MLmAs1/HPIv8fseerJe3+7dRR4/ZI+7kP//zmsXKLeL3s0Ryknz40wzII5Ht3dfhg/TgIn2hotRS+3ht/O61dOT3hNlZLUvY7p77ViaLQpKJh7zBr9N3e42wg5G1r4zk0pF0sPLkeA8ceahFiIi5uciJsXWqyzKZT/Ctr15+jpejuhhiDlkEtnFnu3qpKXr496UJEghdsYTJ8tTuRfL/1RbWOCQII97mi5LPGq38KnHQ3sg4FDiN8eKD+3uNqL6b6G7Rt5ZaZPAzrWUxmBoDlAwJssivagAQDFagao2a9drfsMZqLMxX6gzHY5ui0PLTkSu/1iFwQNCW69CLO2IG+rFoRATItVw+OjB0SA9BK/VZbeRnWuWUcBCFWQet/XA3nOXJLyuiPSBhiXkYKEZAZ3YwEiXwQBHpIvw8HGNk9Q4BQYxUGY+Vsz+7+cGAdEHXGqCCn3pujuoOoeIwhWHuwLCulm/VFvdanoaJAXEeBrRKcGCHJKy6Hc4O2vsJWlpeqIrB9lTR1FkHU2SNlwrssMZ/I16F1rIVfqMnucxjzlq6mRqDvNVxMWDwSVFiM/Uzj4xSmLHE12syc1MdIA+6LqRVI60U6/sLU+PqI/0m9j0nuiYjBHm7HcZFXI74Xafdjqpx2/c3oyC7RICEg3hsyZqwr8tjB7Lc4Ktm76F/O/aB5xy4WE0VATE5YPX/Ht3q84cq8ofADrYX7OcSr4qT6RlX2PR4E1GtKPd/F9yUcKveEmpBxTh5GYlNZkC35rkBeFLkfVyf0rXcpZOrKBGiTXofTKB7vVtd16P8zXkTasF0xREJkk1pql354f+ZV8hdd0qLt5jVcQ1tyUhG7cchjA9rkvz9M0IasgDa8vddPFPSvULKQctXTqh5dV2sJCkm3sXrN34KfK/Eu1+ExBTrTDLnzfrgVpWdT Xag2TKZ8 mfD9if5iEgJIIbULlm9JdI0PXjf2Zw8nGLdn7toriLNlMMw/ZPvWTB+FOXNcr5pLNSB9gvyxgsOU4/QIxdFWJC+FtMEaK1PD17RzwJkfSD1XLu5UncOTnfrWsC+h43y2zUQBfD8S9ubMIZMx4wfRSySxDgWc4RoWSj8c3oCrllZTBWpl5do/L7Gde73DSv9Hlsy4+pkg+aZjpGDdTDReheHPiku3fn8RfPt+1KXTHLH4mCSwdkNSiDFeKvQ== 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. No functional change intended. 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(-) Index: linux-2.6/kernel/futex/futex.h =================================================================== --- linux-2.6.orig/kernel/futex/futex.h +++ linux-2.6/kernel/futex/futex.h @@ -328,8 +328,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, Index: linux-2.6/kernel/futex/requeue.c =================================================================== --- linux-2.6.orig/kernel/futex/requeue.c +++ linux-2.6/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 @@ retry_private: if (ret) return ret; - if (!(flags & FLAGS_SHARED)) + if (!(flags1 & FLAGS_SHARED)) goto retry_private; goto retry; Index: linux-2.6/kernel/futex/syscalls.c =================================================================== --- linux-2.6.orig/kernel/futex/syscalls.c +++ linux-2.6/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 Thu Sep 21 10:45:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13393854 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 08060E70714 for ; Thu, 21 Sep 2023 11:01:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4C99D6B0205; Thu, 21 Sep 2023 07:01:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 47A246B0208; Thu, 21 Sep 2023 07:01:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2F24A6B0209; Thu, 21 Sep 2023 07:01:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 178756B0205 for ; Thu, 21 Sep 2023 07:01:07 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D972F1CADF1 for ; Thu, 21 Sep 2023 11:01:06 +0000 (UTC) X-FDA: 81260312532.28.9FDF7D7 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf10.hostedemail.com (Postfix) with ESMTP id 01054C0027 for ; Thu, 21 Sep 2023 11:01:04 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=HEloi5ch; spf=none (imf10.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=1695294065; 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=f+fo5qtlWKdma6yR33ByQC30fFdCan4IPhCDTk6tKSM=; b=1giCWq0aDHYH/1ltu7ElaE8r7WM/DJjAlMd2pJPQqUKVowYvH3ewugRnla1S5ueLYGxyBw C1JCOnp7mtlWIENaBT7Hb4qNvm/aIW6ZVLa3FH9dTFoAFqzNuOtumhc6nEvVd20VHvTf9r 94RD9zELMuBVkY2dbmpXFI6P2Q8sk6w= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695294065; a=rsa-sha256; cv=none; b=8rFdMCoO09wr1p4T3YMI4SVZp9wZfYeDgZduT0J5kJOMLlXk14L+lvkzkAun6ocWL5kC3k NEYyQDu5fUV5nAVwtJjs7Ds5LwjDvPXBCis8CIP/OYjgrWmg8t6OkPPDcUcAoHzefKVdon wfjqf6QOhMJhyjnAgpP0WWPwSD7a8M4= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=HEloi5ch; spf=none (imf10.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=f+fo5qtlWKdma6yR33ByQC30fFdCan4IPhCDTk6tKSM=; b=HEloi5chIkoAzJ1qmH9doIMMLS ZkNSD4N2RkkbqgCewVxvAHggRdWZnFRlWj4IhTeRhItbbFVErm62/CTGDqCmyjsnOp4ZuteeOoFdF yIEIu8bnwVXPVpe6KPzotIKluKJ0e+mnwy062T62ceHSKleg0fzg6/b1LE8m/A4OlmlXuCwJfqVcV xHMQu5W5PZqXS6brx0IevaeO27f1kU1m0gjva+SDK5AWHjcO2nWlE/J9+3FVfPKfua0pNdfZVpV3Y v4a1PegmFDKYJ5+tOvwtgzugAgCj5s7ib09/wtVoAKIabLs7TIX8znLpx9OXnGZG8oI1jFkcJns8j 3bUiJ+NA==; 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 1qjHQN-00FJvu-1M; Thu, 21 Sep 2023 11:00:57 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 10D1E300642; Thu, 21 Sep 2023 13:00:43 +0200 (CEST) Message-Id: <20230921105248.511860556@noisy.programming.kicks-ass.net> User-Agent: quilt/0.65 Date: Thu, 21 Sep 2023 12:45:15 +0200 From: peterz@infradead.org To: tglx@linutronix.de, axboe@kernel.dk Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, dvhart@infradead.org, dave@stgolabs.net, andrealmeid@igalia.com, Andrew Morton , urezki@gmail.com, hch@infradead.org, lstoakes@gmail.com, Arnd Bergmann , linux-api@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, malteskarupke@web.de, Geert Uytterhoeven Subject: [PATCH v3 10/15] futex: Add sys_futex_requeue() References: <20230921104505.717750284@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Disposition: inline; filename=peterz-futex2-requeue.patch X-Rspamd-Queue-Id: 01054C0027 X-Rspam-User: X-Stat-Signature: 4sx9qejc39inxj3ozpda7jipyggsa1g4 X-Rspamd-Server: rspam03 X-HE-Tag: 1695294064-831947 X-HE-Meta: U2FsdGVkX1+XhIxNA+W2nBwDgkAUmzUmeDqYzZMm9jWa6oLXzFW8VUkxjN8R9sx7vw4Kq9RoXvsurjeWP/zARn44RkQx+Chg9lOGwPzcWEy44eeIWOaKJN4mY902ObhMFf5BnvTCac8oLErcr7jbQ2slnwdoX7GXDop9lWmZhwlGDvFQPABiWH4sQod1nxVD6hCVDbVY5WhHRrmLm2UB8QOzcgBPizx1Ws+A+TNjC/mxPyjI8puOxvbRUm1ryDBn1k/mUzqw9HhuOzMxmK7LOUUoawZVh+ShRPSJEEdB7GwWCFtBMpcCuMCPIV5aI06DJq8u9ekliuTZZUXrHKqJQ+x15aYqfGS2hkAzRf82O0yqoUgNUM0tedfIPUNYNwh/AReb3IZ9VVc/HIOUcpB4bvW0lkwhhsyVQ/SFdtcEk39TsLP74UEOgT4j9bqCZBPG7VXnSLr0og+lLaUfkqoVwsHwZ/XDkoK1fYZzYTW3+Zlg8tOs3T6Me2qt6Q4qWHavA0hXDX4fU0HKZZ5NL5JX6JZyi7CsYDR+F/50HwO/Nn1SC8baDFfjPwyFL4qq0Oyc9g2lJZaAo8/MuV4pIF/htO4hvC50bNxL4a21AzAafzecJnr1ACweG+knIyQWPT3iQ+CJShDRhDLIL4tTf2hGDpjR+wLBW0mxm/BYUiCDdCSKh0Yi6lRwu20WOtzpqZnz8q8WOocsdFPpHTs0D9KhepSrF5+Zk0mmA6KBq3TTTnXTnop/VLMhEUyvlKmZYd3gFICf3fILWjbDGm9G2HPGh4RlNG0gpdNazC/aDjqtx8jmVm2nVxjgygcC4SDPbPmutvblBcEiL00g2zUVR3bjjJxYYhd58SUa5Ek6TCDKRTIIHsMbIeMf7p6nhKU8zYG5LuKyAMsqpB/sOmjTzGySuAHwkFGV65dvU2XfrnpZ2a6fM6mrwsfPU6YsN2KpuPOYfkmQA7Oh/YZVoxGNGEV LtjANkqG 9YCeBmC3K4k0UPTFPhDHPsvel3b/36oHmId+JTlAhsErv3iwcTaFdwgIt2wwpxxPClhxzY92Khj6CzfmAAHEvU027GBodcx7TV8kfZ+OLZ+5m35WK0Yy+T7xvnujWmE/w1WxMg1yYIZzB20kFhw+LknbAENviaX5a+t2kUYQNjFl/Lxuislq+edUstMr/EZzR6S+mHajVNSuj8ZWGFfGOXJgCoN5vz3RyA86gUWXLoMkal/XJ2EdTzPoFuRrOhEKXv36EYDX+4atSROaRERZxt1W9kmo1LXLFOZbWt3uF6RPhiViwkvNNHZXiLw== 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 off the 'simple' futex2 syscall group by adding sys_futex_requeue(). Unlike sys_futex_{wait,wake}() its arguments are too numerous to fit into a regular syscall. As such, use struct futex_waitv to pass the 'source' and 'destination' futexes to the syscall. This syscall implements what was previously known as FUTEX_CMP_REQUEUE and uses {val, uaddr, flags} for source and {uaddr, flags} for destination. This design explicitly allows requeueing between different types of futex by having a different flags word per uaddr. Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Thomas Gleixner Acked-by: Geert Uytterhoeven --- arch/alpha/kernel/syscalls/syscall.tbl | 1 arch/arm/tools/syscall.tbl | 1 arch/arm64/include/asm/unistd.h | 2 - arch/arm64/include/asm/unistd32.h | 2 + arch/ia64/kernel/syscalls/syscall.tbl | 1 arch/m68k/kernel/syscalls/syscall.tbl | 1 arch/microblaze/kernel/syscalls/syscall.tbl | 1 arch/mips/kernel/syscalls/syscall_n32.tbl | 1 arch/mips/kernel/syscalls/syscall_n64.tbl | 1 arch/mips/kernel/syscalls/syscall_o32.tbl | 1 arch/parisc/kernel/syscalls/syscall.tbl | 1 arch/powerpc/kernel/syscalls/syscall.tbl | 1 arch/s390/kernel/syscalls/syscall.tbl | 1 arch/sh/kernel/syscalls/syscall.tbl | 1 arch/sparc/kernel/syscalls/syscall.tbl | 1 arch/x86/entry/syscalls/syscall_32.tbl | 1 arch/x86/entry/syscalls/syscall_64.tbl | 1 arch/xtensa/kernel/syscalls/syscall.tbl | 1 include/linux/syscalls.h | 3 ++ include/uapi/asm-generic/unistd.h | 4 ++ kernel/futex/syscalls.c | 38 ++++++++++++++++++++++++++++ kernel/sys_ni.c | 1 22 files changed, 64 insertions(+), 2 deletions(-) Index: linux-2.6/arch/alpha/kernel/syscalls/syscall.tbl =================================================================== --- linux-2.6.orig/arch/alpha/kernel/syscalls/syscall.tbl +++ linux-2.6/arch/alpha/kernel/syscalls/syscall.tbl @@ -494,3 +494,4 @@ 562 common fchmodat2 sys_fchmodat2 563 common futex_wake sys_futex_wake 564 common futex_wait sys_futex_wait +565 common futex_requeue sys_futex_requeue Index: linux-2.6/arch/arm/tools/syscall.tbl =================================================================== --- linux-2.6.orig/arch/arm/tools/syscall.tbl +++ linux-2.6/arch/arm/tools/syscall.tbl @@ -468,3 +468,4 @@ 452 common fchmodat2 sys_fchmodat2 454 common futex_wake sys_futex_wake 455 common futex_wait sys_futex_wait +456 common futex_requeue sys_futex_requeue Index: linux-2.6/arch/arm64/include/asm/unistd.h =================================================================== --- linux-2.6.orig/arch/arm64/include/asm/unistd.h +++ linux-2.6/arch/arm64/include/asm/unistd.h @@ -39,7 +39,7 @@ #define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE + 5) #define __ARM_NR_COMPAT_END (__ARM_NR_COMPAT_BASE + 0x800) -#define __NR_compat_syscalls 456 +#define __NR_compat_syscalls 457 #endif #define __ARCH_WANT_SYS_CLONE Index: linux-2.6/arch/arm64/include/asm/unistd32.h =================================================================== --- linux-2.6.orig/arch/arm64/include/asm/unistd32.h +++ linux-2.6/arch/arm64/include/asm/unistd32.h @@ -915,6 +915,8 @@ __SYSCALL(__NR_fchmodat2, sys_fchmodat2) __SYSCALL(__NR_futex_wake, sys_futex_wake) #define __NR_futex_wait 455 __SYSCALL(__NR_futex_wait, sys_futex_wait) +#define __NR_futex_requeue 456 +__SYSCALL(__NR_futex_requeue, sys_futex_requeue) /* * Please add new compat syscalls above this comment and update Index: linux-2.6/arch/ia64/kernel/syscalls/syscall.tbl =================================================================== --- linux-2.6.orig/arch/ia64/kernel/syscalls/syscall.tbl +++ linux-2.6/arch/ia64/kernel/syscalls/syscall.tbl @@ -375,3 +375,4 @@ 452 common fchmodat2 sys_fchmodat2 454 common futex_wake sys_futex_wake 455 common futex_wait sys_futex_wait +456 common futex_requeue sys_futex_requeue Index: linux-2.6/arch/m68k/kernel/syscalls/syscall.tbl =================================================================== --- linux-2.6.orig/arch/m68k/kernel/syscalls/syscall.tbl +++ linux-2.6/arch/m68k/kernel/syscalls/syscall.tbl @@ -454,3 +454,4 @@ 452 common fchmodat2 sys_fchmodat2 454 common futex_wake sys_futex_wake 455 common futex_wait sys_futex_wait +456 common futex_requeue sys_futex_requeue Index: linux-2.6/arch/microblaze/kernel/syscalls/syscall.tbl =================================================================== --- linux-2.6.orig/arch/microblaze/kernel/syscalls/syscall.tbl +++ linux-2.6/arch/microblaze/kernel/syscalls/syscall.tbl @@ -460,3 +460,4 @@ 452 common fchmodat2 sys_fchmodat2 454 common futex_wake sys_futex_wake 455 common futex_wait sys_futex_wait +456 common futex_requeue sys_futex_requeue Index: linux-2.6/arch/mips/kernel/syscalls/syscall_n32.tbl =================================================================== --- linux-2.6.orig/arch/mips/kernel/syscalls/syscall_n32.tbl +++ linux-2.6/arch/mips/kernel/syscalls/syscall_n32.tbl @@ -393,3 +393,4 @@ 452 n32 fchmodat2 sys_fchmodat2 454 n32 futex_wake sys_futex_wake 455 n32 futex_wait sys_futex_wait +456 n32 futex_requeue sys_futex_requeue Index: linux-2.6/arch/mips/kernel/syscalls/syscall_n64.tbl =================================================================== --- linux-2.6.orig/arch/mips/kernel/syscalls/syscall_n64.tbl +++ linux-2.6/arch/mips/kernel/syscalls/syscall_n64.tbl @@ -369,3 +369,4 @@ 452 n64 fchmodat2 sys_fchmodat2 454 n64 futex_wake sys_futex_wake 455 n64 futex_wait sys_futex_wait +456 n64 futex_requeue sys_futex_requeue Index: linux-2.6/arch/mips/kernel/syscalls/syscall_o32.tbl =================================================================== --- linux-2.6.orig/arch/mips/kernel/syscalls/syscall_o32.tbl +++ linux-2.6/arch/mips/kernel/syscalls/syscall_o32.tbl @@ -442,3 +442,4 @@ 452 o32 fchmodat2 sys_fchmodat2 454 o32 futex_wake sys_futex_wake 455 o32 futex_wait sys_futex_wait +456 o32 futex_requeue sys_futex_requeue Index: linux-2.6/arch/parisc/kernel/syscalls/syscall.tbl =================================================================== --- linux-2.6.orig/arch/parisc/kernel/syscalls/syscall.tbl +++ linux-2.6/arch/parisc/kernel/syscalls/syscall.tbl @@ -453,3 +453,4 @@ 452 common fchmodat2 sys_fchmodat2 454 common futex_wake sys_futex_wake 455 common futex_wait sys_futex_wait +456 common futex_requeue sys_futex_requeue Index: linux-2.6/arch/powerpc/kernel/syscalls/syscall.tbl =================================================================== --- linux-2.6.orig/arch/powerpc/kernel/syscalls/syscall.tbl +++ linux-2.6/arch/powerpc/kernel/syscalls/syscall.tbl @@ -541,3 +541,4 @@ 452 common fchmodat2 sys_fchmodat2 454 common futex_wake sys_futex_wake 455 common futex_wait sys_futex_wait +456 common futex_requeue sys_futex_requeue Index: linux-2.6/arch/s390/kernel/syscalls/syscall.tbl =================================================================== --- linux-2.6.orig/arch/s390/kernel/syscalls/syscall.tbl +++ linux-2.6/arch/s390/kernel/syscalls/syscall.tbl @@ -457,3 +457,4 @@ 452 common fchmodat2 sys_fchmodat2 sys_fchmodat2 454 common futex_wake sys_futex_wake sys_futex_wake 455 common futex_wait sys_futex_wait sys_futex_wait +456 common futex_requeue sys_futex_requeue sys_futex_requeue Index: linux-2.6/arch/sh/kernel/syscalls/syscall.tbl =================================================================== --- linux-2.6.orig/arch/sh/kernel/syscalls/syscall.tbl +++ linux-2.6/arch/sh/kernel/syscalls/syscall.tbl @@ -457,3 +457,4 @@ 452 common fchmodat2 sys_fchmodat2 454 common futex_wake sys_futex_wake 455 common futex_wait sys_futex_wait +456 common futex_requeue sys_futex_requeue Index: linux-2.6/arch/sparc/kernel/syscalls/syscall.tbl =================================================================== --- linux-2.6.orig/arch/sparc/kernel/syscalls/syscall.tbl +++ linux-2.6/arch/sparc/kernel/syscalls/syscall.tbl @@ -500,3 +500,4 @@ 452 common fchmodat2 sys_fchmodat2 454 common futex_wake sys_futex_wake 455 common futex_wait sys_futex_wait +456 common futex_requeue sys_futex_requeue Index: linux-2.6/arch/x86/entry/syscalls/syscall_32.tbl =================================================================== --- linux-2.6.orig/arch/x86/entry/syscalls/syscall_32.tbl +++ linux-2.6/arch/x86/entry/syscalls/syscall_32.tbl @@ -459,3 +459,4 @@ 452 i386 fchmodat2 sys_fchmodat2 454 i386 futex_wake sys_futex_wake 455 i386 futex_wait sys_futex_wait +456 i386 futex_requeue sys_futex_requeue Index: linux-2.6/arch/x86/entry/syscalls/syscall_64.tbl =================================================================== --- linux-2.6.orig/arch/x86/entry/syscalls/syscall_64.tbl +++ linux-2.6/arch/x86/entry/syscalls/syscall_64.tbl @@ -377,6 +377,7 @@ 453 64 map_shadow_stack sys_map_shadow_stack 454 common futex_wake sys_futex_wake 455 common futex_wait sys_futex_wait +456 common futex_requeue sys_futex_requeue # # Due to a historical design error, certain syscalls are numbered differently Index: linux-2.6/arch/xtensa/kernel/syscalls/syscall.tbl =================================================================== --- linux-2.6.orig/arch/xtensa/kernel/syscalls/syscall.tbl +++ linux-2.6/arch/xtensa/kernel/syscalls/syscall.tbl @@ -425,3 +425,4 @@ 452 common fchmodat2 sys_fchmodat2 454 common futex_wake sys_futex_wake 455 common futex_wait sys_futex_wait +456 common futex_requeue sys_futex_requeue Index: linux-2.6/include/linux/syscalls.h =================================================================== --- linux-2.6.orig/include/linux/syscalls.h +++ linux-2.6/include/linux/syscalls.h @@ -556,6 +556,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, Index: linux-2.6/include/uapi/asm-generic/unistd.h =================================================================== --- linux-2.6.orig/include/uapi/asm-generic/unistd.h +++ linux-2.6/include/uapi/asm-generic/unistd.h @@ -826,9 +826,11 @@ __SYSCALL(__NR_fchmodat2, sys_fchmodat2) __SYSCALL(__NR_futex_wake, sys_futex_wake) #define __NR_futex_wait 455 __SYSCALL(__NR_futex_wait, sys_futex_wait) +#define __NR_futex_requeue 456 +__SYSCALL(__NR_futex_requeue, sys_futex_requeue) #undef __NR_syscalls -#define __NR_syscalls 456 +#define __NR_syscalls 457 /* * 32 bit systems traditionally used different Index: linux-2.6/kernel/futex/syscalls.c =================================================================== --- linux-2.6.orig/kernel/futex/syscalls.c +++ linux-2.6/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, Index: linux-2.6/kernel/sys_ni.c =================================================================== --- linux-2.6.orig/kernel/sys_ni.c +++ linux-2.6/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 Thu Sep 21 10:45:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13393855 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 49C49E70718 for ; Thu, 21 Sep 2023 11:01:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B5A2A6B0208; Thu, 21 Sep 2023 07:01:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AB9D46B0209; Thu, 21 Sep 2023 07:01:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D0536B020A; Thu, 21 Sep 2023 07:01:08 -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 8A8EC6B0208 for ; Thu, 21 Sep 2023 07:01:08 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 5637AC091C for ; Thu, 21 Sep 2023 11:01:08 +0000 (UTC) X-FDA: 81260312616.29.BA87800 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf11.hostedemail.com (Postfix) with ESMTP id 675254001B for ; Thu, 21 Sep 2023 11:01:05 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=ViAEDbVG; dmarc=none; 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695294065; a=rsa-sha256; cv=none; b=G1nfh4+jDRFZnfzHdTEwS7cjTocusvGOq6P4mWM5Seld5F9n6zsXH7VTH6fFRUcToBiyuK aJ1rS+c87yA0ZdkNhkSNeHPG6WYfevUNPQhGpAdyyuLyHRgpIVKFqW+2KQ0uW7a8ZvEWNe wbELpkKz6fOJuspVQCL1gTGlUyTtIUQ= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=ViAEDbVG; dmarc=none; 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695294065; 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=+WIdohk1HL2nzrHveE43px5IkTjGhV/7JBkH2s5C174=; b=khN+rxFEkYQmNMkyhgAwRCG8RClH5ZndRUM2HuhmO5IOmFWLw7YM1eLa7qFRsbNEmvTnHX Y5oIOzPV+Ftgc2TUrBmNeOtGsUxgTsHRgwBePwiK2c5EZHSUWujTXBdQPZgK6Lpsob7OaF 3MR7KqKyAIXQNXVSqUChFJENDrZG334= 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=+WIdohk1HL2nzrHveE43px5IkTjGhV/7JBkH2s5C174=; b=ViAEDbVGOlyxSg3ebF8KxwAziD ZJXxCIy42X12v4Mep2vVxljFUC4bpie4jrjZc5b7y0aR/AFBwBx8QQf7IyrWb6in0/ZjL0xzIPnSx pb6UQGfcsxlZIGeiFtjBChv2JNIQwRXxcHOt6/36MAnZlaHZe1+0fz5A4w/a/h9G+i1YiZoOjLNE4 OwpOyR+wNSWxm0UFxB37sVSQEBBvFtN6ftl6Pn5yJIMtEP7rAmx4bdY6aw54FXq2amDzF8WCOnnaP MIOPlPb7NIN0RqyDlWXr9vkr9PkW1Y4MN8g0z/WF3CPS10TmZ2L6+1wJRYHnIB47xz4TyxFPPPHSd HzrBon7A==; 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 1qjHQN-00FJvv-1Z; Thu, 21 Sep 2023 11:00:59 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 15CCD30067A; Thu, 21 Sep 2023 13:00:43 +0200 (CEST) Message-Id: <20230921105248.683656626@noisy.programming.kicks-ass.net> User-Agent: quilt/0.65 Date: Thu, 21 Sep 2023 12:45:16 +0200 From: peterz@infradead.org 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, Christoph Hellwig Subject: [PATCH v3 11/15] mm: Add vmalloc_huge_node() References: <20230921104505.717750284@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Disposition: inline; filename=peterz-vmalloc_huge_node.patch X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 675254001B X-Stat-Signature: kmkbabm95ze991gp87s9hmbmmmkmrffa X-HE-Tag: 1695294065-600994 X-HE-Meta: U2FsdGVkX18itry9AVRmbLajxxsAAkHHfmOH8mfaVEyr51v2NkdUbSfHfndZFiNIP+bhAYKerpnfxHQ6Qs1otSWBsm20ilUSorKiVe63AqNUBoZlL3c34RkZ5mwoLIq9d/48bGQawIyXGPxJRIE8loMM5VxnVyD8T8Hu3hAOgbhS+WIIbvqpBzIWOd6IwqJ+acEyl+aGU8ujwbCh7eKoPjVz9KfwgUb26R+zw/3MyT/Ekhj3oL/tVtVQ1MHHDGM6DRCZ9f7bBuDzcKSmQCb1/tf2GQxZ0VXsdSPj/tJMPUrcapUT7uthTXNXaimBPgrFRo3CBpAlGrAXTOy/xY52uSEIMVcGJqW7vHqkGg9x40zXtc2Qgix3my06iRnTxPacXQgrL9uRm4hZ4+ilcXhpJfI6xPOVd1kHX3i0Tso3tsDBZAUdReUyMrj2AhwI2OUQtU3K7OHIq7qobIFPamzj/JKK5ndlftcJMMU4Usd7p89t984bBUzL85u/8eYAme0fFgSTFS6Hp8Ee5JHx9ntrS1GE09YEHxMu/YNv4dxuPufMZ0lyn1Bgjk0vN4JbPBkSmoPMfMOJO3SQn00dTBsyjpY+gnjJWKheITecLavPRqbpecwl26RsxanTu+8Y+vXWv87qTVMhPiQhvGwF9YUgVyKbYho/asVyqunngPfn2H8f1R952Oz+lO4o8Kx9+HqLVI7dRbrOjG29s5nW51UZ/Fu4LXnYFwPPbwMKon42mZDMP9m+7FZr1huh4Da5BrxKm2NLMHmd+Y4ybr6xeMK/fph1pUohKebaZnD4kPr6K3PnatD3OyTM1w7W6VvCG7ZOBdJtcjox6MHVzBBekHORS7LCFCxXkfg+c5oYGuVjmMGCxw4yq2jbwwlS5NOa8U70i744OFjENuonAuqMsYw/q2ekQOXYSwDQ0KTwzNo3JBRP9QHvkMwwg+LD3Yh75V93PAgdYHsD4EQ68dAqny2 pfCm4w7C pPavVfT/VrI8HuGaFVseCeHKAbM1XeOMjvh48TN29nNCYXE7USZhmQE4nrcctHpJXbePcERdyk04ccL9fUY6k/zt2Nyvpo8wl+zH3DFvssmAhM4AVVXZgSESdIfBuZ0EukYvCH8DqBeQn7R96iUJTyX+6A1u4xbUJoMmZelFDgPPA2OY9S3L9bqES33w5NqANS9MORi8VrLtgCG7gvVHxwe4QjQgV5tAu9ej4zE3jQbb6gUX1BVezK5N70Dc1AeSNwZaIwcRMd7pmMqy+5G4kUFa9hA== 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(+) Index: linux-2.6/include/linux/vmalloc.h =================================================================== --- linux-2.6.orig/include/linux/vmalloc.h +++ linux-2.6/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); Index: linux-2.6/mm/vmalloc.c =================================================================== --- linux-2.6.orig/mm/vmalloc.c +++ linux-2.6/mm/vmalloc.c @@ -3420,6 +3420,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 Thu Sep 21 10:45:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13393842 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 9FD34E70718 for ; Thu, 21 Sep 2023 11:00:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0D01C6B018D; Thu, 21 Sep 2023 07:00:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 080B56B0192; Thu, 21 Sep 2023 07:00:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E8A086B01A3; Thu, 21 Sep 2023 07:00:58 -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 D686A6B018D for ; Thu, 21 Sep 2023 07:00:58 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9FE3741042 for ; Thu, 21 Sep 2023 11:00:58 +0000 (UTC) X-FDA: 81260312196.17.E28D100 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf17.hostedemail.com (Postfix) with ESMTP id 8B9704001E for ; Thu, 21 Sep 2023 11:00:56 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=fC10oRh8; dmarc=none; spf=none (imf17.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=1695294057; a=rsa-sha256; cv=none; b=tZtR8LzVgtB6Vgb/Ama6TDkK+F+ey012UPrKFeVDVVVcAf/3D/l8f2Z4mg7fVSFyp2QdNz 67zNz4FsgiQasf7zgNGwBEKk3y9OTAbH8T186hOryxfdwPM3dO5XFuiCBHWcRudJWwzlKK jwCIyvMU4JA2YWjiiAY65wDEKhrAM2c= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=fC10oRh8; dmarc=none; spf=none (imf17.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=1695294057; 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=Q23LA4fNtxuPKBmxlCap1S+ePSWCcBWqnwP5S12UL2A=; b=kw/yjKAwFhFSMxUIr5cl+J9Njpi+gY09LcK8XJlBxhJMGExKsmIZKsKHhc3kXA23vZgeMJ DkIMNvvREmcONnXKBoVWLgVzhT+CG4rtqyhvqLRvhEIxF6jIBs+ZpQRCL6CjDWCQaaZXBQ 5CP5652BNNE25tYgfXMVpGoWVdgcuio= 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=Q23LA4fNtxuPKBmxlCap1S+ePSWCcBWqnwP5S12UL2A=; b=fC10oRh8rfYFZppt9c16iBpKl6 tkQE8L0dalhfkmy47nxsgnYzuJc2FTXNyLp6Rd0ZVmI/KuXMWQpYLjRD+U+fbnmEeJ9gaFyMm1bnb aT0bT1FWUhEoTBablLBTbDrqaF7h+KpyUsKbRO9bRqOlj/qsOceCkEiLP7zh0EbXUzHT4FQy45hya fmEHq61ylgZ0WVZqE3slZONq67sTfxiJPZsPO+eqcx/GQXgQn37LOKWcwtWwjtqB7ENRwaZMaLKGM IYs4YpR7md3q/nWDWIwlAUgK/TXufUhO82cfMxRUll9dQ0evfrrvgxDvbYnkIPPZ657PVpOhfuk4O Soz1laqg==; 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 1qjHQN-00FJvx-1Y; Thu, 21 Sep 2023 11:00:49 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 1BDC230067B; Thu, 21 Sep 2023 13:00:43 +0200 (CEST) Message-Id: <20230921105248.852663217@noisy.programming.kicks-ass.net> User-Agent: quilt/0.65 Date: Thu, 21 Sep 2023 12:45:17 +0200 From: peterz@infradead.org 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 v3 12/15] futex: Implement FUTEX2_NUMA References: <20230921104505.717750284@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Disposition: inline; filename=peterz-futex2-numa.patch X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 8B9704001E X-Stat-Signature: a1yt16gyrdy64fnf5hfm99ecwaffprab X-HE-Tag: 1695294056-48670 X-HE-Meta: U2FsdGVkX1++vrsQfS0q71QqrMP5q1m5VJNuNRDUtLnqSRFaoQni27R5K2UIhaN/Xl50EXPDsYsc3i1mHszqZsEFuRlA/ljQoMaxQMga5QGcHgrNcFG8hqzM9pbcNcjyHlGKdZUYzaOzVTBoG1xYsF4Sbd4ppLrV72jDt3xHBV5imhUl7j+GR+oPxVsrvnPkECqBwexZBfwew3qS4BosAgrricwlEaEvHpNoNUrLc0Yv6NL36uAcGPvMK/hvdcP8LFGS0ryxy7CS3dh+8l1sLkS7KmxZlAa/ycdTFBFryUYa37wStc1SAa2IB8sgZYud5mIncQdwEeubTTerGrVjjTTU13/9pb/slidpmBL6lEmHSytB/xjY7eQSjL7+LVHij8746FVT5n7pvOUdyCgW5hjXA1dBIx+fk/9AQMgis22sor6h5GHng3JdYo/k1EzKSXg0m62KJoTnlC644aAtPSjxsp1Xh6yxUzmi57hF9klCfWFjSoksqOTHcMbS79oI/TXUhduUfs2o3pYYELSQaB302e5T7S9g4V+eJAVZ4yX30ijHBpie921CQSTGpaXaRIPSha57+CrkaPh74DkDGtPAe7ZH02BGJDznLNJ3Nh5JSdWQVO179EIVFkQrmXUJvyls5zRZN2eRocE0engux17zrEOITPGlGpDb9EYsAqyOmsE37NZHhgoUWkb0M71XvDV3eWsHQV/RhurjxOP3Np8mqwn1EwTusAbYsDSJp4qZ8DIKOMqCzsM4xJ5C44GqmUutsg2Ve7L+kt5spT7OpBQViFg7PAHlZF0D91Y1esDN+FDJGrSR1Fjn1zA2LakKbMQQfTuLYdNYVj5RA20DYTnB3+TnDcquZD7u50uFIyw6h5sf+ype9qftCQR3j5MyWrH2tatRG7swynVSFDHL8l0U9HfBtEVBl7m19wC81VhAaO5DoHphFTn3UD4veKTgeTYnx7mdDh/oRv1gdaj GVEPKfgm vGbGwq/w8F7EyDW29JWqOto/G+DDXwhTv0gtYIMeQ4LEY92WV1S7zwtSOV6EEA0EgThk3XVtx8bF2EW5jtRsQHuwzX/eLhWRUoGvngikUJkjxfXN4jDkxWvMl8vSjy9lf7IUtW0zr2PmWsaf50FCjZ12P2UDh9gXrTdjGjMnyNjE0GrWLKHr5mUnfpaf+PgmqQHu/ynIj6OOHL1XyEheesc88/ouMFDfVrzrK14DGWXJnVEn1yBrs2BtZEk3UEiuJfCZ9WePHLn99LBnrLfW5/Brsrw== 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 | 129 +++++++++++++++++++++++++++++++++++++++--------- kernel/futex/futex.h | 25 +++++++-- kernel/futex/syscalls.c | 2 4 files changed, 128 insertions(+), 31 deletions(-) Index: linux-2.6/include/linux/futex.h =================================================================== --- linux-2.6.orig/include/linux/futex.h +++ linux-2.6/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; }; Index: linux-2.6/kernel/futex/core.c =================================================================== --- linux-2.6.orig/kernel/futex/core.c +++ linux-2.6/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; + + if (node == FUTEX_NO_NODE) { + /* + * 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[hash & (futex_hashsize - 1)]; + return &futex_queues[node][hash & (futex_hashsize - 1)]; } @@ -217,7 +259,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, 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; @@ -225,25 +267,49 @@ int get_futex_key(u32 __user *uaddr, uns struct page *page; struct folio *folio; struct address_space *mapping; - int err, ro = 0; + int node, err, size, ro = 0; bool fshared; fshared = flags & FLAGS_SHARED; + size = futex_size(flags); + if (flags & FLAGS_NUMA) + size *= 2; /* * 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 (unlikely(!access_ok(uaddr, size))) return -EFAULT; if (unlikely(should_fail_futex(fshared))) return -EFAULT; + if (flags & FLAGS_NUMA) { + void __user *naddr = uaddr + size / 2; + + if (futex_get_value(&node, naddr, flags)) + return -EFAULT; + + if (node == FUTEX_NO_NODE) { + node = numa_node_id(); + if (futex_put_value(node, naddr, flags)) + return -EFAULT; + + } else if (node >= MAX_NUMNODES || !node_possible(node)) { + return -EINVAL; + } + + key->both.node = node; + + } else { + key->both.node = FUTEX_NO_NODE; + } + /* * PROCESS_PRIVATE futexes are fast. * As the mm cannot disappear under us and the 'key' only needs @@ -1124,26 +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, 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; } Index: linux-2.6/kernel/futex/futex.h =================================================================== --- linux-2.6.orig/kernel/futex/futex.h +++ linux-2.6/kernel/futex/futex.h @@ -83,6 +83,19 @@ static inline bool futex_flags_valid(uns if ((flags & FLAGS_SIZE_MASK) != FLAGS_SIZE_32) return false; + /* + * Must be able to represent both FUTEX_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; + } + return true; } @@ -184,7 +197,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 * Index: linux-2.6/kernel/futex/syscalls.c =================================================================== --- linux-2.6.orig/kernel/futex/syscalls.c +++ linux-2.6/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_VALID_MASK (FUTEX2_SIZE_MASK | FUTEX2_PRIVATE) +#define FUTEX2_VALID_MASK (FUTEX2_SIZE_MASK | FUTEX2_NUMA | FUTEX2_PRIVATE) /** * futex_parse_waitv - Parse a waitv array from userspace Index: linux-2.6/include/uapi/linux/futex.h =================================================================== --- linux-2.6.orig/include/uapi/linux/futex.h +++ linux-2.6/include/uapi/linux/futex.h @@ -74,6 +74,14 @@ /* do not use */ #define FUTEX_32 FUTEX2_SIZE_U32 /* historical accident :-( */ + +/* + * When FUTEX2_NUMA doubles the futex word, the second word is a node value. + * The special value -1 indicates no-node. This is the same value as + * NUMA_NO_NODE, except that value is not ABI, this is. + */ +#define FUTEX_NO_NODE (-1) + /* * Max numbers of elements in a futex_waitv array */ From patchwork Thu Sep 21 10:45:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13393844 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 8F03DE70718 for ; Thu, 21 Sep 2023 11:01:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C911E6B01A3; Thu, 21 Sep 2023 07:00:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BF23E6B01B1; Thu, 21 Sep 2023 07:00:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AE0706B01F9; Thu, 21 Sep 2023 07:00:59 -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 9CAD36B01A3 for ; Thu, 21 Sep 2023 07:00:59 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 6F903C10B6 for ; Thu, 21 Sep 2023 11:00:59 +0000 (UTC) X-FDA: 81260312238.08.956A0B5 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf15.hostedemail.com (Postfix) with ESMTP id 2D556A0041 for ; Thu, 21 Sep 2023 11:00:55 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b="D3oUK/pO"; dmarc=none; spf=none (imf15.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=1695294056; 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=s6qOxGEZJpUErRo7Rj/ShDjtuA5F7i3OQJb+GA/Bkxo=; b=KKWRMsXTl2xmGrltwQhr7zbk9pXpVk4VKYYKVbLuVo2441wKwlLR9hH0+ynKJ8SW6Wq69n Zmll2VVtw/85jWYZqfRFw06gvNLwnA6dylFH51jMgxgoaIPgYi/cyalfvFdHjdyFQNvHBW VlkhFsKhua9bcpDvfOs3z4m/t9uQi9E= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b="D3oUK/pO"; dmarc=none; spf=none (imf15.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=1695294056; a=rsa-sha256; cv=none; b=CC63KW3eUF3s2bDJ0YvIAn/u6fpWed4r9XNguxbB0ZLpwVe2/DNNFarS7UkTkHp7qtcvp6 MmdLNKMLmxxJINQTuYCH7KEplIyYpkSqacj+DkfI4AshLKyWQ/7A/G5PBGPys9m8++XP2u e3T4e2H6oZ2XjOVr5PCTVoTuYDv36iM= 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=s6qOxGEZJpUErRo7Rj/ShDjtuA5F7i3OQJb+GA/Bkxo=; b=D3oUK/pO445uaPiP0UtrFW7hXa oKZz9yxvDNPjaKGxg+tuiKw82E47h3XSx1J1DtEx5/rO/Ue7n1RjsT8ClHfs5ISvz5vNJWJsrkIuA 0ui4A/To6UDY07L1ltjrTzUwk7nI3WvMdvonqicjSHRMsq5KyZxf0tb6QrOfqs7ZLA//VIXr/9qFW cze4siUErqj4DLV5JdF5b/Icns3tEaq1kbYbpCZmyI419v1f7F+4SLOHmrjiK5p3eoVvuUByqPDQz eLLWEv5LdNv7XBieo03gAqykd/mkLRixRW1Oph05DbRI73MxCQQfYN3EUx6SKXBr/CbYfTLYJm1Ng Gk8gGfng==; 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 1qjHQN-00FJvy-1Y; Thu, 21 Sep 2023 11:00:49 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 20ED33006F6; Thu, 21 Sep 2023 13:00:43 +0200 (CEST) Message-Id: <20230921105249.002168440@noisy.programming.kicks-ass.net> User-Agent: quilt/0.65 Date: Thu, 21 Sep 2023 12:45:18 +0200 From: peterz@infradead.org 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 v3 13/15] futex: Propagate flags into futex_get_value_locked() References: <20230921104505.717750284@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Disposition: inline; filename=peterz-futex2-get_values_locked.patch X-Rspam-User: X-Stat-Signature: 9kpztqngd6r74f5tj19wgq3m87czgub3 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 2D556A0041 X-HE-Tag: 1695294055-489623 X-HE-Meta: U2FsdGVkX1/vu2661eXOGpMyqI3fxxoVOwUmgifcsg+aqxcXAEsRFRNH5GvDL3hAwHhEAH76Ceoi5SVZYTVyH3BY+YzCwgR1HE6aCiuhAGKdZe7LkPuo9d/aaJSF6tbveTMZ5KX9jObZbNgNBNnvIOR8n6R3mOsRNQkq3RF/Pya+XwhWt42gvmU2GZ8h5EpY9hExC5iuUmBDib42M9ViXxSWdvmkEA99XJw7pGH1WrsL9SL31wkQzMP//K+oZpNZ4RQUVgiEQshoAp2kTccl1MPeLJsMnV7KOoODRT6kdvlJy32DaAacBNJcnHoyqGOY7xjfJahkEzruq89ZGQYMztgD3J+zWOPpTh1kuWwd24no4brbMOOc21Ola4S8EW7S4qKvznMhPNujIzh7AlYzkZo6vf1NeDzEZ+/2pCwOXC9HTq9M7yEhIkd5xqbi9krnVKZBp3S5CcV17fx9esE8ztkVzgU0XrOe5TVTYeCZzYV549CCdFRWtSJgscd6XJXJF3I5D8W+Wl+mverGY1vqvo2xQCs6MAl9gjQaOOvzhCZ4pzO60fyXPkUiZONQ8DYT6Ro1ydEWZcXoXY2MABYZ8lsuyF35qNxMITD8fV4wDY+EM+MFsp9OSSlM2TXuKVOOcqPQ/aImo7goc6HafaPOT7T9W1BlDZYCqeuaITSNWZX7gZMCjz2Z/QuJYxfG1yU5+OOsYzsJ0+O/XOZvicU3LijPARyP4mNJRiB6nYUjO9+r4aAY2B01CdgiMg4heFLkH32if9mCxyMqYdyhGS0Zr+t4qAm7J1j6igaZPrLOZwW5eaamNxgBGjyMG7H+GdvsWMKwKI+n1S2doNfmj2SV49au4Ow/J17SURlt1q0F5DgUM4ftDpDjs27eXFW1x6PI+qj+w6kds7JWKnW90laOZ4XK+iDpbtOfF7VbOsEPHQkWBgszTjGhDzm5u3I1rhV7YOuJAqiQ8l4r+7WeEBf 3tKguzbG UhyJTlq0YTYr47dKyhewe3Nds5hq7fW33uHsTPQQYhVZtQFGPrR/I9BNpeiquq9GCeSTfrU+zSMgGdcGBikicp3mtHh/H1m9CnAfIXtUGD4lAKc7umPzIV2yJUit24Tdj5d4abiZYAS09b911t8OB8pJUx1o4v8px7dLV7wEkV4714RUJZ4sU3zgTnDwXuGU/LOXa2gGZEmPT3q03X+OZaSHkSKtvO4hxO2YEmZDOeuMOS2kzO1DY32fxBFTHnWCL3Ix59pPiENnIlUIdq6Rd9IT8o0SLI0IRGLenv6sf+vcInr2oBfYyZ5kGyC3/YSoLK5IRzttvUndqXzI= 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(). No functional change intended. Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Thomas Gleixner --- 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(-) Index: linux-2.6/kernel/futex/core.c =================================================================== --- linux-2.6.orig/kernel/futex/core.c +++ linux-2.6/kernel/futex/core.c @@ -516,12 +516,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; Index: linux-2.6/kernel/futex/futex.h =================================================================== --- linux-2.6.orig/kernel/futex/futex.h +++ linux-2.6/kernel/futex/futex.h @@ -229,7 +229,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); Index: linux-2.6/kernel/futex/pi.c =================================================================== --- linux-2.6.orig/kernel/futex/pi.c +++ linux-2.6/kernel/futex/pi.c @@ -240,7 +240,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) @@ -359,7 +359,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. */ @@ -527,7 +527,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))) @@ -750,7 +750,7 @@ retry: 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; Index: linux-2.6/kernel/futex/requeue.c =================================================================== --- linux-2.6.orig/kernel/futex/requeue.c +++ linux-2.6/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 @@ retry_private: 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); Index: linux-2.6/kernel/futex/waitwake.c =================================================================== --- linux-2.6.orig/kernel/futex/waitwake.c +++ linux-2.6/kernel/futex/waitwake.c @@ -441,7 +441,7 @@ retry: 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) { /* @@ -609,7 +609,7 @@ retry: 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 Thu Sep 21 10:45:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13393849 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 93102E70718 for ; Thu, 21 Sep 2023 11:01:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C71956B01FF; Thu, 21 Sep 2023 07:01:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A6B5D6B01B1; Thu, 21 Sep 2023 07:01:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 69E606B0205; Thu, 21 Sep 2023 07:01:00 -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 44ACE6B0206 for ; Thu, 21 Sep 2023 07:01:00 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id D1C848104B for ; Thu, 21 Sep 2023 11:00:59 +0000 (UTC) X-FDA: 81260312238.23.98DE2AC Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf29.hostedemail.com (Postfix) with ESMTP id 0CE3F120023 for ; Thu, 21 Sep 2023 11:00:57 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=GGxYiouD; dmarc=none; spf=none (imf29.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=1695294058; 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=9OUktNkwNXjB5runbwWnUkYaH4gkQXyoyA8wphj6CxQ=; b=8AvrVAcwOx8Z7D4z/W+t+xDauu9lEDEo4q3XplSfuNM2QE3cQvpofrx+KbD4v9PWsTUyLb BHRlPY4zDhiSE7iB1CeyGZmOHQHWRscDWnmkohhkdLptW85bUpxNQ1SPiZ7lWSI61N321e G3M2BEY1isu9aFG5Yvfg4M+TYVX2jjQ= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=GGxYiouD; dmarc=none; spf=none (imf29.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=1695294058; a=rsa-sha256; cv=none; b=WnzrqnoHfFzbasdNw8PXVr6+fMEswFZ/PfgToRp035RjmyXYc4fmcHl1091K1NqBpGk22p IoB2DRKSqNvSlNO0sKKx+N2MdnCeLfBsewQwB4O+dGV7wk9dA0u0pwr2OcsDZn6jQ88Fij PaxyOL+xKPrWqDC3QE0EwYGaUyNjYAc= 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=9OUktNkwNXjB5runbwWnUkYaH4gkQXyoyA8wphj6CxQ=; b=GGxYiouDxwMhpCaPcVH40k98P/ XAfPr7EX2gzP8TckrBbk0itBDqh1K7L47qzj5ufg0WUG7Olk8Cby/mGQk/MfSUHpFcAoHFbPrC9vs EjyJVceNWZaOGslnAhpSgFyQciPs7Zl7wH+N2XntEXFqDsPfCoE6LiaK/AnohyGjrKsGsSQ089gs3 hlcFVZvN0eJHab3vYggwHl9ShJvSk4C58uCtLGwBHhEyqjaQe2iX2kH0aoMJkbcnplJDonkvdIIhK hXDu6aGgekrKWj5LYF6dmt9W2ciUrqRrAGk+jg2tMV2PEMXwjpNtLXqPV9S9yK+8ASFpo1IaN/Y4q uQIXkbmg==; 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 1qjHQO-00BTom-U1; Thu, 21 Sep 2023 11:00:49 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 26D833008D6; Thu, 21 Sep 2023 13:00:43 +0200 (CEST) Message-Id: <20230921105249.108410391@noisy.programming.kicks-ass.net> User-Agent: quilt/0.65 Date: Thu, 21 Sep 2023 12:45:19 +0200 From: peterz@infradead.org 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 v3 14/15] futex: Enable FUTEX2_{8,16} References: <20230921104505.717750284@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Disposition: inline; filename=peterz-futex2-small.patch X-Rspamd-Queue-Id: 0CE3F120023 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: njcemi3tiyq86oumqfa1hcikm1rg6h3x X-HE-Tag: 1695294057-799360 X-HE-Meta: U2FsdGVkX18jXEXj7abuOgGTn0qg37uD7KsWdAmo7M/RFwHih4fFxyFD2GefbUziYI5Zh9Cuc0sjJ16Qz9MTZ6Br9gq4gmPSMpbzb4J+ht8uraGhjWFbq3maGgIGDqd4HeE65eafiU2F0+e2N8CBgeIIcThSMIca0nmS+f2ZqiRu7SlIklv+pUvtIkSjsUs4GIWrE55RJ6yhrWLcS9oHHKynp3cxVDK2M+q81U0kYSEpeTIuPh/1NReWUB+EBkLLrfbWQd/XgIPj1le9gDq9prFFivwlIjk1BuESKXaJeG9rpidGDNF//LWL23W76pAHAXwQars0UFBcz3m/NNdc/axpmNNFmEQYMp2YnIInjg5sxQSplODipUuyWCgCFGW3mT++Mnf7WWIecTEqfXP6aMxjXo5K3FS95ja1r8hzjAJzB2OGff4jUOobQdflrW/sKdS6yLH25cpD9I0hzI+WFX7WuVXmf4RuQMJktMY5SEndfmWskYhE3IWZBrFpFLBV6g8roapAmUwu6WpeDu1vs5OErl05j8fDsQ+lXxW1HYMKvg4JJyG2DmnuO0+1bSo3iaJBMHMHnsV5CiWgt7KZpB4YG/jiTAZpL2ffxCA3MeewoBwZq215aph7zmxQcqk5chiYbR4MaWX3bdgWKqz7olbL40ORQKMYe1mJYrFjQNIfVBwTtAbravKQJ6dxxkw1HAlzkGUxzJQSoIBfQL4B/9ipWcHXn4XmlhkbsdnHG7kwAP0/eKkljy7nIEwUPCc6B4CQEt5N3h0SFrRE8vLKO0NDqOA5eFri1yzJig51Y8HuO49tzk/19jxRX0gwrOAXRT653rTvHu8TFZ/u41O75Np33QOrxjcufpJ63YgEbUCD9Y9hJ562+U/GCAEzGLfs2NwOL5ell7KGWyUdqQB5uDkLbGaR4TS2cSEVypkRFjh7V2Zat6cATgg1tO2RBW3ZodQDs+Jhw/kKtckxz3o C1t20f2v aPMU5VezwLTF4dFDylYZlMdQRaEqMJ98beB9My9IGw79F/9spUAvkLT5MGJEtbEZdDD8qfTf0TF4vHOsquajx7Q0VRxEhmocCNweoY77VZ1mRrjMcQ+Dmnhe+H65jobfx10D4ddUBXLY0hl5EB4LpDzNQVgNq276dsVvQ2VEg4zGqsF1ZeeVG82MHKmCcyaPxy/j5A++nZwWrKS3CbSy1CaNpQemKssrqWiKmIUhMa/xzGRf35d44U9Ud4ywvNYP1RxQL7mqkYZ2RJFsQCm5eB7QLlw== 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_SIZE_U64 instead of mandating FUTEX2_SIZE_U32. Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Thomas Gleixner --- 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(-) Index: linux-2.6/include/linux/futex.h =================================================================== --- linux-2.6.orig/include/linux/futex.h +++ linux-2.6/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 { Index: linux-2.6/kernel/futex/core.c =================================================================== --- linux-2.6.orig/kernel/futex/core.c +++ linux-2.6/kernel/futex/core.c @@ -311,6 +311,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. + */ + 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. Index: linux-2.6/kernel/futex/futex.h =================================================================== --- linux-2.6.orig/kernel/futex/futex.h +++ linux-2.6/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; /* Index: linux-2.6/kernel/futex/waitwake.c =================================================================== --- linux-2.6.orig/kernel/futex/waitwake.c +++ linux-2.6/kernel/futex/waitwake.c @@ -437,11 +437,12 @@ retry: 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) { /* @@ -609,7 +610,7 @@ retry: 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 Thu Sep 21 10:45:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13393853 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 4959FE70718 for ; Thu, 21 Sep 2023 11:01:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DF25B6B0204; Thu, 21 Sep 2023 07:01:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DA5006B0208; Thu, 21 Sep 2023 07:01:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A20F46B0205; Thu, 21 Sep 2023 07:01:01 -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 6CE3E6B0207 for ; Thu, 21 Sep 2023 07:01:01 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 3CEA31A08C3 for ; Thu, 21 Sep 2023 11:01:01 +0000 (UTC) X-FDA: 81260312322.22.62485CD Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf14.hostedemail.com (Postfix) with ESMTP id 1624510003E for ; Thu, 21 Sep 2023 11:00:58 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=SbTkocQo; spf=none (imf14.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=1695294059; 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=fyxg1ddJvWatw1JXyI0YYA49BqK/pr5vHXcY+zgsi84=; b=bCdwX8wE3v5jw4kn9OEhu1cbY6DDwNZH02v97+a25vmYSudd0S0N9kVVJz6HK3B1Gz8gia 1mqbB1ZVnavQ+45dtlI15Atw4ErVL1Ngl57H5TMHEUgGUtrhstg8OoT6ucKgpFDyezrnWs hMlfr2et9efFl2+jRAk5LcRXeR3T9j0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695294059; a=rsa-sha256; cv=none; b=mf2iK0aLyUdqOCqUsHmdxBrBTNzjrrC7xysRhmHNLo3yGCuZaeFl9D7qXe5yIxcFOQEKg+ WPvlJoUmwfgz+ydIR9QK77/L9SCM9jMJrU1OJELu9+6y3WCgZXk7tUAhgZuav7UHt/I7+E oXM+mQwlItrub2eXt7coPwFqfoWolCo= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=SbTkocQo; spf=none (imf14.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=fyxg1ddJvWatw1JXyI0YYA49BqK/pr5vHXcY+zgsi84=; b=SbTkocQo9lW9WukkQBhKrwBEuC BTd79yk4lKXrRgv0hqZylgiK6CARXtVkPsdmIWm6/46AEGuH2n3LR1XHR5vqf7W5IYTuUxuV7FfOQ Kmj05lyIjwafVCWmd3Lv8eTfRYeKH0MgPGAOkc9mdnVMpTUIcWluAEWmUKomy6Hfq/4shYj3h76wt XyBh9RvtpmlQ5Nxw8Us4u9ChhkBQwoKMfmQWP+mTD0UsUQIqzuN2VcuwUUAzrNw/se/mk/zSG0V01 0VfAFl6yjoo8fExKwlzWb3N5Ne1hFX2EptUsq32O5dKcdNokdFrlklW0Wi7kMKsJnd8Gg05FrK2F6 tH0xMm6Q==; 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 1qjHQR-00FJwH-0l; Thu, 21 Sep 2023 11:00:53 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 2C225300AFE; Thu, 21 Sep 2023 13:00:43 +0200 (CEST) Message-Id: <20230921105249.214313438@noisy.programming.kicks-ass.net> User-Agent: quilt/0.65 Date: Thu, 21 Sep 2023 12:45:20 +0200 From: peterz@infradead.org 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 v3 15/15] futex,selftests: Extend the futex selftests References: <20230921104505.717750284@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Disposition: inline; filename=peterz-futex2-tests.patch X-Stat-Signature: 6yy46ekwtkzfrtp6wzpob3jbcr3cwc1z X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 1624510003E X-Rspam-User: X-HE-Tag: 1695294058-665796 X-HE-Meta: U2FsdGVkX1949RjeqfOueazyvJW5SVIjIMN+zaZ3IpB1R2KzLiYC7S7tPlGFEMmWC5kia5H64OexnmPZml72NXJ8PkXyRYrJsC66AQvJfOayZS+AAsEAP3KowkmTxiBv0V2YpgqMLPug6XXYDJXsRivZR1Zn7jMZVECeH2av9L/s6UvgtE/MBY7I+0Bh/YRxst3yq3+r2AfMGrZSHzlqaAOOqct3UU8nfbkqELJ/8aNTQLeFAAukXQciVR7pIPWRPDbBkPk6BXHDe8KNfMrCoHTWlCVoDVZMjFdxC/a2scbjJ89p+YHn0UXOzZBrmxM6XR5aaYvC0B2lJkxWM3La7PzyymJSrGPDC6eVDB+HVnJSPcDVFngGjSMsREy0xiH2osHC4FK2PHdOz0K7JqS+ZYU1XW3WVSbh7b7IHLmSioCSS1Du05l/f5Q1aHQJxgx5NvlQplr/9REd9zt/zusAUwYcXoWOjY5l5JEZIks1vnDr5iUyEMok42/+KHmevcpHxdInkcDx/b2qQ6MiFhKyQMfickO9hJln4Mn0Q2j7hAV46/8euifzJn4La6Aen/BMr7K7NhPGQL4PjIaNINM+2GhFNF4xcjkc0/UUPVVVdAY4bwjWFFA2hC3q0QEh45pKerMsAEbtW8GbJeVfRzvVnYQb+u9lGnmO0brbzgs1YXqBSHgJybMxZPhll6cnSMQjRwWd2S95pIpSMjghBfCwtXZcd0kEEBh8dypePl55l0PtQG199FC9bKZ707MfsKhcyBB03QezD3aeUaLU2UTXcyWtS/lBA7wPx0mnTjIjkG0Lefeyrf6705a9LFrAKDFdhDB6UJz+G7XFJDhT54BNR1POWI4oZRihndBA88J0EGd/1KeHrfDdIu2fwUi0LvT6vCRDYSjTYnmthvOa/rvdW0grUp5y/XfaPUa7E8+f41qr506zIUV8vjWbLmU9G7LsmiQ/sNhOgsrTx3wXiBK SgyEoWFF BolLqTYx8TSFiAA5Qxt3nw8aGLayJ9pSlv4L15i9aOsLt8OV2jnhSNW6uIQoEft0C8acOEY5vkCm7S1WBgxEQTW47ICzy2eJprrA/K1AlCjWOzdmdKVO8M1C9Xyi1fWa4UM6HVGvJmCLkzpH2pFEq9iJk7AO+BDcvecvp92Gj1yRE8QtAhmbQKDr8dlA5/n+hj9Wjm0Oy9T2cW7ZC835ZDv4sEC8/sWkLh3cZpO31Q26UszQ= 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(-) Index: linux-2.6/tools/testing/selftests/futex/functional/futex_requeue.c =================================================================== --- linux-2.6.orig/tools/testing/selftests/futex/functional/futex_requeue.c +++ linux-2.6/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_SIZE_U16; + mask = (unsigned short)(~0U); + } else { + flags |= FUTEX2_SIZE_U32; + 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_SIZE_U16 : FUTEX2_SIZE_U32, + }, + { + .uaddr = (unsigned long)&f2, + .flags = FUTEX2_SIZE_U32, + }, + }; + 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_SIZE_U32); + } 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_SIZE_U16 : FUTEX2_SIZE_U32, + }, + { + .uaddr = (unsigned long)&f2, + .flags = FUTEX2_SIZE_U32, + }, + }; + 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_SIZE_U32); + } 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, Index: linux-2.6/tools/testing/selftests/futex/functional/futex_wait.c =================================================================== --- linux-2.6.orig/tools/testing/selftests/futex/functional/futex_wait.c +++ linux-2.6/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_SIZE_U32, + &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_SIZE_U32 | 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_SIZE_U32); + } 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_SIZE_U32); + } 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)); Index: linux-2.6/tools/testing/selftests/futex/functional/futex_wait_timeout.c =================================================================== --- linux-2.6.orig/tools/testing/selftests/futex/functional/futex_wait_timeout.c +++ linux-2.6/tools/testing/selftests/futex/functional/futex_wait_timeout.c @@ -128,7 +128,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); @@ -201,6 +201,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_SIZE_U32, &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_SIZE_U32, &to, CLOCK_REALTIME); + test_timeout(res, &ret, "futex2_wait realtime", ETIMEDOUT); + ksft_print_cnts(); return ret; } Index: linux-2.6/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c =================================================================== --- linux-2.6.orig/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c +++ linux-2.6/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_SIZE_U32 | 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_SIZE_U32 | 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; } Index: linux-2.6/tools/testing/selftests/futex/functional/futex_waitv.c =================================================================== --- linux-2.6.orig/tools/testing/selftests/futex/functional/futex_waitv.c +++ linux-2.6/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_SIZE_U32 | 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_SIZE_U32); 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_SIZE_U32; 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_SIZE_U32 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_SIZE_U32\n"); } /* Testing a waiter with an unaligned address */ - waitv[0].flags = FUTEX_PRIVATE_FLAG | FUTEX_32; + waitv[0].flags = FUTEX2_PRIVATE | FUTEX2_SIZE_U32; waitv[0].uaddr = 1; if (clock_gettime(CLOCK_MONOTONIC, &to)) Index: linux-2.6/tools/testing/selftests/futex/functional/run.sh =================================================================== --- linux-2.6.orig/tools/testing/selftests/futex/functional/run.sh +++ linux-2.6/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 Index: linux-2.6/tools/testing/selftests/futex/include/futex2test.h =================================================================== --- linux-2.6.orig/tools/testing/selftests/futex/include/futex2test.h +++ linux-2.6/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_SIZE_U8 +/* + * Flags for futex2 syscalls. + */ +#define FUTEX2_SIZE_U8 0x00 +#define FUTEX2_SIZE_U16 0x01 +#define FUTEX2_SIZE_U32 0x02 +#define FUTEX2_SIZE_U64 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); +} From patchwork Fri Sep 22 20:01:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13396387 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 47195CE7A81 for ; Fri, 22 Sep 2023 20:59:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2CEAB6B02F1; Fri, 22 Sep 2023 16:59:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 27E5C6B02DE; Fri, 22 Sep 2023 16:59:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 129C96B02F1; Fri, 22 Sep 2023 16:59:26 -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 EBF1B6B02F1 for ; Fri, 22 Sep 2023 16:59:25 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id BFA551411A3 for ; Fri, 22 Sep 2023 20:59:25 +0000 (UTC) X-FDA: 81265449090.29.7E94E2D Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf27.hostedemail.com (Postfix) with ESMTP id 2788B40023 for ; Fri, 22 Sep 2023 20:59:21 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=hktQlK3I; 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=1695416364; 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=zWIQ6Yi556U65myk2PzRkq/DHdsIiBTxeyqBKDx6r2g=; b=WEYlx7WJy1Lgv4srwwGnkdIUVl5OyYbxaInihXWd2hLwq7Fbuf0PzGzhQ+fLD8MtZE6rKe OwIJNMjOJOIBxs7QEVCzh1+yJqSTLr/pfntmMq1S2eTXSIx/IJqPdS7Ism6r/YQqOXc0gZ uj2asdcJV/ld/3eb0D78ZGiIyhyeOiM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695416364; a=rsa-sha256; cv=none; b=yFWQciN4a5/cNJOmCYH8ZsiRM/GbANLQWKVKjlWG/IAS2mUAe57iJOfEoqPaQ8H6j3vNnR W9xZopDE1dwEYyb5QjwR1NXPNNjy43j05BW0lIATZ3KTirALTPrqgexd/rfbhdkVx2B0vr 3mP+J1Ess+QZgLlxWYlwVo6FfaLPrZs= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=hktQlK3I; 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=zWIQ6Yi556U65myk2PzRkq/DHdsIiBTxeyqBKDx6r2g=; b=hktQlK3IZ5z27ejm1FLGbbL1mo mzMcjkhwk3cOL9uWlaupMqvTCXnVZAoT6CJRQ0M29Q5yLP4ldsnxOmGjX4q6rjSEI64QiOYmhDBl1 P34q0qimycD9b/kQhEEKct+8KTKDGbkWMwSTmS278soTtIfi9R+SqnOIrE5sNsyZz3ma+fTYPc4zF 1bnVko5qUEoPXj7iOJw+xXKE+NPyQD41xo32nxvuoljsm3NlHTZLfVHISoB7SITHfEz+0mYyjkOq8 DkRxp0jw7F5ICVHtOBTQtELeVEyWis3tl7y1KZ2CkP3ihqlF98Q0ECbL3/aloKy0AEDNlzdBY/hIg FSIpHA6A==; 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 1qjnEs-00GXzC-2v; Fri, 22 Sep 2023 20:59:05 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id F0DDE3008D6; Fri, 22 Sep 2023 22:59:03 +0200 (CEST) Message-Id: <20230922205450.033535181@infradead.org> User-Agent: quilt/0.65 Date: Fri, 22 Sep 2023 22:01:23 +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, steve.shaw@intel.com, marko.makela@mariadb.com, andrei.artemev@intel.com Subject: [PATCH 17/15] [HACK] futex: Force futex hash collision References: <20230921104505.717750284@noisy.programming.kicks-ass.net> <20230921104505.717750284@noisy.programming.kicks-ass.net> <20230922200120.011184118@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 2788B40023 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: ojmxktkwsqsmokc5mwmypee6gw5fifce X-HE-Tag: 1695416361-122592 X-HE-Meta: U2FsdGVkX189V4QAJ+BH+Mw5DVhw5wAS3FjGGQdiaRU+y8pw92oD5pm6mI4gbFXP5zU7jXZpRnpfw0RY06ND8NHPLVi6gfLed21FBZOIYf3LQNcNQciVHyLx+3ZD+UnsiAFnWTnpR7dpOFJU6GBHqjFmOkSD0xu39yCQDbBk6cz7GJ61Mc5sB98Q7WP1LJmSQV7Ri8pOifnxAr/ER4mKawIHaEIAwUm/KMW6i0tnw5guo4e7tGlUT4Clopuj0sj4VIBWwuB+PfsULdXP57kyQM0C1ONQgQp9x50FUjDlO85QNaJA7nE2Gs2sByhlaH1qs2XosjXSZaQKgT+vMlGcDvxrxQSwgpt9YPmR6PcpBu0tOvHPeIn2AR4KVS0jZ4KG+NaZvPcfDtuU2RTne+qeCPOQh5IfGBwHlXGSvI5oJiNSPOzh6fVt74crFsu05ZDE97RJQUSYX1MB7fbwCJtdYZKozt1ZdVJkPvZXIDlrzPGAYwgJq3S8T1SLqFXDxjZC89X+fhnGMStR/7jAnvKP6TryHWHGmdE64H+0qparPNMIvP40jqOacT4g9PJYv49ItB5zW1GDSCE/JwntElijXuLEsdfnOB+l2GRUZbKwUVG51tm2X8/TVnjI3ycJYT6BAY8TA/OngxBvPgZNyBqBhJ7kLS4rw5CLW5eDy4NJ4E0R2AX9mMUKU6VcLmbmrb8ndpGtU1wLaKPEOkbrea5WKWOP5af4QhLbNlNYyhVd+RSGdfFvt/9ijqnHHQqtBukNnkHRKNlhxAQs/PCL/tRZ6gDyfyi6cHRSULjVfnXHUDNx+K/FQjs2eTwq1vs1s+5hZntuetAgiY56mt3HhdYygSTXrN+hF8MTqNOmHUnNE6xJqkoGT8g5BgH0yqnR2TXf1KIUKQJE3mEhkxQOm967Qz0nlZO6qzORWDY3ZjesCN7Z7XH20fu99N3bfNzSkShFuagShqFNNwwmkR8Uu9W V78vsWvT gp/lVharEk9JUCn5LltmlNTkOFU8BVeRLnygN1XAvPeaE3KZLb1902gzeMDml+P4sgrJffx9JjXMa/k+kmajzC7GEpX+1+fsid2BBdnwM0i15XWuHjc446yj89jXs+JJ4ACyjeNtXTtE7IA597o+T4UjbNAJP8ZunuMXcPECjLxnDEk0hvrptMtFsyGo6chfNAsAZC8+KYWfwMI1/isVVHrFBc6tM38e+U6qzaRCseJMqRUA6s5tI0mzMcQCCrPo2gUiZO0MNKdMBRxX7t8ydDOviqg== 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: If you hate performance -- use this. Signed-off-by: Peter Zijlstra (Intel) --- kernel/futex/core.c | 6 ++++++ kernel/sched/features.h | 2 ++ 2 files changed, 8 insertions(+) --- a/kernel/futex/core.c +++ b/kernel/futex/core.c @@ -128,6 +128,9 @@ static int futex_put_value(u32 val, u32 } } +#include +#include "../sched/sched.h" + /** * futex_hash - Return the hash bucket in the global hash * @key: Pointer to the futex key for which the hash is calculated @@ -159,6 +162,9 @@ struct futex_hash_bucket *futex_hash(uni } } + if (sched_feat(FUTEX_SQUASH)) + hash = 0; + return &futex_queues[node][hash & (futex_hashsize - 1)]; } --- a/kernel/sched/features.h +++ b/kernel/sched/features.h @@ -89,3 +89,5 @@ SCHED_FEAT(UTIL_EST_FASTUP, true) SCHED_FEAT(LATENCY_WARN, false) SCHED_FEAT(HZ_BW, true) + +SCHED_FEAT(FUTEX_SQUASH, false)