From patchwork Thu Sep 21 17:36:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 143050 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5245679vqi; Thu, 21 Sep 2023 18:05:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGCb6OAkudLUXdf1m2QN1TfakSJEVhCP8XFhqOTwiBNXlNuMyyLfxiPGe8Ghiq1GckN1ZPe X-Received: by 2002:a05:6870:b621:b0:1bf:dc26:4947 with SMTP id cm33-20020a056870b62100b001bfdc264947mr8101751oab.46.1695344745673; Thu, 21 Sep 2023 18:05:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695344745; cv=none; d=google.com; s=arc-20160816; b=Cl9uI+I00Z9DhjiSJotMWsqtw4jvh2Whm4qpAdM80FaL2bUg8zJRoxW5IZ89wKcFS4 +IbDMJ3AbWHYd8zz/4ciCEkmCiod61CrZjx1rBvj5eTunfx2Ub4PqD58AvGCi9XYsD9l RW/Wxol4zc3nrJWp7QnXcApdIBM+1hR0jzqo8l6bPDaQpdvihcAAAh44yix5nt6liy5x JqnsnjDii9rLprw4w4XVtmcqvg3ycxiy+aYR2glAj1Bzf/WvwNcG7dTVgeSjEFm6ng3r 3QVd61ce/Oo4WK1mbPK6ClhsxcmOwsmE2UT/RYHdzLBXBUhafHMEsUoIpShWuEGZdzqP iytQ== 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=3XRfkGiSd1IkNkmWQtBjb47qPW4JP4rD89hnWo2C6uw=; fh=OLJGSWHwN9Ti+GR4AByPoKXEFKK/D9ARGqUCqKnaSEU=; b=grIEFB43HjwGQtEOMqiqgnRQtJ1DVjRYBwqNAwnr/MzObFqtrHkus3W0hCcFLJQLpr YxPxEjLqTTM+xf5gptVD+1dwiKqBvefIW4NrBJbnlrFcc9FeZtGegoKNuWRhcLB+wIVk 7RrHERFQkLgHENIQ8YgVqHE7uCPjVm3x6cZ/HvqQTchf1bV9za/rzufMzGm2a9/L7Beu DayKoc2l7WiL6z3/tuFpWgqPfaBY0WyQaXMcmGoZX5UCjelrTFee0MoJZROYT9fB3/+Q fNt8NRhLEjAP8f9mZWCdDbp8/GWKXETMgMHqsW01aHapOn5JCGjBDIxA/VHDNHuAVTIv 2rZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=T2cEyQkA; 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:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id m65-20020a633f44000000b0055c95e91f67si2705624pga.155.2023.09.21.18.05.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 18:05:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=T2cEyQkA; 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:5 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 groat.vger.email (Postfix) with ESMTP id 5BE4A8098490; Thu, 21 Sep 2023 12:01:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230479AbjIUTBj (ORCPT + 28 others); Thu, 21 Sep 2023 15:01:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230295AbjIUTBL (ORCPT ); Thu, 21 Sep 2023 15:01:11 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25D297E4D9; Thu, 21 Sep 2023 10:36:03 -0700 (PDT) Date: Thu, 21 Sep 2023 17:36:01 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695317761; 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=3XRfkGiSd1IkNkmWQtBjb47qPW4JP4rD89hnWo2C6uw=; b=T2cEyQkAt2DSbxI7+TQrDQaIC0NuB3hEpUpsKv8xWsxo4vbBYyAUCkK6j3qTxGGK7JDebH ZUPB4nV+AQK1OxfVXksw9d8qBDYX0r4pMHJ2NjwgSmUWErlifP7bviw+d3GYr8iQWLYf5E wpdaQm6wn+CnPQn4tKNPgjcjgHpx4AngyE9fA4oVZTM4EBtajzwAl08PAdLrqRH4TmSjn5 GHuijXB9KkSTUhgD0SGOCZz6tZ4qGWyCQL9qucVjAqWelPj2ArhC36RW6SJxGvY84F/HWp hN8OUBqlTx6tk7w/3+tqVbU6dGaiYh3C5gUSjYpY1R0z+DSkd4FvxkWAsy2+uw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695317761; 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=3XRfkGiSd1IkNkmWQtBjb47qPW4JP4rD89hnWo2C6uw=; b=wo+VX+h/7RE9uKqmxNx5z+q+SzIBIv4hIgenh1okqwynOr51zTda9J2Y6fxQkyewvUeCA4 P3dihlYLmja7dhBg== 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: Propagate flags into get_futex_key() Cc: "Peter Zijlstra (Intel)" , Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230921105248.282857501@noisy.programming.kicks-ass.net> References: <20230921105248.282857501@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Message-ID: <169531776100.27769.14852378896731331661.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 groat.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 (groat.vger.email [0.0.0.0]); Thu, 21 Sep 2023 12:01:56 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777697812245372513 X-GMAIL-MSGID: 1777697812245372513 The following commit has been merged into the locking/core branch of tip: Commit-ID: 3b63a55f498b763aba0886b244df613587a73c46 Gitweb: https://git.kernel.org/tip/3b63a55f498b763aba0886b244df613587a73c46 Author: peterz@infradead.org AuthorDate: Thu, 21 Sep 2023 12:45:13 +02:00 Committer: Peter Zijlstra CommitterDate: Thu, 21 Sep 2023 19:22:09 +02:00 futex: Propagate flags into get_futex_key() 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 Link: https://lore.kernel.org/r/20230921105248.282857501@noisy.programming.kicks-ass.net --- kernel/futex/core.c | 7 +++++-- kernel/futex/futex.h | 2 +- kernel/futex/pi.c | 4 ++-- kernel/futex/requeue.c | 6 +++--- kernel/futex/waitwake.c | 14 +++++++------- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/kernel/futex/core.c b/kernel/futex/core.c index d1d7b3c..ade7c73 100644 --- a/kernel/futex/core.c +++ b/kernel/futex/core.c @@ -193,7 +193,7 @@ static u64 get_inode_sequence_number(struct inode *inode) /** * get_futex_key() - Get parameters which are the keys for a futex * @uaddr: virtual address of the futex - * @fshared: false for a PROCESS_PRIVATE futex, true for PROCESS_SHARED + * @flags: FLAGS_* * @key: address where result is stored. * @rw: mapping needs to be read/write (values: FUTEX_READ, * FUTEX_WRITE) @@ -217,7 +217,7 @@ static u64 get_inode_sequence_number(struct inode *inode) * * lock_page() might sleep, the caller should not hold a spinlock. */ -int get_futex_key(u32 __user *uaddr, bool fshared, union futex_key *key, +int get_futex_key(u32 __user *uaddr, unsigned int flags, union futex_key *key, enum futex_access rw) { unsigned long address = (unsigned long)uaddr; @@ -226,6 +226,9 @@ int get_futex_key(u32 __user *uaddr, bool fshared, union futex_key *key, struct folio *folio; struct address_space *mapping; int err, ro = 0; + bool fshared; + + fshared = flags & FLAGS_SHARED; /* * The futex address must be "naturally" aligned. diff --git a/kernel/futex/futex.h b/kernel/futex/futex.h index e74888a..a8ea5ef 100644 --- a/kernel/futex/futex.h +++ b/kernel/futex/futex.h @@ -184,7 +184,7 @@ enum futex_access { FUTEX_WRITE }; -extern int get_futex_key(u32 __user *uaddr, bool fshared, union futex_key *key, +extern int get_futex_key(u32 __user *uaddr, unsigned int flags, union futex_key *key, enum futex_access rw); extern struct hrtimer_sleeper * diff --git a/kernel/futex/pi.c b/kernel/futex/pi.c index d636a1b..90e5197 100644 --- a/kernel/futex/pi.c +++ b/kernel/futex/pi.c @@ -933,7 +933,7 @@ int futex_lock_pi(u32 __user *uaddr, unsigned int flags, ktime_t *time, int tryl to = futex_setup_timer(time, &timeout, flags, 0); retry: - ret = get_futex_key(uaddr, flags & FLAGS_SHARED, &q.key, FUTEX_WRITE); + ret = get_futex_key(uaddr, flags, &q.key, FUTEX_WRITE); if (unlikely(ret != 0)) goto out; @@ -1129,7 +1129,7 @@ retry: if ((uval & FUTEX_TID_MASK) != vpid) return -EPERM; - ret = get_futex_key(uaddr, flags & FLAGS_SHARED, &key, FUTEX_WRITE); + ret = get_futex_key(uaddr, flags, &key, FUTEX_WRITE); if (ret) return ret; diff --git a/kernel/futex/requeue.c b/kernel/futex/requeue.c index 4c73e0b..5bf6958 100644 --- a/kernel/futex/requeue.c +++ b/kernel/futex/requeue.c @@ -424,10 +424,10 @@ int futex_requeue(u32 __user *uaddr1, unsigned int flags, u32 __user *uaddr2, } 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 *uaddr, unsigned int flags, */ 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; diff --git a/kernel/futex/waitwake.c b/kernel/futex/waitwake.c index b109a08..37860f7 100644 --- a/kernel/futex/waitwake.c +++ b/kernel/futex/waitwake.c @@ -145,13 +145,13 @@ int futex_wake(u32 __user *uaddr, unsigned int flags, int nr_wake, u32 bitset) struct futex_hash_bucket *hb; struct futex_q *this, *next; union futex_key key = FUTEX_KEY_INIT; - int ret; DEFINE_WAKE_Q(wake_q); + int ret; if (!bitset) return -EINVAL; - ret = get_futex_key(uaddr, flags & FLAGS_SHARED, &key, FUTEX_READ); + ret = get_futex_key(uaddr, flags, &key, FUTEX_READ); if (unlikely(ret != 0)) return ret; @@ -248,10 +248,10 @@ int futex_wake_op(u32 __user *uaddr1, unsigned int flags, u32 __user *uaddr2, DEFINE_WAKE_Q(wake_q); retry: - ret = get_futex_key(uaddr1, flags & FLAGS_SHARED, &key1, FUTEX_READ); + ret = get_futex_key(uaddr1, flags, &key1, FUTEX_READ); if (unlikely(ret != 0)) return ret; - ret = get_futex_key(uaddr2, flags & FLAGS_SHARED, &key2, FUTEX_WRITE); + ret = get_futex_key(uaddr2, flags, &key2, FUTEX_WRITE); if (unlikely(ret != 0)) return ret; @@ -426,7 +426,7 @@ retry: continue; ret = get_futex_key(u64_to_user_ptr(vs[i].w.uaddr), - vs[i].w.flags & FLAGS_SHARED, + vs[i].w.flags, &vs[i].q.key, FUTEX_READ); if (unlikely(ret)) @@ -438,7 +438,7 @@ retry: for (i = 0; i < count; i++) { u32 __user *uaddr = (u32 __user *)(unsigned long)vs[i].w.uaddr; struct futex_q *q = &vs[i].q; - u32 val = (u32)vs[i].w.val; + u32 val = vs[i].w.val; hb = futex_q_lock(q); ret = futex_get_value_locked(&uval, uaddr); @@ -602,7 +602,7 @@ int futex_wait_setup(u32 __user *uaddr, u32 val, unsigned int flags, * while the syscall executes. */ retry: - ret = get_futex_key(uaddr, flags & FLAGS_SHARED, &q->key, FUTEX_READ); + ret = get_futex_key(uaddr, flags, &q->key, FUTEX_READ); if (unlikely(ret != 0)) return ret; From patchwork Thu Sep 21 10:45:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 143053 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5247596vqi; Thu, 21 Sep 2023 18:10:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFl3kYyoeb2R9PDiGMlKxE9w5qfCWIWaUwS0lXMyUNujoXdoj6WlmzpsddFW9yxiShBp2q6 X-Received: by 2002:a05:6808:186:b0:3ae:a81:55a9 with SMTP id w6-20020a056808018600b003ae0a8155a9mr2544183oic.24.1695345007485; Thu, 21 Sep 2023 18:10:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695345007; cv=none; d=google.com; s=arc-20160816; b=X9Wxc6M3vfnTZKtYWvYtyePo7wFXCQCitNrwkLegxaPTtgipFvKxMCaxMO39Ak4P+K LpyIeZJxvjFSlCi/zFKkkwYGhQ+wAVEtZj925jo1ycT7nuJkHpkRQtC4UvsNCZhgUyA6 FM7KFlSIilEjyQNl4HdkTzWZMiDTeYpVMx4gE1T9cJHlMGp8mdtg/jBNQ+pbWcPZrf9L Uwbei9ev5G30t0k/thvS7wTyuAS16VfcCccLTbhzZ0LPMaMymVJ6WPpVSkl2TB+4g1Jv nUwmXJssNHdvK1xYiG+lbF4ESWNes/QOsTJxB0werlkVB6+ANOl7jWe1+4XEoZ1nEQAS yZOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:references :subject:cc:to:from:date:user-agent:message-id:dkim-signature; bh=UZPFE2ZScTicMie2LbY/rLHSb/ea3l5YRQ8Geimizx8=; fh=gKrHpzx5aMrklt5E8Fmce1sSUBKxYyMxbBSs7w4zkwQ=; b=xRl99q5rXvkLoG96KhNjWluw0hyCP5tRjBCEtq8+ySKlZAzuMC8au4+C5X2zZbvkuX ThtdbErF+uspJOwDvIobvdps2Td7PCb/aAm33w8h/jGEF+4xXMQOgYgWsf6LlgFGmPjf WFx6hCtbz4nxhYdhwYRZzE+83p62pNmuXlsiniLbRLbl7khuRwPsGYE+lsQ/PRr9vF+u F3/dYSgsOWygZiCEmHA8jEGr6hWI+wIgE+WuA6oAySw9szqY3PJa+dKI6gT6NbSpHwUH 6vGL8A4D3pYmTxUuetbn8HJ7eUIwg8rOTyU2kn/a1gNO1Xck6bUi5YQhHpgYgPHAhOn5 +LNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=D2+0fnUy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id m65-20020a633f44000000b00578b9d1d118si197201pga.219.2023.09.21.18.10.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 18:10:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=D2+0fnUy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 631C481A236B; Thu, 21 Sep 2023 13:16:41 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231356AbjIUUQB (ORCPT + 29 others); Thu, 21 Sep 2023 16:16:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230059AbjIUUPl (ORCPT ); Thu, 21 Sep 2023 16:15:41 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8032B585C1; Thu, 21 Sep 2023 10:19:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-Id:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=UZPFE2ZScTicMie2LbY/rLHSb/ea3l5YRQ8Geimizx8=; b=D2+0fnUyypGBp3tmehpApHtBuE RnJo83xqyajrpKhjalpbKvZ+nGASRjTehHdoMNEhFFbTcsMZXNEJLm5K1AwRxz7Hx/fTASdxtRhBO zohke4ebc70ACqv8Bs7aQndNOXz9ac9ZANpPzFBrOQ+RyKLLvLq/F29cabLPlXJbmlNe4x7U3YzAj CxhoAB6qRbKq148GeIUfQzuoCLGewVVsVQtiU45YMCM4+B7uyU9yU2RrlLxkSF/Fj0+YTFgao96V8 1zSsgA3Ssz8jktwFUDjRfiOf68jkKJufk5rw+2mIG7SIRiJkGC5VD+RKhcC+J5orR8ZLAEtgTlYUz zhFFmjAQ==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qjHQN-00FJvt-1M; Thu, 21 Sep 2023 11:00:49 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 058B53005B2; Thu, 21 Sep 2023 13:00:43 +0200 (CEST) Message-Id: <20230921105248.282857501@noisy.programming.kicks-ass.net> User-Agent: quilt/0.65 Date: Thu, 21 Sep 2023 12:45:13 +0200 From: peterz@infradead.org To: tglx@linutronix.de, axboe@kernel.dk Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, dvhart@infradead.org, dave@stgolabs.net, andrealmeid@igalia.com, Andrew Morton , urezki@gmail.com, hch@infradead.org, lstoakes@gmail.com, Arnd Bergmann , linux-api@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, malteskarupke@web.de Subject: [PATCH v3 08/15] futex: Propagate flags into get_futex_key() References: <20230921104505.717750284@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Disposition: inline; filename=peterz-futex2-get_futex_key-flags.patch X-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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Thu, 21 Sep 2023 13:16:41 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777697812245372513 X-GMAIL-MSGID: 1777698086594451850 Instead of only passing FLAGS_SHARED as a boolean, pass down flags as a whole. No functional change intended. Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Thomas Gleixner --- kernel/futex/core.c | 5 ++++- kernel/futex/futex.h | 2 +- kernel/futex/pi.c | 4 ++-- kernel/futex/requeue.c | 6 +++--- kernel/futex/waitwake.c | 14 +++++++------- 5 files changed, 17 insertions(+), 14 deletions(-) Index: linux-2.6/kernel/futex/core.c =================================================================== --- linux-2.6.orig/kernel/futex/core.c +++ linux-2.6/kernel/futex/core.c @@ -193,7 +193,7 @@ static u64 get_inode_sequence_number(str /** * get_futex_key() - Get parameters which are the keys for a futex * @uaddr: virtual address of the futex - * @fshared: false for a PROCESS_PRIVATE futex, true for PROCESS_SHARED + * @flags: FLAGS_* * @key: address where result is stored. * @rw: mapping needs to be read/write (values: FUTEX_READ, * FUTEX_WRITE) @@ -217,7 +217,7 @@ static u64 get_inode_sequence_number(str * * lock_page() might sleep, the caller should not hold a spinlock. */ -int get_futex_key(u32 __user *uaddr, bool fshared, union futex_key *key, +int get_futex_key(u32 __user *uaddr, unsigned int flags, union futex_key *key, enum futex_access rw) { unsigned long address = (unsigned long)uaddr; @@ -226,6 +226,9 @@ int get_futex_key(u32 __user *uaddr, boo struct folio *folio; struct address_space *mapping; int err, ro = 0; + bool fshared; + + fshared = flags & FLAGS_SHARED; /* * The futex address must be "naturally" aligned. Index: linux-2.6/kernel/futex/futex.h =================================================================== --- linux-2.6.orig/kernel/futex/futex.h +++ linux-2.6/kernel/futex/futex.h @@ -184,7 +184,7 @@ enum futex_access { FUTEX_WRITE }; -extern int get_futex_key(u32 __user *uaddr, bool fshared, union futex_key *key, +extern int get_futex_key(u32 __user *uaddr, unsigned int flags, union futex_key *key, enum futex_access rw); extern struct hrtimer_sleeper * Index: linux-2.6/kernel/futex/pi.c =================================================================== --- linux-2.6.orig/kernel/futex/pi.c +++ linux-2.6/kernel/futex/pi.c @@ -933,7 +933,7 @@ int futex_lock_pi(u32 __user *uaddr, uns to = futex_setup_timer(time, &timeout, flags, 0); retry: - ret = get_futex_key(uaddr, flags & FLAGS_SHARED, &q.key, FUTEX_WRITE); + ret = get_futex_key(uaddr, flags, &q.key, FUTEX_WRITE); if (unlikely(ret != 0)) goto out; @@ -1129,7 +1129,7 @@ retry: if ((uval & FUTEX_TID_MASK) != vpid) return -EPERM; - ret = get_futex_key(uaddr, flags & FLAGS_SHARED, &key, FUTEX_WRITE); + ret = get_futex_key(uaddr, flags, &key, FUTEX_WRITE); if (ret) return ret; Index: linux-2.6/kernel/futex/requeue.c =================================================================== --- linux-2.6.orig/kernel/futex/requeue.c +++ linux-2.6/kernel/futex/requeue.c @@ -424,10 +424,10 @@ int futex_requeue(u32 __user *uaddr1, un } retry: - ret = get_futex_key(uaddr1, flags & FLAGS_SHARED, &key1, FUTEX_READ); + ret = get_futex_key(uaddr1, flags, &key1, FUTEX_READ); if (unlikely(ret != 0)) return ret; - ret = get_futex_key(uaddr2, flags & FLAGS_SHARED, &key2, + ret = get_futex_key(uaddr2, flags, &key2, requeue_pi ? FUTEX_WRITE : FUTEX_READ); if (unlikely(ret != 0)) return ret; @@ -789,7 +789,7 @@ int futex_wait_requeue_pi(u32 __user *ua */ rt_mutex_init_waiter(&rt_waiter); - ret = get_futex_key(uaddr2, flags & FLAGS_SHARED, &key2, FUTEX_WRITE); + ret = get_futex_key(uaddr2, flags, &key2, FUTEX_WRITE); if (unlikely(ret != 0)) goto out; Index: linux-2.6/kernel/futex/waitwake.c =================================================================== --- linux-2.6.orig/kernel/futex/waitwake.c +++ linux-2.6/kernel/futex/waitwake.c @@ -145,13 +145,13 @@ int futex_wake(u32 __user *uaddr, unsign struct futex_hash_bucket *hb; struct futex_q *this, *next; union futex_key key = FUTEX_KEY_INIT; - int ret; DEFINE_WAKE_Q(wake_q); + int ret; if (!bitset) return -EINVAL; - ret = get_futex_key(uaddr, flags & FLAGS_SHARED, &key, FUTEX_READ); + ret = get_futex_key(uaddr, flags, &key, FUTEX_READ); if (unlikely(ret != 0)) return ret; @@ -248,10 +248,10 @@ int futex_wake_op(u32 __user *uaddr1, un DEFINE_WAKE_Q(wake_q); retry: - ret = get_futex_key(uaddr1, flags & FLAGS_SHARED, &key1, FUTEX_READ); + ret = get_futex_key(uaddr1, flags, &key1, FUTEX_READ); if (unlikely(ret != 0)) return ret; - ret = get_futex_key(uaddr2, flags & FLAGS_SHARED, &key2, FUTEX_WRITE); + ret = get_futex_key(uaddr2, flags, &key2, FUTEX_WRITE); if (unlikely(ret != 0)) return ret; @@ -426,7 +426,7 @@ retry: continue; ret = get_futex_key(u64_to_user_ptr(vs[i].w.uaddr), - vs[i].w.flags & FLAGS_SHARED, + vs[i].w.flags, &vs[i].q.key, FUTEX_READ); if (unlikely(ret)) @@ -438,7 +438,7 @@ retry: for (i = 0; i < count; i++) { u32 __user *uaddr = (u32 __user *)(unsigned long)vs[i].w.uaddr; struct futex_q *q = &vs[i].q; - u32 val = (u32)vs[i].w.val; + u32 val = vs[i].w.val; hb = futex_q_lock(q); ret = futex_get_value_locked(&uval, uaddr); @@ -602,7 +602,7 @@ int futex_wait_setup(u32 __user *uaddr, * while the syscall executes. */ retry: - ret = get_futex_key(uaddr, flags & FLAGS_SHARED, &q->key, FUTEX_READ); + ret = get_futex_key(uaddr, flags, &q->key, FUTEX_READ); if (unlikely(ret != 0)) return ret;