From patchwork Mon Aug 7 12:18:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13344116 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 69F2BC04A94 for ; Mon, 7 Aug 2023 12:37:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 490FF8E0002; Mon, 7 Aug 2023 08:37:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 15E1B6B0078; Mon, 7 Aug 2023 08:37:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DBA6B900002; Mon, 7 Aug 2023 08:37:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 3C8F0900002 for ; Mon, 7 Aug 2023 08:37:10 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 11ACF160A2F for ; Mon, 7 Aug 2023 12:37:10 +0000 (UTC) X-FDA: 81097258620.12.65E18AF Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf17.hostedemail.com (Postfix) with ESMTP id D77F940003 for ; Mon, 7 Aug 2023 12:37:07 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=eqmLvazG; dmarc=none; spf=none (imf17.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691411828; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:references:dkim-signature; bh=53jHvCThY56ekVsZwPC+RAqN66FMg8fPTI36UoUqaKU=; b=ZaSbHjk0NJbTMO1nSFAZJrf6jtgnkdGMmgFw7m+3M9UGWQ9pNZ4iZK94EJvlgqkH7cIJ0J nyAlH0Fgcjkp2sZCfYetAm5132agtmT+pfN8TOUMnI5cokuVKuAXRMwbLN3W4b5hCh8yA+ X+1qhOltQcj/5vO763dMyvr8+HsrhrI= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=eqmLvazG; dmarc=none; spf=none (imf17.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691411828; a=rsa-sha256; cv=none; b=ZlBrDnhbEb0upyJaIw6Yk+JlpKFjREouSwz/4C1l5PjbKFn5wWztDjgJamXeh5lcW7RieV rHziHlcUskZO6bzh/t5Dmj4VMEZOBtlJCHUvlkRbH3Qkm2s4B7zAHu9Fl565LbjtHTeC9X qwtA5dx+tat9NgbjlDwe8Nsue8rUA6w= 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=53jHvCThY56ekVsZwPC+RAqN66FMg8fPTI36UoUqaKU=; b=eqmLvazGl7vBH7qJgPl+mV8Rn1 Db9gNWnIQZ6A9f+8x4iCTa3tOp45OF1tMlCfJCzFVwpufed2L7Syzuc7UOY9iih9D4mimwCVtlcDQ 5FAN+SfFoNcoZgnC0ba/iDFxh6N7opePHRF2GS1XFSgF6jwb1TdsPczXS237JH48Uo2hQM6B4//4N 5GuRLi7XiTPgNCyPEcQw5aln/fT+PUo0QdWUVkjjAyoUG6MzYF3TqTPqdrdvCZsTN9LYGFKD0FGFf TQK0/YtXVD4x9hkj8ivhhhRiVCQ2Rx4zxOsKNOlw0CNxd3aDi11330mX1Q9ng36kvGJP2ha83Y9ht EjcAsWdA==; 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 1qSzTk-00AxFz-Rv; Mon, 07 Aug 2023 12:36:57 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id D39913005A2; Mon, 7 Aug 2023 14:36:54 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 8A81C2021C3D4; Mon, 7 Aug 2023 14:36:54 +0200 (CEST) Message-ID: <20230807123322.814039156@infradead.org> User-Agent: quilt/0.66 Date: Mon, 07 Aug 2023 14:18:44 +0200 From: Peter Zijlstra To: tglx@linutronix.de, axboe@kernel.dk Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, dvhart@infradead.org, dave@stgolabs.net, andrealmeid@igalia.com, Andrew Morton , urezki@gmail.com, hch@infradead.org, lstoakes@gmail.com, Arnd Bergmann , linux-api@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, malteskarupke@web.de Subject: [PATCH v2 01/14] futex: Clarify FUTEX2 flags References: <20230807121843.710612856@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: D77F940003 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 16quya88i9mpdp6s9r76ecc7cj9fusor X-HE-Tag: 1691411827-505605 X-HE-Meta: U2FsdGVkX18eA9Ol54IlV2RZnx1d/GXdaT8PaP7OlouzywFLGa6P4LA0H40xqunAsg/8Tw+fv5HY4yNFoAkXisje8q7gAIPjuKUqohHFgRMv251Zbc2VqqPS57r5OoynQPcXbks92rEd7ct8AQu0syojGS8XKtedNK968ZhXJ+EQbSRQRvhroKL+8u9rsiMN9Y6GeO2o/Vaq6c69uyJk7wE+Gj0JAAkTC67U4z4G3PlQ4Evq37mxtGhJ2Ec+JDNeWfG5fOALgDPfiqBXQTSPGXBWPOrpDrVPBR+L6rEXVDB2GByt95UI2WATrEsw/o2HnZi7LUUBPcu0ypq4voApLKVFwM/Xq+TegQCx7NKl+gM2OBBKg1DioO2RC6CDnmpAwV7rtDCQLMoXgnEsqnCxfj6EWwy0r8rNSygjrbd678kPwnfVZEkywdwZR8Oq0m1xwddcFQu/AFkdvXqUop4LLA04O7WQND7Ame4+3bhjGds6Xuaggzy+5pi6cW5AIStOFka3RHdgLA5QOPtinI3NRtsyfOaQeTB93QbJid+POVxaelTbCtnErS9ALsBEHI8P+ua+13kRLI+R5sBecFAf7tc2HuZ5xpbItRdeJREvVeeGMUGAcbKKacursv9cdtrW8uFLvzhw4XzEq+Po7j60Sq8um6pokMqP/GvaBBFgx4S+4Vfr9RxrwF+r4ktJ/81kRgr1ziaaFXF77DEdHZ5cYIAFRvTeczN8eV1iiqeGeH1RirYJDyF3cASObMFeSYFToC7/ZmtwLHw4mtiaaQi1mDGJ7FTpyOK25aYfDEnixaRO6XMf7F20AHqR3ogJLbYD7FPS7o/BvG4FB4CjLENob/cfVeZe8/ISZ82ijybZjpIfj1vm/A5EThMSwSyfVlugJJYO+VhIRgVqzD1aie8KGxLLKmlYQSL7ZDWjTfN8C+ZNNvECy8dw+sQPxfANO+J3pMNuIz5/uHyqnRkCPIU 7O2vdWyw VJAZJzToyjNj8bzduTEOp1QbqYWWkR0yP3lR6zOKafvKPWA6FpSocyhLhz/pW2X7ktRVrcrzXdidPPEXyRp3ykiZh1qrALTQaAMerPafLVc9BIO3Xs0tR64aEzhMtPM9TW7VWyIc3CITlBtetEcxN4eJYC080XtQaVDaFQhEOr65CZsSSFqGmNeccCWeeMnRepSsPEvH23PyJBdXqotIIDhnFitrbkHXnAZFV8H94VZl8BgN58712zAelz2o6QBVDS2vFKbLAq1aGt0XoyFWZ4TtTrQ== 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 Mon Aug 7 12:18:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13344171 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 2446CC001B0 for ; Mon, 7 Aug 2023 12:55:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 935D16B0072; Mon, 7 Aug 2023 08:55:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 90D5F8D0003; Mon, 7 Aug 2023 08:55:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7FCC78D0002; Mon, 7 Aug 2023 08:55:39 -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 7302C6B0072 for ; Mon, 7 Aug 2023 08:55:39 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 45D611608E5 for ; Mon, 7 Aug 2023 12:55:39 +0000 (UTC) X-FDA: 81097305198.21.44753E3 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf23.hostedemail.com (Postfix) with ESMTP id 18130140012 for ; Mon, 7 Aug 2023 12:55:36 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=Y0Ic2ASP; spf=none (imf23.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=1691412937; 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=VeisDNjC4AzLF+2mqHFPpkzGGrK09hiTJOlUvJPWkc0=; b=kxpn0jk7JHVeIWxgqt0g7ourdtbmiPinl9Iy64TFviCaIdeepjJrBkRiDCHHO3VFDz7yd1 vfPfhL8omrDF6rmB/wY2iV7RS+38XIh90BNJ5x5bFrCIDvuVIvTvZFjqxZ9hHjUlC7NV/W 6Nh2TGBqCf2sF8mqJ/RvrIjKA+N5u68= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691412937; a=rsa-sha256; cv=none; b=2uH0Bi+TzKmzUHP/1I8waumdAGXTQLwOZQgJFseA4zAZ9Jpw9v6ML2H1x9DPGdFut6t6hG 5mDb5GuSrY6MwGnyrFNJUt+TXIkMg719aZ6ATJud9PVyilgtqVuUK1p00lxqqgb9uDKMWW J7y88Aks/NB1NPMqzytkOvUNb+4siOs= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=Y0Ic2ASP; spf=none (imf23.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=VeisDNjC4AzLF+2mqHFPpkzGGrK09hiTJOlUvJPWkc0=; b=Y0Ic2ASPfM4zwCf8njfDLQ9TfI OuHwsWViCbzS/XDUIJxYEuz+6570rMjB76ialdlDvBGnoZ5f0lGB/AZPHEL1zLVvE+0SXP3E9NKXG aChDsIyEWqNqEjGtk0KBEbmdyoBkO60j1QC7lLf0GPh1j3ArPWtOzZPV1lbRjDAWphs19H93MFN/Y TuDXZNeMFZiuB7FXopYB4UqHciRVwN4uVfSTNPU0z/3z4PBBCn6Q/8fMMasBpNmDC+gK3mHnZENIx 4WJRUxHLhoH2oxp5n9XSV6JwbcpNwv/1h/idKQawLI7xtQnn4TDuz8SQ4B7D5AQpkC0GsM4dn+LC8 mUPicgtA==; 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 1qSzTk-003oSe-1T; Mon, 07 Aug 2023 12:36:56 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id D56643006F1; Mon, 7 Aug 2023 14:36:54 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 902A920236021; Mon, 7 Aug 2023 14:36:54 +0200 (CEST) Message-ID: <20230807123322.883413972@infradead.org> User-Agent: quilt/0.66 Date: Mon, 07 Aug 2023 14:18:45 +0200 From: Peter Zijlstra To: tglx@linutronix.de, axboe@kernel.dk Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, dvhart@infradead.org, dave@stgolabs.net, andrealmeid@igalia.com, Andrew Morton , urezki@gmail.com, hch@infradead.org, lstoakes@gmail.com, Arnd Bergmann , linux-api@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, malteskarupke@web.de Subject: [PATCH v2 02/14] futex: Extend the FUTEX2 flags References: <20230807121843.710612856@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 18130140012 X-Rspam-User: X-Stat-Signature: kk6amdos1psg1bcu13xh6yqngecig4o4 X-Rspamd-Server: rspam03 X-HE-Tag: 1691412936-588943 X-HE-Meta: U2FsdGVkX1+Kp1DnwCJilaNsYbKQ9CJWI3vfpjcdcQdTuObdG6ZccaSgMbkczjcCHGPv6YOaeDhuc8jtHe3B9ghoIzLCdWCleIGl+YsOjni/VteNDIz+CGcxYPcIAQnR5YcZtVvMimdoRcRFaqy8+R/om2NiL+s5aFRj7zDCis7ct4p+/pGhCV9mU6xzwcnoklhbLYMtG9VXDcumWWZSQf0eunJZ++YUJuMdhd871OzJaulgblC0hgHvS0bCi0R+EIaUl4GZXDkMRL/5O8BOeJDN79nyoEt518kJ0wcHErORAhrArZbr07Cj9yn+KVVdXNPSl95dLMEqpNddcBhxVcxd/bEQu28v4GGGEcCiVLdeQVKA2a7FPj6VXvKWXrz5gmd383hBI3HALg2vco9Qy2F+RsX/yHOpTiT8FU2aUM+lDup24allSQr8Q/cs23ymvEwRPmdmoOVh4YczeLJy1TfainVMkbdlHptDVDDZkb0v6rK/VbzRpqXau/tJybFRwELbGE8FXfEkNryWCf/f64/dto6r0/NQ1l5DiCv3paycRjx6wRmzOyskE/HZYlUyet3tlniWf/5pVvyr2/773r2+NQfh42KF4VeNgyoxdeZ1R0ioVCplDXMu9jcp/9QuSxepomT/B8obnpLwvw9UFvj1dJiFOMCFken8Uxm4gNhZ07vCVN1opLervBuGMuTS4v0erlCe/MKaJ2LDv3qNDqb3oYd5m6nX74T75Qi8uFEmjkYidE6C+Cy3VxO/YEpomOYvj8oZBx4rigu2mG5kR5NUVCtW945h2Jl3dNMWhVseXqaf1i4e7YXi888Ek0dIL5MIMJWPE3Xp9Roa8ldfBT3DUyQxy9kAVpO5rEHOjsL76AaCvUX5RLZKWYsAh1rxM3LlkO1OJ9/Xb9MiOOkKyEBCmidX5GGrDevN50ypUWDolB5uyaX1Ge6TSCwfZXPuIrMLPlKjwbBS3KgNZx1 8R3kmRaV QT/X33aONHY99UEBurdeCgf2HId+MGF/kt44cf1C6TnhkXydlH5YJbO2/BHM4ySgGKjNpKxqoapmgGW30TkYLtwMSx8UoaBexl4ClosVWEpva8c6COOuvYZ7pYyT51l9z4v0Ohc5vcCJgA3GArJKa9ikvYcYsKZuZf/XupxrS5icAoGMoIVFJPpmtvS9pXgu6IiNjOJOAv/mS5fomkxp1qjGpiOx3mJMAcfrgnTgj/aTpxjU= 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(-) --- a/include/uapi/linux/futex.h +++ b/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 :-( */ --- a/kernel/futex/syscalls.c +++ b/kernel/futex/syscalls.c @@ -183,7 +183,7 @@ SYSCALL_DEFINE6(futex, u32 __user *, uad return do_futex(uaddr, op, val, tp, uaddr2, (unsigned long)utime, val3); } -#define FUTEX2_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 Mon Aug 7 12:18:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13344179 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 D6EF6C001DB for ; Mon, 7 Aug 2023 13:03:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3BE0B8D0003; Mon, 7 Aug 2023 09:03:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 346638D0002; Mon, 7 Aug 2023 09:03:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 20DBF8D0003; Mon, 7 Aug 2023 09:03: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 0D8C38D0002 for ; Mon, 7 Aug 2023 09:03:37 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id C85CF1A0AC6 for ; Mon, 7 Aug 2023 13:03:36 +0000 (UTC) X-FDA: 81097325232.21.8CE0C92 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf05.hostedemail.com (Postfix) with ESMTP id 35D1F1001FD for ; Mon, 7 Aug 2023 13:01:46 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=HVQVCCwt; spf=none (imf05.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691413307; 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=w9vOIgSzc3lTdvJPA8NMQRoDG93TaTUpiM2kUBnJUKc=; b=c3Uvzs9977x0ac8178ainVqxh5iYfAcUj3DsYnz9bMqaHrdrK1M6ihyhFxi2p7CmN/LEIH xu4ljt0NWvHUWMp1gw9L+NGtck2gZ68azPu2rtMJCpULn/A8MpLE+p/4qhUZNyd1W3jor0 jo4ljbCtyIj0CFvncf26lRk3jb8KiOk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691413307; a=rsa-sha256; cv=none; b=Jojw0MYSn94OQc3PMtpLmohgsOw3QDBbEl5m6QOIpExqVuO47SJGyo0thIzle6+S0zKp5/ k7bZ3l+m8q3zvPHu/e5+pRWbdejgHtLijwBqFSPZuwORDl22FZqKYIzYghkUWtrS6Qk+pg 8O7ODsgrVsjEt0595UWRqHyq8gzsxqo= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=HVQVCCwt; spf=none (imf05.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org; dmarc=none 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=w9vOIgSzc3lTdvJPA8NMQRoDG93TaTUpiM2kUBnJUKc=; b=HVQVCCwtOi10B4bKYKmHp+D8Xn 3Mwa7mNyJqgKtoSRW8aoRhg2wTYWEV9bu/9nUYfTmEk+3fz/rBjtI7q1THMC5ThblPseixtBckC3P jjsb4x5Dz2mO5rtOJ9ot0TyP3uuCeT8xgf7r1l0LNK1BT5L6Qi6StGFPGzQmtVQY9lWOzBzHyC66H q+xN/XwnxvVLzZCjTSvnUwEl4A5jKDjzYcTRry6ZggG2oevtz8yX4SWXiLop/BFRdUUsRCip7yNiw js+pcKYQeW/P2tUP49TmzRMkJdXA+QWfsKkYRpUYtcwdtt5yxgOY5SqOCkQ1ofSU6Lq0Uq+3lN0Wc sDcW8hMQ==; 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 1qSzTk-00AxG0-S3; Mon, 07 Aug 2023 12:36:57 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id D731E30092A; Mon, 7 Aug 2023 14:36:54 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 95E432029B0A3; Mon, 7 Aug 2023 14:36:54 +0200 (CEST) Message-ID: <20230807123322.952568452@infradead.org> User-Agent: quilt/0.66 Date: Mon, 07 Aug 2023 14:18:46 +0200 From: Peter Zijlstra To: tglx@linutronix.de, axboe@kernel.dk Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, dvhart@infradead.org, dave@stgolabs.net, andrealmeid@igalia.com, Andrew Morton , urezki@gmail.com, hch@infradead.org, lstoakes@gmail.com, Arnd Bergmann , linux-api@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, malteskarupke@web.de Subject: [PATCH v2 03/14] futex: Flag conversion References: <20230807121843.710612856@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 35D1F1001FD X-Rspam-User: X-Stat-Signature: 7pkufy94ka7p7bchegt5h7jb17p5jsyf X-Rspamd-Server: rspam03 X-HE-Tag: 1691413306-189872 X-HE-Meta: U2FsdGVkX181bj31NB1ymNxymDsNRX5ruihWGWfpIzArke9phKE1rN1/uberXbiac3yNgPwpzpmLX11/DujU84BjEr+5+7FpbVd6jTthwz/MCkK8aeuz8ul2q1L15YLRYdC6+ESnh7bkiM42k3ube7/CF5yRTPJ01w7vKHeiWwiu+GZkjKzRxNxMV5yikcucuPTFOSLCcOXlZxZ4ETpUjLFuor1Qz86CR502ghBYDpfEv4DfXFYwUgzrM2GsSpvkytMPZqIubJm4S8w1fnyulPwjquBi2Ua58x7u+kT/AYJJlyJKhrvy6Llv0b3ulavG1bbnWyUN3e7Zv4lOVTilVCJtbTSuMAobsgPpfN5JBpNAHzwHppJ4oUvEKQvC8+VUGBad24mVxg9lPeixrfNhdc74B8PoAUdbeMh2XbvOxZ/mslPio3YLQUEdKZvlU7T6bmDbkbPEUyk2a0fxbcxnthbm3jGiCeqdASM+2jOxIeYwrX0yOS5ZXfwUdgcvH0iSzt7m/B5bJm+afSxBXzewi/wBpmoouqrB4rL/1GYpOChWRcHzQHAu3PpWhG1QtZvAMgz7xO1igkyxg36Zp03fX2ZVw1SNYNjRnqAwW3ElRw4XPrjUjtKqc+sRR+T9/WKA/yrF9C3+GoIOcPdeH9frSrnpoqrncS4PDeDlc06YTo4aA8JdGJT8Ukr/XcwEpD/l16HErUASo4U/f13t9P+1wOyrtTw+M2S/pfg+FxEvBQHltPN06W+YhX8zDIG//KyZ1QMiTEQbC8mpY6k7t3hHqiUYnu7rahj040UVFWm26eV7fEn66eghPo3T8GEPxgjfM8ogllGqd3kw6lsHLbv0DI01m7dPjYYA/zg3dPOwrB3QyJfUnhg+A7s9hgrvDdTnwNyLEhQGwDxj4b+vxKLnPXhVoP4SBqd7PwJ59qyhVr3PTBmAt8MNvMImKVIcIF5siobs++X1Fh3N+49B1Zo QukIRPAi jFjuzhMPDPveqAm24d/EYBIZujszv2ighQa9kDJLXP4saRU2DR3po7lUUojP4AZT+Ytu+u5QtrVUHso4vng6xk+/DKQSOJ8f/J/K4IGnd8D/bSl9D+4DVjNd+Zv42sxkG7FB1py8xYuguSaFbZRqdJxXWUE96htwPogVXXf04IsdPDB9uR/2bM0Xb7iH+I54HzpJ/6HZHxIG83nmbLUVYidSG6nf0Rd+bDp3AXckSzD+HxnarE8STcjqzXWc9D7W9cDlsaCjE5PazgZxTG6Jb/wvrGQ== 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(-) --- a/kernel/futex/futex.h +++ b/kernel/futex/futex.h @@ -5,6 +5,7 @@ #include #include #include +#include #ifdef CONFIG_PREEMPT_RT #include @@ -16,8 +17,15 @@ * Futex flags used to encode options to functions and preserve them across * restarts. */ +#define FLAGS_SIZE_8 0x00 +#define FLAGS_SIZE_16 0x01 +#define FLAGS_SIZE_32 0x02 +#define FLAGS_SIZE_64 0x03 + +#define FLAGS_SIZE_MASK 0x03 + #ifdef CONFIG_MMU -# define FLAGS_SHARED 0x01 +# define FLAGS_SHARED 0x10 #else /* * NOMMU does not have per process address space. Let the compiler optimize @@ -25,8 +33,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 bool futex_flags_valid(unsigned int flags) +{ + /* Only 64bit futexes for 64bit code */ + if (!IS_ENABLED(CONFIG_64BIT) || in_compat_syscall()) { + if ((flags & FLAGS_SIZE_MASK) == FLAGS_SIZE_64) + return false; + } + + /* Only 32bit futexes are implemented -- for now */ + if ((flags & FLAGS_SIZE_MASK) != FLAGS_SIZE_32) + return false; + + return true; +} + +static inline unsigned int futex_size(unsigned int flags) +{ + return 1 << (flags & FLAGS_SIZE_MASK); +} #ifdef CONFIG_FAIL_FUTEX extern bool should_fail_futex(bool fshared); --- a/kernel/futex/syscalls.c +++ b/kernel/futex/syscalls.c @@ -1,6 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-or-later -#include #include #include @@ -85,15 +84,12 @@ SYSCALL_DEFINE3(get_robust_list, int, pi long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout, u32 __user *uaddr2, u32 val2, u32 val3) { + unsigned int flags = futex_to_flags(op); int cmd = op & FUTEX_CMD_MASK; - unsigned int flags = 0; - if (!(op & FUTEX_PRIVATE_FLAG)) - flags |= FLAGS_SHARED; - - if (op & FUTEX_CLOCK_REALTIME) { - flags |= FLAGS_CLOCKRT; - if (cmd != FUTEX_WAIT_BITSET && cmd != FUTEX_WAIT_REQUEUE_PI && + if (flags & FLAGS_CLOCKRT) { + if (cmd != FUTEX_WAIT_BITSET && + cmd != FUTEX_WAIT_REQUEUE_PI && cmd != FUTEX_LOCK_PI2) return -ENOSYS; } @@ -201,21 +197,19 @@ static int futex_parse_waitv(struct fute unsigned int i; for (i = 0; i < nr_futexes; i++) { + unsigned int flags; + if (copy_from_user(&aux, &uwaitv[i], sizeof(aux))) return -EFAULT; if ((aux.flags & ~FUTEX2_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; --- a/kernel/futex/waitwake.c +++ b/kernel/futex/waitwake.c @@ -419,11 +419,11 @@ static int futex_wait_multiple_setup(str */ retry: for (i = 0; i < count; i++) { - if ((vs[i].w.flags & FUTEX_PRIVATE_FLAG) && retry) + if (!(vs[i].w.flags & FLAGS_SHARED) && retry) continue; ret = get_futex_key(u64_to_user_ptr(vs[i].w.uaddr), - !(vs[i].w.flags & FUTEX_PRIVATE_FLAG), + vs[i].w.flags & FLAGS_SHARED, &vs[i].q.key, FUTEX_READ); if (unlikely(ret)) From patchwork Mon Aug 7 12:18:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13344114 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 2236CC04A6A for ; Mon, 7 Aug 2023 12:37:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E3A08900004; Mon, 7 Aug 2023 08:37:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B49A46B007D; Mon, 7 Aug 2023 08:37:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 79FD18E0005; Mon, 7 Aug 2023 08:37:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 2CB188E0002 for ; Mon, 7 Aug 2023 08:37:10 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id DF46A140A14 for ; Mon, 7 Aug 2023 12:37:09 +0000 (UTC) X-FDA: 81097258578.10.95D7C8C Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf30.hostedemail.com (Postfix) with ESMTP id 087F280016 for ; Mon, 7 Aug 2023 12:37:07 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=Co5btgZE; dmarc=none; 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691411828; a=rsa-sha256; cv=none; b=oLZzVXGafNw069f8YD2+61WOGMeLF8PmJd5IDKDD1/48YgdaahhM5m1uTnaxcrQwS+wTM4 ypjuLUNg2Cq4eGgiV0o/APN42jHglZPRJ2g+2MWjIpA7+uCZKFflXVd+5A0xs95zbJpSHR 745a6NWu3aohoQi9Mqh8p6lppjXqxWY= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=Co5btgZE; dmarc=none; 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691411828; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:references:dkim-signature; bh=1Epi3uPitQ1on7D3YBD3uiLy0TLxJfWf5bL2Vyq95Dw=; b=VHM2XS05fHSWgZVEoJcLpghyfjNCXw5bzoq/UL1cv739kNeSPr6YpZx9/pdpUOnL9wmPu9 e5Aik6Nb99ZRQ6s2xs3ExWGBxeN4k5G/uNQtsID8P2W/6Lhz/GFHTtS8oEwEEpwhGZ3TfR WW5qI5mD4+PMOp8mMripFGPmOvbwuqA= 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=1Epi3uPitQ1on7D3YBD3uiLy0TLxJfWf5bL2Vyq95Dw=; b=Co5btgZE3bcLd6z8lfAD2yNF2L ng1KYKs/j+LRyQXyEVivIfQ47vWvqix6Wv8uRYB11Zf6YAPWQ2Kzx6ArCzkOTTWGT+8XCPQ7uXuEW vDAkp51vggTuX10agZQ0yg3W576dARN+M8hwxlyoPwRGjE1XOB0MhUIjhFWN9aJ7vL1eea62cfgP6 NvnVZop5Z9+vAD7rvcXJhH1RecuHIqRh/u8NJKUmTnog33pDpfH/OHUZ4xTe7JYu2pvydxZvXodvi 2IHrCULJhmfjc6eogA90H7UhlDF3UynqeHLBuojaS/A/nCPh7Z4kvOMBaOLWLDVm17tOL1bQyvxXM L0ZUXWwQ==; 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 1qSzTk-003oSd-1J; Mon, 07 Aug 2023 12:36:56 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id D1BF4300473; Mon, 7 Aug 2023 14:36:54 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 986A62021C3D7; Mon, 7 Aug 2023 14:36:54 +0200 (CEST) Message-ID: <20230807123323.020870574@infradead.org> User-Agent: quilt/0.66 Date: Mon, 07 Aug 2023 14:18:47 +0200 From: Peter Zijlstra To: tglx@linutronix.de, axboe@kernel.dk Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, dvhart@infradead.org, dave@stgolabs.net, andrealmeid@igalia.com, Andrew Morton , urezki@gmail.com, hch@infradead.org, lstoakes@gmail.com, Arnd Bergmann , linux-api@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, malteskarupke@web.de Subject: [PATCH v2 04/14] futex: Validate futex value against futex size References: <20230807121843.710612856@infradead.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 087F280016 X-Stat-Signature: b4x3hiby6hqw3517jdu8dd54tc8uiaps X-HE-Tag: 1691411827-656064 X-HE-Meta: U2FsdGVkX1+axpYVNbSIVE5gA/JRc7fB/94xSfBeF9Bh66BAUEAPwLaRtCGF3Wa/kB1bbvap+4cECpKQD7QlisRSOnf3IWZ718TGHeaEPsqoN4Y6V3RgTqZsyiBuzPA9xRlPhyV2kDvHWtZv8IH6i9FzgaGV5BMTJloZkNHz56Ypa7+00co6BlI9GVLcZgZJOeCfExgST6z/X7MSrOr0H10LX+c7qCT0oTUfP4owvAmyWAXs2Cpp72YCw87a6prodMd6zq9FJmSUH8XtQeBYmQCMCjinowjiygt3dKg9lA9UEL3queLAJ8oguTRBFYEbWqy5l6fVLBrcRF1YUl6P//3YR5sAGpPi7Kdmk5eADSeytXUzw/4Y3dq9V9nF9XhF7scYZhlqyPr1ue166eVuBsGwhQjuYWmyvjqDFe2h5gf36Fzlfh8J50WytoAJWbm9SKu2MowBMYU0jXMmU5jc/ZXPMZ1f1i4U9lIrDM4I+EwAhgifQZnwCSCOYJb9Jm81RuNEe/GQa6FaLQ3GqSMlCyD1RHNp5PVVyzK3tgehAOGcZ+oIMqVSXc/TVq9+Ej8KvyTOf68+o1kcoYgR56U+cGQZt4QwH8+QxTgreA8orbjBMS1GOlexyhyH7QJXLIYwyLysEyu5svAV23dlQERToV7h4GZy/o95EGKqZS+yposGvXIUTr44LeUm/r2bnPOpIY6DnKj5MWKu/R07q/T1AbIGlLpkQRlecPW5ngGdQEYDTiOqWJUOYzasoroP+m1LDbM3VPmuBAKU7PI5Uov1w/nutFce9F5I7XgCmPeiKL/8I4+tNNWEREmZl6LlLPB/C9abATkbNT5cTJNEF/zBzsAcLf/YBD7HTexG8tcTU5gU4xJ1eX+0rRdDqp36wXzfC48LfQwABPnt+rhLMg/CjTaq+kvPJ1kVVyPCsl3YqYtjFajR62TvIm64dW1YSkq0yfvk3j0QXmChzz6zP4I Y+O78hMm YBIvpxwd1P1ReKAPv1c8SX3I3eo0CnMk3/nOCoiU4F8SZVdtZMAMTciAPcnY0m5JOZoDf8BC+QPodYutBGVRK/iq+laVhJaTVTYPyfJC+vt3pjn7Nil0w/74tFpQbtfbE6/vEYCiEMvAsbwVbdhKpkZwokqO4Rl6XBXgGb5+T00IxLJO/w9c1lqcqgmh5RvH764TJxx4JNeb2a4IUW4QmK0A+fX4lmST1XHzYO6T125vicstOWGp5qr0q/0qPL6deMymAA7T7VuHvWHyBRnMSlMy4ng== 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(+) --- a/kernel/futex/futex.h +++ b/kernel/futex/futex.h @@ -85,6 +85,16 @@ static inline unsigned int futex_size(un return 1 << (flags & FLAGS_SIZE_MASK); } +static inline bool futex_validate_input(unsigned int flags, u64 val) +{ + int bits = 8 * futex_size(flags); + + if (bits < 64 && (val >> bits)) + return false; + + return true; +} + #ifdef CONFIG_FAIL_FUTEX extern bool should_fail_futex(bool fshared); #else --- a/kernel/futex/syscalls.c +++ b/kernel/futex/syscalls.c @@ -209,6 +209,9 @@ static int futex_parse_waitv(struct fute if (!futex_flags_valid(flags)) return -EINVAL; + if (!futex_validate_input(flags, aux.val)) + return -EINVAL; + futexv[i].w.flags = flags; futexv[i].w.val = aux.val; futexv[i].w.uaddr = aux.uaddr; From patchwork Mon Aug 7 12:18:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13344120 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 533C2C04FE1 for ; Mon, 7 Aug 2023 12:37:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E9BCE6B007D; Mon, 7 Aug 2023 08:37:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C8C4C900002; Mon, 7 Aug 2023 08:37:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 99D666B007D; Mon, 7 Aug 2023 08:37:11 -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 164B1900002 for ; Mon, 7 Aug 2023 08:37:11 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id A56E9409E4 for ; Mon, 7 Aug 2023 12:37:10 +0000 (UTC) X-FDA: 81097258620.04.7F0BE9E Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf16.hostedemail.com (Postfix) with ESMTP id 4AC3618000C for ; Mon, 7 Aug 2023 12:37:07 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=WsiTil+c; spf=none (imf16.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=1691411827; 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=e0ODiErkiAW6GZEr+QWyQaocRNB5DYuNqCHK8u2llMY=; b=3tz30U7MQqQMS7/4ZNozc+R1qM/TjSMojSYvt3AxWpsj96jqITWlS4/BeXoC/+SKXoV5II Mn7YtkE61KLsaEYysxX/masgUdM2mmY6WFuZciXU2P56YYJCsmGTLelR60yYeecKsS/NlJ PrtFeH+ybYyVK8xsbuoqCUyQ2qGq61o= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=WsiTil+c; spf=none (imf16.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=1691411827; a=rsa-sha256; cv=none; b=hJg9nw6e3nY+8xvIZvH5Z1zUUS+iJ9B7W08Q/Vhs9dLUSrj/VdZL2vllMVGs/EeWHd5F8v kdrr7cpRDKUYen44KEI9CZnv/t8Fv6Z8RuHreOrNvYtvH48oAvqdkzToQX4/p2DYqDXOGC ruBKbFx0C1n4WWCIJKBzOZpuediOiU0= 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=e0ODiErkiAW6GZEr+QWyQaocRNB5DYuNqCHK8u2llMY=; b=WsiTil+cp9p9DlcqmRAr0x3S3V JnAuedsnn3FQ2guRfve4/1h7VbOAMNu9jEcjXnC1yU3KcSUEPnkCS5lQxwf9Tg/izo/NuwcjkDwxS wrRzof95u3tqna3Mx86ezjdGyx6Af0iTHczZR1lV7GmwnE0zpiqxtB2FOLFcyzxHAv1gLC5ZTxIRB BaYW/z1bWWOyMGePPfiMBtzg9G/xaCgMVQ4Cgp8Eb7nQoaA8gcJP4cLnojosKq4NfsLuN8zVpIu9B /W6S7fNKBXiwiIGZovqxWCFaIZjxYZNZJ39sUbq3p4bZ88ttFaHL7mI5zGGvv2U3Xl+YP4vjrCQ+M USoTyOhw==; 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 1qSzTl-003oSn-1l; Mon, 07 Aug 2023 12:36:58 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 287E73033AE; Mon, 7 Aug 2023 14:36:56 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 9EA5E2021C3D8; Mon, 7 Aug 2023 14:36:54 +0200 (CEST) Message-ID: <20230807123323.090897260@infradead.org> User-Agent: quilt/0.66 Date: Mon, 07 Aug 2023 14:18:48 +0200 From: Peter Zijlstra To: tglx@linutronix.de, axboe@kernel.dk Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, dvhart@infradead.org, dave@stgolabs.net, andrealmeid@igalia.com, Andrew Morton , urezki@gmail.com, hch@infradead.org, lstoakes@gmail.com, Arnd Bergmann , linux-api@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, malteskarupke@web.de, Geert Uytterhoeven Subject: [PATCH v2 05/14] futex: Add sys_futex_wake() References: <20230807121843.710612856@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4AC3618000C X-Rspam-User: X-Stat-Signature: ynk145j8wregtqufu4co4az6s5nnrd5a X-Rspamd-Server: rspam01 X-HE-Tag: 1691411827-489967 X-HE-Meta: U2FsdGVkX1/nAqXB+HF9ZZ7J/P+AEHmMkN4lQCp0MjJJrakCUHp2ylvAQeQ1bmGIS9yIq0CCUnPY9l5V9jp6l8zynxe4VkhKyVCwNjdYUWfb7/R/UqKjp9l5GzHq0cWdziG/mC5pBwYC/gqm/fn32eudEeIErnJ/y8obhs5GDLqbIrN4iajObQzRrhCfQXJcUlKkh58jvDEyq4Ti1ahI/v+OzyTE1Gsvfd4dkI7B5QizJcIwwpfrTABWSe/hpl4ZTZ94BBFcttSTGZizO6cgw3RZ5/smqOV/NVSRlMUpzoRcNoeJQ8GobbJSuTKKFeWZYHO6Ob5bHsAdz/p41McT4dT7WPZeuwYslWw73ZVRFFjQ7DOcQlnpgd++c9BVMKFd67/axwtv//ozzfa6P3XCEw0Ul0328uUyHJcMRwQ8BZQjiq8EuTthiM+Slfo5jgSvz6pVvnxzG2B2K0Rq1UgB4pWznQ3l+MTPjhVfLuRQFE4dS5PN7ScolS31KvtnuZtXtOwH00vsxUYuvAha/Tc+tpRasVYSdaHcb4B4UhzzQSMBHHBmTZ2f2TJsALznxJFwBIQ0BV68ANrbLukhGyfZ48AlgjLPSYYF2g5It4/7NVhtSSxG87r6w+PbLQUiGTgk0bu1epXOhJZFU6rxGuOlybpYfrCKrrhwkTU7W+OP132QxfrvyGjtv16eRNEWT8x8cKtP1NwEIAl1v6VxJ8gyCV+OoGupLsYR8f3U4QYCy4sWxI9dZygZ5YCoipkMXQlCzkhlsm4l6P3GC90E7oOJxrdQFKCmIAOD8ingqE0w9+kkTHFzyCyCNIUc3pLVeDs/CD0NddwQH/lpnYeZ9NAuAVaXX5XbQ7vBAlQtCBh+nwkLpP6PlcdgINxZw0Z6J34zHDcbzFljjWjkOjNyi9mTV4JFieXjcFPw5D24WtYvZgpsSQTLseYQ9I3B9GEgFdZOgBm/uhkq6nWTCRjolal QRXOrzWp DBLh+qqsYfPHaHgv4z1+axz7pjyitN4FIoaoI0tYLBvD+XoBAsJoncRgg6avn+E3rExg9B4I3U9CI69QNCYdJGRAcsqQtuYyuKu4Y9AYsnNruk+eqReP9aGqJCK1gyr7xYEev5wgX80Nud4uat0VOibTiS45o+Hrv+MHery6fVivccWJzQG1FsQ6iMaWljNktq35AAV8Gw6mLabKhxSeVni6whxrdowuhddXwWMuyUWvH9sjDWOhxGkwtmoMzrhrU06tRzby+59k/7JZaOJLSbCRWYQ09S2HhbrkE1pAguESWXZc4gHKtM+27qSZBY0E867t08b322ozayDiARtb2wLDJakn3C3uiZEOHzH26wK9EHjl0SSHcYc5Y9XM+I0mN9EvI 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) Acked-by: Geert Uytterhoeven Reviewed-by: Thomas Gleixner --- arch/alpha/kernel/syscalls/syscall.tbl | 1 arch/arm/tools/syscall.tbl | 1 arch/arm64/include/asm/unistd.h | 2 - arch/arm64/include/asm/unistd32.h | 2 + arch/ia64/kernel/syscalls/syscall.tbl | 1 arch/m68k/kernel/syscalls/syscall.tbl | 1 arch/microblaze/kernel/syscalls/syscall.tbl | 1 arch/mips/kernel/syscalls/syscall_n32.tbl | 1 arch/mips/kernel/syscalls/syscall_n64.tbl | 1 arch/mips/kernel/syscalls/syscall_o32.tbl | 1 arch/parisc/kernel/syscalls/syscall.tbl | 1 arch/powerpc/kernel/syscalls/syscall.tbl | 1 arch/s390/kernel/syscalls/syscall.tbl | 1 arch/sh/kernel/syscalls/syscall.tbl | 1 arch/sparc/kernel/syscalls/syscall.tbl | 1 arch/x86/entry/syscalls/syscall_32.tbl | 1 arch/x86/entry/syscalls/syscall_64.tbl | 1 arch/xtensa/kernel/syscalls/syscall.tbl | 1 include/linux/syscalls.h | 3 ++ include/uapi/asm-generic/unistd.h | 5 ++-- kernel/futex/syscalls.c | 30 ++++++++++++++++++++++++++++ kernel/sys_ni.c | 1 22 files changed, 56 insertions(+), 3 deletions(-) --- a/arch/alpha/kernel/syscalls/syscall.tbl +++ b/arch/alpha/kernel/syscalls/syscall.tbl @@ -491,3 +491,4 @@ 559 common futex_waitv sys_futex_waitv 560 common set_mempolicy_home_node sys_ni_syscall 561 common cachestat sys_cachestat +562 common futex_wake sys_futex_wake --- a/arch/arm/tools/syscall.tbl +++ b/arch/arm/tools/syscall.tbl @@ -465,3 +465,4 @@ 449 common futex_waitv sys_futex_waitv 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat +452 common futex_wake sys_futex_wake --- a/arch/arm64/include/asm/unistd.h +++ b/arch/arm64/include/asm/unistd.h @@ -39,7 +39,7 @@ #define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE + 5) #define __ARM_NR_COMPAT_END (__ARM_NR_COMPAT_BASE + 0x800) -#define __NR_compat_syscalls 452 +#define __NR_compat_syscalls 453 #endif #define __ARCH_WANT_SYS_CLONE --- a/arch/arm64/include/asm/unistd32.h +++ b/arch/arm64/include/asm/unistd32.h @@ -909,6 +909,8 @@ __SYSCALL(__NR_futex_waitv, sys_futex_wa __SYSCALL(__NR_set_mempolicy_home_node, sys_set_mempolicy_home_node) #define __NR_cachestat 451 __SYSCALL(__NR_cachestat, sys_cachestat) +#define __NR_futex_wake 452 +__SYSCALL(__NR_futex_wake, sys_futex_wake) /* * Please add new compat syscalls above this comment and update --- a/arch/ia64/kernel/syscalls/syscall.tbl +++ b/arch/ia64/kernel/syscalls/syscall.tbl @@ -372,3 +372,4 @@ 449 common futex_waitv sys_futex_waitv 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat +452 common futex_wake sys_futex_wake --- a/arch/m68k/kernel/syscalls/syscall.tbl +++ b/arch/m68k/kernel/syscalls/syscall.tbl @@ -451,3 +451,4 @@ 449 common futex_waitv sys_futex_waitv 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat +452 common futex_wake sys_futex_wake --- a/arch/microblaze/kernel/syscalls/syscall.tbl +++ b/arch/microblaze/kernel/syscalls/syscall.tbl @@ -457,3 +457,4 @@ 449 common futex_waitv sys_futex_waitv 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat +452 common futex_wake sys_futex_wake --- a/arch/mips/kernel/syscalls/syscall_n32.tbl +++ b/arch/mips/kernel/syscalls/syscall_n32.tbl @@ -390,3 +390,4 @@ 449 n32 futex_waitv sys_futex_waitv 450 n32 set_mempolicy_home_node sys_set_mempolicy_home_node 451 n32 cachestat sys_cachestat +452 n32 futex_wake sys_futex_wake --- a/arch/mips/kernel/syscalls/syscall_n64.tbl +++ b/arch/mips/kernel/syscalls/syscall_n64.tbl @@ -366,3 +366,4 @@ 449 n64 futex_waitv sys_futex_waitv 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 n64 cachestat sys_cachestat +452 n64 futex_wake sys_futex_wake --- a/arch/mips/kernel/syscalls/syscall_o32.tbl +++ b/arch/mips/kernel/syscalls/syscall_o32.tbl @@ -439,3 +439,4 @@ 449 o32 futex_waitv sys_futex_waitv 450 o32 set_mempolicy_home_node sys_set_mempolicy_home_node 451 o32 cachestat sys_cachestat +452 o32 futex_wake sys_futex_wake --- a/arch/parisc/kernel/syscalls/syscall.tbl +++ b/arch/parisc/kernel/syscalls/syscall.tbl @@ -450,3 +450,4 @@ 449 common futex_waitv sys_futex_waitv 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat +452 common futex_wake sys_futex_wake --- a/arch/powerpc/kernel/syscalls/syscall.tbl +++ b/arch/powerpc/kernel/syscalls/syscall.tbl @@ -538,3 +538,4 @@ 449 common futex_waitv sys_futex_waitv 450 nospu set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat +452 common futex_wake sys_futex_wake --- a/arch/s390/kernel/syscalls/syscall.tbl +++ b/arch/s390/kernel/syscalls/syscall.tbl @@ -454,3 +454,4 @@ 449 common futex_waitv sys_futex_waitv sys_futex_waitv 450 common set_mempolicy_home_node sys_set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat sys_cachestat +452 common futex_wake sys_futex_wake sys_futex_wake --- a/arch/sh/kernel/syscalls/syscall.tbl +++ b/arch/sh/kernel/syscalls/syscall.tbl @@ -454,3 +454,4 @@ 449 common futex_waitv sys_futex_waitv 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat +452 common futex_wake sys_futex_wake --- a/arch/sparc/kernel/syscalls/syscall.tbl +++ b/arch/sparc/kernel/syscalls/syscall.tbl @@ -497,3 +497,4 @@ 449 common futex_waitv sys_futex_waitv 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat +452 common futex_wake sys_futex_wake --- a/arch/x86/entry/syscalls/syscall_32.tbl +++ b/arch/x86/entry/syscalls/syscall_32.tbl @@ -456,3 +456,4 @@ 449 i386 futex_waitv sys_futex_waitv 450 i386 set_mempolicy_home_node sys_set_mempolicy_home_node 451 i386 cachestat sys_cachestat +452 i386 futex_wake sys_futex_wake --- a/arch/x86/entry/syscalls/syscall_64.tbl +++ b/arch/x86/entry/syscalls/syscall_64.tbl @@ -373,6 +373,7 @@ 449 common futex_waitv sys_futex_waitv 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat +452 common futex_wake sys_futex_wake # # Due to a historical design error, certain syscalls are numbered differently --- a/arch/xtensa/kernel/syscalls/syscall.tbl +++ b/arch/xtensa/kernel/syscalls/syscall.tbl @@ -422,3 +422,4 @@ 449 common futex_waitv sys_futex_waitv 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat +452 common futex_wake sys_futex_wake --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -563,6 +563,9 @@ asmlinkage long sys_set_robust_list(stru asmlinkage long sys_futex_waitv(struct futex_waitv *waiters, unsigned int nr_futexes, unsigned int flags, struct __kernel_timespec __user *timeout, clockid_t clockid); + +asmlinkage long sys_futex_wake(void __user *uaddr, unsigned long mask, int nr, unsigned int flags); + asmlinkage long sys_nanosleep(struct __kernel_timespec __user *rqtp, struct __kernel_timespec __user *rmtp); asmlinkage long sys_nanosleep_time32(struct old_timespec32 __user *rqtp, --- a/include/uapi/asm-generic/unistd.h +++ b/include/uapi/asm-generic/unistd.h @@ -816,12 +816,13 @@ __SYSCALL(__NR_process_mrelease, sys_pro __SYSCALL(__NR_futex_waitv, sys_futex_waitv) #define __NR_set_mempolicy_home_node 450 __SYSCALL(__NR_set_mempolicy_home_node, sys_set_mempolicy_home_node) - #define __NR_cachestat 451 __SYSCALL(__NR_cachestat, sys_cachestat) +#define __NR_futex_wake 452 +__SYSCALL(__NR_futex_wake, sys_futex_wake) #undef __NR_syscalls -#define __NR_syscalls 452 +#define __NR_syscalls 453 /* * 32 bit systems traditionally used different --- a/kernel/futex/syscalls.c +++ b/kernel/futex/syscalls.c @@ -306,6 +306,36 @@ SYSCALL_DEFINE5(futex_waitv, struct fute return ret; } +/* + * sys_futex_wake - Wake a number of futexes + * @uaddr: Address of the futex(es) to wake + * @mask: bitmask + * @nr: Number of the futexes to wake + * @flags: FUTEX2 flags + * + * Identical to the traditional FUTEX_WAKE_BITSET op, except it is part of the + * futex2 family of calls. + */ + +SYSCALL_DEFINE4(futex_wake, + void __user *, uaddr, + unsigned long, mask, + int, nr, + unsigned int, flags) +{ + if (flags & ~FUTEX2_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, --- a/kernel/sys_ni.c +++ b/kernel/sys_ni.c @@ -87,6 +87,7 @@ COND_SYSCALL_COMPAT(set_robust_list); COND_SYSCALL(get_robust_list); COND_SYSCALL_COMPAT(get_robust_list); COND_SYSCALL(futex_waitv); +COND_SYSCALL(futex_wake); COND_SYSCALL(kexec_load); COND_SYSCALL_COMPAT(kexec_load); COND_SYSCALL(init_module); From patchwork Mon Aug 7 12:18:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13344111 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 C8ADEC001B0 for ; Mon, 7 Aug 2023 12:37:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 474C48D0005; Mon, 7 Aug 2023 08:37:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3AAFD8E0003; Mon, 7 Aug 2023 08:37:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 05D846B007B; Mon, 7 Aug 2023 08:37:09 -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 CD2BB8D0003 for ; Mon, 7 Aug 2023 08:37:09 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8A84B80A36 for ; Mon, 7 Aug 2023 12:37:09 +0000 (UTC) X-FDA: 81097258578.16.0EC3679 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf19.hostedemail.com (Postfix) with ESMTP id 7A6E51A0003 for ; Mon, 7 Aug 2023 12:37:07 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=ehEsNfwS; 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=1691411827; 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=EZIyQFpYSmr+EWjOL5a+M3dpjuZvxzS495rTXOpv4ME=; b=TDu0NOEj6SaqFWxt8Ixdr5kfCeX/yjrNxWQ8rjywHLYHeYsMwR7Eqo8cgZObpNu2es5v45 2YC5bC8SYcgEeugIiXaYx71NOZh6T9EQXC9v70n8qkQEFZqEUpp0kAVsUwBe1UlARyQy/X 8Eh+eqspElZxXrR5/DDwxR+G10b/fSY= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=ehEsNfwS; 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=1691411827; a=rsa-sha256; cv=none; b=mW6o4Bi/SIE4KUh9VIjwM7YZQs9qId9fsXgHO/gsr5yOalCi3CHuznXKR+kg+fBew7qVNq zrcK3yM+PW/WcQGNLWpzSwLK0pZiotYtacKpXqvl2+8u78OZIQ/tDBPwrnsr+0DPYzdcyJ 9t6YK0yN0xyGvvz2eIt3uyRwBBd5Rb8= 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=EZIyQFpYSmr+EWjOL5a+M3dpjuZvxzS495rTXOpv4ME=; b=ehEsNfwSZ0jDg9NlrPMsn1dqWe hSHvvBaaop3p/hC7EAiKB3mpSXaMcVk/pLfS3vCEm+SJXLH2YTa3jWAswyPgX7W0OWD6DXywxUBwM SlQXRDZUWVskUJ+Jqofi1maJKT60zqta/JoGUMiaYEc6b1f2GrVs0bGoV2QSG7365xb+ZKUIdY6+x X2rgtzAC3ytHrhfdOSjAWDYVC8v6xsHIHRouK6CmddiPPOjmDTrleNbDqa6KGqrcn2f5WjhMHd/na XqN6fR5rZfVtevfu35gZqoqbaHihhri3Ks90q59ukzBFu9teGEpzIi7owwqWXBCS+9kSDOcOPL3Kh Tj0gpo2A==; 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 1qSzTl-003oSm-1l; Mon, 07 Aug 2023 12:36:58 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 277CA301C41; Mon, 7 Aug 2023 14:36:56 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id A15492021C3D9; Mon, 7 Aug 2023 14:36:54 +0200 (CEST) Message-ID: <20230807123323.159400076@infradead.org> User-Agent: quilt/0.66 Date: Mon, 07 Aug 2023 14:18:49 +0200 From: Peter Zijlstra To: tglx@linutronix.de, axboe@kernel.dk Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, dvhart@infradead.org, dave@stgolabs.net, andrealmeid@igalia.com, Andrew Morton , urezki@gmail.com, hch@infradead.org, lstoakes@gmail.com, Arnd Bergmann , linux-api@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, malteskarupke@web.de, Geert Uytterhoeven Subject: [PATCH v2 06/14] futex: Add sys_futex_wait() References: <20230807121843.710612856@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 7A6E51A0003 X-Rspam-User: X-Stat-Signature: c8q83g195apu938gsnw75kxtquyttr8q X-Rspamd-Server: rspam01 X-HE-Tag: 1691411827-107846 X-HE-Meta: U2FsdGVkX19nmYbZjDUCLrFhFgEZqUgHepg9+M/y8ejG1a+Le2jjPGZAWSV9AiBbieFgabZZDm4f6uardJJlgC7zFKyqCVz0Y3CHwlKt+ShWETEwFgQkEkpvpl9YWm5IZJGd6D7YpirWcHQ/729dmxyE/RF3FQD3IIuRWlH4BQYvAu1d8nlKPlu2gG0RJJpD8j1bGyQz23FoDFigzaTETqygckKF8MwloSMwO4yMKooDjAeFahHPoZmxaAv0ewmGG2Md7qX+WHPBrZKBLEu5FX0WtExfAcDRlZ6Gzxy3dqmVUnBeRFoRfpH/20s3pr3nq6qyMum80sFULyEQrbTe8Xo7F0nOYs3YP2s4Qr6F87PCcr/AbP5NsCrJEJExfNA5gXFi0+B+m/Qe9E2rYu4wVBxGQOqVOU1ecU/5tsMitOSUaOEORxKZgyjCWGTVwq7+K3NSbgprN8xJEfiWJSOect+Iz/E/ipjLyGEk0Rdnq3d8dHZ3rbScz1wbZum2fPx++KIuNsPhZFlbV5n3OBaC8aMMkCCcgO0lNwKy6LEK0kUhWPjtsojN4G18SK37bA6U9N5DsVg/PlJ4pM5Ti5/SLQoCc+qvdJtRiYAwhAUmMV1b7IgyBI82iF25WiuzbL4S/EhwaKkm0DDnlnCkpk0A5catKLU7lXMFAXLtu57+a3bH9VZ6wVKBKtuW5zRnLE7C5wJBa9lBAYo5e8YwoyHZVXCDv2zCk0/kBTuOLy5g6guxdkIroGGfEoMoyl6D2jsVDxTBXQMow6O1JB6UkGQFdqGKFhdSuVrsD2884QVwxudrYKywz03U7CXsxCELB389UK5XhgY3PspGLZokG7/f+kPM8zCEkK0s/STlgqL3H1iVj8MQQtjvYg0Fm1GLn8N7OjoK/8Z5lQfiEXxFN1zfgJ5zUE9ZVY5EumITgir2vw1NbBnMus/SsFrVWaliA1cTiRliQugwO/0vOEFKrXg BRVPUooo ybH/uvCNWh9RLPnEYhXOt+5/12JL4xORgE38s/VII/oczdR1gWOdpIPOnohA+y6G2kWfvOn16ATD3HUO16nKQDnxhXYyXbP5u0iw9l2zTGFwI/MookOzaM+x0aEcV2n5hhNX0Ir2I7sK3w9NAgr5m7gchCApFAQEIaQaxBSeWsCjU2/rbW21loRiUA0/2AD42CFWlorXF5yX3ViYYB5FqNt5Wh1G5B0u46iQi4n8X0MIZoT5AWIQCEWqhiHAHCUP+BZ1YoL+FJ+TtnT+LzNPXPhrb3z2MvhJn3NldQiCIz4boiWj1cq/vAOR5MmkQnmVREYie86EQWDgHUIWqRGZAnay3hJZVgJ47ODn8RPkvlliylK1L0IT1G23CIBPDjmeWINLB 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(-) --- a/arch/alpha/kernel/syscalls/syscall.tbl +++ b/arch/alpha/kernel/syscalls/syscall.tbl @@ -492,3 +492,4 @@ 560 common set_mempolicy_home_node sys_ni_syscall 561 common cachestat sys_cachestat 562 common futex_wake sys_futex_wake +563 common futex_wait sys_futex_wait --- a/arch/arm/tools/syscall.tbl +++ b/arch/arm/tools/syscall.tbl @@ -466,3 +466,4 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common futex_wake sys_futex_wake +453 common futex_wait sys_futex_wait --- a/arch/arm64/include/asm/unistd.h +++ b/arch/arm64/include/asm/unistd.h @@ -39,7 +39,7 @@ #define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE + 5) #define __ARM_NR_COMPAT_END (__ARM_NR_COMPAT_BASE + 0x800) -#define __NR_compat_syscalls 453 +#define __NR_compat_syscalls 454 #endif #define __ARCH_WANT_SYS_CLONE --- a/arch/arm64/include/asm/unistd32.h +++ b/arch/arm64/include/asm/unistd32.h @@ -911,6 +911,8 @@ __SYSCALL(__NR_set_mempolicy_home_node, __SYSCALL(__NR_cachestat, sys_cachestat) #define __NR_futex_wake 452 __SYSCALL(__NR_futex_wake, sys_futex_wake) +#define __NR_futex_wait 453 +__SYSCALL(__NR_futex_wait, sys_futex_wait) /* * Please add new compat syscalls above this comment and update --- a/arch/ia64/kernel/syscalls/syscall.tbl +++ b/arch/ia64/kernel/syscalls/syscall.tbl @@ -373,3 +373,4 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common futex_wake sys_futex_wake +453 common futex_wait sys_futex_wait --- a/arch/m68k/kernel/syscalls/syscall.tbl +++ b/arch/m68k/kernel/syscalls/syscall.tbl @@ -452,3 +452,4 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common futex_wake sys_futex_wake +453 common futex_wait sys_futex_wait --- a/arch/microblaze/kernel/syscalls/syscall.tbl +++ b/arch/microblaze/kernel/syscalls/syscall.tbl @@ -458,3 +458,4 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common futex_wake sys_futex_wake +453 common futex_wait sys_futex_wait --- a/arch/mips/kernel/syscalls/syscall_n32.tbl +++ b/arch/mips/kernel/syscalls/syscall_n32.tbl @@ -391,3 +391,4 @@ 450 n32 set_mempolicy_home_node sys_set_mempolicy_home_node 451 n32 cachestat sys_cachestat 452 n32 futex_wake sys_futex_wake +453 n32 futex_wait sys_futex_wait --- a/arch/mips/kernel/syscalls/syscall_n64.tbl +++ b/arch/mips/kernel/syscalls/syscall_n64.tbl @@ -367,3 +367,4 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 n64 cachestat sys_cachestat 452 n64 futex_wake sys_futex_wake +453 n64 futex_wait sys_futex_wait --- a/arch/mips/kernel/syscalls/syscall_o32.tbl +++ b/arch/mips/kernel/syscalls/syscall_o32.tbl @@ -440,3 +440,4 @@ 450 o32 set_mempolicy_home_node sys_set_mempolicy_home_node 451 o32 cachestat sys_cachestat 452 o32 futex_wake sys_futex_wake +453 o32 futex_wait sys_futex_wait --- a/arch/parisc/kernel/syscalls/syscall.tbl +++ b/arch/parisc/kernel/syscalls/syscall.tbl @@ -451,3 +451,4 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common futex_wake sys_futex_wake +453 common futex_wait sys_futex_wait --- a/arch/powerpc/kernel/syscalls/syscall.tbl +++ b/arch/powerpc/kernel/syscalls/syscall.tbl @@ -539,3 +539,4 @@ 450 nospu set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common futex_wake sys_futex_wake +453 common futex_wait sys_futex_wait --- a/arch/s390/kernel/syscalls/syscall.tbl +++ b/arch/s390/kernel/syscalls/syscall.tbl @@ -455,3 +455,4 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat sys_cachestat 452 common futex_wake sys_futex_wake sys_futex_wake +453 common futex_wait sys_futex_wait sys_futex_wait --- a/arch/sh/kernel/syscalls/syscall.tbl +++ b/arch/sh/kernel/syscalls/syscall.tbl @@ -455,3 +455,4 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common futex_wake sys_futex_wake +453 common futex_wait sys_futex_wait --- a/arch/sparc/kernel/syscalls/syscall.tbl +++ b/arch/sparc/kernel/syscalls/syscall.tbl @@ -498,3 +498,4 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common futex_wake sys_futex_wake +453 common futex_wait sys_futex_wait --- a/arch/x86/entry/syscalls/syscall_32.tbl +++ b/arch/x86/entry/syscalls/syscall_32.tbl @@ -457,3 +457,4 @@ 450 i386 set_mempolicy_home_node sys_set_mempolicy_home_node 451 i386 cachestat sys_cachestat 452 i386 futex_wake sys_futex_wake +453 i386 futex_wait sys_futex_wait --- a/arch/x86/entry/syscalls/syscall_64.tbl +++ b/arch/x86/entry/syscalls/syscall_64.tbl @@ -374,6 +374,7 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common futex_wake sys_futex_wake +453 common futex_wait sys_futex_wait # # Due to a historical design error, certain syscalls are numbered differently --- a/arch/xtensa/kernel/syscalls/syscall.tbl +++ b/arch/xtensa/kernel/syscalls/syscall.tbl @@ -423,3 +423,4 @@ 450 common set_mempolicy_home_node sys_set_mempolicy_home_node 451 common cachestat sys_cachestat 452 common futex_wake sys_futex_wake +453 common futex_wait sys_futex_wait --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -566,6 +566,10 @@ asmlinkage long sys_futex_waitv(struct f asmlinkage long sys_futex_wake(void __user *uaddr, unsigned long mask, int nr, unsigned int flags); +asmlinkage long sys_futex_wait(void __user *uaddr, unsigned long val, unsigned long mask, + unsigned int flags, struct __kernel_timespec __user *timespec, + clockid_t clockid); + asmlinkage long sys_nanosleep(struct __kernel_timespec __user *rqtp, struct __kernel_timespec __user *rmtp); asmlinkage long sys_nanosleep_time32(struct old_timespec32 __user *rqtp, --- a/include/uapi/asm-generic/unistd.h +++ b/include/uapi/asm-generic/unistd.h @@ -820,9 +820,11 @@ __SYSCALL(__NR_set_mempolicy_home_node, __SYSCALL(__NR_cachestat, sys_cachestat) #define __NR_futex_wake 452 __SYSCALL(__NR_futex_wake, sys_futex_wake) +#define __NR_futex_wait 453 +__SYSCALL(__NR_futex_wait, sys_futex_wait) #undef __NR_syscalls -#define __NR_syscalls 453 +#define __NR_syscalls 454 /* * 32 bit systems traditionally used different --- a/kernel/futex/futex.h +++ b/kernel/futex/futex.h @@ -331,6 +331,9 @@ extern int futex_requeue(u32 __user *uad u32 __user *uaddr2, int nr_wake, int nr_requeue, u32 *cmpval, int requeue_pi); +extern int __futex_wait(u32 __user *uaddr, unsigned int flags, u32 val, + struct hrtimer_sleeper *to, u32 bitset); + extern int futex_wait(u32 __user *uaddr, unsigned int flags, u32 val, ktime_t *abs_time, u32 bitset); --- a/kernel/futex/syscalls.c +++ b/kernel/futex/syscalls.c @@ -221,6 +221,46 @@ static int futex_parse_waitv(struct fute return 0; } +static int futex2_setup_timeout(struct __kernel_timespec __user *timeout, + clockid_t clockid, struct hrtimer_sleeper *to) +{ + int flag_clkid = 0, flag_init = 0; + struct timespec64 ts; + ktime_t time; + int ret; + + if (!timeout) + return 0; + + if (clockid == CLOCK_REALTIME) { + flag_clkid = FLAGS_CLOCKRT; + flag_init = FUTEX_CLOCK_REALTIME; + } + + if (clockid != CLOCK_REALTIME && clockid != CLOCK_MONOTONIC) + return -EINVAL; + + if (get_timespec64(&ts, timeout)) + return -EFAULT; + + /* + * Since there's no opcode for futex_waitv, use + * FUTEX_WAIT_BITSET that uses absolute timeout as well + */ + ret = futex_init_timeout(FUTEX_WAIT_BITSET, flag_init, &ts, &time); + if (ret) + return ret; + + futex_setup_timer(&time, to, flag_clkid, 0); + return 0; +} + +static inline void futex2_destroy_timeout(struct hrtimer_sleeper *to) +{ + hrtimer_cancel(&to->timer); + destroy_hrtimer_on_stack(&to->timer); +} + /** * sys_futex_waitv - Wait on a list of futexes * @waiters: List of futexes to wait on @@ -250,8 +290,6 @@ SYSCALL_DEFINE5(futex_waitv, struct fute { struct hrtimer_sleeper to; struct futex_vector *futexv; - struct timespec64 ts; - ktime_t time; int ret; /* This syscall supports no flags for now */ @@ -261,30 +299,8 @@ SYSCALL_DEFINE5(futex_waitv, struct fute if (!nr_futexes || nr_futexes > FUTEX_WAITV_MAX || !waiters) return -EINVAL; - if (timeout) { - int flag_clkid = 0, flag_init = 0; - - if (clockid == CLOCK_REALTIME) { - flag_clkid = FLAGS_CLOCKRT; - flag_init = FUTEX_CLOCK_REALTIME; - } - - if (clockid != CLOCK_REALTIME && clockid != CLOCK_MONOTONIC) - return -EINVAL; - - if (get_timespec64(&ts, timeout)) - return -EFAULT; - - /* - * Since there's no opcode for futex_waitv, use - * FUTEX_WAIT_BITSET that uses absolute timeout as well - */ - ret = futex_init_timeout(FUTEX_WAIT_BITSET, flag_init, &ts, &time); - if (ret) - return ret; - - futex_setup_timer(&time, &to, flag_clkid, 0); - } + if (timeout && (ret = futex2_setup_timeout(timeout, clockid, &to))) + return ret; futexv = kcalloc(nr_futexes, sizeof(*futexv), GFP_KERNEL); if (!futexv) { @@ -299,10 +315,8 @@ SYSCALL_DEFINE5(futex_waitv, struct fute kfree(futexv); destroy_timer: - if (timeout) { - hrtimer_cancel(&to.timer); - destroy_hrtimer_on_stack(&to.timer); - } + if (timeout) + futex2_destroy_timeout(&to); return ret; } @@ -336,6 +350,52 @@ SYSCALL_DEFINE4(futex_wake, return futex_wake(uaddr, flags, nr, mask); } +/* + * sys_futex_wait - Wait on a futex + * @uaddr: Address of the futex to wait on + * @val: Value of @uaddr + * @mask: bitmask + * @flags: FUTEX2 flags + * @timeout: Optional absolute timeout + * @clockid: Clock to be used for the timeout, realtime or monotonic + * + * Identical to the traditional FUTEX_WAIT_BITSET op, except it is part of the + * futex2 familiy of calls. + */ + +SYSCALL_DEFINE6(futex_wait, + void __user *, uaddr, + unsigned long, val, + unsigned long, mask, + unsigned int, flags, + struct __kernel_timespec __user *, timeout, + clockid_t, clockid) +{ + struct hrtimer_sleeper to; + int ret; + + if (flags & ~FUTEX2_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, --- a/kernel/futex/waitwake.c +++ b/kernel/futex/waitwake.c @@ -629,20 +629,18 @@ int futex_wait_setup(u32 __user *uaddr, return ret; } -int futex_wait(u32 __user *uaddr, unsigned int flags, u32 val, ktime_t *abs_time, u32 bitset) +int __futex_wait(u32 __user *uaddr, unsigned int flags, u32 val, + struct hrtimer_sleeper *to, u32 bitset) { - struct hrtimer_sleeper timeout, *to; - struct restart_block *restart; - struct futex_hash_bucket *hb; struct futex_q q = futex_q_init; + struct futex_hash_bucket *hb; int ret; if (!bitset) return -EINVAL; + q.bitset = bitset; - to = futex_setup_timer(abs_time, &timeout, flags, - current->timer_slack_ns); retry: /* * Prepare to wait on uaddr. On success, it holds hb->lock and q @@ -650,18 +648,17 @@ int futex_wait(u32 __user *uaddr, unsign */ ret = futex_wait_setup(uaddr, val, flags, &q, &hb); if (ret) - goto out; + return ret; /* futex_queue and wait for wakeup, timeout, or a signal. */ futex_wait_queue(hb, &q, to); /* If we were woken (and unqueued), we succeeded, whatever. */ - ret = 0; if (!futex_unqueue(&q)) - goto out; - ret = -ETIMEDOUT; + return 0; + if (to && !to->task) - goto out; + return -ETIMEDOUT; /* * We expect signal_pending(current), but we might be the @@ -670,24 +667,38 @@ int futex_wait(u32 __user *uaddr, unsign if (!signal_pending(current)) goto retry; - ret = -ERESTARTSYS; - if (!abs_time) - goto out; - - restart = ¤t->restart_block; - restart->futex.uaddr = uaddr; - restart->futex.val = val; - restart->futex.time = *abs_time; - restart->futex.bitset = bitset; - restart->futex.flags = flags | FLAGS_HAS_TIMEOUT; - - ret = set_restart_fn(restart, futex_wait_restart); - -out: - if (to) { - hrtimer_cancel(&to->timer); - destroy_hrtimer_on_stack(&to->timer); + return -ERESTARTSYS; +} + +int futex_wait(u32 __user *uaddr, unsigned int flags, u32 val, ktime_t *abs_time, u32 bitset) +{ + struct hrtimer_sleeper timeout, *to; + struct restart_block *restart; + int ret; + + to = futex_setup_timer(abs_time, &timeout, flags, + current->timer_slack_ns); + + ret = __futex_wait(uaddr, flags, val, to, bitset); + + /* 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; } --- a/kernel/sys_ni.c +++ b/kernel/sys_ni.c @@ -88,6 +88,7 @@ COND_SYSCALL(get_robust_list); COND_SYSCALL_COMPAT(get_robust_list); COND_SYSCALL(futex_waitv); COND_SYSCALL(futex_wake); +COND_SYSCALL(futex_wait); COND_SYSCALL(kexec_load); COND_SYSCALL_COMPAT(kexec_load); COND_SYSCALL(init_module); From patchwork Mon Aug 7 12:18:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13344109 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 797B9C001B0 for ; Mon, 7 Aug 2023 12:37:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DCD188E0001; Mon, 7 Aug 2023 08:37:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C826A8D0002; Mon, 7 Aug 2023 08:37:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B4A418D0003; Mon, 7 Aug 2023 08:37:09 -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 9D2426B0075 for ; Mon, 7 Aug 2023 08:37:09 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4880BA0A8A for ; Mon, 7 Aug 2023 12:37:09 +0000 (UTC) X-FDA: 81097258578.16.6D980D9 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf27.hostedemail.com (Postfix) with ESMTP id 930FD40009 for ; Mon, 7 Aug 2023 12:37:07 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b="n/KciRWL"; dmarc=none; 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691411827; 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=kWs9TUI2FqJo9lXva2lEdKKGsIDSB3Llcr9amlgOJS4=; b=CH9hgoiUZD1O6KkePSwnmqkCobR4UiF7hkHSbCNE23ycAZUiMyE57A2+UYtQSB3qPEc9sc crQAkT4wZOOjbthUhoEGtkzVQPbsph8YgqwPGB0n2z7/8l/ceqsws8N5Gn5xqjF1hs//x3 cNymlShHBEZaI9G18+GFuC56JS92eJM= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b="n/KciRWL"; dmarc=none; 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691411827; a=rsa-sha256; cv=none; b=NvFUvlwrWyijAVJoOEF2G6LFzJnRVYZV85xhPrEtouvVy+kYh6A/Oc2n/RjEw1xUu76Yln 3ZNF3LDoXCEGCMZ3YMgHiszCfFdoH1t1klZKE+ep9vAI+Eu4hEa5OmuMbFRdbYY6YL+yVu e77SUKRxRbLaoDxwxTXfly6t08ushMQ= 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=kWs9TUI2FqJo9lXva2lEdKKGsIDSB3Llcr9amlgOJS4=; b=n/KciRWLyqqJUOUjojGDRmvbp5 /2vbrJgg6yBBhRRMx0DUh3lH3MdS7eMpBG4BHEkx39W9k7snr+E8i3KhRCe0XBfjiVjVuriKRQjWl dYJQZCGbeQHwjPq78B6ac+59qdpEXbqs1btvtMbncK89wDV0RmIOdtNQGHZJH5goNQ75ncT5a6d3P 4tgHvUz8IVyrmMbzw0ZM4T0O/iPv6rQaOgZS8wPfxfNt2zbOBfdkb5vPri+jTkPq3fuDGJr89atvU rD4v3FkYLKoc2VN6WgG4rl8Fn/mhpO8282N3zMcAq2ex+BOMtPvGsUG1WQIMSGHKoMkgvhhNsdwEc wiFgobmQ==; 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 1qSzTl-003oSk-1V; Mon, 07 Aug 2023 12:36:58 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 2876D302DD9; Mon, 7 Aug 2023 14:36:56 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id A69902021C3DA; Mon, 7 Aug 2023 14:36:54 +0200 (CEST) Message-ID: <20230807123323.228604931@infradead.org> User-Agent: quilt/0.66 Date: Mon, 07 Aug 2023 14:18:50 +0200 From: Peter Zijlstra To: tglx@linutronix.de, axboe@kernel.dk Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, dvhart@infradead.org, dave@stgolabs.net, andrealmeid@igalia.com, Andrew Morton , urezki@gmail.com, hch@infradead.org, lstoakes@gmail.com, Arnd Bergmann , linux-api@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, malteskarupke@web.de Subject: [PATCH v2 07/14] futex: Propagate flags into get_futex_key() References: <20230807121843.710612856@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 930FD40009 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: egfbhxo686afqtdh71izbbdkghs1uadx X-HE-Tag: 1691411827-529864 X-HE-Meta: U2FsdGVkX19HCZAj3oabecDb2GSvmgYxkAryYhFvCqjNbO1BUvqBrPzH8IyrdIXP1f2ZYp9LDbPZkvMLuVuEuGwQ24lwYgTZusrGYUillh6YzPIH+YsCjJmHraZ0RU4cY7KoO1j30kBljiL3PZCD80d8XW97PAcbCMjMge13fnRZUwvCT69CSc0cqrJ1Bzl/WH+hNls4sE94kdkd6YkXjZZlDXplcV7oTJ/F5/cj9TmE1XZiie3FaeKsM47q2QB6G1eIL8IbTkivewwlJqsuorjyt+aeJ6X3Tta4JrCjSIx9a0oA4/+0LBq8IQGk8kTpg9GDJzs1F5cx3KNiyprOtQn8H71nbDhJHi8czjOT5A+AVihlKJ5gJvtX4aSa3ak+k8sk5oUi6Kjy3Mc5MmDaeauo505tgas8CGNg+XkbeZi6+bA6Xpz1NyDJAmCcxYKCz/5XrYtsk1mknu7ojDSumDX+MpUMpUKNxUTq6osgRImUUdyMyVa4c5owjgKJrZ0y9cV890auP71URwpofW/vbelFOc5kY2561ZLdiPHVz57dMRnBb3RzLL2kOCb+giP8O5uiRm6vGPrIrbGS+s5u1hI3JDE/xzScYDMT2UK7Ev3HostGn+OTPmMC7uS79A+g6fJcXqA9+9LabQgoIA15Ao5AJQxr/xEQNNr1+98uzBdIjMZKbBoj74G385XIQt5kSQicfdxiNMV4cnXh6yNgYU9gPADROOm8UT6GyyJTrjT3hKlwpD+g7qcVmRnDEBs6OLnxOPJ0hHGqWMpOrjxTZ8zNNyISQL5Fs0mDfvshJP5e2AiDW60skraDtF85BrM3W83OlxAYr0SCJMsQhMtF0iiNqccyKW72rDfiWfPgQrN66Y2mC/MzgZqyqIPwU5eZdXYL0VGuc2Ksgt/ahshFpvt1xr4xXPJq4p845WAhxJuPtY8fLc9zi3ipJZeuvOTg/Qb66QPusC/QXQFy+nK clBGfSj9 84hxuXgaOI8Bcve7HQwfjEafxUaP16LknvGnZbyrJqjBC7kfNlUyliqx874UeGtD3Ljn8jkHHn2JIFYpd2p9h+Q/1SZphsYN8puXNggAAc/kfQHiMRfO0DbsU9sxjhUOp4WlUMCoxRE+/3zpA+3sToM2zoIGRyMtbMABfEXyM2TEVFWuVqlQZlSJx7nr3YorlNYxNN+hcINXaNzl7a8lub0ulLuXvjuH8iJSDT/SpONJe5xE6qvMpZ8uIkNov0H3EiRzAuCuOZ0q3s+4d8Gbny8xX24AuElzxnw+OI4VeVhg3TYmh+ZDLIf0QW90fmXKsg34j 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(-) --- a/kernel/futex/core.c +++ b/kernel/futex/core.c @@ -217,7 +217,7 @@ static u64 get_inode_sequence_number(str * * lock_page() might sleep, the caller should not hold a spinlock. */ -int get_futex_key(u32 __user *uaddr, bool fshared, union futex_key *key, +int get_futex_key(u32 __user *uaddr, unsigned int flags, union futex_key *key, enum futex_access rw) { unsigned long address = (unsigned long)uaddr; @@ -225,6 +225,9 @@ int get_futex_key(u32 __user *uaddr, boo struct page *page, *tail; struct address_space *mapping; int err, ro = 0; + bool fshared; + + fshared = flags & FLAGS_SHARED; /* * The futex address must be "naturally" aligned. --- a/kernel/futex/futex.h +++ b/kernel/futex/futex.h @@ -174,7 +174,7 @@ enum futex_access { FUTEX_WRITE }; -extern int get_futex_key(u32 __user *uaddr, bool fshared, union futex_key *key, +extern int get_futex_key(u32 __user *uaddr, unsigned int flags, union futex_key *key, enum futex_access rw); extern struct hrtimer_sleeper * --- a/kernel/futex/pi.c +++ b/kernel/futex/pi.c @@ -945,7 +945,7 @@ int futex_lock_pi(u32 __user *uaddr, uns to = futex_setup_timer(time, &timeout, flags, 0); retry: - ret = get_futex_key(uaddr, flags & FLAGS_SHARED, &q.key, FUTEX_WRITE); + ret = get_futex_key(uaddr, flags, &q.key, FUTEX_WRITE); if (unlikely(ret != 0)) goto out; @@ -1117,7 +1117,7 @@ int futex_unlock_pi(u32 __user *uaddr, u if ((uval & FUTEX_TID_MASK) != vpid) return -EPERM; - ret = get_futex_key(uaddr, flags & FLAGS_SHARED, &key, FUTEX_WRITE); + ret = get_futex_key(uaddr, flags, &key, FUTEX_WRITE); if (ret) return ret; --- a/kernel/futex/requeue.c +++ b/kernel/futex/requeue.c @@ -424,10 +424,10 @@ int futex_requeue(u32 __user *uaddr1, un } retry: - ret = get_futex_key(uaddr1, flags & FLAGS_SHARED, &key1, FUTEX_READ); + ret = get_futex_key(uaddr1, flags, &key1, FUTEX_READ); if (unlikely(ret != 0)) return ret; - ret = get_futex_key(uaddr2, flags & FLAGS_SHARED, &key2, + ret = get_futex_key(uaddr2, flags, &key2, requeue_pi ? FUTEX_WRITE : FUTEX_READ); if (unlikely(ret != 0)) return ret; @@ -789,7 +789,7 @@ int futex_wait_requeue_pi(u32 __user *ua */ rt_mutex_init_waiter(&rt_waiter); - ret = get_futex_key(uaddr2, flags & FLAGS_SHARED, &key2, FUTEX_WRITE); + ret = get_futex_key(uaddr2, flags, &key2, FUTEX_WRITE); if (unlikely(ret != 0)) goto out; --- a/kernel/futex/waitwake.c +++ b/kernel/futex/waitwake.c @@ -145,13 +145,13 @@ int futex_wake(u32 __user *uaddr, unsign struct futex_hash_bucket *hb; struct futex_q *this, *next; union futex_key key = FUTEX_KEY_INIT; - int ret; DEFINE_WAKE_Q(wake_q); + int ret; if (!bitset) return -EINVAL; - ret = get_futex_key(uaddr, flags & FLAGS_SHARED, &key, FUTEX_READ); + ret = get_futex_key(uaddr, flags, &key, FUTEX_READ); if (unlikely(ret != 0)) return ret; @@ -245,10 +245,10 @@ int futex_wake_op(u32 __user *uaddr1, un DEFINE_WAKE_Q(wake_q); retry: - ret = get_futex_key(uaddr1, flags & FLAGS_SHARED, &key1, FUTEX_READ); + ret = get_futex_key(uaddr1, flags, &key1, FUTEX_READ); if (unlikely(ret != 0)) return ret; - ret = get_futex_key(uaddr2, flags & FLAGS_SHARED, &key2, FUTEX_WRITE); + ret = get_futex_key(uaddr2, flags, &key2, FUTEX_WRITE); if (unlikely(ret != 0)) return ret; @@ -423,7 +423,7 @@ static int futex_wait_multiple_setup(str continue; ret = get_futex_key(u64_to_user_ptr(vs[i].w.uaddr), - vs[i].w.flags & FLAGS_SHARED, + vs[i].w.flags, &vs[i].q.key, FUTEX_READ); if (unlikely(ret)) @@ -435,7 +435,7 @@ static int futex_wait_multiple_setup(str for (i = 0; i < count; i++) { u32 __user *uaddr = (u32 __user *)(unsigned long)vs[i].w.uaddr; struct futex_q *q = &vs[i].q; - u32 val = (u32)vs[i].w.val; + u32 val = vs[i].w.val; hb = futex_q_lock(q); ret = futex_get_value_locked(&uval, uaddr); @@ -599,7 +599,7 @@ int futex_wait_setup(u32 __user *uaddr, * while the syscall executes. */ retry: - ret = get_futex_key(uaddr, flags & FLAGS_SHARED, &q->key, FUTEX_READ); + ret = get_futex_key(uaddr, flags, &q->key, FUTEX_READ); if (unlikely(ret != 0)) return ret; From patchwork Mon Aug 7 12:18:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13344172 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 04C8CC04A6A for ; Mon, 7 Aug 2023 12:55:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6EC3B6B0074; Mon, 7 Aug 2023 08:55:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 69C898D0003; Mon, 7 Aug 2023 08:55:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 58BC78D0002; Mon, 7 Aug 2023 08:55:44 -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 4A0D56B0074 for ; Mon, 7 Aug 2023 08:55:44 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 09DC980A73 for ; Mon, 7 Aug 2023 12:55:44 +0000 (UTC) X-FDA: 81097305408.07.8B434C9 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf11.hostedemail.com (Postfix) with ESMTP id 6203F40010 for ; Mon, 7 Aug 2023 12:55:42 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=pFuSQuVG; 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=1691412942; 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=pYLybm9JZIJCZuh77o+xiW69/IF1XmJJdrRIN+H3ncw=; b=UHenJc/s++qi0ru48xsB0RgjWIGkZ5o3rw0lacuVX3PGBC8MjpjJODvBkRSNkhjqv5nwG2 57GOlsXlvJXT1qZcGGuDrBHCPBhqhUpZGpMCYOhoZ2wbdwFHefcERIhK3mXgpZuj3aUqUr kB9qP8YHh+iW+Y/MQuB1b9X1bzoya3Q= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=pFuSQuVG; 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=1691412942; a=rsa-sha256; cv=none; b=kwD8yfeGWeh1JZGIVFEF/ewok93ohPpHyUxn2sj62/qELEX/Ziph8Nxn44NYCNrlBH/kO9 9x/t5KApevS0IwP9wFwAEcJU/pxLQqLYmK2oIxFa+TabH9FMQ8CPTKQtHXjNADXGcbCbN3 fy/xiWMZdrmOIoPB/t2QSimfZryWlIA= 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=pYLybm9JZIJCZuh77o+xiW69/IF1XmJJdrRIN+H3ncw=; b=pFuSQuVGSBJuutUwmlZpjMWdRU kvMUDLgJkXKo9JPSo4x0sQY9HwX6M+hpbJzOfRDznKFrVHKVWrcBUnYeDmtwOPuHVYstLYl+mrfro cZZpCjRlWeufpcF++64Tvvbk7dVtbbOx8m2nxgp4EKelAXSxwAVvB7sX5tg8Cl+Lr3QQF3oOEcEZw FDF0SkoPTqaoqymn0jO9gOgPdi66KzSZ4r7GlthBVG7UtjsLTArj7CbvEpNC2ab9N64AgmFfVr63v vJ1Fd8ziqqrOHHo214l1verg7oEcGCRSwG1Z0sAByEXYygkgkxN/UGMRogWSyT2ZIV5eMlsQSaDYz V521WANA==; 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 1qSzTl-003oSj-1T; Mon, 07 Aug 2023 12:36:57 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 28739302792; Mon, 7 Aug 2023 14:36:56 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id AD6302021C3D5; Mon, 7 Aug 2023 14:36:54 +0200 (CEST) Message-ID: <20230807123323.297438324@infradead.org> User-Agent: quilt/0.66 Date: Mon, 07 Aug 2023 14:18:51 +0200 From: Peter Zijlstra To: tglx@linutronix.de, axboe@kernel.dk Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, dvhart@infradead.org, dave@stgolabs.net, andrealmeid@igalia.com, Andrew Morton , urezki@gmail.com, hch@infradead.org, lstoakes@gmail.com, Arnd Bergmann , linux-api@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, malteskarupke@web.de Subject: [PATCH v2 08/14] futex: Add flags2 argument to futex_requeue() References: <20230807121843.710612856@infradead.org> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: 6bu8hycs1jwpag7u4uu3ze66brphkuoz X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 6203F40010 X-HE-Tag: 1691412942-434480 X-HE-Meta: U2FsdGVkX1/shFUksICRnkFq/fPN3Kl4NBI3k7sgB8mZj+wUjO2grX4sWHG/m5zwo3XOa8x1moS/WcF+A1i0rg34NlxyXq5dpF8zdS6OexIAmOWPEPRbbCF/zMb06wsHEGC8tp9ri/fkR4J4drNlT7iNKCwbC+a4Ysya7kduqYzuFLxUYWZ48GctrCEHr3Gav8ZwbZdfcKzYSbgGAozcUWz8zWIAQwpfB0UVBA8wCsdvKgMiYBeSytobsRhVZZ/oRdrPodUzU81iWGKHObESkXO54LLm8HSLGNxhWtb/z47H6EXFk/wRSHUFPX5bsS9weH52zSjRWI2rTSHRVkrkf2W9Vjr7MOSbTKnbKujSAG8DrSUvjQLHvx5tG2gP7qA72xy37DHwUPGficfwTZYxqfIqpkjvrOFliFxeCGJX4qWWWevKjcrfAnNU1cb5gEOkEnDSJVLkGBon0LbnbBEQ9qJqWdlOHWCoFhbK7RAj5cNp3rshucwpzhzACCXyMC2yg1z7z4O+xRkXM0+kCfkPH8sn+W5XFc8Cuce9puErI9cUF0i1wEaCJnxuaF7Ihqp+zXWStonYzCwmljLH7OVRZn5uS330qluFk2X2kRlZG8efr+fBiKSwpu39sxiZ2NtgXLRbzTjwFJi7JD5C0aoISVYXN+FVLHNCIe8IxzXU5fH4dg7BAS/D5fG+rb3mq/Jk355VX7UOz5nNpf6qHX3SSp+tjsImr2ydQCv33a1nm0niZetibKrnEi50GbWmqn+c0Gk+aMUt6hQvBD97ugoa/5AVM3SB0+Pmp8toD07tus9trN/ziBylrSI6Dfk9Iap9otVUOaMH0DRM6MrEHGJuournY29Zo9dvDwVZcxxe1FpK6Vf15wHJDs81OISHhTBOyxxvVLHnije8aWZneSZH6mE1lg2eND64z6CPsJXPW9elEWmgL+UwewxTFpuKPTZ/VqpcAhcb+vDWXrGPT51 ftM1H9fg Ai8gJJyC7onYqnr6MBrZcfhBJ5GxIJGbtX1/p7fgvTRIAoJCEO1qrIg13CEriNWurfbdtO7NZiGJZp0vN25HVbPbVfR2ALkNRnJZPNfF/cfxLaVt2+nwl53ht1rcqJW/nQ3UW88LHXlgwxxrd4Pt4b22qRNFHHPSvlspiBPOU0WGWKnFDJERd3Uvut+Sy0KPy1JmR6q/pCNGIM/oClPJz7JJNMquccXdlbmkk1Jw00Iv5aH7kNVrTKS38SwrW4e1FRdZq7ccr1/rK1ACHZvhxAOpCidTfAKE65zuV 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(-) --- a/kernel/futex/futex.h +++ b/kernel/futex/futex.h @@ -318,8 +318,9 @@ extern int futex_wait_requeue_pi(u32 __u val, ktime_t *abs_time, u32 bitset, u32 __user *uaddr2); -extern int futex_requeue(u32 __user *uaddr1, unsigned int flags, - u32 __user *uaddr2, int nr_wake, int nr_requeue, +extern int futex_requeue(u32 __user *uaddr1, unsigned int flags1, + u32 __user *uaddr2, unsigned int flags2, + int nr_wake, int nr_requeue, u32 *cmpval, int requeue_pi); extern int __futex_wait(u32 __user *uaddr, unsigned int flags, u32 val, --- a/kernel/futex/requeue.c +++ b/kernel/futex/requeue.c @@ -346,8 +346,9 @@ futex_proxy_trylock_atomic(u32 __user *p /** * futex_requeue() - Requeue waiters from uaddr1 to uaddr2 * @uaddr1: source futex user address - * @flags: futex flags (FLAGS_SHARED, etc.) + * @flags1: futex flags (FLAGS_SHARED, etc.) * @uaddr2: target futex user address + * @flags2: futex flags (FLAGS_SHARED, etc.) * @nr_wake: number of waiters to wake (must be 1 for requeue_pi) * @nr_requeue: number of waiters to requeue (0-INT_MAX) * @cmpval: @uaddr1 expected value (or %NULL) @@ -361,7 +362,8 @@ futex_proxy_trylock_atomic(u32 __user *p * - >=0 - on success, the number of tasks requeued or woken; * - <0 - on error */ -int futex_requeue(u32 __user *uaddr1, unsigned int flags, u32 __user *uaddr2, +int futex_requeue(u32 __user *uaddr1, unsigned int flags1, + u32 __user *uaddr2, unsigned int flags2, int nr_wake, int nr_requeue, u32 *cmpval, int requeue_pi) { union futex_key key1 = FUTEX_KEY_INIT, key2 = FUTEX_KEY_INIT; @@ -424,10 +426,10 @@ int futex_requeue(u32 __user *uaddr1, un } retry: - ret = get_futex_key(uaddr1, flags, &key1, FUTEX_READ); + ret = get_futex_key(uaddr1, flags1, &key1, FUTEX_READ); if (unlikely(ret != 0)) return ret; - ret = get_futex_key(uaddr2, flags, &key2, + ret = get_futex_key(uaddr2, flags2, &key2, requeue_pi ? FUTEX_WRITE : FUTEX_READ); if (unlikely(ret != 0)) return ret; @@ -459,7 +461,7 @@ int futex_requeue(u32 __user *uaddr1, un if (ret) return ret; - if (!(flags & FLAGS_SHARED)) + if (!(flags1 & FLAGS_SHARED)) goto retry_private; goto retry; --- a/kernel/futex/syscalls.c +++ b/kernel/futex/syscalls.c @@ -106,9 +106,9 @@ long do_futex(u32 __user *uaddr, int op, case FUTEX_WAKE_BITSET: return futex_wake(uaddr, flags, val, val3); case FUTEX_REQUEUE: - return futex_requeue(uaddr, flags, uaddr2, val, val2, NULL, 0); + return futex_requeue(uaddr, flags, uaddr2, flags, val, val2, NULL, 0); case FUTEX_CMP_REQUEUE: - return futex_requeue(uaddr, flags, uaddr2, val, val2, &val3, 0); + return futex_requeue(uaddr, flags, uaddr2, flags, val, val2, &val3, 0); case FUTEX_WAKE_OP: return futex_wake_op(uaddr, flags, uaddr2, val, val2, val3); case FUTEX_LOCK_PI: @@ -125,7 +125,7 @@ long do_futex(u32 __user *uaddr, int op, return futex_wait_requeue_pi(uaddr, flags, val, timeout, val3, uaddr2); case FUTEX_CMP_REQUEUE_PI: - return futex_requeue(uaddr, flags, uaddr2, val, val2, &val3, 1); + return futex_requeue(uaddr, flags, uaddr2, flags, val, val2, &val3, 1); } return -ENOSYS; } From patchwork Mon Aug 7 12:18:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13344113 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9227C001B0 for ; Mon, 7 Aug 2023 12:37:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B70E68D0002; Mon, 7 Aug 2023 08:37:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 974528E0002; Mon, 7 Aug 2023 08:37:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A4D5900003; Mon, 7 Aug 2023 08:37:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 10C128D0002 for ; Mon, 7 Aug 2023 08:37:10 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D344C160A37 for ; Mon, 7 Aug 2023 12:37:09 +0000 (UTC) X-FDA: 81097258578.11.03F1E03 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf06.hostedemail.com (Postfix) with ESMTP id CF3E5180002 for ; Mon, 7 Aug 2023 12:37:07 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=KqO2kuHf; spf=none (imf06.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691411828; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:references:dkim-signature; bh=Xi18wbHB7VNHKYqwwPbXtDuzrsECrr9c5XSVyiI+TAw=; b=7+wXp4nTtvEqvQy399cuLGiL+2SVmhZFlB0/kDowJLBh1NCrIhtvGeW1HGjgLrgMDe2S80 7OusQuDCB7zn7Hop3Z4Ss8VBcp5jV73FiNt6HPGeJyVY85PTOejafQKHyMCSE3ljRMc6v/ LkXI2jivTgaVqBukiKfSH0a7rWoT4a4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691411828; a=rsa-sha256; cv=none; b=F0Z+SkOKKJfaVvRYQcJKU1aL7ALz/FkTK+rCqtr+UA2ZVNrZXxrH2krkwTOjf5czbthJ+Q k1x052nRHUlxsa4Oe5Y3DXr7IcVZzub1HCvX5J28M4tCFXueVVON51BCnJJb5lRmL618/B eIvIhDwvhfwbwIBNN/Hp4wtoITH3t04= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=KqO2kuHf; spf=none (imf06.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=Xi18wbHB7VNHKYqwwPbXtDuzrsECrr9c5XSVyiI+TAw=; b=KqO2kuHfKLrv5u2OY576yuyqTS MpbOyrVFRvo7ba296aw60KiAk4fzQqtj8P72vWN0T9Hc1gT0+aqIWFhqLtPjy5vx0RzYrpumAIOG/ Aek+ye7WtBQr+4HWa5BCSjSCLXADV6kA8mvRfog3zxySGaAosFLdQH4qVcVj/HMrnrwcm+msHG8EC SbcijN7kTPA+UjQ9oTgsiSnlToZ4gjGygc+kq3ct6wQXAoIbErA5zu4gYUNuHSB7VDf7yhdnBnpOd yBQagzYNZhTMX0CGgF0nOZVyjZajZX9sDU6NaMQtsXEEShakqKKrGTlx5US3CXnxVos3p5Kx7zVd9 0aOFqbDA==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qSzTl-00AxGN-Ho; Mon, 07 Aug 2023 12:36:57 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 287AA30334C; Mon, 7 Aug 2023 14:36:56 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id B074B2021C3DC; Mon, 7 Aug 2023 14:36:54 +0200 (CEST) Message-ID: <20230807123323.366498604@infradead.org> User-Agent: quilt/0.66 Date: Mon, 07 Aug 2023 14:18:52 +0200 From: Peter Zijlstra To: tglx@linutronix.de, axboe@kernel.dk Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, dvhart@infradead.org, dave@stgolabs.net, andrealmeid@igalia.com, Andrew Morton , urezki@gmail.com, hch@infradead.org, lstoakes@gmail.com, Arnd Bergmann , linux-api@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, malteskarupke@web.de, Geert Uytterhoeven Subject: [PATCH v2 09/14] futex: Add sys_futex_requeue() References: <20230807121843.710612856@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: CF3E5180002 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: hrigg1wyfg44tngmkx6wgqz5853ijher X-HE-Tag: 1691411827-122153 X-HE-Meta: U2FsdGVkX19J3se0WZB5Oi05LgmkTG4VNBb+k7bG2g8/eE5DTnVPyWCjPgrIen5e74HMQFlP3fMblrA6xEmxgC95okhHF0BaBFyMMYN/s5kdc6SHsxXDzfOTgE1E+85lnI8NVvFlY0wC7j/UJUIXoRQDPtKZWOmhZzYn4SogKmabq9+I1nM2tjEAxkg1TbaIzScK/bPyMbv2s6EowAjOuu9L10XAnNrFi39eKy89hzAVPyDnZxJV69/3f2q81WxAr+W5RXrEegCPYBEMVFdi0Tlg58jdwqaeIAyaxWD/rQrg0as+ptNpDZ16qktXdGDtUeaZkEW/R/zOa9FEbdJM4gOhU/cA4NccrDDGPvndx7oy/WQljgSPCMBujwSzqUScwmpmMS01bl3Is8nbzxj6u77l3LVQfu5urxcEJ0nANFk02tMkwCjvk4+Z6lDYX9XWDRNDhSk0ArvwFF9iEeVZDQ8Mz8qs16rwboCMERNffyUGKU6tLC8lj39lXHa0Sxyl/oximz9TrYB1GO4GWvfTbMtZKL0oVQCUfCAznF22u9+LTv+ZbRNRATOLMZAi0N06zlZ+wcIdmhGANr/BIRwfQuXm22Pk6ZX9zJKcvdqvz5J+SlFCGTGgxoDHASMKuENs8BZHkNWcbbmCUrtJcOlYR7PMFFgYm4Vn3zFRCx7h2FCrfbGDxLCzOwW1BUwtSydKFPy1botVgjuZKsaiR3XGtC6MXtVgA93hMA+j/9O5DWipJdElB8RSlWjP3LTtReTVtlpCHaNVieJWkWkBaGTSctMRinSUWqd1YPzQl3WL/W+ABQ44tH+CCOIyBikdI9NCokG9FwQ/NSI1V7a4lgIN3L+8piWusjYwosSapfL+ZVF/bPK8NxdnMWQCD4+KYTdllxC55tb2uKRy5BM39YrLR5NWTBen5FhqXTQtl03CrziWqbnPDLKt60SgsRzov8P4xo/4dwHncNV3G9POSTD Vt8lbaBs rS/HJOPEzTkTtmarm4a8Re0u3yvTVjg5/FT+NWILL9aJXdSAw5hd/LaFu9+2zQvkzpCAlucoQjGkY5zZsxNHp9qGjkeoBBlE1Tp2DglOBr98+cW64j0Vj9QMhiVPV+sECRxG6rMW4LuFmBX+aer5NTPe6mWfrgjeP8u6pV4iOenEWCwljyAWUytVy41shVkSSMr15tQ9y19CobS1pDS7HjvW+2lZZHKqFp+9S2S2JV0ZjkMBwi53yXouRJ/tlF1PKl/hOOf44tR7rDYzO2duNXdHGGxVnJ6WoxGcXWcjkAQCsTg0L3omNkirlD+tUDMvdky5rtRU99QOrfwmhGLAe0tZRZKKZvadQEXim0uiQiGQ+LwiJ2CzOad+4+ZCEMReztuCT X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Finish of the 'simple' futex2 syscall group by adding sys_futex_requeue(). Unlike sys_futex_{wait,wake}() its arguments are too numerous to fit into a regular syscall. As such, use struct futex_waitv to pass the 'source' and 'destination' futexes to the syscall. This syscall implements what was previously known as FUTEX_CMP_REQUEUE and uses {val, uaddr, flags} for source and {uaddr, flags} for destination. This design explicitly allows requeueing between different types of futex by having a different flags word per uaddr. Signed-off-by: Peter Zijlstra (Intel) Acked-by: Geert Uytterhoeven Reviewed-by: Thomas Gleixner --- arch/alpha/kernel/syscalls/syscall.tbl | 1 arch/arm/tools/syscall.tbl | 1 arch/arm64/include/asm/unistd.h | 2 - arch/arm64/include/asm/unistd32.h | 2 + arch/ia64/kernel/syscalls/syscall.tbl | 1 arch/m68k/kernel/syscalls/syscall.tbl | 1 arch/microblaze/kernel/syscalls/syscall.tbl | 1 arch/mips/kernel/syscalls/syscall_n32.tbl | 1 arch/mips/kernel/syscalls/syscall_n64.tbl | 1 arch/mips/kernel/syscalls/syscall_o32.tbl | 1 arch/parisc/kernel/syscalls/syscall.tbl | 1 arch/powerpc/kernel/syscalls/syscall.tbl | 1 arch/s390/kernel/syscalls/syscall.tbl | 1 arch/sh/kernel/syscalls/syscall.tbl | 1 arch/sparc/kernel/syscalls/syscall.tbl | 1 arch/x86/entry/syscalls/syscall_32.tbl | 1 arch/x86/entry/syscalls/syscall_64.tbl | 1 arch/xtensa/kernel/syscalls/syscall.tbl | 1 include/linux/syscalls.h | 3 ++ include/uapi/asm-generic/unistd.h | 4 ++ kernel/futex/syscalls.c | 38 ++++++++++++++++++++++++++++ kernel/sys_ni.c | 1 22 files changed, 64 insertions(+), 2 deletions(-) --- a/arch/alpha/kernel/syscalls/syscall.tbl +++ b/arch/alpha/kernel/syscalls/syscall.tbl @@ -493,3 +493,4 @@ 561 common cachestat sys_cachestat 562 common futex_wake sys_futex_wake 563 common futex_wait sys_futex_wait +564 common futex_requeue sys_futex_requeue --- a/arch/arm/tools/syscall.tbl +++ b/arch/arm/tools/syscall.tbl @@ -467,3 +467,4 @@ 451 common cachestat sys_cachestat 452 common futex_wake sys_futex_wake 453 common futex_wait sys_futex_wait +454 common futex_requeue sys_futex_requeue --- a/arch/arm64/include/asm/unistd.h +++ b/arch/arm64/include/asm/unistd.h @@ -39,7 +39,7 @@ #define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE + 5) #define __ARM_NR_COMPAT_END (__ARM_NR_COMPAT_BASE + 0x800) -#define __NR_compat_syscalls 454 +#define __NR_compat_syscalls 455 #endif #define __ARCH_WANT_SYS_CLONE --- a/arch/arm64/include/asm/unistd32.h +++ b/arch/arm64/include/asm/unistd32.h @@ -913,6 +913,8 @@ __SYSCALL(__NR_cachestat, sys_cachestat) __SYSCALL(__NR_futex_wake, sys_futex_wake) #define __NR_futex_wait 453 __SYSCALL(__NR_futex_wait, sys_futex_wait) +#define __NR_futex_requeue 454 +__SYSCALL(__NR_futex_requeue, sys_futex_requeue) /* * Please add new compat syscalls above this comment and update --- a/arch/ia64/kernel/syscalls/syscall.tbl +++ b/arch/ia64/kernel/syscalls/syscall.tbl @@ -374,3 +374,4 @@ 451 common cachestat sys_cachestat 452 common futex_wake sys_futex_wake 453 common futex_wait sys_futex_wait +454 common futex_requeue sys_futex_requeue --- a/arch/m68k/kernel/syscalls/syscall.tbl +++ b/arch/m68k/kernel/syscalls/syscall.tbl @@ -453,3 +453,4 @@ 451 common cachestat sys_cachestat 452 common futex_wake sys_futex_wake 453 common futex_wait sys_futex_wait +454 common futex_requeue sys_futex_requeue --- a/arch/microblaze/kernel/syscalls/syscall.tbl +++ b/arch/microblaze/kernel/syscalls/syscall.tbl @@ -459,3 +459,4 @@ 451 common cachestat sys_cachestat 452 common futex_wake sys_futex_wake 453 common futex_wait sys_futex_wait +454 common futex_requeue sys_futex_requeue --- a/arch/mips/kernel/syscalls/syscall_n32.tbl +++ b/arch/mips/kernel/syscalls/syscall_n32.tbl @@ -392,3 +392,4 @@ 451 n32 cachestat sys_cachestat 452 n32 futex_wake sys_futex_wake 453 n32 futex_wait sys_futex_wait +454 n32 futex_requeue sys_futex_requeue --- a/arch/mips/kernel/syscalls/syscall_n64.tbl +++ b/arch/mips/kernel/syscalls/syscall_n64.tbl @@ -368,3 +368,4 @@ 451 n64 cachestat sys_cachestat 452 n64 futex_wake sys_futex_wake 453 n64 futex_wait sys_futex_wait +454 n64 futex_requeue sys_futex_requeue --- a/arch/mips/kernel/syscalls/syscall_o32.tbl +++ b/arch/mips/kernel/syscalls/syscall_o32.tbl @@ -441,3 +441,4 @@ 451 o32 cachestat sys_cachestat 452 o32 futex_wake sys_futex_wake 453 o32 futex_wait sys_futex_wait +454 o32 futex_requeue sys_futex_requeue --- a/arch/parisc/kernel/syscalls/syscall.tbl +++ b/arch/parisc/kernel/syscalls/syscall.tbl @@ -452,3 +452,4 @@ 451 common cachestat sys_cachestat 452 common futex_wake sys_futex_wake 453 common futex_wait sys_futex_wait +454 common futex_requeue sys_futex_requeue --- a/arch/powerpc/kernel/syscalls/syscall.tbl +++ b/arch/powerpc/kernel/syscalls/syscall.tbl @@ -540,3 +540,4 @@ 451 common cachestat sys_cachestat 452 common futex_wake sys_futex_wake 453 common futex_wait sys_futex_wait +454 common futex_requeue sys_futex_requeue --- a/arch/s390/kernel/syscalls/syscall.tbl +++ b/arch/s390/kernel/syscalls/syscall.tbl @@ -456,3 +456,4 @@ 451 common cachestat sys_cachestat sys_cachestat 452 common futex_wake sys_futex_wake sys_futex_wake 453 common futex_wait sys_futex_wait sys_futex_wait +454 common futex_requeue sys_futex_requeue sys_futex_requeue --- a/arch/sh/kernel/syscalls/syscall.tbl +++ b/arch/sh/kernel/syscalls/syscall.tbl @@ -456,3 +456,4 @@ 451 common cachestat sys_cachestat 452 common futex_wake sys_futex_wake 453 common futex_wait sys_futex_wait +454 common futex_requeue sys_futex_requeue --- a/arch/sparc/kernel/syscalls/syscall.tbl +++ b/arch/sparc/kernel/syscalls/syscall.tbl @@ -499,3 +499,4 @@ 451 common cachestat sys_cachestat 452 common futex_wake sys_futex_wake 453 common futex_wait sys_futex_wait +454 common futex_requeue sys_futex_requeue --- a/arch/x86/entry/syscalls/syscall_32.tbl +++ b/arch/x86/entry/syscalls/syscall_32.tbl @@ -458,3 +458,4 @@ 451 i386 cachestat sys_cachestat 452 i386 futex_wake sys_futex_wake 453 i386 futex_wait sys_futex_wait +454 i386 futex_requeue sys_futex_requeue --- a/arch/x86/entry/syscalls/syscall_64.tbl +++ b/arch/x86/entry/syscalls/syscall_64.tbl @@ -375,6 +375,7 @@ 451 common cachestat sys_cachestat 452 common futex_wake sys_futex_wake 453 common futex_wait sys_futex_wait +454 common futex_requeue sys_futex_requeue # # Due to a historical design error, certain syscalls are numbered differently --- a/arch/xtensa/kernel/syscalls/syscall.tbl +++ b/arch/xtensa/kernel/syscalls/syscall.tbl @@ -424,3 +424,4 @@ 451 common cachestat sys_cachestat 452 common futex_wake sys_futex_wake 453 common futex_wait sys_futex_wait +454 common futex_requeue sys_futex_requeue --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -570,6 +570,9 @@ asmlinkage long sys_futex_wait(void __us unsigned int flags, struct __kernel_timespec __user *timespec, clockid_t clockid); +asmlinkage long sys_futex_requeue(struct futex_waitv __user *waiters, + unsigned int flags, int nr_wake, int nr_requeue); + asmlinkage long sys_nanosleep(struct __kernel_timespec __user *rqtp, struct __kernel_timespec __user *rmtp); asmlinkage long sys_nanosleep_time32(struct old_timespec32 __user *rqtp, --- a/include/uapi/asm-generic/unistd.h +++ b/include/uapi/asm-generic/unistd.h @@ -822,9 +822,11 @@ __SYSCALL(__NR_cachestat, sys_cachestat) __SYSCALL(__NR_futex_wake, sys_futex_wake) #define __NR_futex_wait 453 __SYSCALL(__NR_futex_wait, sys_futex_wait) +#define __NR_futex_requeue 454 +__SYSCALL(__NR_futex_requeue, sys_futex_requeue) #undef __NR_syscalls -#define __NR_syscalls 454 +#define __NR_syscalls 455 /* * 32 bit systems traditionally used different --- a/kernel/futex/syscalls.c +++ b/kernel/futex/syscalls.c @@ -396,6 +396,44 @@ SYSCALL_DEFINE6(futex_wait, return ret; } +/* + * sys_futex_requeue - Requeue a waiter from one futex to another + * @waiters: array describing the source and destination futex + * @flags: unused + * @nr_wake: number of futexes to wake + * @nr_requeue: number of futexes to requeue + * + * Identical to the traditional FUTEX_CMP_REQUEUE op, except it is part of the + * futex2 family of calls. + */ + +SYSCALL_DEFINE4(futex_requeue, + struct futex_waitv __user *, waiters, + unsigned int, flags, + int, nr_wake, + int, nr_requeue) +{ + struct futex_vector futexes[2]; + u32 cmpval; + int ret; + + if (flags) + return -EINVAL; + + if (!waiters) + return -EINVAL; + + ret = futex_parse_waitv(futexes, waiters, 2); + if (ret) + return ret; + + cmpval = futexes[0].w.val; + + return futex_requeue(u64_to_user_ptr(futexes[0].w.uaddr), futexes[0].w.flags, + u64_to_user_ptr(futexes[1].w.uaddr), futexes[1].w.flags, + nr_wake, nr_requeue, &cmpval, 0); +} + #ifdef CONFIG_COMPAT COMPAT_SYSCALL_DEFINE2(set_robust_list, struct compat_robust_list_head __user *, head, --- a/kernel/sys_ni.c +++ b/kernel/sys_ni.c @@ -89,6 +89,7 @@ COND_SYSCALL_COMPAT(get_robust_list); COND_SYSCALL(futex_waitv); COND_SYSCALL(futex_wake); COND_SYSCALL(futex_wait); +COND_SYSCALL(futex_requeue); COND_SYSCALL(kexec_load); COND_SYSCALL_COMPAT(kexec_load); COND_SYSCALL(init_module); From patchwork Mon Aug 7 12:18:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13344118 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 42DFBC10F19 for ; Mon, 7 Aug 2023 12:37:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AAD598D0007; Mon, 7 Aug 2023 08:37:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7574F900003; Mon, 7 Aug 2023 08:37:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 338C8900007; Mon, 7 Aug 2023 08:37:11 -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 8EA716B0078 for ; Mon, 7 Aug 2023 08:37:10 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 3DDCD140A2C for ; Mon, 7 Aug 2023 12:37:10 +0000 (UTC) X-FDA: 81097258620.09.8156FE8 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf09.hostedemail.com (Postfix) with ESMTP id 71675140026 for ; Mon, 7 Aug 2023 12:37:07 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=DIfNmxEY; dmarc=none; spf=none (imf09.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691411827; 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=yhuAOwd3npGJeiWmKJXyciafSAGyeTkzn0KP+zTqoEU=; b=32IyyRaMGj0Yck7fN2LyuzF8BsxeCllRM1zZ9yEb1YWCXpIPdm2gbu/+0AZBVJ0cki/15G KrGv8JHX4racuVI1PPPnjg9PWucHiTBYO/LEhQzEYTFfa249C/kvnAMAJcGi7ylp5EWe9J SXykl6L2FCgmgAWe6rFGkgYr52PBsIE= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=DIfNmxEY; dmarc=none; spf=none (imf09.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691411827; a=rsa-sha256; cv=none; b=RDY11/crF/Zm3m6/27Re0yhMD1aZdYdPufogLE/JF1274qZqQ61tWrbrghs/JpBASmuwti dAlu7j/+TZ3IgH0/3iIAKd3Q57JCu7YExS/DtMYDtG0IA4c6f9h4hClrCaaT1HSt6Q6JmY syh9VsEpYjQNtsdic2jVnINNGv0CwBI= 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=yhuAOwd3npGJeiWmKJXyciafSAGyeTkzn0KP+zTqoEU=; b=DIfNmxEY7NkuxRZGvTBNvETWLd ddtah769bA3DgEscE0yGOSe5I39fPDiu5Mjvo17Y567v9fB2s7UX2zdEL/95eWCfI3b3Q1PhxBfaY LYDstXbDtVxb/OurZOWFFWwWlAgq3BKqt2A4y2gFBkoO5WtEh/Pn60AQf1xOMd9mA8wonY7weYkEp Bx9EOyLBwrEFqUCS0it9omaKgOhmDSlZW0dv+uiZc5hKDPEZXaJU2140Vc2QBw/ncEUVuJibJQxVw lTJr2P9b8KYQTkBIXzNM11ot2CJ4W9zOw6AmQWhQLaNvpx7A5KkfFbaocB0ejMdjiL0f3fMIPCfTt T0c0m83Q==; 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 1qSzTl-003oSl-1d; Mon, 07 Aug 2023 12:36:58 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 2DAA73033B1; Mon, 7 Aug 2023 14:36:56 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id B72A22021C3DB; Mon, 7 Aug 2023 14:36:54 +0200 (CEST) Message-ID: <20230807123323.434708155@infradead.org> User-Agent: quilt/0.66 Date: Mon, 07 Aug 2023 14:18:53 +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, Christoph Hellwig Subject: [PATCH v2 10/14] mm: Add vmalloc_huge_node() References: <20230807121843.710612856@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 71675140026 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: bbuyw345859uied4juzjqn66zew19gqi X-HE-Tag: 1691411827-647716 X-HE-Meta: U2FsdGVkX19c7OdW6LbkdvgQERA4Tz0CFyqejFIs+SfDZAJTVe2RngnGNu3jn5/LyVCBuuyr7QaeziTumyZTjrAt9I9RBAfjI7fGmKRNB/j3JXHQkK8i34vdA48qD/CAU2Kq5f638Oy7ACQ/J5ASzlaMA+NsXtflECKGBsw/PyHg9dsTJi+VCwzKXXETwtXdCVvr6GeRR0YaX1Yv36krB4k6QnEJysbLzkbpeh1g8LI1g2kqlSOjWFNSlYn3gx9hYGk8Y2hPIMDvlj/nHDBcCt8jqhzbtSJOFqajGvI1pz9yNY/rIoAerC5kqvSylCLA14Nh7MvXUPhz1lDZ/gCmjCQ/u4nUfDfuTMRe9RXa4lue70P0eIH24GdUWDo7s8YCNcokGC0t4d/cyBiM8/Pj05xjWOd1LxuGHO/q1nGs8PksqkTFaPv0kspJ24I3tIV89vI1WCAbc5EosC5zqmjzso8YW0LINC8CqEK1QOz3r+WEpv8H6deuok3mnfC5vE+vaX0FEvk/2tHmKxsk7CqNcfL/+ng7wnuk7anZnLNwSc58NsW+ymkyaUIyEK0DJT9b3u+8zLiGuVrO/jsZi4ZpDPhc3DwjuOTSmJLFFQMzs8cTspkmfLeJjwfiup1sUm65JMEOxvTZsps6xgVPNM2/nppxrUcBCoAkRmEZIgUrz70xEtcSzumYKGjaYkE5vu4Mp59V/b9V4Bb4quq//IpWLyKQeBrkM8JSc/Ks2x8b/h+vbrRc4OhTTuo0+w1WU2YzXfRHXrs7SPPoDaSpMECXpyy+ZXdoHtnkCR1OG3/x7qF5eaV5p9tpqCIpdLDOZdvypMpi16ppZyschka8FRnT0JXMh94eR2vZbFnY60RLcMKOz2TkjNGpW1KsSPU+zobZC4DrbUXpRHskOOHqlHf0yM5ENRPQCs2QHoSHr2Dlabf+s9Z6L+SY/u/qfAkk3vJUYFl4Ns6b5I7vwCTFHFw 6s4haHcY b2qLynktlwjFfsf8vpU7vgIcOypVmhTmdsBKqNaA4InXtjkv5im4N5rB3tpYUE27/Az0MaUVsGS44JjBo1hXP203rUi0YCip7GJ3j8v0KJ2ZlR41WaCf97OfGnbhZbRZgFh2NxfXmocVDZZ7ay/EfGrg9zeHoiYKRrJJctMasNfbOOhiJPbEDhHKVE37r4tYKolWUIBEgM2uXKS20eMbqxyOmTHb65iqkDby8jfRAYua3JKImEPiteJ36FFEZdFEBmixbu3s7tjeEEkYwlf9lL9LOwQtNEV0KZYMcY6KgpPs2g/anniZb62OjToOSpdOEOHZc X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: To enable node specific hash-tables. Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Christoph Hellwig --- include/linux/vmalloc.h | 1 + mm/vmalloc.c | 7 +++++++ 2 files changed, 8 insertions(+) --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -152,6 +152,7 @@ extern void *__vmalloc_node_range(unsign void *__vmalloc_node(unsigned long size, unsigned long align, gfp_t gfp_mask, int node, const void *caller) __alloc_size(1); void *vmalloc_huge(unsigned long size, gfp_t gfp_mask) __alloc_size(1); +void *vmalloc_huge_node(unsigned long size, gfp_t gfp_mask, int node) __alloc_size(1); extern void *__vmalloc_array(size_t n, size_t size, gfp_t flags) __alloc_size(1, 2); extern void *vmalloc_array(size_t n, size_t size) __alloc_size(1, 2); --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3416,6 +3416,13 @@ void *vmalloc(unsigned long size) } EXPORT_SYMBOL(vmalloc); +void *vmalloc_huge_node(unsigned long size, gfp_t gfp_mask, int node) +{ + return __vmalloc_node_range(size, 1, VMALLOC_START, VMALLOC_END, + gfp_mask, PAGE_KERNEL, VM_ALLOW_HUGE_VMAP, + node, __builtin_return_address(0)); +} + /** * vmalloc_huge - allocate virtually contiguous memory, allow huge pages * @size: allocation size From patchwork Mon Aug 7 12:18:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13344112 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 B3FCBC001DF for ; Mon, 7 Aug 2023 12:37:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 820426B0075; Mon, 7 Aug 2023 08:37:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 72A1C8D0002; Mon, 7 Aug 2023 08:37:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 46BCA6B0075; Mon, 7 Aug 2023 08:37:10 -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 04CEF6B0078 for ; Mon, 7 Aug 2023 08:37:10 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id BC3A0A0A3A for ; Mon, 7 Aug 2023 12:37:09 +0000 (UTC) X-FDA: 81097258578.15.0A4B54C Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf29.hostedemail.com (Postfix) with ESMTP id 85909120015 for ; Mon, 7 Aug 2023 12:37:07 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=rPipdjkX; 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=1691411828; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:references:dkim-signature; bh=15dV+fw3TVZwuZ2GLz+s4AB6Ib3B7DldkK+IHYVR8MU=; b=ZrKmBmaJSZtiWKsbPv54CGabsMApVjK8y6235gyioOSlHZ4CXMXstJxzjkNEr85wCtCgcm KEXZQkHt/W9N4djB4mvI2uR8HdOguAEMkK9AhcHNBjwhlVJHxp113+fPHVp75E2O+DaWkt sNhSPb9iUi7NNm/K/4f7At+TiRJI8HY= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=rPipdjkX; 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=1691411828; a=rsa-sha256; cv=none; b=yaYTCVRrzlYsn7NaxzpHJTiJB8I2So7N+UaU0YAsUhNV9/Kxrcw7dNu+d9nFBqAj7zMN/u pURr9KndGGrHpm60dQZgMRKwpbImevLNxHpzYJsvHDWeCuzGQpa83a9DgSTufD+oxVMuyb P+HHWt10Uom8U0bhBfCakcKtD0pt7XQ= 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=15dV+fw3TVZwuZ2GLz+s4AB6Ib3B7DldkK+IHYVR8MU=; b=rPipdjkXy2N64QJCm3H49Wb5YA s2TPd1tAd7bFDfW/5nyPT5H2/NrqKO7byVKH7j2gZYeLITPjUUMdOTl4F57jAyJFa3J4fmmpUhMug 8dLUwR/TM/6SD8smp7MtGFdU1hN4l6p2XUy9FA30zOZJmzR+UbAF6KsRMEZbHlTnSPNe3cz9k+Svw V6bFGevXhncv9QbCtNwhbsvoOUQynVl1GzEMcjL6hhEtXF8f78PhIAVAma6BiVNd1o70j/HZ2E8+1 meAATMOisxckPnmmuzz9EcDDZwowdLZGsA5Z691qKWRah5tXHHQZzS2V3VaClSFj1WTC956zmoakZ DXK6aBGg==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qSzTl-00AxGK-GQ; Mon, 07 Aug 2023 12:36:57 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 307603033B5; Mon, 7 Aug 2023 14:36:56 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id BC0D12021C3D6; Mon, 7 Aug 2023 14:36:54 +0200 (CEST) Message-ID: <20230807123323.504975124@infradead.org> User-Agent: quilt/0.66 Date: Mon, 07 Aug 2023 14:18:54 +0200 From: Peter Zijlstra To: tglx@linutronix.de, axboe@kernel.dk Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, dvhart@infradead.org, dave@stgolabs.net, andrealmeid@igalia.com, Andrew Morton , urezki@gmail.com, hch@infradead.org, lstoakes@gmail.com, Arnd Bergmann , linux-api@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, malteskarupke@web.de Subject: [PATCH v2 11/14] futex: Implement FUTEX2_NUMA References: <20230807121843.710612856@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 85909120015 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: p6fz1wzeb16c5imirjwpbmca59hsy9kp X-HE-Tag: 1691411827-117552 X-HE-Meta: U2FsdGVkX1+2tZGyztPJ50ZGUkCCyHioOWbpJLZuzCksZMqRR8gfhNdg5SCIOtoyQaJTAZxJbvUYoY3mzIvLFEkjDGL1FO5A6B8QG2STkczOXPTXhBbNqZhfnX4lkk46E/wCXOtQO4XDqt3e67bbZDJ/DSuSxNz0U0s6ozRVaQ7caObY4twRXN/qu1DjGtnG6j9Y4dfvFloXg9/dD8Rm13SznQ1bHze01Lhp4CJaZFGk20UktQg01eiN6hbXzbkcHztXE4XWnfIkMMMEtPkbwy9f9AdwFkCtzlPqZG5OK3qCA4HepUqqCJ2dbcT2p6NBWYpXY7asuAtWQQjw3HHbyHV5nyCou6Gt8cJPSn8IDf23j/MXYBnLzltDf1ddNgPLCPStZdXj+cp6Ccbxrr+gLvkM0LT81D3zNnQscB2AKJcOkZZSCJfOYelDEz/c4oJDvrboummqq97c/oD+myKULDNVk0/3Caz8ikkS6OLBiIsSoU30gZE6OORm6Vw9WQ8QpSNgzQx5OI/BdyRvU0JaMKiFovsNOuPQNdRjx9+BVyWYxpCsIbz81oOo14XtQ3vGfgNfjQIqS5hmibqOz6qkQMJN75sMjoFomenkN/LJhHZtagatsRLZRnyXDETMEBmVzy8ViJcTqp+lS1D7W3rlla6HyZAViCFFj78wTVuJwlyNT0+Q0LPrvYKz1+pKuiIjn9oKHu/Wbs55j7KqybnWRTFfZZpUT2pVhCys2YgQxCpL2/SsbR2HgfAo1bLRRgS9JYlBXWjEvUYkUExp4b8rU5K1Kn6aLcse3M8Es/oY5nDHqbLhXlJHxII+TtuGsZFWhwFaxVu4dJMWK8UexFq9L3M7zIDPC1PMJl/A5d9VgxAZUkT2f0YZBPQSdym/XzD6F5209Q0lQGEO9+ezvFBYU6eLt/WlTdxipIuQCNNnaGsWaVMqX/NZAp9xOQ8QN8k+UqIbRh/RbVj+OTnbTvH 1rgnM7U1 Xn5BSAtEqMf6YgRvruto/A9cW+dsKCNIzwYmFRh0unOFINwYFn/ikf2R4rf17QxFS66M//1ADiEaYTFSmMPoK7iLN/YBqtWK2vZ1o63rqWZcazyPVr1/d0Mp8LWhhMV6tKE3WhSJyL+ZmqNovqg8S8aI7yWgxcorsmfzbvaM0mn9PaYW7iTYYJcnq2PtLq2imWxiokT8T4GQQAtHQl1GuxBeL5+gXiWOTr9/CLYJn7AO904Vmk00H3rOrO7Fxp9VhF+PjEGtBSL3/ZiudTdqt3+/Xz174wKAQKjwb 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(-) --- a/include/linux/futex.h +++ b/include/linux/futex.h @@ -34,6 +34,7 @@ union futex_key { u64 i_seq; unsigned long pgoff; unsigned int offset; + /* unsigned int node; */ } shared; struct { union { @@ -42,11 +43,13 @@ union futex_key { }; unsigned long address; unsigned int offset; + /* unsigned int node; */ } private; struct { u64 ptr; unsigned long word; unsigned int offset; + unsigned int node; /* NOT hashed! */ } both; }; --- a/kernel/futex/core.c +++ b/kernel/futex/core.c @@ -34,7 +34,8 @@ #include #include #include -#include +#include +#include #include #include @@ -47,12 +48,14 @@ * reside in the same cacheline. */ static struct { - struct futex_hash_bucket *queues; unsigned long hashsize; + unsigned int hashshift; + struct futex_hash_bucket *queues[MAX_NUMNODES]; } __futex_data __read_mostly __aligned(2*sizeof(long)); -#define futex_queues (__futex_data.queues) -#define futex_hashsize (__futex_data.hashsize) +#define futex_hashsize (__futex_data.hashsize) +#define futex_hashshift (__futex_data.hashshift) +#define futex_queues (__futex_data.queues) /* * Fault injections for futexes. @@ -105,6 +108,26 @@ late_initcall(fail_futex_debugfs); #endif /* CONFIG_FAIL_FUTEX */ +static int futex_get_value(u32 *val, u32 __user *from, unsigned int flags) +{ + switch (futex_size(flags)) { + case 1: return __get_user(*val, (u8 __user *)from); + case 2: return __get_user(*val, (u16 __user *)from); + case 4: return __get_user(*val, (u32 __user *)from); + default: BUG(); + } +} + +static int futex_put_value(u32 val, u32 __user *to, unsigned int flags) +{ + switch (futex_size(flags)) { + case 1: return __put_user(val, (u8 __user *)to); + case 2: return __put_user(val, (u16 __user *)to); + case 4: return __put_user(val, (u32 __user *)to); + default: BUG(); + } +} + /** * futex_hash - Return the hash bucket in the global hash * @key: Pointer to the futex key for which the hash is calculated @@ -114,10 +137,29 @@ late_initcall(fail_futex_debugfs); */ struct futex_hash_bucket *futex_hash(union futex_key *key) { - u32 hash = jhash2((u32 *)key, offsetof(typeof(*key), both.offset) / 4, + u32 hash = jhash2((u32 *)key, + offsetof(typeof(*key), both.offset) / sizeof(u32), key->both.offset); + int node = key->both.node; + + if (node == -1) { + /* + * In case of !FLAGS_NUMA, use some unused hash bits to pick a + * node -- this ensures regular futexes are interleaved across + * the nodes and avoids having to allocate multiple + * hash-tables. + * + * NOTE: this isn't perfectly uniform, but it is fast and + * handles sparse node masks. + */ + node = (hash >> futex_hashshift) % nr_node_ids; + if (!node_possible(node)) { + node = find_next_bit_wrap(node_possible_map.bits, + nr_node_ids, node); + } + } - return &futex_queues[hash & (futex_hashsize - 1)]; + return &futex_queues[node][hash & (futex_hashsize - 1)]; } @@ -217,32 +259,56 @@ static u64 get_inode_sequence_number(str * * lock_page() might sleep, the caller should not hold a spinlock. */ -int get_futex_key(u32 __user *uaddr, unsigned int flags, union futex_key *key, +int get_futex_key(void __user *uaddr, unsigned int flags, union futex_key *key, enum futex_access rw) { unsigned long address = (unsigned long)uaddr; struct mm_struct *mm = current->mm; struct page *page, *tail; struct address_space *mapping; - int err, ro = 0; + int node, err, size, ro = 0; bool fshared; fshared = flags & FLAGS_SHARED; + size = futex_size(flags); + 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 == -1) { + 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 = -1; + } + /* * PROCESS_PRIVATE futexes are fast. * As the mm cannot disappear under us and the 'key' only needs @@ -1125,27 +1191,42 @@ void futex_exit_release(struct task_stru static int __init futex_init(void) { - unsigned int futex_shift; - unsigned long i; + unsigned int order, n; + unsigned long size, i; #if CONFIG_BASE_SMALL futex_hashsize = 16; #else - futex_hashsize = roundup_pow_of_two(256 * num_possible_cpus()); + futex_hashsize = 256 * num_possible_cpus(); + futex_hashsize /= num_possible_nodes(); + futex_hashsize = roundup_pow_of_two(futex_hashsize); #endif + futex_hashshift = ilog2(futex_hashsize); + size = sizeof(struct futex_hash_bucket) * futex_hashsize; + order = get_order(size); + + for_each_node(n) { + struct futex_hash_bucket *table; + + if (order > MAX_ORDER) + table = vmalloc_huge_node(size, GFP_KERNEL, n); + else + table = alloc_pages_exact_nid(n, size, GFP_KERNEL); + + BUG_ON(!table); + + for (i = 0; i < futex_hashsize; i++) { + atomic_set(&table[i].waiters, 0); + spin_lock_init(&table[i].lock); + plist_head_init(&table[i].chain); + } - futex_queues = alloc_large_system_hash("futex", sizeof(*futex_queues), - futex_hashsize, 0, - futex_hashsize < 256 ? HASH_SMALL : 0, - &futex_shift, NULL, - futex_hashsize, futex_hashsize); - futex_hashsize = 1UL << futex_shift; - - for (i = 0; i < futex_hashsize; i++) { - atomic_set(&futex_queues[i].waiters, 0); - plist_head_init(&futex_queues[i].chain); - spin_lock_init(&futex_queues[i].lock); + futex_queues[n] = table; } + pr_info("futex hash table, %d nodes, %ld entries (order: %d, %lu bytes)\n", + num_possible_nodes(), + futex_hashsize, order, + sizeof(struct futex_hash_bucket) * futex_hashsize); return 0; } --- a/kernel/futex/futex.h +++ b/kernel/futex/futex.h @@ -65,6 +65,11 @@ static inline unsigned int futex2_to_fla 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 */ @@ -77,12 +82,20 @@ static inline bool futex_flags_valid(uns if ((flags & FLAGS_SIZE_MASK) != FLAGS_SIZE_32) return false; - return true; -} + /* + * Must be able to represent both NUMA_NO_NODE and every valid nodeid + * in a futex word. + */ + if (flags & FLAGS_NUMA) { + int bits = 8 * futex_size(flags); + u64 max = ~0ULL; -static inline unsigned int futex_size(unsigned int flags) -{ - return 1 << (flags & FLAGS_SIZE_MASK); + max >>= 64 - bits; + if (nr_node_ids >= max) + return false; + } + + return true; } static inline bool futex_validate_input(unsigned int flags, u64 val) @@ -183,7 +196,7 @@ enum futex_access { FUTEX_WRITE }; -extern int get_futex_key(u32 __user *uaddr, unsigned int flags, union futex_key *key, +extern int get_futex_key(void __user *uaddr, unsigned int flags, union futex_key *key, enum futex_access rw); extern struct hrtimer_sleeper * --- a/kernel/futex/syscalls.c +++ b/kernel/futex/syscalls.c @@ -179,7 +179,7 @@ SYSCALL_DEFINE6(futex, u32 __user *, uad return do_futex(uaddr, op, val, tp, uaddr2, (unsigned long)utime, val3); } -#define FUTEX2_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 From patchwork Mon Aug 7 12:18:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13344110 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 DB618C04A6A for ; Mon, 7 Aug 2023 12:37:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 12CF78D0003; Mon, 7 Aug 2023 08:37:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DBB528D0005; Mon, 7 Aug 2023 08:37:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C0C1B6B0078; Mon, 7 Aug 2023 08:37:09 -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 ABF418D0002 for ; Mon, 7 Aug 2023 08:37:09 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 72FC2C0A62 for ; Mon, 7 Aug 2023 12:37:09 +0000 (UTC) X-FDA: 81097258578.16.F5B76B6 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf02.hostedemail.com (Postfix) with ESMTP id A7CD98001D for ; Mon, 7 Aug 2023 12:37:07 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=gkcqeHyP; spf=none (imf02.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691411827; 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=sh7cl6AJW0b0f2uQNaiBLh5jyRqhKF5FPfLTlh7soFE=; b=Un8DGGqs+7ljHB8MMnlVIDt2DtOXMQmlXEkM4F/QsxwfEjmyiTT+49MApcvD80egNgPiBi afSFeolyXEyiFcMU1Sls+AlkvCZK/Mb4X3dtvt9/Zkobod3bGvIzjXXFGlioxEU4/5NMoh yudliM8DYeX5V6kdkrDAh2Qqw1BQnuo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691411827; a=rsa-sha256; cv=none; b=ITX5/7xAj1s8Z2XnrWYBZyZuzfvoKlMj03GlN2mRv4jr+Qown1MlAhq4JrqY51AkQAegfP Yginv5B8TbBny7IfiaARu+xOLde0v+DOzVl0x3AlynW56R6uKmttWhSuSxcYbH2tjR5Ubl I/bYNwqAQ5/ne04f+bDEra8vRBwkstU= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=gkcqeHyP; spf=none (imf02.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=sh7cl6AJW0b0f2uQNaiBLh5jyRqhKF5FPfLTlh7soFE=; b=gkcqeHyPgX7jzxCrnbCbVQRmKU sxoBoTTJB+eaxMv4o9RWqLYYrr00tzh8Y9tp8nLHPktfM1FlIWx2vk2VRzQe8Q7POGb5HzWl2G6DB +UaFAkRrHRqmTrT5H0aEIWsB903bT6N4SHjiTV15ToaPCWPDJVDqaN1jbyrjUE9/kYCon9BGbjwfG bwREGmgtoAiEptkoyJahuC3WQqM8EuiXjVpJxEg9tVZr/XerxfvGQ3Fof5g32eL8vZq92giDChBrA JAavjQYe3tEWK6PnJUoleS9+plUE+y4ttVSq9quCRNjAa1c6d7MBwqkeAzyLAaklJPnpTzmlb5Ffw yMOOu43w==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qSzTl-00AxGJ-GT; Mon, 07 Aug 2023 12:36:57 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 336FE3033D4; Mon, 7 Aug 2023 14:36:56 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id C12802021C3DD; Mon, 7 Aug 2023 14:36:54 +0200 (CEST) Message-ID: <20230807123323.573374169@infradead.org> User-Agent: quilt/0.66 Date: Mon, 07 Aug 2023 14:18:55 +0200 From: Peter Zijlstra To: tglx@linutronix.de, axboe@kernel.dk Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, dvhart@infradead.org, dave@stgolabs.net, andrealmeid@igalia.com, Andrew Morton , urezki@gmail.com, hch@infradead.org, lstoakes@gmail.com, Arnd Bergmann , linux-api@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, malteskarupke@web.de Subject: [PATCH v2 12/14] futex: Propagate flags into futex_get_value_locked() References: <20230807121843.710612856@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: A7CD98001D X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: hcqi1hzj58qd1ag7zafkrqbonuib6qto X-HE-Tag: 1691411827-916402 X-HE-Meta: U2FsdGVkX19X1RmvXSsF+uaLVimFxAuIYQHtfcmZJjZX6axBllv0tpzKsAj5Fyinz0rRjLpUigsEuVebv+d9HMquziYkOPtzULDmsw0k3PdjBqHtaf94YrVYYH75bGW5JAiNXEsRU8Gtl1cFJIK7xkVx5N8ZG8lrk2dIPJJ4qv+LaDjGKlHNInRKEsEPir4qu02yGDOVwRoFy6Ek1M3c5vAwC6IBK2gKWFzFh3WQ6bve+zQfQ78ebyrSefUxXUzpvfJ2RZ3aeYRihkKLqvsYMh81Py6nccGe9f5hnvnvlLn/AISuKDet8vsiNA0o4ocTqVfoLRtLJ0CtxsgsT3KyB4RhkMWfHMcKyTkA9McYZHIJhBJz3hH8XwKscXnMDmdSvXk5DnK+RX3JkVE/3U9nXjZxGh6H4MkoF0eRhfqWdHQrhwq7ZnOxys3XT0KnlutkZaAQCBCLpbxEBakfrNHZLGBYWhCr281y7htbiqmPVNDmBevbFDLo6NmujWXQHJg7CKYDsSCKaFp/5KmNGraBy+9zGPS50OHjA2atATbnvffzIgpkrIHpyOlIXlwbjFd1NBtC62jEpRPIDvbItisAlNPtuFU4d2Nco+lHnjNtgu72esWpuVNmuGTbKimOU9C5A9oXM3cmPdcZe+QlTrObVDqBQI5Ese7DJYgWAWuc03EAIZd7LLu2IZw2PJaaoc5rP03FcDaFzn0Oq/bvtRww3C/HQx/R4GtbnJBtGwKmZnmnF3ITmi3sRkzTqB9E7u//SwGOfTeNBa32lw4Nx6YgE5Rok1xW907qTjqfR7aEZpphdSK/vZNFWTLiwyOODi9t61+u9YDObZdh3nqXapPctA/5B0IvWP9bwMKIV7DCEhCEiEL+tH23FM0+7LmNrmr92f7fqng0XVt8J7N5UOwgTt5l+m+NPrC9s/gU6n78ZQsFvRZmN0zTYvZ+2gTk28P9/d71xEe9rMtahlz6hwa JvN+bZqS fvEx8PGCxY7wMsD0h7wSs/W4KdHdS6LrBBr3nPjHJz3WkS/UqKWy6+7wJfDO5pxviZ3T9bjamPFIoBCX8SnhXSPR5NTSxZvnD6whB9ZG0XCOSSjO9jRgpzO8deAhuYIEeRdXhhX9BUXb63rSjYNmltYa/Gy7Op2ByHpn4QZGZNoXB+Id3UcY6gQm16lUJI9i9/sD19IUazFEebxavqK8HoQyKOx8lCW7FJGpHNRHHMof4z8PcRPI8irrFVQChfOrjYnHEWC2upy3ypGkhy4sqhZOf5YYSyru4m64X51QTrvyIuq663QPJGdQGaJbPRr3uY8T9 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(-) --- a/kernel/futex/core.c +++ b/kernel/futex/core.c @@ -515,12 +515,12 @@ int futex_cmpxchg_value_locked(u32 *curv return ret; } -int futex_get_value_locked(u32 *dest, u32 __user *from) +int futex_get_value_locked(u32 *dest, u32 __user *from, unsigned int flags) { int ret; pagefault_disable(); - ret = __get_user(*dest, from); + ret = futex_get_value(dest, from, flags); pagefault_enable(); return ret ? -EFAULT : 0; --- a/kernel/futex/futex.h +++ b/kernel/futex/futex.h @@ -218,7 +218,7 @@ extern void futex_wake_mark(struct wake_ extern int fault_in_user_writeable(u32 __user *uaddr); extern int futex_cmpxchg_value_locked(u32 *curval, u32 __user *uaddr, u32 uval, u32 newval); -extern int futex_get_value_locked(u32 *dest, u32 __user *from); +extern int futex_get_value_locked(u32 *dest, u32 __user *from, unsigned int flags); extern struct futex_q *futex_top_waiter(struct futex_hash_bucket *hb, union futex_key *key); extern void __futex_unqueue(struct futex_q *q); --- a/kernel/futex/pi.c +++ b/kernel/futex/pi.c @@ -239,7 +239,7 @@ static int attach_to_pi_state(u32 __user * still is what we expect it to be, otherwise retry the entire * operation. */ - if (futex_get_value_locked(&uval2, uaddr)) + if (futex_get_value_locked(&uval2, uaddr, FLAGS_SIZE_32)) goto out_efault; if (uval != uval2) @@ -358,7 +358,7 @@ static int handle_exit_race(u32 __user * * The same logic applies to the case where the exiting task is * already gone. */ - if (futex_get_value_locked(&uval2, uaddr)) + if (futex_get_value_locked(&uval2, uaddr, FLAGS_SIZE_32)) return -EFAULT; /* If the user space value has changed, try again. */ @@ -526,7 +526,7 @@ int futex_lock_pi_atomic(u32 __user *uad * Read the user space value first so we can validate a few * things before proceeding further. */ - if (futex_get_value_locked(&uval, uaddr)) + if (futex_get_value_locked(&uval, uaddr, FLAGS_SIZE_32)) return -EFAULT; if (unlikely(should_fail_futex(true))) @@ -762,7 +762,7 @@ static int __fixup_pi_state_owner(u32 __ if (!pi_state->owner) newtid |= FUTEX_OWNER_DIED; - err = futex_get_value_locked(&uval, uaddr); + err = futex_get_value_locked(&uval, uaddr, FLAGS_SIZE_32); if (err) goto handle_err; --- a/kernel/futex/requeue.c +++ b/kernel/futex/requeue.c @@ -273,7 +273,7 @@ futex_proxy_trylock_atomic(u32 __user *p u32 curval; int ret; - if (futex_get_value_locked(&curval, pifutex)) + if (futex_get_value_locked(&curval, pifutex, FLAGS_SIZE_32)) return -EFAULT; if (unlikely(should_fail_futex(true))) @@ -451,7 +451,7 @@ int futex_requeue(u32 __user *uaddr1, un if (likely(cmpval != NULL)) { u32 curval; - ret = futex_get_value_locked(&curval, uaddr1); + ret = futex_get_value_locked(&curval, uaddr1, FLAGS_SIZE_32); if (unlikely(ret)) { double_unlock_hb(hb1, hb2); --- a/kernel/futex/waitwake.c +++ b/kernel/futex/waitwake.c @@ -438,7 +438,7 @@ static int futex_wait_multiple_setup(str u32 val = vs[i].w.val; hb = futex_q_lock(q); - ret = futex_get_value_locked(&uval, uaddr); + ret = futex_get_value_locked(&uval, uaddr, FLAGS_SIZE_32); if (!ret && uval == val) { /* @@ -606,7 +606,7 @@ int futex_wait_setup(u32 __user *uaddr, retry_private: *hb = futex_q_lock(q); - ret = futex_get_value_locked(&uval, uaddr); + ret = futex_get_value_locked(&uval, uaddr, FLAGS_SIZE_32); if (ret) { futex_q_unlock(*hb); From patchwork Mon Aug 7 12:18:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13344119 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 E9368C10F00 for ; Mon, 7 Aug 2023 12:37:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CDF4E6B007B; Mon, 7 Aug 2023 08:37:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A608C8D0006; Mon, 7 Aug 2023 08:37:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 46C388D0006; Mon, 7 Aug 2023 08:37:11 -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 C817A8D0006 for ; Mon, 7 Aug 2023 08:37:10 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 2DD04C0A60 for ; Mon, 7 Aug 2023 12:37:10 +0000 (UTC) X-FDA: 81097258620.08.24FB55C Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf12.hostedemail.com (Postfix) with ESMTP id 6DDD34000C for ; Mon, 7 Aug 2023 12:37:07 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=X2O67bPG; 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=1691411828; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:references:dkim-signature; bh=q2JUuQQkf4QJ5HlnBdmZO9ANv9VK51IAZht4p6DhAtU=; b=DHKRFnkszI033PCmkgQetWV/EDuxCOqUeF5/vTx6HO5LsR82XFaX6P9SqFWqvhKPnkLbdS u6u7dk3q5oDrz5a4G2MLQAgLIrfU33SUH6YW4L4Txe3GtIlAMK621Od2pCSCQcYK79xDrl GaKKxT2McMbNtIJcv4A4rqcTOTfwbII= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=X2O67bPG; 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=1691411828; a=rsa-sha256; cv=none; b=WtpdGGjDQn20mh8MxyDejn8Z1pc0BydmpshR3QpJtWTFObAEgMBjrGsoHaos0QSrZGfY8M MaQussSdZBBOZi6e5OuwqTfyAZXdEdpve5qoa1smxt1pXbljZRCaJu4JBe8exhxfKnaZni moSdClnvz16DnOoQmipmR58qbG0AfcQ= 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=q2JUuQQkf4QJ5HlnBdmZO9ANv9VK51IAZht4p6DhAtU=; b=X2O67bPGappPJwoyYOLJli/2uq GGSmNYvPLgZVt2/X3Hmrqu1CS1Zl85dYxPspA117dnFShAiy3LcGcjLWdXZTycTNRrU1JneiRVLRn tF26dsEBGwIqCOIot1HFOrI/Fk0gDY8+KE/QG3B9WI9TIXDwsOozljsjh74EFJdAZuM4h9/nbE9Vh o24zKa2EFC2UIQkKpr0RLuefzcIEbbl+sipU4Ta6NRRJkYkadodRotAl0POJj4WwsxnQYnjlHSVmi cOmGBvprufkD87jLIhKiDB9kt5z1Z/WQKyHaXTVD1+6Jkq1ILqtyz/ZnZFh/da1aKf1GrYhBTezjK bl271Qeg==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qSzTl-00AxGL-Gr; Mon, 07 Aug 2023 12:36:57 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 37457303463; Mon, 7 Aug 2023 14:36:56 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id C5FE42021B5CF; Mon, 7 Aug 2023 14:36:54 +0200 (CEST) Message-ID: <20230807123323.641470179@infradead.org> User-Agent: quilt/0.66 Date: Mon, 07 Aug 2023 14:18:56 +0200 From: Peter Zijlstra To: tglx@linutronix.de, axboe@kernel.dk Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, dvhart@infradead.org, dave@stgolabs.net, andrealmeid@igalia.com, Andrew Morton , urezki@gmail.com, hch@infradead.org, lstoakes@gmail.com, Arnd Bergmann , linux-api@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, malteskarupke@web.de Subject: [PATCH v2 13/14] futex: Enable FUTEX2_{8,16} References: <20230807121843.710612856@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 6DDD34000C X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 76dc85mkhu4m7c1r164yt39g9p3i5erd X-HE-Tag: 1691411827-952380 X-HE-Meta: U2FsdGVkX18OlIfR5gsM3Mj17IFPmZ7srn9uvh1xMUENYvC4PJBdjOfHfHvOaY1WLbIieTQUpl7avaCW+K2JMLNwyCllDWhThyQrCbsOPD3FDRQGxYcdV0vCzHJvJRZi6YS5219aHb6hVY3aOJ9+GRbENbOqvgSl9VO6EyRfBcbixzEiVuC9dRp649a6JaKEXr5T1Sqsb3JzTeoH5jLzkqhuLEhM3yFnnXNU7BccRyDgRdJaZXOEyUF6ONvWzTvaNI3SKmOXqZVTMPqSyCfUkuXy2bMdZYXwZcpbjaQN81glNWCGUq14nortQh/GXu4BIFuw0Cmtkw0GG1ZxIQjtStIoQAzVzuN09m/Ax1Kh8XeXECXnUF327n+nh4bAqqRyLCxxSYHzwZf82tqYKKo566OPrv0Z99vZ8kQStm1o8Zw5Ky212GGfrbHna72ULrkgatSnXx5J4TLa9ekjninliiFAc0d+amSClrveqJIwJ7DAmGte2hQSlNZuI5lNjrb8MkRo0OrU7YAoo1EapQmEKKJHWOss3oI4j7/F3yPebRxShkjgh6gMiCAvDVa93Bd/qKLDDGcmtg4JaYbZNN44bI38mGcNbFDMLGhmGDhaZHhBGdqqgukKbgG/fMUgHgHhc9y1EX8bdLe84O4kg597COvmBFCLiVtpT3iSe11bCMYqn6ZV8Qr/ymP3H2MFo+A+wW0RgCXdWF2FiH0x1VietbLcoxtAml7RRiOoxlYqFqL70tL2q+GZx3mh3/PGUh7E4LQOPd/WcpjCnr1Ql/ivFaNAI3kv/wsRwuPCm4xmB+w0Q6Q+3As36JZjs7Rq8ryKT8vQULYQ6C7uyKgl1vnH/bPkW1i0QiN8rSmNTgPZ2d/CJcYtPt0Apq5CiI5IcPq1LAGkKNDD0mQY2/WHs6kYloj7K7zVYRiKYkbOWshqN90u24g72lER349iC3HJkI/KMAg/WFPXDbnxuW0V6ly ZY4t2r3w Gqp4xc3b4jMMeJiSxYfurCsO9wLjgziIQ5kXJD4k3SpY9l3uWL5Sz3qqz24Co5h0BcTTU7at4N6fQMIdO11tcVhr5vlkyW0XtOijkscgaueQHGJ0gqCI4GnNCJysU+/AgrreWqJuXuC6b48hTCrar97EydTL4TEKUVWz/QraDpWBRKaPe9bBuNOTTRaszCZgQM5EMqGxBxNA5iDRCgK56Y3j34htRqalRut3ByAsbrLQAxUWRD+N/uCbXzMK79oU+TJ839PMGherr37HiNxiDCoRFwqJ9OZrSwUeYzNAjW1OFRNMAnpo9n/5CM7DkVaR9LKF8 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(-) --- a/include/linux/futex.h +++ b/include/linux/futex.h @@ -16,18 +16,19 @@ struct task_struct; * The key type depends on whether it's a shared or private mapping. * Don't rearrange members without looking at hash_futex(). * - * offset is aligned to a multiple of sizeof(u32) (== 4) by definition. - * We use the two low order bits of offset to tell what is the kind of key : + * offset is the position within a page and is in the range [0, PAGE_SIZE). + * The high bits of the offset indicate what kind of key this is: * 00 : Private process futex (PTHREAD_PROCESS_PRIVATE) * (no reference on an inode or mm) * 01 : Shared futex (PTHREAD_PROCESS_SHARED) * mapped on a file (reference on the underlying inode) * 10 : Shared futex (PTHREAD_PROCESS_SHARED) * (but private mapping on an mm, and reference taken on it) -*/ + */ -#define FUT_OFF_INODE 1 /* We set bit 0 if key has a reference on inode */ -#define FUT_OFF_MMSHARED 2 /* We set bit 1 if key has a reference on mm */ +#define FUT_OFF_INODE (PAGE_SIZE << 0) +#define FUT_OFF_MMSHARED (PAGE_SIZE << 1) +#define FUT_OFF_SIZE (PAGE_SIZE << 2) union futex_key { struct { --- a/kernel/futex/core.c +++ b/kernel/futex/core.c @@ -308,6 +308,15 @@ int get_futex_key(void __user *uaddr, un } /* + * Encode the futex size in the offset. This makes cross-size + * wake-wait fail -- see futex_match(). + * + * NOTE that cross-size wake-wait is fundamentally broken wrt + * FLAGS_NUMA but could possibly work for !NUMA. + */ + key->both.offset |= FUT_OFF_SIZE * (flags & FLAGS_SIZE_MASK); + + /* * PROCESS_PRIVATE futexes are fast. * As the mm cannot disappear under us and the 'key' only needs * virtual address, we dont even have to find the underlying vma. --- a/kernel/futex/futex.h +++ b/kernel/futex/futex.h @@ -79,8 +79,8 @@ static inline bool futex_flags_valid(uns return false; } - /* Only 32bit futexes are implemented -- for now */ - if ((flags & FLAGS_SIZE_MASK) != FLAGS_SIZE_32) + /* 64bit futexes aren't implemented -- yet */ + if ((flags & FLAGS_SIZE_MASK) == FLAGS_SIZE_64) return false; /* --- a/kernel/futex/waitwake.c +++ b/kernel/futex/waitwake.c @@ -434,11 +434,12 @@ static int futex_wait_multiple_setup(str for (i = 0; i < count; i++) { u32 __user *uaddr = (u32 __user *)(unsigned long)vs[i].w.uaddr; + unsigned int flags = vs[i].w.flags; struct futex_q *q = &vs[i].q; u32 val = vs[i].w.val; hb = futex_q_lock(q); - ret = futex_get_value_locked(&uval, uaddr, FLAGS_SIZE_32); + ret = futex_get_value_locked(&uval, uaddr, flags); if (!ret && uval == val) { /* @@ -606,7 +607,7 @@ int futex_wait_setup(u32 __user *uaddr, retry_private: *hb = futex_q_lock(q); - ret = futex_get_value_locked(&uval, uaddr, FLAGS_SIZE_32); + ret = futex_get_value_locked(&uval, uaddr, flags); if (ret) { futex_q_unlock(*hb); From patchwork Mon Aug 7 12:18:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13344115 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 0B630C04FDF for ; Mon, 7 Aug 2023 12:37:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 16E50900006; Mon, 7 Aug 2023 08:37:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0C27D900005; Mon, 7 Aug 2023 08:37:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AD40D6B007B; Mon, 7 Aug 2023 08:37:10 -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 239098D0006 for ; Mon, 7 Aug 2023 08:37:10 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id DC59980A5D for ; Mon, 7 Aug 2023 12:37:09 +0000 (UTC) X-FDA: 81097258578.10.CA58C12 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf07.hostedemail.com (Postfix) with ESMTP id D82034000D for ; Mon, 7 Aug 2023 12:37:07 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=m2xRwbPd; dmarc=none; spf=none (imf07.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=1691411828; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:references:dkim-signature; bh=SuU6iwWIqVk8hwlYVFfKmnnvnAg5pfU6VmbV05Pxd1Q=; b=to1hSkUNAWEpyNHn3sSAghevm3aj92a8b2yyKOeLiX1jQCrQe9FIri/yDh9X0I26UvKaBI g3m9YsAi1CSr7MmErzbtmIWDql5hdwjPzUzRXpG1dADvPNmZ2cSS3F0fuelOSWPjCinxPT jWb1ylLj4eNNYlEezYLd3HlHm/NdcXM= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=m2xRwbPd; dmarc=none; spf=none (imf07.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=1691411828; a=rsa-sha256; cv=none; b=fiW0kZeH5zuWGV/CxIyLI2faDpGkrYJi2uwFn35CZzGowFCg2uxL1APfJTWmT+Jh4+/rAc 4EquX4mEIAyjHLRZYM9k4uPFflh7n82OdKhd6ipH9QDC7xPQiI/9QUZV/4uwllACycpZtF WsNmem/cQbFfXyYJKHt1NaYFJZpWsIE= 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=SuU6iwWIqVk8hwlYVFfKmnnvnAg5pfU6VmbV05Pxd1Q=; b=m2xRwbPdauLk+2EhPGclMbKjy4 puYrQxvHgAAcp8hr85eED1DkcDdAE1lTN+A9fOqaeHl7t91bfzTj4keU7QiHhvPu6cu+PaHynO18U 5NMwW4Fibt+7Smho22DvCQKeff8yfU9m5InsACn4bTC9Etg6YvAwWARYiEfacxUKtUBUQgVbHB8N/ MUs1C1j3YXJblu64z/VmATgpiUYp0ssn4A/94t/YUT2TKBz9fAwXXGueK2nnZcgropnAYPYkwarEc t5ifoZn181/WXgf7EAM8oXTHzZj9PPrrotk+1oBKlSZcuSPhqw2uJh6MrFb0kuUXqd/kzcdZD8v6y +yk4Q2YA==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qSzTl-00AxGM-HJ; Mon, 07 Aug 2023 12:36:58 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 3A1283061FF; Mon, 7 Aug 2023 14:36:56 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id CB7C0201FFA49; Mon, 7 Aug 2023 14:36:54 +0200 (CEST) Message-ID: <20230807123323.710299007@infradead.org> User-Agent: quilt/0.66 Date: Mon, 07 Aug 2023 14:18:57 +0200 From: Peter Zijlstra To: tglx@linutronix.de, axboe@kernel.dk Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, dvhart@infradead.org, dave@stgolabs.net, andrealmeid@igalia.com, Andrew Morton , urezki@gmail.com, hch@infradead.org, lstoakes@gmail.com, Arnd Bergmann , linux-api@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, malteskarupke@web.de Subject: [PATCH v2 14/14] futex,selftests: Extend the futex selftests References: <20230807121843.710612856@infradead.org> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: rb4auphopxkfwq6ofzjio7e5jejfiuoi X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: D82034000D X-HE-Tag: 1691411827-576095 X-HE-Meta: U2FsdGVkX194HMFsStP+k3vkBBk9f0eR3yT+/IdSBX0ocYCtyS5XuOHN7IONulslSI/UgknihZMUEtneTkVbtV8UTNEqQxi0XKyao7EkU0KYwvtMvhjSmAZ3DyQmQPJgMX0xneLbgxNIE7owk6nSurueiny00UYUsx7zwI7mig4GroefkJY0EPse4h4gUC/u4fo2FPbzDo9L+rvZNQtNIC+YeefBrcK8pvjwbhOyZ+j+/2Hb0Z8Frp0vEhWrdyqsO2D2MUr+OsG0WUgE8e8a4LY+wyWhYr5R7EE1RELLcEXNqaU7zE1Xy0roQB3HcQ3LWTFr+B+Stvu6ydnJ1YGG60A0S5DWwWlN+e7niJVQLsYR7B5rLlBSjH0g45S4BklrUz9jfG1RzvcJtjBUzzdHJxVEzYmizPh/4ayhmm4GJE8tCmFJZMWAlQe5GvnmdQ5RGzpfxD6xqagr1xw3RzS2A/YxYxUOnitMFK4SD/7jUe1RDI3r/wPzcWGNDcoQScBddY+yeiCEwcvd8ddziCUiA2Sr1Xm8ZKQ03/Onh+HTg309o1JkgznQOIUzEiASf6yYiPHzFxnH6m8K8YPnASi5XFHcmK9gjK8ni/qCh0Qz62MyKVFWkkw7oIKz2tehz08P8zUB6YDcOQY8tyq1EBsswOb/m4s8foHXTBxEO0EBe1crY/a9MI9xf/4q2wSraC9avrYYrlCpR0sJ4H1LNO9G262lKK8R+jfpS8CIjk3z5Mxk2vmVvf63gzUSkVGjzer2+4BBxH0ae2amOFNbNFdWqN5wRA33yb/CTb1hrii41c++3z1VSL8uMMGE0x9TYN8NcIQwOPNBMvZWe/+i+nfqVgstYIbf2z6F2yI/kOpwRTxQkYd0rBnHQfg14XGNcDQPO1zUQyvtkz4yTNtt1yi5PeSTGZpwR3rOlUmdAAGHK6u7h8Gbg7/5VtNF73juDcvZQr2IEfLvq5biL5Muvim ujGTC9Vg SwxVTwaDCeaDClU/VHxVb7OQvdK5e+COD83hw91YsIbNz9JkT1HuC4noDCQXLYl2452kl/+e3Xd35sQxzcYoNic6KOSP08kSLs/NJvpqL+MkssN/nEFM/WrLjwbzIaW70qvj0hCZl5oEvoRnVNoVqTde6dNBMRjnGWMQcT+RmjeDR9NQCO4A2MDcR0FuwYthMDuWio/jszvpmeG3plCM4BX/gqpFZK64urqY7R5WICsW9Ick= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Extend the wait/requeue selftests to also cover the futex2 syscalls. Signed-off-by: Peter Zijlstra (Intel) --- tools/testing/selftests/futex/functional/futex_requeue.c | 100 +++++++++- tools/testing/selftests/futex/functional/futex_wait.c | 56 ++++- tools/testing/selftests/futex/functional/futex_wait_timeout.c | 14 + tools/testing/selftests/futex/functional/futex_wait_wouldblock.c | 28 ++ tools/testing/selftests/futex/functional/futex_waitv.c | 15 - tools/testing/selftests/futex/functional/run.sh | 6 tools/testing/selftests/futex/include/futex2test.h | 39 +++ 7 files changed, 229 insertions(+), 29 deletions(-) --- a/tools/testing/selftests/futex/functional/futex_requeue.c +++ b/tools/testing/selftests/futex/functional/futex_requeue.c @@ -7,8 +7,10 @@ #include #include +#include #include "logging.h" #include "futextest.h" +#include "futex2test.h" #define TEST_NAME "futex-requeue" #define timeout_ns 30000000 @@ -16,24 +18,58 @@ volatile futex_t *f1; +bool futex2 = 0; +bool mixed = 0; + void usage(char *prog) { printf("Usage: %s\n", prog); printf(" -c Use color\n"); + printf(" -n Use futex2 interface\n"); + printf(" -x Use mixed size futex\n"); printf(" -h Display this help message\n"); printf(" -v L Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n", VQUIET, VCRITICAL, VINFO); } -void *waiterfn(void *arg) +static void *waiterfn(void *arg) { + unsigned int flags = 0; struct timespec to; - to.tv_sec = 0; - to.tv_nsec = timeout_ns; + if (futex2) { + unsigned long mask; + + if (clock_gettime(CLOCK_MONOTONIC, &to)) { + printf("clock_gettime() failed errno %d", errno); + return NULL; + } + + to.tv_nsec += timeout_ns; + if (to.tv_nsec >= 1000000000) { + to.tv_sec++; + to.tv_nsec -= 1000000000; + } + + if (mixed) { + flags |= FUTEX2_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, --- a/tools/testing/selftests/futex/functional/futex_wait.c +++ b/tools/testing/selftests/futex/functional/futex_wait.c @@ -9,8 +9,10 @@ #include #include #include +#include #include "logging.h" #include "futextest.h" +#include "futex2test.h" #define TEST_NAME "futex-wait" #define timeout_ns 30000000 @@ -19,10 +21,13 @@ void *futex; +bool futex2 = 0; + void usage(char *prog) { printf("Usage: %s\n", prog); printf(" -c Use color\n"); + printf(" -n Use futex2 interface\n"); printf(" -h Display this help message\n"); printf(" -v L Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n", VQUIET, VCRITICAL, VINFO); @@ -30,17 +35,35 @@ void usage(char *prog) static void *waiterfn(void *arg) { - struct timespec to; unsigned int flags = 0; + struct timespec to; if (arg) flags = *((unsigned int *) arg); - to.tv_sec = 0; - to.tv_nsec = timeout_ns; + if (futex2) { + if (clock_gettime(CLOCK_MONOTONIC, &to)) { + printf("clock_gettime() failed errno %d", errno); + return NULL; + } - if (futex_wait(futex, 0, &to, flags)) - printf("waiter failed errno %d\n", errno); + to.tv_nsec += timeout_ns; + if (to.tv_nsec >= 1000000000) { + to.tv_sec++; + to.tv_nsec -= 1000000000; + } + + if (futex2_wait(futex, 0, ~0U, flags | FUTEX2_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)); --- a/tools/testing/selftests/futex/functional/futex_wait_timeout.c +++ b/tools/testing/selftests/futex/functional/futex_wait_timeout.c @@ -125,7 +125,7 @@ int main(int argc, char *argv[]) } ksft_print_header(); - ksft_set_plan(9); + ksft_set_plan(11); ksft_print_msg("%s: Block on a futex and wait for timeout\n", basename(argv[0])); ksft_print_msg("\tArguments: timeout=%ldns\n", timeout_ns); @@ -194,6 +194,18 @@ int main(int argc, char *argv[]) res = futex_waitv(&waitv, 1, 0, &to, CLOCK_REALTIME); test_timeout(res, &ret, "futex_waitv realtime", ETIMEDOUT); + /* futex2_wait with CLOCK_MONOTONIC */ + if (futex_get_abs_timeout(CLOCK_MONOTONIC, &to, timeout_ns)) + return RET_FAIL; + res = futex2_wait(&f1, f1, 1, FUTEX2_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; } --- a/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c +++ b/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c @@ -46,7 +46,7 @@ int main(int argc, char *argv[]) struct futex_waitv waitv = { .uaddr = (uintptr_t)&f1, .val = f1+1, - .flags = FUTEX_32, + .flags = FUTEX2_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; } --- a/tools/testing/selftests/futex/functional/futex_waitv.c +++ b/tools/testing/selftests/futex/functional/futex_waitv.c @@ -88,7 +88,7 @@ int main(int argc, char *argv[]) for (i = 0; i < NR_FUTEXES; i++) { waitv[i].uaddr = (uintptr_t)&futexes[i]; - waitv[i].flags = FUTEX_32 | FUTEX_PRIVATE_FLAG; + waitv[i].flags = FUTEX2_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)) --- a/tools/testing/selftests/futex/functional/run.sh +++ b/tools/testing/selftests/futex/functional/run.sh @@ -76,9 +76,15 @@ echo echo ./futex_wait $COLOR +echo +./futex_wait -n $COLOR echo ./futex_requeue $COLOR +echo +./futex_requeue -n $COLOR +echo +./futex_requeue -x $COLOR echo ./futex_waitv $COLOR --- a/tools/testing/selftests/futex/include/futex2test.h +++ b/tools/testing/selftests/futex/include/futex2test.h @@ -8,6 +8,28 @@ #define u64_to_ptr(x) ((void *)(uintptr_t)(x)) +#ifndef __NR_futex_wake +#define __NR_futex_wake 452 +#define __NR_futex_wait 453 +#define __NR_futex_requeue 454 +#endif + +#ifndef FUTEX2_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); +}