]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
futex: Convert to get/put_user_inline()
authorThomas Gleixner <tglx@linutronix.de>
Mon, 27 Oct 2025 08:44:00 +0000 (09:44 +0100)
committerIngo Molnar <mingo@kernel.org>
Tue, 4 Nov 2025 07:28:23 +0000 (08:28 +0100)
Replace the open coded implementation with the new get/put_user_inline()
helpers. This might be replaced by a regular get/put_user(), but that needs
a proper performance evaluation.

No functional change intended.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://patch.msgid.link/20251027083745.736737934@linutronix.de
kernel/futex/core.c
kernel/futex/futex.h

index 125804fbb5cb17712555679bb98024fcd7d1b85d..ebcccb16ae0b89c04e8cf80f21365d711bb3e7d0 100644 (file)
@@ -581,7 +581,7 @@ int get_futex_key(u32 __user *uaddr, unsigned int flags, union futex_key *key,
        if (flags & FLAGS_NUMA) {
                u32 __user *naddr = (void *)uaddr + size / 2;
 
-               if (futex_get_value(&node, naddr))
+               if (get_user_inline(node, naddr))
                        return -EFAULT;
 
                if ((node != FUTEX_NO_NODE) &&
@@ -601,7 +601,7 @@ int get_futex_key(u32 __user *uaddr, unsigned int flags, union futex_key *key,
                        node = numa_node_id();
                        node_updated = true;
                }
-               if (node_updated && futex_put_value(node, naddr))
+               if (node_updated && put_user_inline(node, naddr))
                        return -EFAULT;
        }
 
index 2cd57096c38e188835a17d6340d9c3bd2c6a354a..30c2afa03889062a173c4a91f933de48ba8aea95 100644 (file)
@@ -281,63 +281,11 @@ static inline int futex_cmpxchg_value_locked(u32 *curval, u32 __user *uaddr, u32
        return ret;
 }
 
-/*
- * This does a plain atomic user space read, and the user pointer has
- * already been verified earlier by get_futex_key() to be both aligned
- * and actually in user space, just like futex_atomic_cmpxchg_inatomic().
- *
- * We still want to avoid any speculation, and while __get_user() is
- * the traditional model for this, it's actually slower than doing
- * this manually these days.
- *
- * We could just have a per-architecture special function for it,
- * the same way we do futex_atomic_cmpxchg_inatomic(), but rather
- * than force everybody to do that, write it out long-hand using
- * the low-level user-access infrastructure.
- *
- * This looks a bit overkill, but generally just results in a couple
- * of instructions.
- */
-static __always_inline int futex_get_value(u32 *dest, u32 __user *from)
-{
-       u32 val;
-
-       if (can_do_masked_user_access())
-               from = masked_user_access_begin(from);
-       else if (!user_read_access_begin(from, sizeof(*from)))
-               return -EFAULT;
-       unsafe_get_user(val, from, Efault);
-       user_read_access_end();
-       *dest = val;
-       return 0;
-Efault:
-       user_read_access_end();
-       return -EFAULT;
-}
-
-static __always_inline int futex_put_value(u32 val, u32 __user *to)
-{
-       if (can_do_masked_user_access())
-               to = masked_user_access_begin(to);
-       else if (!user_write_access_begin(to, sizeof(*to)))
-               return -EFAULT;
-       unsafe_put_user(val, to, Efault);
-       user_write_access_end();
-       return 0;
-Efault:
-       user_write_access_end();
-       return -EFAULT;
-}
-
+/* Read from user memory with pagefaults disabled */
 static inline int futex_get_value_locked(u32 *dest, u32 __user *from)
 {
-       int ret;
-
-       pagefault_disable();
-       ret = futex_get_value(dest, from);
-       pagefault_enable();
-
-       return ret;
+       guard(pagefault)();
+       return get_user_inline(*dest, from);
 }
 
 extern void __futex_unqueue(struct futex_q *q);