From: "tip-bot2 for peterz@infradead.org" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: andrealmeid@igalia.com,
"Peter Zijlstra (Intel)" <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: locking/core] futex: FLAGS_STRICT
Date: Thu, 21 Sep 2023 17:36:02 -0000 [thread overview]
Message-ID: <169531776286.27769.7382358930466919741.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20230921105248.048643656@noisy.programming.kicks-ass.net>
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 <peterz@infradead.org>
AuthorDate: Thu, 21 Sep 2023 12:45:11 +02:00
Committer: Peter Zijlstra <peterz@infradead.org>
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 <andrealmeid@igalia.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
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 */
next prev parent reply other threads:[~2023-09-21 20:47 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-21 10:45 [PATCH v3 00/15] futex: More futex2 bits peterz
2023-09-21 10:45 ` [PATCH v3 04/15] futex: Validate futex value against futex size peterz
2023-09-21 17:36 ` [tip: locking/core] " tip-bot2 for peterz@infradead.org
2023-09-21 10:45 ` [PATCH v3 05/15] futex: Add sys_futex_wake() peterz
2023-09-21 17:36 ` [tip: locking/core] " tip-bot2 for peterz@infradead.org
2023-09-21 10:45 ` [PATCH v3 07/15] futex: Add sys_futex_wait() peterz
2023-09-21 17:36 ` [tip: locking/core] " tip-bot2 for peterz@infradead.org
2023-09-21 10:45 ` [PATCH v3 08/15] futex: Propagate flags into get_futex_key() peterz
2023-09-21 17:36 ` [tip: locking/core] " tip-bot2 for peterz@infradead.org
2023-09-21 10:45 ` [PATCH v3 09/15] futex: Add flags2 argument to futex_requeue() peterz
2023-09-21 17:36 ` [tip: locking/core] " tip-bot2 for peterz@infradead.org
2023-09-21 10:45 ` [PATCH v3 10/15] futex: Add sys_futex_requeue() peterz
2023-09-21 17:35 ` [tip: locking/core] " tip-bot2 for peterz@infradead.org
2023-09-22 9:35 ` [PATCH v3 10/15] " Ingo Molnar
2023-09-22 11:03 ` Peter Zijlstra
2023-09-22 13:56 ` Jens Axboe
2023-09-21 10:45 ` [PATCH v3 11/15] mm: Add vmalloc_huge_node() peterz
2023-09-21 10:45 ` [PATCH v3 12/15] futex: Implement FUTEX2_NUMA peterz
2023-09-21 10:45 ` [PATCH v3 13/15] futex: Propagate flags into futex_get_value_locked() peterz
2023-09-21 10:45 ` [PATCH v3 14/15] futex: Enable FUTEX2_{8,16} peterz
2023-09-21 10:45 ` [PATCH v3 15/15] futex,selftests: Extend the futex selftests peterz
2023-09-21 11:41 ` Peter Zijlstra
[not found] ` <20230921105248.048643656@noisy.programming.kicks-ass.net>
2023-09-21 15:14 ` [PATCH v3 06/15] futex: FLAGS_STRICT Thomas Gleixner
2023-09-21 17:36 ` tip-bot2 for peterz@infradead.org [this message]
2023-09-22 20:01 ` futex2 numa stuff Peter Zijlstra
2023-09-22 20:01 ` [PATCH 15/15] futex,selftests: Extend the futex selftests Peter Zijlstra
2023-09-22 20:01 ` [PATCH 16/15] futex,selftests: Extend the futex selftests for NUMA Peter Zijlstra
2023-09-22 20:01 ` [PATCH 17/15] [HACK] futex: Force futex hash collision Peter Zijlstra
2023-09-28 13:40 ` futex2 numa stuff Davidlohr Bueso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=169531776286.27769.7382358930466919741.tip-bot2@tip-bot2 \
--to=tip-bot2@linutronix.de \
--cc=andrealmeid@igalia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®