From patchwork Thu Sep 21 17:36:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 143121 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5284550vqi; Thu, 21 Sep 2023 19:57:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF0aRqoVyAiRH8jQbb6QXIxKCBkS5CTBujA1rqT0/LqzhnLjZEiuoD9zYznxPTK94FtMUWm X-Received: by 2002:a17:902:82c3:b0:1c3:f745:1cd5 with SMTP id u3-20020a17090282c300b001c3f7451cd5mr6866118plz.34.1695351437462; Thu, 21 Sep 2023 19:57:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695351437; cv=none; d=google.com; s=arc-20160816; b=TE1XrxSKW7b+D+DmZU+puWe/IS7ViYLtJdaHwJa6UEKMWGHb/TC/bC/d+3lxhOSoUl qS8kYm7xdFyFdgooq1i4Svcg9gY1sCpg8aOxDU9ij92wvpci4MsXnXLqSOSS3bstW9oa e7/86C0xsxGZEkAqAMePiVSWT8vURFedw9+X76sU8te+cEb0y9iYMwoIjFzfiXN/ICN+ ROLaY4KH9Mx+jPyvZp61Rk6Drfqn+u2Uarm4O0QZA5xa2LB1KqQpxr25iAB+ZkMbrqj7 sQN+RwNBObBm07a/ED0jvGRpsVwx/a1H+7rVwVa6+N/0sQSIX/YWKkMerQfZdauoPxN6 cT5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=cZ+AWsu/It5qMoqLvWyHRu3tp7dd43Yf5izBLfEk20A=; fh=SujDfaW6ST3NQsuUoGM6Fn94iCAUZj9y4xceJ/1AvRM=; b=UAkvgcmreFlW4HsWxFkVlYwtrmFkAgziPCUuD6VnBzfGm5AakC04bL2rK60vip4cUR HGj8ZWz/zwu0Sj9BErCG8KAhFtvVz5d364VidEW0wKpAuKibKqkRZuRd9ItdumiNWW8y TUTqS4NrqOcPMOjsxS46Ldl/UWOj4PGKi2e12htHvnkdbBcRzkmbFuw5pYAuDRbRscuP TenxQacOe7eQKQKaW7LsjhxZ18cy/l+VfAkhciYHC/R6baON0ut5s7IHjTP04qdxvCW5 MTerVS9htCkiIPrX1g1mdLzoA+KHVxR/drjiEaSV1mzj9uMcbRk8NJJPTZ9yvp75i6Ya euZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=j6sJNM6o; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id g13-20020a170902c38d00b001b8b37f6b46si2717959plg.556.2023.09.21.19.57.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 19:57:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=j6sJNM6o; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 47A02833938A; Thu, 21 Sep 2023 13:47:43 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232161AbjIUUre (ORCPT + 29 others); Thu, 21 Sep 2023 16:47:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231927AbjIUUrI (ORCPT ); Thu, 21 Sep 2023 16:47:08 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE9837E4F3; Thu, 21 Sep 2023 10:36:05 -0700 (PDT) Date: Thu, 21 Sep 2023 17:36:02 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695317764; h=from:from:sender:sender:reply-to: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cZ+AWsu/It5qMoqLvWyHRu3tp7dd43Yf5izBLfEk20A=; b=j6sJNM6oqKgpQj6qMLdn+nqzbYwE4fu6QpYJICqWKxzEnnxo7gGo2CtKzvosUzm/Rj1QmK f3pLQqm3IwN1J3uJIcEtBuNN2CPpZPBlOB7/exIabkUVBd4QeyW2uq1LxpVmKCNSll00Jd m912p66grCOfKJGD0Bn2jpymw+DJpymJK/jpfzJ6FikbGNoJmWkh/Po1mzXGLJJ42Od/mT qU8YOaiQ7gc5BiCmVZE1EI2PZuObyh6GZh5sMMSC/Glz8+gRergWwQHbE7g7c1mT30MWjO bLKOyFKcg1hDHZIDMjWC+RM4qsNbC9OKKZt5b1OgFdl0rLrFw0aefP37OvdfSQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695317764; h=from:from:sender:sender:reply-to: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cZ+AWsu/It5qMoqLvWyHRu3tp7dd43Yf5izBLfEk20A=; b=CAddA7LF3Yscb8zsb/+4tQ37vZoAFf+VyGH0/hI3WoddMS120kKSdkuK/KIxQtcBl3NRUU WwQ2HuwsD6USA0Cg== From: "tip-bot2 for peterz@infradead.org" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/core] futex: FLAGS_STRICT Cc: andrealmeid@igalia.com, "Peter Zijlstra (Intel)" , Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230921105248.048643656@noisy.programming.kicks-ass.net> References: <20230921105248.048643656@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Message-ID: <169531776286.27769.7382358930466919741.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 21 Sep 2023 13:47:43 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777688071229035889 X-GMAIL-MSGID: 1777704829162676987 The following commit has been merged into the locking/core branch of tip: Commit-ID: 43adf844951084c266f172561f84c5f8120dd60b Gitweb: https://git.kernel.org/tip/43adf844951084c266f172561f84c5f8120dd60b Author: peterz@infradead.org AuthorDate: Thu, 21 Sep 2023 12:45:11 +02:00 Committer: Peter Zijlstra CommitterDate: Thu, 21 Sep 2023 19:22:07 +02:00 futex: FLAGS_STRICT The current semantics for futex_wake() are a bit loose, specifically asking for 0 futexes to be woken actually gets you 1. Adding a !nr check to sys_futex_wake() makes that it would return 0 for unaligned futex words, because that check comes in the shared futex_wake() function. Adding the !nr check there, would affect the legacy sys_futex() semantics. Hence frob a flag :-( Suggested-by: André Almeida Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Thomas Gleixner Link: https://lore.kernel.org/r/20230921105248.048643656@noisy.programming.kicks-ass.net --- kernel/futex/futex.h | 21 +++++++++++---------- kernel/futex/syscalls.c | 2 +- kernel/futex/waitwake.c | 3 +++ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/kernel/futex/futex.h b/kernel/futex/futex.h index a3f1fce..0e7821a 100644 --- a/kernel/futex/futex.h +++ b/kernel/futex/futex.h @@ -17,25 +17,26 @@ * Futex flags used to encode options to functions and preserve them across * restarts. */ -#define FLAGS_SIZE_8 0x00 -#define FLAGS_SIZE_16 0x01 -#define FLAGS_SIZE_32 0x02 -#define FLAGS_SIZE_64 0x03 +#define FLAGS_SIZE_8 0x0000 +#define FLAGS_SIZE_16 0x0001 +#define FLAGS_SIZE_32 0x0002 +#define FLAGS_SIZE_64 0x0003 -#define FLAGS_SIZE_MASK 0x03 +#define FLAGS_SIZE_MASK 0x0003 #ifdef CONFIG_MMU -# define FLAGS_SHARED 0x10 +# define FLAGS_SHARED 0x0010 #else /* * NOMMU does not have per process address space. Let the compiler optimize * code away. */ -# define FLAGS_SHARED 0x00 +# define FLAGS_SHARED 0x0000 #endif -#define FLAGS_CLOCKRT 0x20 -#define FLAGS_HAS_TIMEOUT 0x40 -#define FLAGS_NUMA 0x80 +#define FLAGS_CLOCKRT 0x0020 +#define FLAGS_HAS_TIMEOUT 0x0040 +#define FLAGS_NUMA 0x0080 +#define FLAGS_STRICT 0x0100 /* FUTEX_ to FLAGS_ */ static inline unsigned int futex_to_flags(unsigned int op) diff --git a/kernel/futex/syscalls.c b/kernel/futex/syscalls.c index 7049a52..4739892 100644 --- a/kernel/futex/syscalls.c +++ b/kernel/futex/syscalls.c @@ -333,7 +333,7 @@ SYSCALL_DEFINE4(futex_wake, if (!futex_validate_input(flags, mask)) return -EINVAL; - return futex_wake(uaddr, flags, nr, mask); + return futex_wake(uaddr, FLAGS_STRICT | flags, nr, mask); } #ifdef CONFIG_COMPAT diff --git a/kernel/futex/waitwake.c b/kernel/futex/waitwake.c index fa97577..ceb05b8 100644 --- a/kernel/futex/waitwake.c +++ b/kernel/futex/waitwake.c @@ -155,6 +155,9 @@ int futex_wake(u32 __user *uaddr, unsigned int flags, int nr_wake, u32 bitset) if (unlikely(ret != 0)) return ret; + if ((flags & FLAGS_STRICT) && !nr_wake) + return 0; + hb = futex_hash(&key); /* Make sure we really have tasks to wakeup */