From patchwork Fri Jul 14 13:39:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 13313719 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 5CF27C001DC for ; Fri, 14 Jul 2023 14:16:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 370A16B0074; Fri, 14 Jul 2023 10:16:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 282C26B0075; Fri, 14 Jul 2023 10:16:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0AEAA6B0078; Fri, 14 Jul 2023 10:16:29 -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 EEA1F6B0074 for ; Fri, 14 Jul 2023 10:16:28 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 87D5A1202A1 for ; Fri, 14 Jul 2023 14:16:28 +0000 (UTC) X-FDA: 81010417656.26.A3359BC Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf17.hostedemail.com (Postfix) with ESMTP id 8A8DE4001A for ; Fri, 14 Jul 2023 14:16:26 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=nSMf8b1r; 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; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689344186; 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=gMJRupFzL+218xO81Os5o1A1M02NMRGWkhUhH51/Eio=; b=lqZI0veRcAIw1TthGUM9xzGxKP+FCXjqOCymMXnajSnnesko6zMqRA6rxNmrhAAhTzLQdx ja5EnLGGLVdqDrSS8/ivrJ+4vQPzW7/NBp8WRuzxv0AjUFxPkZKQOT6lFt7ivelIW2N7uL gs4lm9hpMtOXIE4iLHhqs/kUDnJjuHQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689344186; a=rsa-sha256; cv=none; b=voQb/zNynPjvw20yguH9Rk26uVqKS3zOY82vpT2IySf82ETUhZX6ZdP56w/xrv73Tpm9mp Qe9fgShdByzOGV5unm/hhc6Rnd4BkSgInVyxi7p/VHV4Fn+uueqfWb+2ZvpGeBVUu+a40i hxNZdQ4r14BpyZ35oAhnIDTGOmdJfFQ= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=nSMf8b1r; 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; 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=gMJRupFzL+218xO81Os5o1A1M02NMRGWkhUhH51/Eio=; b=nSMf8b1rDj20p7163tEl4RgaYw DSLe3ZSkxQr+7VY+r4TGNHy4IKVGgxGwlAnaBfZ1PYxgc+9BuGU4lppaUgLKt/OlT2VI9vmL+gtik RUUId1CkI+N7mJbbIBxkpyuDGdUa5aVpvS+Yc8iRIksH5FyqowxzwctWZ66ifZj4zpcRzxA1JwJLi xF0TcSWW2JGAR7aiFXIAyNyG7gAGrNLXJTPzDH9o8S5WGUPpfdHzDOaRFWdzQrzyqvi/yLQh8bPzw J3JoHmSbBfv75wEYSpd5GgPHirR718Rgz4S1L/+YVHpWN8Rfzc7tvdreKeoz9KiQE8w+Veqj80xY5 hVMxyKYA==; 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 1qKJah-0016z7-Me; Fri, 14 Jul 2023 14:16:15 +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 B37713014BF; Fri, 14 Jul 2023 16:16:14 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 79A14213728BA; Fri, 14 Jul 2023 16:16:13 +0200 (CEST) Message-ID: <20230714141219.014386004@infradead.org> User-Agent: quilt/0.66 Date: Fri, 14 Jul 2023 15:39:05 +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: [RFC][PATCH 06/10] futex: Propagate flags into get_futex_key() References: <20230714133859.305719029@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 8A8DE4001A X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: axzgx6ea3i8hyjkh315jjfk8shokrriq X-HE-Tag: 1689344186-418799 X-HE-Meta: U2FsdGVkX1+DkUjhcnPfwh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s2P6kob8I89cQs1tZk8pF4rQlYf0IB3nQc+EUMnjnikKVedcFnaPv9nRIBO/1BqNQ7Kjn9GWWZRO77jCMliMZgaQbiTpG2nstRIaWyfMv9OGoUxejY0zQ2z3EFDvABO2wwCu5EXpfSxXyP1LSvLEYIR/sdXEUPoEYtutkpwh56CjnB4gaNEbXYgo5krCozAmPLo2R04CqrgcggZRR 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. Signed-off-by: Peter Zijlstra (Intel) --- kernel/futex/core.c | 5 ++++- kernel/futex/futex.h | 2 +- kernel/futex/pi.c | 4 ++-- kernel/futex/requeue.c | 6 +++--- kernel/futex/waitwake.c | 15 ++++++++------- 5 files changed, 18 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 @@ -158,7 +158,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,8 @@ 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; + unsigned int flags = vs[i].w.flags; + u32 val = vs[i].w.val; hb = futex_q_lock(q); ret = futex_get_value_locked(&uval, uaddr); @@ -599,7 +600,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;