From: Peter Zijlstra <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 <akpm@linux-foundation.org>,
urezki@gmail.com, hch@infradead.org, lstoakes@gmail.com,
Arnd Bergmann <arnd@arndb.de>,
linux-api@vger.kernel.org, linux-mm@kvack.org,
linux-arch@vger.kernel.org, malteskarupke@web.de
Subject: [RFC][PATCH 09/10] futex: Enable FUTEX2_{8,16}
Date: Fri, 14 Jul 2023 15:39:08 +0200 [thread overview]
Message-ID: <20230714141219.215288670@infradead.org> (raw)
In-Reply-To: <20230714133859.305719029@infradead.org>
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_64 instead of mandating FUTEX2_32.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
include/linux/futex.h | 11 ++++++-----
kernel/futex/syscalls.c | 4 ++--
kernel/futex/waitwake.c | 4 ++--
3 files changed, 10 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/syscalls.c
+++ b/kernel/futex/syscalls.c
@@ -206,7 +206,7 @@ static int futex_parse_waitv(struct fute
if ((aux.flags & ~FUTEX2_MASK) || aux.__reserved)
return -EINVAL;
- if ((aux.flags & FUTEX2_64) != FUTEX2_32)
+ if ((aux.flags & FUTEX2_64) == FUTEX2_64)
return -EINVAL;
flags = futex2_to_flags(aux.flags);
@@ -334,7 +334,7 @@ SYSCALL_DEFINE4(futex_wake,
if (flags & ~FUTEX2_MASK)
return -EINVAL;
- if ((flags & FUTEX2_64) != FUTEX2_32)
+ if ((flags & FUTEX2_64) == FUTEX2_64)
return -EINVAL;
flags = futex2_to_flags(flags);
--- a/kernel/futex/waitwake.c
+++ b/kernel/futex/waitwake.c
@@ -439,7 +439,7 @@ static int futex_wait_multiple_setup(str
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) {
/*
@@ -607,7 +607,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);
next prev parent reply other threads:[~2023-07-14 14:16 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-14 13:38 [RFC][PATCH 00/10] futex: More Futex2 bits Peter Zijlstra
2023-07-14 13:39 ` [RFC][PATCH 01/10] futex: Clarify FUTEX2 flags Peter Zijlstra
2023-07-14 13:39 ` [RFC][PATCH 02/10] futex: Extend the " Peter Zijlstra
2023-07-14 13:39 ` [RFC][PATCH 03/10] futex: Flag conversion Peter Zijlstra
2023-07-14 13:39 ` [RFC][PATCH 04/10] futex: Add sys_futex_wake() Peter Zijlstra
2023-07-14 14:26 ` Arnd Bergmann
2023-07-14 14:47 ` Peter Zijlstra
2023-07-14 20:10 ` Arnd Bergmann
2023-07-14 13:39 ` [RFC][PATCH 05/10] mm: Add vmalloc_huge_node() Peter Zijlstra
2023-07-14 14:37 ` Matthew Wilcox
2023-07-14 15:09 ` Peter Zijlstra
2023-07-14 15:11 ` Matthew Wilcox
2023-07-14 15:26 ` Peter Zijlstra
2023-07-14 13:39 ` [RFC][PATCH 06/10] futex: Propagate flags into get_futex_key() Peter Zijlstra
2023-07-14 13:39 ` [RFC][PATCH 07/10] futex: Implement FUTEX2_NUMA Peter Zijlstra
2023-07-14 15:22 ` Peter Zijlstra
2023-07-14 13:39 ` [RFC][PATCH 08/10] futex: Propagate flags into futex_get_value_locked() Peter Zijlstra
2023-07-14 13:39 ` Peter Zijlstra [this message]
2023-07-14 13:39 ` [HACK][PATCH 10/10] futex: Munge size and numa into the legacy interface Peter Zijlstra
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=20230714141219.215288670@infradead.org \
--to=peterz@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=andrealmeid@igalia.com \
--cc=arnd@arndb.de \
--cc=axboe@kernel.dk \
--cc=dave@stgolabs.net \
--cc=dvhart@infradead.org \
--cc=hch@infradead.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lstoakes@gmail.com \
--cc=malteskarupke@web.de \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=urezki@gmail.com \
/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