From patchwork Fri Oct 25 09:03:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13850345 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 F3018D0C5F4 for ; Fri, 25 Oct 2024 09:41:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 37ED76B0096; Fri, 25 Oct 2024 05:41:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3569B6B0098; Fri, 25 Oct 2024 05:41:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F7996B0099; Fri, 25 Oct 2024 05:41:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id F06016B0096 for ; Fri, 25 Oct 2024 05:41:13 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id ECD47806DF for ; Fri, 25 Oct 2024 09:40:56 +0000 (UTC) X-FDA: 82711630302.03.A176DEC Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf08.hostedemail.com (Postfix) with ESMTP id 19BB4160005 for ; Fri, 25 Oct 2024 09:40:58 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=oToK9ZTc; dmarc=none; spf=none (imf08.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=1729849102; 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=dbMjdL9P+u2qdFG5YZQzJ7hdT9tBr5pG921aWEix044=; b=34P2Z+SJv/7stfhIzjq10ZhJIRcr71hE/tXfXZ+KTtQHaIka4Af3ZRp6SjBtRPyLr2B4nm ttY3GKwRXDqT6SCb4GlkOg79bXHNIAZYfpslCp2jAxvgdCV7m/Ie4Ib9XRPkuJcXekvW2I Bd91pefNPDOkK5LIBK/0Ha6blbXCVno= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729849102; a=rsa-sha256; cv=none; b=RSzRnr7lPHnaGIlvHBMCw0wp9IsUx/u4BkDYLiFqEmR7s3xTnk/iLyzsLUFLMoNaa2+zeX OT/61SsndPF5oXIwd1RgEy5WrSmjqkmQJb05gggJKyhylW1OxG7UGvxwpud5gRtAMVaZ3S GqLfTCpvFDHMe8H1DltPjOnkCD5FLC4= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=oToK9ZTc; dmarc=none; spf=none (imf08.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org 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=dbMjdL9P+u2qdFG5YZQzJ7hdT9tBr5pG921aWEix044=; b=oToK9ZTcwKqnYN5RC0kkFefevU u8/ilYOenOsPM+FVeWvDHPVxcg4GGhL6k6STW5NP7C9ct6oVDyUl76zIlqlnzLWUBUkJwh89WFj7Q 5XoeELdhk1ILEt2BpbvKy9ZschyFkZsKVD1/SWt707/NGdhazJYXZP7lmTBDuBWBZX+dxZghMUjIu soy3pCQ3Jo0kqETLQTyhcOX7TsZEFBb6dJhn04uR/LOTn/nyWxdHHxFlw8/P6zSIBS+wVR6aqZu6z ReO4sVqRqBLg0ND9nBe1PXNugWLsBasiG0DRiZKxiKN/M5TGkEehurCM7uqSL5D9qs1MXVLEGrose SG7oVy5w==; 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.98 #2 (Red Hat Linux)) id 1t4GoU-00000008sa9-1l5D; Fri, 25 Oct 2024 09:41:00 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id DA229301D03; Fri, 25 Oct 2024 11:40:57 +0200 (CEST) Message-Id: <20241025093944.707639534@infradead.org> User-Agent: quilt/0.65 Date: Fri, 25 Oct 2024 11:03:51 +0200 From: Peter Zijlstra To: tglx@linutronix.de 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, cl@linux.com, llong@redhat.com Subject: [PATCH 4/6] futex: Enable FUTEX2_{8,16} References: <20241025090347.244183920@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 19BB4160005 X-Stat-Signature: bznb9sdbboxmsyw8jqn6875oh6d8djnh X-Rspam-User: X-HE-Tag: 1729849258-132035 X-HE-Meta: U2FsdGVkX1+W1li72GfmRST59mvWWV76XmHIXnMNPXlmFRWgiLI+iaC2/qwvTQnD5VFhlfPfQ2gyrV9fPk5BCw+kHvwMH4tF7BU5Zmk/8MZJSpMghuJHNYzbBlssZarDJYWGJp2Id21qSM4fPaIikNXD9q/diW+JrHt2pkamC125yjUTSfnaBiWrE4DFiNO8oKaAKiJc5aetABV22Zznb71ckgk658piK3/se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FktKAfqYB6hl1g== 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: List-Subscribe: List-Unsubscribe: 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 @@ -313,6 +313,15 @@ int get_futex_key(void __user *uaddr, un } /* + * Encode the futex size in the offset. This makes cross-size + * wake-wait fail -- see futex_match(). + * + * NOTE that cross-size wake-wait is fundamentally broken wrt + * FLAGS_NUMA. + */ + key->both.offset |= FUT_OFF_SIZE * (flags & FLAGS_SIZE_MASK); + + /* * PROCESS_PRIVATE futexes are fast. * As the mm cannot disappear under us and the 'key' only needs * virtual address, we dont even have to find the underlying vma. --- a/kernel/futex/futex.h +++ b/kernel/futex/futex.h @@ -81,8 +81,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 @@ -449,11 +449,12 @@ int futex_wait_multiple_setup(struct fut 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) { /* @@ -621,7 +622,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);